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   from DDG4 import OutputLevel as Output
0033   from g4units import keV
0034 
0035   args = DDG4.CommandLine()
0036   install_dir = os.environ['DD4hepExamplesINSTALL']
0037   if args.help:
0038     import sys
0039     logger.info("""
0040          python <dir>/Channeling.py -option [-option]
0041               -geometry <geometry file name>  File is expected in the examples
0042                                               install area:
0043                                               """ + install_dir + """
0044               -vis                            Enable visualization
0045               -macro                          Pass G4 macro file to UI executive
0046               -batch                          Run in batch mode for unit testing
0047               -events <number>                Run geant4 for specified number of events
0048                                               (batch mode only)
0049     """)
0050     sys.exit(0)
0051 
0052   kernel = DDG4.Kernel()
0053   kernel.loadGeometry(str("file:" + install_dir + "/examples/DDG4/compact/Channeling.xml"))
0054 
0055   DDG4.importConstants(kernel.detectorDescription(), debug=False)
0056   geant4 = DDG4.Geant4(kernel, tracker='Geant4TrackerCombineAction')
0057   geant4.printDetectors()
0058   # Configure UI
0059   if args.macro:
0060     ui = geant4.setupCshUI(macro=args.macro, vis=args.vis)
0061   else:
0062     ui = geant4.setupCshUI(vis=args.vis)
0063 
0064   if args.batch:
0065     ui.Commands = ['/run/beamOn ' + str(args.events), '/ddg4/UI/terminate']
0066 
0067   # Configure field
0068   geant4.setupTrackingField(prt=True)
0069   # Configure Event actions
0070   prt = DDG4.EventAction(kernel, 'Geant4ParticlePrint/ParticlePrint')
0071   prt.OutputLevel = Output.DEBUG
0072   prt.OutputType = 3  # Print both: table and tree
0073   kernel.eventAction().adopt(prt)
0074 
0075   generator_output_level = Output.INFO
0076 
0077   # Configure G4 geometry setup
0078   seq, act = geant4.addDetectorConstruction("Geant4DetectorGeometryConstruction/ConstructGeo")
0079   act.DebugMaterials = True
0080   act.DebugElements = False
0081   act.DebugVolumes = True
0082   act.DebugShapes = True
0083   act.DebugSurfaces = True
0084 
0085   # Setup particle gun
0086   gun = geant4.setupGun("Gun", particle='gamma', energy=5 * keV, multiplicity=1)
0087   gun.OutputLevel = generator_output_level
0088 
0089   geant4.setupTracker('ChannelingDevice')
0090 
0091   # Instantiate the stacking action
0092   stacking = DDG4.StackingAction(kernel, 'TestStackingAction/MyStacker')
0093   kernel.stackingAction().add(stacking)
0094 
0095   # Now build the physics list:
0096   phys = geant4.setupPhysics('QGSP_BERT')
0097   ph = DDG4.PhysicsList(kernel, 'Channeling')
0098   ph.addPhysicsConstructor(str('Geant4ChannelingPhysics'))
0099   ph.enableUI()
0100   phys.adopt(ph)
0101   phys.dump()
0102   # Start the engine...
0103   geant4.execute()
0104 
0105 
0106 if __name__ == "__main__":
0107   run()