@@ -73,6 +73,12 @@ def par_spms_dsp_trg_thr() -> None:
73
73
)
74
74
log .warning (msg )
75
75
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 )
76
82
else :
77
83
# run the DSP with the provided configuration
78
84
log .debug ("running the DSP chain" )
@@ -87,13 +93,14 @@ def par_spms_dsp_trg_thr() -> None:
87
93
# determine a cutoff for the histogram used to extract the FWHM
88
94
low_cutoff , high_cutoff = np .quantile (wf_current , [0.005 , 0.995 ])
89
95
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 )
95
99
)
96
100
101
+ # make histogram of the curr values
102
+ h = hist .new .Variable (bin_edges ).Double ().fill (wf_current )
103
+
97
104
# determine FWHM
98
105
counts = h .view ()
99
106
idx_over_half = np .where (counts >= np .max (counts ) / 2 )[0 ]
@@ -102,7 +109,7 @@ def par_spms_dsp_trg_thr() -> None:
102
109
fwhm = edges [idx_over_half [- 1 ]] - edges [idx_over_half [0 ]]
103
110
104
111
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 } "
106
113
raise RuntimeError (msg )
107
114
108
115
log .debug (f"writing out baseline_curr_fwhm = { fwhm } " )
0 commit comments