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