Commit 6633967c42a2496cc15d83555ae091af83b00163
1 parent
631c85a9
Exists in
master
Correction on the computation of the spectrum for generation==0
Showing
8 changed files
with
63 additions
and
31 deletions
Show diff stats
Analysis.py
@@ -7,14 +7,18 @@ from Modules.Spectrum import spectrum | @@ -7,14 +7,18 @@ from Modules.Spectrum import spectrum | ||
7 | from Modules.Angle import radial, angle_vs_energy | 7 | from Modules.Angle import radial, angle_vs_energy |
8 | from Modules.Timing import timing | 8 | from Modules.Timing import timing |
9 | 9 | ||
10 | -def error(error_type): | ||
11 | - print error_type | ||
12 | - exit() | 10 | +def InProgress(fileId,i,Nmax): |
11 | + print "Work on ", fileId, ": ", (i*100)/Nmax, "% done" | ||
13 | 12 | ||
14 | -if shape(argv)[0] < 2: | ||
15 | - error("not enough arguments (at least 1)") | 13 | +if shape(argv)[0] < 2: |
14 | + print "not enough arguments (at least 1)" | ||
15 | + exit() | ||
16 | 16 | ||
17 | +#================================================================# | ||
18 | +# Parameters | ||
19 | +#================================================================# | ||
17 | folder = "Results/" | 20 | folder = "Results/" |
21 | +PowerSpectrum=[1,1.5,2,2.5] | ||
18 | 22 | ||
19 | for fileId in argv[1:]: | 23 | for fileId in argv[1:]: |
20 | # read files | 24 | # read files |
@@ -23,6 +27,17 @@ for fileId in argv[1:]: | @@ -23,6 +27,17 @@ for fileId in argv[1:]: | ||
23 | weightini, generation, theta_arrival, Esource = ReadExtraFile(fileId,[2,3,4,5]) | 27 | weightini, generation, theta_arrival, Esource = ReadExtraFile(fileId,[2,3,4,5]) |
24 | nbPhotonsEmitted=ReadProfile(fileId,[3]) | 28 | nbPhotonsEmitted=ReadProfile(fileId,[3]) |
25 | 29 | ||
30 | + lim =100000 | ||
31 | + time=time[:lim] | ||
32 | + energy=energy[:lim] | ||
33 | + weightini=weightini[:lim] | ||
34 | + generation = generation[:lim] | ||
35 | + theta_arrival = theta_arrival[:lim] | ||
36 | + Esource=Esource[:lim] | ||
37 | + | ||
38 | + cond = (generation==0) | ||
39 | + test=energy[cond]/Esource[cond] | ||
40 | + | ||
26 | Gen_contrib = [] | 41 | Gen_contrib = [] |
27 | Gen_cont = zeros((int(max(generation))+1)) | 42 | Gen_cont = zeros((int(max(generation))+1)) |
28 | Source = [] | 43 | Source = [] |
@@ -31,9 +46,15 @@ for fileId in argv[1:]: | @@ -31,9 +46,15 @@ for fileId in argv[1:]: | ||
31 | Angle_Energy = [] | 46 | Angle_Energy = [] |
32 | Timing = [] | 47 | Timing = [] |
33 | 48 | ||
34 | - for powerlaw_index in [1,1.5,2,2.5]: | 49 | + for powerlaw_index in PowerSpectrum: |
35 | # apply source spectrum | 50 | # apply source spectrum |
36 | - weight = weightini*(Esource)**(1-powerlaw_index) | 51 | + weight_source = Esource**(1-powerlaw_index) |
52 | + weight = weightini* weight_source | ||
53 | + | ||
54 | + print "%e" %(max(weight_source)/min(weight_source)) | ||
55 | + | ||
56 | + #cond = (energy>95) & (energy<105) & (generation==0) | ||
57 | + #print weightini[cond], weight[cond] | ||
37 | 58 | ||
38 | #=============================================================================# | 59 | #=============================================================================# |
39 | # GENERATION CONTRIBUTION | 60 | # GENERATION CONTRIBUTION |
@@ -52,8 +73,9 @@ for fileId in argv[1:]: | @@ -52,8 +73,9 @@ for fileId in argv[1:]: | ||
52 | nbBins = 100 | 73 | nbBins = 100 |
53 | # draw source spectrum | 74 | # draw source spectrum |
54 | Es=array(list(set(Esource))) | 75 | Es=array(list(set(Esource))) |
76 | + print shape(Es) | ||
55 | Ws= (Es)**(1-powerlaw_index) | 77 | Ws= (Es)**(1-powerlaw_index) |
56 | - Es,Fs = spectrum(Es,Ws,nbBins) | 78 | + Es,Fs = spectrum(Es,Ws,nbBins=nbBins) |
57 | Es=Es[:,newaxis] | 79 | Es=Es[:,newaxis] |
58 | Fs=Fs[:,newaxis] | 80 | Fs=Fs[:,newaxis] |
59 | if Source==[]: | 81 | if Source==[]: |
@@ -62,11 +84,8 @@ for fileId in argv[1:]: | @@ -62,11 +84,8 @@ for fileId in argv[1:]: | ||
62 | else: | 84 | else: |
63 | Source = append(Source,Fs,axis=1) | 85 | Source = append(Source,Fs,axis=1) |
64 | 86 | ||
65 | - # primary gamma-rays contribution | ||
66 | - cond = (generation==0) | ||
67 | - ener,flux_0 = spectrum(energy[cond],weight[cond],nbBins) | ||
68 | - # full spectrum | ||
69 | - ener,flux = spectrum(energy,weight,nbBins) | 87 | + # primary gamma-rays contribution and full spectrum |
88 | + ener,flux,flux_0 = spectrum(energy,weight,generation,nbBins) | ||
70 | ener=ener[:,newaxis] | 89 | ener=ener[:,newaxis] |
71 | flux=flux[:,newaxis] | 90 | flux=flux[:,newaxis] |
72 | flux_0=flux_0[:,newaxis] | 91 | flux_0=flux_0[:,newaxis] |
@@ -113,6 +132,8 @@ for fileId in argv[1:]: | @@ -113,6 +132,8 @@ for fileId in argv[1:]: | ||
113 | else: | 132 | else: |
114 | Timing = append(Timing,dNdt,axis=1) | 133 | Timing = append(Timing,dNdt,axis=1) |
115 | 134 | ||
135 | + InProgress(fileId,PowerSpectrum.index(powerlaw_index)+1,shape(PowerSpectrum)[0]) | ||
136 | + | ||
116 | savetxt(folder+fileId+"/Generation.txt",Gen_contrib) | 137 | savetxt(folder+fileId+"/Generation.txt",Gen_contrib) |
117 | savetxt(folder+fileId+"/Spectrum.txt",Spectrum) | 138 | savetxt(folder+fileId+"/Spectrum.txt",Spectrum) |
118 | savetxt(folder+fileId+"/Source_spectrum.txt",Source) | 139 | savetxt(folder+fileId+"/Source_spectrum.txt",Source) |
Modules/Angle.pyc
No preview for this file type
Modules/Generation.py
@@ -15,12 +15,11 @@ def drawGeneration(files): | @@ -15,12 +15,11 @@ def drawGeneration(files): | ||
15 | i=1 | 15 | i=1 |
16 | for powerlaw_index in [1,1.5,2,2.5]: | 16 | for powerlaw_index in [1,1.5,2,2.5]: |
17 | generation, ratio = ReadGeneration(fileId,[0,i]) | 17 | generation, ratio = ReadGeneration(fileId,[0,i]) |
18 | - ax.plot(generation-0.5,ratio,drawstyle='steps-mid',label="p=%.1f"%powerlaw_index) | 18 | + ax.plot(generation,ratio,drawstyle='steps-mid',label="p=%.1f"%powerlaw_index) |
19 | 19 | ||
20 | xtick=arange(9) | 20 | xtick=arange(9) |
21 | ax.legend(loc='best') | 21 | ax.legend(loc='best') |
22 | - ax.set_xticks(xtick+0.5) | ||
23 | - ax.set_xticklabels(xtick) | 22 | + ax.set_yscale('log') |
24 | ax.set_xlabel("Generation") | 23 | ax.set_xlabel("Generation") |
25 | ax.set_ylabel("Ratio of events [%]") | 24 | ax.set_ylabel("Ratio of events [%]") |
26 | 25 |
Modules/Generation.pyc
No preview for this file type
Modules/Spectrum.py
@@ -5,20 +5,32 @@ from Read import ReadSpectrum, ReadSourceSpectrum | @@ -5,20 +5,32 @@ from Read import ReadSpectrum, ReadSourceSpectrum | ||
5 | from Constants import degre | 5 | from Constants import degre |
6 | from Analytic import Ethreshold_gg | 6 | from Analytic import Ethreshold_gg |
7 | 7 | ||
8 | -def spectrum(energy,weight,nbBins=100): | 8 | +def spectrum(energy,weight,generation=[],nbBins=100): |
9 | ''' | 9 | ''' |
10 | Compute flux versus energy | 10 | Compute flux versus energy |
11 | Input: events energy and weight (optional: number of bins) | 11 | Input: events energy and weight (optional: number of bins) |
12 | Output: energy, flux (E^2 dN/dE) | 12 | Output: energy, flux (E^2 dN/dE) |
13 | ''' | 13 | ''' |
14 | + Emin=min(energy) | ||
15 | + Emax=max(energy) | ||
14 | energy =log10(energy) | 16 | energy =log10(energy) |
15 | - flux,ener=histogram(energy,nbBins,weights=weight) | 17 | + flux,ener=histogram(energy,nbBins,range=[log10(Emin),log10(Emax)],weights=weight) |
16 | ener = 10**ener | 18 | ener = 10**ener |
17 | enercenter=(ener[1:nbBins+1]+ener[0:nbBins])/2 | 19 | enercenter=(ener[1:nbBins+1]+ener[0:nbBins])/2 |
18 | binSize=ener[1:nbBins+1]-ener[0:nbBins] | 20 | binSize=ener[1:nbBins+1]-ener[0:nbBins] |
19 | flux = enercenter**2 * flux/binSize | 21 | flux = enercenter**2 * flux/binSize |
20 | - flux /= max(flux) #nbPhotonsEmitted | ||
21 | - return enercenter,flux | 22 | + |
23 | + if generation == []: | ||
24 | + return enercenter,flux | ||
25 | + else: | ||
26 | + cond=(generation==0) | ||
27 | + flux_0,ener_0=histogram(energy[cond],nbBins,range=[log10(Emin),log10(Emax)],weights=weight[cond]) | ||
28 | + ener_0 = 10**ener_0 | ||
29 | + enercenter_0=(ener_0[1:nbBins+1]+ener_0[0:nbBins])/2 | ||
30 | + binSize=ener_0[1:nbBins+1]-ener_0[0:nbBins] | ||
31 | + flux_0 = enercenter_0**2 * flux_0/binSize | ||
32 | + return enercenter,flux,flux_0 | ||
33 | + | ||
22 | 34 | ||
23 | def drawSpectrum(files,PlotAnalytic=False): | 35 | def drawSpectrum(files,PlotAnalytic=False): |
24 | ''' | 36 | ''' |
@@ -34,19 +46,19 @@ def drawSpectrum(files,PlotAnalytic=False): | @@ -34,19 +46,19 @@ def drawSpectrum(files,PlotAnalytic=False): | ||
34 | ax2 = fig.add_subplot(gs[1],sharex=ax1) | 46 | ax2 = fig.add_subplot(gs[1],sharex=ax1) |
35 | 47 | ||
36 | for fileId in files: | 48 | for fileId in files: |
37 | - i=1 | ||
38 | - j=1 | 49 | + i=1#3 |
50 | + j=1#5 | ||
39 | for powerlaw_index in [1,1.5,2,2.5]: | 51 | for powerlaw_index in [1,1.5,2,2.5]: |
40 | # read files | 52 | # read files |
41 | Es,Fs = ReadSourceSpectrum(fileId,[0,i]) | 53 | Es,Fs = ReadSourceSpectrum(fileId,[0,i]) |
42 | - p = ax1.plot(Es,Fs,drawstyle='--') | 54 | + p = ax1.plot(Es,Fs,drawstyle='.') |
43 | # draw full spectrum | 55 | # draw full spectrum |
44 | ener,flux,flux_0 = ReadSpectrum(fileId,[0,j,j+1]) | 56 | ener,flux,flux_0 = ReadSpectrum(fileId,[0,j,j+1]) |
45 | - ax1.plot(ener,flux,color=p[0].get_color(),drawstyle='-',label="p=%.1f"%powerlaw_index) | 57 | + ax1.plot(ener,flux,color=p[0].get_color(),drawstyle='steps-mid',label="p=%.1f"%powerlaw_index) |
46 | # primary gamma-rays contribution | 58 | # primary gamma-rays contribution |
47 | - ax1.plot(ener,flux_0,color=p[0].get_color(),linestyle='-.') | 59 | + ax1.plot(ener,flux_0,color=p[0].get_color(),linestyle='--',drawstyle='steps-mid') |
48 | contrib=flux_0/flux | 60 | contrib=flux_0/flux |
49 | - ax2.plot(ener,contrib,'-',color=p[0].get_color()) | 61 | + ax2.plot(ener,contrib,drawstyle='steps-mid',color=p[0].get_color()) |
50 | 62 | ||
51 | i+=1 | 63 | i+=1 |
52 | j+=2 | 64 | j+=2 |
Modules/Spectrum.pyc
No preview for this file type
Modules/Timing.py
@@ -56,9 +56,9 @@ def drawDelay_vs_angle(fileId): | @@ -56,9 +56,9 @@ def drawDelay_vs_angle(fileId): | ||
56 | ax = fig.add_subplot(111) | 56 | ax = fig.add_subplot(111) |
57 | nbBins = 100 | 57 | nbBins = 100 |
58 | 58 | ||
59 | - theta = ReadExtraFile(fileId,[4]) | ||
60 | - energy = ReadEnergy(fileId) | ||
61 | - delay = ReadTime(fileId) | 59 | + theta = ReadExtraFile(fileId,[4]) |
60 | + energy = ReadEnergy(fileId) | ||
61 | + delay = ReadTime(fileId) | ||
62 | 62 | ||
63 | for n in arange(0,8,2): | 63 | for n in arange(0,8,2): |
64 | Emin = 10**(3-n) #GeV | 64 | Emin = 10**(3-n) #GeV |
@@ -74,14 +74,14 @@ def drawDelay_vs_angle(fileId): | @@ -74,14 +74,14 @@ def drawDelay_vs_angle(fileId): | ||
74 | dtheta=10**dtheta | 74 | dtheta=10**dtheta |
75 | thetacenter=(dtheta[1:nbBins+1]+dtheta[0:nbBins])/2 | 75 | thetacenter=(dtheta[1:nbBins+1]+dtheta[0:nbBins])/2 |
76 | dt=dt/dN | 76 | dt=dt/dN |
77 | - ax.plot(thetacenter,dt,color='k',linestyle="steps-mid",linewidth=2) | 77 | + ax.plot(thetacenter,dt,color='m',linestyle="steps-mid",linewidth=2) |
78 | 78 | ||
79 | thmin = 1.e-8 | 79 | thmin = 1.e-8 |
80 | thmax = pi/2. | 80 | thmax = pi/2. |
81 | nth = 1000 | 81 | nth = 1000 |
82 | th = thmin*(thmax/thmin)**(arange(nth)/(nth-1.)) | 82 | th = thmin*(thmax/thmin)**(arange(nth)/(nth-1.)) |
83 | delay_fit = Analytic_delay_vs_theta(th,fileId) | 83 | delay_fit = Analytic_delay_vs_theta(th,fileId) |
84 | - ax.plot(th,delay_fit,'--m',linewidth=2) | 84 | + ax.plot(th,delay_fit,'--k',linewidth=2) |
85 | 85 | ||
86 | ax.set_xscale('log') | 86 | ax.set_xscale('log') |
87 | ax.set_yscale('log') | 87 | ax.set_yscale('log') |
Modules/Timing.pyc
No preview for this file type