

.. _sphx_glr_auto_examples_plot_pmt_directions.py:



==================
PMT Directions
==================

Plot the PMT directions for a given DOM.




.. code-block:: python

    from __future__ import absolute_import, print_function, division

    # Author: Tamas Gal <tgal@km3net.de>
    # License: BSD-3
    from mpl_toolkits.mplot3d import axes3d
    import matplotlib.pyplot as plt

    import km3pipe as kp
    import km3pipe.style
    km3pipe.style.use('km3pipe')
    km3pipe.style.use('talk')

    DETX = 'data/orca_115strings_av23min20mhorizontal_18OMs_alt9mvertical_v1.detx'

    det = kp.hardware.Detector(DETX)





.. rst-class:: sphx-glr-script-out

 Out::

    Loading style definitions from '/Users/tamasgal/Dev/km3pipe/km3pipe/kp-data/stylelib/km3pipe.mplstyle'
    Loading style definitions from '/Users/tamasgal/Dev/km3pipe/km3pipe/kp-data/stylelib/km3pipe-talk.mplstyle'
    Detector: Parsing the DETX header
    Detector: Reading PMT information...
    Detector: Done.


Alternatively, you can use the `det_id` to retrieve the geometry from the DB.



.. code-block:: python


    # det = kp.hardware.Detector(det_id=29)







Let's take the first DOM ID



.. code-block:: python

    dom_id = det.dom_ids[0]







...and get the table of the PMTs in the chosen DOM:



.. code-block:: python


    pmts = det.pmts[det.pmts.dom_id == dom_id]







The `quiver` function can directly plot the PMT data, since those are
stored as numpy arrays.



.. code-block:: python

    fig = plt.figure()
    ax = fig.gca(projection='3d')

    ax.quiver(
        pmts.pos_x,
        pmts.pos_y,
        pmts.pos_z,
        pmts.dir_x,
        pmts.dir_y,
        pmts.dir_z,
        length=0.1)

    ax.set_xlabel("x [m]")
    ax.set_ylabel("y [m]")
    ax.set_zlabel("z [m]")

    ax.set_title("PMT directions on DOM {}".format(dom_id))



.. image:: /auto_examples/images/sphx_glr_plot_pmt_directions_001.png
    :align: center




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



.. only :: html

 .. container:: sphx-glr-footer


  .. container:: sphx-glr-download

     :download:`Download Python source code: plot_pmt_directions.py <plot_pmt_directions.py>`



  .. container:: sphx-glr-download

     :download:`Download Jupyter notebook: plot_pmt_directions.ipynb <plot_pmt_directions.ipynb>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.readthedocs.io>`_
