Reading Online Data

The following example shows how to access hits in a ROOT file which is coming from the detector and written by the JDataWriter application.

Such a file is usually called “KM3NET_00000001_00000002.root”, where the first number is the detector ID and the second the run number.

import km3io as ki

Accessing the event tree

Just pass a filename to the reader class and get access to the event tree with:

f = ki.OnlineReader("samples/km3net_online.root")

Note that only some meta information is read into memory.

Printing it will simply tell you how many events it has found. Again, nothing else is read yet:

print(f.events)

Out:

Number of events: 3

Now let’s look at the hits data:

print(f.events[0].snapshot_hits.tot)

Out:

[26 19 25 22 28 29 24 30 14 26 29 24 24 24 36 25 21 21 28 14 25 30 24 22
 16 23 29 29 37 31 26 27 12 25 22 22 22 27 23 13 35 30 23 27 23 29 28 17
 23 27 20 24 32 34 36 16 28 76  7 17 28 25 26 28 26 24 27 26 19 28 29 18
 23 29 27 22 27 12  9 27 22 24 28 12 20 28 24 25 12 20 23  6 10 29 28 27]

the resulting arrays are numpy arrays.

Reading SummarySlices

The following example shows how to access summary slices, in particular the DOM IDs of the slice with the index 0:

dom_ids = f.summaryslices.slices[0].dom_id

print(dom_ids)

Out:

[806451572 806455814 806465101 806483369 806487219 806487226 806487231
 808432835 808435278 808447180 808447186 808451904 808451907 808469129
 808472260 808472265 808488895 808488990 808489014 808489117 808493910
 808946818 808951460 808956908 808959411 808961448 808961480 808961504
 808961655 808964815 808964852 808969848 808969857 808972593 808972598
 808972698 808974758 808974773 808974811 808974972 808976377 808979567
 808979721 808979729 808981510 808981523 808981672 808981812 808981864
 808982018 808982041 808982077 808982547 808984711 808996773 808997793
 809006037 809007627 809503416 809521500 809524432 809526097 809544058
 809544061]

The .dtype attribute (or in general, <TAB> completion) is useful to find out more about the field structure:

print(f.summaryslices.headers.dtype)

Out:

[(' cnt', '<u4'), (' vers', '<u2'), (' cnt2', '<u4'), (' vers2', '<u2'), (' cnt3', '<u4'), (' vers3', '<u2'), ('detector_id', '<i4'), ('run', '<i4'), ('frame_index', '<i4'), (' cnt4', '<u4'), (' vers4', '<u2'), ('UTC_seconds', '<u4'), ('UTC_16nanosecondcycles', '<u4')]

To read the frame index:

print(f.summaryslices.headers.frame_index)

Out:

[126 127 128]

The resulting array is a ChunkedArray which is an extended version of a numpy array and behaves like one.

Reading TimeSlices

To be continued.

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

Estimated memory usage: 9 MB

Gallery generated by Sphinx-Gallery