]> git.uio.no Git - u/mrichter/AliRoot.git/blame_incremental - TGeant4/TG4ParticlesManager.cxx
Enable creation of fast rec points for ITS, when input argument for ITS = 2.
[u/mrichter/AliRoot.git] / TGeant4 / TG4ParticlesManager.cxx
... / ...
CommitLineData
1// $Id$
2// Category: physics
3//
4// Author: I. Hrivnacova
5//
6// Class TG4ParticlesManager
7// -------------------------
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
23//_____________________________________________________________________________
24TG4ParticlesManager::TG4ParticlesManager()
25 : TG4Verbose("particlesMananger") {
26//
27 if (fgInstance) {
28 TG4Globals::Exception(
29 "TG4ParticlesManager: attempt to create two instances of singleton.");
30 }
31
32 fgInstance = this;
33}
34
35//_____________________________________________________________________________
36TG4ParticlesManager::TG4ParticlesManager(const TG4ParticlesManager& right)
37 : TG4Verbose("particlesMananger") {
38//
39 TG4Globals::Exception(
40 "Attempt to copy TG4ParticlesManager singleton.");
41}
42
43//_____________________________________________________________________________
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
64
65//_____________________________________________________________________________
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
106
107//_____________________________________________________________________________
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
127
128//_____________________________________________________________________________
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 fParticleNameMap.Add("chargedgeantino", "Rootino");
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");
151 fParticlePDGMap.Add("geantino", GetPDGEncoding("geantino"));
152 fParticlePDGMap.Add("chargedgeantino", GetPDGEncoding("chargedgeantino"));
153
154 // add verbose
155 if (VerboseLevel() > 0) {
156 G4cout << "Particle maps have been filled." << G4endl;
157 }
158 if (VerboseLevel() > 1) {
159 fParticleNameMap.PrintAll();
160 fParticlePDGMap.PrintAll();
161 }
162}
163
164// public methods
165
166//_____________________________________________________________________________
167G4int 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
177 // use fParticlePDGMap if standard/ENDF-6 PDG code is not defined
178 if (pdgEncoding == 0) {
179 G4String name = particle->GetParticleName();
180 pdgEncoding = fParticlePDGMap.GetSecond(name, false);
181 }
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
210 return pdgEncoding;
211}
212
213
214//_____________________________________________________________________________
215TParticle* TG4ParticlesManager::GetParticle(const TClonesArray* particles,
216 G4int index) const
217{
218// Retrives particle with given index from TClonesArray
219// and checks type.
220// ---
221
222#ifdef TGEANT4_DEBUG
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");
231#else
232 return (TParticle*)particles->UncheckedAt(index);
233#endif
234}
235
236
237//_____________________________________________________________________________
238G4ParticleDefinition* 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
269
270//_____________________________________________________________________________
271G4DynamicParticle* 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
291
292//_____________________________________________________________________________
293G4ThreeVector 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
307//_____________________________________________________________________________
308G4ThreeVector 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