Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-30 08:06:59

0001 # ==========================================================================
0002 #  AIDA Detector description implementation
0003 # --------------------------------------------------------------------------
0004 # Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
0005 # All rights reserved.
0006 #
0007 # For the licensing terms see $DD4hepINSTALL/LICENSE.
0008 # For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
0009 #
0010 # ==========================================================================
0011 #
0012 #
0013 import os
0014 import time
0015 import DDG4
0016 import logging
0017 from g4units import GeV, MeV, m
0018 logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.INFO)
0019 logger = logging.getLogger(__name__)
0020 #
0021 #
0022 """
0023 
0024    dd4hep simulation example setup using the python configuration
0025 
0026    @author  M.Frank
0027    @version 1.0
0028 
0029 """
0030 
0031 
0032 def run():
0033   args = DDG4.CommandLine()
0034   kernel = DDG4.Kernel()
0035   install_dir = os.environ['DD4hepExamplesINSTALL']
0036   kernel.loadGeometry(str("file:" + install_dir + "/examples/ClientTests/compact/DriftChamber.xml"))
0037 
0038   DDG4.importConstants(kernel.detectorDescription(), debug=False)
0039   geant4 = DDG4.Geant4(kernel, tracker='Geant4TrackerCombineAction')
0040   geant4.registerInterruptHandler()
0041   geant4.printDetectors()
0042   # Configure UI
0043   if args.macro:
0044     ui = geant4.setupCshUI(macro=args.macro)
0045   else:
0046     ui = geant4.setupCshUI()
0047 
0048   cmds = []
0049   if args.verbose:
0050     cmds.append('/run/verbose ' + str(args.verbose))
0051 
0052   if args.events:
0053     cmds.append('/run/beamOn ' + str(args.events))
0054     cmds.append('/ddg4/UI/terminate')
0055 
0056   if len(cmds) > 0:
0057     ui.Commands = cmds
0058 
0059   logger.info("#  Configure G4 magnetic field tracking")
0060   geant4.setupTrackingField()
0061 
0062   logger.info("#  Setup random generator")
0063   rndm = DDG4.Action(kernel, 'Geant4Random/Random')
0064   rndm.Seed = 987654321
0065   if args.seed_time:
0066     rndm.Seed = int(time.time())
0067   rndm.initialize()
0068 
0069   gen = DDG4.GeneratorAction(kernel, "Geant4GeneratorActionInit/GenerationInit")
0070   kernel.generatorAction().adopt(gen)
0071 
0072   logger.info("""
0073   Generation of isotrope tracks of a given multiplicity with overlay:
0074   """)
0075   logger.info("#  First particle generator: pi+")
0076   gen = DDG4.GeneratorAction(kernel, "Geant4IsotropeGenerator/IsotropPi+")
0077   gen.Mask = 1
0078   gen.Particle = 'pi+'
0079   gen.Energy = 100 * GeV
0080   gen.Multiplicity = 2
0081   gen.Distribution = 'cos(theta)'
0082   kernel.generatorAction().adopt(gen)
0083   logger.info("#  Install vertex smearing for this interaction")
0084 
0085   logger.info("#  Merge all existing interaction records")
0086   gen = DDG4.GeneratorAction(kernel, "Geant4InteractionMerger/InteractionMerger")
0087   gen.OutputLevel = 4  # generator_output_level
0088   gen.enableUI()
0089   kernel.generatorAction().adopt(gen)
0090   #
0091   logger.info("#  Finally generate Geant4 primaries")
0092   gen = DDG4.GeneratorAction(kernel, "Geant4PrimaryHandler/PrimaryHandler")
0093   gen.OutputLevel = 4  # generator_output_level
0094   gen.enableUI()
0095   kernel.generatorAction().adopt(gen)
0096   #
0097   logger.info("#  ....and handle the simulation particles.")
0098   part = DDG4.GeneratorAction(kernel, "Geant4ParticleHandler/ParticleHandler")
0099   kernel.generatorAction().adopt(part)
0100   part.SaveProcesses = ['Decay']
0101   part.MinimalKineticEnergy = 100 * MeV
0102   part.OutputLevel = 5  # generator_output_level
0103   part.enableUI()
0104   user = DDG4.Action(kernel, "Geant4TCUserParticleHandler/UserParticleHandler")
0105   user.TrackingVolume_Zmax = 1.5 * m
0106   user.TrackingVolume_Rmax = 1.5 * m
0107   user.enableUI()
0108   part.adopt(user)
0109   #
0110   seq, act = geant4.setupTracker('DriftChamber')
0111   #
0112   logger.info("#  Now build the physics list:")
0113   phys = geant4.setupPhysics('QGSP_BERT')
0114   phys.verbosity = 0
0115   ph = geant4.addPhysics(str('Geant4PhysicsList/Myphysics'))
0116   ph.addPhysicsConstructor(str('G4StepLimiterPhysics'))
0117   #
0118   phys.dump()
0119   #
0120   kernel.configure()
0121   kernel.initialize()
0122 
0123   # DDG4.setPrintLevel(Output.DEBUG)
0124   kernel.run()
0125   kernel.terminate()
0126 
0127 
0128 if __name__ == "__main__":
0129   run()