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

Update DL3 Tools with energy dependent optimized cuts #709

Merged
merged 42 commits into from
Feb 2, 2022

Conversation

chaimain
Copy link
Contributor

@chaimain chaimain commented May 6, 2021

Adding an option (for now), to use optimised (for now only g/h separation) cuts for MC and observed data, for the DL3 files.
Optimization is done on a fixed gamma efficiency for each reco energy bin, using pyirf functions.

I have to test this a bit more before making it open PR.

@codecov
Copy link

codecov bot commented May 7, 2021

Codecov Report

Merging #709 (44ea452) into master (74e35ae) will increase coverage by 0.27%.
The diff coverage is 96.79%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #709      +/-   ##
==========================================
+ Coverage   84.65%   84.92%   +0.27%     
==========================================
  Files          77       77              
  Lines        6074     6170      +96     
==========================================
+ Hits         5142     5240      +98     
+ Misses        932      930       -2     
Impacted Files Coverage Δ
lstchain/high_level/hdu_table.py 93.22% <ø> (+1.04%) ⬆️
lstchain/tools/lstchain_create_dl3_file.py 89.47% <92.00%> (-1.16%) ⬇️
lstchain/tools/lstchain_create_irf_files.py 92.30% <94.44%> (+2.14%) ⬆️
lstchain/io/__init__.py 100.00% <100.00%> (ø)
lstchain/io/event_selection.py 100.00% <100.00%> (ø)
lstchain/io/tests/test_eventselection.py 100.00% <100.00%> (ø)
lstchain/tools/tests/test_tools.py 100.00% <100.00%> (ø)
lstchain/reco/r0_to_dl1.py 93.71% <0.00%> (+0.62%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 74e35ae...44ea452. Read the comment docs.

@chaimain chaimain marked this pull request as ready for review July 7, 2021 21:34
@chaimain
Copy link
Contributor Author

Sorry for the long delay on this PR.

The work on energy-dependent cuts for gammaness is ready.

However, for cuts on the theta parameter, it is not clear how we should define the ON/OFF region. There is an ongoing work in gammapy (gammapy/gammapy#3684) on energy-dependent 1D spectrum extraction, and once it is resolved/merged there, a separate PR can be made in lstchain to appropriately prepare the DL3 files to have the energy-dependent theta cuts and store the data event lists appropriately.

If there is no other issue on this, can this PR be merged before the Analysis School begins next week, or for the 0.8.3 release?

@rlopezcoto
Copy link
Contributor

Hi @chaimain this is a bit long PR that has not been looked at yet, is this absolutely necessary for the school? Otherwise it may be a better idea to leave its merging for afterwards

@maxnoe
Copy link
Member

maxnoe commented Jan 12, 2022

There is an ongoing work in gammapy (gammapy/gammapy#3684) on energy-dependent 1D spectrum extraction, and once it is resolved/merged there, a separate PR can be made in lstchain to appropriately prepare the DL3 files to have the energy-dependent theta cuts and store the data event lists appropriately.

The ongoing work is on how to implement the analysis for the already defined format. The required format will not change as a result of that work.

You just need to include the RAD_MAX HDU in the DL3 files instead of the RAD_MAX header keyword in the EVENTS and irf HDUs

@chaimain
Copy link
Contributor Author

@rlopezcoto It is not absolutely essential, but if it were to be included, it would be great. It is my fault for delaying this one for so long. The school can work fine without this PR.

@chaimain
Copy link
Contributor Author

There is an ongoing work in gammapy (gammapy/gammapy#3684) on energy-dependent 1D spectrum extraction, and once it is resolved/merged there, a separate PR can be made in lstchain to appropriately prepare the DL3 files to have the energy-dependent theta cuts and store the data event lists appropriately.

The ongoing work is on how to implement the analysis for the already defined format. The required format will not change as a result of that work.

You just need to include the RAD_MAX HDU in the DL3 files instead of the RAD_MAX header keyword in the EVENTS and irf HDUs

True, but I am more concerned about how we use separate ON/OFF event lists, based on the theta cuts we apply. It can be kept up to the user on how they work it through maybe, but I would like it to be at least indicated in the Tool, or shown in an example notebook on how it can be done.

So, I wanted to keep that work separate from this PR

@maxnoe
Copy link
Member

maxnoe commented Jan 12, 2022

True, but I am more concerned about how we use separate ON/OFF event lists, based on the theta cuts we apply.

We don't use separated ON/OFF event lists at the DL3 level. DL3 files should include all events surviving gammaness cuts without applying a directional cut with respect to any on or off region.

The work in gammapy is precisely on how off regions are determined and how the theta cuts are applied. This is the domain of gammapy, not the DL3 export.

@chaimain
Copy link
Contributor Author

True, but I am more concerned about how we use separate ON/OFF event lists, based on the theta cuts we apply.

We don't use separated ON/OFF event lists at the DL3 level. DL3 files should include all events surviving gammaness cuts without applying a directional cut with respect to any on or off region.

The work in gammapy is precisely on how off regions are determined and how the theta cuts are applied. This is the domain of gammapy, not the DL3 export.

So, are you implying that the energy-dependent directional cuts should be applied to all the events in MC and observed data?

@maxnoe
Copy link
Member

maxnoe commented Jan 12, 2022

So, are you implying that the energy-dependent directional cuts should be applied to all the events in MC and observed data?

I don't understand the question. The cuts need to be applied on simulated events for calculating the IRFs, but they must not be already applied for simulated test datasets or observed data, as again, this is done later in gammapy and the DL3 events list must not have a directional cut already applied, as this prevents letting gammapy or any other science tool chose the source to be analyzed and the off regions.

There are two parts to the directional cut: the (possibly energy dependent) radius and the position around which this radius is applied. The first thing needs to be fixed by us and written into the file (the RAD_MAX table or header keyword). The second belongs in the domain of the science tools.

Again, no direction cut applied on events in DL3 event lists.

@chaimain
Copy link
Contributor Author

Ok, I understand this now.
I was earlier confused, on whether we should apply direction cuts on events in DL3 event lists, as I assumed that All the cuts applied to simulation data for creating IRFs, should be applied to the real data as well.

Thank you for clarifying this. I will amend the PR accordingly.

Copy link
Member

@maxnoe maxnoe left a comment

Choose a reason for hiding this comment

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

This looks good, some small changes left.

Comment on lines +116 to +117
--energy-dependent-gh
--energy-dependent-theta
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there an advantage in having these? It would be enough to activate the E-dependent cuts if the --gh-efficiency and/or --theta-containment options below are used, right?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, but this would need to change the defaults of the configuration to have them all None and activate the corresponding setting by giving it.

And I think there is a bug in traitlets that doesn't allow a Float(allow_none=True):

ipython/traitlets#637

I fixed it for ctapipe_io_lst here:

https://github.com/cta-observatory/ctapipe_io_lst/blob/e78acdc43ef4c4c95c83ec5100b7c6373af9df86/ctapipe_io_lst/event_time.py#L26

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The config file may have the options, but it will be up to the user to pass these separate flags to use the energy-dependent cuts

Copy link
Member

Choose a reason for hiding this comment

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

Yes, we understand the current situation. We are proposing to change that.

The issue seems to be fixed in traitlets 5.1 we are using now.

Copy link
Collaborator

@moralejo moralejo left a comment

Choose a reason for hiding this comment

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

Looks good to me, I just suggested a few minor things.

…the gh_efficiency and theta_containment to be provided in % without changing the values in the Class

Merge branch 'master' of https://github.com/cta-observatory/cta-lstchain into energy_dependent_cuts
Copy link
Member

@maxnoe maxnoe left a comment

Choose a reason for hiding this comment

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

Three smallish things left, we are getting there!

lstchain/tools/lstchain_create_dl3_file.py Outdated Show resolved Hide resolved
lstchain/tools/lstchain_create_dl3_file.py Show resolved Hide resolved
lstchain/tools/lstchain_create_dl3_file.py Show resolved Hide resolved
lstchain/tools/tests/test_tools.py Show resolved Hide resolved
…RF, fix the pytest of creating RAD_MAX with diffuse gamma across multiple FoV bins
@rlopezcoto rlopezcoto merged commit 333d8ee into master Feb 2, 2022
@rlopezcoto rlopezcoto deleted the energy_dependent_cuts branch February 2, 2022 09:28
chaimain added a commit that referenced this pull request Feb 2, 2022
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.

5 participants