Skip to content

Commit

Permalink
Fix impact being written for non-triggered telescopes, fix reading it…
Browse files Browse the repository at this point in the history
… in HDF5EventSource, fixes #1961
  • Loading branch information
maxnoe committed Jun 27, 2022
1 parent daa8386 commit 6add8c1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
34 changes: 18 additions & 16 deletions ctapipe/io/hdf5eventsource.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,8 @@ def _generate_events(self):
dl2_tel_readers[kind][name] = {
key: HDF5TableReader(self.file_).read(
table._v_pathname,
containers=(ReconstructedGeometryContainer,),
containers=container,
prefixes=True,
)
for key, table in algorithm_group._v_children.items()
}
Expand Down Expand Up @@ -471,34 +472,34 @@ def _generate_events(self):
if self.is_simulation:
data.simulation.shower = next(mc_shower_reader)

for tel in data.trigger.tel.keys():
key = f"tel_{tel:03d}"
if self.allowed_tels and tel not in self.allowed_tels:
for tel_id in data.trigger.tel.keys():
key = f"tel_{tel_id:03d}"
if self.allowed_tels and tel_id not in self.allowed_tels:
continue

if key in true_impact_readers:
data.simulation.tel[tel].impact = next(true_impact_readers[key])
data.simulation.tel[tel_id].impact = next(true_impact_readers[key])

if DataLevel.R1 in self.datalevels:
data.r1.tel[tel] = next(waveform_readers[key])
data.r1.tel[tel_id] = next(waveform_readers[key])

if self.has_simulated_dl1:
simulated = data.simulation.tel[tel]
simulated = data.simulation.tel[tel_id]

if DataLevel.DL1_IMAGES in self.datalevels:
if key not in image_readers:
logger.debug(
f"Triggered telescope {tel} is missing "
f"Triggered telescope {tel_id} is missing "
"from the image table."
)
continue

data.dl1.tel[tel] = next(image_readers[key])
data.dl1.tel[tel_id] = next(image_readers[key])

if self.has_simulated_dl1:
if key not in simulated_image_iterators:
logger.warning(
f"Triggered telescope {tel} is missing "
f"Triggered telescope {tel_id} is missing "
"from the simulated image table, but was present at the "
"reconstructed image table."
)
Expand All @@ -507,17 +508,17 @@ def _generate_events(self):
simulated.true_image = simulated_image_row["true_image"]

if DataLevel.DL1_PARAMETERS in self.datalevels:
if f"tel_{tel:03d}" not in param_readers.keys():
if f"tel_{tel_id:03d}" not in param_readers.keys():
logger.debug(
f"Triggered telescope {tel} is missing "
f"Triggered telescope {tel_id} is missing "
"from the parameters table."
)
continue
# Is there a smarter way to unpack this?
# Best would probbaly be if we could directly read
# into the ImageParametersContainer
params = next(param_readers[key])
data.dl1.tel[tel].parameters = ImageParametersContainer(
data.dl1.tel[tel_id].parameters = ImageParametersContainer(
hillas=params[0],
timing=params[1],
leakage=params[2],
Expand All @@ -527,15 +528,15 @@ def _generate_events(self):
peak_time_statistics=params[6],
)
if self.has_simulated_dl1:
if f"tel_{tel:03d}" not in param_readers.keys():
if f"tel_{tel_id:03d}" not in param_readers.keys():
logger.debug(
f"Triggered telescope {tel} is missing "
f"Triggered telescope {tel_id} is missing "
"from the simulated parameters table, but was "
"present at the reconstructed parameters table."
)
continue
simulated_params = next(
simulated_param_readers[f"tel_{tel:03d}"]
simulated_param_readers[f"tel_{tel_id:03d}"]
)
simulated.true_parameters = ImageParametersContainer(
hillas=simulated_params[0],
Expand All @@ -548,6 +549,7 @@ def _generate_events(self):
for kind, algorithms in dl2_tel_readers.items():
c = getattr(data.dl2.tel[tel_id], kind)
for algorithm, readers in algorithms.items():
print(kind, algorithm, tel_id, key)
c[algorithm] = next(readers[key])

for kind, readers in dl2_readers.items():
Expand Down
6 changes: 3 additions & 3 deletions ctapipe/reco/shower_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ def __call__(self, event: ArrayEventContainer):
shower_geom=event.dl2.stereo.geometry[k], subarray=self.subarray
)

for tel_index, impact_distance in enumerate(impact_distances):
tel_id = self.subarray.tel_ids[tel_index]
for tel_id in event.trigger.tels_with_trigger:
tel_index = self.subarray.tel_indices[tel_id]
event.dl2.tel[tel_id].impact[k] = TelescopeImpactParameterContainer(
distance=impact_distance
distance=impact_distances[tel_index]
)

0 comments on commit 6add8c1

Please sign in to comment.