Blame view

src/analytic.py 5.98 KB
d88319ae   Thomas Fitoussi   Update analysis 2...
1
from numpy import sqrt, abs, cos, sin, arcsin, searchsorted, loadtxt, log, array, select, exp
627ed999   Thomas Fitoussi   1. Reorganized fi...
2
from numpy import pi, sqrt
30f3bf5d   Thomas Fitoussi   Adapt reading of ...
3
4
from scipy.integrate import quad
from read import ReadProfile,resultdir
627ed999   Thomas Fitoussi   1. Reorganized fi...
5
from constants import *
7030f150   Thomas Fitoussi   Full reorganisati...
6

8ffbee93   Thomas Fitoussi   Analytic expressi...
7
8
# Value for analytic expression
Ee_default=1e3 #GeV
fb95bd3d   Thomas Fitoussi   Add time delay ve...
9
Egamma_default=1 #GeV
188a8c6a   Thomas Fitoussi   Update analysis 2...
10
B_default=1e-15 #Gauss
8ffbee93   Thomas Fitoussi   Analytic expressi...
11
12
lambda_B_default=0.3 #Mpc

627ed999   Thomas Fitoussi   1. Reorganized fi...
13
14
15
16
17
18
def Analytic_flux(E_ic,fileId):
   zs=ReadProfile(fileId,[3]) #Gauss #GeV #Mpc 
   return  me*1e3/4*sqrt(3e9/Ecmb)*1e-9*E_ic**(-3/2.) / (1+zs) #GeV

def Analytic_dNdtheta(theta,fileId):
   B,Eg0,Ds,zs=ReadProfile(fileId,[0,1,2,3]) #Gauss #GeV #Mpc 
4d2bede0   Thomas Fitoussi   add script for me...
19
   lgg = 1.32#lambda_gg(Eg0*1e3,zs)[1]
627ed999   Thomas Fitoussi   1. Reorganized fi...
20
21
22
23
24
25
   tau_gg = Ds/lgg
   dNdtheta = m*c**2 *sqrt((3*sigmaT*nCMB)/(2*e*Ecmb*1e-9/erg_to_GeV) * tau_gg/(theta/degre*B)) # rad^-1
   return dNdtheta

def Analytic_dNdt(t,fileId):
   B,Eg0,zs=ReadProfile(fileId,[0,1,3]) #Gauss #GeV 
4d2bede0   Thomas Fitoussi   add script for me...
26
   lgg = 1.32#lambda_gg(Eg0*1e3,zs)[1]
627ed999   Thomas Fitoussi   1. Reorganized fi...
27
28
   dNdt = (m*c**2/4) *sqrt((3*sigmaT*nCMB)/(e*Ecmb*1e-9/erg_to_GeV*B))*(8*c*t*yr/(lgg*Mpc))**(0.25)
   return dNdt
7030f150   Thomas Fitoussi   Full reorganisati...
29

fb95bd3d   Thomas Fitoussi   Add time delay ve...
30
def Analytic_delay_vs_theta(theta,fileId):
30f3bf5d   Thomas Fitoussi   Adapt reading of ...
31
   Esource,distSource=ReadProfile(fileId,[1,2]) #GeV #Mpc 
65135318   Thomas Fitoussi   Reset modules
32
   E0_source = Esource*1e-3 #TeV
65135318   Thomas Fitoussi   Reset modules
33
   Dic0=Dic(E0_source/2)
4d2bede0   Thomas Fitoussi   add script for me...
34
   lgg = 1.32#lambda_gg(Esource*1e3)[0]
627ed999   Thomas Fitoussi   1. Reorganized fi...
35
   delta_ic = arcsin(distSource/lgg*sin(theta))
188a8c6a   Thomas Fitoussi   Update analysis 2...
36
   c_delta_t = (lgg*(1-cos(delta_ic)) - distSource*(1-cos(theta)))
