Skip to content

Commit 0a2b304

Browse files
authored
Merge pull request #115 from rosannadeckert/fwhm
Friedmann Diaconis bins for SiPM threshold determination
2 parents 7a9e1ea + 1437d9c commit 0a2b304

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

workflow/src/legenddataflow/scripts/par/spms/dsp/trigger_threshold.py

+13-6
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ def par_spms_dsp_trg_thr() -> None:
7373
)
7474
log.warning(msg)
7575

76+
elif len(data) < settings.n_events:
77+
msg = (
78+
f"number of waveforms '{args.raw_table_name}/waveform_bit_drop' < {settings.n_events}"
79+
"in {args.raw_file}, can't build histogram"
80+
)
81+
raise RuntimeError(msg)
7682
else:
7783
# run the DSP with the provided configuration
7884
log.debug("running the DSP chain")
@@ -87,13 +93,14 @@ def par_spms_dsp_trg_thr() -> None:
8793
# determine a cutoff for the histogram used to extract the FWHM
8894
low_cutoff, high_cutoff = np.quantile(wf_current, [0.005, 0.995])
8995

90-
# make histogram of the curr values
91-
h = (
92-
hist.new.Regular(settings.n_baseline_bins, low_cutoff, high_cutoff)
93-
.Double()
94-
.fill(wf_current)
96+
# determine hist edges with Friedmann Diaconis Estimator
97+
bin_edges = np.histogram_bin_edges(
98+
wf_current, bins="fd", range=(low_cutoff, high_cutoff)
9599
)
96100

101+
# make histogram of the curr values
102+
h = hist.new.Variable(bin_edges).Double().fill(wf_current)
103+
97104
# determine FWHM
98105
counts = h.view()
99106
idx_over_half = np.where(counts >= np.max(counts) / 2)[0]
@@ -102,7 +109,7 @@ def par_spms_dsp_trg_thr() -> None:
102109
fwhm = edges[idx_over_half[-1]] - edges[idx_over_half[0]]
103110

104111
if fwhm <= 0:
105-
msg = "determined FWHM of baseline derivative distribution is zero or negative"
112+
msg = f"determined FWHM of baseline derivative distribution is so <= 0: {fwhm:.3f}"
106113
raise RuntimeError(msg)
107114

108115
log.debug(f"writing out baseline_curr_fwhm = {fwhm}")

0 commit comments

Comments
 (0)