Fix background sampling
We aim to sample backgrounds in ker_coh_max_and_chisq_versatile
(and possibly elsewhere).
Currently we do this by taking samples offset from the event time for each detector.
These samples are intended to be far enough apart to ensure there is no real common signal between detectors (currently trial_interval = 0.1
seconds).
This serves as a live estimate of the probability that the signal we have observed is spurious.
Current implementation multiplies sample offset by the difference between the ids of the offset IFO and pivotal IFO in an effort to ensure IFOs are offset far enough apart. However it also multiplies the offset by the trial index (up to 100, currently). Running with 4 detectors means we can end up with a total offset of up to 3 seconds. This can exceed the length of the ringbuffer and invalidate our samples.
Current implementation: (trial_sample_inv
= 0.1 seconds in samples)
trial_offset = itrial * trial_sample_inv;
...
NtOff = round(
toa_diff_map[map_idx * num_sky_directions + ipix] / dt);
// The background cohsnr should be obtained coherently as
// well.
int offset =
(j == iifo ? 0
: NtOff - (trial_offset * (j - iifo)) + len);
...
dk[j] =
snr[j][len * tmplt_cur
+ ((start_exe + len_cur + offset + len) % len)];
j - iifo
can also be negative if the pivotal ifo is not 0, and so could wrap around the wrong way (since we don't have data from the future). On that note, how do we handle the pivotal event being before other detectors have seen the signal?
We should consider alternative implementations to take samples that meet our requirements (each detector separated by enough time that they can't have real coherence, reasonably broad sampling). Exact details of sample properties may require consulting a scientist.
We should consider using a (deterministic) pseudo-random process for selecting our samples to give them better statistical significance (in case there are temporally repeating patterns that match our background sampling rate).