File indexing completed on 2025-01-18 09:14:13
0001 """
0002
0003 dd4hep simulation example setup using the python configuration
0004
0005 @author M.Frank
0006 @version 1.0
0007
0008 """
0009 from __future__ import absolute_import, unicode_literals
0010 import os
0011 import time
0012 import DDG4
0013 from g4units import keV, GeV, MeV
0014 import logging
0015
0016 logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.INFO)
0017 logger = logging.getLogger(__name__)
0018
0019
0020 def run():
0021 kernel = DDG4.Kernel()
0022 install_dir = os.environ['DD4hepINSTALL']
0023 kernel.loadGeometry(str("file:" + install_dir + "/examples/CLICSiD/compact/compact.xml"))
0024
0025 simple = DDG4.Simple(kernel, tracker='LcioTestTrackerAction')
0026 simple.printDetectors()
0027
0028 simple.setupCshUI()
0029
0030
0031 run1 = DDG4.RunAction(kernel, 'Geant4TestRunAction/RunInit')
0032 run1.Property_int = 12345
0033 run1.Property_double = -5e15 * keV
0034 run1.Property_string = 'Startrun: Hello_2'
0035 logger.info("%s %s %s", run1.Property_string, run1.Property_double, run1.Property_int)
0036 run1.enableUI()
0037 kernel.registerGlobalAction(run1)
0038 kernel.runAction().add(run1)
0039
0040
0041 evt2 = DDG4.EventAction(kernel, 'Geant4TestEventAction/UserEvent_2')
0042 evt2.Property_int = 123454321
0043 evt2.Property_double = 5e15 * GeV
0044 evt2.Property_string = 'Hello_2 from the python setup'
0045 evt2.enableUI()
0046 kernel.registerGlobalAction(evt2)
0047
0048 evt1 = DDG4.EventAction(kernel, 'Geant4TestEventAction/UserEvent_1')
0049 evt1.Property_int = 0o1234
0050 evt1.Property_double = 1e11
0051 evt1.Property_string = 'Hello_1'
0052 evt1.enableUI()
0053
0054 kernel.eventAction().add(evt1)
0055 kernel.eventAction().add(evt2)
0056 """
0057 trk = DDG4.Action(kernel,"Geant4TrackPersistency/MonteCarloTruthHandler")
0058 kernel.registerGlobalAction(trk)
0059 trk.release()
0060 mc = DDG4.Action(kernel,"Geant4MonteCarloRecordManager/MonteCarloRecordManager")
0061 kernel.registerGlobalAction(mc)
0062 mc.release()
0063 """
0064
0065 simple.setupLCIOOutput('LcioOutput', 'CLICSiD_' + time.strftime('%Y-%m-%d_%H-%M'))
0066
0067 gen = DDG4.GeneratorAction(kernel, "Geant4TestGeneratorAction/Generate")
0068 kernel.generatorAction().add(gen)
0069
0070
0071 simple.setupGun('Gun', 'pi-', 100 * GeV, True)
0072
0073 """
0074 rdr = DDG4.GeneratorAction(kernel,"LcioGeneratorAction/Reader")
0075 rdr.zSpread = 0.0
0076 rdr.lorentzAngle = 0.0
0077 rdr.OutputLevel = DDG4.OutputLevel.INFO
0078 rdr.Input = "LcioEventReader|test.data"
0079 rdr.enableUI()
0080 kernel.generatorAction().add(rdr)
0081 """
0082
0083
0084 f1 = DDG4.Filter(kernel, 'GeantinoRejectFilter/GeantinoRejector')
0085 kernel.registerGlobalFilter(f1)
0086
0087 f2 = DDG4.Filter(kernel, 'ParticleRejectFilter/OpticalPhotonRejector')
0088 f2.particle = 'opticalphoton'
0089 kernel.registerGlobalFilter(f2)
0090
0091 f3 = DDG4.Filter(kernel, 'ParticleSelectFilter/OpticalPhotonSelector')
0092 f3.particle = 'opticalphoton'
0093 kernel.registerGlobalFilter(f3)
0094
0095 f4 = DDG4.Filter(kernel, 'EnergyDepositMinimumCut')
0096 f4.Cut = 10 * MeV
0097 f4.enableUI()
0098 kernel.registerGlobalFilter(f4)
0099
0100
0101 seq, act = simple.setupTracker('SiVertexBarrel')
0102 seq.add(f1)
0103
0104 act.add(f1)
0105
0106 seq, act = simple.setupTracker('SiVertexEndcap')
0107 seq.add(f1)
0108
0109
0110 seq, act = simple.setupTracker('SiTrackerBarrel')
0111 seq, act = simple.setupTracker('SiTrackerEndcap')
0112 seq, act = simple.setupTracker('SiTrackerForward')
0113
0114 seq, act = simple.setupCalorimeter('EcalBarrel')
0115 seq, act = simple.setupCalorimeter('EcalEndcap')
0116 seq, act = simple.setupCalorimeter('HcalBarrel')
0117 seq, act = simple.setupCalorimeter('HcalEndcap')
0118 seq, act = simple.setupCalorimeter('HcalPlug')
0119 seq, act = simple.setupCalorimeter('MuonBarrel')
0120 seq, act = simple.setupCalorimeter('MuonEndcap')
0121 seq, act = simple.setupCalorimeter('LumiCal')
0122 seq, act = simple.setupCalorimeter('BeamCal')
0123
0124
0125 phys = simple.setupPhysics('QGSP_BERT')
0126 ph = DDG4.PhysicsList(kernel, 'Geant4PhysicsList/Myphysics')
0127 ph.addParticleConstructor(str('G4BosonConstructor'))
0128 ph.addParticleConstructor(str('G4LeptonConstructor'))
0129 ph.addParticleProcess(str('e[+-]'), str('G4eMultipleScattering'), -1, 1, 1)
0130 ph.addPhysicsConstructor(str('G4StepLimiterPhysics'))
0131 ph.addPhysicsConstructor(str('G4OpticalPhysics'))
0132 ph.enableUI()
0133 phys.add(ph)
0134
0135 phys.dump()
0136
0137 kernel.configure()
0138 kernel.initialize()
0139
0140
0141 kernel.run()
0142 kernel.terminate()
0143
0144
0145 if __name__ == "__main__":
0146 run()