Newer
Older
"""
Reading Offline tracks
======================
The following example shows how to access tracks data in an offline ROOT file, which is
written by aanet software.
Note: the offline files used here were intentionaly reduced to 10 events.
"""
import km3io as ki
#####################################################
# To access offline tracks/mc_tracks data:
mc_tracks = ki.OfflineReader("samples/numucc.root").events.mc_tracks
tracks = ki.OfflineReader("samples/km3net_offline.root").events.tracks
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#####################################################
# Note that not all data is loaded in memory, so printing
# tracks will only return how many elements (events) were found in
# the tracks branch of the file.
print(tracks)
#####################################################
# same for mc hits
print(mc_tracks)
#####################################################
# Accessing the tracks/mc_tracks keys
# -----------------------------------
# to explore the tracks keys:
keys = tracks.keys()
print(keys)
#####################################################
# to explore the mc_tracks keys:
mc_keys = mc_tracks.keys()
print(mc_keys)
#####################################################
# Accessing tracks data
# ---------------------
# to access data in `E` (tracks energy):
E = tracks.E
print(E)
#####################################################
# to access the likelihood:
likelihood = tracks.lik
print(likelihood)
#####################################################
# That's it! you can access any key of your interest in the tracks
# keys in the exact same way.
#####################################################
# Accessing the mc_tracks data
# ----------------------------
# similarly, you can access mc_tracks data in any key of interest by
# following the same procedure as for tracks:
cos_zenith = mc_tracks.dir_z
print(cos_zenith)
#####################################################
# or:
dir_y = mc_tracks.dir_y
print(dir_y)
#####################################################
# item selection in tracks data
# -----------------------------
# tracks data can be selected as you would select an item from a numpy array.
# for example, to select E (energy) in the tracks corresponding to the first event:
print(tracks[0].E)
#####################################################
# or:
print(tracks.E[0])
#####################################################
# slicing of tracks
# -----------------
# to select a slice of tracks data:
print(tracks[0:3].E)
#####################################################
# or:
print(tracks.E[0:3])
#####################################################
# you can apply masks to tracks data as you would do with numpy arrays:
mask = tracks.lik > 100
print(tracks.lik[mask])
#####################################################
# or:
print(tracks.dir_z[mask])