Skip to content

Commit

Permalink
move impact parameter computation to Reconstructor
Browse files Browse the repository at this point in the history
  • Loading branch information
StFroese committed Sep 20, 2022
1 parent 56ba45c commit 937e212
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 20 deletions.
2 changes: 2 additions & 0 deletions ctapipe/reco/hillas_intersection.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ def __call__(self, event):
hillas_dict, array_pointing, telescope_pointings
)

self._store_impact_parameter(event)

def _predict(self, hillas_dict, array_pointing, telescopes_pointings=None):
"""
Expand Down
2 changes: 2 additions & 0 deletions ctapipe/reco/hillas_reconstructor.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ def __call__(self, event):
event, hillas_dict, array_pointing, telescope_pointings
)

self._store_impact_parameter(event)

def _predict(self, event, hillas_dict, array_pointing, telescopes_pointings):
"""
The function you want to call for the reconstruction of the
Expand Down
20 changes: 18 additions & 2 deletions ctapipe/reco/reco_algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import numpy as np
from astropy.coordinates import AltAz, SkyCoord

from ctapipe.containers import ArrayEventContainer
from ctapipe.containers import ArrayEventContainer, TelescopeImpactParameterContainer
from ctapipe.core import Component, QualityQuery
from ctapipe.core.traits import List

from .impact_distance import shower_impact_distance

__all__ = ["Reconstructor", "TooFewTelescopesException", "InvalidWidthException"]


Expand Down Expand Up @@ -52,7 +54,6 @@ def __call__(self, event: ArrayEventContainer):
----------
tels_dict : dict
general dictionary containing all triggered telescopes data
Returns
-------
None
Expand Down Expand Up @@ -93,3 +94,18 @@ def _get_telescope_pointings(event):
)
for tel_id in event.dl1.tel.keys()
}

def _store_impact_parameter(self, event):
"""Compute and store the impact parameter for each reconstruction."""
impact_distances = shower_impact_distance(
shower_geom=event.dl2.stereo.geometry[self.__class__.__name__],
subarray=self.subarray,
)
for tel_id in event.trigger.tels_with_trigger:
tel_index = self.subarray.tel_indices[tel_id]
event.dl2.tel[tel_id].impact[
self.__class__.__name__
] = TelescopeImpactParameterContainer(
distance=impact_distances[tel_index],
prefix=f"{self.__class__.__name__}_tel",
)
19 changes: 1 addition & 18 deletions ctapipe/reco/shower_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@
- estimation of classification (optional, currently unavailable)
"""
from ..containers import ArrayEventContainer, TelescopeImpactParameterContainer
from ..containers import ArrayEventContainer
from ..core import Component
from ..core.traits import List, create_class_enum_trait
from ..instrument import SubarrayDescription
from . import Reconstructor
from .impact_distance import shower_impact_distance


class ShowerProcessor(Component):
Expand Down Expand Up @@ -80,19 +79,3 @@ def __call__(self, event: ArrayEventContainer):
self.reconstructor_types, self.reconstructors
):
reconstructor(event)

# compute and store the impact parameter for each reconstruction

# for the stereo reconstructor:
impact_distances = shower_impact_distance(
shower_geom=event.dl2.stereo.geometry[reco_type], subarray=self.subarray
)

for tel_id in event.trigger.tels_with_trigger:
tel_index = self.subarray.tel_indices[tel_id]
event.dl2.tel[tel_id].impact[
reco_type
] = TelescopeImpactParameterContainer(
distance=impact_distances[tel_index],
prefix=f"{reco_type}_tel",
)
3 changes: 3 additions & 0 deletions ctapipe/reco/tests/test_hillas_intersection.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,9 @@ def test_selected_subarray(subarray_and_event_gamma_off_axis_500_gev):
for tel_id in subarray.tel.keys():
if tel_id not in allowed_tels:
event.dl1.tel.pop(tel_id, None)
event.trigger.tels_with_trigger = event.trigger.tels_with_trigger[
event.trigger.tels_with_trigger != tel_id
]

subarray = subarray.select_subarray(allowed_tels)

Expand Down

0 comments on commit 937e212

Please sign in to comment.