-
Notifications
You must be signed in to change notification settings - Fork 1
/
endcapsim.py
executable file
·102 lines (83 loc) · 3.13 KB
/
endcapsim.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
"""
DD4hep simulation with some argument parsing
Based on M. Frank and F. Gaede runSim.py
@author A.Sailer
@version 0.1
Modified with settings for RICH simulation
"""
from __future__ import absolute_import, unicode_literals
import logging
import sys
import os
from DDSim.DD4hepSimulation import DD4hepSimulation
if __name__ == "__main__":
logging.basicConfig(
format="%(name)-16s %(levelname)s %(message)s",
level=logging.INFO,
stream=sys.stdout,
)
logger = logging.getLogger("DDSim")
SIM = DD4hepSimulation()
# Default is enable visualization of tracks
SIM.runType = "qt"
SIM.macroFile ='vis.mac'
# Ensure that Cerenkov and optical physics are always loaded
def setupCerenkov(kernel):
from DDG4 import PhysicsList
seq = kernel.physicsList()
cerenkov = PhysicsList(kernel, "Geant4CerenkovPhysics/CerenkovPhys")
cerenkov.MaxNumPhotonsPerStep = 10
cerenkov.MaxBetaChangePerStep = 10.0
cerenkov.TrackSecondariesFirst = False
cerenkov.VerboseLevel = 0
cerenkov.enableUI()
seq.adopt(cerenkov)
ph = PhysicsList(kernel, "Geant4OpticalPhotonPhysics/OpticalGammaPhys")
ph.addParticleConstructor("G4OpticalPhoton")
ph.VerboseLevel = 0
ph.BoundaryInvokeSD = True
ph.enableUI()
seq.adopt(ph)
return None
SIM.physics.setupUserPhysics(setupCerenkov)
# Allow energy depositions to 0 energy in trackers (which include optical detectors)
SIM.filter.tracker = "edep0"
# Some detectors are only sensitive to optical photons
SIM.filter.filters["opticalphotons"] = dict(
name="ParticleSelectFilter/OpticalPhotonSelector",
parameter={"particle": "opticalphoton"},
)
SIM.filter.mapDetFilter["ARCENDCAP"] = "opticalphotons"
# Use the optical tracker for the PFRICH
SIM.action.mapActions["ARCENDCAP"] = "Geant4OpticalTrackerAction"
# Disable user tracker particle handler, so hits can be associated to photons
SIM.part.userParticleHandler = ""
# Particle gun settings: pions with fixed energy and theta, varying phi
SIM.numberOfEvents = 1000
SIM.enableGun = True
SIM.gun.energy = "50*GeV"
SIM.gun.particle = "pi+"
#SIM.gun.thetaMin = "55*deg"
#SIM.gun.thetaMax = "90*deg"
#SIM.gun.phiMin = "0*deg"
#SIM.gun.phiMax = "45.1*deg"
SIM.gun.distribution = "uniform"
SIM.gun.multiplicity = 1
SIM.gun.position = "0 0 0*cm"
# Default compact file
SIM.compactFile = "./compact/arc_endcap_v0.xml"
# Output file (assuming CWD)
SIM.outputFile = "arcsime.root"
# Override with user options
SIM.parseOptions()
# Run the simulation
try:
SIM.run()
logger.info("TEST: passed")
if os.path.getsize( SIM.outputFile ) < 1000000 :
raise RuntimeError("Output file not found or size less than 1MB")
except NameError as e:
logger.fatal("TEST: failed")
if "global name" in str(e):
globalToSet = str(e).split("'")[1]
logger.fatal("Unknown global variable, please add\nglobal %s\nto your steeringFile" % globalToSet)