Reading Offline hits

The following example shows how to access hits 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

To access offline hits/mc_hits data:

mc_hits = ki.OfflineReader("samples/numucc.root").events.mc_hits
hits = ki.OfflineReader("samples/km3net_offline.root").events.hits

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

print(hits)

Out:

OfflineBranch (hits) with 10 elements

same for mc hits

print(mc_hits)

Out:

OfflineBranch (mc_hits) with 10 elements

Accessing the hits/mc_hits keys

to explore the hits keys:

keys = hits.keys()
print(keys)

Out:

dict_keys(['pos_y', 'dir_y', 'trig', 'pos_x', 'channel_id', 'pure_t', 'type', 'tdc', 'tot', 'id', 'dir_z', 'pos_z', 'dir_x', 'dom_id', 'pattern_flags', 't'])

to explore the mc_hits keys:

mc_keys = mc_hits.keys()
print(mc_keys)

Out:

dict_keys(['type', 'usr_names', 'pattern_flags', 'pos_y', 'origin', 'a', 'pure_a', 'pure_t', 't', 'dir_z', 'pmt_id', 'dir_y', 'dir_x', 'pos_x', 'pos_z', 'id'])

Accessing hits data

to access data in dom_id:

dom_ids = hits.dom_id
print(dom_ids)

Out:

[[806451572 806451572 806451572 ... 809544061 809544061 809544061] [806451572 806451572 806451572 ... 809524432 809526097 809544061] [806451572 806451572 806451572 ... 809544061 809544061 809544061] ... [806451572 806455814 806465101 ... 809526097 809544058 809544061] [806455814 806455814 806455814 ... 809544061 809544061 809544061] [806455814 806455814 806455814 ... 809544058 809544058 809544061]]

to access the channel ids:

channel_ids = hits.channel_id
print(channel_ids)

Out:

[[8 9 14 ... 5 7 26] [22 16 16 ... 15 6 17] [9 27 0 ... 2 7 11] ... [3 26 26 ... 0 12 12] [27 5 13 ... 15 17 19] [1 2 3 ... 10 11 0]]

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

Accessing the mc_hits data

similarly, you can access mc_hits data in any key of interest by following the same procedure as for hits:

mc_pmt_ids = mc_hits.pmt_id
print(mc_pmt_ids)

Out:

[[677 687 689 ... 115501 115613 115619] [15507 15509 15561 ... 102259 102379 102401] [103417 103423 103425 ... 103677 103677 103685] ... [36591 36619 36621 ... 116797 116797 116805] [799 1687 1811 ... 105741 105741 105769] [16147 25313 25317 ... 103641 103641 103695]]

to access the mc_hits time:

mc_t = mc_hits.t
print(mc_t)

Out:

[[2128.702998731661 2062.772153901148 2061.6887296192476 ... 155.88040924475436 463.3581477976378 458.5734164952344] [1332.412502419935 1334.1885280505683 1377.6012379206886 ... 683.1870083887352 529.0759430636384 503.47264946347167] [1571.9241524308304 1572.4602613256027 1571.9791446996503 ... 1170.7994191361904 1171.1814215223837 1175.0892505145878] ... [1585.8419308390314 1872.3878114680522 1576.246595372566 ... 136.61437723706516 137.01688046067602 139.0889917897132] [1671.9530305120354 1887.8385781657973 1592.6855002954326 ... 528.6011720312038 605.3713541320684 528.123785408378] [2643.2774684433884 904.2188499473267 909.8721470965456 ... 353.7748742780894 498.0783969698712 416.89402505183523]]

item selection in hits data

hits data can be selected as you would select an item from a numpy array. for example, to select DOM ids in the hits corresponding to the first event:

print(hits[0].dom_id)

Out:

