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
from km3net_testdata import data_path

Accessing the event tree

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

f = ki.OnlineReader(data_path("online/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)
Number of events: 3

Now let’s look at the hits data:

print(f.events[0].snapshot_hits.tot)
[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. The current implementation of the summaryslice I/O uses a chunked reading for better performance, which means that when you iterate through the .slices, you’ll get chunks of summaryslices in each iteration instead of a single one.

In the example below, we simulate a single iteration by using the break keyword and then use the data which has been “pulled out” of the ROOT file.

for chunk in f.summaryslices:
    break

chunk now contains the first set of summaryslices so chunk.slice[0] refers to the first summaryslice in the ROOT file. To access e.g. the DOM IDs, use the .dom_id attribute

dom_ids = chunk.slices[0].dom_id

print(dom_ids)
[806451572, 806455814, 806465101, 806483369, ... 809526097, 809544058, 809544061]

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

print(chunk.slices.type)
3 * var * {"dom_id": int32, "dq_status": uint32, "hrv": uint32, "fifo": uint32, "status3": uint32, "status4": uint32, "ch0": uint8, "ch1": uint8, "ch2": uint8, "ch3": uint8, "ch4": uint8, "ch5": uint8, "ch6": uint8, "ch7": uint8, "ch8": uint8, "ch9": uint8, "ch10": uint8, "ch11": uint8, "ch12": uint8, "ch13": uint8, "ch14": uint8, "ch15": uint8, "ch16": uint8, "ch17": uint8, "ch18": uint8, "ch19": uint8, "ch20": uint8, "ch21": uint8, "ch22": uint8, "ch23": uint8, "ch24": uint8, "ch25": uint8, "ch26": uint8, "ch27": uint8, "ch28": uint8, "ch29": uint8, "ch30": uint8}

Similar to the summaryslice data, the headers can be accessed the same way To read the frame index of all summaryslices in the obtained chunk:

print(chunk.headers.frame_index)
[126, 127, 128]

To be continued…

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

Estimated memory usage: 9 MB

Gallery generated by Sphinx-Gallery