4d2bede0   Thomas Fitoussi   add script for me...
37
   lgg = 117#lambda_gg(8e3)[0]
627ed999   Thomas Fitoussi   1. Reorganized fi...
38
39
40
   delta_ic = arcsin(distSource/lgg*sin(theta))
   c_delta_t2 = (lgg*(1-cos(delta_ic)) - distSource*(1-cos(theta)))
   return c_delta_t *Mpc/c, c_delta_t2 *Mpc/c  # sec.
fb95bd3d   Thomas Fitoussi   Add time delay ve...
41

188a8c6a   Thomas Fitoussi   Update analysis 2...
42
43
44
def Analytic_observables_vs_energy(Egamma, fileId):
   B,Eg0,Ds,zs=ReadProfile(fileId,[0,1,2,3]) #Gauss #GeV #Mpc 
   Ee0=Eg0*1e3/2 #GeV
188a8c6a   Thomas Fitoussi   Update analysis 2...
45
46
47
48
   RL0=RL(Ee0,B,zs)
   Dic0=Dic(Ee0,zs)
   E_e = Ee(Egamma,zs)
   delta = Dic0/(2*RL0)*((Ee0/E_e)**2 -1)
627ed999   Thomas Fitoussi   1. Reorganized fi...
49
   lgg = lambda_gg(Eg0*1e3,zs)[1]
188a8c6a   Thomas Fitoussi   Update analysis 2...
50
   theta = arcsin(lgg/Ds*sin(delta))
d88319ae   Thomas Fitoussi   Update analysis 2...
51
   c_delta_t = lgg*(1-cos(delta)) - Ds*(1-cos(theta)) #+Dic(E_e,zs)
627ed999   Thomas Fitoussi   1. Reorganized fi...
52
53
54
55
56
57
   lgg = lambda_gg(8e3,zs)[1]
   theta2 = arcsin(lgg/Ds*sin(delta))
   c_delta_t2 = lgg*(1-cos(delta)) - Ds*(1-cos(theta)) #+Dic(E_e,zs)
   return abs(theta)/degre, c_delta_t *Mpc/c, abs(theta2)/degre, c_delta_t2 *Mpc/c # sec.

def arrival_approx(B=B_default,z=0.13,Egamma0=1e5): # Pour Egamma = 1GeV
4d2bede0   Thomas Fitoussi   add script for me...
58
59
60
61
62
   delta = Dic(Ee=Ee(1),z=z)/(2*RL(B=B,z=z))  
   lgg =  1.32# lambda_gg(Egamma0,z)[0]
   print distance(z)[0], lgg, distance(z)[0]/lgg
   theta = lgg/distance(z)[0] * delta
   cdt = lgg/2 * delta**2
627ed999   Thomas Fitoussi   1. Reorganized fi...
63
   return theta/degre, cdt*Mpc/c /yr
f4246390   Thomas Fitoussi   Improve angular d...
64

8ffbee93   Thomas Fitoussi   Analytic expressi...
65
# Compton accumulation
a44230b7   Thomas Fitoussi   Improve approxima...
66
67
def ECompton_threshold(Compton_threshold = 0.005,z=0):
   return Compton_threshold/(4/3*Ecmb*(1+z)/me*1e-3) *me*1e-6 #GeV
8ffbee93   Thomas Fitoussi   Analytic expressi...
68
69

# Compton scattering
a44230b7   Thomas Fitoussi   Improve approxima...
70
71
def Dic(Ee=Ee_default,z=0): # Ee (GeV)
   return 3*(me*1e3)**2/(4*sigmaT*Ee*1e9*rhoCMB*(1+z)**4) /Mpc #Mpc
8ffbee93   Thomas Fitoussi   Analytic expressi...
72

a44230b7   Thomas Fitoussi   Improve approxima...
73
74
def lambdaIC(z=0):
   return 1/(sigmaT*Mpc*nCMB*(1+z)**3) #Mpc
8ffbee93   Thomas Fitoussi   Analytic expressi...
75

