VMC Examples Version 6.6
Loading...
Searching...
No Matches
PrimaryGenerator.cxx
Go to the documentation of this file.
1//------------------------------------------------
2// The Virtual Monte Carlo examples
3// Copyright (C) 2007 - 2016 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 ExGarfield/src/PrimaryGenerator.cxx
11/// \brief Implementation of the ExGarfield::PrimaryGenerator class
12///
13/// Garfield garfieldpp example adapted to Virtual Monte Carlo.
14///
15/// \date 28/10/2015
16/// \author I. Hrivnacova; IPN, Orsay
17
18#include <TDatabasePDG.h>
19#include <TPDGCode.h>
20#include <TParticlePDG.h>
21#include <TRandom.h>
22#include <TVector3.h>
23#include <TVirtualMC.h>
24#include <TVirtualMCApplication.h>
25#include <TVirtualMCStack.h>
26
27#include "PrimaryGenerator.h"
28
29/// \cond CLASSIMP
31 /// \endcond
32
33 namespace VMC
34{
35 namespace ExGarfield
36 {
37
38 //_____________________________________________________________________________
40 : TObject(),
41 fStack(stack),
42 fNofPrimaries(1),
43 fVertexPosition(),
44 fVertexDirection(TVector3(0, 0, 1))
45 {
46 /// Standard constructor
47 /// \param stack The VMC stack
48 }
49
50 //_____________________________________________________________________________
52 const PrimaryGenerator& origin, TVirtualMCStack* stack)
53 : TObject(origin),
54 fStack(stack),
55 fNofPrimaries(origin.fNofPrimaries),
56 fVertexPosition(origin.fVertexPosition),
57 fVertexDirection(origin.fVertexDirection)
58 {
59 /// Copy constructor (for clonig on worker thread in MT mode).
60 /// \param origin The source object (on master).
61 /// \param stack The VMC stack
62 }
63
64 //_____________________________________________________________________________
66 : TObject(),
67 fStack(0),
68 fNofPrimaries(0),
69 fVertexPosition(),
70 fVertexDirection()
71 {
72 /// Default constructor
73 }
74
75 //_____________________________________________________________________________
77 {
78 /// Destructor
79 }
80
81 //
82 // private methods
83 //
84
85 //_____________________________________________________________________________
86 void PrimaryGenerator::GenerateOnePrimary(const TVector3& origin)
87 {
88 /// Add one primary particle (kElectron) to the user stack
89 /// (derived from TVirtualMCStack).
90 /// \param origin The track position
91
92 // Track ID (filled by stack)
93 Int_t ntr;
94
95 // Option: to be tracked
96 Int_t toBeDone = 1;
97
98 // PDG
99 Int_t pdg = kMuonPlus;
100
101 // Polarization
102 Double_t polx = 0.;
103 Double_t poly = 0.;
104 Double_t polz = 0.;
105
106 // Position
107 Double_t vx = origin.X();
108 Double_t vy = origin.Y();
109 Double_t vz = origin.Z();
110 Double_t tof = 0.;
111 fVertexPosition = origin;
112
113 // Energy (in GeV)
114 Double_t kinEnergy = 4.;
115 Double_t mass = 0.1056583715;
116 Double_t e = mass + kinEnergy;
117 Double_t pmag = sqrt(e * e - mass * mass);
118
119 // Particle momentum
120 Double_t px, py, pz;
121 px = pmag * fVertexDirection.X();
122 py = pmag * fVertexDirection.Y();
123 pz = pmag * fVertexDirection.Z();
124
125 // Randomize position
126 // if (fIsRandom) {
127 // vy = origin.Y()*(gRandom->Rndm() - 0.5);
128 // vz = origin.Z()*(gRandom->Rndm() - 0.5);
129 // }
130
131 // Add particle to stack
132 fStack->PushTrack(toBeDone, -1, pdg, px, py, pz, e, vx, vy, vz, tof, polx,
133 poly, polz, kPPrimary, ntr, 1., 0);
134 }
135
136 //
137 // public methods
138 //
139
140 //_____________________________________________________________________________
141 void PrimaryGenerator::GeneratePrimaries(const TVector3& origin)
142 {
143 /// Fill the user stack (derived from TVirtualMCStack) with primary
144 /// particles.
145
146 for (Int_t i = 0; i < fNofPrimaries; i++) GenerateOnePrimary(origin);
147 }
148
149 } // namespace ExGarfield
150}
void GenerateOnePrimary(const TVector3 &origin)
virtual void GeneratePrimaries(const TVector3 &worldSize)
TVirtualMCStack * fStack
VMC stack.
TVector3 fVertexPosition
Vertex position.
Int_t fNofPrimaries
Number of primary particles.
TVector3 fVertexDirection
Vertex direction.