Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SPECTUB segfault when using PSF with 0 intercept #1547

Open
KrisThielemans opened this issue Nov 26, 2024 · 0 comments
Open

SPECTUB segfault when using PSF with 0 intercept #1547

KrisThielemans opened this issue Nov 26, 2024 · 0 comments
Assignees
Labels

Comments

@KrisThielemans
Copy link
Collaborator

When setting the intercept to zero (which is irrealistic, but can be useful), @varzakis and I see segfaults when the detector is "inside" the image (e.g. for small detector radius). The calc_psf_bin code doesn't seem to handle the case of a very narrow (or zero width) PSF. Relevant code:

psf1d_h->sgmcm = calc_sigma_h(vox, wmh.COL);
psf1d_h->di = min((int)floor(szdx / psf1d_h->sgmcm), gaussdens->lng - 1);
psf1d_h->lngcmd2 = psf1d_h->sgmcm * wmh.maxsigm;
psf1d_h->lngcm = psf1d_h->lngcmd2 * (float)2.;
psf1d_h->efres = gaussdens->res * psf1d_h->sgmcm;

(di could be very large/infinite)
float beg_psf = center_psf - psf->lngcmd2; // position of the begin of the psf in the detection line (cm)
int jm = (int)floor(beg_psf / binszcm); // first index in detection line interacting with psf (it can be negative)
float r_nextb = (float)(jm + 1) * binszcm; // position of the next change of bin (cm)
int i1 = min((int)floor((r_nextb - beg_psf) / psf->efres),
vxprj->lng - 1); // index in vxprj distribution in which happens the change of bin
int Ncb = (vxprj->lng - i1 - 1) / psf->di; // number of complete bins covered by PSF

(i1 would be undefined but was in our case a very negative number, Ncb should then be 0, but isn't necessarily)
weight = vxprj->acu[i1] - vxprj->acu[0];

crashes as i1 is out-of-range

I think this needs 2 modifications:

  • if psref is very small, just set
    psf->val[0] = 1.F;`
    psf->ind[0] = jm;
    psf->Nib = 1;
  • add an assert that i1>=0

@varzakis @danieldeidda ok?

@KrisThielemans KrisThielemans self-assigned this Nov 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant