{ "cells": [ { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "# Add file to current python path\n", "from pathlib import Path\n", "import sys\n", "sys.path.append(str(Path.cwd().parent))\n", "Path.cwd()\n", "\n", "# test samples directory - aanet test file\n", "files_path = Path.cwd().parent / 'tests/samples' \n", "aanet_file = files_path / 'aanet_v2.0.0.root'" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Read offline files (aanet)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "<km3io.aanet.OfflineReader at 0x7f756b8edd90>" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import km3io as ki\n", "r = ki.OfflineReader(aanet_file)\n", "r" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To explore all the available branches in our offline file:" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Events keys are:\n", "\tid\n", "\tdet_id\n", "\tmc_id\n", "\trun_id\n", "\tmc_run_id\n", "\tframe_index\n", "\ttrigger_mask\n", "\ttrigger_counter\n", "\toverlays\n", "\thits\n", "\ttrks\n", "\tw\n", "\tw2list\n", "\tw3list\n", "\tmc_t\n", "\tmc_hits\n", "\tmc_trks\n", "\tcomment\n", "\tindex\n", "\tflags\n", "\tt.fSec\n", "\tt.fNanoSec\n", "Hits keys are:\n", "\thits.id\n", "\thits.dom_id\n", "\thits.channel_id\n", "\thits.tdc\n", "\thits.tot\n", "\thits.trig\n", "\thits.pmt_id\n", "\thits.t\n", "\thits.a\n", "\thits.pos.x\n", "\thits.pos.y\n", "\thits.pos.z\n", "\thits.dir.x\n", "\thits.dir.y\n", "\thits.dir.z\n", "\thits.pure_t\n", "\thits.pure_a\n", "\thits.type\n", "\thits.origin\n", "\thits.pattern_flags\n", "Tracks keys are:\n", "\ttrks.fUniqueID\n", "\ttrks.fBits\n", "\ttrks.id\n", "\ttrks.pos.x\n", "\ttrks.pos.y\n", "\ttrks.pos.z\n", "\ttrks.dir.x\n", "\ttrks.dir.y\n", "\ttrks.dir.z\n", "\ttrks.t\n", "\ttrks.E\n", "\ttrks.len\n", "\ttrks.lik\n", "\ttrks.type\n", "\ttrks.rec_type\n", "\ttrks.rec_stages\n", "\ttrks.status\n", "\ttrks.mother_id\n", "\ttrks.fitinf\n", "\ttrks.hit_ids\n", "\ttrks.error_matrix\n", "\ttrks.comment\n", "Mc hits keys are:\n", "\tmc_hits.id\n", "\tmc_hits.dom_id\n", "\tmc_hits.channel_id\n", "\tmc_hits.tdc\n", "\tmc_hits.tot\n", "\tmc_hits.trig\n", "\tmc_hits.pmt_id\n", "\tmc_hits.t\n", "\tmc_hits.a\n", "\tmc_hits.pos.x\n", "\tmc_hits.pos.y\n", "\tmc_hits.pos.z\n", "\tmc_hits.dir.x\n", "\tmc_hits.dir.y\n", "\tmc_hits.dir.z\n", "\tmc_hits.pure_t\n", "\tmc_hits.pure_a\n", "\tmc_hits.type\n", "\tmc_hits.origin\n", "\tmc_hits.pattern_flags\n", "Mc tracks keys are:\n", "\tmc_trks.fUniqueID\n", "\tmc_trks.fBits\n", "\tmc_trks.id\n", "\tmc_trks.pos.x\n", "\tmc_trks.pos.y\n", "\tmc_trks.pos.z\n", "\tmc_trks.dir.x\n", "\tmc_trks.dir.y\n", "\tmc_trks.dir.z\n", "\tmc_trks.t\n", "\tmc_trks.E\n", "\tmc_trks.len\n", "\tmc_trks.lik\n", "\tmc_trks.type\n", "\tmc_trks.rec_type\n", "\tmc_trks.rec_stages\n", "\tmc_trks.status\n", "\tmc_trks.mother_id\n", "\tmc_trks.fitinf\n", "\tmc_trks.hit_ids\n", "\tmc_trks.error_matrix\n", "\tmc_trks.comment" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "r.keys" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# read events data" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "<OfflineEvents: 10 parsed events>" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "r.events" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "number of events:" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "10" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "len(r.events)" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "<ChunkedArray [1 2 3 ... 8 9 10] at 0x7f249eeb6f10>" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "r.events.id" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "<ChunkedArray [44 44 44 ... 44 44 44] at 0x7f249eeba050>" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "r.events.det_id" ] }, { "cell_type": "code", "execution_count": 23, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "<ChunkedArray [182 183 202 ... 185 185 204] at 0x7f249eeba410>" ] }, "execution_count": 23, "metadata": {}, "output_type": "execute_result" } ], "source": [ "r.events.frame_index" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "<ChunkedArray [176 125 318 ... 84 255 105] at 0x7f756b805ad0>" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "r.events.hits" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "lazyarrays can be used with any Numpy universal function. For example:" ] }, { "cell_type": "code", "execution_count": 33, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "<ChunkedArray [5.170483995038151 4.8283137373023015 5.762051382780177 ... 4.430816798843313 5.541263545158426 4.653960350157523] at 0x7f249b8ebb90>" ] }, "execution_count": 33, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import numpy as np\n", "np.log(r.events.hits)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "let's look at event 0:" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "offline event:\n", "\tid : 1\n", "\tdet_id : 44\n", "\tmc_id : 0\n", "\trun_id : 5971\n", "\tmc_run_id : 0\n", "\tframe_index : 182\n", "\ttrigger_mask : 22\n", "\ttrigger_counter : 0\n", "\toverlays : 60\n", "\thits : 176\n", "\ttrks : 56\n", "\tw : []\n", "\tw2list : []\n", "\tw3list : []\n", "\tmc_t : 0.0\n", "\tmc_hits : 0\n", "\tmc_trks : 0\n", "\tcomment : b''\n", "\tindex : 0\n", "\tflags : 0\n", "\tt_fSec : 1567036818\n", "\tt_fNanoSec : 200000000" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "r.events[0]" ] }, { "cell_type": "code", "execution_count": 47, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "60" ] }, "execution_count": 47, "metadata": {}, "output_type": "execute_result" } ], "source": [ "r.events[0].overlays" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "176" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "r.events[0].hits" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# read hits data:" ] }, { "cell_type": "code", "execution_count": 56, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "<ChunkedArray [[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]] at 0x7f249eebac50>" ] }, "execution_count": 56, "metadata": {}, "output_type": "execute_result" } ], "source": [ "r.hits.dom_id" ] }, { "cell_type": "code", "execution_count": 61, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "<ChunkedArray [[24 30 22 ... 38 26 23] [29 26 22 ... 26 28 24] [27 19 13 ... 27 24 16] ... [22 22 9 ... 27 32 27] [30 32 17 ... 30 24 29] [27 41 36 ... 29 24 28]] at 0x7f249eec9050>" ] }, "execution_count": 61, "metadata": {}, "output_type": "execute_result" } ], "source": [ "r.hits.tot" ] }, { "cell_type": "code", "execution_count": 62, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "<OfflineHits: 176 parsed elements>" ] }, "execution_count": 62, "metadata": {}, "output_type": "execute_result" } ], "source": [ "r[0].hits" ] }, { "cell_type": "code", "execution_count": 68, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([806451572, 806451572, 806451572, 806451572, 806455814, 806455814,\n", " 806455814, 806483369, 806483369, 806483369, 806483369, 806483369,\n", " 806483369, 806483369, 806483369, 806483369, 806483369, 806487219,\n", " 806487226, 806487231, 806487231, 808432835, 808435278, 808435278,\n", " 808435278, 808435278, 808435278, 808447180, 808447180, 808447180,\n", " 808447180, 808447180, 808447180, 808447180, 808447180, 808447186,\n", " 808451904, 808451904, 808472265, 808472265, 808472265, 808472265,\n", " 808472265, 808472265, 808472265, 808472265, 808488895, 808488990,\n", " 808488990, 808488990, 808488990, 808488990, 808489014, 808489014,\n", " 808489117, 808489117, 808489117, 808489117, 808493910, 808946818,\n", " 808949744, 808951460, 808951460, 808951460, 808951460, 808951460,\n", " 808956908, 808956908, 808959411, 808959411, 808959411, 808961448,\n", " 808961448, 808961504, 808961504, 808961655, 808961655, 808961655,\n", " 808964815, 808964815, 808964852, 808964908, 808969857, 808969857,\n", " 808969857, 808969857, 808969857, 808972593, 808972698, 808972698,\n", " 808972698, 808974758, 808974758, 808974758, 808974758, 808974758,\n", " 808974758, 808974758, 808974758, 808974758, 808974758, 808974758,\n", " 808974773, 808974773, 808974773, 808974773, 808974773, 808974972,\n", " 808974972, 808976377, 808976377, 808976377, 808979567, 808979567,\n", " 808979567, 808979721, 808979721, 808979721, 808979721, 808979721,\n", " 808979721, 808979721, 808979729, 808979729, 808979729, 808981510,\n", " 808981510, 808981510, 808981510, 808981672, 808981672, 808981672,\n", " 808981672, 808981672, 808981672, 808981672, 808981672, 808981672,\n", " 808981672, 808981672, 808981672, 808981672, 808981672, 808981672,\n", " 808981672, 808981672, 808981812, 808981812, 808981812, 808981864,\n", " 808981864, 808982005, 808982005, 808982005, 808982018, 808982018,\n", " 808982018, 808982041, 808982041, 808982077, 808982077, 808982547,\n", " 808982547, 808982547, 808997793, 809006037, 809524432, 809526097,\n", " 809526097, 809544061, 809544061, 809544061, 809544061, 809544061,\n", " 809544061, 809544061], dtype=int32)" ] }, "execution_count": 68, "metadata": {}, "output_type": "execute_result" } ], "source": [ "r[0].hits.dom_id" ] }, { "cell_type": "code", "execution_count": 74, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "offline hit:\n", "\tid : 0\n", "\tdom_id : 806451572\n", "\tchannel_id : 8\n", "\ttdc : 0\n", "\ttot : 24\n", "\ttrig : 1\n", "\tpmt_id : 0\n", "\tt : 70104010.0\n", "\ta : 0.0\n", "\tpos_x : 0.0\n", "\tpos_y : 0.0\n", "\tpos_z : 0.0\n", "\tdir_x : 0.0\n", "\tdir_y : 0.0\n", "\tdir_z : 0.0\n", "\tpure_t : 0.0\n", "\tpure_a : 0.0\n", "\ttype : 0\n", "\torigin : 0\n", "\tpattern_flags : 0" ] }, "execution_count": 74, "metadata": {}, "output_type": "execute_result" } ], "source": [ "r[0].hits[0]" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "806451572" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "r[0].hits[0].dom_id" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# read tracks data:" ] }, { "cell_type": "code", "execution_count": 77, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "<OfflineTracks: 10 parsed elements>" ] }, "execution_count": 77, "metadata": {}, "output_type": "execute_result" } ], "source": [ "r.tracks" ] }, { "cell_type": "code", "execution_count": 79, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "<ChunkedArray [[294.6407542676734 294.6407542676734 294.6407542676734 ... 67.81221253265059 67.7756405143316 67.77250505700384] [96.75133289411137 96.75133289411137 96.75133289411137 ... 39.21916536442286 39.184645826013806 38.870325146341884] [560.2775306614813 560.2775306614813 560.2775306614813 ... 118.88577278801066 118.72271313687405 117.80785995187605] ... [71.03251451148226 71.03251451148226 71.03251451148226 ... 16.714140573909347 16.444395245214945 16.34639241716669] [326.440133294878 326.440133294878 326.440133294878 ... 87.79818671079849 87.75488082571873 87.74839444768625] [159.77779654216795 159.77779654216795 159.77779654216795 ... 33.8669134999348 33.821631538334984 33.77240735670646]] at 0x7f249eed2590>" ] }, "execution_count": 79, "metadata": {}, "output_type": "execute_result" } ], "source": [ "r.tracks.lik" ] }, { "cell_type": "code", "execution_count": 80, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "<OfflineTracks: 56 parsed elements>" ] }, "execution_count": 80, "metadata": {}, "output_type": "execute_result" } ], "source": [ "r[0].tracks" ] }, { "cell_type": "code", "execution_count": 81, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([294.64075427, 294.64075427, 294.64075427, 291.64653113,\n", " 291.27392663, 290.69031512, 289.19290546, 289.08449217,\n", " 289.03373947, 288.19030836, 282.92343367, 282.71527118,\n", " 282.10762402, 280.20553861, 275.93183966, 273.01809111,\n", " 257.46433694, 220.94357656, 194.99426403, 190.47809685,\n", " 79.95235686, 78.94389763, 78.90791169, 77.96122466,\n", " 77.9579604 , 76.90769883, 75.97546175, 74.91530508,\n", " 74.9059469 , 72.94007716, 72.90467038, 72.8629316 ,\n", " 72.81280833, 72.80229533, 72.78899435, 71.82404165,\n", " 71.80085542, 71.71028058, 70.91130096, 70.89150223,\n", " 70.85845637, 70.79081796, 70.76929743, 69.80667603,\n", " 69.64058976, 68.93085058, 68.84304037, 68.83154232,\n", " 68.79944298, 68.79019375, 68.78581291, 68.72340328,\n", " 67.86628937, 67.81221253, 67.77564051, 67.77250506])" ] }, "execution_count": 81, "metadata": {}, "output_type": "execute_result" } ], "source": [ "r[0].tracks.lik" ] }, { "cell_type": "code", "execution_count": 83, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "offline track:\n", "\tfUniqueID : 0\n", "\tfBits : 33554432\n", "\tid : 1\n", "\tpos_x : 445.835395997812\n", "\tpos_y : 615.1089636184813\n", "\tpos_z : 125.1448339836911\n", "\tdir_x : 0.0368711082700674\n", "\tdir_y : -0.48653048395923415\n", "\tdir_z : -0.872885221293917\n", "\tt : 70311446.46401498\n", "\tE : 99.10458562488608\n", "\tlen : 0.0\n", "\tlik : 294.6407542676734\n", "\ttype : 0\n", "\trec_type : 4000\n", "\trec_stages : [1, 3, 5, 4]\n", "\tstatus : 0\n", "\tmother_id : -1\n", "\thit_ids : []\n", "\terror_matrix : []\n", "\tcomment : 0\n", "\tJGANDALF_BETA0_RAD : 0.004957442219414389\n", "\tJGANDALF_BETA1_RAD : 0.003417848024252858\n", "\tJGANDALF_CHI2 : -294.6407542676734\n", "\tJGANDALF_NUMBER_OF_HITS : 142.0\n", "\tJENERGY_ENERGY : 99.10458562488608\n", "\tJENERGY_CHI2 : 1.7976931348623157e+308\n", "\tJGANDALF_LAMBDA : 4.2409761837248484e-12\n", "\tJGANDALF_NUMBER_OF_ITERATIONS : 10.0\n", "\tJSTART_NPE_MIP : 24.88469697331908\n", "\tJSTART_NPE_MIP_TOTAL : 55.88169412579765\n", "\tJSTART_LENGTH_METRES : 98.89582506402911\n", "\tJVETO_NPE : 0.0\n", "\tJVETO_NUMBER_OF_HITS : 0.0\n", "\tJENERGY_MUON_RANGE_METRES : 344.9767431592819\n", "\tJENERGY_NOISE_LIKELIHOOD : -333.87773581129136\n", "\tJENERGY_NDF : 1471.0\n", "\tJENERGY_NUMBER_OF_HITS : 101.0" ] }, "execution_count": 83, "metadata": {}, "output_type": "execute_result" } ], "source": [ "r[0].tracks[0]" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "294.6407542676734" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "r[0].tracks[0].lik" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# read mc hits:" ] }, { "cell_type": "code", "execution_count": 86, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "<OfflineHits: 10 parsed elements>" ] }, "execution_count": 86, "metadata": {}, "output_type": "execute_result" } ], "source": [ "r.mc_hits" ] }, { "cell_type": "code", "execution_count": 87, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "<OfflineTracks: 10 parsed elements>" ] }, "execution_count": 87, "metadata": {}, "output_type": "execute_result" } ], "source": [ "r.mc_tracks" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.4" } }, "nbformat": 4, "nbformat_minor": 4 }