File indexing completed on 2025-01-30 09:17:45
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, cm
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/FiberTubeCalorimeter.xml"))
0036
0037 DDG4.importConstants(kernel.detectorDescription(), debug=False)
0038 geant4 = DDG4.Geant4(kernel, tracker='Geant4TrackerCombineAction')
0039 geant4.printDetectors()
0040
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
0049 geant4.setupTrackingField(prt=True)
0050
0051 prt = DDG4.EventAction(kernel, 'Geant4ParticlePrint/ParticlePrint')
0052 prt.OutputLevel = Output.DEBUG
0053 prt.OutputType = 3
0054 kernel.eventAction().adopt(prt)
0055
0056 generator_output_level = Output.INFO
0057
0058
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
0067 geant4.setupROOTOutput('RootOutput', 'FiberTubeCalorimeter_' + time.strftime('%Y-%m-%d_%H-%M'))
0068
0069
0070 pos = (0.0, 0.0, -364.0 * cm)
0071 gun = geant4.setupGun("Gun", particle='e+', energy=50 * GeV, multiplicity=1, position=pos)
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.setupCalorimeter('FiberTubeCalorimeter')
0088
0089
0090 phys = geant4.setupPhysics('QGSP_BERT')
0091 phys.dump()
0092 geant4.execute()
0093
0094
0095 if __name__ == "__main__":
0096 run()