@@ -193,35 +193,63 @@ class gps(simcfg.PrimaryGenerator) :
193193 super().__init__(name,'simcore::generators::GeneralParticleSource')
194194 self.initCommands = initCommands
195195
196+ def _single_e_upstream_tagger(position, momentum, energy):
197+ """Internal helper function for creating electron beam guns upstream of tagger
198+
199+ The guns position and momentum are determined by shooting a positron
200+ _backwards_ from the target without any detector components present. This
201+ uses Geant4 to calculate the trajectory within the magnetic field for us.
202+ Since the particle (if its high enough energy) will not interact with anything,
203+ you only need to generate a few events to get a good measurement.
204+
205+ Parameters
206+ ----------
207+ position: list[float]
208+ end-point position of the positron shot backwards from target,
209+ is the start-point of an electron being shot into the target
210+ momentum: list[float]
211+ end-point momentum of the backwards positron **multiplied by -1**,
212+ defines the starting direction of an electron being shot into
213+ the target
214+ energy: float
215+ the energy of the electron in GeV, should be the same energy
216+ as the backwards positron used to deduce position and momentum
217+
218+ Returns
219+ -------
220+ gun:
221+ configured instance of gun firing from far upstream of detector
222+ """
223+
224+ import math
225+ momentum_mag = math.sqrt(sum(map(lambda x: x*x, momentum)))
226+ unit_direction = list(map(lambda x: x/momentum_mag, momentum))
227+
228+ particle_gun = gun(f'single_{energy}gev_e_upstream_tagger')
229+ particle_gun.particle = 'e-'
230+ particle_gun.position = position
231+ particle_gun.direction = unit_direction
232+ particle_gun.energy = energy
233+ return particle_gun
234+
196235def single_4gev_e_upstream_tagger() :
197236 """Configure a particle gun to fire a 4 GeV electron upstream of the tagger tracker.
198237
199238 The position and direction are set such that the electron will be bent by
200- the field and arrive at the target at approximately [0, 0, 0] (assuming
201- it's not smeared).
202-
203- The gun position of [ -27.926 , 0 , -700 ] # mm requires the particles to be fired at theta = 4.5 degrees.
204- The gun position of [ -44. , 0 , -880 ] # mm requires the particles to be fired at theta = 5.65 degrees.
239+ the field and arrive at the target at [0, 0, 0] if it isn't smeared and doesn't
240+ interact with any material. In reality, it will be smeared and it will interact
241+ with some material but we can dream.
205242
206- The direction vector is calculated as follows:
207-
208- dir_vector = [ sin(theta), 0, cos(theta) ]
209-
210243 Returns
211244 -------
212245 Instance of a particle gun configured to fire a single 4 Gev electron
213- directly upstream of the tagger tracker.
214-
246+ upstream of the entire detector apparatus.
215247 """
216- particle_gun = gun('single_4gev_e_upstream_tagger')
217- particle_gun.particle = 'e-'
218- particle_gun.position = [ -44. , 0. , -880. ] # mm
219- import math
220- theta = math.radians(5.65)
221- particle_gun.direction = [ math.sin(theta) , 0, math.cos(theta) ] #unitless
222- particle_gun.energy = 4.0 # GeV
223-
224- return particle_gun
248+ return _single_e_upstream_tagger(
249+ [ -600.8976671223825, 0.0, -6000.0 ],
250+ [ 434.54301089006407, 0.0, 3976.8404804302777],
251+ 4.0
252+ )
225253
226254def single_4gev_e_upstream_target() :
227255 """Configure a particle gun to fire a 4 GeV electron upstream of the tagger tracker.
@@ -233,8 +261,7 @@ def single_4gev_e_upstream_target() :
233261 Returns
234262 -------
235263 Instance of a particle gun configured to fire a single 4 Gev electron
236- directly upstream of the tagger tracker.
237-
264+ directly upstream of the target.
238265 """
239266
240267 particle_gun = gun('single_4gev_e_upstream_target')
@@ -246,62 +273,39 @@ def single_4gev_e_upstream_target() :
246273 return particle_gun
247274
248275def single_1pt2gev_e_upstream_tagger():
249- """Configure a particle gun to fire a 1.2 GeV electron upstream of the tagger tracker.
250-
251- This is used to study the rejection of off energy electrons in the tagger
252- tracker. The position and direction are set such that the electron will be
253- bent by the field and arrive at the target at approximately [0, 0, 0]
254- (assuming it's not smeared).
276+ """Configure a particle gun to fire a 8 GeV electron upstream of the tagger tracker.
255277
256- The gun position below requires the particles to be fired at 11.011 degrees.
257- The direction vector is calculated as follows:
258-
259- dir_vector = [ sin(11.011) = .2292/1.2, 0, cos(11.011) = 1.1779/1.2 ]
278+ The position and direction are set such that the electron will be bent by
279+ the field and arrive at the target at [0, 0, 0] if it isn't smeared and doesn't
280+ interact with any material. In reality, it will be smeared and it will interact
281+ with some material but we can dream.
260282
261-
262283 Returns
263284 -------
264- Instance of a particle gun configured to fire a single 1.2 Gev electron
265- directly upstream of the tagger tracker.
266-
285+ Instance of a particle gun configured to fire a single 8 GeV electron
286+ upstream of the entire detector apparatus.
267287 """
268- particle_gun = gun( "single_1.2gev_e_upstream_tagger" )
269- particle_gun.particle = 'e-'
270- particle_gun.position = [ -36.387, 0, -700 ] #mm
271- import math
272- theta = math.radians(11.011)
273- particle_gun.direction = [ math.sin(theta) , 0, math.cos(theta) ] #unitless
274- particle_gun.energy = 1.2 #GeV
275-
276- return particle_gun
277-
288+ return _single_e_upstream_tagger(
289+ [ -2083.3707473241993, 0.0, -6000.0 ],
290+ [ 425.132266424426, 0.0, 1122.7149711218378],
291+ 1.2
292+ )
278293
279294def single_8gev_e_upstream_tagger():
280295 """Configure a particle gun to fire a 8 GeV electron upstream of the tagger tracker.
281296
282- This is used to study the rejection of off energy electrons in the tagger
283- tracker. The position and direction are set such that the electron will be
284- bent by the field and arrive at the target at approximately [0, 0, 0]
285- (assuming it's not smeared).
286-
287- The gun position below requires the particles to be fired at 2.5 degrees.
288- The direction vector is calculated as follows:
289-
290- dir_vector = [ 8.*sin(2.5) = .349, 0, 8.*cos(2.5) = 7.9924 ]
297+ The position and direction are set such that the electron will be bent by
298+ the field and arrive at the target at [0, 0, 0] if it isn't smeared and doesn't
299+ interact with any material. In reality, it will be smeared and it will interact
300+ with some material but we can dream.
291301
292-
293302 Returns
294303 -------
295- Instance of a particle gun configured to fire a single 8 Gev electron
296- directly upstream of the tagger tracker.
297-
304+ Instance of a particle gun configured to fire a single 8 GeV electron
305+ upstream of the entire detector apparatus.
298306 """
299- particle_gun = gun( "single_1.2gev_e_upstream_tagger" )
300- particle_gun.particle = 'e-'
301- particle_gun.position = [ -14.292, 0, -700 ] #mm
302- import math
303- theta = math.radians(2.5)
304- particle_gun.direction = [ math.sin(theta) , 0, math.cos(theta) ] #unitless
305- particle_gun.energy = 8.0 #GeV
306-
307- return particle_gun
307+ return _single_e_upstream_tagger(
308+ [ -299.2386690686212, 0.0, -6000.0 ],
309+ [ 434.59663056485 , 0.0, 7988.698356992288],
310+ 8.0
311+ )
0 commit comments