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 """
0024 
0025 
0026 def run():
0027   import os
0028   import DDG4
0029   from DDG4 import OutputLevel as Output
0030   from g4units import GeV, keV
0031 
0032   kernel = DDG4.Kernel()
0033   install_dir = os.environ['DD4hepExamplesINSTALL']
0034   kernel.loadGeometry(str("file:" + install_dir + "/examples/ClientTests/compact/SiliconBlock.xml"))
0035 
0036   DDG4.importConstants(kernel.detectorDescription(), debug=False)
0037   geant4 = DDG4.Geant4(kernel, tracker='Geant4TrackerCombineAction')
0038   geant4.printDetectors()
0039   # Configure UI
0040   geant4.setupUI(typ="tcsh", vis=False, macro=None, ui=False)
0041 
0042   # Configure field
0043   geant4.setupTrackingField(prt=True)
0044   # Configure Event actions
0045   prt = DDG4.EventAction(kernel, 'Geant4ParticlePrint/ParticlePrint')
0046   prt.OutputLevel = Output.DEBUG
0047   prt.OutputType = 3  # Print both: table and tree
0048   kernel.eventAction().adopt(prt)
0049 
0050   generator_output_level = Output.INFO
0051 
0052   # Configure G4 geometry setup
0053   seq, act = geant4.addDetectorConstruction("Geant4DetectorGeometryConstruction/ConstructGeo")
0054   act.DebugMaterials = True
0055   act.DebugElements = False
0056   act.DebugVolumes = True
0057   act.DebugShapes = True
0058   act.DebugSurfaces = True
0059 
0060   # Setup particle gun
0061   gun = geant4.setupGun("Gun", particle='gamma', energy=1 * GeV, multiplicity=1)
0062   gun.direction = (0.0, 0.0, 1.0)
0063   gun.OutputLevel = generator_output_level
0064   kernel.NumEvents = 10
0065   # Instantiate the stepping action
0066   stepping = DDG4.SteppingAction(kernel, 'TestSteppingAction/MyStepper')
0067   kernel.steppingAction().add(stepping)
0068 
0069   # And handle the simulation particles.
0070   part = DDG4.GeneratorAction(kernel, "Geant4ParticleHandler/ParticleHandler")
0071   kernel.generatorAction().adopt(part)
0072   part.SaveProcesses = ['conv', 'Decay']
0073   part.MinimalKineticEnergy = 1 * keV
0074   part.KeepAllParticles = False
0075   part.PrintEndTracking = True
0076   part.enableUI()
0077 
0078   # Now build the physics list:
0079   phys = geant4.setupPhysics('QGSP_BERT')
0080   phys.dump()
0081   # Start the engine...
0082   geant4.execute()
0083 
0084 
0085 if __name__ == "__main__":
0086   run()