Commit 4448ea24ac7838ad3cb055ce3b6832aafd4eda5a

Authored by Thomas Fitoussi
1 parent d33c0beb
Exists in master

Time distribution

add a comparison between different precision on zlim
Add a test on generation and charge in all scripts
Angle_distribution.py
... ... @@ -48,7 +48,7 @@ ind = 0
48 48 for fileId in argv[2:]:
49 49 energy,dirx,diry,dirz = loadtxt(fileName+fileId+"/Results_momentum",unpack=True,usecols=[0,1,2,3])
50 50 posx,posy,posz = loadtxt(fileName+fileId+"/Results_position",unpack=True,usecols=[1,2,3])
51   - weight,gen=loadtxt(fileName+fileId+"/Results_extra",unpack=True,usecols=[2,3])
  51 + charge,weight,gen=loadtxt(fileName+fileId+"/Results_extra",unpack=True,usecols=[0,2,3])
52 52  
53 53 hyp=sqrt(posx**2+posy**2+posz**2)
54 54 posx=posx/hyp
... ... @@ -59,7 +59,7 @@ for fileId in argv[2:]:
59 59 diry=diry/hyp
60 60 dirz=dirz/hyp
61 61 costheta=dirx*posx+diry*posy+dirz*posz
62   - cond=(costheta<=1)&(costheta>=-1)&(gen==2)
  62 + cond=(costheta<=1)&(costheta>=-1)&(charge==0)
63 63 theta = arccos(costheta[cond])*degre
64 64 weight= weight[cond]
65 65 energy= energy[cond]
... ...
Arrival_direction.py
... ... @@ -14,7 +14,7 @@ if len(argv)&lt;2:
14 14 nbBins = 50
15 15 degre= 180/np.pi
16 16 borne=5 # degree
17   -Elim=1e-3 # GeV
  17 +Elim=1e-6 # GeV
18 18  
19 19 fig = plt.figure()
20 20  
... ...
Energy_distribution.py
... ... @@ -39,7 +39,11 @@ Emin = min(Edata)
39 39 ind = 0
40 40 for fileId in argv[2:]:
41 41 energy= np.loadtxt(fileName+fileId+"/Results_momentum",unpack=True,usecols=[0])
42   - weight= np.loadtxt(fileName+fileId+"/Results_extra",unpack=True,usecols=[2])
  42 + charge,weight=np.loadtxt(fileName+fileId+"/Results_extra",unpack=True,usecols=[0,2])
  43 +
  44 + cond= (charge==0)
  45 + energy=energy[cond]
  46 + weight=weight[cond]
43 47 print "data shape:", np.shape(energy)
44 48  
45 49 Edata =np.log10(energy)
... ... @@ -54,14 +58,13 @@ for fileId in argv[2:]:
54 58 label="$J_\gamma$ $10^{-%.0f"%float(fileId)+"}$Gauss")
55 59 elif argv[1] == "EBL":
56 60 ax.plot(enercenter,flux[:]/max(flux),"."+color[ind],label=Model[int(fileId)-1])
57   -
58   - # Results from Elmag
59   - Elmag=fileName+fileId+"/spec_diff_test"
60   - if os.path.isfile(Elmag):
61   - energy,fluxGamma,fluxLepton = np.loadtxt(Elmag,unpack=True,usecols=[0,1,2])
62   - energy=energy*10**(-9)
63   - flux=fluxGamma+fluxLepton
64   - ax.plot(energy,flux/max(flux),"-"+color[ind],label="Elmag - "+Model[int(fileId)-1])
  61 + # Results from Elmag
  62 + Elmag=fileName+fileId+"/spec_diff_test"
  63 + if os.path.isfile(Elmag):
  64 + energy,fluxGamma,fluxLepton = np.loadtxt(Elmag,unpack=True,usecols=[0,1,2])
  65 + energy=energy*10**(-9)
  66 + flux=fluxGamma+fluxLepton
  67 + ax.plot(energy,flux/max(flux),"-"+color[ind],label="Elmag - "+Model[int(fileId)-1])
65 68  
66 69 ind=ind+1
67 70  
... ...
Generation_distribution.py
... ... @@ -10,7 +10,7 @@ if len(argv)&lt;2:
10 10  
11 11 # figure: energy distribution
12 12 #=============================
13   -nbBins = 8
  13 +nbBins = 7
