File indexing completed on 2025-01-30 09:17:19
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 from __future__ import absolute_import, unicode_literals
0014 import os
0015 import time
0016 import logging
0017 import DDG4
0018 from DDG4 import OutputLevel as Output
0019 from g4units import keV, GeV, mm, ns, MeV
0020
0021 global geant4
0022 logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.INFO)
0023 logger = logging.getLogger(__name__)
0024
0025 """
0026
0027 dd4hep simulation example setup using the python configuration
0028
0029 @author M.Frank
0030 @version 1.0
0031
0032 """
0033
0034
0035 def setupWorker():
0036 k = DDG4.Kernel()
0037 kernel = k.worker()
0038 logger.info('PYTHON: +++ Creating Geant4 worker thread ....')
0039
0040
0041 run1 = DDG4.RunAction(kernel, 'Geant4TestRunAction/RunInit')
0042 run1.Property_int = 12345
0043 run1.Property_double = -5e15 * keV
0044 run1.Property_string = 'Startrun: Hello_2'
0045 logger.info("%s %f %d", run1.Property_string, run1.Property_double, run1.Property_int)
0046 run1.enableUI()
0047 kernel.registerGlobalAction(run1)
0048 kernel.runAction().adopt(run1)
0049
0050
0051 prt = DDG4.EventAction(kernel, 'Geant4ParticlePrint/ParticlePrint')
0052 prt.OutputLevel = Output.DEBUG
0053 prt.OutputType = 3
0054 kernel.eventAction().adopt(prt)
0055
0056
0057 prt = DDG4.EventAction(kernel, 'Geant4SurfaceTest/SurfaceTest')
0058 prt.OutputLevel = Output.INFO
0059 kernel.eventAction().adopt(prt)
0060
0061
0062 evt_lcio = geant4.setupLCIOOutput('LcioOutput', 'CLICSiD_' + time.strftime('%Y-%m-%d_%H-%M'))
0063 evt_lcio.OutputLevel = Output.DEBUG
0064
0065
0066
0067
0068 gen = DDG4.GeneratorAction(kernel, "Geant4GeneratorActionInit/GenerationInit")
0069 kernel.generatorAction().adopt(gen)
0070
0071
0072 """
0073 Generation of isotrope tracks of a given multiplicity with overlay:
0074 """
0075
0076 gen = DDG4.GeneratorAction(kernel, "Geant4IsotropeGenerator/IsotropPi+")
0077 gen.Particle = 'pi+'
0078 gen.Energy = 100 * GeV
0079 gen.Multiplicity = 2
0080 gen.Mask = 1
0081 gen.OutputLevel = Output.DEBUG
0082 gen.PhiMin = 0
0083 gen.PhiMax = 0
0084 gen.ThetaMin = 1.61
0085 gen.ThetaMax = 1.61
0086
0087 kernel.generatorAction().adopt(gen)
0088
0089 gen = DDG4.GeneratorAction(kernel, "Geant4InteractionVertexSmear/SmearPi+")
0090 gen.Mask = 1
0091 gen.Offset = (20 * mm, 10 * mm, 10 * mm, 0 * ns)
0092 gen.Sigma = (4 * mm, 1 * mm, 1 * mm, 0 * ns)
0093 kernel.generatorAction().adopt(gen)
0094 """
0095 # Second particle generator: e-
0096 gen = DDG4.GeneratorAction(kernel,"Geant4IsotropeGenerator/IsotropE-");
0097 gen.Particle = 'e-'
0098 gen.Energy = 25 * GeV
0099 gen.Multiplicity = 3
0100 gen.Mask = 2
0101 gen.OutputLevel = Output.DEBUG
0102 kernel.generatorAction().adopt(gen)
0103 # Install vertex smearing for this interaction
0104 gen = DDG4.GeneratorAction(kernel,"Geant4InteractionVertexSmear/SmearE-");
0105 gen.Mask = 2
0106 gen.Offset = (-20*mm, -10*mm, -10*mm, 0*ns)
0107 gen.Sigma = (12*mm, 8*mm, 8*mm, 0*ns)
0108 kernel.generatorAction().adopt(gen)
0109 #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
0110 """
0111
0112 gen = DDG4.GeneratorAction(kernel, "Geant4InteractionMerger/InteractionMerger")
0113 gen.OutputLevel = 4
0114 gen.enableUI()
0115 kernel.generatorAction().adopt(gen)
0116
0117
0118 gen = DDG4.GeneratorAction(kernel, "Geant4PrimaryHandler/PrimaryHandler")
0119 gen.OutputLevel = Output.DEBUG
0120 gen.enableUI()
0121 kernel.generatorAction().adopt(gen)
0122
0123
0124 part = DDG4.GeneratorAction(kernel, "Geant4ParticleHandler/ParticleHandler")
0125 kernel.generatorAction().adopt(part)
0126
0127 part.SaveProcesses = ['Decay']
0128 part.MinimalKineticEnergy = 100 * MeV
0129 part.OutputLevel = Output.DEBUG
0130 part.enableUI()
0131 user = DDG4.Action(kernel, "Geant4TCUserParticleHandler/UserParticleHandler")
0132 user.TrackingVolume_Zmax = DDG4.EcalEndcap_zmin
0133 user.TrackingVolume_Rmax = DDG4.EcalBarrel_rmin
0134 user.enableUI()
0135 part.adopt(user)
0136 logger.info('PYTHON: +++ Geant4 worker thread configured successfully....')
0137 return 1
0138
0139
0140 def setupMaster():
0141 logger.info('PYTHON: +++ Setting up master thread.....')
0142 return 1
0143
0144
0145 def setupSensitives():
0146 global geant4
0147
0148 seq, act = geant4.setupTracker('SiVertexBarrel')
0149 act.OutputLevel = Output.ERROR
0150 act.CollectSingleDeposits = False
0151 seq, act = geant4.setupTracker('SiVertexEndcap')
0152 act.OutputLevel = Output.ERROR
0153 act.CollectSingleDeposits = False
0154 logger.info('PYTHON: +++ Setting up Geant4 sensitive detectors for worker thread.....')
0155 return 1
0156
0157
0158 def dummy_sd():
0159 logger.info('PYTHON: +++ Setting up DUMMY Geant4 sensitive detectors for worker thread.....')
0160 return 1
0161
0162
0163 def dummy_geom():
0164 logger.info('PYTHON: +++ Setting up DUMMY Geant4 geometry for worker thread.....')
0165 return 1
0166
0167
0168 def run():
0169 global geant4
0170 kernel = DDG4.Kernel()
0171 description = kernel.detectorDescription()
0172 install_dir = os.environ['DD4hepINSTALL']
0173 kernel.loadGeometry(str("file:" + install_dir + "/DDDetectors/compact/SiD_Markus.xml"))
0174 DDG4.importConstants(description)
0175 DDG4.Core.setPrintLevel(Output.DEBUG)
0176 DDG4.Core.setPrintFormat(str("%-32s %6s %s"))
0177
0178 kernel.NumberOfThreads = 1
0179 geant4 = DDG4.Geant4(kernel, tracker='Geant4TrackerWeightedAction')
0180 geant4.printDetectors()
0181
0182 geant4.setupCshUI()
0183
0184
0185 geant4.addUserInitialization(worker=setupWorker, master=setupMaster)
0186
0187
0188 seq, act = geant4.addDetectorConstruction("Geant4DetectorGeometryConstruction/ConstructGeo")
0189
0190
0191 self.setupTrackingFieldMT()
0192
0193 seq, act = geant4.addDetectorConstruction("Geant4PythonDetectorConstruction/DummyDet",
0194 geometry=dummy_geom,
0195 sensitives=dummy_sd)
0196
0197 seq, act = geant4.addDetectorConstruction("Geant4PythonDetectorConstruction/SetupSD",
0198 sensitives=setupSensitives)
0199
0200
0201 seq, act = geant4.addDetectorConstruction("Geant4DetectorSensitivesConstruction/ConstructSD",
0202 allow_threads=True)
0203
0204
0205 rndm = DDG4.Action(kernel, 'Geant4Random/Random')
0206 rndm.Seed = 987654321
0207 rndm.initialize()
0208
0209
0210 f1 = DDG4.Filter(kernel, 'GeantinoRejectFilter/GeantinoRejector')
0211 kernel.registerGlobalFilter(f1)
0212
0213
0214
0215
0216
0217
0218
0219
0220
0221
0222
0223
0224
0225
0226
0227
0228 seq = geant4.setupPhysics('QGSP_BERT')
0229 phys = DDG4.PhysicsList(geant4.master(), 'Geant4PhysicsList/MyPhysics')
0230 part = DDG4.Action(geant4.master(), 'Geant4ExtraParticles/extraparts')
0231 part.pdgfile = 'checkout/DDG4/examples/particle.tbl'
0232 phys.adoptPhysicsConstructor(part.get())
0233 seq.add(phys)
0234
0235 geant4.run()
0236
0237
0238
0239
0240
0241
0242
0243 return 1
0244
0245
0246 if __name__ == "__main__":
0247 import sys
0248 logger.info('Arguments: %s', str(sys.argv))
0249 run()