Skip to content

Commit 0249ec2

Browse files
committed
spms par dsp returns null pars if waveform is not there (zero supp)
1 parent c5fbfcf commit 0249ec2

File tree

1 file changed

+60
-37
lines changed

1 file changed

+60
-37
lines changed

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

+60-37
Original file line numberDiff line numberDiff line change
@@ -44,47 +44,70 @@ def par_spms_dsp_trg_thr() -> None:
4444
utils.load_dict(cfgtools.get_channel_config(config.settings, args.sipm_name))
4545
)
4646

47-
# read raw file list
48-
log.debug("reading in the raw waveforms")
49-
data = lh5.read(
50-
args.raw_table_name,
51-
args.raw_file,
52-
field_mask=["waveform_bit_drop"],
53-
n_rows=settings.n_events,
54-
)
55-
5647
# get DSP database from overrides
5748
_db_dict = Props.read_from(args.dsp_db).get(args.sipm_name, {})
5849

59-
# run the DSP with the provided configuration
60-
log.debug("running the DSP chain")
61-
chain, _, dsp_output = build_processing_chain(data, dsp_config, db_dict=_db_dict)
62-
chain.execute()
63-
64-
log.debug("analyzing DSP outputs")
65-
# get output of the current processor
66-
wf_current = dsp_output.wf_current.values.view_as("np").flatten()
67-
# determine a cutoff for the histogram used to extract the FWHM
68-
low_cutoff, high_cutoff = np.quantile(wf_current, [0.005, 0.995])
69-
70-
# make histogram of the curr values
71-
h = (
72-
hist.new.Regular(settings.n_baseline_bins, low_cutoff, high_cutoff)
73-
.Double()
74-
.fill(wf_current)
75-
)
76-
77-
# determine FWHM
78-
counts = h.view()
79-
idx_over_half = np.where(counts >= np.max(counts) / 2)[0]
80-
81-
edges = h.axes[0].edges
82-
fwhm = edges[idx_over_half[-1]] - edges[idx_over_half[0]]
50+
fwhm = None
8351

84-
if fwhm <= 0:
85-
msg = "determined FWHM of baseline derivative distribution is zero or negative"
86-
raise RuntimeError(msg)
52+
# read raw file list
53+
log.debug("reading in the raw waveforms")
54+
if len(lh5.ls(args.raw_file, f"{args.raw_table_name}/waveform_bit_drop")) == 0:
55+
msg = (
56+
f"could not find waveform '{args.raw_table_name}/waveform_bit_drop' "
57+
"in {args.raw_file}, returning null pars"
58+
)
59+
log.warning(msg)
60+
61+
else:
62+
data = lh5.read(
63+
args.raw_table_name,
64+
args.raw_file,
65+
field_mask=["waveform_bit_drop"],
66+
n_rows=settings.n_events,
67+
)
68+
69+
if len(data) == 0:
70+
msg = (
71+
f"could not find any waveforms '{args.raw_table_name}/waveform_bit_drop' "
72+
"in {args.raw_file}, returning null pars"
73+
)
74+
log.warning(msg)
75+
76+
else:
77+
# run the DSP with the provided configuration
78+
log.debug("running the DSP chain")
79+
chain, _, dsp_output = build_processing_chain(
80+
data, dsp_config, db_dict=_db_dict
81+
)
82+
chain.execute()
83+
84+
log.debug("analyzing DSP outputs")
85+
# get output of the current processor
86+
wf_current = dsp_output.wf_current.values.view_as("np").flatten()
87+
# determine a cutoff for the histogram used to extract the FWHM
88+
low_cutoff, high_cutoff = np.quantile(wf_current, [0.005, 0.995])
89+
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)
95+
)
96+
97+
# determine FWHM
98+
counts = h.view()
99+
idx_over_half = np.where(counts >= np.max(counts) / 2)[0]
100+
101+
edges = h.axes[0].edges
102+
fwhm = edges[idx_over_half[-1]] - edges[idx_over_half[0]]
103+
104+
if fwhm <= 0:
105+
msg = "determined FWHM of baseline derivative distribution is zero or negative"
106+
raise RuntimeError(msg)
87107

88108
log.debug(f"writing out baseline_curr_fwhm = {fwhm}")
89109
Path(args.output_file).parent.mkdir(parents=True, exist_ok=True)
90-
Props.write_to(args.output_file, {"baseline_curr_fwhm": float(fwhm)})
110+
Props.write_to(
111+
args.output_file,
112+
{"baseline_curr_fwhm": float(fwhm) if fwhm is not None else fwhm},
113+
)

0 commit comments

Comments
 (0)