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="TRY_2026")
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
61sink = ROOT.FairRootFileSink(outFile)
62run.SetSink(sink)
63ROOT.SetOwnership(sink, False) # C++ FairRun takes ownership
64run.SetUserConfig("g4Config.C") # user configuration file default g4Config.C
65rtdb = run.GetRuntimeDb()
66
67# -----Materials----------------------------------------------
68run.SetMaterials("media.geo")
69# -----Create geometry----------------------------------------------
70cave = ROOT.ShipCave("CAVE")
71cave.SetGeometryFileName("cave.geo")
72run.AddModule(cave)
73
74
75class Block(ROOT.pyFairModule):
76 "block of material"
77
78 def __init__(self) -> None:
79 ROOT.pyFairModule.__init__(self, self)
80
81 def ConstructGeometry(self) -> None:
82 print("Construct Block")
83 top = ROOT.gGeoManager.GetTopVolume()
84 geoLoad = ROOT.FairGeoLoader.Instance()
85 geoFace = geoLoad.getGeoInterface()
86 media = geoFace.getMedia()
87 geoBuild = geoLoad.getGeoBuilder()
88 ShipMedium = media.getMedium(material)
89 W = ROOT.gGeoManager.GetMedium(material)
90 if not W:
91 geoBuild.createMedium(ShipMedium)
92 W = ROOT.gGeoManager.GetMedium(material)
93 aBox = ROOT.gGeoManager.MakeBox("target", W, 100.0 * u.cm, 100.0 * u.cm, thickness)
94 top.AddNode(aBox, 1, ROOT.TGeoTranslation(0, 0, 0))
95
96 def InitParContainers() -> None:
97 print("not implemented!")
98
99
100sensPlane = ROOT.exitHadronAbsorber()
101sensPlane.SetEnergyCut(ecut * u.GeV)
102sensPlane.SetZposition(thickness + 10 * u.cm)
103run.AddModule(sensPlane)
104target = Block()
105run.AddModule(target)
106
107primGen = ROOT.FairPrimaryGenerator()
108myPgun = ROOT.FairBoxGenerator(2212, 1) # pdg id and multiplicity
109myPgun.SetPRange(minmomentum, maxmomentum)
110myPgun.SetPhiRange(0, 0) # // Azimuth angle range [degree]
111myPgun.SetThetaRange(0, 0) # // Polar angle in lab system range [degree]
112myPgun.SetXYZ(0.0 * u.cm, 0.0 * u.cm, -10.0 * u.cm - (thickness))
113primGen.AddGenerator(myPgun)
114run.SetGenerator(primGen)
115#
116run.SetGenerator(primGen)
117# -----Initialize simulation run------------------------------------
118run.Init()
119gMC = ROOT.TVirtualMC.GetMC()
120
121fStack = gMC.GetStack()
122fStack.SetMinPoints(1)
123fStack.SetEnergyCut(-1.0)
124
125# -----Start run----------------------------------------------------
126run.Run(nev)
127
128# -----Start Analysis---------------
129
130import rootUtils as ut
131
132f = ROOT.TFile("TLV.root")
133pdg = ROOT.TDatabasePDG.Instance()
134h = {}
135sTree = f.Get("cbmsim")
136ut.bookHist(h, "Ekin", "Ekin of particles in sens plane", 400000, 0.0, 400)
137ut.bookHist(h, "EkinLow", "Ekin of particles in sens plane", 1000, 0.0, 0.001)
138for n in range(sTree.GetEntries()):
139 rc = sTree.GetEvent(n)
140 for aHit in sTree.vetoPoint:
141 oTrack = sTree.MCTrack[aHit.GetTrackID()]
142 _p = ut.get_particle(oTrack.GetPdgCode())
143 M = _p.Mass()
144 Ekin = ROOT.TMath.Sqrt(aHit.GetPx() ** 2 + aHit.GetPy() ** 2 + aHit.GetPz() ** 2 + M**2) - M
145 rc = h["Ekin"].Fill(Ekin)
146 rc = h["EkinLow"].Fill(Ekin)
147ut.bookCanvas(h, key=s, title=s, nx=900, ny=600, cx=1, cy=1)
148tc = h[s].cd(1)
149tc.SetLogy(1)
150h["Ekin"].Draw()
151
152# tungsten dedex mev cm**2/g 1.145 * rho g/cm-3 19.3 * 0.1
153# interactionLength 191.9 / 19.3 = 9.94cm, 0.1/9.94 = 1%
154
155# -----Finish-------------------------------------------------------
156timer.Stop()
157rtime = timer.RealTime()
158ctime = timer.CpuTime()
159print(" ")
160print("Macro finished successfully.")
161print("Output file is ", outFile)
162print("Real time ", rtime, " s, CPU time ", ctime, "s")
create_config(str DecayVolumeMedium="helium", float Yheight=6.0, int strawDesign=10, str shieldName="TRY_2026", int nuTargetPassive=1, bool SND=True, SND_design=None, TARGET_YAML=None)
None configure(darkphoton=None)