a44230b7   Thomas Fitoussi   Improve approxima...
76
77
def Eic(Ee=Ee_default,z=0):
   return 4*Ecmb*(1+z) *Ee**2/(3*me**2)*1e3 #GeV 
8ffbee93   Thomas Fitoussi   Analytic expressi...
78

a44230b7   Thomas Fitoussi   Improve approxima...
79
80
def Ee(Egamma=Egamma_default,z=0):
   return me*sqrt((3*Egamma*1e-3 )/(4*Ecmb*(1+z))) #GeV 
fb95bd3d   Thomas Fitoussi   Add time delay ve...
81

8ffbee93   Thomas Fitoussi   Analytic expressi...
82
83
84
85
def tIC():
   return lambdaIC()/(c*yr/Mpc) #yr

# Larmor radius
188a8c6a   Thomas Fitoussi   Update analysis 2...
86
87
def RL(Ee=Ee_default,B=B_default,z=0):
   return (Ee/erg_to_GeV)/(e*B) /(1+z) /Mpc #Mpc
8ffbee93   Thomas Fitoussi   Analytic expressi...
88
89

# Magnetic deflection
188a8c6a   Thomas Fitoussi   Update analysis 2...
90
def delta(Ee=Ee_default,B=B_default,lambda_B=lambda_B_default,z=0):
7f9b17ff   Thomas Fitoussi   Add notebook chec...
91
   Ee=array(Ee)
188a8c6a   Thomas Fitoussi   Update analysis 2...
92
93
94
95
96
97
98
99
   D_ic=Dic(Ee,z)
   condlist=[lambda_B>=D_ic,lambda_B<D_ic]
   delta=[D_ic/RL(Ee,B),sqrt(D_ic*lambda_B)/RL(Ee,B)]
   return select(condlist,delta)

def Delta(Ee=Ee_default,B=B_default,lambda_B=lambda_B_default,z=0,Esource=1e5):
   lgg=lambda_gg(Esource)[0]
   Dsource=distance(z)[1]
3c65fe50   Thomas Fitoussi   Modification in t...
100
   return arcsin(lgg/Dsource*delta(Ee,B,lambda_B,z))/degre
188a8c6a   Thomas Fitoussi   Update analysis 2...
101
102
103
104
105
106
107
108

def Dt(Ee=Ee_default,B=B_default,lambda_B=lambda_B_default,z=0,Esource=1e5):
   lgg=lambda_gg(Esource)[0]
   return lgg/2*delta(Ee,B,lambda_B,z)**2 /c *Mpc/yr

#synchrotron radiation
def Esc(Ee=Ee_default,B=B_default): # eV
   return (3*hb*e*c)/(2*m**3*c**6) * B*(Ee/erg_to_GeV)**2 *erg_to_GeV*1e9
8ffbee93   Thomas Fitoussi   Analytic expressi...
109
110
111
112

# Threshold energy when Dic = RL
def Ethreshold_ic(Ee=Ee_default,B=B_default):
   return Eic(Ee)*Dic(Ee)/RL(Ee,B) # GeV
8ffbee93   Thomas Fitoussi   Analytic expressi...
113

d943e502   Thomas Fitoussi   Update 'analysis'...
114
115
def Ethreshold_gg(epsilon=Eebl):
   return (me)**2/epsilon *1e-3 #GeV
8ffbee93   Thomas Fitoussi   Analytic expressi...
116

30f3bf5d   Thomas Fitoussi   Adapt reading of ...
117
def lambda_gg(Egamma=1e3,z=0): # Egamma (GeV)
a44230b7   Thomas Fitoussi   Improve approxima...
118
   # Bilinear interpolation 
4d2bede0   Thomas Fitoussi   add script for me...
119
   z_tab = [0,0.03,0.1,0.5,1,2,3]
