3from decorators
import *
9from argparse
import ArgumentParser
10ROOT.gROOT.ProcessLine(
'#include "Geant4/G4UIterminal.hh"')
11ROOT.gROOT.ProcessLine(
'#include "Geant4/G4Neutron.hh"')
12ROOT.gROOT.ProcessLine(
'#include "Geant4/G4ProcessManager.hh"')
13ROOT.gROOT.ProcessLine(
'#include "Geant4/G4ParticleHPThermalScattering.hh"')
14ROOT.gROOT.ProcessLine(
'#include "Geant4/G4ParticleHPElastic.hh"')
15ROOT.gROOT.ProcessLine(
'#include "Geant4/G4HadronElasticProcess.hh"')
16ROOT.gROOT.ProcessLine(
'#include "Geant4/G4HadronicProcessStore.hh"')
17ROOT.gROOT.ProcessLine(
'#include "Geant4/G4ParticleHPThermalScatteringData.hh"')
18ROOT.gROOT.ProcessLine(
'#include "Geant4/G4ParticleHPElasticData.hh"')
19ROOT.gROOT.ProcessLine(
'#include "Geant4/G4GenericPhysicsList.hh"')
20ROOT.gROOT.ProcessLine(
'#include "Geant4/G4RunManager.hh"')
21ROOT.gROOT.ProcessLine(
'#include "Geant4/G4TransportationManager.hh"')
25parser = ArgumentParser()
26parser.add_argument(
"-b",
"--heartbeat", dest=
"heartbeat", type=int, help=
"progress report", default=10000)
27parser.add_argument(
"-n",
"--nEvents", dest=
"nEvents", type=int, help=
"number of events", default=100)
28parser.add_argument(
"-r",
"--run", dest=
"run", type=int, help=
"production sequence number", default=0)
29parser.add_argument(
'--material', dest=
'targetMaterial', type=str,help=
"target material BoronCarbide or Boratedpolyethylene", default=
"BoronCarbide")
30parser.add_argument(
'--thick', dest=
'targetLength', type=float,help=
"target thickness", default=0.1)
31parser.add_argument(
'-c',
'--command', dest=
'command', help=
"command")
32parser.add_argument(
"--Estart", dest=
"Estart", help=
"start of energy range of particle gun (default= 0 MeV)", required=
False, default=1E-20, type=float)
33parser.add_argument(
"--Eend", dest=
"Eend", help=
"end of energy range of particle gun (default=10 MeV)", required=
False, default=0.01, type=float)
34parser.add_argument(
"--pID", dest=
"pID", help=
"id of particle used by the gun (default=2112)", required=
False, default=2112, type=int)
35parser.add_argument(
"--setup", dest=
"neutron", help=
"setup for absorptionLength or neutron in cold box)", required=
False, action=
'store_true')
36options = parser.parse_args()
39logEstart =
int(ROOT.TMath.Log10(options.Estart))
40logEend =
int(ROOT.TMath.Log10(options.Eend))
41outFile =
'thermNeutron_'+options.targetMaterial+
'_'+
str(options.targetLength)+
'_'+
str(logEstart)+
'_'+
str(logEend)+
'_'+
str(options.run)+
'.root'
42if options.neutron: outFile =
'thermNeutron_%s_%s_coldbox_%s-%iM.root'%(options.targetMaterial,
str(options.targetLength),
str(options.run),options.nEvents/1000000.)
43parFile = outFile.replace(
'thermNeutron',
'params-thermNeutron')
46timer = ROOT.TStopwatch()
50run = ROOT.FairRunSim()
52run.SetSink(ROOT.FairRootFileSink(outFile))
53run.SetUserConfig(
"g4ConfigNeutron.C")
56primGen = ROOT.FairPrimaryGenerator()
59 Neutrongen = ROOT.NeutronGenerator_FLUKA()
60 primGen.AddGenerator(Neutrongen)
62 myPgun = ROOT.FairBoxGenerator(options.pID,1)
63 myPgun.SetEkinRange(options.Estart,options.Eend)
64 myPgun.SetPhiRange(0, 0)
65 myPgun.SetThetaRange(0,0)
66 myPgun.SetXYZ(0.,0.,-1.)
67 primGen.AddGenerator(myPgun)
68 ROOT.FairLogger.GetLogger().SetLogScreenLevel(
"WARNING")
71run.SetMaterials(
"media.geo")
73cave = ROOT.ShipCave(
"CAVE")
74cave.SetGeometryFileName(
"caveXS.geo")
77target = ROOT.boxTarget()
78target.SetTarget(options.targetMaterial,options.targetLength*u.cm,
not options.neutron)
82run.SetGenerator(primGen)
86from decorators
import *
88neutron = ROOT.G4Neutron.Neutron()
89pManager = neutron.GetProcessManager()
93 process = pManager.GetProcess(
"hadElastic")
94 if process: pManager.RemoveProcess(process)
95 process1 = ROOT.G4HadronElasticProcess()
96 pManager.AddDiscreteProcess(process1)
97 model1a = ROOT.G4ParticleHPElastic()
99 model1a.SetMinEnergy(4*eV)
100 process1.RegisterMe(model1a)
101 process1.AddDataSet(ROOT.G4ParticleHPElasticData())
102 model1b = ROOT.G4ParticleHPThermalScattering()
103 process1.RegisterMe(model1b)
104 process1.AddDataSet(ROOT.G4ParticleHPThermalScatteringData())
107gMC = ROOT.TVirtualMC.GetMC()
108fStack = gMC.GetStack()
109fStack.SetMinPoints(-1)
110fStack.SetEnergyCut(-1.)
113run.Run(options.nEvents)
117rtime = timer.RealTime()
118ctime = timer.CpuTime()
120print(
"Macro finished succesfully.")
121print(
"Output file is ", outFile)
122print(
"Real time ",rtime,
" s, CPU time ",ctime,
"s")
124run.CreateGeometryFile(
"geofile-"+outFile)
125sGeo = ROOT.gGeoManager
126sGeo.SetNmeshPoints(10000)
127sGeo.CheckOverlaps(0.1)
132import rootUtils
as ut
135 ut.bookHist(h,
'E',
';log10(Ekin [MeV])',1000,-10.,4.)
136 ut.bookHist(h,
'Epassed',
';log10(Ekin [MeV])',1000,-10.,4.)
137 ut.bookHist(h,
'Lab',
';absorption Length vs logE',1000,-10.,4.,500,-0.1,10.)
138 ut.bookHist(h,
'Labz',
';absorption Length vs logE',1000,-10.,4.,500,-0.1,10.)
139 ut.bookHist(h,
'xyz',
'', 100,-0.1,0.1,100,-0.1,0.1,200,-1.,1.)
140 ut.bookHist(h,
'dxyz',
'',100,-0.1,0.1,100,-0.1,0.1,200,-1.,1.)
141 ut.bookHist(h,
'Epassed',
';log10(Ekin [MeV])',1000,-10.,4.)
143 for sTree
in f.cbmsim:
145 Ekin = N.GetP()**2/(2*N.GetMass())*1000.
146 logEkin = ROOT.TMath.Log10(Ekin)
147 rc = h[
'E'].Fill(logEkin)
148 for p
in sTree.vetoPoint:
149 if not p.PdgCode()==2112:
continue
150 if p.GetDetectorID()==1 :
151 mean = ROOT.TVector3(p.GetX(),p.GetY(),p.GetZ())
155 rc = h[
'Lab'].Fill(logEkin,D.Mag())
156 rc = h[
'Labz'].Fill(logEkin,D.Z())
157 rc = h[
'xyz'].Fill(start.X(),start.Y(),start.Z())
158 rc = h[
'dxyz'].Fill(end.X(),end.Y(),end.Z())
161 rc = h[
'Epassed'].Fill(ROOT.TMath.Log10(Ekin))
162 h[
'Eff'] = ROOT.TEfficiency(h[
'Epassed'],h[
'E'])
166pathToPlots =
"/mnt/hgfs/microDisk/CERNBOX/SND@LHC/Thermal Neutrons/"
168 for z
in [
'.png',
'.pdf',
'.root']:
170 os.system(
'mv '+tname+z+
' '+pathToPlots)
174 for material
in [
'Boratedpolyethylene',
'BoronCarbide']:
175 for Erange
in [
'-10_-8',
'-8_-7',
'-6_-4']:
176 fname =
"thermNeutron_"+material+
"_100.0_"+Erange+
"_0.root"
178 for x
in [
'Lab',
'Labz']:
179 hname = x+
'_'+material+E
180 h[hname] = h[x].ProfileX(hname,1,-1,
'g')
187 Lfun = ROOT.TF1(
'Lfun',
'[0]*(10**x)**[1]',-9,-6)
188 Lfun.SetParameter(0,6.4)
189 Lfun.SetParameter(1,0.98)
190 hFiles = {
"thermNeutron_BoronCarbide_X.XX_-E_-E_0.root":[0.08,0.3],
"thermNeutron_Boratedpolyethylene_X.XX_0.root":[1.0,100.]}
193 Ls = {0.01:ROOT.kRed,0.1:ROOT.kOrange,0.04:ROOT.kCyan,0.4:ROOT.kBlue,4.0:ROOT.kMagenta}
196 material = hFile.split(
'_')[1]
197 ut.bookCanvas(h,
'absorb'+material,
'',1200,800,1,1)
198 h[
'absorb'+material].cd()
201 if L<3: tmp = hFile.replace(
"X.XX",l).replace(
" _-E_-E",
"")
202 else: tmp = hFile.replace(
"X.XX",l).replace(
" _-E_-E",
"_-8_-7")
204 h[
'Eff_'+l]=h[
'Eff'].Clone(
'Eff_'+l)
205 h[
'L_'+l]=ROOT.TGraph()
206 h[
'L_'+l].SetLineColor(Ls[L])
208 g = h[
'Eff'].GetPaintedGraph()
209 for n
in range(g.GetN()):
210 logE, p = g.GetPointX(n),g.GetPointY(n)
212 absL = -L/ROOT.TMath.Log(p)
215 h[
'L_'+l].SetPoint(n,logE,absL)
216 ut.bookHist(h,
'L',
';logE; L [cm]',100,-9.,-6.)
217 h[
'L'].SetMaximum(hFiles[hFile][0])
221 if L>hFiles[hFile][1]:
continue
222 h[
'L_'+
str(L)].Draw(
'same')
223 h[
'L_'+
str(0.1)].Fit(Lfun)
224 myPrint(h[
'absorb'+material],
'absorbLength'+material)
227rate = ROOT.TF1(
'rate',
'1./10**x*exp(-[0]/([1]*sqrt(10**x)))',-9,2)
229rate.SetParameter(0,1.)
230rate.SetParameter(1,130.)
237import hepunit
as G4Unit
238ROOT.gROOT.ProcessLine(
'#include "Geant4/G4HadronicProcessStore.hh"')
241 neutron = ROOT.G4Neutron.Neutron()
243 pManager = neutron.GetProcessManager()
245 for p
in pManager.GetProcessList():
247 store = ROOT.G4HadronicProcessStore.Instance()
249 runManager = ROOT.G4RunManager.GetRunManager()
250 gt = ROOT.G4TransportationManager.GetTransportationManager()
251 gn = gt.GetNavigatorForTracking()
252 world = gn.GetWorldVolume().GetLogicalVolume()
254 for da
in range(world.GetNoDaughters()):
255 vl = world.GetDaughter(da)
256 vmap[vl.GetName().c_str()] = vl
257 lvl = vl.GetLogicalVolume()
258 mat = lvl.GetMaterial()
259 print(
"%2i %s %5.3F g/cm3 %5.2F kg %s"%(da, vl.GetName(),mat.GetDensity()/G4Unit.g*G4Unit.cm3,lvl.GetMass()/G4Unit.kg,mat.GetName()))
260 for n
in range(mat.GetNumberOfElements()):
261 element = mat.GetElement(n)
262 print(
" %2i %s %4.1F %5.4F "%(n,element.GetName(),element.GetAtomicMassAmu(),mat.GetFractionVector()[n]))