File indexing completed on 2026-09-22 08:03:39
0001
0002
0003
0004
0005
0006
0007
0008
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 NOTE:
0025 If you get to the command prompt, you must not forget to enable GFlash!
0026 By default Geant4 does not enable it. Hence:
0027 Idle> /GFlash/flag 1
0028
0029 @author M.Frank
0030 @version 1.0
0031
0032 """
0033
0034
0035 def run():
0036 args = DDG4.CommandLine()
0037 kernel = DDG4.Kernel()
0038 install_dir = os.environ['DD4hepExamplesINSTALL']
0039 kernel.loadGeometry(str("file:" + install_dir + "/examples/ClientTests/compact/SiliconBlock.xml"))
0040
0041 DDG4.importConstants(kernel.detectorDescription(), debug=False)
0042 geant4 = DDG4.Geant4(kernel, tracker='Geant4TrackerAction', calo='Geant4CalorimeterAction')
0043 geant4.printDetectors()
0044
0045 if args.macro:
0046 ui = geant4.setupCshUI(macro=args.macro)
0047 else:
0048 ui = geant4.setupCshUI()
0049 if args.batch:
0050 ui.Commands = ['/run/beamOn ' + str(args.events), '/ddg4/UI/terminate']
0051
0052
0053 geant4.setupTrackingField(prt=True)
0054
0055 prt = DDG4.EventAction(kernel, 'Geant4ParticlePrint/ParticlePrint')
0056 prt.OutputLevel = Output.DEBUG
0057 kernel.eventAction().adopt(prt)
0058
0059 generator_output_level = prt.OutputLevel
0060
0061
0062 seq, act = geant4.addDetectorConstruction('Geant4DetectorGeometryConstruction/ConstructGeo')
0063 act.DebugMaterials = True
0064 act.DebugElements = False
0065 act.DebugVolumes = True
0066 act.DebugShapes = True
0067
0068
0069 sensitives = DDG4.DetectorConstruction(kernel, str('Geant4DetectorSensitivesConstruction/ConstructSD'))
0070 sensitives.enableUI()
0071 seq.adopt(sensitives)
0072
0073
0074 model = DDG4.DetectorConstruction(kernel, str('Geant4Par01EMShowerModel/ShowerModel'))
0075
0076 model.RegionName = 'SiRegion'
0077 model.Material = 'Silicon'
0078 model.ApplicableParticles = ['e+', 'e-']
0079 model.Etrigger = {'e+': 0.1 * GeV, 'e-': 0.1 * GeV}
0080 model.Enable = True
0081
0082 model.Emin = {'e+': 0.1 * GeV, 'e-': 0.1 * GeV}
0083 model.Ekill = {'e+': 0.1 * MeV, 'e-': 0.1 * MeV}
0084 model.enableUI()
0085 seq.adopt(model)
0086
0087
0088 geant4.setupROOTOutput('RootOutput', 'SiliconBlock_FastSim_' + time.strftime('%Y-%m-%d_%H-%M'))
0089
0090
0091 gun = geant4.setupGun("Gun", particle='e+', energy=50 * GeV, multiplicity=1)
0092 gun.OutputLevel = generator_output_level
0093
0094
0095 part = DDG4.GeneratorAction(kernel, "Geant4ParticleHandler/ParticleHandler")
0096 kernel.generatorAction().adopt(part)
0097 part.SaveProcesses = ['Decay']
0098 part.MinimalKineticEnergy = 100 * MeV
0099 part.OutputLevel = Output.INFO
0100 part.enableUI()
0101 user = DDG4.Action(kernel, "Geant4TCUserParticleHandler/UserParticleHandler")
0102 user.TrackingVolume_Zmax = 3.0 * m
0103 user.TrackingVolume_Rmax = 3.0 * m
0104 user.enableUI()
0105 part.adopt(user)
0106
0107 geant4.setupCalorimeter('SiliconBlockUpper')
0108 geant4.setupCalorimeter('SiliconBlockDown')
0109
0110
0111 phys = geant4.setupPhysics('FTFP_BERT')
0112 ph = DDG4.PhysicsList(kernel, str('Geant4FastPhysics/FastPhysicsList'))
0113 ph.EnabledParticles = ['e+', 'e-']
0114 ph.BeVerbose = True
0115 ph.enableUI()
0116 phys.adopt(ph)
0117 phys.dump()
0118
0119 geant4.execute()
0120
0121
0122 if __name__ == "__main__":
0123 run()