File indexing completed on 2025-01-30 09:17:51
0001 from __future__ import absolute_import, unicode_literals
0002 import os
0003 import sys
0004 import time
0005 import DDG4
0006 from DDG4 import OutputLevel as Output
0007 from g4units import GeV, MeV
0008 import logging
0009
0010 logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.INFO)
0011 logger = logging.getLogger(__name__)
0012
0013
0014
0015 """
0016
0017 dd4hep example setup using the python configuration
0018
0019 \author M.Frank
0020 \version 1.0
0021
0022 """
0023
0024
0025 def run():
0026 kernel = DDG4.Kernel()
0027 install_dir = os.environ['DD4hepExamplesINSTALL']
0028 kernel.setOutputLevel(str('Geant4Converter'), Output.DEBUG)
0029 kernel.setOutputLevel(str('Gun'), Output.INFO)
0030 kernel.detectorDescription().fromXML(str("file:" + install_dir + "/examples/DDCMS/data/dd4hep-config.xml"))
0031 kernel.NumEvents = 5
0032 geant4 = DDG4.Geant4(kernel, tracker='Geant4TrackerCombineAction')
0033 geant4.printDetectors()
0034 geant4.setupCshUI()
0035 batch = False
0036 test = False
0037 for i in range(len(sys.argv)):
0038 arg = sys.argv[i].lower()
0039 if arg == 'batch':
0040 batch = True
0041 elif arg == 'test':
0042 test = True
0043 elif arg == 'numevents':
0044 kernel.NumEvents = int(sys.argv[i + 1])
0045 if batch or test:
0046 kernel.UI = ''
0047
0048
0049 geant4.setupTrackingField(prt=True)
0050
0051 geant4.setupROOTOutput('RootOutput', 'CMSTracker_' + time.strftime('%Y-%m-%d_%H-%M'), mc_truth=True)
0052
0053 generators = []
0054 generators.append(geant4.setupGun("GunPi-", particle='pi-', energy=300 * GeV,
0055 multiplicity=1, Standalone=False, register=False, Mask=1))
0056 if not test:
0057 generators.append(geant4.setupGun("GunPi+", particle='pi+', energy=300 * GeV,
0058 multiplicity=1, Standalone=False, register=False, Mask=2))
0059 generators.append(geant4.setupGun("GunE-", particle='e-', energy=100 * GeV,
0060 multiplicity=1, Standalone=False, register=False, Mask=4))
0061 generators.append(geant4.setupGun("GunE+", particle='e+', energy=100 * GeV,
0062 multiplicity=1, Standalone=False, register=False, Mask=8))
0063 geant4.buildInputStage(generators)
0064
0065 for i in geant4.description.detectors():
0066 o = DDG4.DetElement(i.second.ptr())
0067 sd = geant4.description.sensitiveDetector(o.name())
0068 if sd.isValid():
0069 typ = geant4.sensitive_types[sd.type()]
0070 logger.info('CMSTracker: Configure subdetector %-24s of type %s' % (o.name(), typ,))
0071 geant4.setupDetector(o.name(), typ)
0072
0073
0074 part = DDG4.GeneratorAction(kernel, "Geant4ParticleHandler/ParticleHandler")
0075 kernel.generatorAction().adopt(part)
0076 part.SaveProcesses = ['conv', 'Decay']
0077 part.MinimalKineticEnergy = 1 * MeV
0078 part.OutputLevel = 5
0079 part.enableUI()
0080
0081
0082 phys = kernel.physicsList()
0083 phys.extends = 'QGSP_BERT'
0084 phys.enableUI()
0085
0086 geant4.execute()
0087
0088
0089 if __name__ == "__main__":
0090 run()