Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-21 08:24:39

0001 #
0002 #
0003 import os
0004 import sys
0005 import time
0006 import DDG4
0007 from DDG4 import OutputLevel as Output
0008 from g4units import GeV, m
0009 #
0010 #
0011 """
0012 
0013    dd4hep simulation example setup using the python configuration
0014 
0015    @author  M.Frank
0016    @version 1.0
0017 
0018 """
0019 
0020 
0021 def run():
0022   kernel = DDG4.Kernel()
0023   install_dir = os.environ['DD4hepExamplesINSTALL']
0024   kernel.loadGeometry(str("file:" + install_dir + "/examples/DDCodex/compact/CODEX-b-alone.xml"))
0025 
0026   DDG4.importConstants(kernel.detectorDescription(), debug=False)
0027   geant4 = DDG4.Geant4(kernel, tracker='Geant4TrackerCombineAction')
0028   geant4.printDetectors()
0029   # Configure UI
0030   if len(sys.argv) > 1:
0031     geant4.setupCshUI(macro=sys.argv[1])
0032   else:
0033     geant4.setupCshUI()
0034 
0035   # Configure field
0036   geant4.setupTrackingField(prt=True)
0037   # Configure Event actions
0038   prt = DDG4.EventAction(kernel, 'Geant4ParticlePrint/ParticlePrint')
0039   prt.OutputLevel = Output.WARNING
0040   prt.OutputType = 3  # Print both: table and tree
0041   kernel.eventAction().adopt(prt)
0042 
0043   # Configure I/O
0044   geant4.setupROOTOutput('RootOutput', 'CodexB_' + time.strftime('%Y-%m-%d_%H-%M'))
0045 
0046   # Setup particle gun
0047 
0048   # gun = geant4.setupGun("Gun",particle='pi+',
0049   gun = geant4.setupGun("Gun", particle='mu-',
0050                         energy=1000 * GeV,
0051                         multiplicity=1,
0052                         isotrop=False, Standalone=True,
0053                         direction=(1, 0, 0),
0054                         # direction=(0.866025,0,0.5),
0055                         position='(0,0,12650)')
0056   # position='(0,0,0)')
0057   gun.print = True
0058   """
0059   gen =  DDG4.GeneratorAction(kernel,"Geant4InputAction/Input")
0060   # gen.Input = "Geant4EventReaderHepMC|"+
0061   #             "/afs/cern.ch/work/j/jongho/Project_DD4hep/Test/DD4hep/examples/DDG4/data/hepmc_geant4.dat"
0062   gen.Input = "Geant4EventReaderHepMC|"+
0063               "/afs/cern.ch/work/j/jongho/Project_DD4hep/Test/DD4hep/DDG4/examples/MinBias_HepMC.txt"
0064   gen.MomentumScale = 1.0
0065   gen.Mask = 1
0066   geant4.buildInputStage([gen],output_level=Output.DEBUG)
0067   """
0068 
0069   seq, action = geant4.setupTracker('CODEXb')
0070   # action.OutputLevel = Output.ERROR
0071   # seq,action = geant4.setupTracker('Shield')
0072   # action.OutputLevel = Output.ERROR
0073 
0074   # And handle the simulation particles.
0075   part = DDG4.GeneratorAction(kernel, "Geant4ParticleHandler/ParticleHandler")
0076   kernel.generatorAction().adopt(part)
0077   part.OutputLevel = Output.INFO
0078   part.enableUI()
0079   user = DDG4.Action(kernel, "Geant4TCUserParticleHandler/UserParticleHandler")
0080   user.TrackingVolume_Zmax = 999999. * m  # Something big. All is a tracker
0081   user.TrackingVolume_Rmax = 999999. * m
0082   user.enableUI()
0083   part.adopt(user)
0084 
0085   # Now build the physics list:
0086   # phys = kernel.physicsList()
0087   phys = geant4.setupPhysics('QGSP_BERT')
0088   ph = DDG4.PhysicsList(kernel, 'Geant4PhysicsList/Myphysics')
0089   ph.addParticleConstructor('G4LeptonConstructor')
0090   ph.addParticleConstructor('G4BaryonConstructor')
0091   ph.addParticleConstructor('G4MesonConstructor')
0092   ph.addParticleConstructor('G4BosonConstructor')
0093   ph.enableUI()
0094   phys.adopt(ph)
0095   phys.enableUI()
0096   phys.dump()
0097   # run
0098   kernel.configure()
0099   kernel.initialize()
0100   kernel.run()
0101   kernel.terminate()
0102 
0103 
0104 if __name__ == "__main__":
0105   run()