Newer
Older
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/bin/python
#==========================================================================
# AIDA Detector description implementation for LCD
#--------------------------------------------------------------------------
# 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.
#
#==========================================================================
import os, sys, errno, optparse
def printOpts(opts):
o = eval(str(opts))
prefix = sys.argv[0].split(os.sep)[-1]
for name,value in o.items():
print '%s > %-18s %s [%s]'%(prefix,name+':',str(value),str(value.__class__),)
def materialScan(opts):
kernel = DDG4.Kernel()
install_dir = os.environ['DD4hepINSTALL']
kernel.loadGeometry(opts.compact)
DDG4.Core.setPrintFormat("%-32s %6s %s")
geant4 = DDG4.Geant4(kernel)
# Configure UI
geant4.setupCshUI(ui=None)
for i in geant4.lcdd.detectors():
o = DDG4.DetElement(i.second.ptr())
sd = geant4.lcdd.sensitiveDetector(o.name())
if sd.isValid():
typ = sd.type()
if geant4.sensitive_types.has_key(typ):
geant4.setupDetector(o.name(),geant4.sensitive_types[typ])
sdtyp = geant4.sensitive_types[typ]
else:
print '+++ %-32s type:%-12s --> Unknown Sensitive type: %s'%(o.name(), typ, sdtyp,)
sys.exit(errno.EINVAL)
gun = geant4.setupGun("Gun",
Standalone=True,
particle='geantino',
energy=20*SystemOfUnits.GeV,
position=opts.position,
direction=opts.direction,
multiplicity=1,
isotrop=False )
scan = DDG4.SteppingAction(kernel,'Geant4MaterialScanner/MaterialScan')
kernel.steppingAction().adopt(scan)
# Now build the physics list:
phys = geant4.setupPhysics('QGSP_BERT')
"""
phys = geant4.setupPhysics('')
ph = DDG4.PhysicsList(kernel,'Geant4PhysicsList/Myphysics')
ph.addParticleConstructor('G4Geantino')
ph.addParticleConstructor('G4BosonConstructor')
ph.addParticleConstructor('G4LeptonConstructor')
phys.transportation = True
phys.decays = True
phys.adopt(ph)
"""
kernel.configure()
kernel.initialize()
kernel.NumEvents = 1
kernel.run()
kernel.terminate()
return 0
parser = optparse.OptionParser()
parser.formatter.width = 132
parser.description = 'Material scan using Geant4.'
parser.add_option('-c', '--compact', dest='compact', default=None,
help='Define LCCDD style compact xml input',
metavar='<FILE>')
parser.add_option('-P', '--print',
dest='print_level', default=2,
help='Set DD4hep print level.',
metavar='<int>')
parser.add_option('-p', '--position',
dest='position', default='0.0,0.0,0.0',
help='Start position of the material scan. [give tuple "x,y,z" as string]',
metavar='<tuple>')
parser.add_option('-d', '--direction',
dest='direction', default='0.0,1.0,0.0',
help='Direction of the material scan. [give tuple "x,y,z" as string]',
metavar='<tuple>')
(opts, args) = parser.parse_args()
if opts.compact is None:
print " ",parser.format_help()
sys.exit(1)
opts.position=eval('('+opts.position+')')
opts.direction=eval('('+opts.direction+')')
printOpts(opts)
try:
import ROOT
from ROOT import gROOT
gROOT.SetBatch(1)
except ImportError,X:
print 'PyROOT interface not accessible:',X
print parser.format_help()
sys.exit(errno.ENOENT)
try:
import DDG4, SystemOfUnits
except ImportError,X:
print 'DDG4 python interface not accessible:',X
print parser.format_help()
sys.exit(errno.ENOENT)
#
ret = materialScan(opts)
sys.exit(ret);