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)

Out:

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)

Out:

<OfflineReader [10] path='E/Evt'>

to explore the events keys:

keys = r.events.keys()
print(keys)

Out:

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

to access the number of hits associated with each event:

n_hits = r.events.n_hits
print(n_hits)

Out:

[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)

Out:

[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)

Out:

[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)

Out:

[11, 25, 12, 10, 10, 13, 11, 10, 13, 16]

to access the overlays:

overlays = r.events.overlays
print(overlays)

Out:

[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)

Out:

<Branch [1/10] path='mc_hits'>

or:

print(r.events.mc_hits[0])

Out:

<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])

Out:

[58, 145, 28, 19, 78]

or:

print(r.events[0:5].n_mc_hits)

Out:

[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])

Out:

[58, 145, 78, 58]

or:

print(r.events.n_mc_tracks[mask])

Out:

[11, 25, 10, 11]

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

Estimated memory usage: 9 MB

Gallery generated by Sphinx-Gallery