Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-07-13 07:39:04

0001 #
0002 #
0003 import os
0004 import time
0005 import DDG4
0006 from DDG4 import OutputLevel as Output
0007 from g4units import GeV
0008 #
0009 #
0010 """
0011 
0012    dd4hep simulation example setup using the python configuration
0013 
0014    @author  M.Frank
0015    @version 1.0
0016 
0017 """
0018 
0019 
0020 def run():
0021   args = DDG4.CommandLine()
0022   kernel = DDG4.Kernel()
0023   install_dir = os.environ['DD4hepExamplesINSTALL']
0024   kernel.loadGeometry(str("file:" + install_dir + "/examples/ClientTests/compact/SiliconBlock.xml"))
0025   DDG4.importConstants(kernel.detectorDescription(), debug=False)
0026   # =======================================================================================
0027   # ===> This is actually the ONLY difference to ClientTests/scripts/SiliconBlock.py
0028   # =======================================================================================
0029   geant4 = DDG4.Geant4(kernel, tracker='MyTrackerSDAction')
0030   geant4.printDetectors()
0031 
0032   # Configure UI
0033   if args.macro:
0034     ui = geant4.setupCshUI(macro=args.macro)
0035   else:
0036     ui = geant4.setupCshUI()
0037   if args.batch:
0038     ui.Commands = ['/run/beamOn ' + str(args.events), '/ddg4/UI/terminate']
0039 
0040   # Configure field
0041   geant4.setupTrackingField(prt=True)
0042   # Configure Event actions
0043   prt = DDG4.EventAction(kernel, 'Geant4ParticlePrint/ParticlePrint')
0044   prt.OutputLevel = Output.WARNING
0045   prt.OutputType = 3  # Print both: table and tree
0046   kernel.eventAction().adopt(prt)
0047 
0048   # Configure I/O
0049   geant4.setupROOTOutput('RootOutput', 'MySD_' + time.strftime('%Y-%m-%d_%H-%M'), mc_truth=False)
0050   # Setup particle gun
0051   geant4.setupGun("Gun", particle='mu-', energy=5 * GeV, multiplicity=1, Standalone=True, position=(0, 0, 0))
0052   seq, act = geant4.setupTracker('SiliconBlockUpper')
0053   act.OutputLevel = Output.INFO
0054   seq, act = geant4.setupTracker('SiliconBlockDown')
0055   act.OutputLevel = Output.INFO
0056   # Now build the physics list:
0057   phys = kernel.physicsList()
0058   phys.extends = 'QGSP_BERT'
0059   phys.enableUI()
0060   phys.dump()
0061   # run
0062   kernel.configure()
0063   kernel.initialize()
0064   kernel.run()
0065   kernel.terminate()
0066 
0067 
0068 if __name__ == "__main__":
0069   run()