Newer
Older
Markus Frank
committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# ==========================================================================
# AIDA Detector description implementation
# --------------------------------------------------------------------------
# Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
# All rights reserved.
#
# For the licensing terms see $DD4hepINSTALL/LICENSE.
# For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
#
# ==========================================================================
#
from __future__ import absolute_import, unicode_literals
import logging
#
logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.INFO)
logger = logging.getLogger(__name__)
#
#
"""
dd4hep simulation example setup using the python configuration
"""
def run():
import os
import DDG4
from DDG4 import OutputLevel as Output
from g4units import GeV, keV
kernel = DDG4.Kernel()
install_dir = os.environ['DD4hepExamplesINSTALL']
kernel.loadGeometry(str("file:" + install_dir + "/examples/ClientTests/compact/SiliconBlock.xml"))
DDG4.importConstants(kernel.detectorDescription(), debug=False)
geant4 = DDG4.Geant4(kernel, tracker='Geant4TrackerCombineAction')
geant4.registerInterruptHandler()
geant4.printDetectors()
# Configure UI
geant4.setupUI(typ="tcsh", vis=False, macro=None, ui=False)
# Configure field
geant4.setupTrackingField(prt=True)
# Configure Event actions
prt = DDG4.EventAction(kernel, 'Geant4ParticlePrint/ParticlePrint')
prt.OutputLevel = Output.DEBUG
prt.OutputType = 3 # Print both: table and tree
kernel.eventAction().adopt(prt)
generator_output_level = Output.INFO
# Configure G4 geometry setup
seq, act = geant4.addDetectorConstruction("Geant4DetectorGeometryConstruction/ConstructGeo")
act.DebugMaterials = True
act.DebugElements = False
act.DebugVolumes = True
act.DebugShapes = True
act.DebugSurfaces = True
# Setup particle gun
gun = geant4.setupGun("Gun", particle='gamma', energy=1 * GeV, multiplicity=1)
gun.direction = (0.0, 0.0, 1.0)
gun.OutputLevel = generator_output_level
kernel.NumEvents = 10
act = DDG4.EventAction(kernel, 'TestSignalAction/SigAction', True)
act.signal_event = 3
kernel.eventAction().add(act)
Markus Frank
committed
Markus Frank
committed
# And handle the simulation particles.
part = DDG4.GeneratorAction(kernel, "Geant4ParticleHandler/ParticleHandler")
kernel.generatorAction().adopt(part)
part.SaveProcesses = ['conv', 'Decay']
part.MinimalKineticEnergy = 1 * keV
part.KeepAllParticles = False
part.PrintEndTracking = True
part.enableUI()
# Now build the physics list:
phys = geant4.setupPhysics('QGSP_BERT')
phys.dump()
# Start the engine...
geant4.execute()
if __name__ == "__main__":
run()