4 // Author: I. Hrivnacova
6 // Class TG4ParticlesManager
7 // -------------------------
8 // See the class description in the header file.
10 #include "TG4ParticlesManager.h"
11 #include "TG4G3Units.h"
13 #include <G4ParticleDefinition.hh>
14 #include <G4DynamicParticle.hh>
15 #include <G4ParticleTable.hh>
17 #include <TDatabasePDG.h>
18 #include <TParticle.h>
19 #include <TClonesArray.h>
21 TG4ParticlesManager* TG4ParticlesManager::fgInstance = 0;
23 //_____________________________________________________________________________
24 TG4ParticlesManager::TG4ParticlesManager()
28 TG4Globals::Exception(
29 "TG4ParticlesManager: attempt to create two instances of singleton.");
35 //_____________________________________________________________________________
36 TG4ParticlesManager::TG4ParticlesManager(const TG4ParticlesManager& right) {
38 TG4Globals::Exception(
39 "Attempt to copy TG4ParticlesManager singleton.");
42 //_____________________________________________________________________________
43 TG4ParticlesManager::~TG4ParticlesManager() {
50 TG4ParticlesManager::operator=(const TG4ParticlesManager& right)
52 // check assignement to self
53 if (this == &right) return *this;
55 TG4Globals::Exception(
56 "Attempt to assign TG4ParticlesManager singleton.");
64 //_____________________________________________________________________________
65 G4int TG4ParticlesManager::GetPDGEncoding(G4ParticleDefinition* particle)
67 // Returns the PDG code of particle;
68 // if standard PDG code is not defined the TDatabasePDG
72 // get PDG encoding from G4 particle definition
73 G4int pdgEncoding = particle->GetPDGEncoding();
75 if (pdgEncoding == 0) {
76 // get PDG encoding from TDatabasePDG
78 // get particle name from the name map
79 G4String g4name = particle->GetParticleName();
80 G4String tname = fParticleNameMap.GetSecond(g4name);
81 if (tname == "Undefined") {
82 G4String text = "TG4ParticlesManager::GetPDGEncoding: \n";
83 text = text + " Particle " + g4name;
84 text = text + " was not found in the name map.";
85 TG4Globals::Exception(text);
88 // get particle from TDatabasePDG
89 TDatabasePDG* pdgDB = TDatabasePDG::Instance();
90 TParticlePDG* particle = pdgDB->GetParticle(tname);
92 G4String text = "TG4ParticlesManager::GetPDGEncoding: \n";
93 text = text + " Particle " + tname;
94 text = text + " was not found in TDatabasePDG.";
95 TG4Globals::Exception(text);
99 pdgEncoding = particle->PdgCode();
106 //_____________________________________________________________________________
107 G4int TG4ParticlesManager::GetPDGEncoding(G4String particleName)
109 // Returns the PDG code of particle sepcified by name.
112 G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
114 G4ParticleDefinition* particle = 0;
115 particle = particleTable->FindParticle(particleName);
117 G4String text = "TG4ParticlesManager::GetPDGEncoding:\n";
118 text = text + " G4ParticleTable::FindParticle() " + particleName;
119 text = text + " failed.";
120 TG4Globals::Exception(text);
123 return GetPDGEncoding(particle);
127 //_____________________________________________________________________________
128 void TG4ParticlesManager::MapParticles()
130 // map G4 particle names to TDatabasePDG names
131 // (the map is built only for particles that have not
132 // defined standard PDG encoding)
134 fParticleNameMap.Add("deuteron","Deuteron");
135 fParticleNameMap.Add("triton", "Triton");
136 fParticleNameMap.Add("alpha", "Alpha");
137 fParticleNameMap.Add("He3", "HE3");
138 fParticleNameMap.Add("opticalphoton","Cherenkov");
139 // fParticleNameMap.Add("???","FeedbackPhoton");
140 fParticleNameMap.Add("geantino", "Rootino");
142 // map G4 particle names to TDatabasePDG encodings
143 fParticlePDGMap.Add("deuteron", GetPDGEncoding("deuteron"));
144 fParticlePDGMap.Add("triton", GetPDGEncoding("triton"));
145 fParticlePDGMap.Add("alpha", GetPDGEncoding("alpha"));
146 fParticlePDGMap.Add("He3", GetPDGEncoding("He3") );
147 fParticlePDGMap.Add("opticalphoton", GetPDGEncoding("opticalphoton"));
148 // fParticlePDGMap.Add("???","FeedbackPhoton");
149 fParticlePDGMap.Add("geantino", GetPDGEncoding("geantino"));
152 G4cout << "Particle maps have been filled." << G4endl;
153 //fParticleNameMap.PrintAll();
154 //fParticlePDGMap.PrintAll();
159 G4int TG4ParticlesManager::GetPDGEncodingFast(G4ParticleDefinition* particle)
161 // Returns the PDG code of particle;
162 // if standard PDG code is not defined the preregistred
163 // fParticlePDGMap is used.
166 // get PDG encoding from G4 particle definition
167 G4int pdgEncoding = particle->GetPDGEncoding();
169 if (pdgEncoding == 0) {
170 // use FParticlePDGMap if standard PDG code is not defined
171 G4String name = particle->GetParticleName();
172 pdgEncoding = fParticlePDGMap.GetSecond(name);
179 //_____________________________________________________________________________
180 TParticle* TG4ParticlesManager::GetParticle(const TClonesArray* particles,
183 // Retrives particle with given index from TClonesArray
188 TObject* particleTObject = particles->UncheckedAt(index);
190 = dynamic_cast<TParticle*>(particleTObject);
192 // check particle type
194 TG4Globals::Exception(
195 "TG4ParticlesManager::GetParticle: Unknown particle type");
197 return (TParticle*)particles->UncheckedAt(index);
202 //_____________________________________________________________________________
203 G4ParticleDefinition* TG4ParticlesManager::GetParticleDefinition(
204 const TParticle* particle) const
206 // Returns G4 particle definition for given TParticle
207 // TO DO: replace with using particles name map
210 // get particle definition from G4ParticleTable
211 G4int pdgEncoding = particle->GetPdgCode();
212 G4ParticleTable* particleTable
213 = G4ParticleTable::GetParticleTable();
214 G4ParticleDefinition* particleDefinition = 0;
215 if (pdgEncoding != 0)
216 particleDefinition = particleTable->FindParticle(pdgEncoding);
218 G4String name = particle->GetName();
219 if (name == "Rootino")
220 particleDefinition = particleTable->FindParticle("geantino");
223 if (particleDefinition==0) {
224 G4cout << "pdgEncoding: " << pdgEncoding << G4endl;
226 "TG4ParticlesManager::GetParticleDefinition:\n";
227 text = text + " G4ParticleTable::FindParticle() failed.";
228 TG4Globals::Warning(text);
231 return particleDefinition;
235 //_____________________________________________________________________________
236 G4DynamicParticle* TG4ParticlesManager::CreateDynamicParticle(
237 const TParticle* particle) const
239 // Creates G4DynamicParticle.
242 // get particle properties
243 G4ParticleDefinition* particleDefinition
244 = GetParticleDefinition(particle);
245 if (!particleDefinition) return 0;
247 G4ThreeVector momentum = GetParticleMomentum(particle);
249 // create G4DynamicParticle
250 G4DynamicParticle* dynamicParticle
251 = new G4DynamicParticle(particleDefinition, momentum);
253 return dynamicParticle;
257 //_____________________________________________________________________________
258 G4ThreeVector TG4ParticlesManager::GetParticlePosition(
259 const TParticle* particle) const
261 // Returns particle vertex position.
264 G4ThreeVector position
265 = G4ThreeVector(particle->Vx()*TG4G3Units::Length(),
266 particle->Vy()*TG4G3Units::Length(),
267 particle->Vz()*TG4G3Units::Length());
272 //_____________________________________________________________________________
273 G4ThreeVector TG4ParticlesManager::GetParticleMomentum(
274 const TParticle* particle) const
276 // Returns particle momentum.
278 G4ThreeVector momentum
279 = G4ThreeVector(particle->Px()*TG4G3Units::Energy(),
280 particle->Py()*TG4G3Units::Energy(),
281 particle->Pz()*TG4G3Units::Energy());