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

Irf maker and cut optimiser #2473

Draft
wants to merge 136 commits into
base: main
Choose a base branch
from
Draft

Irf maker and cut optimiser #2473

wants to merge 136 commits into from

Conversation

Tobychev
Copy link
Contributor

As we are planning to produce IRFs on events that were not used to select the GH cut, it makes sense to split the procedure generating IRFs into two tools. Because this splitting results in a large restructuring of the the previous PR on generating IRFs (#2315) that was basically working properly, I open a new PR to preserve the discussion on the old attempt and let its more or less functional code serve as easy reference.

@Tobychev Tobychev marked this pull request as draft November 24, 2023 09:45
ctapipe/irf/binning.py Outdated Show resolved Hide resolved
ctapipe/irf/irf_classes.py Outdated Show resolved Hide resolved
ctapipe/irf/irf_classes.py Outdated Show resolved Hide resolved
ctapipe/irf/irf_classes.py Outdated Show resolved Hide resolved
help="Percent of events in each energy bin keep after the theta cut",
).tag(config=True)

def calculate_theta_cuts(self, theta, reco_energy, energy_bins):
Copy link
Member

Choose a reason for hiding this comment

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

Classes that basically are configurable functions (i.e. have traitlets and then a single method) should use __call__ I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After recently having tried to explain how __call__ means you can do object(args) to a beginner, I think that syntax has too much magic and explicit is better.

Copy link
Member

Choose a reason for hiding this comment

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

I think it's more important to be consistent. If that's a decision we should make, we should make it everywhere and not just here. However, regarding this particular point, I have a different opinion.

We have many instances in ctapipe now that implement __call__ and I think it's the correct thing to do.

Beginners have problems with many concepts, that shouldn't mean that we optimize our code for being understandable by beginners vs. writing idiomatic python.

ctapipe/irf/binning.py Outdated Show resolved Hide resolved
ctapipe/irf/optimise.py Outdated Show resolved Hide resolved
def __init__(self, gh_cuts=None, offset_lim=None):
self.gh_cuts = gh_cuts
if gh_cuts:
self.gh_cuts.meta["extname"] = "GH_CUTS"
Copy link
Member

Choose a reason for hiding this comment

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

extname is the name of a FITS extension. You should't set this in the metadata of the table, but only when writing out, it's the name argument of write.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I got

TypeError: write_table_fits() got an unexpected keyword argument 'name'

when I tried self.gh_cuts.write(out_name, name="GH_CUTS", format="fits", overwrite=overwrite) and I don't find anything about a name argument to table.write, do you mean I should manage the fits file more directly and just cast the tables to hdus?

ctapipe/irf/optimise.py Outdated Show resolved Hide resolved
ctapipe/irf/select.py Outdated Show resolved Hide resolved
ctapipe/irf/select.py Outdated Show resolved Hide resolved
ctapipe/irf/select.py Outdated Show resolved Hide resolved

quality_criteria = List(
default_value=[
("multiplicity 4", "np.count_nonzero(tels_with_trigger,axis=1) >= 4"),
Copy link
Member

Choose a reason for hiding this comment

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

Do we really want a multiplicity cut of 4 by default? I would remove that and only require the valid reconstruction.

ctapipe/tools/make_irf.py Outdated Show resolved Hide resolved
self.source_offset_bins = self.bins.source_offset_bins()
self.fov_offset_bins = self.opt_result.offset_lim

self.particles = [
Copy link
Member

@maxnoe maxnoe Nov 24, 2023

Choose a reason for hiding this comment

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

Protons and electrons should probably be optional or not given at all.

You only need them to compute a background model, which we maybe should split into a separate tool (ctapipe-compute-background-from-simulations) or similar, since we won't use simulations for computing the background component later.

ctapipe/tools/make_irf.py Outdated Show resolved Hide resolved
)
)

# calculate sensitivity
Copy link
Member

@maxnoe maxnoe Nov 24, 2023

Choose a reason for hiding this comment

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

computing sensitivity should be separate from computing IRFs I think.

In datapipe, we will need to compute the signal-related IRFs from the planned tailored simulations, but won't have proton, electron or heavier nuclei.

ctapipe/tools/make_irf.py Outdated Show resolved Hide resolved
ctapipe/tools/make_irf.py Outdated Show resolved Hide resolved
)
# Here we use reconstructed energy instead of true energy for the sake of
# current pipelines comparisons
bias_resolution = energy_bias_resolution(
Copy link
Member

Choose a reason for hiding this comment

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

bias_resolution are benchmarks that can be computed from events (like here) or from the IRFs (functions in pyirf or methods of the irf objects in gammapy), I'd not compute them here in the IRF tool.


# Here we use reconstructed energy instead of true energy for the sake of
# current pipelines comparisons
ang_res = angular_resolution(
Copy link
Member

Choose a reason for hiding this comment

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

same here, it's a benchmark, not an IRF, so I'd say it doesn't belong into the IRF tool

ctapipe/tools/make_irf.py Outdated Show resolved Hide resolved
ctapipe/irf/irfs.py Outdated Show resolved Hide resolved
ctapipe/tools/make_irf.py Outdated Show resolved Hide resolved
ctapipe/irf/binning.py Outdated Show resolved Hide resolved
src/ctapipe/irf/optimize.py Outdated Show resolved Hide resolved
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.

4 participants