VMC Examples Version 6.6
Loading...
Searching...
No Matches
Ex03PrimaryGenerator.cxx
Go to the documentation of this file.
1//------------------------------------------------
2// The Virtual Monte Carlo examples
3// Copyright (C) 2014 - 2018 Ivana Hrivnacova
4// All rights reserved.
5//
6// For the licensing terms see geant4_vmc/LICENSE.
7// Contact: root-vmc@cern.ch
8//-------------------------------------------------
9
10/// \file Ex03PrimaryGenerator.cxx
11/// \brief Implementation of the Ex03PrimaryGenerator class
12///
13/// Geant4 ExampleN03 adapted to Virtual Monte Carlo \n
14/// Id: ExN03PrimaryGeneratorAction.cc,v 1.6 2002/01/09 17:24:13 ranjard Exp \n
15/// GEANT4 tag Name: geant4-05-00
16///
17/// \date 06/03/2002
18/// \author I. Hrivnacova; IPN, Orsay
19
20#include <TDatabasePDG.h>
21#include <TPDGCode.h>
22#include <TParticlePDG.h>
23#include <TRandom.h>
24#include <TVector3.h>
25#include <TVirtualMC.h>
26#include <TVirtualMCApplication.h>
27#include <TVirtualMCStack.h>
28
29#include "Ex03PrimaryGenerator.h"
30
31/// \cond CLASSIMP
33 /// \endcond
34
35 //_____________________________________________________________________________
37 : TObject(),
38 fStack(stack),
39 fIsRandom(false),
40 fPrimaryType(kDefault),
41 fNofPrimaries(1)
42
43{
44 /// Standard constructor
45 /// \param stack The VMC stack
46}
47
48//_____________________________________________________________________________
50 const Ex03PrimaryGenerator& origin, TVirtualMCStack* stack)
51 : TObject(origin),
52 fStack(stack),
53 fIsRandom(origin.fIsRandom),
54 fPrimaryType(origin.fPrimaryType),
55 fNofPrimaries(origin.fNofPrimaries)
56{
57 /// Copy constructor (for clonig on worker thread in MT mode).
58 /// \param origin The source object (on master).
59 /// \param stack The VMC stack
60}
61
62//_____________________________________________________________________________
64 : TObject(),
65 fStack(0),
66 fIsRandom(false),
67 fPrimaryType(kDefault),
68 fNofPrimaries(0)
69{
70 /// Default constructor
71}
72
73//_____________________________________________________________________________
75{
76 /// Destructor
77}
78
79//
80// private methods
81//
82
83//_____________________________________________________________________________
84void Ex03PrimaryGenerator::GeneratePrimary1(const TVector3& origin)
85{
86 /// Add one primary particle (kElectron) to the user stack
87 /// (derived from TVirtualMCStack).
88 /// \param origin The track position
89
90 // Track ID (filled by stack)
91 Int_t ntr;
92
93 // Option: to be tracked
94 Int_t toBeDone = 1;
95
96 // PDG
97 Int_t pdg = kElectron;
98
99 // Polarization
100 Double_t polx = 0.;
101 Double_t poly = 0.;
102 Double_t polz = 0.;
103
104 // Position
105 Double_t vx = -0.5 * origin.X();
106 Double_t vy = 0.;
107 Double_t vz = 0.;
108 Double_t tof = 0.;
109
110 // Energy (in GeV)
111 Double_t kinEnergy = 0.050;
112 Double_t mass = 0.51099906 * 1e-03;
113 Double_t e = mass + kinEnergy;
114
115 // Particle momentum
116 Double_t px, py, pz;
117 px = sqrt(e * e - mass * mass);
118 py = 0.;
119 pz = 0.;
120
121 // Randomize position
122 if (fIsRandom) {
123 vy = origin.Y() * (gRandom->Rndm() - 0.5);
124 vz = origin.Z() * (gRandom->Rndm() - 0.5);
125 }
126
127 // Add particle to stack
128 fStack->PushTrack(toBeDone, -1, pdg, px, py, pz, e, vx, vy, vz, tof, polx,
129 poly, polz, kPPrimary, ntr, 1., 0);
130}
131
132//_____________________________________________________________________________
133void Ex03PrimaryGenerator::GeneratePrimary2(const TVector3& origin)
134{
135 /// Add user defined particle and ion as primaries to the user stack
136 /// (derived from TVirtualMCStack).
137 /// \param origin The track position
138
139 // Track ID (filled by stack)
140 Int_t ntr;
141
142 // Option: to be tracked
143 Int_t toBeDone = 1;
144
145 // User defined particle
146 TParticlePDG* particle = TDatabasePDG::Instance()->GetParticle("He5");
147 Int_t pdg = particle->PdgCode();
148
149 // Polarization
150 Double_t polx = 0.;
151 Double_t poly = 0.;
152 Double_t polz = 0.;
153
154 // Position
155 Double_t vx = -0.5 * origin.X();
156 Double_t vy = 0.;
157 Double_t vz = 0.;
158 Double_t tof = 0.;
159
160 // Energy (in GeV)
161 Double_t kinEnergy = 0.050;
162 Double_t mass = particle->Mass();
163 Double_t e = mass + kinEnergy;
164
165 // Particle momentum
166 Double_t px, py, pz;
167 px = sqrt(e * e - mass * mass);
168 py = 0.;
169 pz = 0.;
170
171 // Randomize position
172 if (fIsRandom) {
173 vy = origin.Y() * (gRandom->Rndm() - 0.5);
174 vz = origin.Z() * (gRandom->Rndm() - 0.5);
175 }
176
177 // Add particle to stack
178 fStack->PushTrack(toBeDone, -1, pdg, px, py, pz, e, vx, vy, vz, tof, polx,
179 poly, polz, kPPrimary, ntr, 1., 0);
180
181 // User defined ion
182 particle = TDatabasePDG::Instance()->GetParticle("MyIon");
183 pdg = particle->PdgCode();
184
185 // Energy (in GeV)
186 kinEnergy = 1.050;
187 mass = particle->Mass();
188 e = mass + kinEnergy;
189
190 px = sqrt(e * e - mass * mass);
191 py = 0.;
192 pz = 0.;
193
194 fStack->PushTrack(toBeDone, -1, pdg, px, py, pz, e, vx, vy, vz, tof, polx,
195 poly, polz, kPPrimary, ntr, 1., 0);
196}
197
198//_____________________________________________________________________________
199void Ex03PrimaryGenerator::GeneratePrimary3(const TVector3& origin)
200{
201 /// Add one primary particle (kK0Short) to the user stack
202 /// (derived from TVirtualMCStack).
203 /// \param origin The track position
204
205 // Track ID (filled by stack)
206 Int_t ntr;
207
208 // Option: to be tracked
209 Int_t toBeDone = 1;
210
211 // PDG
212 Int_t pdg = kK0Short; // 310
213
214 // Polarization
215 Double_t polx = 0.;
216 Double_t poly = 0.;
217 Double_t polz = 0.;
218
219 // Position
220 Double_t vx = -0.5 * origin.X();
221 Double_t vy = 0.;
222 Double_t vz = 0.;
223 Double_t tof = 0.;
224
225 // Energy (in GeV)
226 Double_t kinEnergy = 0.050;
227 Double_t mass = 0.497614;
228 Double_t e = mass + kinEnergy;
229
230 // Particle momentum
231 Double_t px, py, pz;
232 px = sqrt(e * e - mass * mass);
233 py = 0.;
234 pz = 0.;
235
236 // Randomize position
237 if (fIsRandom) {
238 vy = origin.Y() * (gRandom->Rndm() - 0.5);
239 vz = origin.Z() * (gRandom->Rndm() - 0.5);
240 }
241
242 // Add particle to stack
243 fStack->PushTrack(toBeDone, -1, pdg, px, py, pz, e, vx, vy, vz, tof, polx,
244 poly, polz, kPPrimary, ntr, 1., 0);
245}
246
247//_____________________________________________________________________________
248void Ex03PrimaryGenerator::GeneratePrimary4(const TVector3& origin)
249{
250 /// Add light anti-ions:
251
252 // Track ID (filled by stack)
253 Int_t ntr;
254
255 // Option: to be tracked
256 Int_t toBeDone = 1;
257
258 // PDG
259 TParticlePDG* particle =
260 TDatabasePDG::Instance()->GetParticle("AntiDeuteron");
261 Int_t pdg = particle->PdgCode();
262 ;
263
264 // Polarization
265 Double_t polx = 0.;
266 Double_t poly = 0.;
267 Double_t polz = 0.;
268
269 // Position
270 Double_t vx = -0.5 * origin.X();
271 Double_t vy = 0.;
272 Double_t vz = 0.;
273 Double_t tof = 0.;
274
275 // Energy (in GeV)
276 Double_t kinEnergy = 5;
277 Double_t mass = particle->Mass();
278 Double_t e = mass + kinEnergy;
279
280 // Particle momentum
281 Double_t px, py, pz;
282 px = sqrt(e * e - mass * mass);
283 py = 0.;
284 pz = 0.;
285
286 // Randomize position
287 if (fIsRandom) {
288 vy = origin.Y() * (gRandom->Rndm() - 0.5);
289 vz = origin.Z() * (gRandom->Rndm() - 0.5);
290 }
291
292 // Add particle to stack
293 fStack->PushTrack(toBeDone, -1, pdg, px, py, pz, e, vx, vy, vz, tof, polx,
294 poly, polz, kPPrimary, ntr, 1., 0);
295
296 // anti_triton
297 particle = TDatabasePDG::Instance()->GetParticle("AntiTriton");
298 pdg = particle->PdgCode();
299 mass = particle->Mass();
300 e = mass + kinEnergy;
301
302 px = sqrt(e * e - mass * mass);
303 py = 0.;
304 pz = 0.;
305
306 fStack->PushTrack(toBeDone, -1, pdg, px, py, pz, e, vx, vy, vz, tof, polx,
307 poly, polz, kPPrimary, ntr, 1., 0);
308
309 // anti_alpha
310 particle = TDatabasePDG::Instance()->GetParticle("AntiAlpha");
311 pdg = particle->PdgCode();
312 mass = particle->Mass();
313 e = mass + kinEnergy;
314
315 px = sqrt(e * e - mass * mass);
316 py = 0.;
317 pz = 0.;
318
319 fStack->PushTrack(toBeDone, -1, pdg, px, py, pz, e, vx, vy, vz, tof, polx,
320 poly, polz, kPPrimary, ntr, 1., 0);
321
322 // anti_He3
323 particle = TDatabasePDG::Instance()->GetParticle("AntiHE3");
324 pdg = particle->PdgCode();
325 mass = particle->Mass();
326 e = mass + kinEnergy;
327
328 px = sqrt(e * e - mass * mass);
329 py = 0.;
330 pz = 0.;
331
332 fStack->PushTrack(toBeDone, -1, pdg, px, py, pz, e, vx, vy, vz, tof, polx,
333 poly, polz, kPPrimary, ntr, 1., 0);
334}
335
336//_____________________________________________________________________________
337void Ex03PrimaryGenerator::GeneratePrimary5(const TVector3& origin)
338{
339 /// Add one primary particle (kMuonPlus) to the user stack
340
341 // Track ID (filled by stack)
342 Int_t ntr;
343
344 // Option: to be tracked
345 Int_t toBeDone = 1;
346
347 // PDG
348 Int_t pdg = kMuonPlus;
349
350 // Polarization
351 Double_t polx = 0.;
352 Double_t poly = 0.;
353 Double_t polz = 0.;
354
355 // Position
356 Double_t vx = -0.5 * origin.X();
357 Double_t vy = 0.;
358 Double_t vz = 0.;
359 Double_t tof = 0.;
360
361 // Energy (in GeV)
362 Double_t kinEnergy = 0.1;
363 Double_t mass = 0.1056583715;
364 Double_t e = mass + kinEnergy;
365
366 // Particle momentum
367 Double_t px, py, pz;
368 px = sqrt(e * e - mass * mass);
369 py = 0.;
370 pz = 0.;
371
372 // Randomize position
373 if (fIsRandom) {
374 vy = origin.Y() * (gRandom->Rndm() - 0.5);
375 vz = origin.Z() * (gRandom->Rndm() - 0.5);
376 }
377
378 // Add particle to stack
379 fStack->PushTrack(toBeDone, -1, pdg, px, py, pz, e, vx, vy, vz, tof, polx,
380 poly, polz, kPPrimary, ntr, 1., 0);
381}
382
383//_____________________________________________________________________________
384void Ex03PrimaryGenerator::GeneratePrimary6(const TVector3& origin)
385{
386 /// Add one primary particle (kPiMinus) to the user stack
387
388 // Track ID (filled by stack)
389 Int_t ntr;
390
391 // Option: to be tracked
392 Int_t toBeDone = 1;
393
394 // PDG
395 Int_t pdg = kPiMinus;
396
397 // Polarization
398 Double_t polx = 0.;
399 Double_t poly = 0.;
400 Double_t polz = 0.;
401
402 // Position
403 Double_t vx = -0.5 * origin.X();
404 Double_t vy = 0.;
405 Double_t vz = 0.;
406 Double_t tof = 0.;
407
408 // Energy (in GeV)
409 Double_t kinEnergy = 0.1;
410 Double_t mass = 0.1395701;
411 Double_t e = mass + kinEnergy;
412
413 // Particle momentum
414 Double_t px, py, pz;
415 px = sqrt(e * e - mass * mass);
416 py = 0.;
417 pz = 0.;
418
419 // Randomize position
420 if (fIsRandom) {
421 vy = origin.Y() * (gRandom->Rndm() - 0.5);
422 vz = origin.Z() * (gRandom->Rndm() - 0.5);
423 }
424
425 // Add particle to stack
426 fStack->PushTrack(toBeDone, -1, pdg, px, py, pz, e, vx, vy, vz, tof, polx,
427 poly, polz, kPPrimary, ntr, 1., 0);
428}
429
430//
431// public methods
432//
433
434//_____________________________________________________________________________
435void Ex03PrimaryGenerator::GeneratePrimaries(const TVector3& origin)
436{
437 /// Fill the user stack (derived from TVirtualMCStack) with primary particles.
438
439 switch (fPrimaryType) {
440
441 case kDefault:
442 for (Int_t i = 0; i < fNofPrimaries; i++) GeneratePrimary1(origin);
443 return;
444
445 case kUser:
446 if (fNofPrimaries < 2) fNofPrimaries = 2;
447 for (Int_t i = 0; i < fNofPrimaries / 2; i++) GeneratePrimary2(origin);
448 return;
449
450 case kUserDecay:
451 for (Int_t i = 0; i < fNofPrimaries; i++) GeneratePrimary3(origin);
452 return;
453
454 case kAnti:
455 if (fNofPrimaries < 4) fNofPrimaries = 4;
456 for (Int_t i = 0; i < fNofPrimaries / 4; i++) GeneratePrimary4(origin);
457 return;
458
459 case kTestField:
460 for (Int_t i = 0; i < fNofPrimaries; i++) GeneratePrimary5(origin);
461 return;
462
463 case kPion:
464 for (Int_t i = 0; i < fNofPrimaries; i++) GeneratePrimary6(origin);
465 return;
466
467 default:
468 return;
469 }
470}
The primary generator.
void GeneratePrimary1(const TVector3 &origin)
virtual void GeneratePrimaries(const TVector3 &worldSize)
void GeneratePrimary3(const TVector3 &origin)
TVirtualMCStack * fStack
VMC stack.
void GeneratePrimary2(const TVector3 &origin)
void GeneratePrimary6(const TVector3 &origin)
void GeneratePrimary5(const TVector3 &origin)
Int_t fNofPrimaries
Number of primary particles.
void GeneratePrimary4(const TVector3 &origin)
@ kTestField
mu+ with a suitable energy to test magnetic field
@ kUserDecay
particle with user defined decay (K0Short)
@ kUser
user defined particle and ion
@ kAnti
light anti-nuclei (with Geant4 only)
@ kPion
pi- ith a suitable energy to test biasing
Type fPrimaryType
Primary generator selection.
Bool_t fIsRandom
Switch to random generator.