Skip to content

SPECTUB segfault when using PSF with 0 intercept #1547

Open
@KrisThielemans

Description

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?

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions