@@ -88,11 +88,30 @@ def gather_pulse_data(
88
88
lgdo_obj = lh5 .read (
89
89
f"/{ channel } /{ tierinfo .group } /{ column } " , tierinfo .file , idx = idx
90
90
)
91
- data = lgdo_obj .view_as (library = "ak " )
91
+ data = lgdo_obj .view_as (library = "np " )
92
92
93
93
# remove nans (this happens when SiPM data is stored as ArrayOfEqualSizedArrays)
94
94
data = ak .drop_none (ak .nan_to_none (data ))
95
95
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
+
96
115
# increase the dimensionality by one (events)
97
116
data = ak .unflatten (data , np .full (data .layout .length , 1 , dtype = "uint8" ))
98
117
@@ -161,17 +180,18 @@ def gather_tcm_data(
161
180
for field in ("id" , "idx" ):
162
181
tcm_vov [field ] = types .VectorOfVectors (
163
182
flattened_data = tcm ._asdict ()[field ], cumulative_length = tcm .cumulative_length
164
- ). view_as ( "ak" )
183
+ )
165
184
166
185
# list user wanted table names
167
186
table_ids = [
168
187
utils .get_tcm_id_by_pattern (datainfo .hit .table_fmt , id ) for id in table_names
169
188
]
170
189
# 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 )
172
192
173
193
# select tcm field requested by the user
174
- data = tcm_vov [tcm_field ]
194
+ data = tcm_vov [tcm_field ]. view_as ( "ak" )
175
195
176
196
# apply mask
177
197
# NOTE: need to cast to irregular axes, otherwise the masking result is
@@ -201,6 +221,7 @@ def gather_tcm_data(
201
221
raise ValueError (msg )
202
222
203
223
# 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 ]
204
225
ch_mask = ak .sum (pulse_mask , axis = - 1 ) > 0
205
226
206
227
# apply the mask
0 commit comments