.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plot_offline_tracks.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_plot_offline_tracks.py: Reading Offline tracks ====================== The following example shows how to access tracks data in an offline ROOT file. Note: the offline files used here were intentionaly reduced to 10 events. .. GENERATED FROM PYTHON SOURCE LINES 9-13 .. code-block:: Python import km3io as ki from km3net_testdata import data_path .. GENERATED FROM PYTHON SOURCE LINES 14-15 We open the file using the .. GENERATED FROM PYTHON SOURCE LINES 15-18 .. code-block:: Python f = ki.OfflineReader(data_path("offline/numucc.root")) .. GENERATED FROM PYTHON SOURCE LINES 19-20 To access offline tracks/mc_tracks data: .. GENERATED FROM PYTHON SOURCE LINES 20-24 .. code-block:: Python f.tracks f.mc_tracks .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 25-28 Note that no data is loaded in memory at this point, so printing tracks will only return how many sub-branches (corresponding to events) were found. .. GENERATED FROM PYTHON SOURCE LINES 28-31 .. code-block:: Python f.tracks .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 32-33 same for mc hits .. GENERATED FROM PYTHON SOURCE LINES 33-36 .. code-block:: Python f.mc_tracks .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 37-40 Accessing the tracks/mc_tracks keys ----------------------------------- to explore the reconstructed tracks fields: .. GENERATED FROM PYTHON SOURCE LINES 40-43 .. code-block:: Python f.tracks.fields .. rst-class:: sphx-glr-script-out .. code-block:: none ['id', 'pos_x', 'pos_y', 'pos_z', 'dir_x', 'dir_y', 'dir_z', 't', 'E', 'len', 'lik', 'rec_type', 'rec_stages', 'fitinf'] .. GENERATED FROM PYTHON SOURCE LINES 44-45 the same for MC tracks .. GENERATED FROM PYTHON SOURCE LINES 45-48 .. code-block:: Python f.mc_tracks.fields .. rst-class:: sphx-glr-script-out .. code-block:: none ['id', 'pos_x', 'pos_y', 'pos_z', 'dir_x', 'dir_y', 'dir_z', 'E', 't', 'len', 'pdgid', 'hit_ids', 'usr', 'usr_names'] .. GENERATED FROM PYTHON SOURCE LINES 49-53 Accessing tracks data --------------------- each field will return a nested `awkward.Array` and load everything into memory, so be careful if you are working with larger files. .. GENERATED FROM PYTHON SOURCE LINES 53-56 .. code-block:: Python f.tracks.E .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 57-58 The z direction of all reconstructed tracks .. GENERATED FROM PYTHON SOURCE LINES 58-61 .. code-block:: Python f.tracks.dir_z .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 62-63 The likelihoods .. GENERATED FROM PYTHON SOURCE LINES 63-67 .. code-block:: Python f.tracks.lik .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 68-71 To select just a single event or a subset of events, use the indices or slices. The following will access all tracks and their fields of the third event (0 is the first): .. GENERATED FROM PYTHON SOURCE LINES 71-74 .. code-block:: Python f[2].tracks .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 75-76 The z direction of all tracks in the third event: .. GENERATED FROM PYTHON SOURCE LINES 76-80 .. code-block:: Python f[2].tracks.dir_z .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 81-83 while here, we select the first 3 events. Notice that all fields will return nested arrays, as we have seem above where all events were selected. .. GENERATED FROM PYTHON SOURCE LINES 83-86 .. code-block:: Python f[:3] .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 87-88 All tracks for the first three events .. GENERATED FROM PYTHON SOURCE LINES 88-91 .. code-block:: Python f[:3].tracks .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 92-93 The z directions of all tracks of the first three events .. GENERATED FROM PYTHON SOURCE LINES 93-96 .. code-block:: Python f[:3].tracks.dir_z .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 97-98 or events from 3 and 5 (again, 0 indexing): .. GENERATED FROM PYTHON SOURCE LINES 98-102 .. code-block:: Python f[2:5] .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 103-104 the tracks of those events .. GENERATED FROM PYTHON SOURCE LINES 104-107 .. code-block:: Python f[2:5].tracks .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 108-109 and just the z directions of those .. GENERATED FROM PYTHON SOURCE LINES 109-111 .. code-block:: Python f[2:5].tracks.dir_z .. rst-class:: sphx-glr-script-out .. code-block:: none .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 5.365 seconds) **Estimated memory usage:** 9 MB .. _sphx_glr_download_auto_examples_plot_offline_tracks.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_offline_tracks.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_offline_tracks.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_