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