forked from mgaug/Muons_DualMirror
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsingle_mirror_lib.py
More file actions
312 lines (227 loc) · 11.2 KB
/
single_mirror_lib.py
File metadata and controls
312 lines (227 loc) · 11.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
import numpy as np
import matplotlib.colors as mcolors
import matplotlib.pyplot as plt
def Lmax_M1(rhoR, phi0,nu,psi,phi,theta_c,R1,c):
'''
Implements the single mirror maximum length Eqs. 30 to Eq. 32
Input:
======
Muon parameters:
- rhoR: radial distance of the muon impact point in relative units,
rhoR = rho/R1
- phi0: azimquthal projection of muon impact point on primary mirror plane,
in deg
- nu: inclination angle of muon,
in rad
- psi: azimuthal projection of muon inclination on primary mirror plane,
in deg
Photon parameters:
- phi: azimuthal projection of photon emission angle on primary mirror plane,
in deg
- theta_c: Cherenkov angle of emission,
in rad
M1 parameters:
- R1: radius of primary mirror M1
in m
- c: curvature of the mirror M1, =1/(4F) for a parabolic mirror
in m^-1
'''
rhoR = np.atleast_1d(rhoR).astype(np.float64) # (Nr,)
phi = np.atleast_1d(phi).astype(np.float64) # (Nphi,)
phi0 = np.atleast_1d(phi0).astype(np.float64) # (Nphi0,)
rho = rhoR[:, None, None] # (Nr,1,1)
ph = phi[None, :, None] # (1,Nphi,1)
ph0 = phi0[None, None, :] # (1,1,Nphi0)
# Angles in radians
ang_pps = np.deg2rad(ph - psi) # (1,Nphi,1) if psi scalar
ang_pp0 = np.deg2rad(ph - ph0) # (1,Nphi,Nphi0)
cospps = nu * np.cos(ang_pps) # (1,Nphi,1)
sinpps = nu * np.sin(ang_pps) # (1,Nphi,1)
rsinpp0 = rho * np.sin(ang_pp0) # (Nr,Nphi,Nphi0)
rcospp0 = rho * np.cos(ang_pp0) # (Nr,Nphi,Nphi0)
dphi = (ph - ph0 + 180.0) % 360.0 - 180.0 # (1,Nphi,Nphi0)
extra = (np.abs(dphi) < 90.0)
sqrtarg = 1-rsinpp0**2
sqrtcond = (sqrtarg > 0)
sqsinp = np.sqrt(np.maximum(sqrtarg, 1.0e-8))
LmaxVac = np.where(sqrtcond,R1 * (rcospp0 + sqsinp) / theta_c, 0.) # Vacanti solution, np.maximum condition avoids unnecessary warnings
FOcorr = c*R1**2 * (1-rho**2) # 0th order correction, forgotten by Vacanti
F1corr = FOcorr * cospps / theta_c # 1st order correction for nu != 0
F2corr = FOcorr * sinpps * rsinpp0 /2./sqsinp/theta_c # 2nd order correction for nu != 0
return np.where(((rho < 1.0) | extra) & sqrtcond,
LmaxVac + FOcorr + F1corr - F2corr,
0.
)
def Lmin_M1(rhoR, phi0,nu,psi,phi,theta_c,R1,c):
'''
Implements the single mirror minimum length Eq. 33
Input:
======
Muon parameters:
- rhoR: radial distance of the muon impact point in relative units,
rhoR = rho/R1
- phi0: azimquthal projection of muon impact point on primary mirror plane,
in deg
- nu: inclination angle of muon,
in rad
- psi: azimuthal projection of muon inclination on primary mirror plane,
in deg
Photon parameters:
- phi: azimuthal projection of photon emission angle on primary mirror plane,
in deg
- theta_c: Cherenkov angle of emission,
in rad
M1 parameters:
- R1: radius of primary mirror M1
in m
- c: curvature of the mirror M1, =1/(4F) for a parabolic mirror
in m^-1
'''
rhoR = np.atleast_1d(rhoR).astype(np.float64) # (Nr,)
phi = np.atleast_1d(phi).astype(np.float64) # (Nphi,)
phi0 = np.atleast_1d(phi0).astype(np.float64) # (Nphi0,)
rho = rhoR[:, None, None] # (Nr,1,1)
ph = phi[None, :, None] # (1,Nphi,1)
ph0 = phi0[None, None, :] # (1,1,Nphi0)
# Angles in radians
ang_pps = np.deg2rad(ph - psi) # (1,Nphi,1) if psi scalar
ang_pp0 = np.deg2rad(ph - ph0) # (1,Nphi,Nphi0)
cospps = nu * np.cos(ang_pps) # (1,Nphi,1)
sinpps = nu * np.sin(ang_pps) # (1,Nphi,1)
rsinpp0 = rho * np.sin(ang_pp0) # (Nr,Nphi,Nphi0)
rcospp0 = rho * np.cos(ang_pp0) # (Nr,Nphi,Nphi0)
dphi = (ph - ph0 + 180.0) % 360.0 - 180.0 # (1,Nphi,Nphi0)
extra = (np.abs(dphi) < 90.0)
sqrtarg = 1-rsinpp0**2
sqrtcond = (sqrtarg > 0)
sqsinp = np.sqrt(np.maximum(sqrtarg, 1.0e-8))
LminVac = np.where(sqrtcond,R1 * (rcospp0 - sqsinp) / theta_c, 0.) # Vacanti solution, np.maximum condition avoids unnecessary warnings
return np.where((rho < 1.0),
0.,
np.where(extra & sqrtcond,LminVac,0.)
)
def global_shadow_condition_from_quadratic_camera(rhoR,phi0,nu,psi, # muon parameters
phi,theta_c, # photon parameters
R1, # primary mirror parameters
A,D): # camera parameters
'''
Implements the shadow conditions for the quadratic camera
Input:
======
Muon parameters:
- rhoR: radial distance of the muon impact point in relative units,
rhoR = rho/R1
- phi0: azimquthal projection of muon impact point on primary mirror plane,
in deg
- nu: inclination angle of muon,
in rad
- psi: azimuthal projection of muon inclination on primary mirror plane,
in deg
Photon parameters:
- phi: azimuthal projection of photon emission angle on primary mirror plane,
in deg
- theta_c: Cherenkov angle of emission,
in rad
M1 parameters:
- R1: radius of primary mirror M1
in m
M2 parameters:
- A: Camera half side (see Fig. 28 of https://iopscience.iop.org/article/10.3847/1538-4365/ab2123)
in m
- D: Vertical separation of M1 pole to camera
in m
rhoR, phi0 and phi may be np arrays
returns an array of booleans with dimension (rhoR.size, phi.size, phi0.size)
'''
rhoR = np.atleast_1d(rhoR).astype(np.float64) # (Nr,)
phi = np.atleast_1d(phi).astype(np.float64) # (Nphi,)
phi0 = np.atleast_1d(phi0).astype(np.float64) # (Nphi0,)
rho = R1 * rhoR[:, None, None] # (Nr,1,1)
ph = phi[None, :, None] # (1,Nphi,1)
ph0 = phi0[None, None, :] # (1,1,Nphi0)
# Angles in radians
ang_pps = np.deg2rad(ph - psi) # (1,Nphi,1) if psi scalar
ang_pp0 = np.deg2rad(ph - ph0) # (1,Nphi,Nphi0)
ang_ph = np.deg2rad(ph)
ang_ps = np.deg2rad(psi)
ang_p0 = np.deg2rad(ph0)
rsinph0 = rho * np.sin(ang_pp0) # (Nr,Nphi,Nphi0)
nsinpsi = D * nu * np.sin(ang_pps) # psi is scalar
sinph = np.sin(ang_ph) # (1,Nphi,1)
cosph = np.cos(ang_ph) # (1,Nphi,1)
Rproj = rsinph0 + nsinpsi # (Nr,Nphi,Nphi0)
cond = (np.abs(Rproj) <= A*(np.abs(sinph)+np.abs(cosph)))
# Extra condition when rho*R1 > Rsh: require |phi - phi0| < 90 deg
dphi = (ph - ph0 + 180.0) % 360.0 - 180.0 # (1,Nphi,Nphi0)
extra = (np.abs(dphi) < 90.0)
# Now the condition that the MUON impact point (ρcos(ϕ_0+π), ρsin(ϕ_0+π))=(−ρcosϕ_0, −ρsinϕ_0)
# lies inside the projection of the square camera onto the mirror plane:
# For the muon direction projected onto the transverse plane, the displacement from
# z=0 to D is (D*ν*cosψ, D*ν*sinψ), so the square camera centered at the origin in the plane
# z=D and ∣x∣≤A,∣y∣≤A, projects onto z=0 as the translated square
# ∣x+D*ν*cosψ∣≤A,∣y+D*ν*sinψ∣≤A.
# Therefore, the condition that the muon impact point lies within that projection is
# ∣−ρcosϕ_0+D*ν*cosψ∣≤A and ∣−ρsinϕ_0+D*ν*sinψ∣≤A.
condproj = (np.abs(-rho * np.cos(ang_p0) + D*nu*np.cos(ang_ps)) < A) & (np.abs(-rho * np.sin(ang_p0) + D*nu*np.sin(ang_ps)) < A)
return np.where(condproj, cond, cond & extra)
def min_to_abs(u, v):
return (u + v - abs(u - v))/2
def max_to_abs(u, v):
return (u + v + abs(u - v))/2
def Lmax2min2_from_quadratic_camera(rhoR,phi0,nu,psi, # muon parameters
phi,theta_c, # photon parameters
R1, # primary mirror parameters
A,D): # camera parameters
'''
Implements Lmax and Lmin for the quadratic camera
Input:
======
Muon parameters:
- rhoR: radial distance of the muon impact point in relative units,
rhoR = rho/R1
- phi0: azimquthal projection of muon impact point on primary mirror plane,
in deg
- nu: inclination angle of muon,
in rad
- psi: azimuthal projection of muon inclination on primary mirror plane,
in deg
Photon parameters:
- phi: azimuthal projection of photon emission angle on primary mirror plane,
in deg
- theta_c: Cherenkov angle of emission,
in rad
M1 parameters:
- R1: radius of primary mirror M1
in m
M2 parameters:
- A: Camera half side (see Fig. 28 of https://iopscience.iop.org/article/10.3847/1538-4365/ab2123)
in m
- D: Vertical separation of M1 pole to camera
in m
rhoR, phi0 and phi may be np arrays
returns two arrays of booleans with dimension (rhoR.size, phi.size, phi0.size) corresponding to Lmax and Lmin
!!! The condition global_shadow_condition_from_quadratic_camera must be applied separately !!!
'''
rhoR = np.atleast_1d(rhoR).astype(np.float64) # (Nr,)
phi = np.atleast_1d(phi).astype(np.float64) # (Nphi,)
phi0 = np.atleast_1d(phi0).astype(np.float64) # (Nphi0,)
rho = rhoR[:, None, None] # (Nr,1,1)
ph = phi[None, :, None] # (1,Nphi,1)
ph0 = phi0[None, None, :] # (1,1,Nphi0)
# Angles in radians
angpsi = np.deg2rad(psi) # psi is scalar
angpp0 = np.deg2rad(ph0) # (1,1,Nphi0)
angphi = np.deg2rad(ph) # (1,Nphi,1)
ncospsi = D * nu * np.cos(angpsi) # psi is scalar
nsinpsi = D * nu * np.sin(angpsi) # psi is scalar
tcosphi = theta_c * np.cos(angphi) # (1,Nphi,1)
tsinphi = theta_c * np.sin(angphi) # (1,Nphi,1)
rcosph0 = R1 * rho * np.cos(angpp0) # (Nr,1,Nphi0)
rsinph0 = R1 * rho * np.sin(angpp0) # (Nr,1,Nphi0)
Lx0 = D + (ncospsi + rcosph0) / tcosphi # (Nr,Nphi,Nphi0)
Ly0 = D + (nsinpsi + rsinph0) / tsinphi # (Nr,Nphi,Nphi0)
Lx_min = Lx0 - A/np.abs(tcosphi)
Lx_max = Lx0 + A/np.abs(tcosphi)
Ly_min = Ly0 - A/np.abs(tsinphi)
Ly_max = Ly0 + A/np.abs(tsinphi)
return min_to_abs(Lx_max, Ly_max), max_to_abs(Ly_min, Lx_min)