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