]>
Commit | Line | Data |
---|---|---|
1 | // $Id$ | |
2 | // Category: event | |
3 | // | |
4 | // Author: I. Hrivnacova | |
5 | // | |
6 | // Class AliParticleGun | |
7 | // -------------------- | |
8 | // See the class description in the header file. | |
9 | ||
10 | #include "AliParticleGun.h" | |
11 | #include "AliParticleGunMessenger.h" | |
12 | #include "AliGunParticle.h" | |
13 | #include "AliGlobals.h" | |
14 | ||
15 | #include <G4ParticleDefinition.hh> | |
16 | #include <G4PrimaryParticle.hh> | |
17 | #include <G4PrimaryVertex.hh> | |
18 | #include <G4Event.hh> | |
19 | ||
20 | //_____________________________________________________________________________ | |
21 | AliParticleGun::AliParticleGun() | |
22 | : AliVerbose("particleGun"), | |
23 | fMessenger(this) { | |
24 | // | |
25 | } | |
26 | ||
27 | //_____________________________________________________________________________ | |
28 | AliParticleGun::AliParticleGun(const AliParticleGun& right) | |
29 | : AliVerbose("particleGun"), | |
30 | G4VPrimaryGenerator(right), | |
31 | fMessenger(this) | |
32 | { | |
33 | // copy stuff | |
34 | *this = right; | |
35 | } | |
36 | ||
37 | //_____________________________________________________________________________ | |
38 | AliParticleGun::~AliParticleGun() { | |
39 | // | |
40 | // delete gun particles | |
41 | Reset(); | |
42 | } | |
43 | ||
44 | // operators | |
45 | ||
46 | //_____________________________________________________________________________ | |
47 | AliParticleGun& AliParticleGun::operator=(const AliParticleGun& right) | |
48 | { | |
49 | // check assignement to self | |
50 | if (this == &right) return *this; | |
51 | ||
52 | // base class assignment | |
53 | this->G4VPrimaryGenerator::operator=(right); | |
54 | ||
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)); | |
63 | ||
64 | return *this; | |
65 | } | |
66 | ||
67 | // public methods | |
68 | ||
69 | //_____________________________________________________________________________ | |
70 | void AliParticleGun::AddParticle(AliGunParticle* particle) | |
71 | { | |
72 | // Adds particle. | |
73 | // --- | |
74 | ||
75 | fGunParticleVector.push_back(particle); | |
76 | } | |
77 | ||
78 | //_____________________________________________________________________________ | |
79 | void AliParticleGun::RemoveParticle(G4int iParticle) | |
80 | { | |
81 | // Removes particle. | |
82 | // --- | |
83 | ||
84 | GunParticleIterator it = fGunParticleVector.begin(); | |
85 | it += iParticle; | |
86 | //advance(it,iParticle); | |
87 | ||
88 | delete *it; | |
89 | fGunParticleVector.erase(it); | |
90 | } | |
91 | ||
92 | //_____________________________________________________________________________ | |
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 | ||
102 | GunParticleIterator it; | |
103 | for (it = fGunParticleVector.begin(); it != fGunParticleVector.end(); it++) { | |
104 | ||
105 | AliGunParticle* particle = *it; | |
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; | |
117 | if (it == fGunParticleVector.begin() || | |
118 | position != previousPosition || time != previousTime ) { | |
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 | ||
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 | } | |
159 | ||
160 | // delete gun particles | |
161 | Reset(); | |
162 | } | |
163 | ||
164 | //_____________________________________________________________________________ | |
165 | void AliParticleGun::Reset() | |
166 | { | |
167 | // Resets the particle gun. | |
168 | // --- | |
169 | ||
170 | GunParticleIterator it; | |
171 | for (it = fGunParticleVector.begin(); it != fGunParticleVector.end(); it++) | |
172 | delete *it; | |
173 | ||
174 | fGunParticleVector.clear(); | |
175 | } | |
176 | ||
177 | //_____________________________________________________________________________ | |
178 | void AliParticleGun::List() | |
179 | { | |
180 | // Lists the particle gun. | |
181 | // --- | |
182 | ||
183 | G4cout << "Particle Gun: " << G4endl; | |
184 | ||
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; | |
194 | G4cout << "============================" << G4endl; | |
195 | (*it)->Print(); | |
196 | } | |
197 | } | |
198 | } | |
199 |