14 14 color=['b','g','r','c','m','y']
15 15  
16 16 fig = plt.figure()
... ... @@ -20,7 +20,7 @@ ind = 0
20 20 for fileId in argv[1:]:
21 21 weight,nbGen=np.loadtxt("Results_EGMF"+fileId+"/Results_extra",unpack=True,usecols=[2,3])
22 22  
23   - plt.hist(nbGen,nbBins, weights=weight,range=[1,9],log=1,facecolor=color[ind],alpha=.5,
  23 + plt.hist(nbGen,nbBins,range=[2,9],log=1,facecolor=color[ind],alpha=.5, weights=weight,
24 24 label="$10^{-%.0f"%float(fileId)+"}$Gauss")
25 25 ind=ind+1
26 26  
... ...
Time_distribution.py
... ... @@ -2,10 +2,9 @@
2 2  
3 3 from sys import argv
4 4 import os.path
5   -import numpy as np
6   -from scipy.optimize import curve_fit
7 5 import matplotlib.pyplot as plt
8   -from Constantes import s_to_yr
  6 +from Constantes import *
  7 +from scipy.integrate import quad
9 8  
10 9 if argv[1] == "EGMF":
11 10 fileName="Results_EGMF"
... ... @@ -14,6 +13,9 @@ elif argv[1] == &quot;EBL&quot;:
14 13 B=10**(-15)
15 14 Model=["Kneiske and Doll - 'best fit'","Kneiske and Doll - 'lower limit'",
16 15 "Franceschini","Finke and Al","Gilmore and Al","Dominguez and Al"]
  16 +elif argv[1] == "prec":
  17 + fileName="Results_prec"
  18 + B=10**(-17)
17 19 else:
18 20 print "Used: ./Energy_distribution.py arg1 ind1 ind2 ..."
19 21 print " arg1 = EGMF or EBL "
... ... @@ -25,39 +27,57 @@ else:
25 27  
26 28 # figure: energy distribution
27 29 #=============================
28   -nbBins = 200
29   -convert= 180/np.pi
  30 +zSource = 0.0308
  31 +nbBins = 100
  32 +convert= 180/pi
30 33 color=['b','r','g','c','m','y']
31 34  
32 35 fig = plt.figure()
33 36 ax = fig.add_subplot(111)
34 37  
35   -time= np.loadtxt(fileName+argv[2]+"/Results_position",unpack=True,usecols=[0])
  38 +def properTime(z):
  39 + return -1/(H0*(1+z)*sqrt(omegaM*(1+z)**3+omegaK*(1+z)**2+omegaL))
  40 +
  41 +tlim = quad(properTime,zSource,0)[0]/s_to_yr
  42 +print tlim
  43 +
  44 +time= loadtxt(fileName+argv[2]+"/Results_position",unpack=True,usecols=[0])
  45 +time=time[time>0]
  46 +time=time/tlim
36 47 tmax = max(time)
37 48 tmin = min(time)
38 49 print tmin, tmax
39 50  
40 51 ind = 0
41 52 for fileId in argv[2:]:
42   - time= np.loadtxt(fileName+fileId+"/Results_position",unpack=True,usecols=[0])
43   - weight,gen=np.loadtxt(fileName+fileId+"/Results_extra",unpack=True,usecols=[2,3])
  53 + time= loadtxt(fileName+fileId+"/Results_position",unpack=True,usecols=[0])
  54 + charge,weight,gen=loadtxt(fileName+fileId+"/Results_extra",unpack=True,usecols=[0,2,3])
  55 + time=time/tlim
  56 +
  57 + prop = float(shape(time[time<0])[0])/shape(time)[0]
  58 + print "data shape",fileName+fileId,":", shape(time), "negative time:", shape(time[time<0]), "~", prop
44 59  
45   - cond=(gen<8)
  60 + cond= (gen<10) & (time>0) & (charge==0)
46 61 time=time[cond]
47 62 weight=weight[cond]
  63 + time=log10(time)
48 64  
49   - print "data shape",fileName+fileId,":", np.shape(time)
50   -
51   - dN,dt=np.histogram(time,nbBins,range=(tmin,tmax),weights=weight)
  65 + dN,dt=histogram(time,nbBins,range=(log10(tmin),log10(tmax)),weights=weight)
  66 + #time=10**time
52 67 timecenter=(dt[1:nbBins+1]+dt[0:nbBins])/2
53 68 binSize=dt[1:nbBins+1]-dt[0:nbBins]
54 69 dNdt=dN/binSize
55 70  
56 71 if argv[1] == "EGMF":
57   - #ax.hist(time,nbBins,weights=weight,range=(tmin,tmax),log=1,facecolor=color[ind],alpha=.5,
58   - # label="$10^{-%.0f"%float(fileId)+"}$Gauss")
  72 + ax.hist(time,nbBins,weights=weight,range=(log10(tmin),log10(tmax)),log=1,facecolor=color[ind],
  73 + alpha=.5, label="$10^{-%.0f"%float(fileId)+"}$Gauss")
59 74 ax.plot(timecenter[dNdt!=0],dNdt[dNdt!=0],"-"+color[ind],
60 75 label="$10^{-%.0f"%float(fileId)+"}$Gauss")
  76 + elif argv[1] == "prec":
  77 + ax.hist(time,nbBins,weights=weight,range=(log10(tmin),log10(tmax)),log=1,facecolor=color[ind],
  78 + alpha=.5)#, label="prec = $10^{-%.0f"%float(fileId)+"}$")
  79 + ax.plot(timecenter[dNdt!=0],dNdt[dNdt!=0],"-"+color[ind],
  80 + label="prec = $10^{-%.0f"%float(fileId)+"}$")
61 81 elif argv[1] == "EBL":
62 82 #plt.hist(time,nbBins,weights=weight,range=(tmin,tmax),log=1,facecolor=color[ind],alpha=.5,
63 83 ax.plot(timecenter,dNdt,"."+color[ind],
... ... @@ -69,7 +89,9 @@ for fileId in argv[2:]:
69 89 #ax.set_yscale('log')
70 90 ax.grid(b=True,which='major')
71 91 ax.legend(loc="best")
72   -ax.set_xlabel("Time [yr]")
73   -ax.set_ylabel("$dN/dt$ [yr$^{-1}$]")
  92 +if argv[1]=="prec":
  93 + ax.legend(loc="best",title="$10^{-17}$Gauss")
  94 +ax.set_xlabel("Time [$\Delta t / t$ log scale]")
  95 +ax.set_ylabel("$t\ dN/dt$")
74 96  
75 97 plt.show()
... ...