File indexing completed on 2026-09-23 08:24:21
0001
0002
0003
0004
0005
0006
0007
0008
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 @author M.Frank
0023 @version 1.0
0024
0025 """
0026
0027
0028 def run():
0029 import os
0030 import DDG4
0031
0032 args = DDG4.CommandLine()
0033 if args.help:
0034 import sys
0035 logger.info("""
0036 python <dir>/TestUserCommands.py -option [-option]
0037 -vis Enable visualization
0038 -macro Pass G4 macro file to UI executive
0039 """)
0040 sys.exit(0)
0041
0042 kernel = DDG4.Kernel()
0043 install = os.environ['DD4hepExamplesINSTALL']
0044 geo_file = "file:" + install + "/examples/ClientTests/compact/BoxTrafos.xml"
0045 kernel.loadGeometry(str(geo_file))
0046 geant4 = DDG4.Geant4(kernel)
0047
0048 if args.macro:
0049 ui = geant4.setupCshUI(macro=args.macro, vis=args.vis)
0050 else:
0051 ui = geant4.setupCshUI(vis=args.vis)
0052
0053 ui.HaveUI = False
0054
0055 ui.ConfigureCommands = ['/ddg4/Print/param configure-command-1',
0056 '/ddg4/Print/print_param',
0057 '/ddg4/Print/param configure-command-2',
0058 '/ddg4/Print/print_param']
0059 ui.InitializeCommands = ['/ddg4/Print/param initialize-command-1',
0060 '/ddg4/Print/print_param',
0061 '/ddg4/Print/param initialize-command-2',
0062 '/ddg4/Print/print_param']
0063 ui.PreRunCommands = ['/ddg4/Print/param pre-run-command-1',
0064 '/ddg4/Print/print_param',
0065 '/ddg4/Print/param pre-run-command-2',
0066 '/ddg4/Print/print_param']
0067 ui.TerminateCommands = ['/ddg4/Print/param terminate-command-1',
0068 '/ddg4/Print/print_param',
0069 '/ddg4/Print/param terminate-command-2',
0070 '/ddg4/Print/print_param',
0071 '/ddg4/UI/terminate']
0072
0073 ui.PostRunCommands = ['/ddg4/Print/param post-run-command-1',
0074 '/ddg4/Print/print_param',
0075 '/ddg4/Print/param post-run-command-2',
0076 '/ddg4/Print/print_param']
0077
0078 prt = DDG4.Action(kernel, 'TestPrintAction/Print')
0079 prt.enableUI()
0080 kernel.registerGlobalAction(prt)
0081
0082 ui.applyCommand('/ddg4/Print/param interactive-1')
0083 ui.applyCommand('/ddg4/Print/print_param')
0084
0085
0086 geant4.setupPhysics('QGSP_BERT')
0087 logger.info('# Execute some G4 action using the UI handle from DDG4....')
0088 geant4.ui().applyCommand('/ddg4/Print/param interactive-2')
0089 geant4.ui().applyCommand('/ddg4/Print/print_param')
0090
0091
0092 logger.info("# No we should see the configuration commands:")
0093 kernel.configure()
0094 logger.info("# No we should see the initialization commands:")
0095 kernel.initialize()
0096 kernel.NumEvents = 0
0097 logger.info("# No we should see the pre-run commands:")
0098 kernel.run()
0099 logger.info("# No we should see the termination commands:")
0100 ui.applyCommand('/ddg4/Print/param interactive-3')
0101 ui.applyCommand('/ddg4/Print/print_param')
0102 kernel.terminate()
0103
0104
0105 if __name__ == "__main__":
0106 run()