FairShip
Loading...
Searching...
No Matches
study_GammaConv.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 os
6import sys
7import time
8from typing import NamedTuple
9
10import ROOT
11import shipRoot_conf
12
13ROOT.gROOT.ProcessLine('#include "FairModule.h"')
14time.sleep(20)
15
16import geometry_config
17import shipunit as u
18
19mcEngine = "TGeant4"
20runnr = 1
21nev = 10 # 000000
22
23
24class Setup(NamedTuple):
25 """Target block and beam configuration for one photon-conversion study point."""
26
27 thickness: float
28 material: str
29 momentum: float
30
31
32setup = {
33 "10": Setup(2 * u.cm, "Aluminium", 10 * u.GeV),
34 "100": Setup(2 * u.cm, "Aluminium", 100 * u.GeV),
35 "200": Setup(2 * u.cm, "Aluminium", 200 * u.GeV),
36}
37
38# 8cm = 0.9X0
39
40
41s = sys.argv[1]
42thickness, material, momentum = setup[s]
43
44checkOverlap = True
45
46outFile = "gconv" + s + ".root"
47theSeed = int(10000 * time.time() % 10000000)
48ecut = 0.0
49
50# -------------------------------------------------------------------
51ROOT.gRandom.SetSeed(theSeed) # this should be propagated via ROOT to Pythia8 and Geant4VMC
52shipRoot_conf.configure() # load basic libraries, prepare atexit for python
53ship_geo = geometry_config.create_config(Yheight=10, shieldName="TRY_2026")
54
55# -----Timer--------------------------------------------------------
56timer = ROOT.TStopwatch()
57timer.Start()
58
59# -----Create simulation run----------------------------------------
60run = ROOT.FairRunSim()
61run.SetName(mcEngine) # Transport engine
62sink = ROOT.FairRootFileSink(outFile)
63run.SetSink(sink)
64ROOT.SetOwnership(sink, False) # C++ FairRun takes ownership
65
66boostFactor = 100.0
67if boostFactor > 1:
68 # Turn off UseGeneralProcess to access GammaToMuons directly when cross-sections need to be changed
69 os.environ["SET_GENERAL_PROCESS_TO_FALSE"] = "1"
70run.SetUserConfig("g4Config.C") # user configuration file default g4Config.C
71rtdb = run.GetRuntimeDb()
72
73# -----Materials----------------------------------------------
74run.SetMaterials("media.geo")
75# -----Create geometry----------------------------------------------
76cave = ROOT.ShipCave("CAVE")
77cave.SetGeometryFileName("cave.geo")
78run.AddModule(cave)
79
80
81class Block(ROOT.pyFairModule):
82 "block of material"
83
84 def __init__(self) -> None:
85 ROOT.pyFairModule.__init__(self, self)
86 self.sensPlane = None
87
88 def ConstructGeometry(self) -> None:
89 print("Construct Block")
90 top = ROOT.gGeoManager.GetTopVolume()
91 geoLoad = ROOT.FairGeoLoader.Instance()
92 geoFace = geoLoad.getGeoInterface()
93 media = geoFace.getMedia()
94 geoBuild = geoLoad.getGeoBuilder()
95 ShipMedium = media.getMedium(material)
96 W = ROOT.gGeoManager.GetMedium(material)
97 if not W:
98 geoBuild.createMedium(ShipMedium)
99 W = ROOT.gGeoManager.GetMedium(material)
100 aBox = ROOT.gGeoManager.MakeBox("target", W, 100.0 * u.cm, 100.0 * u.cm, thickness)
101 top.AddNode(aBox, 1, ROOT.TGeoTranslation(0, 0, 0))
102 if self.sensPlane:
103 self.sensPlane.AddSensitiveVolume(aBox)
104
105 def InitParContainers() -> None:
106 print("not implemented!")
107
108 def makeSensitive(self, sensPlane) -> None:
109 self.sensPlane = sensPlane
110
111
112sensPlane = ROOT.exitHadronAbsorber()
113sensPlane.SetEnergyCut(ecut * u.GeV)
114sensPlane.SetZposition(thickness + 10 * u.cm)
115run.AddModule(sensPlane)
116target = Block()
117target.makeSensitive(sensPlane)
118run.AddModule(target)
119
120primGen = ROOT.FairPrimaryGenerator()
121myPgun = ROOT.FairBoxGenerator(22, 1) # pdg id and multiplicity
122myPgun.SetPRange(momentum - 0.01, momentum + 0.01)
123myPgun.SetPhiRange(0, 0) # // Azimuth angle range [degree]
124myPgun.SetThetaRange(0, 0) # // Polar angle in lab system range [degree]
125myPgun.SetXYZ(0.0 * u.cm, 0.0 * u.cm, -10.0 * u.cm - (thickness))
126primGen.AddGenerator(myPgun)
127run.SetGenerator(primGen)
128#
129run.SetGenerator(primGen)
130# -----Initialize simulation run------------------------------------
131run.Init()
132gMC = ROOT.TVirtualMC.GetMC()
133
134fStack = gMC.GetStack()
135fStack.SetMinPoints(1)
136fStack.SetEnergyCut(-1.0)
137
138if boostFactor > 1:
139 ROOT.gROOT.ProcessLine('#include "Geant4/G4ProcessTable.hh"')
140 ROOT.gROOT.ProcessLine('#include "Geant4/G4AnnihiToMuPair.hh"')
141 ROOT.gROOT.ProcessLine('#include "Geant4/G4GammaConversionToMuons.hh"')
142 gProcessTable = ROOT.G4ProcessTable.GetProcessTable()
143 procAnnihil = gProcessTable.FindProcess(ROOT.G4String("AnnihiToMuPair"), ROOT.G4String("e+"))
144 procGMuPair = gProcessTable.FindProcess(ROOT.G4String("GammaToMuPair"), ROOT.G4String("gamma"))
145 procGMuPair.SetCrossSecFactor(boostFactor)
146 procAnnihil.SetCrossSecFactor(boostFactor)
147
148# -----Start run----------------------------------------------------
149run.Run(nev)
150
151# -----Start Analysis---------------
152ROOT.gROOT.ProcessLine('#include "Geant4/G4EmParameters.hh"')
153emP = ROOT.G4EmParameters.Instance()
154emP.Dump()
155
156import rootUtils as ut
157
158f = ROOT.gROOT.GetListOfFiles()[0]
159h = {}
160ut.bookHist(h, "muons", "muon mult", 10, -0.5, 9.5)
161ut.bookHist(h, "electrons", "e mult", 10, -0.5, 9.5)
162sTree = f.Get("cbmsim")
163for n in range(sTree.GetEntries()):
164 rc = sTree.GetEvent(n)
165 nMu = 0
166 nEl = 0
167 for aHit in sTree.vetoPoint:
168 if abs(sTree.MCTrack[aHit.GetTrackID()].GetPdgCode()) == 13:
169 nMu += 1
170 if abs(sTree.MCTrack[aHit.GetTrackID()].GetPdgCode()) == 11:
171 nEl += 1
172 rc = h["muons"].Fill(nMu)
173 rc = h["electrons"].Fill(nEl)
174h["muons"].Draw()
175
176# -----Finish-------------------------------------------------------
177timer.Stop()
178rtime = timer.RealTime()
179ctime = timer.CpuTime()
180print(" ")
181print("Macro finished successfully.")
182print("Output file is ", outFile)
183print("Real time ", rtime, " s, CPU time ", ctime, "s")
None makeSensitive(self, sensPlane)
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)