Newer
Older
The following example shows how to access tracks data in an offline ROOT file.
Note: the offline files used here were intentionaly reduced to 10 events.
"""
import km3io as ki
#####################################################
# We open the file using the
f = ki.OfflineReader(data_path("offline/numucc.root"))
#####################################################
# To access offline tracks/mc_tracks data:
#####################################################
# Note that no data is loaded in memory at this point, so printing
# tracks will only return how many sub-branches (corresponding to
# events) were found.
#####################################################
# same for mc hits
#####################################################
# Accessing the tracks/mc_tracks keys
# -----------------------------------
#####################################################
#####################################################
# Accessing tracks data
# ---------------------
# each field will return a nested `awkward.Array` and load everything into
# memory, so be careful if you are working with larger files.
print(f.tracks.E)
print(f.tracks.dir_z)
print(f.tracks.lik)
#####################################################
# To select just a single event or a subset of events, use the indices or slices.
# The following will access all tracks and their fields
# of the third event (0 is the first):
#####################################################
# while here, we select the first 3 events. Notice that all fields will return
# nested arrays, as we have seem above where all events were selected.
print(f[:3])
print(f[:3].tracks)
print(f[:3].tracks.dir_z)
#####################################################
print(f[2:5])
print(f[2:5].tracks)
print(f[2:5].tracks.dir_z)