File indexing completed on 2026-05-31 07:50:19
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 import os
0014 import time
0015 import DDG4
0016 from DDG4 import OutputLevel as Output
0017 from g4units import GeV, mm, cm
0018 import logging
0019
0020 logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.INFO)
0021 logger = logging.getLogger(__name__)
0022
0023
0024
0025 """
0026
0027 dd4hep simulation example setup using the python configuration
0028
0029 @author M.Frank
0030 @version 1.0
0031
0032 """
0033
0034
0035 def run():
0036 args = DDG4.CommandLine()
0037 kernel = DDG4.Kernel()
0038 description = kernel.detectorDescription()
0039
0040 install_dir = os.environ['DD4hepExamplesINSTALL']
0041 kernel.loadGeometry(str("file:" + install_dir + "/examples/ClientTests/compact/LheD_tracker.xml"))
0042
0043 DDG4.importConstants(description, debug=False)
0044 geant4 = DDG4.Geant4(kernel, tracker='Geant4TrackerCombineAction')
0045 geant4.printDetectors()
0046
0047
0048 geant4.setupCshUI()
0049
0050
0051 if args.batch:
0052 kernel.UI = ''
0053
0054
0055 geant4.setupTrackingField(prt=True)
0056
0057 prt = DDG4.EventAction(kernel, 'Geant4ParticlePrint/ParticlePrint')
0058 prt.OutputLevel = Output.WARNING
0059 prt.OutputType = 3
0060 kernel.eventAction().adopt(prt)
0061
0062
0063 geant4.setupROOTOutput('RootOutput', 'LHeD_tracker_' + time.strftime('%Y-%m-%d_%H-%M'))
0064 gen = geant4.setupGun("Gun", particle='geantino', energy=20 * GeV, position=(0 * mm, 0 * mm, 0 * cm), multiplicity=3)
0065 gen.isotrop = False
0066 gen.direction = (1, 0, 0)
0067 gen.OutputLevel = Output.WARNING
0068
0069
0070
0071
0072 phys = geant4.setupPhysics('QGSP_BERT')
0073 ph = DDG4.PhysicsList(kernel, 'Geant4PhysicsList/Myphysics')
0074 ph.addParticleConstructor(str('G4Geantino'))
0075 ph.addParticleConstructor(str('G4BosonConstructor'))
0076 ph.enableUI()
0077 phys.adopt(ph)
0078 phys.dump()
0079
0080 kernel.configure()
0081 kernel.initialize()
0082
0083
0084 kernel.run()
0085 logger.info('End of run. Terminating .......')
0086 kernel.terminate()
0087
0088
0089 if __name__ == "__main__":
0090 run()