Back to home page

EIC code displayed by LXR

 
 

    


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

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