README.md 2.38 KB
Newer Older
Ievgen Vovk's avatar
Ievgen Vovk committed
1
2
3
4
5
6
7
8
## *ctapipe* MAGIC event source

This module implements the *ctapipe* class, needed to read the calibrated data of the MAGIC telescope system. It requires the [*ctapipe*](https://github.com/cta-observatory/ctapipe) and [*uproot*](https://github.com/scikit-hep/uproot) packages to run.

#### Installation

Provided *ctapipe* is already installed, the installation can be done like so:

9
10
11
12
13
14
15
```bash
git clone https://gitlab.mpcdf.mpg.de/ievo/ctapipe_io_magic.git
pip install ./ctapipe_io_magic/
```

This installation via pip (provided, pip is installed) has the advantage to be nicely controlled for belonging to a given conda environment (and to be uninstalled). Alternatively, do

Ievgen Vovk's avatar
Ievgen Vovk committed
16
17
18
19
20
21
22
23
24
25
26
27
```bash
git clone https://gitlab.mpcdf.mpg.de/ievo/ctapipe_io_magic.git
cd ctapipe_io_magic
python setup.py install --user
```

#### Usage

```python
import ctapipe
from ctapipe_io_magic import MAGICEventSource

Moritz Huetten's avatar
Moritz Huetten committed
28
29
with MAGICEventSource(input_url=file_name) as event_source:
    for event in event_source:
Ievgen Vovk's avatar
Ievgen Vovk committed
30
31
32
        ...some processing...
```

Moritz Huetten's avatar
Moritz Huetten committed
33
34
35
The reader also works with multiple files parsed as wildcards, e.g.,

```python
Moritz Huetten's avatar
Moritz Huetten committed
36
event_source = MAGICEventSource(input_url='data_dir/*.root')
Moritz Huetten's avatar
Moritz Huetten committed
37
38
39
40
41
42
43
44
45
46
```

This is necessary to load and match stereo events, which are automatically created if data files from M1 and M2 for the same run are loaded. 

The reader is able to handle data or Monte Carlo files, which are automatically recognized. Note that the file names have to follow the convention:
- `*_M[1-2]_RUNNUMBER.SUBRUNNR_Y_*.root` for data
- `*_M[1-2]_za??to??_?_RUNNUMBER_Y_*.root` for Monte Carlos.

Note that currently, when loading multiple runs at once, the event ID is not unique.

Moritz Huetten's avatar
Moritz Huetten committed
47
48
49
50
51
52
##### More usage
Select a single run:
```python
run = event_source._set_active_run(event_source.run_numbers[0])
for n in range(run['data'].n_stereo_events):
    run['data'].get_stereo_event_data(n)
Moritz Huetten's avatar
Moritz Huetten committed
53
    
Moritz Huetten's avatar
Moritz Huetten committed
54
55
for n in range(run['data'].n_mono_events_m1):
    run['data'].get_mono_event_data(n, 'M1')
Moritz Huetten's avatar
Moritz Huetten committed
56
    
Moritz Huetten's avatar
Moritz Huetten committed
57
58
59
60
61
62
63
64
65
for n in range(run['data'].n_pedestal_events_m1):
    run['data'].get_pedestal_event_data(n, 'M1')
```

Select mono/pedestal events over event generator:
```python
mono_event_generator = event_source._mono_event_generator(telescope='M1')
for m1_mono_event in mono_event_generator:
     ...some processing...
Moritz Huetten's avatar
Moritz Huetten committed
66
     
Moritz Huetten's avatar
Moritz Huetten committed
67
68
69
70
pedestal_event_generator = event_source._pedestal_event_generator(telescope='M1')
...
```

Moritz Huetten's avatar
Moritz Huetten committed
71
72
73
74
75

#### Changelog

- v0.1: Initial version
- v0.2.0: Unification of data and MC reading