Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:14:55

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 from __future__ import absolute_import, unicode_literals
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 DDG4
0032 
0033   args = DDG4.CommandLine()
0034   if args.help:
0035     import sys
0036     logger.info("""
0037          python <dir>/TestUserCommands.py -option [-option]
0038               -vis                            Enable visualization
0039               -macro                          Pass G4 macro file to UI executive
0040     """)
0041     sys.exit(0)
0042 
0043   kernel = DDG4.Kernel()
0044   install = os.environ['DD4hepExamplesINSTALL']
0045   geo_file = "file:" + install + "/examples/ClientTests/compact/BoxTrafos.xml"
0046   kernel.loadGeometry(str(geo_file))
0047   geant4 = DDG4.Geant4(kernel)
0048   # Configure UI
0049   if args.macro:
0050     ui = geant4.setupCshUI(macro=args.macro, vis=args.vis)
0051   else:
0052     ui = geant4.setupCshUI(vis=args.vis)
0053 
0054   ui.HaveUI = False
0055 
0056   ui.ConfigureCommands = ['/ddg4/Print/param configure-command-1',
0057                           '/ddg4/Print/print_param',
0058                           '/ddg4/Print/param configure-command-2',
0059                           '/ddg4/Print/print_param']
0060   ui.InitializeCommands = ['/ddg4/Print/param initialize-command-1',
0061                            '/ddg4/Print/print_param',
0062                            '/ddg4/Print/param initialize-command-2',
0063                            '/ddg4/Print/print_param']
0064   ui.PreRunCommands = ['/ddg4/Print/param pre-run-command-1',
0065                        '/ddg4/Print/print_param',
0066                        '/ddg4/Print/param pre-run-command-2',
0067                        '/ddg4/Print/print_param']
0068   ui.TerminateCommands = ['/ddg4/Print/param terminate-command-1',
0069                           '/ddg4/Print/print_param',
0070                           '/ddg4/Print/param terminate-command-2',
0071                           '/ddg4/Print/print_param',
0072                           '/ddg4/UI/terminate']
0073   # Post-run commands are only executed in interactive mode!
0074   ui.PostRunCommands = ['/ddg4/Print/param post-run-command-1',
0075                         '/ddg4/Print/print_param',
0076                         '/ddg4/Print/param post-run-command-2',
0077                         '/ddg4/Print/print_param']
0078 
0079   prt = DDG4.Action(kernel, 'TestPrintAction/Print')
0080   prt.enableUI()
0081   kernel.registerGlobalAction(prt)
0082 
0083   ui.applyCommand('/ddg4/Print/param interactive-1')
0084   ui.applyCommand('/ddg4/Print/print_param')
0085 
0086   # Now build the physics list:
0087   geant4.setupPhysics('QGSP_BERT')
0088   logger.info('# Execute some G4 action using the UI handle from DDG4....')
0089   geant4.ui().applyCommand('/ddg4/Print/param interactive-2')
0090   geant4.ui().applyCommand('/ddg4/Print/print_param')
0091 
0092   # Start the engine...
0093   logger.info("# No we should see the configuration commands:")
0094   kernel.configure()
0095   logger.info("# No we should see the initialization commands:")
0096   kernel.initialize()
0097   kernel.NumEvents = 0
0098   logger.info("# No we should see the pre-run commands:")
0099   kernel.run()
0100   logger.info("# No we should see the termination commands:")
0101   ui.applyCommand('/ddg4/Print/param interactive-3')
0102   ui.applyCommand('/ddg4/Print/print_param')
0103   kernel.terminate()
0104 
0105 
0106 if __name__ == "__main__":
0107   run()