FairShip
Loading...
Searching...
No Matches
study_muMSC.py
Go to the documentation of this file.
1#!/usr/bin/env python
2# SPDX-License-Identifier: LGPL-3.0-or-later
3# SPDX-FileCopyrightText: Copyright CERN for the benefit of the SHiP Collaboration
4
5import sys
6import time
7
8import ROOT
9import shipRoot_conf
10
11ROOT.gROOT.ProcessLine('#include "FairModule.h"')
12time.sleep(20)
13
14import geometry_config
15import shipunit as u
16
17mcEngine = "TGeant4"
18runnr = 1
19nev = 10000000
20
21setup = {}
22setup["Fig3"] = {"thickness": 0.1 * u.cm, "material": "lead", "momentum": 2 * u.GeV, "maxTheta": 0.2}
23setup["Fig4"] = {"thickness": 0.1 * u.cm, "material": "lead", "momentum": 8 * u.GeV, "maxTheta": 0.04}
24setup["Fig5"] = {"thickness": 0.1 * u.cm, "material": "lead", "momentum": 14 * u.GeV, "maxTheta": 0.02}
25
26setup["Fig6"] = {"thickness": 1.44 * u.cm, "material": "copper", "momentum": 11.7 * u.GeV, "maxTheta": 0.045}
27setup["Fig7"] = {"thickness": 1.44 * u.cm, "material": "copper", "momentum": 7.3 * u.GeV, "maxTheta": 0.045}
28
29s = sys.argv[1]
30thickness = setup[s]["thickness"]
31material = setup[s]["material"]
32momentum = setup[s]["momentum"]
33maxTheta = setup[s]["maxTheta"]
34
35checkOverlap = True
36storeOnlyMuons = True
37
38outFile = "msc" + s + ".root"
39theSeed = int(10000 * time.time() % 10000000)
40ecut = 0.0
41
42# -------------------------------------------------------------------
43ROOT.gRandom.SetSeed(theSeed) # this should be propagated via ROOT to Pythia8 and Geant4VMC
44shipRoot_conf.configure() # load basic libraries, prepare atexit for python
45ship_geo = geometry_config.create_config(Yheight=10, shieldName="warm_opt")
46
47# -----Timer--------------------------------------------------------
48timer = ROOT.TStopwatch()
49timer.Start()
50
51# -----Create simulation run----------------------------------------
52run = ROOT.FairRunSim()
53run.SetName(mcEngine) # Transport engine
54run.SetSink(ROOT.FairRootFileSink(outFile)) # Output file
55run.SetUserConfig("g4Config.C") # user configuration file default g4Config.C
56rtdb = run.GetRuntimeDb()
57
58# -----Materials----------------------------------------------
59run.SetMaterials("media.geo")
60# -----Create geometry----------------------------------------------
61cave = ROOT.ShipCave("CAVE")
62cave.SetGeometryFileName("cave.geo")
63run.AddModule(cave)
64
65
66class Block(ROOT.pyFairModule):
67 "block of material"
68
69 def __init__(self) -> None:
70 ROOT.pyFairModule.__init__(self, self)
71
72 def ConstructGeometry(self) -> None:
73 print("Construct Block")
74 top = ROOT.gGeoManager.GetTopVolume()
75 geoLoad = ROOT.FairGeoLoader.Instance()
76 geoFace = geoLoad.getGeoInterface()
77 media = geoFace.getMedia()
78 geoBuild = geoLoad.getGeoBuilder()
79 ShipMedium = media.getMedium(material)
80 W = ROOT.gGeoManager.GetMedium(material)
81 if not W:
82 geoBuild.createMedium(ShipMedium)
83 W = ROOT.gGeoManager.GetMedium(material)
84 aBox = ROOT.gGeoManager.MakeBox("target", W, 100.0 * u.cm, 100.0 * u.cm, thickness)
85 top.AddNode(aBox, 1, ROOT.TGeoTranslation(0, 0, 0))
86
87 def InitParContainers() -> None:
88 print("not implemented!")
89
90
91sensPlane = ROOT.exitHadronAbsorber()
92sensPlane.SetEnergyCut(ecut * u.GeV)
93if storeOnlyMuons:
94 sensPlane.SetOnlyMuons()
95sensPlane.SetZposition(thickness + 10 * u.cm)
96run.AddModule(sensPlane)
97target = Block()
98run.AddModule(target)
99
100primGen = ROOT.FairPrimaryGenerator()
101myPgun = ROOT.FairBoxGenerator(13, 1) # pdg id and multiplicity
102myPgun.SetPRange(momentum - 0.01, momentum + 0.01)
103myPgun.SetPhiRange(0, 0) # // Azimuth angle range [degree]
104myPgun.SetThetaRange(0, 0) # // Polar angle in lab system range [degree]
105myPgun.SetXYZ(0.0 * u.cm, 0.0 * u.cm, -10.0 * u.cm - (thickness))
106primGen.AddGenerator(myPgun)
107run.SetGenerator(primGen)
108#
109run.SetGenerator(primGen)
110# -----Initialize simulation run------------------------------------
111run.Init()
112gMC = ROOT.TVirtualMC.GetMC()
113
114fStack = gMC.GetStack()
115fStack.SetMinPoints(1)
116fStack.SetEnergyCut(-1.0)
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, "theta", "scattering angle " + str(momentum) + "GeV/c;{Theta}(rad)", 500, 0, maxTheta)
131sTree = f.Get("cbmsim")
132for n in range(sTree.GetEntries()):
133 rc = sTree.GetEvent(n)
134 for aHit in sTree.vetoPoint:
135 if aHit.GetTrackID() != 0:
136 continue
137 pt = ROOT.TMath.Sqrt(aHit.GetPx() ** 2 + aHit.GetPy() ** 2)
138 scat = ROOT.TMath.ATan2(pt, aHit.GetPz())
139 rc = h["theta"].Fill(scat)
140ut.bookCanvas(h, key=s, title=s, nx=900, ny=600, cx=1, cy=1)
141tc = h[s].cd(1)
142tc.SetLogy(1)
143h["theta_100"] = h["theta"].Clone("theta_100")
144h["theta_100"] = h["theta"].Rebin(5)
145h["theta_100"].Scale(1.0 / h["theta_100"].GetMaximum())
146h["theta_100"].Draw()
147h[s].Print(s + ".png")
148h[s].Print(s + ".root")
149
150f.Write(h["theta"].GetName())
151f.Write(h["theta_100"].GetName())
152
153# -----Finish-------------------------------------------------------
154timer.Stop()
155rtime = timer.RealTime()
156ctime = timer.CpuTime()
157print(" ")
158print("Macro finished successfully.")
159print("Output file is ", outFile)
160print("Real time ", rtime, " s, CPU time ", ctime, "s")
None ConstructGeometry(self)
Definition: study_muMSC.py:72
None __init__(self)
Definition: study_muMSC.py:69
None InitParContainers()
Definition: study_muMSC.py:87
def create_config(str DecayVolumeMedium="helium", float Yheight=6.0, int strawDesign=10, muShieldGeo=None, str shieldName="New_HA_Design", int nuTargetPassive=1, bool SND=True, SND_design=None, TARGET_YAML=None)
None configure(darkphoton=None)