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
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 logger = DDG4.Logger('BoxOfStraws')
0035 install_dir = os.environ['DD4hepExamplesINSTALL']
0036
0037 if args.sensitive:
0038 kernel.loadGeometry(str('file:' + install_dir + '/examples/ClientTests/compact/BoxOfStraws_sensitive.xml'))
0039 else:
0040 kernel.loadGeometry(str('file:' + install_dir + '/examples/ClientTests/compact/BoxOfStraws.xml'))
0041
0042 DDG4.importConstants(kernel.detectorDescription(), debug=False)
0043 geant4 = DDG4.Geant4(kernel)
0044 geant4.printDetectors()
0045
0046 if args.macro:
0047 ui = geant4.setupCshUI(macro=args.macro)
0048 else:
0049 ui = geant4.setupCshUI()
0050 if args.batch:
0051 ui.Commands = ['/run/beamOn ' + str(args.events), '/ddg4/UI/terminate']
0052
0053
0054 geant4.setupTrackingField(prt=True)
0055
0056 prt = DDG4.EventAction(kernel, 'Geant4ParticlePrint/ParticlePrint')
0057 prt.OutputLevel = Output.DEBUG
0058 prt.OutputType = 3
0059 kernel.eventAction().adopt(prt)
0060
0061 seq, act = geant4.addDetectorConstruction('Geant4DetectorConstructionResources/ResourcesBeforeConstruction')
0062 act.When = "geometry"
0063
0064
0065 seq, act = geant4.addDetectorConstruction('Geant4DetectorGeometryConstruction/ConstructGeo')
0066 act.DebugVolumes = True
0067
0068 if args.sensitive:
0069
0070 seq, act = geant4.addDetectorConstruction('Geant4DetectorSensitivesConstruction/ConstructSD')
0071 else:
0072
0073 seq, act = geant4.addDetectorConstruction('Geant4RegexSensitivesConstruction/ConstructSDRegEx')
0074 act.Detector = 'BoxOfStrawsDet'
0075 act.OutputLevel = Output.ALWAYS
0076 act.Match = ['gas_']
0077
0078 seq, act = geant4.addDetectorConstruction('Geant4DetectorConstructionResources/ResourcesAfterConstruction')
0079 act.When = "sensitives"
0080
0081
0082 geant4.setupROOTOutput('RootOutput', 'BoxOfStraws_' + time.strftime('%Y-%m-%d_%H-%M'))
0083
0084
0085 gun = geant4.setupGun('Gun', particle='pi+', energy=10 * GeV, multiplicity=1)
0086 gun.OutputLevel = Output.INFO
0087 gun.enableUI()
0088
0089
0090 part = DDG4.GeneratorAction(kernel, 'Geant4ParticleHandler/ParticleHandler')
0091 kernel.generatorAction().adopt(part)
0092 part.SaveProcesses = ['Decay']
0093 part.MinimalKineticEnergy = 50 * MeV
0094 user = DDG4.Action(kernel, 'Geant4TCUserParticleHandler/UserParticleHandler')
0095 user.TrackingVolume_Zmax = 2.5 * m
0096 user.TrackingVolume_Rmax = 2.5 * m
0097 part.adopt(user)
0098
0099
0100 sd = geant4.description.sensitiveDetector(str('BoxOfStrawsDet'))
0101 logger.info(f'+++ BoxOfStraws: SD type: {str(sd.type())}')
0102 energy_filter = DDG4.Filter(kernel, 'EnergyDepositMinimumCut')
0103 energy_filter.Cut = 1.0 * MeV
0104 energy_filter.enableUI()
0105 kernel.registerGlobalFilter(energy_filter)
0106 seq, act = geant4.setupDetector(name='BoxOfStrawsDet', action='MyTrackerSDAction')
0107 seq.adopt(energy_filter)
0108 act.HaveCellID = False
0109
0110
0111 phys = geant4.setupPhysics(str('QGSP_BERT'))
0112 phys.dump()
0113 if args.simultate:
0114 geant4.execute()
0115 else:
0116 geant4.kernel().configure()
0117 geant4.kernel().initialize()
0118 geant4.kernel().terminate()
0119
0120
0121 if __name__ == "__main__":
0122 run()