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