SND@LHC Software
Loading...
Searching...
No Matches
study_GammaConv.py
Go to the documentation of this file.
1#!/usr/bin/env python
2from __future__ import print_function
3import ROOT,os,sys,getopt,time,shipRoot_conf
4ROOT.gROOT.ProcessLine('#include "FairModule.h"')
5time.sleep(20)
6
7import shipunit as u
8from ShipGeoConfig import ConfigRegistry
9
10mcEngine = "TGeant4"
11runnr = 1
12nev = 10# 000000
13
14setup = {}
15setup['10'] = {'thickness': 2*u.cm, 'material':'aluminium','momentum': 10*u.GeV}
16setup['100'] = {'thickness': 2*u.cm, 'material':'aluminium','momentum': 100*u.GeV}
17setup['200'] = {'thickness': 2*u.cm, 'material':'aluminium','momentum': 200*u.GeV}
18
19# 8cm = 0.9X0
20
21
22s = sys.argv[1]
23thickness = setup[s]['thickness']
24material = setup[s]['material']
25momentum = setup[s]['momentum']
26
27checkOverlap = True
28
29outFile = "gconv"+s+".root"
30theSeed = int(10000 * time.time() % 10000000)
31ecut = 0.0
32
33# -------------------------------------------------------------------
34ROOT.gRandom.SetSeed(theSeed) # this should be propagated via ROOT to Pythia8 and Geant4VMC
35shipRoot_conf.configure() # load basic libraries, prepare atexit for python
36ship_geo = ConfigRegistry.loadpy("$FAIRSHIP/geometry/geometry_config.py", Yheight = 10, tankDesign = 5, muShieldDesign = 7, nuTauTargetDesign=1)
37
38# -----Timer--------------------------------------------------------
39timer = ROOT.TStopwatch()
40timer.Start()
41
42# -----Create simulation run----------------------------------------
43run = ROOT.FairRunSim()
44run.SetName(mcEngine) # Transport engine
45run.SetOutputFile(outFile) # Output file
46run.SetUserConfig("g4Config.C") # user configuration file default g4Config.C
47rtdb = run.GetRuntimeDb()
48
49# -----Materials----------------------------------------------
50run.SetMaterials("media.geo")
51# -----Create geometry----------------------------------------------
52cave= ROOT.ShipCave("CAVE")
53cave.SetGeometryFileName("cave.geo")
54run.AddModule(cave)
55
56class Block(ROOT.pyFairModule):
57 "block of material"
58 def __init__(self):
59 ROOT.pyFairModule.__init__(self,self)
60 self.sensPlane = None
62 print("Construct Block")
63 top=ROOT.gGeoManager.GetTopVolume()
64 geoLoad=ROOT.FairGeoLoader.Instance()
65 geoFace=geoLoad.getGeoInterface()
66 media=geoFace.getMedia()
67 geoBuild=geoLoad.getGeoBuilder()
68 ShipMedium=media.getMedium(material)
69 W = ROOT.gGeoManager.GetMedium(material)
70 if not W:
71 rc = geoBuild.createMedium(ShipMedium)
72 W = ROOT.gGeoManager.GetMedium(material)
73 aBox = ROOT.gGeoManager.MakeBox("target", W, 100.*u.cm, 100.*u.cm, thickness)
74 top.AddNode(aBox, 1, ROOT.TGeoTranslation(0, 0, 0 ))
75 if self.sensPlane: self.sensPlane.AddSensitiveVolume(aBox)
77 print("not implemented!")
78 def makeSensitive(self,sensPlane):
79 self.sensPlane = sensPlane
80
81sensPlane = ROOT.exitHadronAbsorber()
82sensPlane.SetEnergyCut(ecut*u.GeV)
83sensPlane.SetZposition(thickness+10*u.cm)
84run.AddModule(sensPlane)
85target = Block()
86target.makeSensitive(sensPlane)
87run.AddModule(target)
88
89primGen = ROOT.FairPrimaryGenerator()
90myPgun = ROOT.FairBoxGenerator(22,1) # pdg id and multiplicity
91myPgun.SetPRange(momentum-0.01,momentum+0.01)
92myPgun.SetPhiRange(0,0) # // Azimuth angle range [degree]
93myPgun.SetThetaRange(0,0) # // Polar angle in lab system range [degree]
94myPgun.SetXYZ(0.*u.cm, 0.*u.cm, -10.*u.cm - (thickness) )
95primGen.AddGenerator(myPgun)
96run.SetGenerator(primGen)
97#
98run.SetGenerator(primGen)
99# -----Initialize simulation run------------------------------------
100run.Init()
101gMC = ROOT.TVirtualMC.GetMC()
102
103fStack = gMC.GetStack()
104fStack.SetMinPoints(1)
105fStack.SetEnergyCut(-1.)
106
107boostFactor = 100.
108if boostFactor > 1:
109 ROOT.gROOT.ProcessLine('#include "Geant4/G4ProcessTable.hh"')
110 ROOT.gROOT.ProcessLine('#include "Geant4/G4AnnihiToMuPair.hh"')
111 ROOT.gROOT.ProcessLine('#include "Geant4/G4GammaConversionToMuons.hh"')
112 gProcessTable = ROOT.G4ProcessTable.GetProcessTable()
113 procAnnihil = gProcessTable.FindProcess(ROOT.G4String('AnnihiToMuPair'),ROOT.G4String('e+'))
114 procGMuPair = gProcessTable.FindProcess(ROOT.G4String('GammaToMuPair'),ROOT.G4String('gamma'))
115 procGMuPair.SetCrossSecFactor(boostFactor)
116 procAnnihil.SetCrossSecFactor(boostFactor)
117
118# -----Start run----------------------------------------------------
119run.Run(nev)
120
121# -----Start Analysis---------------
122ROOT.gROOT.ProcessLine('#include "Geant4/G4EmParameters.hh"')
123emP = ROOT.G4EmParameters.Instance()
124emP.Dump()
125
126import rootUtils as ut
127
128f=ROOT.gROOT.GetListOfFiles()[0]
129h={}
130ut.bookHist(h,'muons','muon mult',10,-0.5,9.5)
131ut.bookHist(h,'electrons','e mult',10,-0.5,9.5)
132sTree = f.cbmsim
133for n in range(sTree.GetEntries()):
134 rc = sTree.GetEvent(n)
135 nMu = 0
136 nEl = 0
137 for aHit in sTree.vetoPoint:
138 if abs(sTree.MCTrack[aHit.GetTrackID()].GetPdgCode())==13: nMu+=1
139 if abs(sTree.MCTrack[aHit.GetTrackID()].GetPdgCode())==11: nEl+=1
140 rc = h['muons'].Fill(nMu)
141 rc = h['electrons'].Fill(nEl)
142h['muons'].Draw()
143
144# -----Finish-------------------------------------------------------
145timer.Stop()
146rtime = timer.RealTime()
147ctime = timer.CpuTime()
148print(' ')
149print("Macro finished succesfully.")
150print("Output file is ", outFile)
151print("Real time ",rtime, " s, CPU time ",ctime,"s")
makeSensitive(self, sensPlane)
configure(darkphoton=None)