-
Notifications
You must be signed in to change notification settings - Fork 266
/
list_simtel_events_per_telescope.py
executable file
·66 lines (45 loc) · 2.11 KB
/
list_simtel_events_per_telescope.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Print the list of triggered events per telescope of the given simtel file.
"""
import argparse
from ctapipe.io.hessio import hessio_event_source
def list_simtel_events_per_telescope(simtel_file_path):
"""Make a dictionary of triggered events per telescope of the
'simtel_file_path' file.
Parameters
----------
simtel_file_path : str
The path of the simtel file to process.
Returns
-------
Dictionary of triggered events per telescope of the 'simtel_file_path'
file (for each item: key=telescope id, value=the list of triggered events).
"""
source = hessio_event_source(simtel_file_path, allowed_tels=None, max_events=None)
events_per_tel_dict = {} # List of events per telescope
for event in source:
triggered_telescopes_list = [int(tel_id) for tel_id in event.trig.tels_with_trigger]
for telescope_id in triggered_telescopes_list:
if telescope_id not in events_per_tel_dict:
events_per_tel_dict[telescope_id] = []
events_per_tel_dict[telescope_id].append(int(event.r0.event_id))
return events_per_tel_dict
def main():
"""Parse command options (sys.argv) and print the dictionary of triggered
events returned by the 'list_simtel_events_per_telescope' function."""
# PARSE OPTIONS ###########################################################
desc = "Print the list of triggered events per telescope of the given simtel file."
parser = argparse.ArgumentParser(description=desc)
parser.add_argument("fileargs", nargs=1, metavar="FILE",
help="The simtel file to process")
args = parser.parse_args()
simtel_file_path = args.fileargs[0]
# PRINT THE LIST ##########################################################
events_per_tel_dict = list_simtel_events_per_telescope(simtel_file_path)
print("Triggered events per telescope:")
for telescope_id, events_id_list in events_per_tel_dict.items():
print("- Telescope {:03}: {}".format(telescope_id, events_id_list))
if __name__ == '__main__':
main()