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