Commit fb95bd3d6aeb1ad2cee4d9fb4b5a58a7d11e5375
1 parent
f4246390
Exists in
master
Add time delay versus energy and versus arrival angle
Showing
8 changed files
with
116 additions
and
38 deletions
Show diff stats
EBL-spectrums.py
... | ... | @@ -16,40 +16,40 @@ lamb,lambdaI = np.loadtxt("EBL_files/lambdaI_Dominguez.dat",unpack=True,usecols= |
16 | 16 | hv = h*c/(lamb*1e-4) # erg |
17 | 17 | density = 1e-6*(4*pi/c)*lambdaI/(hv**2) /(erg_to_GeV*1e9) *(1+z)**3 |
18 | 18 | hv = hv *(erg_to_GeV*1e9) |
19 | -ax.plot(hv,density,"--b",label="Dominguez and Al") | |
19 | +ax.plot(hv,density*hv**2,"--b",label="Dominguez and Al") | |
20 | 20 | |
21 | 21 | # ==== Kneiske and Doll - "best fit" ==== |
22 | 22 | hv,density = np.loadtxt("EBL_files/n_bestfit10.dat",unpack=True,usecols=[0,1]) |
23 | -ax.plot(hv,density,"--r",label="Kneiske and Doll - 'best fit'") | |
23 | +ax.plot(hv,density*hv**2,"--r",label="Kneiske and Doll - 'best fit'") | |
24 | 24 | |
25 | 25 | # ==== Kneiske and Doll - "lower limit" ==== |
26 | 26 | hv,density = np.loadtxt("EBL_files/n_lowerlimit10.dat",unpack=True,usecols=[0,179]) |
27 | 27 | #hv,density =np.loadtxt("EBL_files/n_lowerlimit10.dat",unpack=True,usecols=[0,1]) |
28 | 28 | density=density*(1+z)**3 |
29 | -ax.plot(hv,density,"--g",label="Kneiske and Doll - 'lower limit'") | |
29 | +ax.plot(hv,density*hv**2,"--g",label="Kneiske and Doll - 'lower limit'") | |
30 | 30 | |
31 | 31 | # ==== Fransceschini ==== |
32 | 32 | hv,density = np.loadtxt("EBL_files/n_Fra.dat",unpack=True,usecols=[0,11]) |
33 | 33 | #hv,density = np.loadtxt("EBL_files/n_Fra.dat",unpack=True,usecols=[0,1]) |
34 | 34 | density=density*(1+z)**3 |
35 | -ax.plot(hv,density,"--c",label="Fraceschini") | |
35 | +ax.plot(hv,density*hv**2,"--c",label="Fraceschini") | |
36 | 36 | |
37 | 37 | # ==== Finke ==== |
38 | 38 | hv,density = np.loadtxt("EBL_files/n_Finke.dat",unpack=True,usecols=[0,201]) |
39 | 39 | #hv,density = np.loadtxt("EBL_files/n_Finke.dat",unpack=True,usecols=[0,1]) |
40 | 40 | density=density*(1+z)**3 |
41 | -ax.plot(hv,density,"--m",label="Finke and Al") | |
41 | +ax.plot(hv,density*hv**2,"--m",label="Finke and Al") | |
42 | 42 | |
43 | 43 | # ==== Gilmore ==== |
44 | 44 | hv,density = np.loadtxt("EBL_files/n_Gil.dat",unpack=True,usecols=[0,14]) |
45 | 45 | #hv,density = np.loadtxt("EBL_files/n_Gil.dat",unpack=True,usecols=[0,1]) |
46 | -ax.plot(hv,density,"--y",label="Gilmore and Al") | |
46 | +ax.plot(hv,density*hv**2,"--y",label="Gilmore and Al") | |
47 | 47 | |
48 | 48 | ax.set_xscale('log') |
49 | 49 | ax.set_yscale('log') |
50 | 50 | ax.grid(b=True,which='major') |
51 | 51 | ax.legend(loc="best",title="z = %.0f"%z) |
52 | 52 | ax.set_xlabel("energy [eV]") |
53 | -ax.set_ylabel("$n_{EBL}$ [$cm^{-3} eV^{-1}$]") | |
53 | +ax.set_ylabel("$n_{EBL}$ [$eV.cm^{-3}$]") | |
54 | 54 | |
55 | 55 | plt.show() | ... | ... |
Modules/Analytic.py
... | ... | @@ -4,6 +4,7 @@ from Read import ReadE_source, ReadD_source, ReadEGMF |
4 | 4 | |
5 | 5 | # Value for analytic expression |
6 | 6 | Ee_default=1e3 #GeV |
7 | +Egamma_default=1 #GeV | |
7 | 8 | B_default=1e-17 #Gauss |
8 | 9 | lambda_B_default=0.3 #Mpc |
9 | 10 | |
... | ... | @@ -21,12 +22,24 @@ def Analytic_theta(E_ic,fileId): |
21 | 22 | delta=Dic0/(2*RL0)*((Esource/2)**2 /Ee2 -1) |
22 | 23 | return abs(arcsin(delta_to_theta*sin(delta))*degre) |
23 | 24 | |
24 | -def Analytic_delay(theta, E0_source, distSource): | |
25 | - delta_ic = arcsin(lambda_gg(E0_source)/distSource*theta/degre) | |
26 | - #c_delta_t = lambda_gg(E0_source)*(1-cos(delta_ic))-distSource*(1-cos(theta)) | |
27 | - #return abs(c_delta_t*Mpc/c) | |
28 | - coef = lambda_gg(E0_source)/(2*c/Mpc) | |
29 | - return coef*delta_ic#**2 | |
25 | +def Analytic_delay_vs_theta(theta,fileId): | |
26 | + E0_source = ReadE_source(fileId)*1e-3 #TeV | |
27 | + distSource = ReadD_source(fileId) | |
28 | + delta_ic = arcsin(distSource/lambda_gg(E0_source)*sin(theta/degre)) | |
29 | + c_delta_t = lambda_gg(E0_source)*(1-cos(delta_ic)) - distSource*(1-cos(theta/degre)) | |
30 | + return c_delta_t *Mpc/c # sec. | |
31 | + | |
32 | +def Analytic_delay_vs_Egamma(Egamma, fileId): | |
33 | + Esource=ReadE_source(fileId) #GeV | |
34 | + Dsource=ReadD_source(fileId) #Mpc | |
35 | + B=ReadEGMF(fileId) #Gauss | |
36 | + RL0=RL(Esource/2,B) | |
37 | + Dic0=Dic(Esource/2) | |
38 | + Ee2 = Ee(Egamma)**2 | |
39 | + delta_ic = Dic0/(2*RL0)*((Esource/2)**2 /Ee2 -1) | |
40 | + theta = arcsin(lambda_gg(Esource)/Dsource*sin(delta_ic/degre)) | |
41 | + c_delta_t = lambda_gg(Esource)*(1-cos(delta_ic)) - Dsource*(1-cos(theta/degre)) | |
42 | + return c_delta_t *Mpc/c # sec. | |
30 | 43 | |
31 | 44 | # Compton accumulation |
32 | 45 | def ECompton_threshold(Compton_threshold = 0.005): |
... | ... | @@ -42,6 +55,9 @@ def lambdaIC(): |
42 | 55 | def Eic(Ee=Ee_default): |
43 | 56 | return 4*Ecmb*Ee**2/(3*me**2)*1e3 #GeV |
44 | 57 | |
58 | +def Ee(Egamma=Egamma_default): | |
59 | + return sqrt((3*me**2)/(4*Ecmb)*1e-3 *Egamma) #GeV | |
60 | + | |
45 | 61 | def tIC(): |
46 | 62 | return lambdaIC()/(c*yr/Mpc) #yr |
47 | 63 | |
... | ... | @@ -66,6 +82,6 @@ def Ethreshold_ic(Ee=Ee_default,B=B_default): |
66 | 82 | def Ethreshold_gg(): |
67 | 83 | return (me)**2/Eebl *1e-3 #GeV |
68 | 84 | |
69 | -def lambda_gg(Egamma=1e3): # Egamma (GeV) | |
70 | - return 0.8 /(Egamma*1e-3) *1e3#Mpc (from Durrer and Neronov 2013) | |
85 | +def lambda_gg(Egamma=1): # Egamma (GeV) | |
86 | + return 800. /(Egamma)#Mpc (from Durrer and Neronov 2013) | |
71 | 87 | ... | ... |
Modules/Analytic.pyc
No preview for this file type
Modules/Angle.py
... | ... | @@ -44,11 +44,12 @@ def angle_vs_energy(fileName): |
44 | 44 | nbBins = 40 |
45 | 45 | |
46 | 46 | energy =log10(energy) |
47 | - angle,ener =histogram(energy,nbBins,weights=weight*theta) | |
47 | + angle,ener =histogram(energy,nbBins,weights=theta*weight) | |
48 | 48 | nb,ener =histogram(energy,nbBins,weights=weight) |
49 | 49 | ener = 10**ener |
50 | 50 | enercenter=(ener[1:nbBins+1]+ener[0:nbBins])/2 |
51 | - angle = angle/nb | |
51 | + maxflux = ReadNphot_source(fileName) | |
52 | + angle = angle/(nb*maxflux) | |
52 | 53 | |
53 | 54 | return enercenter, angle |
54 | 55 | ... | ... |
Modules/Angle.pyc
No preview for this file type
Modules/Spectrum.pyc
No preview for this file type
Modules/Timing.py
... | ... | @@ -2,10 +2,10 @@ from numpy import histogram, log10, shape, sqrt, arccos |
2 | 2 | from matplotlib.pyplot import figure, show |
3 | 3 | from scipy.integrate import quad |
4 | 4 | from Read import ReadTime, ReadWeight, ReadGeneration, ReadE_source, ReadD_source |
5 | -from Read import ReadNphot_source,ReadPosition,ReadMomentum,ReadNbLeptonsProd | |
5 | +from Read import ReadNphot_source,ReadPosition,ReadMomentum,ReadNbLeptonsProd,ReadEnergy | |
6 | 6 | from Constants import yr, degre |
7 | 7 | from Integrand import comobileTime |
8 | -from Analytic import Analytic_delay | |
8 | +from Analytic import Analytic_delay_vs_theta,Analytic_delay_vs_Egamma | |
9 | 9 | |
10 | 10 | def timing(fileId,gen=-1): |
11 | 11 | ''' |
... | ... | @@ -93,8 +93,10 @@ def delay_vs_angle(fileId,gen=-1): |
93 | 93 | ''' |
94 | 94 | position = ReadPosition(fileId) |
95 | 95 | momentum = ReadMomentum(fileId) |
96 | + energy = ReadEnergy(fileId) | |
96 | 97 | weight = ReadWeight(fileId) |
97 | 98 | time=ReadTime(fileId) |
99 | + generation = ReadGeneration(fileId) | |
98 | 100 | |
99 | 101 | hyp=sqrt(position[0]**2+position[1]**2+position[2]**2) |
100 | 102 | position /= hyp |
... | ... | @@ -103,21 +105,20 @@ def delay_vs_angle(fileId,gen=-1): |
103 | 105 | costheta=position[0]*momentum[0]+position[1]*momentum[1]+position[2]*momentum[2] |
104 | 106 | |
105 | 107 | if gen != -1 : |
106 | - generation = ReadGeneration(fileId) | |
107 | - cond=(abs(costheta)<=1) & (generation==gen) & (time>0) | |
108 | + cond=(abs(costheta)<=1) & (generation==gen) & (time>0) & (energy>1) | |
108 | 109 | else: |
109 | - cond=(abs(costheta)<=1) & (time>0) | |
110 | + cond=(abs(costheta)<=1) & (time>0) & (energy>1) | |
110 | 111 | |
111 | 112 | prop = float(shape(time[time<0])[0])/shape(time)[0] |
113 | + print "gen", int(gen), "->", shape(time[time<0])[0], "negative time events among ",shape(time)[0], "~", prop | |
112 | 114 | theta = arccos(costheta[cond])*degre |
113 | 115 | weight= weight[cond] |
114 | 116 | time=time[cond]*yr |
115 | - print "gen", int(gen), "->", shape(time)[0], "events", "negative time:",shape(time[time<0])[0], "~", prop | |
116 | 117 | cond=(theta!=0) |
117 | - return theta[cond], time[cond], weight[cond] | |
118 | + return theta[cond], time[cond], weight[cond], generation[cond] | |
118 | 119 | |
119 | 120 | def delay_vs_angle_histo(fileId,gen=-1): |
120 | - theta, time, weight = delay_vs_angle(fileId,gen) | |
121 | + theta, time, weight, generation = delay_vs_angle(fileId,gen) | |
121 | 122 | nbBins = 100 |
122 | 123 | |
123 | 124 | theta=log10(theta) |
... | ... | @@ -138,22 +139,17 @@ def drawDelay_vs_angle(fileId): |
138 | 139 | fig = figure() |
139 | 140 | ax = fig.add_subplot(111) |
140 | 141 | |
141 | - Nmax = ReadNphot_source(fileId) | |
142 | - | |
143 | - for gen in list(set(ReadGeneration(fileId))): | |
144 | - angle,delay,weight = delay_vs_angle(fileId,gen) | |
145 | - ax.plot(angle,delay/weight/Nmax,".",label="gen="+str(int(gen))) | |
146 | - | |
147 | - #angle,delay = delay_vs_angle_histo(fileId,gen) | |
148 | - #ax.plot(angle,delay,linestyle="steps-mid",label="gen="+str(int(gen))) | |
142 | + angle,delay,weight,generation = delay_vs_angle(fileId) | |
143 | + #for gen in list(set(generation)): | |
144 | + for gen in [2]: | |
145 | + cond= (generation==gen) | |
146 | + ax.plot(angle[cond],delay[cond]/weight[cond],".",label="gen="+str(int(gen))) | |
149 | 147 | |
150 | 148 | angle,delay = delay_vs_angle_histo(fileId) |
151 | - ax.plot(angle,delay/Nmax,color='k',linestyle="steps-mid",label="gen=all") | |
149 | + #ax.plot(angle,delay,color='k',linestyle="steps-mid",label="gen=all") | |
152 | 150 | |
153 | - Esource = ReadE_source(fileId) | |
154 | - dSource = ReadD_source(fileId) | |
155 | - yfit = Analytic_delay(angle,Esource,dSource) | |
156 | - ax.plot(angle,yfit,'--k',linewidth=2) | |
151 | + delay_fit = Analytic_delay_vs_theta(angle,fileId) | |
152 | + ax.plot(angle,delay_fit,'--r',linewidth=2) | |
157 | 153 | |
158 | 154 | ax.set_xscale('log') |
159 | 155 | ax.set_yscale('log') |
... | ... | @@ -163,3 +159,68 @@ def drawDelay_vs_angle(fileId): |
163 | 159 | ax.set_ylabel("Time delay [s]") |
164 | 160 | |
165 | 161 | show() |
162 | + | |
163 | +######## delay versus angle ############### | |
164 | +def delay_vs_energy(fileId,gen=-1): | |
165 | + ''' | |
166 | + Compute time delay versus arrival angle | |
167 | + Input: directory name | |
168 | + Input (optional): generation (default = all) | |
169 | + Output: arrival angle [degre], time delay [sec] | |
170 | + ''' | |
171 | + energy = ReadEnergy(fileId) | |
172 | + weight = ReadWeight(fileId) | |
173 | + time=ReadTime(fileId) | |
174 | + generation = ReadGeneration(fileId) | |
175 | + | |
176 | + if gen != -1 : | |
177 | + cond= (generation==gen) & (time>0) & (energy>1) | |
178 | + else: | |
179 | + cond= (time>0) & (energy>1) | |
180 | + | |
181 | + prop = float(shape(time[time<0])[0])/shape(time)[0] | |
182 | + print "gen", int(gen), "->", shape(time[time<0])[0], "negative time events among ",shape(time)[0], "~", prop | |
183 | + return energy[cond], time[cond]*yr, weight[cond], generation[cond] | |
184 | + | |
185 | +def delay_vs_energy_histo(fileId,gen=-1): | |
186 | + energy, time, weight, generation = delay_vs_energy(fileId,gen) | |
187 | + nbBins = 100 | |
188 | + | |
189 | + energy=log10(energy) | |
190 | + dt,dE=histogram(energy,nbBins,weights=time) | |
191 | + dN,dE=histogram(energy,nbBins,weights=weight) | |
192 | + dE=10**dE | |
193 | + Ecenter=(dE[1:nbBins+1]+dE[0:nbBins])/2 | |
194 | + timing = dt/dN | |
195 | + | |
196 | + return Ecenter, timing | |
197 | + | |
198 | +def drawDelay_vs_energy(fileId): | |
199 | + ''' | |
200 | + Plot angle versus time delay, generation by generation | |
201 | + Input: directory name | |
202 | + Output: graph of angle versus time delay, generation by generation | |
203 | + ''' | |
204 | + fig = figure() | |
205 | + ax = fig.add_subplot(111) | |
206 | + | |
207 | + energy,delay,weight,generation = delay_vs_energy(fileId) | |
208 | + #for gen in list(set(generation)): | |
209 | + for gen in [2]: | |
210 | + cond= (generation==gen) | |
211 | + ax.plot(energy[cond],delay[cond]/weight[cond],".",label="gen="+str(int(gen))) | |
212 | + | |
213 | + energy,delay = delay_vs_energy_histo(fileId) | |
214 | + #ax.plot(energy,delay,color='k',linestyle="steps-mid",label="gen=all") | |
215 | + | |
216 | + delay_fit = Analytic_delay_vs_Egamma(energy,fileId) | |
217 | + ax.plot(energy,delay_fit,'--r',linewidth=2) | |
218 | + | |
219 | + ax.set_xscale('log') | |
220 | + ax.set_yscale('log') | |
221 | + ax.grid(b=True,which='major') | |
222 | + ax.legend(loc="best") | |
223 | + ax.set_xlabel("E [GeV]") | |
224 | + ax.set_ylabel("Time delay [s]") | |
225 | + | |
226 | + show() | ... | ... |
Modules/Timing.pyc
No preview for this file type