Note
Go to the end to download the full example code.
Make a theta-square plot#
This is a basic example to analyze some events and make a \(\Theta^2\) plot
10 # %matplotlib inline
11
12 import matplotlib.pyplot as plt
13 import numpy as np
14 from astropy import units as u
15 from astropy.coordinates import angular_separation
16 from tqdm.auto import tqdm
17
18 from ctapipe.calib import CameraCalibrator
19 from ctapipe.image import ImageProcessor
20 from ctapipe.io import EventSource
21 from ctapipe.reco import ShowerProcessor
Get source events in MC dataset.
27 source = EventSource(
28 "dataset://gamma_prod5.simtel.zst",
29 # allowed_tels={1, 2, 3, 4},
30 )
31
32 subarray = source.subarray
33
34 calib = CameraCalibrator(subarray=subarray)
35 image_processor = ImageProcessor(subarray=subarray)
36 shower_processor = ShowerProcessor(subarray=subarray)
37
38 off_angles = []
39
40 for event in tqdm(source):
41 # calibrating the event
42 calib(event)
43 image_processor(event)
44 shower_processor(event)
45
46 reco_result = event.dl2.stereo.geometry["HillasReconstructor"]
47
48 # get angular offset between reconstructed shower direction and MC
49 # generated shower direction
50 true_shower = event.simulation.shower
51 off_angle = angular_separation(
52 true_shower.az, true_shower.alt, reco_result.az, reco_result.alt
53 )
54
55 # Appending all estimated off angles
56 off_angles.append(off_angle.to(u.deg).value)
0it [00:00, ?it/s]
1it [00:00, 8.25it/s]
2it [00:00, 4.29it/s]
3it [00:00, 5.49it/s]
4it [00:00, 4.85it/s]
5it [00:01, 3.04it/s]
6it [00:01, 3.81it/s]
7it [00:01, 4.33it/s]
7it [00:01, 4.24it/s]
calculate theta square for angles which are not nan
63 off_angles = np.array(off_angles)
64 thetasquare = off_angles[np.isfinite(off_angles)] ** 2
Plot the results#
72 plt.hist(thetasquare, bins=10, range=[0, 0.4])
73 plt.xlabel(r"$\theta^2$ (deg)")
74 plt.ylabel("# of events")
75 plt.show()
Total running time of the script: (0 minutes 4.411 seconds)