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
#!/usr/bin/env python
from __future__ import absolute_import, unicode_literals
import os
import time
import logging
import argparse
parser = argparse.ArgumentParser(
prog='run_topside',
description='''This runs the simulation the but that is okay''',
epilog='''
This program should be run in the "compact" directory.
''')
parser.add_argument("-v","--verbose", help="increase output verbosity", type=int, default=0)
parser.add_argument("--compact", help="compact detector file",default="topside/vertex_tracker.xml")
parser.add_argument("--vis", help="vis true/false", action="store_true",default=False)
parser.add_argument("--ui", help="ui setting tcsh or qt; default=qt", type=str,default="qt",dest="ui")
parser.add_argument("-n","--n-events", help="number of events", type=int, default=0)
parser.add_argument("-s","--n-skip", help="number of events to skip", type=int, default=0)
parser.add_argument("-m","--macro", help="macro to execute", default="macro/vis.mac")
parser.add_argument("-o","--output", help="output file", default=None)
parser.add_argument("-i","--input", help="input data file", default=None)
parser.add_argument("--target-position", nargs=3, help="nominal location of the target in units of mm", default=[0.0,0.0,-3000.0],metavar=("X","Y","Z"))
args = parser.parse_args()
import DDG4
from DDG4 import OutputLevel as Output
from g4units import keV, GeV, mm, ns, MeV
def run():
if not args.vis:
os.environ['G4UI_USE_TCSH'] = "0"
kernel = DDG4.Kernel()
description = kernel.detectorDescription()
kernel.loadGeometry(str("file:" + args.compact))
DDG4.importConstants(description)
geant4 = DDG4.Geant4(kernel)
if args.vis > 0:
geant4.printDetectors()
n_events = args.n_events
if args.vis:
geant4.setupUI(typ=args.ui, vis=True,ui=True, macro=args.macro)
else:
geant4.setupUI(typ=args.ui, vis=False,ui=False,macro=False)
if n_events <= 0:
n_events = 1
kernel.NumEvents = n_events
geant4.setupTrackingField(stepper='ClassicalRK4', equation='Mag_UsualEqRhs')
rndm = DDG4.Action(kernel, 'Geant4Random/Random')
if os.getenv('SEED') is None:
rndm.Seed = 1234
else :
rndm.Seed = os.getenv('SEED')
rndm.initialize()
rndm.showStatus()
run1 = DDG4.RunAction(kernel, 'Geant4TestRunAction/RunInit')
run1.Property_int = 12345
run1.Property_double = -5e15 * keV
run1.Property_string = 'Startrun: Hello_2'
run1.enableUI()
kernel.registerGlobalAction(run1)
kernel.runAction().adopt(run1)
prt = DDG4.EventAction(kernel, 'Geant4ParticlePrint/ParticlePrint')
kernel.eventAction().adopt(prt)
outputfile = args.output
if outputfile is None:
outputfile = 'data/simple_topside_' + time.strftime('%Y-%m-%d_%H-%M')
#rootoutput = geant4.setupROOTOutput('RootOutput', outputfile)
#rootoutput.HandleMCTruth = True
podio = DDG4.EventAction(kernel, 'Geant4Output2Podio/RootOutput', True)
podio.HandleMCTruth = False
podio.Control = True
podio.Output = outputfile
podio.enableUI()
kernel.eventAction().adopt(podio)
#--------------------------------
gen = DDG4.GeneratorAction(kernel, "Geant4GeneratorActionInit/GenerationInit")
gen.OutputLevel = 5
gen.enableUI()
kernel.generatorAction().adopt(gen)
gen = DDG4.GeneratorAction(kernel, "Geant4InputAction/hepmc3")
gen.Mask = 0

