Blame view

Modules/Angle.py 3.46 KB
65135318   Thomas Fitoussi   Reset modules
1
2
from numpy import log10, histogram
from matplotlib.pyplot import figure, show
7030f150   Thomas Fitoussi   Full reorganisati...
3
from matplotlib import gridspec
074c1729   Thomas Fitoussi   Analysis.py used ...
4
from Read import ReadRadial, ReadAngleVsEnergy
7030f150   Thomas Fitoussi   Full reorganisati...
5
from Analytic import Analytic_theta
7030f150   Thomas Fitoussi   Full reorganisati...
6
7
from Constants import degre

138898c8   Thomas Fitoussi   Computation of ra...
8
def angle_vs_energy(theta,energy,weight,nbBins=50):
f4246390   Thomas Fitoussi   Improve angular d...
9
10
11
12
13
   '''
      Compute arrival angle versus energy
      Input: directory name
      Output: energy, arrival angle
   '''
138898c8   Thomas Fitoussi   Computation of ra...
14

7030f150   Thomas Fitoussi   Full reorganisati...
15
   energy =log10(energy)
138898c8   Thomas Fitoussi   Computation of ra...
16
17
   angle,ener = histogram(energy,nbBins,weights=weight*theta)
   nb,   ener = histogram(energy,nbBins,weights=weight)
7030f150   Thomas Fitoussi   Full reorganisati...
18
   ener = 10**ener
138898c8   Thomas Fitoussi   Computation of ra...
19
20
21
   enercenter = (ener[1:nbBins+1]+ener[0:nbBins])/2
   angle /= nb

484df032   Thomas Fitoussi   Correction on the...
22
23
24
   return enercenter, angle

def radial(theta,weight,nbBins=50):
138898c8   Thomas Fitoussi   Computation of ra...
25
   cond = theta!=0
484df032   Thomas Fitoussi   Correction on the...
26
   theta = 2*log10(theta[cond])
138898c8   Thomas Fitoussi   Computation of ra...
27
   weight = weight[cond]
484df032   Thomas Fitoussi   Correction on the...
28
29
30
31
   dn,angle2 = histogram(theta,nbBins,range=[2*log10(1e-3),2*log10(25)],weights=weight)
   angle2=10**angle2
   #theta = theta**2
   #dn,angle2 = histogram(theta,nbBins,range=[0,25],weights=weight)
138898c8   Thomas Fitoussi   Computation of ra...
32
33
34
35
   thetacenter = (angle2[1:nbBins+1]+angle2[0:nbBins])/2
   dtheta = angle2[1:nbBins+1]-angle2[0:nbBins]
   dndtheta = dn/dtheta
   dndtheta /= max(dndtheta)
7030f150   Thomas Fitoussi   Full reorganisati...
36

484df032   Thomas Fitoussi   Correction on the...
37
   return thetacenter, dndtheta
138898c8   Thomas Fitoussi   Computation of ra...
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
 
def drawRadial(files,all_source_spectrum=False,all_jets=False):
   '''
      Plot flux versus arrival angle
      Input: list of directories
      Output: graph of flux versus angle
   '''
   fig = figure()
   ax = fig.add_subplot(111)

   for fileId in files:
      if all_source_spectrum:
         i=1
         for powerlaw_index in [1,1.5,2,2.5]: 
            theta,dndtheta2 = ReadRadial(fileId,[0,i])
            ax.plot(theta,dndtheta2,drawstyle='steps-mid',label="p=%.1f"%powerlaw_index)
            i+=1
      elif all_jets:
         i=5
         for jet_opening in ["isotrop","60 deg","30 deg"]: 
            theta,dndtheta2 = ReadRadial(fileId,[0,i])
            ax.plot(theta,dndtheta2,drawstyle='steps-mid',label=jet_opening)
            i+=1
      else:
         theta,dndtheta2 = ReadRadial(fileId,[0,5])
         ax.plot(theta,dndtheta2,drawstyle='steps-mid',label=fileId)

   ax.legend(loc="best")
484df032   Thomas Fitoussi   Correction on the...
66
   ax.set_xscale('log')
138898c8   Thomas Fitoussi   Computation of ra...
67
68
69
   ax.set_yscale('log')
   ax.grid(b=True,which='major')
   ax.set_xlabel("$\\theta^2$ [deg$^2$]")
484df032   Thomas Fitoussi   Correction on the...
70
   ax.set_ylabel("$dN/d\\theta^2$ [arbitrary]")
138898c8   Thomas Fitoussi   Computation of ra...
71
72
   
   show()
7030f150   Thomas Fitoussi   Full reorganisati...
73

484df032   Thomas Fitoussi   Correction on the...
74
def drawAngle_vs_energy(files,all_source_spectrum=False,all_jets=False,PlotAnalytic=False):
f4246390   Thomas Fitoussi   Improve angular d...
75
76
77
78
79
   '''
      Plot arrival angle versus energy + analytic expression
      Input: list of directories
      Output: graph of arrival angle versus energy
   '''
7030f150   Thomas Fitoussi   Full reorganisati...
80
   fig = figure()
65135318   Thomas Fitoussi   Reset modules
81
   ax1 = fig.add_subplot(111)
7030f150   Thomas Fitoussi   Full reorganisati...
82
83

   for fileId in files:
484df032   Thomas Fitoussi   Correction on the...
84
85
86
87
88
89
90
91
92
93
94
95
96
      if all_source_spectrum:
         i=1
         for powerlaw_index in [1,1.5,2,2.5]: 
            ener,angle = ReadAngleVsEnergy(fileId,[0,i])
            p=ax1.plot(ener,angle,drawstyle='steps-mid',label="p=%.1f"%powerlaw_index)
      elif all_jets:
         i=5
         for jet_opening in ["isotrop","60 deg","30 deg"]: 
            ener,angle = ReadAngleVsEnergy(fileId,[0,i])
            p=ax1.plot(ener,angle,drawstyle='steps-mid',label=jet_opening)
      else:
         ener,angle = ReadAngleVsEnergy(fileId,[0,1])
         p=ax1.plot(ener,angle,drawstyle='steps-mid',label=fileId)
65135318   Thomas Fitoussi   Reset modules
97

484df032   Thomas Fitoussi   Correction on the...
98
99
100
      if PlotAnalytic:
         yfit = Analytic_theta(ener,fileId)
         ax1.plot(ener,yfit,'--',color=p[0].get_color(),linewidth=2,label="analytic")
7030f150   Thomas Fitoussi   Full reorganisati...
101
102
103
104
105
106

   ax1.legend(loc="best")
   ax1.set_xscale('log')
   ax1.set_yscale('log')
   ax1.set_ylim([0,180])
   ax1.grid(b=True,which='major')
484df032   Thomas Fitoussi   Correction on the...
107
   ax1.set_ylabel("$\\theta$ [deg]")
65135318   Thomas Fitoussi   Reset modules
108
   ax1.set_xlabel("energy [GeV]")
7030f150   Thomas Fitoussi   Full reorganisati...
109
110

   show()