Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-20 07:37:09

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 #
0013 import os
0014 import sys
0015 import time
0016 import DDG4
0017 from DDG4 import OutputLevel as Output
0018 from g4units import GeV, MeV, m
0019 #
0020 #
0021 """
0022 
0023    dd4hep simulation example setup using the python configuration
0024 
0025    @author  M.Frank
0026    @version 1.0
0027 
0028 """
0029 
0030 
0031 def run():
0032   kernel = DDG4.Kernel()
0033   install_dir = os.environ['DD4hepExamplesINSTALL']
0034   kernel.loadGeometry(str("file:" + install_dir + "/examples/ClientTests/compact/Issue_786.xml"))
0035   DDG4.importConstants(kernel.detectorDescription(), debug=False)
0036   geant4 = DDG4.Geant4(kernel, tracker='Geant4TrackerCombineAction')
0037   geant4.printDetectors()
0038   # Configure UI
0039   if len(sys.argv) > 1:
0040     geant4.setupCshUI(macro=sys.argv[1])
0041   else:
0042     geant4.setupCshUI()
0043 
0044   # Configure field
0045   geant4.setupTrackingField(prt=True)
0046   # Configure Event actions
0047   prt = DDG4.EventAction(kernel, 'Geant4ParticlePrint/ParticlePrint')
0048   prt.OutputLevel = Output.DEBUG
0049   prt.OutputType = 3  # Print both: table and tree
0050   kernel.eventAction().adopt(prt)
0051 
0052   generator_output_level = Output.INFO
0053 
0054   # Configure G4 geometry setup
0055   seq, act = geant4.addDetectorConstruction("Geant4DetectorGeometryConstruction/ConstructGeo")
0056   act.DebugMaterials = False
0057   act.DebugElements = False
0058   act.DebugVolumes = True
0059   act.DebugShapes = True
0060   act.DebugPlacements = True
0061 
0062   # Configure I/O
0063   geant4.setupROOTOutput('RootOutput', 'Issue_' + time.strftime('%Y-%m-%d_%H-%M'))
0064 
0065   # Setup particle gun
0066   gun = geant4.setupGun("Gun", particle='mu-', energy=20 * GeV, multiplicity=1)
0067   gun.OutputLevel = generator_output_level
0068 
0069   # And handle the simulation particles.
0070   part = DDG4.GeneratorAction(kernel, "Geant4ParticleHandler/ParticleHandler")
0071   kernel.generatorAction().adopt(part)
0072   part.SaveProcesses = ['Decay']
0073   part.MinimalKineticEnergy = 100 * MeV
0074   part.OutputLevel = Output.INFO  # generator_output_level
0075   part.enableUI()
0076   user = DDG4.Action(kernel, "Geant4TCUserParticleHandler/UserParticleHandler")
0077   user.TrackingVolume_Zmax = 3.0 * m
0078   user.TrackingVolume_Rmax = 3.0 * m
0079   user.enableUI()
0080   part.adopt(user)
0081 
0082   geant4.setupTracker('Issue')
0083 
0084   # Now build the physics list:
0085   phys = geant4.setupPhysics('QGSP_BERT')
0086   ph = DDG4.PhysicsList(kernel, str('Geant4PhysicsList/Myphysics'))
0087   ph.addParticleConstructor(str('G4Geantino'))
0088   ph.addParticleConstructor(str('G4BosonConstructor'))
0089   ph.enableUI()
0090   phys.adopt(ph)
0091   phys.dump()
0092 
0093   geant4.execute()
0094 
0095 
0096 if __name__ == "__main__":
0097   run()