Whitney Armstrong
committed
gen.OutputLevel = 5
98
99
100
101
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
211
212
213
214
inputfile = args.input
if inputfile is None:
inputfile = "data/proton_dvcs_eic.hepmc"
gen = DDG4.GeneratorAction(kernel, "Geant4InputAction/hepmc3")
gen.Mask = 0
gen.Input = "HEPMC3FileReader|" + inputfile
gen.OutputLevel = 0 # generator_output_level
gen.Sync = args.n_skip
gen.enableUI()
kernel.generatorAction().adopt(gen)
####
#
####
gen = DDG4.GeneratorAction(kernel, "EICInteractionVertexSmear/BeamDivergence")
gen.Mask = 0
gen.OutputLevel = 5 # generator_output_level
#gen.Sigma = (4 * mm, 1 * mm, 1 * mm, 0 * ns)
kernel.generatorAction().adopt(gen)
gen = DDG4.GeneratorAction(kernel, "EICInteractionVertexBoost/CrossingAngle")
gen.Mask = 0
gen.OutputLevel = 5 # generator_output_level
#gen.Sigma = (4 * mm, 1 * mm, 1 * mm, 0 * ns)
kernel.generatorAction().adopt(gen)
gen = DDG4.GeneratorAction(kernel, "Geant4InteractionMerger/InteractionMerger")
gen.OutputLevel = 0 # generator_output_level
gen.enableUI()
kernel.generatorAction().adopt(gen)
gen = DDG4.GeneratorAction(kernel, "Geant4PrimaryHandler/PrimaryHandler")
gen.OutputLevel = 0 # generator_output_level
gen.enableUI()
kernel.generatorAction().adopt(gen)
part = DDG4.GeneratorAction(kernel, "Geant4ParticleHandler/ParticleHandler")
# part.SaveProcesses = ['conv','Decay']
#part.SaveProcesses = ['Decay']
part.MinimalKineticEnergy = 100000 * GeV
part.OutputLevel = 0 # generator_output_level
part.enableUI()
kernel.generatorAction().adopt(part)
####
#
####
f3 = DDG4.Filter(kernel, 'ParticleSelectFilter/OpticalPhotonSelector')
f3.particle = 'opticalphoton'
kernel.registerGlobalFilter(f3)
#seq, act = geant4.setupDetector('ForwardRICH','PhotoMultiplierSDAction')
#act.adopt(f3)
seq, act = geant4.setupTracker('SiVertexBarrel')
#seq, act = geant4.setupTracker('SiTrackerForward')
#seq, act = geant4.setupCalorimeter('EcalBarrel')
#seq, act = geant4.setupCalorimeter('EcalEndcap')
#seq, act = geant4.setupCalorimeter('HcalBarrel')
#seq, act = geant4.setupTracker('RomanPot1')
#seq, act = geant4.setupTracker('RomanPot2')
#seq, act = geant4.setupTracker('RomanPot3')
#seq, act = geant4.setupTracker('RomanPot4')
#seq, act = geant4.setupTracker('RomanPot44')
#seq, act = geant4.setupTracker('RomanPot45')
#seq, act = geant4.setupTracker('RomanPot46')
#seq, act = geant4.setupTracker('RomanPot47')
#seq, act = geant4.setupTracker('RomanPot48')
#seq, act = geant4.setupTracker('RomanPot49')
#seq, act = geant4.setupTracker('RomanPot50')
#seq, act = geant4.setupTracker('RomanPot51')
phys = geant4.setupPhysics('QGSP_BERT')
geant4.addPhysics(str('Geant4PhysicsList/Myphysics'))
#ph = DDG4.PhysicsList(kernel, 'Geant4OpticalPhotonPhysics/OpticalPhotonPhys')
#ph.VerboseLevel = 0
#ph.enableUI()
#phys.adopt(ph)
#ph = DDG4.PhysicsList(kernel, 'Geant4CerenkovPhysics/CerenkovPhys')
#ph.MaxNumPhotonsPerStep = 10
#ph.MaxBetaChangePerStep = 10.0
#ph.TrackSecondariesFirst = True
#ph.VerboseLevel = 0
#ph.enableUI()
#phys.adopt(ph)
## Add special particle types from specialized physics constructor
#part = geant4.addPhysics('Geant4ExtraParticles/ExtraParticles')
#part.pdgfile = 'checkout/DDG4/examples/particle.tbl'
# Add global range cut
rg = geant4.addPhysics('Geant4DefaultRangeCut/GlobalRangeCut')
rg.RangeCut = 0.7 * mm
#phys.dump()
#ui_action = dd4hep.sim.createAction(kernel, "Geant4UIManager/UI")
#ui_action.HaveVIS = True
#ui_action.HaveUI = True
#ui_action.SessionType = qt
#ui_action.SetupUI = macro
#kernel.registerGlobalAction(ui_action)
kernel.configure()
kernel.initialize()
# DDG4.setPrintLevel(Output.DEBUG)
kernel.run()
kernel.terminate()
if __name__ == "__main__":
run()