File indexing completed on 2025-01-18 09:14:55
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 from __future__ import absolute_import, unicode_literals
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 @author M.Frank
0024 @version 1.0
0025
0026 """
0027
0028
0029 def run():
0030 import os
0031 import DDG4
0032 from DDG4 import OutputLevel as Output
0033 from g4units import keV
0034
0035 args = DDG4.CommandLine()
0036 install_dir = os.environ['DD4hepExamplesINSTALL']
0037 if args.help:
0038 import sys
0039 logger.info("""
0040 python <dir>/Channeling.py -option [-option]
0041 -geometry <geometry file name> File is expected in the examples
0042 install area:
0043 """ + install_dir + """
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 kernel = DDG4.Kernel()
0053 kernel.loadGeometry(str("file:" + install_dir + "/examples/DDG4/compact/Channeling.xml"))
0054
0055 DDG4.importConstants(kernel.detectorDescription(), debug=False)
0056 geant4 = DDG4.Geant4(kernel, tracker='Geant4TrackerCombineAction')
0057 geant4.printDetectors()
0058
0059 if args.macro:
0060 ui = geant4.setupCshUI(macro=args.macro, vis=args.vis)
0061 else:
0062 ui = geant4.setupCshUI(vis=args.vis)
0063
0064 if args.batch:
0065 ui.Commands = ['/run/beamOn ' + str(args.events), '/ddg4/UI/terminate']
0066
0067
0068 geant4.setupTrackingField(prt=True)
0069
0070 prt = DDG4.EventAction(kernel, 'Geant4ParticlePrint/ParticlePrint')
0071 prt.OutputLevel = Output.DEBUG
0072 prt.OutputType = 3
0073 kernel.eventAction().adopt(prt)
0074
0075 generator_output_level = Output.INFO
0076
0077
0078 seq, act = geant4.addDetectorConstruction("Geant4DetectorGeometryConstruction/ConstructGeo")
0079 act.DebugMaterials = True
0080 act.DebugElements = False
0081 act.DebugVolumes = True
0082 act.DebugShapes = True
0083 act.DebugSurfaces = True
0084
0085
0086 gun = geant4.setupGun("Gun", particle='gamma', energy=5 * keV, multiplicity=1)
0087 gun.OutputLevel = generator_output_level
0088
0089 geant4.setupTracker('ChannelingDevice')
0090
0091
0092 phys = geant4.setupPhysics('QGSP_BERT')
0093 ph = DDG4.PhysicsList(kernel, 'Channeling')
0094 ph.addPhysicsConstructor(str('Geant4ChannelingPhysics'))
0095 ph.enableUI()
0096 phys.adopt(ph)
0097 phys.dump()
0098
0099 phys.dump()
0100
0101 geant4.execute()
0102
0103
0104 if __name__ == "__main__":
0105 run()