File indexing completed on 2026-07-17 07:53:21
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, cm
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/FiberTubeCalorimeter.xml"))
0035
0036 DDG4.importConstants(kernel.detectorDescription(), debug=False)
0037 geant4 = DDG4.Geant4(kernel, tracker='Geant4TrackerCombineAction')
0038 geant4.printDetectors()
0039
0040 if args.macro:
0041 ui = geant4.setupCshUI(macro=args.macro)
0042 else:
0043 ui = geant4.setupCshUI()
0044 if args.batch:
0045 ui.Commands = ['/run/beamOn ' + str(args.events), '/ddg4/UI/terminate']
0046
0047
0048 geant4.setupTrackingField(prt=True)
0049
0050 prt = DDG4.EventAction(kernel, 'Geant4ParticlePrint/ParticlePrint')
0051 prt.OutputLevel = Output.DEBUG
0052 prt.OutputType = 3
0053 kernel.eventAction().adopt(prt)
0054
0055 generator_output_level = Output.INFO
0056
0057
0058 seq, act = geant4.addDetectorConstruction("Geant4DetectorGeometryConstruction/ConstructGeo")
0059 act.DebugMaterials = True
0060 act.DebugElements = False
0061 act.DebugVolumes = True
0062 act.DebugShapes = True
0063 seq, act = geant4.addDetectorConstruction("Geant4DetectorSensitivesConstruction/ConstructSD")
0064
0065
0066 geant4.setupROOTOutput('RootOutput', 'FiberTubeCalorimeter_' + time.strftime('%Y-%m-%d_%H-%M'))
0067
0068
0069 pos = (0.0, 0.0, -364.0 * cm)
0070 gun = geant4.setupGun("Gun", particle='e+', energy=50 * GeV, multiplicity=1, position=pos)
0071 gun.OutputLevel = generator_output_level
0072
0073
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
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.setupCalorimeter('FiberTubeCalorimeter')
0087
0088
0089 phys = geant4.setupPhysics('QGSP_BERT')
0090 phys.dump()
0091 geant4.execute()
0092
0093
0094 if __name__ == "__main__":
0095 run()