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

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)

Out:

OfflineBranch (tracks) with 10 elements

same for mc hits

print(mc_tracks)

Out:

OfflineBranch (mc_tracks) with 10 elements

Accessing the tracks/mc_tracks keys

to explore the tracks keys:

keys = tracks.keys()
print(keys)

Out:

dict_keys(['fitinf', 'dir_z', 'type', 'pos_y', 'mother_id', 'E', 'status', 'rec_stages', 'pos_z', 'pos_x', 'dir_x', 'comment', 'hit_ids', 'id', 'rec_type', 'error_matrix', 'dir_y', 'usr_names', 'len', 't', 'lik'])

to explore the mc_tracks keys:

mc_keys = mc_tracks.keys()
print(mc_keys)

Out:

dict_keys(['id', 'comment', 'dir_z', 'usr', 'pos_x', 't', 'pos_y', 'rec_type', 'dir_y', 'lik', 'usr_names', 'dir_x', 'pos_z', 'error_matrix', 'E', 'len', 'hit_ids', 'type'])

Accessing tracks data

to access data in E (tracks energy):

E = tracks.E
print(E)

Out:

[[99.10458562488608 0.0 0.0 ... 0.0 0.0 0.0] [99.10458562488608 0.0 0.0 ... 0.0 0.0 0.0] [99.10458562488608 0.0 0.0 ... 0.0 0.0 0.0] ... [99.10458562488608 0.0 0.0 ... 0.0 0.0 0.0] [49.13672985920654 0.0 0.0 ... 0.0 0.0 0.0] [20.35137468173687 0.0 0.0 ... 0.0 0.0 0.0]]

to access the likelihood:

likelihood = tracks.lik
print(likelihood)

Out:

[[294.6407542676734 294.6407542676734 294.6407542676734 ... 67.81221253265059 67.7756405143316 67.77250505700384] [96.75133289411137 96.75133289411137 96.75133289411137 ... 39.21916536442286 39.184645826013806 38.870325146341884] [560.2775306614813 560.2775306614813 560.2775306614813 ... 118.88577278801066 118.72271313687405 117.80785995187605] ... [71.03251451148226 71.03251451148226 71.03251451148226 ... 16.714140573909347 16.444395245214945 16.34639241716669] [326.440133294878 326.440133294878 326.440133294878 ... 87.79818671079849 87.75488082571873 87.74839444768625] [159.77779654216795 159.77779654216795 159.77779654216795 ... 33.8669134999348 33.821631538334984 33.77240735670646]]

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)

Out:

[[0.230189 0.230189 0.218663 ... 0.454533 0.163034 0.214805] [-0.199551 -0.199551 -0.209328 ... -0.552111 -0.54383 -0.497666] [-0.970691 -0.970691 -0.979032 ... -0.932142 -0.444712 -0.766195] ... [0.237249 0.237249 0.252804 ... 0.195875 -0.166947 -0.073677] [-0.117873 -0.117873 -0.095363 ... -0.229408 0.288494 0.002943] [-0.47429 -0.47429 -0.479018 ... 0.600508 -0.328485 -0.321784]]

or:

dir_y = mc_tracks.dir_y
print(dir_y)

Out:

[[0.253904 0.253904 0.272617 ... 0.18187 0.496095 0.180521] [0.659914 0.659914 0.633951 ... 0.820612 0.620541 0.609052] [0.028334 0.028334 -0.005391 ... 0.171771 -0.87258 0.593915] ... [0.08056 0.08056 0.086408 ... 0.06398 -0.073539 0.133062] [0.482464 0.482464 0.463778 ... 0.636396 0.653415 0.874786] [0.466036 0.466036 0.459793 ... 0.522106 0.072336 -0.048011]]

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)

Out:

[99.10458562  0.          0.          0.          0.          0.
  0.          0.          0.          0.          0.          0.
  0.          0.          0.          0.          0.          0.
  0.          0.          0.          0.          0.          0.
  0.          0.          0.          0.          0.          0.
  0.          0.          0.          0.          0.          0.
  0.          0.          0.          0.          0.          0.
  0.          0.          0.          0.          0.          0.
  0.          0.          0.          0.          0.          0.
  0.          0.        ]

or:

print(tracks.E[0])

Out:

[99.10458562  0.          0.          0.          0.          0.
  0.          0.          0.          0.          0.          0.
  0.          0.          0.          0.          0.          0.
  0.          0.          0.          0.          0.          0.
  0.          0.          0.          0.          0.          0.
  0.          0.          0.          0.          0.          0.
  0.          0.          0.          0.          0.          0.
  0.          0.          0.          0.          0.          0.
  0.          0.          0.          0.          0.          0.
  0.          0.        ]

slicing of tracks

to select a slice of tracks data:

print(tracks[0:3].E)

Out:

[[99.10458562488608 0.0 0.0 ... 0.0 0.0 0.0] [99.10458562488608 0.0 0.0 ... 0.0 0.0 0.0] [99.10458562488608 0.0 0.0 ... 0.0 0.0 0.0]]

or:

print(tracks.E[0:3])

Out:

[[99.10458562488608 0.0 0.0 ... 0.0 0.0 0.0] [99.10458562488608 0.0 0.0 ... 0.0 0.0 0.0] [99.10458562488608 0.0 0.0 ... 0.0 0.0 0.0]]

you can apply masks to tracks data as you would do with numpy arrays:

mask = tracks.lik > 100

print(tracks.lik[mask])

Out:

[[295, 295, 295, 292, 291, 291, 289, 289, ... 144, 142, 140, 138, 137, 134, 127]]

or:

print(tracks.dir_z[mask])

Out:

[[-0.873, -0.873, -0.873, -0.874, -0.871, ... -0.741, -0.743, -0.746, -0.754]]

Total running time of the script: ( 0 minutes 2.775 seconds)

Estimated memory usage: 11 MB

Gallery generated by Sphinx-Gallery