3import ROOT,os,sys,getopt,time,shipRoot_conf
50 ROOT.gRandom.SetSeed(theSeed)
54 timer = ROOT.TStopwatch()
57 gFairBaseContFact = ROOT.FairBaseContFact()
58 run = ROOT.FairRunSim()
60 if nev==0: run.SetOutputFile(
"dummy.root")
61 else: run.SetOutputFile(outFile)
62 run.SetUserConfig(
"g4Config.C")
63 rtdb = run.GetRuntimeDb()
65 run.SetMaterials(
"media.geo")
67 cave= ROOT.ShipCave(
"CAVE")
68 cave.SetGeometryFileName(
"cave.geo")
71 target = ROOT.simpleTarget()
72 material, thickness, 0
74 target.SetEnergyCut(ecut*u.GeV)
75 if storeOnlyMuons: target.SetOnlyMuons()
76 target.SetParameters(material,thickness,0.)
79 primGen = ROOT.FairPrimaryGenerator()
80 myPgun = ROOT.FairBoxGenerator(13,1)
81 if s==
"NA62": myPgun.SetPRange(momentum,maxTheta)
82 else: myPgun.SetPRange(momentum-0.01,momentum+0.01)
83 myPgun.SetPhiRange(0,0)
84 myPgun.SetThetaRange(0,0)
85 myPgun.SetXYZ(0.*u.cm, 0.*u.cm, -1.*u.mm - (thickness) )
86 primGen.AddGenerator(myPgun)
88 run.SetGenerator(primGen)
92 gMC = ROOT.TVirtualMC.GetMC()
94 fStack = gMC.GetStack()
95 fStack.SetMinPoints(1)
96 fStack.SetEnergyCut(-1.)
99 print(
"run for ",nev,
"events")
103 ROOT.gROOT.ProcessLine(
'#include "Geant4/G4EmParameters.hh"')
104 emP = ROOT.G4EmParameters.Instance()
106 h[
'f']= ROOT.gROOT.GetListOfFiles()[0].GetName()
109 rtime = timer.RealTime()
110 ctime = timer.CpuTime()
112 print(
"Macro finished succesfully.")
113 print(
"Output file is ", outFile)
114 print(
"Real time ",rtime,
" s, CPU time ",ctime,
"s")
118 sGeo=ROOT.gGeoManager
120 v = sGeo.FindVolumeFast(
'target')
122 length = v.GetShape().GetDZ()*2
123 print(
"Material:",m.GetName(),
'total interaction length=',length/m.GetIntLen(),
'total rad length=',length/m.GetRadLen())
127 print(
"Use predefined values:",density,length)
129 ut.bookHist(h,
'theta',
'scattering angle '+str(momentum)+
'GeV/c;{Theta}(rad)',500,0,maxTheta)
130 ut.bookHist(h,
'eloss',
'rel energy loss as function of momentum GeV/c',100,0,maxTheta,10000,0.,1.)
131 ut.bookHist(h,
'elossRaw',
'energy loss as function of momentum GeV/c',100,0,maxTheta, 10000,0.,100.)
133 for n
in range(sTree.GetEntries()):
134 rc = sTree.GetEvent(n)
135 Ein = sTree.MCTrack[0].GetEnergy()
136 M = sTree.MCTrack[0].GetMass()
138 for aHit
in sTree.vetoPoint:
139 Eloss+=aHit.GetEnergyLoss()
141 rc = h[
'eloss'].Fill(Ein,Eloss/Ein)
142 rc = h[
'elossRaw'].Fill(Ein,Eloss)
143 ut.bookCanvas(h,key=s,title=s,nx=900,ny=600,cx=1,cy=1)
147 h[
'95'] = h[
'eloss'].ProjectionX(
'95',96,100)
149 h[
'0'] = h[
'eloss'].ProjectionX(
'0',1,100)
151 rc = h[
'95'].Divide(h[
'0'] )
153 h[
'meanEloss'] = h[
'elossRaw'].ProjectionX()
154 for n
in range(1,h[
'elossRaw'].GetNbinsX()+1):
155 tmp = h[
'elossRaw'].ProjectionY(
'tmp',n,n)
156 eloss = tmp.GetMean()
157 h[
'meanEloss'].SetBinContent(n,eloss/density/length*1000)
158 h[
'meanEloss'].SetTitle(
'mean energy loss MeV cm2 / g')
159 h[
'meanEloss'].Draw()
162 h[
'>eloss']=h[
'eloss'].ProjectionY().Clone(
'>eloss')
164 N = float(h[
'>eloss'].GetEntries())
165 for n
in range(h[
'>eloss'].GetNbinsX(),0,-1):
166 cum+=h[
'>eloss'].GetBinContent(n)
167 h[
'>eloss'].SetBinContent(n,cum/N)
168 print(
"Ethreshold event fraction in %")
169 for E
in [15.,20.,30.,50.,80.]:
170 n = h[
'>eloss'].FindBin(E/350.)
171 print(
" %5.0F %5.2F "%(E,h[
'>eloss'].GetBinContent(n)*100))
174 h[
'theta_100']=h[
'theta'].Clone(
'theta_100')
175 h[
'theta_100']=h[
'theta'].Rebin(5)
176 h[
'theta_100'].Scale(1./h[
'theta_100'].GetMaximum())
177 h[
'theta_100'].Draw()
179 h[s].Print(s+
'.root')
180 f.Write(h[
'theta'].GetName())
181 f.Write(h[
'theta_100'].GetName())
191 na62Points = open(
'NA62.points')
192 allPoints = na62Points.readlines()
193 N = int((len(allPoints)-1)/3.)
194 h[
'NA62']=ROOT.TGraphErrors(N)
196 tmp = allPoints[3*l].split(
',')
198 y=float(tmp[1].replace(
'\n',
''))
199 tmp = allPoints[3*l+1].split(
',')
200 y1=float(tmp[1].replace(
'\n',
''))
201 tmp = allPoints[3*l+2].split(
',')
202 y2=float(tmp[1].replace(
'\n',
''))
203 h[
'NA62'].SetPoint(l,x,y*1E-6)
204 h[
'NA62'].SetPointError(l,0,abs(y1-y2)/2.*1E-6)
205 h[
'NA62'].SetLineColor(ROOT.kRed)
206 h[
'NA62'].SetMarkerColor(ROOT.kRed)
207 h[
'NA62'].SetMarkerStyle(20)
212 pdg={10.0:1.914,14.0:1.978,20.0:2.055,30.0:2.164,40.0:2.263,80.0:2.630,100.:2.810,140.:3.170,200.:3.720,277.:4.420,300.:4.631,400.:5.561}
213 h[
'Gpdg'] = ROOT.TGraph(len(pdg))
215 Gpdg.SetMarkerColor(ROOT.kRed)
216 Gpdg.SetMarkerStyle(20)
217 keys = sorted(pdg.keys())
218 for n
in range(len(keys)):
219 Gpdg.SetPoint(n,keys[n],pdg[keys[n]])
222 ut.readHists(h,
"/mnt/hgfs/microDisk/Data/eloss/eloss_sum.root")
223 ut.readHists(h,
"/mnt/hgfs/microDisk/Data/eloss/eloss_withRaw.root")
224 ut.bookCanvas(h,key=
'summary',title=
" ",nx=1200,ny=600,cx=2,cy=1)
225 tc = h[
'summary'].cd(1)
226 h[
'0'] = h[
'eloss'].ProjectionX(
'0',1,h[
'eloss'].GetNbinsY())
230 h[t] = h[
'eloss'].ProjectionX(str(t),int(h[
'eloss'].GetNbinsY()*t/100.),h[
'eloss'].GetNbinsY())
233 h[t].SetMarkerStyle(24)
234 rc = h[t].Divide(h[
'0'] )
238 h[t].SetMarkerColor(ROOT.kBlue)
241 h[t].SetMaximum(1E-5)
242 h[t].SetMarkerColor(ROOT.kMagenta)
243 h[t].SetXTitle(
'incoming muon momentum [GeV/c]')
244 h[t].SetYTitle(
'prob #DeltaE>X%')
247 h[
'NA62'].Draw(
'sameP')
248 h[
'lg'] = ROOT.TLegend(0.53,0.79,0.98,0.94)
249 h[
'lg'].AddEntry(h[
'NA62'],
'NA62 measurement >95%',
'PL')
250 h[
'lg'].AddEntry(h[95],
'FairShip >95%',
'PL')
251 h[
'lg'].AddEntry(h[93],
'FairShip >93%',
'PL')
253 tc = h[
'summary'].cd(2)
254 h[
'meanEloss'] = h[
'elossRaw'].ProjectionX()
255 for n
in range(1,h[
'elossRaw'].GetNbinsX()+1):
256 tmp = h[
'elossRaw'].ProjectionY(
'tmp',n,n)
257 eloss = tmp.GetMean()
258 h[
'meanEloss'].SetBinContent(n,eloss/density/length*1000)
259 h[
'meanEloss'].SetBinError(n,0)
260 h[
'meanEloss'].SetTitle(
'mean energy loss MeV cm^{2}/g')
261 h[
'meanEloss'].SetStats(0)
262 h[
'meanEloss'].SetMaximum(7.)
263 h[
'meanEloss'].SetXTitle(
'incoming muon momentum [GeV/c]')
264 h[
'meanEloss'].SetYTitle(
'mean energy loss [MeV cm^[2]]/g')
265 h[
'meanEloss'].SetTitle(
'')
266 h[
'meanEloss'].Draw()
268 h[
'lg2'] = ROOT.TLegend(0.53,0.79,0.98,0.94)
269 h[
'lg2'].AddEntry(h[
'Gpdg'],
'muon dE/dx, PDG ',
'PL')
270 h[
'lg2'].AddEntry(h[
'meanEloss'],
'energy deposited in krypton, FairShip',
'PL')
272 h[
'summary'].Print(
'catastrophicEnergyLoss.png')