Back to home page

EIC code displayed by LXR

 
 

    


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

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