Skip to content

Commit

Permalink
Only transform geometries once, not per event
Browse files Browse the repository at this point in the history
  • Loading branch information
maxnoe committed Nov 17, 2023
1 parent e1e5d06 commit 437c75a
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions ctapipe/image/muon/intensity_fitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,8 @@ def image_prediction_no_units(

def build_negative_log_likelihood(
image,
telescope_description,
optics,
geometry_tel_frame,
mask,
oversampling,
min_lambda,
Expand All @@ -329,23 +330,20 @@ def build_negative_log_likelihood(
"""

# get all the neeed values and transform them into appropriate units
optics = telescope_description.optics
mirror_area = optics.mirror_area.to_value(u.m**2)
mirror_radius = np.sqrt(mirror_area / np.pi)

cam = telescope_description.camera.geometry.transform_to(TelescopeFrame())

# Use only a subset of pixels, indicated by mask:
pixel_x = cam.pix_x.to_value(u.rad)
pixel_y = cam.pix_y.to_value(u.rad)
pixel_x = geometry_tel_frame.pix_x.to_value(u.rad)
pixel_y = geometry_tel_frame.pix_y.to_value(u.rad)

if mask is not None:
pixel_x = pixel_x[mask]
pixel_y = pixel_y[mask]
image = image[mask]
pedestal = pedestal[mask]

pixel_diameter = cam.pixel_width[0].to_value(u.rad)
pixel_diameter = geometry_tel_frame.pixel_width[0].to_value(u.rad)

min_lambda = min_lambda.to_value(u.m)
max_lambda = max_lambda.to_value(u.m)
Expand Down Expand Up @@ -458,6 +456,14 @@ class MuonIntensityFitter(TelescopeComponent):
help="Oversampling for the line integration", default_value=3
).tag(config=True)

def __init__(self, subarray, **kwargs):
super().__init__(subarray=subarray, **kwargs)

self._geometries_tel_frame = {
tel_id: tel.camera.geometry.transform_to(TelescopeFrame())
for tel_id, tel in subarray.tel.items()
}

def __call__(self, tel_id, center_x, center_y, radius, image, pedestal, mask=None):
"""
Expand Down Expand Up @@ -490,9 +496,10 @@ def __call__(self, tel_id, center_x, center_y, radius, image, pedestal, mask=Non
)

negative_log_likelihood = build_negative_log_likelihood(
image,
telescope,
mask,
image=image,
optics=telescope.optics,
geometry_tel_frame=self._geometries_tel_frame[tel_id],
mask=mask,
oversampling=self.oversampling.tel[tel_id],
min_lambda=self.min_lambda_m.tel[tel_id] * u.m,
max_lambda=self.max_lambda_m.tel[tel_id] * u.m,
Expand Down

0 comments on commit 437c75a

Please sign in to comment.