Newer
Older
from SystemOfUnits import *
#
#
"""
DD4hep example setup using the python configuration
@author M.Frank
@version 1.0
"""
def run():
install_dir = os.environ['DD4hepINSTALL']
example_dir = install_dir+'/examples/DDG4/examples';
kernel.loadGeometry("file:"+install_dir+"/examples/CLICSiD/compact/compact.xml")
kernel.loadXML("file:"+example_dir+"/DDG4_field.xml")
lcdd = kernel.lcdd()
print '+++ List of sensitive detectors:'
for i in lcdd.detectors():
o = DDG4.DetElement(i.second)
sd = lcdd.sensitiveDetector(o.name())
if sd.isValid():
print '+++ %-32s type:%s'%(o.name(), sd.type(), )
# Configure UI
ui = DDG4.Action(kernel,"Geant4UIManager/UI")
ui.HaveVIS = True
ui.HaveUI = True
ui.SessionType = 'csh'
kernel.registerGlobalAction(ui)
# Configure Run actions
run1 = DDG4.RunAction(kernel,'Geant4TestRunAction/RunInit')
run1.Property_int = 12345
run1.Property_double = -5e15*keV
run1.Property_string = 'Startrun: Hello_2'
print run1.Property_string, run1.Property_double, run1.Property_int
run1.enableUI()
kernel.registerGlobalAction(run1)
kernel.runAction().add(run1)
# Configure Event actions
evt2 = DDG4.EventAction(kernel,'Geant4TestEventAction/UserEvent_2')
evt2.Property_int = 123454321
evt2.Property_double = 5e15*GeV
evt2.Property_string = 'Hello_2 from the python setup'
evt2.enableUI()
kernel.registerGlobalAction(evt2)
evt1 = DDG4.EventAction(kernel,'Geant4TestEventAction/UserEvent_1')
evt1.Property_int=01234
evt1.Property_double=1e11
evt1.Property_string='Hello_1'
evt1.enableUI()
kernel.eventAction().add(evt1)
kernel.eventAction().add(evt2)
trk = DDG4.Action(kernel,"Geant4TrackPersistency/MonteCarloTruthHandler")
mc = DDG4.Action(kernel,"Geant4MonteCarloRecordManager/MonteCarloRecordManager")
kernel.registerGlobalAction(trk)
kernel.registerGlobalAction(mc)
trk.release()
mc.release()
# Configure I/O
evt_root = DDG4.EventAction(kernel,'Geant4Output2ROOT/RootOutput')
evt_root.Control = True
evt_root.Output = "simple.root"
evt_root.enableUI()
kernel.eventAction().add(evt_root)
#evt_lcio = DDG4.EventAction(kernel,'Geant4Output2LCIO/LcioOutput')
#evt_lcio.Output = "simple_lcio"
#evt_lcio.enableUI()
#kernel.eventAction().add(evt_lcio)
# Setup particle gun
gun = DDG4.GeneratorAction(kernel,"Geant4ParticleGun/Gun")
gun.energy = 0.5*GeV
gun.particle = 'e-'
gun.multiplicity = 1
gun.enableUI()
kernel.generatorAction().add(gun)
"""
rdr = DDG4.GeneratorAction(kernel,"LcioGeneratorAction/Reader")
rdr.zSpread = 0.0
rdr.lorentzAngle = 0.0
rdr.OutputLevel = DDG4.OutputLevel.INFO
rdr.Input = "LcioEventReader|test.data"
rdr.enableUI()
kernel.generatorAction().add(rdr)
"""
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
# Setup global filters fur use in sensntive detectors
f1 = DDG4.Filter(kernel,'GeantinoRejectFilter/GeantinoRejector')
f2 = DDG4.Filter(kernel,'ParticleRejectFilter/OpticalPhotonRejector')
f2.particle = 'opticalphoton'
f3 = DDG4.Filter(kernel,'ParticleSelectFilter/OpticalPhotonSelector')
f3.particle = 'opticalphoton'
f4 = DDG4.Filter(kernel,'EnergyDepositMinimumCut')
f4.Cut = 10*MeV
f4.enableUI()
kernel.registerGlobalFilter(f1)
kernel.registerGlobalFilter(f2)
kernel.registerGlobalFilter(f3)
kernel.registerGlobalFilter(f4)
# First the tracking detectors
seq = DDG4.SensitiveSequence(kernel,'Geant4SensDetActionSequence/SiVertexBarrel')
act = DDG4.SensitiveAction(kernel,'Geant4SimpleTrackerAction/SiVertexBarrelHandler','SiVertexBarrel')
seq.add(act)
seq.add(f1)
seq.add(f4)
act.add(f1)
seq = DDG4.SensitiveSequence(kernel,'Geant4SensDetActionSequence/SiVertexEndcap')
act = DDG4.SensitiveAction(kernel,'Geant4SimpleTrackerAction/SiVertexEndcapHandler','SiVertexEndcap')
seq.add(act)
seq.add(f1)
seq.add(f4)
seq = DDG4.SensitiveSequence(kernel,'Geant4SensDetActionSequence/SiTrackerBarrel')
act = DDG4.SensitiveAction(kernel,'Geant4SimpleTrackerAction/SiTrackerBarrelHandler','SiTrackerBarrel')
seq.add(act)
seq.add(f1)
seq.add(f4)
seq = DDG4.SensitiveSequence(kernel,'Geant4SensDetActionSequence/SiTrackerEndcap')
act = DDG4.SensitiveAction(kernel,'Geant4SimpleTrackerAction/SiTrackerEndcapHandler','SiTrackerEndcap')
seq.add(act)
seq = DDG4.SensitiveSequence(kernel,'Geant4SensDetActionSequence/SiTrackerForward')
act = DDG4.SensitiveAction(kernel,'Geant4SimpleTrackerAction/SiTrackerForwardHandler','SiTrackerForward')
seq.add(act)
# Now the calorimeters
seq = DDG4.SensitiveSequence(kernel,'Geant4SensDetActionSequence/EcalBarrel')
act = DDG4.SensitiveAction(kernel,'Geant4SimpleCalorimeterAction/EcalBarrelHandler','EcalBarrel')
seq.add(act)
seq = DDG4.SensitiveSequence(kernel,'Geant4SensDetActionSequence/EcalEndcap')
act = DDG4.SensitiveAction(kernel,'Geant4SimpleCalorimeterAction/EcalEndCapHandler','EcalEndcap')
seq.add(act)
seq = DDG4.SensitiveSequence(kernel,'Geant4SensDetActionSequence/HcalBarrel')
act = DDG4.SensitiveAction(kernel,'Geant4SimpleCalorimeterAction/HcalBarrelHandler','HcalBarrel')
act.adoptFilter(kernel.globalFilter('OpticalPhotonRejector'))
seq.add(act)
act = DDG4.SensitiveAction(kernel,'Geant4SimpleCalorimeterAction/HcalOpticalBarrelHandler','HcalBarrel')
act.adoptFilter(kernel.globalFilter('OpticalPhotonSelector'))
seq.add(act)
seq = DDG4.SensitiveSequence(kernel,'Geant4SensDetActionSequence/HcalEndcap')
act = DDG4.SensitiveAction(kernel,'Geant4SimpleCalorimeterAction/HcalEndcapHandler','HcalEndcap')
seq.add(act)
seq = DDG4.SensitiveSequence(kernel,'Geant4SensDetActionSequence/HcalPlug')
act = DDG4.SensitiveAction(kernel,'Geant4SimpleCalorimeterAction/HcalPlugHandler','HcalPlug')
seq.add(act)
seq = DDG4.SensitiveSequence(kernel,'Geant4SensDetActionSequence/MuonBarrel')
act = DDG4.SensitiveAction(kernel,'Geant4SimpleCalorimeterAction/MuonBarrelHandler','MuonBarrel')
seq.add(act)
seq = DDG4.SensitiveSequence(kernel,'Geant4SensDetActionSequence/MuonEndcap')
act = DDG4.SensitiveAction(kernel,'Geant4SimpleCalorimeterAction/MuonEndcapHandler','MuonEndcap')
seq.add(act)
seq = DDG4.SensitiveSequence(kernel,'Geant4SensDetActionSequence/LumiCal')
act = DDG4.SensitiveAction(kernel,'Geant4SimpleCalorimeterAction/LumiCalHandler','LumiCal')
seq.add(act)
seq = DDG4.SensitiveSequence(kernel,'Geant4SensDetActionSequence/BeamCal')
act = DDG4.SensitiveAction(kernel,'Geant4SimpleCalorimeterAction/BeamCalHandler','BeamCal')
seq.add(act)
# Now build the physics list:
phys = kernel.physicsList()
phys.extends = 'FTFP_BERT'
#phys.transportation = True
phys.decays = True
phys.enableUI()
ph = DDG4.PhysicsList(kernel,'Geant4PhysicsList/Myphysics')
ph.addParticleConstructor('G4BosonConstructor')
ph.addParticleConstructor('G4LeptonConstructor')
ph.addParticleProcess('e[+-]','G4eMultipleScattering',-1,1,1)
ph.addPhysicsConstructor('G4OpticalPhysics')
ph.enableUI()
phys.add(ph)
phys.dump()
kernel.configure()
kernel.initialize()
kernel.run()
kernel.terminate()
if __name__ == "__main__":
run()