Commit 631c85a94f95a402e462ad6a1e0eaf4ec7ab3d86
1 parent
074c1729
Exists in
master
Ad generation computing to Analysis.py
Showing
6 changed files
with
24 additions
and
38 deletions
Show diff stats
Analysis.py
1 | 1 | #!/bin/python |
2 | 2 | |
3 | 3 | from sys import argv |
4 | -from numpy import append,savetxt, shape, array, newaxis, empty | |
4 | +from numpy import append, savetxt, shape, array, newaxis, zeros, arange | |
5 | 5 | from Modules.Read import ReadEnergy, ReadTime, ReadExtraFile, ReadProfile |
6 | 6 | from Modules.Spectrum import spectrum |
7 | 7 | from Modules.Angle import radial, angle_vs_energy |
... | ... | @@ -23,6 +23,8 @@ for fileId in argv[1:]: |
23 | 23 | weightini, generation, theta_arrival, Esource = ReadExtraFile(fileId,[2,3,4,5]) |
24 | 24 | nbPhotonsEmitted=ReadProfile(fileId,[3]) |
25 | 25 | |
26 | + Gen_contrib = [] | |
27 | + Gen_cont = zeros((int(max(generation))+1)) | |
26 | 28 | Source = [] |
27 | 29 | Spectrum = [] |
28 | 30 | Radial = [] |
... | ... | @@ -34,6 +36,17 @@ for fileId in argv[1:]: |
34 | 36 | weight = weightini*(Esource)**(1-powerlaw_index) |
35 | 37 | |
36 | 38 | #=============================================================================# |
39 | + # GENERATION CONTRIBUTION | |
40 | + #=============================================================================# | |
41 | + NbTotEvents = sum(weight) | |
42 | + if Gen_contrib==[]: | |
43 | + Gen_contrib = arange(0,max(generation)+1,1)[:,newaxis] | |
44 | + | |
45 | + for gen in list(set(generation)): | |
46 | + Gen_cont[int(gen)] = sum(weight[generation==gen])/NbTotEvents *100 | |
47 | + Gen_contrib = append(Gen_contrib,Gen_cont[:,newaxis],axis=1) | |
48 | + | |
49 | + #=============================================================================# | |
37 | 50 | # SPECTRUM (SOURCE AND MEASURED) |
38 | 51 | #=============================================================================# |
39 | 52 | nbBins = 100 |
... | ... | @@ -100,6 +113,7 @@ for fileId in argv[1:]: |
100 | 113 | else: |
101 | 114 | Timing = append(Timing,dNdt,axis=1) |
102 | 115 | |
116 | + savetxt(folder+fileId+"/Generation.txt",Gen_contrib) | |
103 | 117 | savetxt(folder+fileId+"/Spectrum.txt",Spectrum) |
104 | 118 | savetxt(folder+fileId+"/Source_spectrum.txt",Source) |
105 | 119 | savetxt(folder+fileId+"/Angle_vs_Energy.txt",Angle_Energy) | ... | ... |
Modules/Generation.py
1 | 1 | from numpy import shape, arange |
2 | 2 | from matplotlib.pyplot import figure, show, hist |
3 | -from Read import ReadExtraFile | |
3 | +from Read import ReadGeneration | |
4 | 4 | |
5 | 5 | |
6 | 6 | def drawGeneration(files): |
... | ... | @@ -11,29 +11,17 @@ def drawGeneration(files): |
11 | 11 | ''' |
12 | 12 | fig = figure() |
13 | 13 | ax = fig.add_subplot(111) |
14 | - nbBins = 7 | |
15 | 14 | for fileId in files: |
16 | - weight, generation = ReadExtraFile(fileId,[2,3]) | |
17 | - print "file", fileId, "->", shape(generation)[0], "events" | |
18 | - hist(generation,nbBins,range=[2,9],log=1,alpha=.5, weights=weight,label=fileId) | |
15 | + i=1 | |
16 | + for powerlaw_index in [1,1.5,2,2.5]: | |
17 | + generation, ratio = ReadGeneration(fileId,[0,i]) | |
18 | + ax.plot(generation-0.5,ratio,drawstyle='steps-mid',label="p=%.1f"%powerlaw_index) | |
19 | 19 | |
20 | 20 | xtick=arange(9) |
21 | 21 | ax.legend(loc='best') |
22 | 22 | ax.set_xticks(xtick+0.5) |
23 | 23 | ax.set_xticklabels(xtick) |
24 | 24 | ax.set_xlabel("Generation") |
25 | - ax.set_ylabel("Number of events") | |
25 | + ax.set_ylabel("Ratio of events [%]") | |
26 | 26 | |
27 | 27 | show() |
28 | - | |
29 | -def GenContribution(fileId): | |
30 | - ''' | |
31 | - compute the contribution to the final events of each | |
32 | - generation | |
33 | - ''' | |
34 | - weight, generation = ReadExtraFile(fileId,[2,3]) | |
35 | - | |
36 | - NbTotEvents = sum(weight) | |
37 | - | |
38 | - for gen in list(set(generation)): | |
39 | - print "Generation", gen, " -> ", sum(weight[generation==gen])/NbTotEvents *100, "\percent" | ... | ... |
Modules/Generation.pyc
No preview for this file type
Modules/Read.py
... | ... | @@ -38,21 +38,6 @@ def ReadMomentum(fileName): |
38 | 38 | def ReadMomentumAngle(fileName): |
39 | 39 | return loadtxt(resultDirectory+fileName+momentumFile,unpack=True,usecols=[4,5]) |
40 | 40 | |
41 | -def ReadCharge(fileName): | |
42 | - return loadtxt(resultDirectory+fileName+extraFile,unpack=True,usecols=[0]) | |
43 | - | |
44 | -def ReadRedshift(fileName): | |
45 | - return loadtxt(resultDirectory+fileName+extraFile,unpack=True,usecols=[1]) | |
46 | - | |
47 | -def ReadWeight(fileName): | |
48 | - return loadtxt(resultDirectory+fileName+extraFile,unpack=True,usecols=[2]) | |
49 | - | |
50 | -def ReadGeneration(fileName): | |
51 | - return loadtxt(resultDirectory+fileName+extraFile,unpack=True,usecols=[3]) | |
52 | - | |
53 | -def ReadArrivalAngle(fileName): | |
54 | - return loadtxt(resultDirectory+fileName+extraFile,unpack=True,usecols=[4]) | |
55 | - | |
56 | 41 | def ReadElmag(fileName): |
57 | 42 | Elmag=resultDirectory+fileName+ElmagFile |
58 | 43 | energy,fluxGamma,fluxLepton = loadtxt(Elmag,unpack=True,usecols=[0,1,2]) |
... | ... | @@ -74,3 +59,6 @@ def ReadRadial(fileName,cols=[0,1,2,3,4]): |
74 | 59 | |
75 | 60 | def ReadTiming(fileName,cols=[0,1,2,3,4]): |
76 | 61 | return loadtxt(resultDirectory+fileName+"/Timing.txt",unpack=True,usecols=cols) |
62 | + | |
63 | +def ReadGeneration(fileName,cols=[0,1,2,3,4]): | |
64 | + return loadtxt(resultDirectory+fileName+"/Generation.txt",unpack=True,usecols=cols) | ... | ... |
Modules/Read.pyc
No preview for this file type
Modules/Timing.py
... | ... | @@ -11,10 +11,6 @@ def timing(time,weight,nbBins=100): |
11 | 11 | Input (optional): generation (default = all) |
12 | 12 | Output: time delay (sec), flux |
13 | 13 | ''' |
14 | - | |
15 | - prop = float(shape(time[time<0])[0])/shape(time)[0] | |
16 | - print shape(time)[0], "events", "negative time:",shape(time[time<0])[0], "~", prop | |
17 | - | |
18 | 14 | time=time[time>0] |
19 | 15 | weight=weight[time>0] |
20 | 16 | ... | ... |