3 from __future__
import absolute_import, unicode_literals
8 from DDG4
import OutputLevel
as Output
9 from g4units
import keV, GeV, mm, ns, MeV
12 logging.basicConfig(format=
'%(levelname)s: %(message)s', level=logging.INFO)
13 logger = logging.getLogger(__name__)
17 dd4hep simulation example setup using the python configuration
28 logger.info(
'PYTHON: +++ Creating Geant4 worker thread ....')
32 run1.Property_int = 12345
33 run1.Property_double = -5e15 * keV
34 run1.Property_string =
'Startrun: Hello_2'
35 logger.info(
"%s %f %d", run1.Property_string, run1.Property_double, run1.Property_int)
37 kernel.registerGlobalAction(run1)
38 kernel.runAction().adopt(run1)
42 prt.OutputLevel = Output.DEBUG
44 kernel.eventAction().adopt(prt)
48 prt.OutputLevel = Output.INFO
49 kernel.eventAction().adopt(prt)
52 evt_lcio = geant4.setupLCIOOutput(
'LcioOutput',
'CLICSiD_' + time.strftime(
'%Y-%m-%d_%H-%M'))
53 evt_lcio.OutputLevel = Output.DEBUG
59 kernel.generatorAction().adopt(gen)
63 Generation of isotrope tracks of a given multiplicity with overlay:
68 gen.Energy = 100 * GeV
71 gen.OutputLevel = Output.DEBUG
77 kernel.generatorAction().adopt(gen)
81 gen.Offset = (20 * mm, 10 * mm, 10 * mm, 0 * ns)
82 gen.Sigma = (4 * mm, 1 * mm, 1 * mm, 0 * ns)
83 kernel.generatorAction().adopt(gen)
85 # Second particle generator: e-
86 gen = DDG4.GeneratorAction(kernel,"Geant4IsotropeGenerator/IsotropE-");
91 gen.OutputLevel = Output.DEBUG
92 kernel.generatorAction().adopt(gen)
93 # Install vertex smearing for this interaction
94 gen = DDG4.GeneratorAction(kernel,"Geant4InteractionVertexSmear/SmearE-");
96 gen.Offset = (-20*mm, -10*mm, -10*mm, 0*ns)
97 gen.Sigma = (12*mm, 8*mm, 8*mm, 0*ns)
98 kernel.generatorAction().adopt(gen)
99 #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
105 kernel.generatorAction().adopt(gen)
109 gen.OutputLevel = Output.DEBUG
111 kernel.generatorAction().adopt(gen)
115 kernel.generatorAction().adopt(part)
117 part.SaveProcesses = [
'Decay']
118 part.MinimalKineticEnergy = 100 * MeV
119 part.OutputLevel = Output.DEBUG
121 user =
DDG4.Action(kernel,
"Geant4TCUserParticleHandler/UserParticleHandler")
122 user.TrackingVolume_Zmax = DDG4.EcalEndcap_zmin
123 user.TrackingVolume_Rmax = DDG4.EcalBarrel_rmin
126 logger.info(
'PYTHON: +++ Geant4 worker thread configured successfully....')
131 logger.info(
'PYTHON: +++ Setting up master thread.....')
138 seq, act = geant4.setupTracker(
'SiVertexBarrel')
139 act.OutputLevel = Output.ERROR
140 act.CollectSingleDeposits =
False
141 seq, act = geant4.setupTracker(
'SiVertexEndcap')
142 act.OutputLevel = Output.ERROR
143 act.CollectSingleDeposits =
False
144 logger.info(
'PYTHON: +++ Setting up Geant4 sensitive detectors for worker thread.....')
149 logger.info(
'PYTHON: +++ Setting up DUMMY Geant4 sensitive detectors for worker thread.....')
154 logger.info(
'PYTHON: +++ Setting up DUMMY Geant4 geometry for worker thread.....')
161 description = kernel.detectorDescription()
162 install_dir = os.environ[
'DD4hepINSTALL']
163 kernel.loadGeometry(str(
"file:" + install_dir +
"/DDDetectors/compact/SiD_Markus.xml"))
165 DDG4.Core.setPrintLevel(Output.DEBUG)
166 DDG4.Core.setPrintFormat(str(
"%-32s %6s %s"))
168 kernel.NumberOfThreads = 1
169 geant4 =
DDG4.Geant4(kernel, tracker=
'Geant4TrackerWeightedAction')
170 geant4.printDetectors()
175 geant4.addUserInitialization(worker=setupWorker, master=setupMaster)
178 seq, act = geant4.addDetectorConstruction(
"Geant4DetectorGeometryConstruction/ConstructGeo")
181 self.setupTrackingFieldMT()
183 seq, act = geant4.addDetectorConstruction(
"Geant4PythonDetectorConstruction/DummyDet",
187 seq, act = geant4.addDetectorConstruction(
"Geant4PythonDetectorConstruction/SetupSD",
188 sensitives=setupSensitives)
191 seq, act = geant4.addDetectorConstruction(
"Geant4DetectorSensitivesConstruction/ConstructSD",
196 rndm.Seed = 987654321
200 f1 =
DDG4.Filter(kernel,
'GeantinoRejectFilter/GeantinoRejector')
201 kernel.registerGlobalFilter(f1)
218 seq = geant4.setupPhysics(
'QGSP_BERT')
220 part =
DDG4.Action(geant4.master(),
'Geant4ExtraParticles/extraparts')
221 part.pdgfile =
'checkout/DDG4/examples/particle.tbl'
222 phys.adoptPhysicsConstructor(part.get())
236 if __name__ ==
"__main__":
238 logger.info(
'Arguments: %s', str(sys.argv))