SND@LHC Software
Loading...
Searching...
No Matches
study_muMSC.py
Go to the documentation of this file.
1#!/usr/bin/env python
2import ROOT,os,sys,getopt,time,shipRoot_conf
3from argparse import ArgumentParser
4
5import shipunit as u
6from ShipGeoConfig import ConfigRegistry
7
8mcEngine = "TGeant4"
9runnr = 1
10
11setup = {}
12setup['Fig3'] = {'thickness': 0.1*u.cm, 'material':'lead','momentum': 2*u.GeV,'maxTheta':0.2}
13setup['Fig4'] = {'thickness': 0.1*u.cm, 'material':'lead','momentum': 8*u.GeV,'maxTheta':0.04}
14setup['Fig5'] = {'thickness': 0.1*u.cm, 'material':'lead','momentum': 14*u.GeV,'maxTheta':0.02}
15
16setup['Fig6'] = {'thickness': 1.44*u.cm, 'material':'copper','momentum': 11.7*u.GeV,'maxTheta':0.045}
17setup['Fig7'] = {'thickness': 1.44*u.cm, 'material':'copper','momentum': 7.3*u.GeV,'maxTheta':0.045}
18
19parser = ArgumentParser()
20parser.add_argument("-b", "--heartbeat", dest="heartbeat", type=int, help="progress report", default=10000)
21parser.add_argument("-n", "--nEvents", dest="nEvents", type=int, help="number of events", default=10000)
22parser.add_argument("-s", "--setup", dest="s", type=str, help="setup to simulate", default='Fig3')
23options = parser.parse_args()
24s = options.s
25nev = options.nEvents
26thickness = setup[s]['thickness']
27material = setup[s]['material']
28momentum = setup[s]['momentum']
29maxTheta = setup[s]['maxTheta']
30
31checkOverlap = True
32storeOnlyMuons = True
33
34outFile = "msc"+s+".root"
35theSeed = int(10000 * time.time() % 10000000)
36ecut = 0.0
37
38# -------------------------------------------------------------------
39ROOT.gRandom.SetSeed(theSeed) # this should be propagated via ROOT to Pythia8 and Geant4VMC
40shipRoot_conf.configure() # load basic libraries, prepare atexit for python
41ship_geo = ConfigRegistry.loadpy("$FAIRSHIP/geometry/geometry_config.py", Yheight = 10, tankDesign = 5, muShieldDesign = 7, nuTauTargetDesign=1)
42
43# -----Timer--------------------------------------------------------
44timer = ROOT.TStopwatch()
45timer.Start()
46
47# -----Create simulation run----------------------------------------
48run = ROOT.FairRunSim()
49run.SetName(mcEngine) # Transport engine
50run.SetOutputFile(outFile) # Output file
51run.SetUserConfig("g4Config.C") # user configuration file default g4Config.C
52rtdb = run.GetRuntimeDb()
53
54# -----Materials----------------------------------------------
55run.SetMaterials("media.geo")
56# -----Create geometry----------------------------------------------
57cave= ROOT.ShipCave("CAVE")
58cave.SetGeometryFileName("cave.geo")
59run.AddModule(cave)
60
61target = ROOT.boxTarget()
62target.SetTarget(material,thickness)
63run.AddModule(target)
64
65primGen = ROOT.FairPrimaryGenerator()
66myPgun = ROOT.FairBoxGenerator(13,1) # pdg id and multiplicity
67myPgun.SetPRange(momentum-0.01,momentum+0.01)
68myPgun.SetPhiRange(0,0) # // Azimuth angle range [degree]
69myPgun.SetThetaRange(0,0) # // Polar angle in lab system range [degree]
70myPgun.SetXYZ(0.*u.cm, 0.*u.cm, -10.*u.cm - (thickness) )
71ROOT.FairLogger.GetLogger().SetLogScreenLevel("WARNING") # otherwise stupid printout for each event
72
73primGen.AddGenerator(myPgun)
74run.SetGenerator(primGen)
75#
76run.SetGenerator(primGen)
77# -----Initialize simulation run------------------------------------
78run.Init()
79gMC = ROOT.TVirtualMC.GetMC()
80
81fStack = gMC.GetStack()
82fStack.SetMinPoints(1)
83fStack.SetEnergyCut(-1.)
84
85# -----Start run----------------------------------------------------
86run.Run(nev)
87
88# -----Start Analysis---------------
89ROOT.gROOT.ProcessLine('#include "Geant4/G4EmParameters.hh"')
90emP = ROOT.G4EmParameters.Instance()
91emP.Dump()
92
93import rootUtils as ut
94
95f=ROOT.TFile(outFile)
96h={}
97ut.bookHist(h,'theta','scattering angle '+str(momentum)+'GeV/c;{Theta}(rad)',5000,0,maxTheta)
98ut.bookHist(h,'theta2D','scattering angle '+str(momentum)+'GeV/c;{Theta}(rad)',5000,-maxTheta,maxTheta)
99sTree = f.cbmsim
100for n in range(sTree.GetEntries()):
101 rc = sTree.GetEvent(n)
102 for aHit in sTree.vetoPoint:
103 if not aHit.GetTrackID()==0: continue
104 pt = ROOT.TMath.Sqrt(aHit.GetPx()**2+aHit.GetPy()**2)
105 scat = ROOT.TMath.ATan2(pt,aHit.GetPz())
106 rc = h['theta'].Fill(scat)
107 scatX = ROOT.TMath.ATan2(aHit.GetPx(),aHit.GetPz())
108 scatY = ROOT.TMath.ATan2(aHit.GetPy(),aHit.GetPz())
109 rc = h['theta'].Fill(scat)
110 rc = h['theta2D'].Fill(scatX)
111 rc = h['theta2D'].Fill(scatY)
112ut.bookCanvas(h,key=s,title=s,nx=900,ny=600,cx=1,cy=1)
113tc = h[s].cd(1)
114tc.SetLogy(1)
115h['theta_100']=h['theta'].Clone('theta_100')
116h['theta_100']=h['theta'].Rebin(5)
117h['theta_100'].Scale(1./h['theta_100'].GetMaximum())
118h['theta_100'].Draw()
119h[s].Print(s+'.png')
120h[s].Print(s+'.root')
121
122f.Write(h['theta'].GetName())
123f.Write(h['theta_100'].GetName())
124
125# -----Finish-------------------------------------------------------
126timer.Stop()
127rtime = timer.RealTime()
128ctime = timer.CpuTime()
129print(' ')
130print("Macro finished succesfully.")
131print("Output file is ", outFile)
132print("Real time ",rtime, " s, CPU time ",ctime,"s")
configure(darkphoton=None)