Reading Offline events

The following example shows how to access events data in an offline ROOT file, which is written by aanet software.

Note: the offline file used here has MC offline data and was intentionaly reduced to 10 events.

import km3io as ki
from km3net_testdata import data_path

First, pass a filename to the OfflineReader class to open the file. Note that only some meta information is read into memory.

r = ki.OfflineReader(data_path("offline/numucc.root"))

Accessing the file header

Note that not all file headers are supported, so don’t be surprised if nothing is returned when the file header is called (this can happen if your file was produced with old versions of aanet).

h = r.header
print(h)
MC Header:
  DAQ(livetime=394)
  PDF(i1=4, i2=58)
  can(zmin=0, zmax=1027, r=888.4)
  can_user: can_user(field_0=0.0, field_1=1027.0, field_2=888.4)
  coord_origin(x=0, y=0, z=0)
  cut_in(Emin=0, Emax=0, cosTmin=0, cosTmax=0)
  cut_nu(Emin=100, Emax=100000000.0, cosTmin=-1, cosTmax=1)
  cut_primary(Emin=0, Emax=0, cosTmin=0, cosTmax=0)
  cut_seamuon(Emin=0, Emax=0, cosTmin=0, cosTmax=0)
  decay: decay(field_0='doesnt', field_1='happen')
  detector: NOT
  drawing: Volume
  genhencut(gDir=2000, Emin=0)
  genvol(zmin=0, zmax=1027, r=888.4, volume=2649000000.0, numberOfEvents=100000)
  kcut: 2
  livetime(numberOfSeconds=0, errorOfSeconds=0)
  model(interaction=1, muon=2, scattering=0, numberOfEnergyBins=1, field_4=12)
  ngen: 100000.0
  norma(primaryFlux=0, numberOfPrimaries=0)
  nuflux: nuflux(field_0=0, field_1=3, field_2=0, field_3=0.5, field_4=0.0, field_5=1.0, field_6=3.0)
  physics(program='GENHEN', version='7.2-220514', date=181116, time=1138)
  seed(program='GENHEN', level=3, iseed=305765867, field_3=0, field_4=0)
  simul(program='JSirene', version=11012, date='11/17/18', time=7)
  sourcemode: diffuse
  spectrum(alpha=-1.4)
  start_run(run_id=1)
  target: isoscalar
  usedetfile: false
  xlat_user: 0.63297
  xparam: OFF
  zed_user: zed_user(field_0=0.0, field_1=3450.0)

Accessing the events data

Note that not all data is loaded in memory (again), so printing events will only return how many events were found in the file.

print(r.events)
<OfflineReader [10] path='E/Evt'>

to explore the events keys:

keys = r.events.keys()
print(keys)
{'t_ns', 'mc_tracks', 'overlays', 't_sec', 'n_trks', 'w', 'index', 'mc_id', 'n_hits', 'hits', 'trigger_mask', 'n_mc_tracks', 'trigger_counter', 'usr', 'run_id', 'mc_run_id', 'mc_trks', 'n_mc_trks', 'n_tracks', 'frame_index', 'tracks', 'usr_names', 'n_mc_hits', 'flags', 'mc_hits', 'comment', 'mc_t', 'id', 'trks', 'w3list', 'w2list', 'det_id'}

to access the number of hits associated with each event:

n_hits = r.events.n_hits
print(n_hits)
[4271, 4145, 3680, 3967, 4105, 4301, 3949, 4180, 4210, 4024]

to access the number of tracks associated with each event:

n_tracks = r.events.n_tracks
print(n_tracks)
[68, 38, 38, 18, 0, 60, 59, 66, 38, 22]

to access the number of mc hits associated with each event:

n_mc_hits = r.events.n_mc_hits
print(n_mc_hits)
[58, 145, 28, 19, 78, 50, 58, 49, 35, 48]

to access the number of mc tracks associated with each event:

n_mc_tracks = r.events.n_mc_tracks
print(n_mc_tracks)
[11, 25, 12, 10, 10, 13, 11, 10, 13, 16]

to access the overlays:

overlays = r.events.overlays
print(overlays)
[1, 2, 1, 1, 0, 1, 2, 1, 1, 0]

That’s it! you can access any key of your interest in the events keys in the exact same way.

item selection in events data

events can be selected as you would select an item from a numpy array. for example, to select the mc_hits in event 0:

print(r.events[0].mc_hits)
<Branch [1/10] path='mc_hits'>

or:

print(r.events.mc_hits[0])
<Branch [1/10] path='mc_hits'>

slicing of events

you can select a slice of events data. For example, to select the number of mc hits in the first 5 events:

print(r.events.n_mc_hits[0:5])
[58, 145, 28, 19, 78]

or:

print(r.events[0:5].n_mc_hits)
[58, 145, 28, 19, 78]

you can apply masks to events data as you would do with numpy arrays. For example, to select the number of hits higher than 50:

mask = r.events.n_mc_hits > 50

print(r.events.n_mc_hits[mask])
[58, 145, 78, 58]

or:

print(r.events.n_mc_tracks[mask])
[11, 25, 10, 11]

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

Estimated memory usage: 9 MB

Gallery generated by Sphinx-Gallery