|
1 | 1 | #!/usr/bin/env python3 |
2 | 2 |
|
3 | | -"""Components for computing event weights.""" |
| 3 | +""" |
| 4 | +Components for computing event weights. |
| 5 | +
|
| 6 | +`~ctapipe.irf.EventWeighter` is a base Component with implementations of spectral event weighting: |
| 7 | +
|
| 8 | +* `~ctapipe.irf.SimpleEventWeighter`: spectral weighting for the full FOV |
| 9 | +* `~ctapipe.irf.RadialEventWeighter`: spectral weighing in radial bins in the FOV |
| 10 | +
|
| 11 | +They operate on a pre-processed table of DL2 information, where you specify the |
| 12 | +energy and FOV coordinate columns to use. The interface is as follows: |
| 13 | +
|
| 14 | +.. code-block:: python |
| 15 | +
|
| 16 | + from astropy.table import QTable |
| 17 | +
|
| 18 | + from ctapipe.irf import RadialEventWeighter spectrum_from_name |
| 19 | +
|
| 20 | + table = QTable( |
| 21 | + dict( |
| 22 | + true_energy=[1.0, 2.0, 0.5, 0.2] * u.TeV, |
| 23 | + true_fov_offset=[0.1, 1.2, 2.2, 3.2] * u.deg, |
| 24 | + ) |
| 25 | + ) |
| 26 | +
|
| 27 | + # the source spectrum can be anything, but is usually loaded |
| 28 | + # with ctapipe.irf.spectrum_from_simulation_config() to |
| 29 | + # weight simulations. Here we will just use the electron |
| 30 | + # spectrum as a demo: |
| 31 | + source_spectrum = spectrum_from_name("IRFDOC_ELECTRON_SPECTRUM") |
| 32 | +
|
| 33 | + weighter = RadialEventWeighter( |
| 34 | + source_spectrum=source_spectrum |
| 35 | + target_spectrum_name="CRAB_HEGRA", |
| 36 | + fov_offset_max=5.0*u.deg, |
| 37 | + fov_offset_n_bins=5, |
| 38 | + ) |
| 39 | +
|
| 40 | + table_with_weights = weighter(table) |
| 41 | + print(table_with_weights) |
| 42 | +
|
| 43 | +
|
| 44 | +:: |
| 45 | +
|
| 46 | + true_energy true_fov_offset weight fov_offset_bin |
| 47 | + TeV deg |
| 48 | + ----------- --------------- ------------------ -------------- |
| 49 | + 1.0 0.1 12.399508446433442 1 |
| 50 | + 2.0 1.2 7.247055871572714 2 |
| 51 | + 0.5 2.2 1.4149219056909543 3 |
| 52 | + 0.2 3.2 0.4812883464910382 4 |
| 53 | +
|
| 54 | +
|
| 55 | +""" |
4 | 56 |
|
5 | 57 | from abc import abstractmethod |
6 | 58 | from collections.abc import Callable |
|
0 commit comments