.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/tutorials/theta_square.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_tutorials_theta_square.py: Make a theta-square plot ======================== This is a basic example to analyze some events and make a :math:`\Theta^2` plot .. GENERATED FROM PYTHON SOURCE LINES 9-23 .. code-block:: Python :lineno-start: 10 # %matplotlib inline import matplotlib.pyplot as plt import numpy as np from astropy import units as u from astropy.coordinates import angular_separation from tqdm.auto import tqdm from ctapipe.calib import CameraCalibrator from ctapipe.image import ImageProcessor from ctapipe.io import EventSource from ctapipe.reco import ShowerProcessor .. GENERATED FROM PYTHON SOURCE LINES 24-26 Get source events in MC dataset. .. GENERATED FROM PYTHON SOURCE LINES 26-59 .. code-block:: Python :lineno-start: 27 source = EventSource( "dataset://gamma_prod5.simtel.zst", # allowed_tels={1, 2, 3, 4}, ) subarray = source.subarray calib = CameraCalibrator(subarray=subarray) image_processor = ImageProcessor(subarray=subarray) shower_processor = ShowerProcessor(subarray=subarray) off_angles = [] for event in tqdm(source): # calibrating the event calib(event) image_processor(event) shower_processor(event) reco_result = event.dl2.stereo.geometry["HillasReconstructor"] # get angular offset between reconstructed shower direction and MC # generated shower direction true_shower = event.simulation.shower off_angle = angular_separation( true_shower.az, true_shower.alt, reco_result.az, reco_result.alt ) # Appending all estimated off angles off_angles.append(off_angle.to(u.deg).value) .. rst-class:: sphx-glr-script-out .. code-block:: none 0it [00:00, ?it/s] 2it [00:00, 8.49it/s] 4it [00:00, 9.62it/s] 5it [00:00, 6.05it/s] 7it [00:00, 8.43it/s] 7it [00:00, 8.07it/s] .. GENERATED FROM PYTHON SOURCE LINES 60-62 calculate theta square for angles which are not nan .. GENERATED FROM PYTHON SOURCE LINES 62-67 .. code-block:: Python :lineno-start: 63 off_angles = np.array(off_angles) thetasquare = off_angles[np.isfinite(off_angles)] ** 2 .. GENERATED FROM PYTHON SOURCE LINES 68-71 Plot the results ---------------- .. GENERATED FROM PYTHON SOURCE LINES 71-76 .. code-block:: Python :lineno-start: 72 plt.hist(thetasquare, bins=10, range=[0, 0.4]) plt.xlabel(r"$\theta^2$ (deg)") plt.ylabel("# of events") plt.show() .. image-sg:: /auto_examples/tutorials/images/sphx_glr_theta_square_001.png :alt: theta square :srcset: /auto_examples/tutorials/images/sphx_glr_theta_square_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 2.641 seconds) .. _sphx_glr_download_auto_examples_tutorials_theta_square.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: theta_square.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: theta_square.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: theta_square.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_