]>
Commit | Line | Data |
---|---|---|
676fb573 | 1 | // $Id$ |
2 | // Category: event | |
3 | // | |
ad42298e | 4 | // Author: I. Hrivnacova |
5 | // | |
6 | // Class AliParticleGun | |
7 | // -------------------- | |
676fb573 | 8 | // See the class description in the header file. |
9 | ||
10 | #include "AliParticleGun.h" | |
11 | #include "AliParticleGunMessenger.h" | |
c97337f9 | 12 | #include "AliGunParticle.h" |
676fb573 | 13 | #include "AliGlobals.h" |
14 | ||
c97337f9 | 15 | #include <G4ParticleDefinition.hh> |
676fb573 | 16 | #include <G4PrimaryParticle.hh> |
c97337f9 | 17 | #include <G4PrimaryVertex.hh> |
676fb573 | 18 | #include <G4Event.hh> |
676fb573 | 19 | |
78ca1e9c | 20 | //_____________________________________________________________________________ |
ad42298e | 21 | AliParticleGun::AliParticleGun() |
e980662a | 22 | : AliVerbose("particleGun"), |
23 | fMessenger(this) { | |
676fb573 | 24 | // |
676fb573 | 25 | } |
26 | ||
78ca1e9c | 27 | //_____________________________________________________________________________ |
676fb573 | 28 | AliParticleGun::AliParticleGun(const AliParticleGun& right) |
e980662a | 29 | : AliVerbose("particleGun"), |
30 | G4VPrimaryGenerator(right), | |
ad42298e | 31 | fMessenger(this) |
676fb573 | 32 | { |
58c0119e | 33 | // copy stuff |
34 | *this = right; | |
676fb573 | 35 | } |
36 | ||
78ca1e9c | 37 | //_____________________________________________________________________________ |
676fb573 | 38 | AliParticleGun::~AliParticleGun() { |
39 | // | |
ad42298e | 40 | // delete gun particles |
41 | Reset(); | |
676fb573 | 42 | } |
43 | ||
44 | // operators | |
45 | ||
78ca1e9c | 46 | //_____________________________________________________________________________ |
676fb573 | 47 | AliParticleGun& AliParticleGun::operator=(const AliParticleGun& right) |
48 | { | |
49 | // check assignement to self | |
50 | if (this == &right) return *this; | |
51 | ||
58c0119e | 52 | // base class assignment |
53 | this->G4VPrimaryGenerator::operator=(right); | |
54 | ||
ad42298e | 55 | // delete gun particles |
56 | Reset(); | |
57 | ||
58 | // copy gun particles | |
59 | GunParticleConstIterator it; | |
60 | for (it = (right.fGunParticleVector).begin(); | |
61 | it != (right.fGunParticleVector).end(); it++) | |
62 | fGunParticleVector.push_back(new AliGunParticle(**it)); | |
58c0119e | 63 | |
676fb573 | 64 | return *this; |
65 | } | |
66 | ||
67 | // public methods | |
68 | ||
78ca1e9c | 69 | //_____________________________________________________________________________ |
676fb573 | 70 | void AliParticleGun::AddParticle(AliGunParticle* particle) |
71 | { | |
72 | // Adds particle. | |
73 | // --- | |
74 | ||
ad42298e | 75 | fGunParticleVector.push_back(particle); |
676fb573 | 76 | } |
77 | ||
78ca1e9c | 78 | //_____________________________________________________________________________ |
676fb573 | 79 | void AliParticleGun::RemoveParticle(G4int iParticle) |
80 | { | |
81 | // Removes particle. | |
82 | // --- | |
83 | ||
ad42298e | 84 | GunParticleIterator it = fGunParticleVector.begin(); |
85 | it += iParticle; | |
86 | //advance(it,iParticle); | |
87 | ||
88 | delete *it; | |
89 | fGunParticleVector.erase(it); | |
676fb573 | 90 | } |
91 | ||
78ca1e9c | 92 | //_____________________________________________________________________________ |
676fb573 | 93 | void AliParticleGun::GeneratePrimaryVertex(G4Event* event) |
94 | { | |
95 | // Generates primary vertices. | |
96 | // --- | |
97 | ||
98 | G4PrimaryVertex* previousVertex = 0; | |
99 | G4ThreeVector previousPosition = G4ThreeVector(); | |
100 | G4double previousTime = 0.; | |
101 | ||
ad42298e | 102 | GunParticleIterator it; |
103 | for (it = fGunParticleVector.begin(); it != fGunParticleVector.end(); it++) { | |
104 | ||
105 | AliGunParticle* particle = *it; | |
676fb573 | 106 | |
107 | G4ParticleDefinition* particleDefinition | |
108 | = particle->GetParticleDefinition(); | |
109 | if (particleDefinition==0) { | |
110 | AliGlobals::Exception( | |
111 | "AliParticleGun::GeneratePrimaryVertex: Unknown particle definition."); | |
112 | } | |
113 | ||
114 | G4ThreeVector position = particle->GetPosition(); | |
115 | G4double time = particle->GetTime(); | |
116 | G4PrimaryVertex* vertex; | |
ad42298e | 117 | if (it == fGunParticleVector.begin() || |
118 | position != previousPosition || time != previousTime ) { | |
676fb573 | 119 | // create a new vertex |
120 | // in case position and time of gun particle are different from | |
121 | // previous values | |
122 | // (vertex objects are destroyed in G4EventManager::ProcessOneEvent() | |
123 | // when event is deleted) | |
124 | vertex = new G4PrimaryVertex(position, time); | |
125 | event->AddPrimaryVertex(vertex); | |
126 | ||
127 | previousVertex = vertex; | |
128 | previousPosition = position; | |
129 | previousTime = time; | |
130 | } | |
131 | else | |
132 | vertex = previousVertex; | |
133 | ||
134 | // create a primary particle and add it to the vertex | |
135 | // (primaryParticle objects are destroyed in G4EventManager::ProcessOneEvent() | |
136 | // when event and then vertex is deleted) | |
137 | G4double px = particle->GetMomentum().x(); | |
138 | G4double py = particle->GetMomentum().y(); | |
139 | G4double pz = particle->GetMomentum().z(); | |
140 | G4PrimaryParticle* primaryParticle | |
141 | = new G4PrimaryParticle(particleDefinition, px, py, pz); | |
142 | ||
143 | G4double mass = particleDefinition->GetPDGMass(); | |
144 | primaryParticle->SetMass(mass); | |
145 | primaryParticle->SetPolarization(particle->GetPolarization().x(), | |
146 | particle->GetPolarization().y(), | |
147 | particle->GetPolarization().z()); | |
148 | ||
149 | vertex->SetPrimary(primaryParticle); | |
150 | } | |
151 | ||
e980662a | 152 | if (VerboseLevel() > 0) { |
153 | G4cout << "AliParticleGun::GeneratePrimaryVertex:" << G4endl; | |
154 | G4cout << " " | |
155 | << event->GetNumberOfPrimaryVertex() << " of primary vertices," | |
156 | << " " << fGunParticleVector.size() << " of primary particles " | |
157 | << G4endl; | |
158 | } | |
ad42298e | 159 | |
160 | // delete gun particles | |
161 | Reset(); | |
676fb573 | 162 | } |
163 | ||
78ca1e9c | 164 | //_____________________________________________________________________________ |
676fb573 | 165 | void AliParticleGun::Reset() |
166 | { | |
167 | // Resets the particle gun. | |
168 | // --- | |
169 | ||
ad42298e | 170 | GunParticleIterator it; |
171 | for (it = fGunParticleVector.begin(); it != fGunParticleVector.end(); it++) | |
172 | delete *it; | |
173 | ||
174 | fGunParticleVector.clear(); | |
676fb573 | 175 | } |
176 | ||
78ca1e9c | 177 | //_____________________________________________________________________________ |
676fb573 | 178 | void AliParticleGun::List() |
179 | { | |
180 | // Lists the particle gun. | |
181 | // --- | |
182 | ||
5f1d09c5 | 183 | G4cout << "Particle Gun: " << G4endl; |
676fb573 | 184 | |
ad42298e | 185 | if (fGunParticleVector.size() == 0) |
186 | G4cout << " No particles are defined." << G4endl; | |
187 | else { | |
188 | G4int i = 0; | |
189 | GunParticleIterator it; | |
190 | for (it = fGunParticleVector.begin(); | |
191 | it != fGunParticleVector.end(); it++) { | |
192 | ||
193 | G4cout << i++ << " th particle properties: " << G4endl; | |
5f1d09c5 | 194 | G4cout << "============================" << G4endl; |
ad42298e | 195 | (*it)->Print(); |
676fb573 | 196 | } |
197 | } | |
198 | } | |
199 |