.. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_plot_dom_hits.py: ================== DOM hits. ================== Estimate track/DOM distances using the number of hits per DOM. .. image:: /auto_examples/images/sphx_glr_plot_dom_hits_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out Out: .. code-block:: none Loading style definitions from '/home/docs/checkouts/readthedocs.org/user_builds/km3pipe/conda/stable/lib/python3.5/site-packages/km3pipe/kp-data/stylelib/km3pipe.mplstyle' Detector: Parsing the DETX header Detector: Reading PMT information... Detector: Done. km3pipe.io.hdf5.HDF5Pump.HDF5Pump: Opening data/atmospheric_muons_sample.h5 Pipeline and module initialisation took 0.087s (CPU 0.030s). --------------------------[ Blob 100 ]--------------------------- --------------------------[ Blob 200 ]--------------------------- --------------------------[ Blob 300 ]--------------------------- --------------------------[ Blob 400 ]--------------------------- --------------------------[ Blob 500 ]--------------------------- ================================[ . ]================================ distance n_hits 0 91.942233 2 1 102.049055 1 2 40.741508 10 3 31.440725 10 4 24.587057 7 5 22.536263 9 6 26.431013 1 7 34.302613 4 8 44.069214 2 9 51.685196 2 10 100.397015 1 11 41.087020 3 12 62.607851 3 13 62.784801 1 14 837.073030 2 15 25.076556 2 16 21.508783 7 17 24.161485 3 18 31.500516 2 19 41.469520 2 20 30.938144 3 21 21.953858 6 22 17.150236 11 23 19.840485 16 24 27.937692 11 25 109.076917 2 26 101.322346 2 27 68.453759 2 28 42.055092 4 29 22.430258 5 ... ... ... 10003 82.207365 2 10004 22.966139 2 10005 7.525868 11 10006 38.005070 6 10007 34.325134 4 10008 29.461088 4 10009 50.150594 3 10010 32.454418 4 10011 30.079037 3 10012 29.033956 7 10013 47.733305 2 10014 58.684574 2 10015 54.514653 2 10016 46.042135 2 10017 39.849995 2 10018 47.899119 2 10019 53.290604 5 10020 60.909623 1 10021 31.300220 2 10022 68.615025 2 10023 69.396050 2 10024 42.843036 2 10025 87.527179 2 10026 35.125770 4 10027 72.235454 2 10028 31.671456 1 10029 51.261673 2 10030 55.623002 1 10031 46.319427 3 10032 61.987838 2 [10033 rows x 2 columns] ============================================================ 500 cycles drained in 17.043223s (CPU 7.320046s). Memory peak: 423.30 MB wall mean: 0.033542s medi: 0.021250s min: 0.004386s max: 5.033129s std: 0.224743s CPU mean: 0.014449s medi: 0.009318s min: 0.004353s max: 2.261111s std: 0.100644s | .. code-block:: python from __future__ import absolute_import, print_function, division # Author: Tamas Gal # License: BSD-3 from collections import defaultdict, Counter import numpy as np import pandas as pd import matplotlib.pyplot as plt from matplotlib.colors import LogNorm import km3pipe as kp from km3pipe.dataclasses import Table from km3pipe.math import pld3 from km3modules.common import StatusBar import km3pipe.style km3pipe.style.use("km3pipe") filename = "data/atmospheric_muons_sample.h5" cal = kp.calib.Calibration(filename="data/KM3NeT_-00000001_20171212.detx") def filter_muons(blob): """Write all muons from McTracks to Muons.""" tracks = blob['McTracks'] muons = tracks[tracks.type == -13] # PDG particle code blob["Muons"] = Table(muons) return blob class DOMHits(kp.Module): """Create histogram with n_hits and distance of hit to track.""" def configure(self): self.hit_statistics = defaultdict(list) def process(self, blob): hits = blob['Hits'] muons = blob['Muons'] highest_energetic_muon = Table(muons[np.argmax(muons.energy)]) muon = highest_energetic_muon triggered_hits = hits.triggered_rows dom_hits = Counter(triggered_hits.dom_id) for dom_id, n_hits in dom_hits.items(): try: distance = pld3( cal.detector.dom_positions[dom_id], muon.pos, muon.dir ) except KeyError: self.log.warning("DOM ID %s not found!" % dom_id) continue self.hit_statistics['n_hits'].append(n_hits) self.hit_statistics['distance'].append(distance) return blob def finish(self): df = pd.DataFrame(self.hit_statistics) print(df) sdf = df[(df['distance'] < 200) & (df['n_hits'] < 50)] bins = (max(sdf['distance']) - 1, max(sdf['n_hits']) - 1) plt.hist2d( sdf['distance'], sdf['n_hits'], cmap='plasma', bins=bins, norm=LogNorm() ) plt.xlabel('Distance between hit and muon track [m]') plt.ylabel('Number of hits on DOM') plt.show() pipe = kp.Pipeline() pipe.attach(kp.io.HDF5Pump, filename=filename) pipe.attach(StatusBar, every=100) pipe.attach(filter_muons) pipe.attach(DOMHits) pipe.drain() **Total running time of the script:** ( 0 minutes 37.289 seconds) .. _sphx_glr_download_auto_examples_plot_dom_hits.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download :download:`Download Python source code: plot_dom_hits.py ` .. container:: sphx-glr-download :download:`Download Jupyter notebook: plot_dom_hits.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_