File indexing completed on 2026-05-26 07:36:52
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 import logging
0014
0015 logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.INFO)
0016 logger = logging.getLogger(__name__)
0017
0018
0019 """
0020
0021 dd4hep simulation example setup using the python configuration
0022
0023 NOTE:
0024 If you get to the command prompt, you must not forget to enable GFlash!
0025 By default Geant4 does not enable it. Hence:
0026 Idle> /GFlash/flag 1
0027
0028 @author M.Frank
0029 @version 1.0
0030
0031 """
0032
0033
0034 def run():
0035 import os
0036 import time
0037 import DDG4
0038 args = DDG4.CommandLine()
0039 if args.help:
0040 import sys
0041 logger.info("""
0042 python <dir>/ParamValue.py -option [-option]
0043 -geometry <geometry file> Geometry with full path
0044 -vis Enable visualization
0045 -macro Pass G4 macro file to UI executive
0046 -batch Run in batch mode for unit testing
0047 -events <number> Run geant4 for specified number of events
0048 (batch mode only)
0049 """)
0050 sys.exit(0)
0051
0052 from DDG4 import OutputLevel as Output
0053 from g4units import GeV, MeV, m
0054 kernel = DDG4.Kernel()
0055 if args.geometry:
0056 kernel.loadGeometry(str("file:" + args.geometry))
0057 else:
0058 install_dir = os.environ['DD4hepExamplesINSTALL']
0059 kernel.loadGeometry(str("file:" + install_dir + "/examples/ClientTests/compact/SiliconBlock.xml"))
0060
0061 DDG4.importConstants(kernel.detectorDescription(), debug=False)
0062 geant4 = DDG4.Geant4(kernel, tracker='Geant4TrackerCombineAction', calo='Geant4CalorimeterAction')
0063 geant4.printDetectors()
0064
0065 if args.macro:
0066 ui = geant4.setupCshUI(macro=args.macro, vis=args.vis)
0067 else:
0068 ui = geant4.setupCshUI()
0069 if args.batch:
0070 ui.Commands = ['/run/beamOn ' + str(args.events), '/ddg4/UI/terminate']
0071
0072
0073 geant4.setupTrackingField(prt=True)
0074
0075 prt = DDG4.EventAction(kernel, 'Geant4ParticlePrint/ParticlePrint')
0076 prt.OutputLevel = Output.DEBUG
0077 kernel.eventAction().adopt(prt)
0078
0079 generator_output_level = prt.OutputLevel
0080
0081
0082 seq, act = geant4.addDetectorConstruction('Geant4DetectorGeometryConstruction/ConstructGeo')
0083 act.DebugMaterials = True
0084 act.DebugElements = False
0085 act.DebugVolumes = True
0086 act.DebugShapes = True
0087
0088
0089 sensitives = DDG4.DetectorConstruction(kernel, str('Geant4DetectorSensitivesConstruction/ConstructSD'))
0090 sensitives.enableUI()
0091 seq.adopt(sensitives)
0092
0093
0094 model = DDG4.DetectorConstruction(kernel, str('Geant4GFlashShowerModel/ShowerModel'))
0095 model.Parametrization = 'GFlashHomoShowerParameterisation'
0096
0097 model.RegionName = 'SiRegion'
0098 model.Material = 'Silicon'
0099 model.Enable = True
0100
0101 model.Emin = {'e+': 0.1 * GeV, 'e-': 0.1 * GeV}
0102 model.Emax = {'e+': 100 * GeV, 'e-': 100 * GeV}
0103 model.Ekill = {'e+': 0.1 * MeV, 'e-': 0.1 * MeV}
0104 model.enableUI()
0105 seq.adopt(model)
0106
0107
0108 geant4.setupROOTOutput('RootOutput', 'SiliconBlock_GFlash_' + time.strftime('%Y-%m-%d_%H-%M'))
0109
0110
0111 gun = geant4.setupGun("Gun", particle='e+', energy=50 * GeV, multiplicity=1)
0112 gun.OutputLevel = generator_output_level
0113
0114
0115 part = DDG4.GeneratorAction(kernel, "Geant4ParticleHandler/ParticleHandler")
0116 kernel.generatorAction().adopt(part)
0117 part.SaveProcesses = ['Decay']
0118 part.MinimalKineticEnergy = 100 * MeV
0119 part.OutputLevel = Output.INFO
0120 part.enableUI()
0121 user = DDG4.Action(kernel, "Geant4TCUserParticleHandler/UserParticleHandler")
0122 user.TrackingVolume_Zmax = 3.0 * m
0123 user.TrackingVolume_Rmax = 3.0 * m
0124 user.enableUI()
0125 part.adopt(user)
0126
0127 geant4.setupTracker('SiliconBlockUpper')
0128 geant4.setupTracker('SiliconBlockDown')
0129
0130
0131 phys = geant4.setupPhysics('FTFP_BERT')
0132 ph = DDG4.PhysicsList(kernel, str('Geant4FastPhysics/FastPhysicsList'))
0133 ph.EnabledParticles = ['e+', 'e-']
0134 ph.BeVerbose = True
0135 ph.enableUI()
0136 phys.adopt(ph)
0137 phys.dump()
0138
0139 geant4.execute()
0140
0141
0142 if __name__ == "__main__":
0143 run()