This repository was archived by the owner on May 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerators.py.in
More file actions
337 lines (275 loc) · 10.3 KB
/
Copy pathgenerators.py.in
File metadata and controls
337 lines (275 loc) · 10.3 KB
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
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
"""Primary Generator templates for use throughout ldmx-sw
Mainly focused on reducing the number of places that certain parameter and class names
are hardcoded into the python configuration.
"""
from @PYTHON_PACKAGE_NAME@.SimCore import simcfg
class gun(simcfg.PrimaryGenerator) :
"""New basic particle gun primary generator
Parameters
----------
name : str
name of new primary generator
Attributes
----------
time : float, optional
Time to shoot from [ns]
verbosity : int, optional
Verbosity flag for this generator
particle : str
Geant4 particle name to shoot
energy : float
Energy of particle to shoot [GeV]
position : list of float
Position to shoot from [mm]
direction : list of float
Unit vector direction to shoot from
Examples
--------
myGun = gun( 'myGun' )
myGun.particle = 'e-'
myGun.energy = 4.0
myGun.direction = [ 0., 0., 1. ]
myGun.position = [ 0., 0., 0. ]
"""
def __init__(self, name ) :
super().__init__( name , "simcore::generators::ParticleGun" )
self.time = 0.
self.verbosity = 0
self.particle = ''
self.energy = 0.
self.position = [ ]
self.direction = [ ]
class multi(simcfg.PrimaryGenerator) :
"""New multi particle gun primary generator
Parameters
----------
name : str
name of new primary generator
Attributes
----------
enablePoisson : bool, optional
Poisson-distribute number of particles?
vertex : list of float
Position to shoot particle(s) from [mm]
momentum : list of float
3-momentum to give particle(s) in [MeV]
nParticles : int, optional
Number of particles to shoot (or average of Poisson distribution)
pdgID : int
PDG ID of particle(s) to shoot
"""
def __init__(self,name) :
super().__init__(name,'simcore::generators::MultiParticleGunPrimaryGenerator')
#turn off Poisson by default
self.enablePoisson = False
self.vertex = [ ]
self.momentum = [ ]
self.nParticles = 1
self.pdgID = 0
class lhe(simcfg.PrimaryGenerator) :
"""New LHE file primary generator
Parameters
----------
name : str
name of new primary generator
filePath : str
path to LHE file containing the primary vertices
"""
def __init__(self,name,filePath):
super().__init__(name,'simcore::generators::LHEPrimaryGenerator')
self.filePath = filePath
class completeReSim(simcfg.PrimaryGenerator) :
"""New complete re-simprimary generator
Parameters
----------
name : str
name of new primary generator
file_path : str
path to ROOT file containing the SimParticles to re-simulate
Attributes
----------
collection_name : str
Name of SimParticles collection to re-sim
pass_name : str
Pass name of SimParticles to re-sim
"""
def __init__(self,name,file_path) :
super().__init__(name,'simcore::generators::RootCompleteReSim')
self.filePath = file_path
self.collection_name = 'SimParticles'
self.pass_name = ''
class ecalSP(simcfg.PrimaryGenerator) :
"""New ecal scoring planes primary generator
Sets the collection name, pass name, and time cutoff
to reasonable defaults.
Parameters
----------
name : str
name of new primary generator
filePath : str
path to ROOT file containing the EcalScoringPlanes to re-simulate
Attributes
----------
collection_name : str, optional
Name of EcalScoringPlaneHits collection to re-sim
pass_name : str, optional
Pass name of EcalScoringPlaneHits to re-sim
time_cutoff : float, optional
Maximum time of scoring plane hit to still re-sim [ns]
"""
def __init__(self,name,filePath) :
super().__init__( name , 'simcore::generators::RootSimFromEcalSP' )
self.filePath = filePath
self.collection_name = 'EcalScoringPlaneHits'
self.pass_name = ''
self.time_cutoff = 50.
class gps(simcfg.PrimaryGenerator) :
"""New general particle source
The input initialization commands are run in the order that they are listed.
Parameters
----------
name : str
name of new primary generator
initCommands : list of strings
List of Geant4 commands to initialize this GeneralParticleSource
Returns
-------
simcfg.PrimaryGenerator
configured to be a GeneralParticleSource with the passed initialization commands
Examples
--------
myGPS = gps( 'myGPS' , [
"/gps/particle e-",
"/gps/pos/type Plane",
"/gps/pos/shape Square",
"/gps/pos/centre 0 0 0 mm",
"/gps/pos/halfx 40 mm",
"/gps/pos/halfy 80 mm",
"/gps/ang/type cos",
"/gps/ene/type Lin",
"/gps/ene/min 3 GeV",
"/gps/ene/max 4 GeV",
"/gps/ene/gradient 1",
"/gps/ene/intercept 1"
] )
"""
def __init__(self,name,initCommands) :
super().__init__(name,'simcore::generators::GeneralParticleSource')
self.initCommands = initCommands
def _single_e_upstream_tagger(position, momentum, energy):
"""Internal helper function for creating electron beam guns upstream of tagger
The guns position and momentum are determined by shooting a positron
_backwards_ from the target without any detector components present. This
uses Geant4 to calculate the trajectory within the magnetic field for us.
Since the particle (if its high enough energy) will not interact with anything,
you only need to generate a few events to get a good measurement.
Parameters
----------
position: list[float]
end-point position of the positron shot backwards from target,
is the start-point of an electron being shot into the target
momentum: list[float]
end-point momentum of the backwards positron **multiplied by -1**,
defines the starting direction of an electron being shot into
the target
energy: float
the energy of the electron in GeV, should be the same energy
as the backwards positron used to deduce position and momentum
Returns
-------
gun:
configured instance of gun firing from far upstream of detector
"""
import math
momentum_mag = math.sqrt(sum(map(lambda x: x*x, momentum)))
unit_direction = list(map(lambda x: x/momentum_mag, momentum))
particle_gun = gun(f'single_{energy}gev_e_upstream_tagger')
particle_gun.particle = 'e-'
particle_gun.position = position
particle_gun.direction = unit_direction
particle_gun.energy = energy
return particle_gun
def single_4gev_e_upstream_tagger() :
"""Configure a particle gun to fire a 4 GeV electron upstream of the tagger tracker.
The position and direction are set such that the electron will be bent by
the field and arrive at the target at [0, 0, 0] if it isn't smeared and doesn't
interact with any material. In reality, it will be smeared and it will interact
with some material but we can dream.
Returns
-------
Instance of a particle gun configured to fire a single 4 Gev electron
upstream of the entire detector apparatus.
"""
return _single_e_upstream_tagger(
[ -600.8976671223825, 0.0, -6000.0 ],
[ 434.54301089006407, 0.0, 3976.8404804302777],
4.0
)
def single_4gev_e_upstream_target() :
"""Configure a particle gun to fire a 4 GeV electron upstream of the tagger tracker.
The position and direction are set such that the electron will be bent by
the field and arrive at the target at approximately [0, 0, 0] (assuming
it's not smeared).
Returns
-------
Instance of a particle gun configured to fire a single 4 Gev electron
directly upstream of the target.
"""
particle_gun = gun('single_4gev_e_upstream_target')
particle_gun.particle = 'e-'
particle_gun.position = [ 0., 0., -1.2 ] # mm
particle_gun.direction = [ 0., 0., 1]
particle_gun.energy = 4.0 # GeV
return particle_gun
def single_1pt2gev_e_upstream_tagger():
"""Configure a particle gun to fire a 8 GeV electron upstream of the tagger tracker.
The position and direction are set such that the electron will be bent by
the field and arrive at the target at [0, 0, 0] if it isn't smeared and doesn't
interact with any material. In reality, it will be smeared and it will interact
with some material but we can dream.
Returns
-------
Instance of a particle gun configured to fire a single 8 GeV electron
upstream of the entire detector apparatus.
"""
return _single_e_upstream_tagger(
[ -2083.3707473241993, 0.0, -6000.0 ],
[ 425.132266424426, 0.0, 1122.7149711218378],
1.2
)
def single_8gev_e_upstream_tagger():
"""Configure a particle gun to fire a 8 GeV electron upstream of the tagger tracker.
The position and direction are set such that the electron will be bent by
the field and arrive at the target at [0, 0, 0] if it isn't smeared and doesn't
interact with any material. In reality, it will be smeared and it will interact
with some material but we can dream.
Returns
-------
Instance of a particle gun configured to fire a single 8 GeV electron
upstream of the entire detector apparatus.
"""
return _single_e_upstream_tagger(
[ -299.2386690686212, 0.0, -6000.0 ],
[ 434.59663056485 , 0.0, 7988.698356992288],
8.0
)
def single_backwards_positron(energy: float):
"""A particle gun configured to shoot positrons backwards (i.e. upstream)
from the target at the input energy.
This generator is helpful for studying where electron guns of different energies should
be started from if they should end up at the center of the target.
Parameters
----------
energy: float
energy in GeV of the positron
Returns
-------
gun:
configured particle gun to shoot positrons backwards at the input energy
"""
beam = gun(f'backwards-positron-{energy}GeV')
beam.particle = 'e+'
beam.position = [0., 0., 0.]
beam.direction = [0., 0., -1.]
beam.energy = energy
return beam