Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-19 07:36:43

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 logging
0014 #
0015 logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.INFO)
0016 logger = logging.getLogger(__name__)
0017 #
0018 #
0019 """
0020 
0021    dd4hep simulation example setup using the python configuration
0022 
0023    @author  M.Frank
0024    @version 1.0
0025 
0026 """
0027 
0028 
0029 def run():
0030   import os
0031   import sys
0032   import time
0033   import DDG4
0034   args = DDG4.CommandLine()
0035   install_dir = os.environ['DD4hepExamplesINSTALL']
0036   install_dir = install_dir + "/examples/ClientTests/compact"
0037   if args.help:
0038     logger.info("""
0039          python <dir>/ParamValue.py -option [-option]
0040               -geometry <geometry file name>  File is expected in the examples
0041                                               install area:
0042                                               """ + install_dir + """
0043               -vis                            Enable visualization
0044               -macro                          Pass G4 macro file to UI executive
0045               -batch                          Run in batch mode for unit testing
0046               -events <number>                Run geant4 for specified number of events
0047                                               (batch mode only)
0048     """)
0049     sys.exit(0)
0050 
0051   from DDG4 import OutputLevel as Output
0052   from g4units import GeV, MeV, mm
0053 
0054   kernel = DDG4.Kernel()
0055   kernel.loadGeometry(str("file:" + install_dir + os.sep + args.geometry))
0056 
0057   DDG4.importConstants(kernel.detectorDescription(), debug=False)
0058   geant4 = DDG4.Geant4(kernel, calo='Geant4CalorimeterAction')
0059   geant4.printDetectors()
0060 
0061   # Configure UI
0062   if args.macro:
0063     ui = geant4.setupCshUI(macro=args.macro, vis=args.vis)
0064   else:
0065     ui = geant4.setupCshUI(vis=args.vis)
0066   if args.batch:
0067     ui.Commands = ['/run/beamOn ' + str(args.events), '/ddg4/UI/terminate']
0068 
0069   if args.sensitive:
0070     geant4.setupDetectors()
0071 
0072   # Configure field
0073   geant4.setupTrackingField(prt=True)
0074   # Configure Event actions
0075   prt = DDG4.EventAction(kernel, 'Geant4ParticlePrint/ParticlePrint')
0076   prt.OutputLevel = Output.DEBUG
0077   prt.OutputType = 3  # Print both: table and tree
0078   kernel.eventAction().adopt(prt)
0079 
0080   generator_output_level = Output.INFO
0081 
0082   # Configure G4 geometry setup
0083   seq, act = geant4.addDetectorConstruction("Geant4DetectorGeometryConstruction/ConstructGeo")
0084   act.DebugMaterials = True
0085   act.DebugElements = False
0086   act.DebugVolumes = True
0087   act.DebugShapes = True
0088   seq, act = geant4.addDetectorConstruction("Geant4DetectorSensitivesConstruction/ConstructSD")
0089 
0090   # Configure I/O
0091   geant4.setupROOTOutput('RootOutput', 'ParamVolume1D_' + time.strftime('%Y-%m-%d_%H-%M'))
0092 
0093   # Setup particle gun
0094   gun = geant4.setupGun("Gun", particle='e+', energy=20 * GeV, multiplicity=1)
0095   gun.OutputLevel = generator_output_level
0096 
0097   # 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 = Output.INFO  # generator_output_level
0103   part.enableUI()
0104   user = DDG4.Action(kernel, "Geant4TCUserParticleHandler/UserParticleHandler")
0105   user.TrackingVolume_Zmax = 1 * mm
0106   user.TrackingVolume_Rmax = 1 * mm
0107   user.enableUI()
0108   part.adopt(user)
0109 
0110   # Now build the physics list:
0111   phys = geant4.setupPhysics('QGSP_BERT')
0112   ph = DDG4.PhysicsList(kernel, str('Geant4PhysicsList/Myphysics'))
0113   ph.addParticleConstructor(str('G4Geantino'))
0114   ph.addParticleConstructor(str('G4BosonConstructor'))
0115   ph.enableUI()
0116   phys.adopt(ph)
0117   phys.dump()
0118 
0119   geant4.execute()
0120 
0121 
0122 if __name__ == "__main__":
0123   run()