4 // See the class description in the header file.
6 #include "TG4ParticlesManager.h"
7 #include "TG4G3Units.h"
9 #include <G4ParticleDefinition.hh>
10 #include <G4DynamicParticle.hh>
11 #include <G4ParticleTable.hh>
13 #include <TDatabasePDG.h>
14 #include <TParticle.h>
15 #include <TClonesArray.h>
17 TG4ParticlesManager* TG4ParticlesManager::fgInstance = 0;
19 TG4ParticlesManager::TG4ParticlesManager()
23 TG4Globals::Exception(
24 "TG4ParticlesManager: attempt to create two instances of singleton.");
30 TG4ParticlesManager::TG4ParticlesManager(const TG4ParticlesManager& right) {
32 TG4Globals::Exception(
33 "Attempt to copy TG4ParticlesManager singleton.");
36 TG4ParticlesManager::~TG4ParticlesManager() {
43 TG4ParticlesManager::operator=(const TG4ParticlesManager& right)
45 // check assignement to self
46 if (this == &right) return *this;
48 TG4Globals::Exception(
49 "Attempt to assign TG4ParticlesManager singleton.");
56 G4int TG4ParticlesManager::GetPDGEncoding(G4ParticleDefinition* particle)
58 // Returns the PDG code of particle;
59 // if standard PDG code is not defined the TDatabasePDG
63 // get PDG encoding from G4 particle definition
64 G4int pdgEncoding = particle->GetPDGEncoding();
66 if (pdgEncoding == 0) {
67 // get PDG encoding from TDatabasePDG
69 // get particle name from the name map
70 G4String g4name = particle->GetParticleName();
71 G4String tname = fParticleNameMap.GetSecond(g4name);
72 if (tname == "Undefined") {
73 G4String text = "TG4ParticlesManager::GetPDGEncoding: \n";
74 text = text + " Particle " + g4name;
75 text = text + " was not found in the name map.";
76 TG4Globals::Exception(text);
79 // get particle from TDatabasePDG
80 TDatabasePDG* pdgDB = TDatabasePDG::Instance();
81 TParticlePDG* particle = pdgDB->GetParticle(tname);
83 G4String text = "TG4ParticlesManager::GetPDGEncoding: \n";
84 text = text + " Particle " + tname;
85 text = text + " was not found in TDatabasePDG.";
86 TG4Globals::Exception(text);
90 pdgEncoding = particle->PdgCode();
96 G4int TG4ParticlesManager::GetPDGEncoding(G4String particleName)
98 // Returns the PDG code of particle sepcified by name.
101 G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
103 G4ParticleDefinition* particle = 0;
104 particle = particleTable->FindParticle(particleName);
106 G4String text = "TG4ParticlesManager::GetPDGEncoding:\n";
107 text = text + " G4ParticleTable::FindParticle() " + particleName;
108 text = text + " failed.";
109 TG4Globals::Exception(text);
112 return GetPDGEncoding(particle);
115 void TG4ParticlesManager::MapParticles()
117 // map G4 particle names to TDatabasePDG names
118 // (the map is built only for particles that have not
119 // defined standard PDG encoding)
121 fParticleNameMap.Add("deuteron","Deuteron");
122 fParticleNameMap.Add("triton", "Triton");
123 fParticleNameMap.Add("alpha", "Alpha");
124 fParticleNameMap.Add("He3", "HE3");
125 fParticleNameMap.Add("opticalphoton","Cherenkov");
126 // fParticleNameMap.Add("???","FeedbackPhoton");
127 fParticleNameMap.Add("geantino", "Rootino");
129 // map G4 particle names to TDatabasePDG encodings
130 fParticlePDGMap.Add("deuteron", GetPDGEncoding("deuteron"));
131 fParticlePDGMap.Add("triton", GetPDGEncoding("triton"));
132 fParticlePDGMap.Add("alpha", GetPDGEncoding("alpha"));
133 fParticlePDGMap.Add("He3", GetPDGEncoding("He3") );
134 fParticlePDGMap.Add("opticalphoton", GetPDGEncoding("opticalphoton"));
135 // fParticlePDGMap.Add("???","FeedbackPhoton");
136 fParticleNameMap.Add("geantino", GetPDGEncoding("geantino"));
139 G4cout << "Particle maps have been filled." << G4endl;
140 //fParticleNameMap.PrintAll();
141 //fParticlePDGMap.PrintAll();
146 G4int TG4ParticlesManager::GetPDGEncodingFast(G4ParticleDefinition* particle)
148 // Returns the PDG code of particle;
149 // if standard PDG code is not defined the preregistred
150 // fParticlePDGMap is used.
153 // get PDG encoding from G4 particle definition
154 G4int pdgEncoding = particle->GetPDGEncoding();
156 if (pdgEncoding == 0) {
157 // use FParticlePDGMap if standard PDG code is not defined
158 G4String name = particle->GetParticleName();
159 pdgEncoding = fParticlePDGMap.GetSecond(name);
166 TParticle* TG4ParticlesManager::GetParticle(const TClonesArray* particles,
169 // Retrives particle with given index from TClonesArray
173 TObject* particleTObject = particles->UncheckedAt(index);
175 = dynamic_cast<TParticle*>(particleTObject);
177 // check particle type
179 TG4Globals::Exception(
180 "TG4ParticlesManager::GetParticle: Unknown particle type");
186 G4ParticleDefinition* TG4ParticlesManager::GetParticleDefinition(
187 const TParticle* particle) const
189 // Returns G4 particle definition for given TParticle
190 // TO DO: replace with using particles name map
193 // get particle definition from G4ParticleTable
194 G4int pdgEncoding = particle->GetPdgCode();
195 G4ParticleTable* particleTable
196 = G4ParticleTable::GetParticleTable();
197 G4ParticleDefinition* particleDefinition = 0;
198 if (pdgEncoding != 0)
199 particleDefinition = particleTable->FindParticle(pdgEncoding);
201 G4String name = particle->GetName();
202 if (name == "Rootino")
203 particleDefinition = particleTable->FindParticle("geantino");
206 if (particleDefinition==0) {
207 G4cout << "pdgEncoding: " << pdgEncoding << G4endl;
209 "TG4ParticlesManager::GetParticleDefinition:\n";
210 text = text + " G4ParticleTable::FindParticle() failed.";
211 TG4Globals::Warning(text);
214 return particleDefinition;
217 G4DynamicParticle* TG4ParticlesManager::CreateDynamicParticle(
218 const TParticle* particle) const
220 // Creates G4DynamicParticle.
223 // get particle properties
224 G4ParticleDefinition* particleDefinition
225 = GetParticleDefinition(particle);
226 if (!particleDefinition) return 0;
228 G4ThreeVector momentum = GetParticleMomentum(particle);
230 // create G4DynamicParticle
231 G4DynamicParticle* dynamicParticle
232 = new G4DynamicParticle(particleDefinition, momentum);
234 return dynamicParticle;
237 G4ThreeVector TG4ParticlesManager::GetParticlePosition(
238 const TParticle* particle) const
240 // Returns particle vertex position.
243 G4ThreeVector position
244 = G4ThreeVector(particle->Vx()*TG4G3Units::Length(),
245 particle->Vy()*TG4G3Units::Length(),
246 particle->Vz()*TG4G3Units::Length());
251 G4ThreeVector TG4ParticlesManager::GetParticleMomentum(
252 const TParticle* particle) const
254 // Returns particle momentum.
256 G4ThreeVector momentum
257 = G4ThreeVector(particle->Px()*TG4G3Units::Energy(),
258 particle->Py()*TG4G3Units::Energy(),
259 particle->Pz()*TG4G3Units::Energy());