File indexing completed on 2025-01-18 09:14:58
0001 """
0002 DD4hep simulation with some argument parsing
0003 Based on M. Frank and F. Gaede runSim.py
0004 @author A.Sailer
0005 @version 0.1
0006
0007 Modified with settings for RICH simulation
0008 """
0009 from __future__ import absolute_import, unicode_literals
0010 import logging
0011 import sys
0012 import os
0013
0014 from DDSim.DD4hepSimulation import DD4hepSimulation
0015
0016
0017 if __name__ == "__main__":
0018 logging.basicConfig(
0019 format="%(name)-16s %(levelname)s %(message)s",
0020 level=logging.INFO,
0021 stream=sys.stdout,
0022 )
0023 logger = logging.getLogger("DDSim")
0024
0025 SIM = DD4hepSimulation()
0026
0027
0028 def setupCerenkov(kernel):
0029 from DDG4 import PhysicsList
0030
0031 seq = kernel.physicsList()
0032 cerenkov = PhysicsList(kernel, "Geant4CerenkovPhysics/CerenkovPhys")
0033 cerenkov.MaxNumPhotonsPerStep = 10
0034 cerenkov.MaxBetaChangePerStep = 10.0
0035 cerenkov.TrackSecondariesFirst = False
0036 cerenkov.VerboseLevel = 0
0037 cerenkov.enableUI()
0038 seq.adopt(cerenkov)
0039 ph = PhysicsList(kernel, "Geant4OpticalPhotonPhysics/OpticalGammaPhys")
0040 ph.addParticleConstructor("G4OpticalPhoton")
0041 ph.VerboseLevel = 0
0042 ph.enableUI()
0043 seq.adopt(ph)
0044 return None
0045
0046 SIM.physics.setupUserPhysics(setupCerenkov)
0047
0048
0049 SIM.filter.tracker = "edep0"
0050
0051
0052 SIM.filter.filters["opticalphotons"] = dict(
0053 name="ParticleSelectFilter/OpticalPhotonSelector",
0054 parameter={"particle": "opticalphoton"},
0055 )
0056 SIM.filter.mapDetFilter["PFRICH"] = "opticalphotons"
0057
0058
0059 SIM.action.mapActions["PFRICH"] = "Geant4OpticalTrackerAction"
0060
0061
0062 SIM.part.userParticleHandler = ""
0063
0064
0065 SIM.numberOfEvents = 100
0066 SIM.enableGun = True
0067 SIM.gun.energy = "40*GeV"
0068 SIM.gun.particle = "pi+"
0069 SIM.gun.thetaMin = "195.0*deg"
0070 SIM.gun.thetaMax = "195.1*deg"
0071 SIM.gun.distribution = "cos(theta)"
0072
0073
0074 install_prefix = os.environ.get("DD4hepExamplesINSTALL")
0075 if install_prefix:
0076 SIM.compactFile = install_prefix + "/examples/RICH/compact/pfrich.xml"
0077
0078
0079 SIM.outputFile = "sim.root"
0080 SIM.outputConfig.forceDD4HEP = True
0081
0082
0083 SIM.parseOptions()
0084
0085
0086 try:
0087 SIM.run()
0088 logger.info("TEST: passed")
0089 except NameError as e:
0090 logger.fatal("TEST: failed")
0091 if "global name" in str(e):
0092 globalToSet = str(e).split("'")[1]
0093 logger.fatal("Unknown global variable, please add\nglobal %s\nto your steeringFile" % globalToSet)