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

Implement custom energy-dependent cuts for IRFs and DL3 creations #280

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

gabemery
Copy link
Collaborator

These changes introduce the option to provide energy-dependent cuts on gammaness or theta 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.

Usage : In the config file

@gabemery gabemery added the new functionality For new functionalities label Feb 12, 2025
@gabemery gabemery self-assigned this Feb 12, 2025
Copy link

codecov bot commented Feb 12, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 77.51%. Comparing base (785b6ec) to head (38e0baa).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #280      +/-   ##
==========================================
+ Coverage   77.18%   77.51%   +0.33%     
==========================================
  Files          22       22              
  Lines        2621     2660      +39     
==========================================
+ Hits         2023     2062      +39     
  Misses        598      598              

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

@Elisa-Visentin
Copy link
Collaborator

Thank you @gabemery. Very useful. I was just checking this quickly: there are if clauses inside an elif? (Maybe we can reformulate a bit this and through elifs). As for the new io function, I would suggest passing only the dictionary and string, instead of the whole config, so that we can try to keep backward compatibility (i.e., if the new 'entry' is not in the config, the script can exit w/o erros in the module), but this depends on if we want to create a new major version or not

@gabemery
Copy link
Collaborator Author

Hi @Elisa-Visentin , Thank you for the review. I was also a bit bothered by the elif : if, but I didn't have a clear idea of a better solution.

Currently the structure is:

if global
    apply cut, do metadata
elif energy dependent
    if dynamic
        get dynamic cut and setup metadata
    if custom
        get custom cut and setup meta
    apply energy dependent cut + other common code (35 lines)
else
    handle wrong keyword

To avoid duplicating 35 lines of code, for the energy depedent case, it is needed to have the cuts recovery handled for both before the application.
To handle the wrong key word, everything needs to be handled in the same if, elif, else.

I can think of alternatives, but I am not sure which would be good. To give a few I can invent now :

  1. Handle the error first, do only if
if not global or dynamic or custom
    error
if global
    apply cut, do metadata
if dynamic
     get dynamic cut and setup metadata
if custom
    get custom cut and setup meta
if energy dependent (dynamic or custom)
    apply energy dependent cut + other common code
  1. Duplicate the code or make a function handling it. Keep current if elif else
if global
    apply cut, do metadata
elif dynamic
    get dynamic cut and setup metadata
    apply energy dependent cut + other common code (35 lines)
elif custom
    get custom cut and setup meta
    apply energy dependent cut + other common code (35 lines)
else
    handle wrong keyword

@gabemery
Copy link
Collaborator Author

As for the new io function, I would suggest passing only the dictionary and string, instead of the whole config,

This is possible without issue, it is only moving config["interpolate_kind"], and config["custom_cuts"] as input to the function instead of config.

so that we can try to keep backward compatibility (i.e., if the new 'entry' is not in the config, the script can exit w/o erros in the module), but this depends on if we want to create a new major version or not

For backward compatibility I think it is already ok, since the new entries are only read in the new io function, and in log.info messages in the if blocks for "custom" cuts.
Also, if the method selected is custom, and the associated entries are missing, we should have an error. And looking into the config in the io function or before would lead to the same failure.

So I think there is nothing to change there.

@Elisa-Visentin
Copy link
Collaborator

Hi @Elisa-Visentin , Thank you for the review. I was also a bit bothered by the elif : if, but I didn't have a clear idea of a better solution.

Currently the structure is:

if global
    apply cut, do metadata
elif energy dependent
    if dynamic
        get dynamic cut and setup metadata
    if custom
        get custom cut and setup meta
    apply energy dependent cut + other common code (35 lines)
else
    handle wrong keyword

To avoid duplicating 35 lines of code, for the energy depedent case, it is needed to have the cuts recovery handled for both before the application. To handle the wrong key word, everything needs to be handled in the same if, elif, else.

I can think of alternatives, but I am not sure which would be good. To give a few I can invent now :

  1. Handle the error first, do only if
if not global or dynamic or custom
    error
if global
    apply cut, do metadata
if dynamic
     get dynamic cut and setup metadata
if custom
    get custom cut and setup meta
if energy dependent (dynamic or custom)
    apply energy dependent cut + other common code
  1. Duplicate the code or make a function handling it. Keep current if elif else
if global
    apply cut, do metadata
elif dynamic
    get dynamic cut and setup metadata
    apply energy dependent cut + other common code (35 lines)
elif custom
    get custom cut and setup meta
    apply energy dependent cut + other common code (35 lines)
else
    handle wrong keyword

Hi, probably the most 'beautiful' solution is the last one, where a new function (which could also be defined inside the main function), so that we have only one if-elif-else statement, but I would suggest to wait for Alessio and Julian before changing this (maybe they have a better solution)

@Elisa-Visentin
Copy link
Collaborator

As for the new io function, I would suggest passing only the dictionary and string, instead of the whole config,

This is possible without issue, it is only moving config["interpolate_kind"], and config["custom_cuts"] as input to the function instead of config.

so that we can try to keep backward compatibility (i.e., if the new 'entry' is not in the config, the script can exit w/o erros in the module), but this depends on if we want to create a new major version or not

For backward compatibility I think it is already ok, since the new entries are only read in the new io function, and in log.info messages in the if blocks for "custom" cuts. Also, if the method selected is custom, and the associated entries are missing, we should have an error. And looking into the config in the io function or before would lead to the same failure.

So I think there is nothing to change there.

I have to check this better.... (sorry, I'm quite busy and I'm working on too many things at the same time). Probably we should first fix the nested ifs, to be sure about where we call the involved function: if it is only in the 'elif custom', it should work fine

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

Successfully merging this pull request may close these issues.

2 participants