Skip to content

Commit e84c132

Browse files
authored
Merge pull request #597 from rosannadeckert/dev-build
Changed `evt/spms` to allow for event building with zero-suppression data
2 parents 29d9b63 + bc3dbbb commit e84c132

File tree

3 files changed

+32
-6
lines changed

3 files changed

+32
-6
lines changed

src/pygama/evt/build_evt.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,12 @@ def evaluate_expression(
414414
# pygama.evt.modules.spms.my_func([...], arg1=val, arg2=val)
415415

416416
# get arguments list passed to the function (outermost parentheses)
417-
args_str = re.search(r"\((.*)\)$", expr.strip()).group(1)
417+
result = re.search(r"\((.*)\)$", expr.strip(), re.DOTALL)
418+
if result is None:
419+
msg = f"could not parse the function arguments in '{expr}'"
420+
raise RuntimeError(msg)
421+
422+
args_str = result.group(1)
418423

419424
# handle tier scoping: evt.<>
420425
args_str = args_str.replace("evt.", "")

src/pygama/evt/modules/spms.py

+25-4
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,30 @@ def gather_pulse_data(
8888
lgdo_obj = lh5.read(
8989
f"/{channel}/{tierinfo.group}/{column}", tierinfo.file, idx=idx
9090
)
91-
data = lgdo_obj.view_as(library="ak")
91+
data = lgdo_obj.view_as(library="np")
9292

9393
# remove nans (this happens when SiPM data is stored as ArrayOfEqualSizedArrays)
9494
data = ak.drop_none(ak.nan_to_none(data))
9595

96+
# number of channels per event
97+
evt_length = np.diff(np.insert(tcm.cumulative_length, 0, 0))
98+
99+
# construct global event ID's
100+
glob_ids = np.repeat(
101+
np.arange(0, tcm.cumulative_length.shape[0], 1), evt_length
102+
)
103+
glob_ids_ch = glob_ids[
104+
tcm.id == table_id
105+
] # global ID's where channel had a trigger
106+
107+
# count number of hits per channel for global events with trigger in channel, else 0
108+
glob_ids_cts = np.zeros(tcm.cumulative_length.shape[0], dtype=int)
109+
glob_ids_cts[glob_ids_ch] = ak.count(data, axis=1)
110+
111+
# insert empty row [] for global events with no trigger in channel
112+
# unflatten to the number of hits in channel otherwise
113+
data = ak.unflatten(ak.flatten(data), glob_ids_cts)
114+
96115
# increase the dimensionality by one (events)
97116
data = ak.unflatten(data, np.full(data.layout.length, 1, dtype="uint8"))
98117

@@ -161,17 +180,18 @@ def gather_tcm_data(
161180
for field in ("id", "idx"):
162181
tcm_vov[field] = types.VectorOfVectors(
163182
flattened_data=tcm._asdict()[field], cumulative_length=tcm.cumulative_length
164-
).view_as("ak")
183+
)
165184

166185
# list user wanted table names
167186
table_ids = [
168187
utils.get_tcm_id_by_pattern(datainfo.hit.table_fmt, id) for id in table_names
169188
]
170189
# find them in tcm.id (we'll filter the rest out)
171-
locs = np.isin(tcm_vov["id"], table_ids)
190+
tcm_id_padded = tcm_vov["id"].to_aoesa().view_as("np")
191+
locs = np.isin(tcm_id_padded, table_ids)
172192

173193
# select tcm field requested by the user
174-
data = tcm_vov[tcm_field]
194+
data = tcm_vov[tcm_field].view_as("ak")
175195

176196
# apply mask
177197
# NOTE: need to cast to irregular axes, otherwise the masking result is
@@ -201,6 +221,7 @@ def gather_tcm_data(
201221
raise ValueError(msg)
202222

203223
# convert the 3D mask to a 2D mask (can be used to filter table_ids)
224+
pulse_mask = pulse_mask[ak.num(pulse_mask, axis=2) > 0]
204225
ch_mask = ak.sum(pulse_mask, axis=-1) > 0
205226

206227
# apply the mask

src/pygama/hit/build_hit.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ def build_hit(
109109
# sanitize config
110110
hit_config = utils.load_dict(hit_config)
111111

112+
lh5_tables_config = {}
112113
if lh5_tables is None:
113-
lh5_tables_config = {}
114114
if "dsp" in ls(infile):
115115
log.debug("found candidate table /dsp")
116116
lh5_tables_config["dsp"] = hit_config

0 commit comments

Comments
 (0)