Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-07-15 07:39:44

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 import logging
0013 #
0014 logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.INFO)
0015 logger = logging.getLogger(__name__)
0016 #
0017 #
0018 """
0019 
0020    dd4hep simulation example setup using the python configuration
0021 
0022 """
0023 
0024 
0025 def run():
0026   import os
0027   import DDG4
0028   from DDG4 import OutputLevel as Output
0029   from g4units import GeV, keV
0030 
0031   kernel = DDG4.Kernel()
0032   install_dir = os.environ['DD4hepExamplesINSTALL']
0033   kernel.loadGeometry(str("file:" + install_dir + "/examples/ClientTests/compact/SiliconBlock.xml"))
0034 
0035   DDG4.importConstants(kernel.detectorDescription(), debug=False)
0036   geant4 = DDG4.Geant4(kernel, tracker='Geant4TrackerCombineAction')
0037   geant4.printDetectors()
0038   # Configure UI
0039   geant4.setupUI(typ="tcsh", vis=False, macro=None, ui=False)
0040 
0041   # Configure field
0042   geant4.setupTrackingField(prt=True)
0043   # Configure Event actions
0044   prt = DDG4.EventAction(kernel, 'Geant4ParticlePrint/ParticlePrint')
0045   prt.OutputLevel = Output.DEBUG
0046   prt.OutputType = 3  # Print both: table and tree
0047   kernel.eventAction().adopt(prt)
0048 
0049   generator_output_level = Output.INFO
0050 
0051   # Configure G4 geometry setup
0052   seq, act = geant4.addDetectorConstruction("Geant4DetectorGeometryConstruction/ConstructGeo")
0053   act.DebugMaterials = True
0054   act.DebugElements = False
0055   act.DebugVolumes = True
0056   act.DebugShapes = True
0057   act.DebugSurfaces = True
0058 
0059   # Setup particle gun
0060   gun = geant4.setupGun("Gun", particle='gamma', energy=1 * GeV, multiplicity=1)
0061   gun.direction = (0.0, 0.0, 1.0)
0062   gun.OutputLevel = generator_output_level
0063   kernel.NumEvents = 10
0064   # Instantiate the stepping action
0065   stepping = DDG4.SteppingAction(kernel, 'TestSteppingAction/MyStepper')
0066   kernel.steppingAction().add(stepping)
0067 
0068   # And handle the simulation particles.
0069   part = DDG4.GeneratorAction(kernel, "Geant4ParticleHandler/ParticleHandler")
0070   kernel.generatorAction().adopt(part)
0071   part.SaveProcesses = ['conv', 'Decay']
0072   part.MinimalKineticEnergy = 1 * keV
0073   part.KeepAllParticles = False
0074   part.PrintEndTracking = True
0075   part.enableUI()
0076 
0077   # Now build the physics list:
0078   phys = geant4.setupPhysics('QGSP_BERT')
0079   phys.dump()
0080   # Start the engine...
0081   geant4.execute()
0082 
0083 
0084 if __name__ == "__main__":
0085   run()