File indexing completed on 2025-01-30 09:17:45
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 """
0012 dd4hep example setup using the python configuration
0013
0014 \author M.Frank
0015 \version 1.0
0016
0017 """
0018 from __future__ import absolute_import, unicode_literals
0019 import logging
0020 import math
0021 import time
0022 import sys
0023 import os
0024 from g4units import rad, GeV, MeV, mm, m
0025
0026 logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.INFO)
0027 logger = logging.getLogger(__name__)
0028
0029
0030 def show_help():
0031 logging.info("Check_shape.py -option [-option] ")
0032 logging.info(" -geometry <geometry file> Geometry file ")
0033 logging.info(" -vis Enable visualization ")
0034 logging.info(" -batch Batch execution ")
0035
0036
0037 def run():
0038 geo = None
0039 vis = False
0040 batch = False
0041 install_dir = os.environ['DD4hepINSTALL']
0042 for i in list(range(len(sys.argv))):
0043 c = sys.argv[i].upper()
0044 if c.find('BATCH') < 2 and c.find('BATCH') >= 0:
0045 batch = True
0046 elif c[:4] == '-GEO':
0047 geo = sys.argv[i + 1]
0048 elif c[:4] == '-VIS':
0049 vis = True
0050
0051 if not geo:
0052 show_help()
0053 sys.exit(1)
0054
0055 import DDG4
0056 Output = DDG4.OutputLevel
0057 kernel = DDG4.Kernel()
0058
0059 geant4 = DDG4.Geant4(kernel, tracker='Geant4TrackerCombineAction')
0060 if batch:
0061 ui = geant4.setupCshUI(ui=None, vis=None)
0062 kernel.UI = 'UI'
0063 else:
0064 ui = geant4.setupCshUI(vis=vis)
0065 kernel.loadGeometry(geo)
0066
0067 geant4.setupTrackingField(prt=True)
0068
0069 logger.info("# Setup random generator")
0070 rndm = DDG4.Action(kernel, 'Geant4Random/Random')
0071 rndm.Seed = 987654321
0072 rndm.initialize()
0073
0074
0075 seq, act = geant4.setupDetectors()
0076
0077
0078 geant4.setupROOTOutput('RootOutput', 'CheckShape_' + time.strftime('%Y-%m-%d_%H-%M'), mc_truth=True)
0079
0080
0081 geant4.setupGun(name="Gun",
0082 particle='e-',
0083 energy=100 * GeV,
0084 isotrop=True,
0085 multiplicity=1,
0086 position=(0 * m, 0 * m, 0 * m),
0087 PhiMin=0.0 * rad,
0088 PhiMax=math.pi * 2.0 * rad,
0089 ThetaMin=0.0 * rad,
0090 ThetaMax=math.pi * rad)
0091
0092 prt = DDG4.EventAction(kernel, str('Geant4ParticlePrint/ParticlePrint'))
0093 prt.OutputLevel = Output.INFO
0094 prt.OutputType = 3
0095 kernel.eventAction().adopt(prt)
0096 part = DDG4.GeneratorAction(kernel, str('Geant4ParticleHandler/ParticleHandler'))
0097 kernel.generatorAction().adopt(part)
0098 part.MinimalKineticEnergy = 100 * MeV
0099 part.SaveProcesses = ['Decay']
0100 part.OutputLevel = 5
0101 part.enableUI()
0102 user = DDG4.Action(kernel, str('Geant4TCUserParticleHandler/UserParticleHandler'))
0103 user.TrackingVolume_Rmax = 3.0 * m
0104 user.TrackingVolume_Zmax = 2.0 * m
0105 user.enableUI()
0106 part.adopt(user)
0107
0108
0109 prt = DDG4.EventAction(kernel, str('Geant4ParticlePrint/ParticlePrint'))
0110 prt.OutputLevel = Output.INFO
0111 prt.OutputType = 3
0112 kernel.eventAction().adopt(prt)
0113
0114
0115 phys = geant4.setupPhysics(str('QGSP_BERT'))
0116 ph = geant4.addPhysics(str('Geant4PhysicsList/Myphysics'))
0117 ph.addPhysicsConstructor(str('G4StepLimiterPhysics'))
0118 ph.addParticleConstructor(str('G4Geantino'))
0119 ph.addParticleConstructor(str('G4BosonConstructor'))
0120
0121
0122 part = geant4.addPhysics('Geant4ExtraParticles/ExtraParticles')
0123 part.pdgfile = os.path.join(install_dir, 'examples/DDG4/examples/particle.tbl')
0124
0125
0126 rg = geant4.addPhysics('Geant4DefaultRangeCut/GlobalRangeCut')
0127 rg.RangeCut = 0.7 * mm
0128
0129 phys.dump()
0130
0131 cmds = []
0132 if vis:
0133 cmds.append('/control/verbose 2')
0134 cmds.append('/run/initialize')
0135 cmds.append('/vis/open OGL')
0136 cmds.append('/vis/verbose errors')
0137 cmds.append('/vis/drawVolume')
0138 cmds.append('/vis/viewer/set/viewpointThetaPhi 55. 11.')
0139 cmds.append('/vis/scene/add/axes 0 0 0 1 m')
0140
0141
0142
0143
0144 ui.Commands = cmds
0145 kernel.NumEvents = 0
0146 kernel.configure()
0147 kernel.initialize()
0148 kernel.run()
0149 kernel.terminate()
0150
0151
0152 if __name__ == "__main__":
0153 run()