Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-22 08:03:57

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 import logging
0010 import sys
0011 import os
0012 
0013 from DDSim.DD4hepSimulation import DD4hepSimulation
0014 
0015 
0016 if __name__ == "__main__":
0017     logging.basicConfig(
0018         format="%(name)-16s %(levelname)s %(message)s",
0019         level=logging.INFO,
0020         stream=sys.stdout,
0021         )
0022     logger = logging.getLogger("DDSim")
0023 
0024     SIM = DD4hepSimulation()
0025 
0026     # Ensure that Cerenkov and optical physics are always loaded
0027     def setupCerenkov(kernel):
0028         from DDG4 import PhysicsList
0029 
0030         seq = kernel.physicsList()
0031         cerenkov = PhysicsList(kernel, "Geant4CerenkovPhysics/CerenkovPhys")
0032         cerenkov.MaxNumPhotonsPerStep = 10
0033         cerenkov.MaxBetaChangePerStep = 10.0
0034         cerenkov.TrackSecondariesFirst = False
0035         cerenkov.VerboseLevel = 0
0036         cerenkov.enableUI()
0037         seq.adopt(cerenkov)
0038         ph = PhysicsList(kernel, "Geant4OpticalPhotonPhysics/OpticalGammaPhys")
0039         ph.addParticleConstructor("G4OpticalPhoton")
0040         ph.VerboseLevel = 0
0041         ph.enableUI()
0042         seq.adopt(ph)
0043         return None
0044 
0045     SIM.physics.setupUserPhysics(setupCerenkov)
0046 
0047     # Allow energy depositions to 0 energy in trackers (which include optical detectors)
0048     SIM.filter.tracker = "edep0"
0049 
0050     # Some detectors are only sensitive to optical photons
0051     SIM.filter.filters["opticalphotons"] = dict(
0052         name="ParticleSelectFilter/OpticalPhotonSelector",
0053         parameter={"particle": "opticalphoton"},
0054         )
0055     SIM.filter.mapDetFilter["PFRICH"] = "opticalphotons"
0056 
0057     # Use the optical tracker for the PFRICH
0058     SIM.action.mapActions["PFRICH"] = "Geant4OpticalTrackerAction"
0059 
0060     # Disable user tracker particle handler, so hits can be associated to photons
0061     SIM.part.userParticleHandler = ""
0062 
0063     # Particle gun settings: pions with fixed energy and theta, varying phi
0064     SIM.numberOfEvents = 100
0065     SIM.enableGun = True
0066     SIM.gun.energy = "40*GeV"
0067     SIM.gun.particle = "pi+"
0068     SIM.gun.thetaMin = "195.0*deg"
0069     SIM.gun.thetaMax = "195.1*deg"
0070     SIM.gun.distribution = "cos(theta)"
0071 
0072     # Installed compact file, otherwise assume the user passed `--compactFile`
0073     install_prefix = os.environ.get("DD4hepExamplesINSTALL")
0074     if install_prefix:
0075         SIM.compactFile = install_prefix + "/examples/RICH/compact/pfrich.xml"
0076 
0077     # Output file (assuming CWD)
0078     SIM.outputFile = "sim.root"
0079     SIM.outputConfig.forceDD4HEP = True
0080 
0081     # Override with user options
0082     SIM.parseOptions()
0083 
0084     # Run the simulation
0085     try:
0086         SIM.run()
0087         logger.info("TEST: passed")
0088     except NameError as e:
0089         logger.fatal("TEST: failed")
0090         if "global name" in str(e):
0091             globalToSet = str(e).split("'")[1]
0092             logger.fatal("Unknown global variable, please add\nglobal %s\nto your steeringFile" % globalToSet)