Blame view

Time_distribution.py 3.01 KB
d33c0beb   Thomas Fitoussi   Add time distribu...
1
2
3
4
#!/usr/bin/python

from sys import argv
import os.path
d33c0beb   Thomas Fitoussi   Add time distribu...
5
import matplotlib.pyplot as plt
4448ea24   Thomas Fitoussi   Time distribution
6
7
from Constantes import *
from scipy.integrate import quad
d33c0beb   Thomas Fitoussi   Add time distribu...
8
9
10
11
12
13
14
15

if argv[1] == "EGMF":
   fileName="Results_EGMF"
elif argv[1] == "EBL":
   fileName="Results_EBL"
   B=10**(-15)
   Model=["Kneiske and Doll - 'best fit'","Kneiske and Doll - 'lower limit'",
         "Franceschini","Finke and Al","Gilmore and Al","Dominguez and Al"]
4448ea24   Thomas Fitoussi   Time distribution
16
17
18
elif argv[1] == "prec":
   fileName="Results_prec"
   B=10**(-17)
d33c0beb   Thomas Fitoussi   Add time distribu...
19
20
21
22
23
24
25
26
27
28
29
else:
   print "Used: ./Energy_distribution.py arg1 ind1 ind2 ..."
   print "        arg1 = EGMF or EBL "
   print "        ind1 = file number \n"
   print "Examples: "
   print "   to study EGMF14: ./Energy_distribution.py EGMF 14 "
   print "   to study EBL1 and EBL2: ./Energy_distribution.py EBL 1 2 \n"
   exit()

# figure: energy distribution
#=============================
4448ea24   Thomas Fitoussi   Time distribution
30
31
32
zSource = 0.0308
nbBins = 100
convert= 180/pi
d33c0beb   Thomas Fitoussi   Add time distribu...
33
34
35
36
37
color=['b','r','g','c','m','y']

fig = plt.figure()
ax = fig.add_subplot(111)

4448ea24   Thomas Fitoussi   Time distribution
38
39
40
41
42
43
44
45
46
def properTime(z):
   return -1/(H0*(1+z)*sqrt(omegaM*(1+z)**3+omegaK*(1+z)**2+omegaL))

tlim = quad(properTime,zSource,0)[0]/s_to_yr
print tlim

time= loadtxt(fileName+argv[2]+"/Results_position",unpack=True,usecols=[0])
time=time[time>0]
time=time/tlim
d33c0beb   Thomas Fitoussi   Add time distribu...
47
48
49
50
51
52
tmax = max(time)
tmin = min(time) 
print tmin, tmax

ind = 0
for fileId in argv[2:]:
4448ea24   Thomas Fitoussi   Time distribution
53
54
55
56
57
58
   time= loadtxt(fileName+fileId+"/Results_position",unpack=True,usecols=[0])
   charge,weight,gen=loadtxt(fileName+fileId+"/Results_extra",unpack=True,usecols=[0,2,3])
   time=time/tlim

   prop = float(shape(time[time<0])[0])/shape(time)[0]
   print "data shape",fileName+fileId,":", shape(time), "negative time:", shape(time[time<0]), "~", prop
d33c0beb   Thomas Fitoussi   Add time distribu...
59

4448ea24   Thomas Fitoussi   Time distribution
60
   cond= (gen<10) & (time>0) & (charge==0)
d33c0beb   Thomas Fitoussi   Add time distribu...
61
62
   time=time[cond]
   weight=weight[cond]
4448ea24   Thomas Fitoussi   Time distribution
63
   time=log10(time)
d33c0beb   Thomas Fitoussi   Add time distribu...
64

4448ea24   Thomas Fitoussi   Time distribution
65
66
   dN,dt=histogram(time,nbBins,range=(log10(tmin),log10(tmax)),weights=weight)
   #time=10**time
d33c0beb   Thomas Fitoussi   Add time distribu...
67
68
69
70
71
   timecenter=(dt[1:nbBins+1]+dt[0:nbBins])/2
   binSize=dt[1:nbBins+1]-dt[0:nbBins]
   dNdt=dN/binSize

   if argv[1] == "EGMF":
4448ea24   Thomas Fitoussi   Time distribution
72
73
      ax.hist(time,nbBins,weights=weight,range=(log10(tmin),log10(tmax)),log=1,facecolor=color[ind],
            alpha=.5, label="$10^{-%.0f"%float(fileId)+"}$Gauss")
d33c0beb   Thomas Fitoussi   Add time distribu...
74
75
      ax.plot(timecenter[dNdt!=0],dNdt[dNdt!=0],"-"+color[ind],
         label="$10^{-%.0f"%float(fileId)+"}$Gauss")
4448ea24   Thomas Fitoussi   Time distribution
76
77
78
79
80
   elif argv[1] == "prec":
      ax.hist(time,nbBins,weights=weight,range=(log10(tmin),log10(tmax)),log=1,facecolor=color[ind],
            alpha=.5)#, label="prec = $10^{-%.0f"%float(fileId)+"}$")
      ax.plot(timecenter[dNdt!=0],dNdt[dNdt!=0],"-"+color[ind],
            label="prec = $10^{-%.0f"%float(fileId)+"}$")
d33c0beb   Thomas Fitoussi   Add time distribu...
81
82
83
84
85
86
87
88
89
90
91
   elif argv[1] == "EBL":
      #plt.hist(time,nbBins,weights=weight,range=(tmin,tmax),log=1,facecolor=color[ind],alpha=.5,
      ax.plot(timecenter,dNdt,"."+color[ind],
         label=Model[int(fileId)-1])

   ind=ind+1

#ax.set_xscale('log')
#ax.set_yscale('log')
ax.grid(b=True,which='major')
ax.legend(loc="best")
4448ea24   Thomas Fitoussi   Time distribution
92
93
94
95
if argv[1]=="prec":
   ax.legend(loc="best",title="$10^{-17}$Gauss")
ax.set_xlabel("Time [$\Delta t / t$ log scale]")
ax.set_ylabel("$t\ dN/dt$")
d33c0beb   Thomas Fitoussi   Add time distribu...
96
97

plt.show()