]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TGeant4/TG4ParticlesManager.cxx
fgkDefaultMaxStep changed to DBL_MAX
[u/mrichter/AliRoot.git] / TGeant4 / TG4ParticlesManager.cxx
CommitLineData
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
21TG4ParticlesManager* TG4ParticlesManager::fgInstance = 0;
22
72095f7c 23//_____________________________________________________________________________
17929791 24TG4ParticlesManager::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 36TG4ParticlesManager::TG4ParticlesManager(const TG4ParticlesManager& right)
37 : TG4Verbose("particlesMananger") {
17929791 38//
39 TG4Globals::Exception(
40 "Attempt to copy TG4ParticlesManager singleton.");
41}
42
72095f7c 43//_____________________________________________________________________________
17929791 44TG4ParticlesManager::~TG4ParticlesManager() {
45//
46}
47
48// operators
49
50TG4ParticlesManager&
51TG4ParticlesManager::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 66G4int 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 108G4int 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 129void 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");
142
143 // map G4 particle names to TDatabasePDG encodings
144 fParticlePDGMap.Add("deuteron", GetPDGEncoding("deuteron"));
145 fParticlePDGMap.Add("triton", GetPDGEncoding("triton"));
146 fParticlePDGMap.Add("alpha", GetPDGEncoding("alpha"));
147 fParticlePDGMap.Add("He3", GetPDGEncoding("He3") );
148 fParticlePDGMap.Add("opticalphoton", GetPDGEncoding("opticalphoton"));
149 // fParticlePDGMap.Add("???","FeedbackPhoton");
bcb189b7 150 fParticlePDGMap.Add("geantino", GetPDGEncoding("geantino"));
17929791 151
152 // add verbose
5b6ecd36 153 if (VerboseLevel() > 0) {
154 G4cout << "Particle maps have been filled." << G4endl;
155 }
156 if (VerboseLevel() > 1) {
157 fParticleNameMap.PrintAll();
158 fParticlePDGMap.PrintAll();
159 }
17929791 160}
161
162// public methods
163
164G4int TG4ParticlesManager::GetPDGEncodingFast(G4ParticleDefinition* particle)
165{
166// Returns the PDG code of particle;
167// if standard PDG code is not defined the preregistred
168// fParticlePDGMap is used.
169// ---
170
171 // get PDG encoding from G4 particle definition
172 G4int pdgEncoding = particle->GetPDGEncoding();
173
174 if (pdgEncoding == 0) {
175 // use FParticlePDGMap if standard PDG code is not defined
176 G4String name = particle->GetParticleName();
177 pdgEncoding = fParticlePDGMap.GetSecond(name);
178 }
179
180 return pdgEncoding;
181}
182
72095f7c 183
184//_____________________________________________________________________________
17929791 185TParticle* TG4ParticlesManager::GetParticle(const TClonesArray* particles,
499b353a 186 G4int index) const
17929791 187{
188// Retrives particle with given index from TClonesArray
189// and checks type.
190// ---
191
499b353a 192#ifdef TGEANT4_DEBUG
17929791 193 TObject* particleTObject = particles->UncheckedAt(index);
194 TParticle* particle
195 = dynamic_cast<TParticle*>(particleTObject);
196
197 // check particle type
198 if (!particle)
199 TG4Globals::Exception(
200 "TG4ParticlesManager::GetParticle: Unknown particle type");
499b353a 201#else
202 return (TParticle*)particles->UncheckedAt(index);
203#endif
17929791 204}
205
206
72095f7c 207//_____________________________________________________________________________
17929791 208G4ParticleDefinition* TG4ParticlesManager::GetParticleDefinition(
209 const TParticle* particle) const
210{
211// Returns G4 particle definition for given TParticle
212// TO DO: replace with using particles name map
213// ---
214
215 // get particle definition from G4ParticleTable
216 G4int pdgEncoding = particle->GetPdgCode();
217 G4ParticleTable* particleTable
218 = G4ParticleTable::GetParticleTable();
219 G4ParticleDefinition* particleDefinition = 0;
220 if (pdgEncoding != 0)
221 particleDefinition = particleTable->FindParticle(pdgEncoding);
222 else {
223 G4String name = particle->GetName();
224 if (name == "Rootino")
225 particleDefinition = particleTable->FindParticle("geantino");
226 }
227
228 if (particleDefinition==0) {
229 G4cout << "pdgEncoding: " << pdgEncoding << G4endl;
230 G4String text =
231 "TG4ParticlesManager::GetParticleDefinition:\n";
232 text = text + " G4ParticleTable::FindParticle() failed.";
233 TG4Globals::Warning(text);
234 }
235
236 return particleDefinition;
237}
238
72095f7c 239
240//_____________________________________________________________________________
17929791 241G4DynamicParticle* TG4ParticlesManager::CreateDynamicParticle(
242 const TParticle* particle) const
243{
244// Creates G4DynamicParticle.
245// ---
246
247 // get particle properties
248 G4ParticleDefinition* particleDefinition
249 = GetParticleDefinition(particle);
250 if (!particleDefinition) return 0;
251
252 G4ThreeVector momentum = GetParticleMomentum(particle);
253
254 // create G4DynamicParticle
255 G4DynamicParticle* dynamicParticle
256 = new G4DynamicParticle(particleDefinition, momentum);
257
258 return dynamicParticle;
259}
260
72095f7c 261
262//_____________________________________________________________________________
17929791 263G4ThreeVector TG4ParticlesManager::GetParticlePosition(
264 const TParticle* particle) const
265{
266// Returns particle vertex position.
267// ---
268
269 G4ThreeVector position
270 = G4ThreeVector(particle->Vx()*TG4G3Units::Length(),
271 particle->Vy()*TG4G3Units::Length(),
272 particle->Vz()*TG4G3Units::Length());
273 return position;
274}
275
276
72095f7c 277//_____________________________________________________________________________
17929791 278G4ThreeVector TG4ParticlesManager::GetParticleMomentum(
279 const TParticle* particle) const
280{
281// Returns particle momentum.
282// ---
283 G4ThreeVector momentum
284 = G4ThreeVector(particle->Px()*TG4G3Units::Energy(),
285 particle->Py()*TG4G3Units::Energy(),
286 particle->Pz()*TG4G3Units::Energy());
287 return momentum;
288}
289