Skip to content

Commit

Permalink
Support new light_dat shape
Browse files Browse the repository at this point in the history
  • Loading branch information
mjkramer committed Dec 31, 2023
1 parent 241a6a2 commit d245d15
Showing 1 changed file with 32 additions and 5 deletions.
37 changes: 32 additions & 5 deletions src/proto_nd_flow/reco/light/mc_event_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,15 +185,42 @@ def init(self):
)

# copy and remap the truth information
self.data_manager.create_dset(self.mc_truth_dset_name, dtype=self.light_dat.dtype, shape=self.channel_map.shape)
truth_len = ceil(self.light_dat.shape[0] // self.size)
if type(self.light_dat) is h5py.Group: # We have four 96-column matrices
light_dat = self._bloat_light_dat(self.light_dat) # Now have 384 col
else: # We have the old 384-column matrix
light_dat = self.light_dat

self.data_manager.create_dset(self.mc_truth_dset_name, dtype=light_dat.dtype, shape=self.channel_map.shape)
truth_len = ceil(light_dat.shape[0] // self.size)
truth_slice = slice(self.rank * truth_len, (self.rank+1) * truth_len)
remapped_light_dat = self._remap_array(self.channel_map, self.light_dat[truth_slice], axis=-1)
remapped_light_dat = self._remap_array(self.channel_map, light_dat[truth_slice], axis=-1)
self.data_manager.reserve_data(self.mc_truth_dset_name, truth_slice)
self.data_manager.write_data(self.mc_truth_dset_name, truth_slice, remapped_light_dat)

mc_channel = np.indices(self.light_dat[0:1].shape)[1]

mc_channel = np.indices(light_dat[0:1].shape)[1]


@staticmethod
def _bloat_light_dat(light_dat_group: h5py.Group) -> np.array:
""" HACK
Merge the four 96-channel matrices into a 384-channel matrix like the
one that larnd-sim formerly produced. Avoids modifying downstream code. """
def blocks(i):
"""Return the `light_dat` for module `i` and a clone with
`n_photons_det` set to 0."""
dat = light_dat_group[f'light_dat_module{i}']
nulls = np.array(dat)
nulls['n_photons_det'] = 0
return dat, nulls
dat0, nulls0 = blocks(0)
dat1, nulls1 = blocks(1)
dat2, nulls2 = blocks(2)
dat3, nulls3 = blocks(3)
light_dat_wide0 = np.hstack([dat0, nulls0, nulls0, nulls0])
light_dat_wide1 = np.hstack([nulls1, dat1, nulls1, nulls1])
light_dat_wide2 = np.hstack([nulls2, nulls2, dat2, nulls2])
light_dat_wide3 = np.hstack([nulls3, nulls3, nulls3, dat3])
return np.vstack([light_dat_wide0, light_dat_wide1, light_dat_wide2, light_dat_wide3])

def finish(self):
super(LightEventGeneratorMC, self).finish()
Expand Down

0 comments on commit d245d15

Please sign in to comment.