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

Allow using custom energy dependent cuts (e.g. based on sensitivity optimization) for IRFs and DL3 #1348

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

gabemery
Copy link
Collaborator

@gabemery gabemery commented Feb 5, 2025

Currently, IRF and DL3 creation tools only allow for global or energy-dependent gammaness, theta or alpha cuts calculated based on MC gamma-ray efficiency.

These changes introduce the option to provide custom previously calculated energy-dependent cuts on gammaness, theta or alpha during the IRFs creation. And provides associated metadata in the IRFs and DL3 files.

Why is it needed : Allows to provide energy dependent cuts based on criteria different from gamma efficiency. Such as best sensitivity.

Tool usage change with the new implementation :
Removed flags --energy-dependent-gh, --energy-dependent-theta and --energy-dependent-alpha and replaced them by a --cut_strategy-{gh, theta, alpha} which receives the technique used as a string input.

The implementation is near complete and can be reviewed, but some points need discussion/further work.
To do before merging :

  • (optionnal) Decide how to store the energy dependent cuts : Should the input be stored in the metadata? Before or after re-binning? Other strategy?
  • Implement tests

@gabemery gabemery self-assigned this Feb 5, 2025
@morcuended
Copy link
Member

morcuended commented Feb 7, 2025

Hi @gabemery, thanks for the implementation, I think it makes sense to support this. Maybe have a look at how it was recently done in ctapipe, so here we use similar naming and so on (cta-observatory/ctapipe#2473).

Specifically, they implement:
Two components for calculating G/H and optionally theta cuts are added:
PercentileCuts keeps a certain percentage of gamma events in each bin and (what we had already)
PointSourceSensitivityOptimizer optimizes G/H cuts for maximum point source sensitivity and
optionally calculates percentile theta cuts.

Copy link

codecov bot commented Feb 7, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 72.99%. Comparing base (76540cc) to head (87056e5).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1348      +/-   ##
==========================================
+ Coverage   72.86%   72.99%   +0.12%     
==========================================
  Files         137      137              
  Lines       14515    14583      +68     
==========================================
+ Hits        10577    10645      +68     
  Misses       3938     3938              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@gabemery
Copy link
Collaborator Author

gabemery commented Feb 7, 2025

@morcuended Thanks for bringing the ctapipe version to my attention. I will have a look and see what can be implemented without re-writing the full tool.

@gabemery
Copy link
Collaborator Author

gabemery commented Feb 7, 2025

After having a look, there is nothing to directly implement from the ctapipe irf production into this PR since the pipelines are very different.
It could be interesting to fully transition to the ctapipe tools later. But I would say this is out of the scope of this feature addition.

@moralejo
Copy link
Collaborator

@morcuended can you approve? I had a quick look and it seems ok to me, but probably you know this better.

@morcuended
Copy link
Member

Let me have a look first

@morcuended morcuended changed the title Energy dependent cuts for IRFs and DL3 Allow using custom energy dependent cuts (e.g. based on sensitivity optimization) for IRFs and DL3 Feb 14, 2025
Copy link
Member

@morcuended morcuended left a comment

Choose a reason for hiding this comment

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

I leave some comments. It looks good overall.

help="True for applying energy-dependent gammaness cuts",
default_value=False,
cut_strategy_gh = traits.Unicode(
help="Define the strategy used for the gammaness cut."
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
help="Define the strategy used for the gammaness cut."
help="Strategy used for the gammaness cut."

help="True for applying energy-dependent theta cuts",
default_value=False,
cut_strategy_theta = traits.Unicode(
help="Define the strategy used for the theta cut."
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
help="Define the strategy used for the theta cut."
help="Strategy used for the theta cut."

help="True for applying energy-dependent alpha cuts",
default_value=False,
cut_strategy_alpha = traits.Unicode(
help="Define the strategy used for the alpha cut."
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
help="Define the strategy used for the alpha cut."
help="Strategy used for the alpha cut."

interpolate_custom = traits.Unicode(
help="Interpolation option for scipy.interpolate.interp1d used with "
"custom, energy dependent cuts.",
default_value="global",
Copy link
Member

Choose a reason for hiding this comment

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

default "linear", "nearest"? not global

default_value="global",
).tag(config=True)

interpolate_custom = traits.Unicode(
Copy link
Member

Choose a reason for hiding this comment

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

I would name this argument differently to indicate that you're interpolating cut values. Something like interp_method_custom_cuts


input_ebins_center = (cuts_dict["energy_bins"][:-1]* u.TeV + cuts_dict["energy_bins"][1:] * u.TeV) * 0.5

cut_table["low"] =energy_bins[:-1]
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
cut_table["low"] =energy_bins[:-1]
cut_table["low"] = energy_bins[:-1]

'gh', 'theta' or 'alpha'
energy_bins: `astropy.units.quantity.Quantity`
energy bins used for the IRFs
interpolate_kind: string
Copy link
Member

Choose a reason for hiding this comment

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

I'd use interpolation instead of interpolate here

def from_dict(self, parameter, energy_bins, interpolate_kind='nearest'):
"""
Convert the cut dictionary to a QTable for the requested parameter.

Copy link
Member

Choose a reason for hiding this comment

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

I'd also add that the cut values are interpolated along the IRF energy binning.


Returns
-------
cut_table: QTable
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
cut_table: QTable
cut_table: `astropy.table.QTable`

----------
parameter: string
'gh', 'theta' or 'alpha'
energy_bins: `astropy.units.quantity.Quantity`
Copy link
Member

Choose a reason for hiding this comment

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

maybe explicitly irf_energy_bins?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants