]>
Commit | Line | Data |
---|---|---|
17929791 | 1 | // $Id$ |
2 | // Category: physics | |
3 | // | |
499b353a | 4 | // Author: I. Hrivnacova |
5 | // | |
6 | // Class TG4ParticlesManager | |
7 | // ------------------------- | |
17929791 | 8 | // See the class description in the header file. |
9 | ||
10 | #include "TG4ParticlesManager.h" | |
11 | #include "TG4G3Units.h" | |
12 | ||
13 | #include <G4ParticleDefinition.hh> | |
14 | #include <G4DynamicParticle.hh> | |
15 | #include <G4ParticleTable.hh> | |
16 | ||
17 | #include <TDatabasePDG.h> | |
18 | #include <TParticle.h> | |
19 | #include <TClonesArray.h> | |
20 | ||
21 | TG4ParticlesManager* TG4ParticlesManager::fgInstance = 0; | |
22 | ||
72095f7c | 23 | //_____________________________________________________________________________ |
17929791 | 24 | TG4ParticlesManager::TG4ParticlesManager() |
5b6ecd36 | 25 | : TG4Verbose("particlesMananger") { |
17929791 | 26 | // |
27 | if (fgInstance) { | |
28 | TG4Globals::Exception( | |
29 | "TG4ParticlesManager: attempt to create two instances of singleton."); | |
30 | } | |
31 | ||
32 | fgInstance = this; | |
33 | } | |
34 | ||
72095f7c | 35 | //_____________________________________________________________________________ |
5b6ecd36 | 36 | TG4ParticlesManager::TG4ParticlesManager(const TG4ParticlesManager& right) |
37 | : TG4Verbose("particlesMananger") { | |
17929791 | 38 | // |
39 | TG4Globals::Exception( | |
40 | "Attempt to copy TG4ParticlesManager singleton."); | |
41 | } | |
42 | ||
72095f7c | 43 | //_____________________________________________________________________________ |
17929791 | 44 | TG4ParticlesManager::~TG4ParticlesManager() { |
45 | // | |
46 | } | |
47 | ||
48 | // operators | |
49 | ||
50 | TG4ParticlesManager& | |
51 | TG4ParticlesManager::operator=(const TG4ParticlesManager& right) | |
52 | { | |
53 | // check assignement to self | |
54 | if (this == &right) return *this; | |
55 | ||
56 | TG4Globals::Exception( | |
57 | "Attempt to assign TG4ParticlesManager singleton."); | |
58 | ||
59 | return *this; | |
60 | } | |
61 | ||
62 | // private methods | |
63 | ||
72095f7c | 64 | |
65 | //_____________________________________________________________________________ | |
17929791 | 66 | G4int TG4ParticlesManager::GetPDGEncoding(G4ParticleDefinition* particle) |
67 | { | |
68 | // Returns the PDG code of particle; | |
69 | // if standard PDG code is not defined the TDatabasePDG | |
70 | // is used. | |
71 | // --- | |
72 | ||
73 | // get PDG encoding from G4 particle definition | |
74 | G4int pdgEncoding = particle->GetPDGEncoding(); | |
75 | ||
76 | if (pdgEncoding == 0) { | |
77 | // get PDG encoding from TDatabasePDG | |
78 | ||
79 | // get particle name from the name map | |
80 | G4String g4name = particle->GetParticleName(); | |
81 | G4String tname = fParticleNameMap.GetSecond(g4name); | |
82 | if (tname == "Undefined") { | |
83 | G4String text = "TG4ParticlesManager::GetPDGEncoding: \n"; | |
84 | text = text + " Particle " + g4name; | |
85 | text = text + " was not found in the name map."; | |
86 | TG4Globals::Exception(text); | |
87 | } | |
88 | ||
89 | // get particle from TDatabasePDG | |
90 | TDatabasePDG* pdgDB = TDatabasePDG::Instance(); | |
91 | TParticlePDG* particle = pdgDB->GetParticle(tname); | |
92 | if (!particle) { | |
93 | G4String text = "TG4ParticlesManager::GetPDGEncoding: \n"; | |
94 | text = text + " Particle " + tname; | |
95 | text = text + " was not found in TDatabasePDG."; | |
96 | TG4Globals::Exception(text); | |
97 | } | |
98 | ||
99 | // get PDG encoding | |
100 | pdgEncoding = particle->PdgCode(); | |
101 | } | |
102 | ||
103 | return pdgEncoding; | |
104 | } | |
105 | ||
72095f7c | 106 | |
107 | //_____________________________________________________________________________ | |
17929791 | 108 | G4int TG4ParticlesManager::GetPDGEncoding(G4String particleName) |
109 | { | |
110 | // Returns the PDG code of particle sepcified by name. | |
111 | // --- | |
112 | ||
113 | G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable(); | |
114 | ||
115 | G4ParticleDefinition* particle = 0; | |
116 | particle = particleTable->FindParticle(particleName); | |
117 | if (!particle) { | |
118 | G4String text = "TG4ParticlesManager::GetPDGEncoding:\n"; | |
119 | text = text + " G4ParticleTable::FindParticle() " + particleName; | |
120 | text = text + " failed."; | |
121 | TG4Globals::Exception(text); | |
122 | } | |
123 | ||
124 | return GetPDGEncoding(particle); | |
125 | } | |
126 | ||
72095f7c | 127 | |
128 | //_____________________________________________________________________________ | |
17929791 | 129 | void TG4ParticlesManager::MapParticles() |
130 | { | |
131 | // map G4 particle names to TDatabasePDG names | |
132 | // (the map is built only for particles that have not | |
133 | // defined standard PDG encoding) | |
134 | ||
135 | fParticleNameMap.Add("deuteron","Deuteron"); | |
136 | fParticleNameMap.Add("triton", "Triton"); | |
137 | fParticleNameMap.Add("alpha", "Alpha"); | |
138 | fParticleNameMap.Add("He3", "HE3"); | |
139 | fParticleNameMap.Add("opticalphoton","Cherenkov"); | |
140 | // fParticleNameMap.Add("???","FeedbackPhoton"); | |
141 | fParticleNameMap.Add("geantino", "Rootino"); | |
5e690f3c | 142 | fParticleNameMap.Add("chargedgeantino", "Rootino"); |
17929791 | 143 | |
144 | // map G4 particle names to TDatabasePDG encodings | |
145 | fParticlePDGMap.Add("deuteron", GetPDGEncoding("deuteron")); | |
146 | fParticlePDGMap.Add("triton", GetPDGEncoding("triton")); | |
147 | fParticlePDGMap.Add("alpha", GetPDGEncoding("alpha")); | |
148 | fParticlePDGMap.Add("He3", GetPDGEncoding("He3") ); | |
149 | fParticlePDGMap.Add("opticalphoton", GetPDGEncoding("opticalphoton")); | |
150 | // fParticlePDGMap.Add("???","FeedbackPhoton"); | |
bcb189b7 | 151 | fParticlePDGMap.Add("geantino", GetPDGEncoding("geantino")); |
5e690f3c | 152 | fParticlePDGMap.Add("chargedgeantino", GetPDGEncoding("chargedgeantino")); |
17929791 | 153 | |
154 | // add verbose | |
5b6ecd36 | 155 | if (VerboseLevel() > 0) { |
156 | G4cout << "Particle maps have been filled." << G4endl; | |
157 | } | |
158 | if (VerboseLevel() > 1) { | |
159 | fParticleNameMap.PrintAll(); | |
160 | fParticlePDGMap.PrintAll(); | |
161 | } | |
17929791 | 162 | } |
163 | ||
164 | // public methods | |
165 | ||
5e690f3c | 166 | //_____________________________________________________________________________ |
17929791 | 167 | G4int TG4ParticlesManager::GetPDGEncodingFast(G4ParticleDefinition* particle) |
168 | { | |
169 | // Returns the PDG code of particle; | |
170 | // if standard PDG code is not defined the preregistred | |
171 | // fParticlePDGMap is used. | |
172 | // --- | |
173 | ||
174 | // get PDG encoding from G4 particle definition | |
175 | G4int pdgEncoding = particle->GetPDGEncoding(); | |
176 | ||
5e690f3c | 177 | // use fParticlePDGMap if standard/ENDF-6 PDG code is not defined |
17929791 | 178 | if (pdgEncoding == 0) { |
5e690f3c | 179 | G4String name = particle->GetParticleName(); |
180 | pdgEncoding = fParticlePDGMap.GetSecond(name, false); | |
17929791 | 181 | } |
5e690f3c | 182 | |
183 | // if a nucleus - add it to PDG table | |
184 | if (pdgEncoding == 0 && particle->GetParticleType() == "nucleus") { | |
185 | ||
186 | // use ENDF-6 mapping 10000*z+10*a+iso + 10000000 for nuclei | |
187 | G4int a = particle->GetBaryonNumber(); | |
188 | G4int z = G4int(particle->GetPDGCharge()/eplus); | |
189 | pdgEncoding = 10000000 + 10000*z + 10*a; | |
190 | ||
191 | // add nucleus to PDG database | |
192 | TDatabasePDG::Instance() | |
193 | ->AddParticle(particle->GetParticleName(), particle->GetParticleName(), | |
194 | particle->GetPDGMass(), particle->GetPDGStable(), particle->GetPDGWidth(), | |
195 | z, "Ion", pdgEncoding); | |
196 | ||
197 | // add nucleus to PDG map | |
198 | fParticlePDGMap.Add(particle->GetParticleName(), pdgEncoding); | |
199 | } | |
200 | ||
201 | if (pdgEncoding == 0 && | |
202 | particle->GetParticleName() != "geantino" && | |
203 | particle->GetParticleName() != "chargedgeantino" ) { | |
204 | // unknown particle | |
205 | G4String text = "TG4ParticlesManager::GetPDGEncodingFast: "; | |
206 | text = text + particle->GetParticleName() + " is not defined."; | |
207 | TG4Globals::Warning(text); | |
208 | } | |
209 | ||
17929791 | 210 | return pdgEncoding; |
211 | } | |
212 | ||
72095f7c | 213 | |
214 | //_____________________________________________________________________________ | |
17929791 | 215 | TParticle* TG4ParticlesManager::GetParticle(const TClonesArray* particles, |
499b353a | 216 | G4int index) const |
17929791 | 217 | { |
218 | // Retrives particle with given index from TClonesArray | |
219 | // and checks type. | |
220 | // --- | |
221 | ||
499b353a | 222 | #ifdef TGEANT4_DEBUG |
17929791 | 223 | TObject* particleTObject = particles->UncheckedAt(index); |
224 | TParticle* particle | |
225 | = dynamic_cast<TParticle*>(particleTObject); | |
226 | ||
227 | // check particle type | |
228 | if (!particle) | |
229 | TG4Globals::Exception( | |
230 | "TG4ParticlesManager::GetParticle: Unknown particle type"); | |
499b353a | 231 | #else |
232 | return (TParticle*)particles->UncheckedAt(index); | |
233 | #endif | |
17929791 | 234 | } |
235 | ||
236 | ||
72095f7c | 237 | //_____________________________________________________________________________ |
17929791 | 238 | G4ParticleDefinition* TG4ParticlesManager::GetParticleDefinition( |
239 | const TParticle* particle) const | |
240 | { | |
241 | // Returns G4 particle definition for given TParticle | |
242 | // TO DO: replace with using particles name map | |
243 | // --- | |
244 | ||
245 | // get particle definition from G4ParticleTable | |
246 | G4int pdgEncoding = particle->GetPdgCode(); | |
247 | G4ParticleTable* particleTable | |
248 | = G4ParticleTable::GetParticleTable(); | |
249 | G4ParticleDefinition* particleDefinition = 0; | |
250 | if (pdgEncoding != 0) | |
251 | particleDefinition = particleTable->FindParticle(pdgEncoding); | |
252 | else { | |
253 | G4String name = particle->GetName(); | |
254 | if (name == "Rootino") | |
255 | particleDefinition = particleTable->FindParticle("geantino"); | |
256 | } | |
257 | ||
258 | if (particleDefinition==0) { | |
259 | G4cout << "pdgEncoding: " << pdgEncoding << G4endl; | |
260 | G4String text = | |
261 | "TG4ParticlesManager::GetParticleDefinition:\n"; | |
262 | text = text + " G4ParticleTable::FindParticle() failed."; | |
263 | TG4Globals::Warning(text); | |
264 | } | |
265 | ||
266 | return particleDefinition; | |
267 | } | |
268 | ||
72095f7c | 269 | |
270 | //_____________________________________________________________________________ | |
17929791 | 271 | G4DynamicParticle* TG4ParticlesManager::CreateDynamicParticle( |
272 | const TParticle* particle) const | |
273 | { | |
274 | // Creates G4DynamicParticle. | |
275 | // --- | |
276 | ||
277 | // get particle properties | |
278 | G4ParticleDefinition* particleDefinition | |
279 | = GetParticleDefinition(particle); | |
280 | if (!particleDefinition) return 0; | |
281 | ||
282 | G4ThreeVector momentum = GetParticleMomentum(particle); | |
283 | ||
284 | // create G4DynamicParticle | |
285 | G4DynamicParticle* dynamicParticle | |
286 | = new G4DynamicParticle(particleDefinition, momentum); | |
287 | ||
288 | return dynamicParticle; | |
289 | } | |
290 | ||
72095f7c | 291 | |
292 | //_____________________________________________________________________________ | |
17929791 | 293 | G4ThreeVector TG4ParticlesManager::GetParticlePosition( |
294 | const TParticle* particle) const | |
295 | { | |
296 | // Returns particle vertex position. | |
297 | // --- | |
298 | ||
299 | G4ThreeVector position | |
300 | = G4ThreeVector(particle->Vx()*TG4G3Units::Length(), | |
301 | particle->Vy()*TG4G3Units::Length(), | |
302 | particle->Vz()*TG4G3Units::Length()); | |
303 | return position; | |
304 | } | |
305 | ||
306 | ||
72095f7c | 307 | //_____________________________________________________________________________ |
17929791 | 308 | G4ThreeVector TG4ParticlesManager::GetParticleMomentum( |
309 | const TParticle* particle) const | |
310 | { | |
311 | // Returns particle momentum. | |
312 | // --- | |
313 | G4ThreeVector momentum | |
314 | = G4ThreeVector(particle->Px()*TG4G3Units::Energy(), | |
315 | particle->Py()*TG4G3Units::Energy(), | |
316 | particle->Pz()*TG4G3Units::Energy()); | |
317 | return momentum; | |
318 | } | |
319 |