[806451572 806451572 806451572 806451572 806455814 806455814 806455814
 806483369 806483369 806483369 806483369 806483369 806483369 806483369
 806483369 806483369 806483369 806487219 806487226 806487231 806487231
 808432835 808435278 808435278 808435278 808435278 808435278 808447180
 808447180 808447180 808447180 808447180 808447180 808447180 808447180
 808447186 808451904 808451904 808472265 808472265 808472265 808472265
 808472265 808472265 808472265 808472265 808488895 808488990 808488990
 808488990 808488990 808488990 808489014 808489014 808489117 808489117
 808489117 808489117 808493910 808946818 808949744 808951460 808951460
 808951460 808951460 808951460 808956908 808956908 808959411 808959411
 808959411 808961448 808961448 808961504 808961504 808961655 808961655
 808961655 808964815 808964815 808964852 808964908 808969857 808969857
 808969857 808969857 808969857 808972593 808972698 808972698 808972698
 808974758 808974758 808974758 808974758 808974758 808974758 808974758
 808974758 808974758 808974758 808974758 808974773 808974773 808974773
 808974773 808974773 808974972 808974972 808976377 808976377 808976377
 808979567 808979567 808979567 808979721 808979721 808979721 808979721
 808979721 808979721 808979721 808979729 808979729 808979729 808981510
 808981510 808981510 808981510 808981672 808981672 808981672 808981672
 808981672 808981672 808981672 808981672 808981672 808981672 808981672
 808981672 808981672 808981672 808981672 808981672 808981672 808981812
 808981812 808981812 808981864 808981864 808982005 808982005 808982005
 808982018 808982018 808982018 808982041 808982041 808982077 808982077
 808982547 808982547 808982547 808997793 809006037 809524432 809526097
 809526097 809544061 809544061 809544061 809544061 809544061 809544061
 809544061]

or:

print(hits.dom_id[0])

Out:

[806451572 806451572 806451572 806451572 806455814 806455814 806455814
 806483369 806483369 806483369 806483369 806483369 806483369 806483369
 806483369 806483369 806483369 806487219 806487226 806487231 806487231
 808432835 808435278 808435278 808435278 808435278 808435278 808447180
 808447180 808447180 808447180 808447180 808447180 808447180 808447180
 808447186 808451904 808451904 808472265 808472265 808472265 808472265
 808472265 808472265 808472265 808472265 808488895 808488990 808488990
 808488990 808488990 808488990 808489014 808489014 808489117 808489117
 808489117 808489117 808493910 808946818 808949744 808951460 808951460
 808951460 808951460 808951460 808956908 808956908 808959411 808959411
 808959411 808961448 808961448 808961504 808961504 808961655 808961655
 808961655 808964815 808964815 808964852 808964908 808969857 808969857
 808969857 808969857 808969857 808972593 808972698 808972698 808972698
 808974758 808974758 808974758 808974758 808974758 808974758 808974758
 808974758 808974758 808974758 808974758 808974773 808974773 808974773
 808974773 808974773 808974972 808974972 808976377 808976377 808976377
 808979567 808979567 808979567 808979721 808979721 808979721 808979721
 808979721 808979721 808979721 808979729 808979729 808979729 808981510
 808981510 808981510 808981510 808981672 808981672 808981672 808981672
 808981672 808981672 808981672 808981672 808981672 808981672 808981672
 808981672 808981672 808981672 808981672 808981672 808981672 808981812
 808981812 808981812 808981864 808981864 808982005 808982005 808982005
 808982018 808982018 808982018 808982041 808982041 808982077 808982077
 808982547 808982547 808982547 808997793 809006037 809524432 809526097
 809526097 809544061 809544061 809544061 809544061 809544061 809544061
 809544061]

slicing of hits

to select a slice of hits data:

print(hits[0:3].channel_id)

Out:

[[8 9 14 ... 5 7 26] [22 16 16 ... 15 6 17] [9 27 0 ... 2 7 11]]

or:

print(hits.channel_id[0:3])

Out:

[[8 9 14 ... 5 7 26] [22 16 16 ... 15 6 17] [9 27 0 ... 2 7 11]]

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

mask = hits.channel_id > 10

print(hits.channel_id[mask])

Out:

[[14, 18, 23, 27, 29, 11, 15, 17, 23, 27, ... 29, 17, 30, 24, 25, 19, 12, 19, 11]]

or:

print(hits.dom_id[mask])

Out:

[[806451572, 806451572, 806455814, 806483369, ... 809521500, 809521500, 809544058]]

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

Estimated memory usage: 9 MB

Gallery generated by Sphinx-Gallery