Analytic_comparison.py
4.31 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
#!/usr/bin/python
from sys import argv
import matplotlib.pyplot as plt
from matplotlib import gridspec
from Constantes import *
if len(argv)<2:
print "Please give at least 1 file id \n For example: 15 for Results_EGMF15"
exit()
nbBins = 100
Eelec,Eperp,Egamma=loadtxt("Results_EGMF"+argv[1]+"/Compton_Energy",unpack=True)
deltaTheta,theta,dIC,RLtrue,RLestimate=loadtxt("Results_EGMF"+argv[1]+"/Compton_Lambda",unpack=True)
B=10**(-float(argv[1]))
lambdaB=1 #Mpc
# Distance between 2 IC versus Lepton energy
#============================================
fig = plt.figure()
gs = gridspec.GridSpec(3, 1, height_ratios=[4,1,1])
fig.subplots_adjust(hspace=0.001)
ax = fig.add_subplot(gs[0])
Edata =log10(Eelec)
dist,ener =histogram(Edata,nbBins,weights=dIC)
nb,ener =histogram(Edata,nbBins)
ener = 10**ener
enercenter=(ener[1:nbBins+1]+ener[0:nbBins])/2
dist = dist/nb
ax.plot(enercenter,dist,".b",label="$\\lambda_{IC}$ - Simulation")
def fit_lambdaIC(E):
return lambdaIC*E**0# Mpc
yfit = fit_lambdaIC(enercenter)
ax.plot(enercenter,yfit,'--c',linewidth=2,
label="$\\lambda_{IC}= %.2f$ kpc"%(lambdaIC*1e3))
ax2 = plt.subplot(gs[1], sharex=ax)
error=dist/yfit-1
ax2.plot(enercenter,error,'+b')
step=0.2*(max(error)-min(error))
plt.ylim(min(error)-step, max(error)+step)
def fit_Dic(E):
return Dic*(E/1000)**(-1) #Mpc
yfit = fit_Dic(enercenter)
ax.plot(enercenter,yfit,'--g',linewidth=2,
label="$D_{IC}=%.2f \\left(\\frac{E}{1TeV}\\right)^{-1}$Mpc"%Dic)
Edata =log10(Eperp)
dist,ener =histogram(Edata,nbBins,weights=RLestimate)
nb,ener =histogram(Edata,nbBins)
ener = 10**ener
enercenter=(ener[1:nbBins+1]+ener[0:nbBins])/2
dist = dist/nb
ax.plot(enercenter,dist,".r",label="$R_{L}$ - estimate")
#ax.plot(Eperp,RLestimate,".r",label="$R_{L}$ - estimate")
#ax.plot(Eperp,RLtrue,".y",label="$R_{L}$ - true")
def fit_RL(E,B):
return RL*(E/1e3)*(B/1e-17)**-1 # Mpc
yfit = fit_RL(enercenter,B)
ax.plot(enercenter,yfit,'--m',linewidth=2,
label="$R_{L}=%.2f \\left(\\frac{E}{1TeV}\\right)$ Mpc"%(RL*1e-17/B))
ax3 = plt.subplot(gs[2], sharex=ax)
error=dist/yfit-1
ax3.plot(enercenter,error,'+r')
step=0.2*(max(error)-min(error))
plt.ylim(min(error)-step, max(error)+step)
ax.legend(loc="best",title="$10^{-%.0f"%float(argv[1])+"}$Gauss")
ax.grid(b=True,which='major')
ax2.grid(b=True,which='major')
ax3.grid(b=True,which='major')
ax.set_xscale('log')
ax.set_yscale('log')
ax2.set_xscale('log')
ax3.set_xscale('log')
ax3.set_xlabel("energy [GeV]")
ax.set_ylabel("$\lambda$ [Mpc]")
ax2.set_ylabel("relative error $d_{IC}$")
ax3.set_ylabel("relative error $R_L$")
xticklabels = ax.get_xticklabels()+ax2.get_xticklabels()
plt.setp(xticklabels, visible=False)
# Deflexion angle versus Lepton energy
#======================================
fig = plt.figure()
gs = gridspec.GridSpec(2, 1, height_ratios=[4,1])
fig.subplots_adjust(hspace=0.001)
ax = fig.add_subplot(gs[0])
angle,ener =histogram(Edata,nbBins,weights=theta)
nb,ener =histogram(Edata,nbBins)
ener = 10**ener
enercenter=(ener[1:nbBins+1]+ener[0:nbBins])/2
angle = angle/nb*degre
ax.plot(enercenter,angle,".b",linewidth=2,label="Simulation -$10^{-%.0f"%float(argv[1])+"}$Gauss")
def fit_deltaIC(E):
return delta*(E/1e3)**(-1)*(B/1e-17)*(lambdaB/0.3)**(1/2) #degre
yfit = fit_deltaIC(enercenter)
ax.plot(enercenter,yfit,'--c',linewidth=2,label="Analytic")
ax2 = plt.subplot(gs[1], sharex=ax)
error=angle/yfit-1
ax2.plot(enercenter,error,'+b')
step=0.2*(max(error)-min(error))
plt.ylim(min(error)-step, max(error)+step)
#a=0.2 # degre
#def fitLeptonDN13(E,a,B):
# return a* (E/1000)**(-2) *(B/1e-17)
#
#yfit = fitLeptonDN13(enercenter,a,B)
#ax.plot(enercenter,yfit,'--g',linewidth=2,label="Durrer 2013")
ax.legend(loc="best")
ax.grid(b=True,which='major')
ax2.grid(b=True,which='major')
ax.set_xscale('log')
ax2.set_xscale('log')
ax.set_yscale('log')
ax2.set_xlabel("energy [GeV]")
ax.set_ylabel("$\\delta$ [degre]")
ax2.set_ylabel("relative error $\\theta$")
xticklabels = ax.get_xticklabels()
plt.setp(xticklabels, visible=False)
# Histo leptons energy
#======================
#fig = plt.figure()
#ax = fig.add_subplot(111)
#
#plt.hist(Eelec, nbBins, log=True, facecolor="green", alpha=0.5,
# label="$E_{lepton}$")
#
#ax.set_title("mean E lepton: %.3f"%(mean(Eelec))+"GeV")
#ax.legend(loc="best")
#ax.grid(b=True,which='major')
#ax.set_ylabel("Nb events")
#ax.set_xlabel("$E$ [GeV]")
plt.show()