Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fit status fields to output container of MuonIntensityFitter #2381

Merged
merged 11 commits into from
Jul 17, 2023
3 changes: 3 additions & 0 deletions ctapipe/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -984,6 +984,9 @@ class MuonEfficiencyContainer(Container):
impact_x = Field(nan * u.m, "impact parameter x position")
impact_y = Field(nan * u.m, "impact parameter y position")
optical_efficiency = Field(nan, "optical efficiency muon")
is_valid = Field(False, "True if the fit converged successfully")
parameters_at_limit = Field(False, "True if any bounded parameter was fitted close to a bound")
likelihood_value = Field(nan, "cost function value at the minimum")


class MuonParametersContainer(Container):
Expand Down
5 changes: 4 additions & 1 deletion ctapipe/image/muon/intensity_fitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ def __call__(self, tel_id, center_x, center_y, radius, image, pedestal, mask=Non

# Perform minimisation
minuit.migrad()

# Get fitted values
result = minuit.values

Expand All @@ -545,4 +545,7 @@ def __call__(self, tel_id, center_x, center_y, radius, image, pedestal, mask=Non
impact_y=result["impact_parameter"] * np.sin(result["phi"]) * u.m,
width=u.Quantity(np.rad2deg(result["ring_width"]), u.deg),
optical_efficiency=result["optical_efficiency_muon"],
is_valid=minuit.valid,
parameters_at_limit=minuit.fmin.has_parameters_at_limit,
likelihood_value=minuit.fval
)
3 changes: 3 additions & 0 deletions ctapipe/image/muon/tests/test_intensity_fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ def test_muon_efficiency_fit(prod5_lst):
assert u.isclose(result.impact, impact_parameter, rtol=0.05)
assert u.isclose(result.width, ring_width, rtol=0.05)
assert u.isclose(result.optical_efficiency, efficiency, rtol=0.05)
assert result.is_valid
assert not result.parameters_at_limit
assert np.isfinite(result.likelihood_value)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is is very hard to change this test so it checks that the likelihood is reasonably close to a known value?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Testing a particular value will be hard, yes. Maybe testing that the value is lower for a fit with the correct ring parameters passed in than for one where we don't have ring center / radius values?



def test_scts(prod5_sst):
Expand Down
1 change: 1 addition & 0 deletions docs/changes/2381.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added new fields to the `MuonEfficiencyContainer` - `is_valid` to check if fit converged successfully, `parameters_at_limit` to check if parameters were fitted close to a bound and `likelihood_value` which represents cost function value atthe minimum. These fields were added to the output of the `MuonIntensityFitter`
maxnoe marked this conversation as resolved.
Show resolved Hide resolved