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()
25 : TG4Verbose("particlesMananger") {
28 TG4Globals::Exception(
29 "TG4ParticlesManager: attempt to create two instances of singleton.");
35 //_____________________________________________________________________________
36 TG4ParticlesManager::TG4ParticlesManager(const TG4ParticlesManager& right)
37 : TG4Verbose("particlesMananger") {
39 TG4Globals::Exception(
40 "Attempt to copy TG4ParticlesManager singleton.");
43 //_____________________________________________________________________________
44 TG4ParticlesManager::~TG4ParticlesManager() {
51 TG4ParticlesManager::operator=(const TG4ParticlesManager& right)
53 // check assignement to self
54 if (this == &right) return *this;
56 TG4Globals::Exception(
57 "Attempt to assign TG4ParticlesManager singleton.");
65 //_____________________________________________________________________________
66 G4int TG4ParticlesManager::GetPDGEncoding(G4ParticleDefinition* particle)
68 // Returns the PDG code of particle;
69 // if standard PDG code is not defined the TDatabasePDG
73 // get PDG encoding from G4 particle definition
74 G4int pdgEncoding = particle->GetPDGEncoding();
76 if (pdgEncoding == 0) {
77 // get PDG encoding from TDatabasePDG
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);
89 // get particle from TDatabasePDG
90 TDatabasePDG* pdgDB = TDatabasePDG::Instance();
91 TParticlePDG* particle = pdgDB->GetParticle(tname);
93 G4String text = "TG4ParticlesManager::GetPDGEncoding: \n";
94 text = text + " Particle " + tname;
95 text = text + " was not found in TDatabasePDG.";
96 TG4Globals::Exception(text);
100 pdgEncoding = particle->PdgCode();
107 //_____________________________________________________________________________
108 G4int TG4ParticlesManager::GetPDGEncoding(G4String particleName)
110 // Returns the PDG code of particle sepcified by name.
113 G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
115 G4ParticleDefinition* particle = 0;
116 particle = particleTable->FindParticle(particleName);
118 G4String text = "TG4ParticlesManager::GetPDGEncoding:\n";
119 text = text + " G4ParticleTable::FindParticle() " + particleName;
120 text = text + " failed.";
121 TG4Globals::Exception(text);
124 return GetPDGEncoding(particle);
128 //_____________________________________________________________________________
129 void TG4ParticlesManager::MapParticles()
131 // map G4 particle names to TDatabasePDG names
132 // (the map is built only for particles that have not
133 // defined standard PDG encoding)
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");
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");
150 fParticlePDGMap.Add("geantino", GetPDGEncoding("geantino"));
153 if (VerboseLevel() > 0) {
154 G4cout << "Particle maps have been filled." << G4endl;
156 if (VerboseLevel() > 1) {
157 fParticleNameMap.PrintAll();
158 fParticlePDGMap.PrintAll();
164 G4int TG4ParticlesManager::GetPDGEncodingFast(G4ParticleDefinition* particle)
166 // Returns the PDG code of particle;
167 // if standard PDG code is not defined the preregistred
168 // fParticlePDGMap is used.
171 // get PDG encoding from G4 particle definition
172 G4int pdgEncoding = particle->GetPDGEncoding();
174 if (pdgEncoding == 0) {
175 // use FParticlePDGMap if standard PDG code is not defined
176 G4String name = particle->GetParticleName();
177 pdgEncoding = fParticlePDGMap.GetSecond(name);
184 //_____________________________________________________________________________
185 TParticle* TG4ParticlesManager::GetParticle(const TClonesArray* particles,
188 // Retrives particle with given index from TClonesArray
193 TObject* particleTObject = particles->UncheckedAt(index);
195 = dynamic_cast<TParticle*>(particleTObject);
197 // check particle type
199 TG4Globals::Exception(
200 "TG4ParticlesManager::GetParticle: Unknown particle type");
202 return (TParticle*)particles->UncheckedAt(index);
207 //_____________________________________________________________________________
208 G4ParticleDefinition* TG4ParticlesManager::GetParticleDefinition(
209 const TParticle* particle) const
211 // Returns G4 particle definition for given TParticle
212 // TO DO: replace with using particles name map
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);
223 G4String name = particle->GetName();
224 if (name == "Rootino")
225 particleDefinition = particleTable->FindParticle("geantino");
228 if (particleDefinition==0) {
229 G4cout << "pdgEncoding: " << pdgEncoding << G4endl;
231 "TG4ParticlesManager::GetParticleDefinition:\n";
232 text = text + " G4ParticleTable::FindParticle() failed.";
233 TG4Globals::Warning(text);
236 return particleDefinition;
240 //_____________________________________________________________________________
241 G4DynamicParticle* TG4ParticlesManager::CreateDynamicParticle(
242 const TParticle* particle) const
244 // Creates G4DynamicParticle.
247 // get particle properties
248 G4ParticleDefinition* particleDefinition
249 = GetParticleDefinition(particle);
250 if (!particleDefinition) return 0;
252 G4ThreeVector momentum = GetParticleMomentum(particle);
254 // create G4DynamicParticle
255 G4DynamicParticle* dynamicParticle
256 = new G4DynamicParticle(particleDefinition, momentum);
258 return dynamicParticle;
262 //_____________________________________________________________________________
263 G4ThreeVector TG4ParticlesManager::GetParticlePosition(
264 const TParticle* particle) const
266 // Returns particle vertex position.
269 G4ThreeVector position
270 = G4ThreeVector(particle->Vx()*TG4G3Units::Length(),
271 particle->Vy()*TG4G3Units::Length(),
272 particle->Vz()*TG4G3Units::Length());
277 //_____________________________________________________________________________
278 G4ThreeVector TG4ParticlesManager::GetParticleMomentum(
279 const TParticle* particle) const
281 // Returns particle momentum.
283 G4ThreeVector momentum
284 = G4ThreeVector(particle->Px()*TG4G3Units::Energy(),
285 particle->Py()*TG4G3Units::Energy(),
286 particle->Pz()*TG4G3Units::Energy());