SND@LHC Software
Loading...
Searching...
No Matches
study_thinTarget.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 = 1000000
13
14setup = {}
15setup['TLV'] = {'thickness': 0.1*u.cm, 'material':'tungsten','min momentum': 400*u.GeV,'max momentum': 400*u.GeV}
16
17s = 'TLV'
18thickness = setup[s]['thickness']
19material = setup[s]['material']
20minmomentum = setup[s]['min momentum']
21maxmomentum = setup[s]['max momentum']
22
23checkOverlap = True
24
25outFile = "TLV.root"
26theSeed = 0
27ecut = 0.0
28
29# -------------------------------------------------------------------
30ROOT.gRandom.SetSeed(theSeed) # this should be propagated via ROOT to Pythia8 and Geant4VMC
31shipRoot_conf.configure() # load basic libraries, prepare atexit for python
32ship_geo = ConfigRegistry.loadpy("$FAIRSHIP/geometry/geometry_config.py", Yheight = 10, tankDesign = 5, muShieldDesign = 7, nuTauTargetDesign=1)
33
34# -----Timer--------------------------------------------------------
35timer = ROOT.TStopwatch()
36timer.Start()
37
38# -----Create simulation run----------------------------------------
39gFairBaseContFact = ROOT.FairBaseContFact() # required by change to FairBaseContFact to avoid TList::Clear errors
40run = ROOT.FairRunSim()
41run.SetName(mcEngine) # Transport engine
42run.SetOutputFile(outFile) # Output file
43run.SetUserConfig("g4Config.C") # user configuration file default g4Config.C
44rtdb = run.GetRuntimeDb()
45
46# -----Materials----------------------------------------------
47run.SetMaterials("media.geo")
48# -----Create geometry----------------------------------------------
49cave= ROOT.ShipCave("CAVE")
50cave.SetGeometryFileName("cave.geo")
51run.AddModule(cave)
52
53
54class Block(ROOT.pyFairModule):
55 "block of material"
56 def __init__(self): ROOT.pyFairModule.__init__(self,self)
58 print("Construct Block")
59 top=ROOT.gGeoManager.GetTopVolume()
60 geoLoad=ROOT.FairGeoLoader.Instance()
61 geoFace=geoLoad.getGeoInterface()
62 media=geoFace.getMedia()
63 geoBuild=geoLoad.getGeoBuilder()
64 ShipMedium=media.getMedium(material)
65 W = ROOT.gGeoManager.GetMedium(material)
66 if not W:
67 rc = geoBuild.createMedium(ShipMedium)
68 W = ROOT.gGeoManager.GetMedium(material)
69 aBox = ROOT.gGeoManager.MakeBox("target", W, 100.*u.cm, 100.*u.cm, thickness)
70 top.AddNode(aBox, 1, ROOT.TGeoTranslation(0, 0, 0 ))
72 print("not implemented!")
73
74sensPlane = ROOT.exitHadronAbsorber()
75sensPlane.SetEnergyCut(ecut*u.GeV)
76sensPlane.SetZposition(thickness+10*u.cm)
77run.AddModule(sensPlane)
78target = Block()
79run.AddModule(target)
80
81primGen = ROOT.FairPrimaryGenerator()
82myPgun = ROOT.FairBoxGenerator(2212,1) # pdg id and multiplicity
83myPgun.SetPRange(minmomentum,maxmomentum)
84myPgun.SetPhiRange(0,0) # // Azimuth angle range [degree]
85myPgun.SetThetaRange(0,0) # // Polar angle in lab system range [degree]
86myPgun.SetXYZ(0.*u.cm, 0.*u.cm, -10.*u.cm - (thickness) )
87primGen.AddGenerator(myPgun)
88run.SetGenerator(primGen)
89#
90run.SetGenerator(primGen)
91# -----Initialize simulation run------------------------------------
92run.Init()
93gMC = ROOT.TVirtualMC.GetMC()
94
95fStack = gMC.GetStack()
96fStack.SetMinPoints(1)
97fStack.SetEnergyCut(-1.)
98
99# -----Start run----------------------------------------------------
100run.Run(nev)
101
102# -----Start Analysis---------------
103
104import rootUtils as ut
105
106f=ROOT.TFile('TLV.root')
107pdg = ROOT.TDatabasePDG.Instance()
108h={}
109sTree = f.cbmsim
110ut.bookHist(h,'Ekin','Ekin of particles in sens plane',400000,0.,400)
111ut.bookHist(h,'EkinLow','Ekin of particles in sens plane',1000,0.,0.001)
112for n in range(sTree.GetEntries()):
113 rc = sTree.GetEvent(n)
114 for aHit in sTree.vetoPoint:
115 oTrack = sTree.MCTrack[aHit.GetTrackID()]
116 M = pdg.GetParticle(oTrack.GetPdgCode()).Mass()
117 Ekin = ROOT.TMath.Sqrt( aHit.GetPx()**2+aHit.GetPy()**2+aHit.GetPz()**2 + M**2) - M
118 rc = h['Ekin'].Fill(Ekin)
119 rc = h['EkinLow'].Fill(Ekin)
120ut.bookCanvas(h,key=s,title=s,nx=900,ny=600,cx=1,cy=1)
121tc = h[s].cd(1)
122tc.SetLogy(1)
123h['Ekin'].Draw()
124
125# tungsten dedex mev cm**2/g 1.145 * rho g/cm-3 19.3 * 0.1
126# interactionLength 191.9 / 19.3 = 9.94cm, 0.1/9.94 = 1%
127
128# -----Finish-------------------------------------------------------
129timer.Stop()
130rtime = timer.RealTime()
131ctime = timer.CpuTime()
132print(' ')
133print("Macro finished succesfully.")
134print("Output file is ", outFile)
135print("Real time ",rtime, " s, CPU time ",ctime,"s")
configure(darkphoton=None)