188a8c6a   Thomas Fitoussi   Update analysis 2...
120
   E_tab = loadtxt("Results/lambda_e.dat",unpack=True,usecols=[0])*me*1e-6
a44230b7   Thomas Fitoussi   Improve approxima...
121
122
123
124
125
126
127
128
129
130
131
132
133
134
   i2 = searchsorted(z_tab,z)
   if z<=0:
      fy=1
      i1=i2
   elif z>3:
      fy=1
      i2-=1
      i1=i2
   else:
      i1 = i2-1
      fy=(z-z_tab[i1])/(z_tab[i2]-z_tab[i1])
   j2 = searchsorted(E_tab,Egamma)
   j1 = j2-1
   fx=(Egamma-E_tab[j1])/(E_tab[j2]-E_tab[j1])
4d2bede0   Thomas Fitoussi   add script for me...
135
   lambda_e = loadtxt("Results/lambda_e.dat",unpack=True,usecols=[i1+1,i2+1,i1+7,i2+7])
a44230b7   Thomas Fitoussi   Improve approxima...
136
137
138
139
140
141
142
143
144
145
146
   lambda11 = lambda_e[0,j1]*((1-fx)*(1-fy))
   lambda12 = lambda_e[1,j1]*((1-fx)*fy)
   lambda21 = lambda_e[0,j2]*(fx*(1-fy))
   lambda22 = lambda_e[1,j2]*(fx*fy)
   lambda_proper = lambda11 + lambda12 + lambda21 + lambda22
   lambda11 = lambda_e[2,j1]*((1-fx)*(1-fy))
   lambda12 = lambda_e[3,j1]*((1-fx)*fy)
   lambda21 = lambda_e[2,j2]*(fx*(1-fy))
   lambda22 = lambda_e[3,j2]*(fx*fy)
   lambda_comobile = lambda11 + lambda12 + lambda21 + lambda22
   return lambda_proper, lambda_comobile, 800.e3/Egamma #Mpc (from Durrer and Neronov 2013)
30f3bf5d   Thomas Fitoussi   Adapt reading of ...
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165

def comobileTime(z):
   return -1/(H0*(1+z)*sqrt(omegaM*(1+z)**3+omegaK*(1+z)**2+omegaL))

def distPhoton(z):
   return -c/(H0*a0*sqrt(omegaM*(1+z)**3+omegaK*(1+z)**2+omegaL))

def distLepton(z,E):
   beta = sqrt(1-m**2*c**4/E**2)
   return -beta*c/(H0*a0*sqrt(omegaM*(1+z)**3+omegaK*(1+z)**2+omegaL))

def properIntegrand(z):
   return -c/(H0*(1+z)*sqrt(omegaM*(1+z)**3+omegaK*(1+z)**2+omegaL))

def comobileIntegrand(z):
   return -c/(H0*sqrt(omegaM*(1+z)**3+omegaK*(1+z)**2+omegaL))

def distance(z=0):
   return quad(properIntegrand,z,0)[0]/Mpc, quad(comobileIntegrand,z,0)[0]/Mpc
7f9b17ff   Thomas Fitoussi   Add notebook chec...
166
167
168
169
170
171
172
173
174
175

def Ecut(z=0.1): # TeV
   z=array(z)
   z1= 0.045
   z2= 0.1
   condlist=[z<z1,(z>=z1)&(z<z2),z>=z2]
   Ecut=[54*(z/0.001)**(-0.5),3.4*(z/0.06)**(-3),0.35*(z/0.4)**(-0.5)]
   return select(condlist,Ecut)

def Etarget(Egamma=1): # Egamma en TeV, Etarget en eV
188a8c6a   Thomas Fitoussi   Update analysis 2...
176
177
178
   return 6.9*(Egamma/0.2)**(-0.9)

def PSF_Taylor2011(E): # E in GeV -> PSF in degre
3c65fe50   Thomas Fitoussi   Modification in t...
179
   return 1.7 * E**(-0.74) * (1+(E/15)**2)**0.37