File indexing completed on 2025-02-25 09:20:19
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 from __future__ import absolute_import, unicode_literals
0014 import os
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 args = DDG4.CommandLine()
0033 kernel = DDG4.Kernel()
0034 install_dir = os.environ['DD4hepExamplesINSTALL']
0035 kernel.loadGeometry(str("file:" + install_dir + "/examples/ClientTests/compact/SiliconBlock.xml"))
0036
0037 DDG4.importConstants(kernel.detectorDescription(), debug=False)
0038 geant4 = DDG4.Geant4(kernel, tracker='Geant4TrackerCombineAction')
0039 geant4.registerInterruptHandler()
0040 geant4.printDetectors()
0041
0042 if args.macro:
0043 ui = geant4.setupCshUI(macro=args.macro)
0044 else:
0045 ui = geant4.setupCshUI()
0046 if args.batch:
0047 ui.Commands = ['/run/beamOn ' + str(args.events), '/ddg4/UI/terminate']
0048
0049
0050 geant4.setupTrackingField(prt=True)
0051
0052 prt = DDG4.EventAction(kernel, 'Geant4ParticlePrint/ParticlePrint')
0053 prt.OutputLevel = Output.DEBUG
0054 prt.OutputType = 3
0055 kernel.eventAction().adopt(prt)
0056
0057 generator_output_level = Output.INFO
0058
0059
0060 seq, act = geant4.addDetectorConstruction("Geant4DetectorGeometryConstruction/ConstructGeo")
0061 act.DebugMaterials = True
0062 act.DebugElements = False
0063 act.DebugVolumes = True
0064 act.DebugShapes = True
0065 seq, act = geant4.addDetectorConstruction("Geant4DetectorSensitivesConstruction/ConstructSD")
0066
0067
0068 geant4.setupROOTOutput('RootOutput', 'SiliconBlock_' + time.strftime('%Y-%m-%d_%H-%M'))
0069
0070
0071 gun = geant4.setupGun("Gun", particle='e+', energy=20 * GeV, multiplicity=1)
0072 gun.OutputLevel = generator_output_level
0073
0074
0075 part = DDG4.GeneratorAction(kernel, "Geant4ParticleHandler/ParticleHandler")
0076 kernel.generatorAction().adopt(part)
0077 part.SaveProcesses = ['Decay']
0078 part.MinimalKineticEnergy = 100 * MeV
0079 part.OutputLevel = Output.INFO
0080 part.enableUI()
0081 user = DDG4.Action(kernel, "Geant4TCUserParticleHandler/UserParticleHandler")
0082 user.TrackingVolume_Zmax = 3.0 * m
0083 user.TrackingVolume_Rmax = 3.0 * m
0084 user.enableUI()
0085 part.adopt(user)
0086
0087 geant4.setupTracker('SiliconBlockUpper')
0088 geant4.setupTracker('SiliconBlockDown')
0089
0090
0091 phys = geant4.setupPhysics('QGSP_BERT')
0092 ph = DDG4.PhysicsList(kernel, str('Geant4PhysicsList/Myphysics'))
0093 ph.addParticleConstructor(str('G4Geantino'))
0094 ph.addParticleConstructor(str('G4BosonConstructor'))
0095 ph.enableUI()
0096 phys.adopt(ph)
0097 phys.dump()
0098
0099 geant4.execute()
0100
0101
0102 if __name__ == "__main__":
0103 run()