Skip to content

Commit 82ba7eb

Browse files
committed
merges
2 parents fd6970b + c7a281b commit 82ba7eb

File tree

5 files changed

+21
-63
lines changed

5 files changed

+21
-63
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}")

workflow/src/legenddataflow/scripts/tier/raw_blind.py

+3-14
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
"""
1212

1313
import argparse
14-
from pathlib import Path
1514

1615
import numexpr as ne
1716
import numpy as np
@@ -111,12 +110,6 @@ def build_tier_raw_blind() -> None:
111110
# gets events that should not be blinded
112111
tokeep = allind[np.logical_not(np.isin(allind, toblind))]
113112

114-
# make some temp file to write the output to before renaming it
115-
rng = np.random.default_rng()
116-
rand_num = f"{rng.integers(0,99999):05d}"
117-
temp_output = f"{args.output}.{rand_num}"
118-
Path(temp_output).parent.mkdir(parents=True, exist_ok=True)
119-
120113
for channel in all_channels:
121114
try:
122115
chnum = int(channel[2::])
@@ -126,7 +119,7 @@ def build_tier_raw_blind() -> None:
126119
store.write_object(
127120
chobj,
128121
channel,
129-
lh5_file=temp_output,
122+
lh5_file=args.output,
130123
wo_mode="w",
131124
**hdf_settings,
132125
)
@@ -139,7 +132,7 @@ def build_tier_raw_blind() -> None:
139132
chobj,
140133
group=channel,
141134
name="raw",
142-
lh5_file=temp_output,
135+
lh5_file=args.output,
143136
wo_mode="w",
144137
**hdf_settings,
145138
)
@@ -157,11 +150,7 @@ def build_tier_raw_blind() -> None:
157150
blinded_chobj,
158151
group=channel,
159152
name="raw",
160-
lh5_file=temp_output,
153+
lh5_file=args.output,
161154
wo_mode="w",
162155
**hdf_settings,
163156
)
164-
165-
# rename the temp file
166-
Path(args.output).parent.mkdir(parents=True, exist_ok=True)
167-
Path(temp_output).rename(args.output)

workflow/src/legenddataflow/scripts/tier/raw_fcio.py

+2-24
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import argparse
2-
from copy import deepcopy
32
from pathlib import Path
43

5-
import numpy as np
64
from daq2lh5 import build_raw
75
from dbetto import TextDB
86
from dbetto.catalog import Props
@@ -36,24 +34,11 @@ def build_tier_raw_fcio() -> None:
3634
channel_dict = channel_dict.out_spec
3735
all_config = Props.read_from(channel_dict.gen_config)
3836

39-
chmap = (
40-
TextDB(args.chan_maps, lazy=True).channelmaps.on(args.timestamp).group("system")
41-
)
42-
4337
if "geds_config" in channel_dict:
4438
raise NotImplementedError()
4539

4640
if "spms_config" in channel_dict:
4741
spm_config = Props.read_from(channel_dict.spms_config)
48-
spm_channels = chmap.spms.map("daq.rawid")
49-
50-
for rawid, chinfo in spm_channels.items():
51-
cfg_block = deepcopy(spm_config["FCEventDecoder"]["__output_table_name__"])
52-
cfg_block["key_list"] = [chinfo.daq.fc_channel]
53-
spm_config["FCEventDecoder"][f"ch{rawid:07d}/raw"] = cfg_block
54-
55-
spm_config["FCEventDecoder"].pop("__output_table_name__")
56-
5742
Props.add_to(all_config, spm_config)
5843

5944
if "auxs_config" in channel_dict:
@@ -62,17 +47,10 @@ def build_tier_raw_fcio() -> None:
6247
if "muon_config" in channel_dict:
6348
raise NotImplementedError()
6449

65-
rng = np.random.default_rng()
66-
rand_num = f"{rng.integers(0,99999):05d}"
67-
temp_output = f"{args.output}.{rand_num}"
68-
6950
build_raw(
7051
args.input,
71-
instream_type="FlashCam",
7252
out_spec=all_config,
73-
filekey=temp_output,
53+
instream_type="FlashCam",
54+
filekey=args.output,
7455
**settings,
7556
)
76-
77-
# rename the temp file
78-
Path(temp_output).rename(args.output)

workflow/src/legenddataflow/scripts/tier/raw_orca.py

+2-10
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import logging
33
from pathlib import Path
44

5-
import numpy as np
65
from daq2lh5 import build_raw
76
from dbetto import TextDB
87
from dbetto.catalog import Props
@@ -101,17 +100,10 @@ def build_tier_raw_orca() -> None:
101100
)
102101
Props.add_to(all_config, aux_config)
103102

104-
rng = np.random.default_rng()
105-
rand_num = f"{rng.integers(0,99999):05d}"
106-
temp_output = f"{args.output}.{rand_num}"
107-
108103
build_raw(
109104
args.input,
110-
in_stream_type="ORCA",
111105
out_spec=all_config,
112-
filekey=temp_output,
106+
in_stream_type="ORCA",
107+
filekey=args.output,
113108
**settings,
114109
)
115-
116-
# rename the temp file
117-
Path(temp_output).rename(args.output)

workflow/src/legenddataflow/scripts/tier/tcm.py

+1-9
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import argparse
2-
from pathlib import Path
32

43
import lgdo.lh5 as lh5
5-
import numpy as np
64
from daq2lh5.orca import orca_flashcam
75
from dbetto import TextDB
86
from dbetto.catalog import Props
@@ -28,10 +26,6 @@ def build_tier_tcm() -> None:
2826

2927
settings = Props.read_from(config_dict["inputs"]["config"])
3028

31-
rng = np.random.default_rng()
32-
temp_output = f"{args.output}.{rng.integers(0, 99999):05d}"
33-
Path(args.output).parent.mkdir(parents=True, exist_ok=True)
34-
3529
# get the list of channels by fcid
3630
ch_list = lh5.ls(args.input, "/ch*")
3731
fcid_channels = {}
@@ -46,10 +40,8 @@ def build_tier_tcm() -> None:
4640
for fcid, fcid_dict in fcid_channels.items():
4741
build_tcm(
4842
[(args.input, fcid_dict)],
49-
out_file=temp_output,
43+
out_file=args.output,
5044
out_name=f"hardware_tcm_{fcid}",
5145
wo_mode="o",
5246
**settings,
5347
)
54-
55-
Path(temp_output).rename(args.output)

0 commit comments

Comments
 (0)