File indexing completed on 2026-09-14 08:23:24
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 import logging
0013
0014 logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.INFO)
0015 logger = logging.getLogger(__name__)
0016
0017
0018 """
0019
0020 dd4hep simulation example setup using the python configuration
0021
0022 @author M.Frank
0023 @version 1.0
0024
0025 """
0026
0027
0028 def run():
0029 import os
0030 import DDG4
0031 from DDG4 import OutputLevel as Output
0032 from g4units import keV
0033
0034 args = DDG4.CommandLine()
0035 install_dir = os.environ['DD4hepExamplesINSTALL']
0036 if args.help:
0037 import sys
0038 logger.info("""
0039 python <dir>/Channeling.py -option [-option]
0040 -geometry <geometry file name> File is expected in the examples
0041 install area:
0042 """ + install_dir + """
0043 -vis Enable visualization
0044 -macro Pass G4 macro file to UI executive
0045 -batch Run in batch mode for unit testing
0046 -events <number> Run geant4 for specified number of events
0047 (batch mode only)
0048 """)
0049 sys.exit(0)
0050
0051 kernel = DDG4.Kernel()
0052 kernel.loadGeometry(str("file:" + install_dir + "/examples/DDG4/compact/Channeling.xml"))
0053
0054 DDG4.importConstants(kernel.detectorDescription(), debug=False)
0055 geant4 = DDG4.Geant4(kernel, tracker='Geant4TrackerCombineAction')
0056 geant4.printDetectors()
0057
0058 if args.macro:
0059 ui = geant4.setupCshUI(macro=args.macro, vis=args.vis)
0060 else:
0061 ui = geant4.setupCshUI(vis=args.vis)
0062
0063 if args.batch:
0064 ui.Commands = ['/run/beamOn ' + str(args.events), '/ddg4/UI/terminate']
0065
0066
0067 geant4.setupTrackingField(prt=True)
0068
0069 prt = DDG4.EventAction(kernel, 'Geant4ParticlePrint/ParticlePrint')
0070 prt.OutputLevel = Output.DEBUG
0071 prt.OutputType = 3
0072 kernel.eventAction().adopt(prt)
0073
0074 generator_output_level = Output.INFO
0075
0076
0077 seq, act = geant4.addDetectorConstruction("Geant4DetectorGeometryConstruction/ConstructGeo")
0078 act.DebugMaterials = True
0079 act.DebugElements = False
0080 act.DebugVolumes = True
0081 act.DebugShapes = True
0082 act.DebugSurfaces = True
0083
0084
0085 gun = geant4.setupGun("Gun", particle='gamma', energy=5 * keV, multiplicity=1)
0086 gun.OutputLevel = generator_output_level
0087
0088 geant4.setupTracker('ChannelingDevice')
0089
0090
0091 phys = geant4.setupPhysics('QGSP_BERT')
0092 ph = DDG4.PhysicsList(kernel, 'Channeling')
0093 ph.addPhysicsConstructor(str('Geant4ChannelingPhysics'))
0094 ph.enableUI()
0095 phys.adopt(ph)
0096 phys.dump()
0097
0098 phys.dump()
0099
0100 geant4.execute()
0101
0102
0103 if __name__ == "__main__":
0104 run()