This repository has been 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
/
generators.py
305 lines (239 loc) · 8.96 KB
/
generators.py
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
"""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 LDMX.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 , "ldmx::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,'ldmx::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,'ldmx::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,'ldmx::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 , 'ldmx::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,'ldmx::GeneralParticleSource')
self.initCommands = initCommands
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 approximately [0, 0, 0] (assuming
it's not smeared).
The gun position below requires the particles to be fired at 4.5 degrees.
The direction vector is calculated as follows:
dir_vector = [ sin(4.5) = .3138/4, 0, cos(4.5) = 3.9877/4 ]
Returns
-------
Instance of a particle gun configured to fire a single 4 Gev electron
directly upstream of the tagger tracker.
"""
particle_gun = gun('single_4gev_e_upstream_tagger')
particle_gun.particle = 'e-'
particle_gun.position = [ -27.926 , 0 , -700 ] # mm
import math
theta = math.radians(4.5)
particle_gun.direction = [ math.sin(theta) , 0, math.cos(theta) ] #unitless
particle_gun.energy = 4.0 # GeV
return particle_gun
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 tagger tracker.
"""
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 1.2 GeV electron upstream of the tagger tracker.
This is used to study the rejection of off energy electrons in 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).
The gun position below requires the particles to be fired at 11.011 degrees.
The direction vector is calculated as follows:
dir_vector = [ sin(11.011) = .2292/1.2, 0, cos(11.011) = 1.1779/1.2 ]
Returns
-------
Instance of a particle gun configured to fire a single 1.2 Gev electron
directly upstream of the tagger tracker.
"""
particle_gun = gun( "single_1.2gev_e_upstream_tagger" )
particle_gun.particle = 'e-'
particle_gun.position = [ -36.387, 0, -700 ] #mm
import math
theta = math.radians(11.011)
particle_gun.direction = [ math.sin(theta) , 0, math.cos(theta) ] #unitless
particle_gun.energy = 1.2 #GeV
return particle_gun
def single_8gev_e_upstream_tagger():
"""Configure a particle gun to fire a 8 GeV electron upstream of the tagger tracker.
This is used to study the rejection of off energy electrons in 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).
The gun position below requires the particles to be fired at 2.5 degrees.
The direction vector is calculated as follows:
dir_vector = [ 8.*sin(2.5) = .349, 0, 8.*cos(2.5) = 7.9924 ]
Returns
-------
Instance of a particle gun configured to fire a single 8 Gev electron
directly upstream of the tagger tracker.
"""
particle_gun = gun( "single_1.2gev_e_upstream_tagger" )
particle_gun.particle = 'e-'
particle_gun.position = [ -14.292, 0, -700 ] #mm
import math
theta = math.radians(2.5)
particle_gun.direction = [ math.sin(theta) , 0, math.cos(theta) ] #unitless
particle_gun.energy = 8.0 #GeV
return particle_gun