]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TGeant4/TG4ParticlesManager.cxx
StepProcesses(): OpBoundaryStatus process added to the list of processes
[u/mrichter/AliRoot.git] / TGeant4 / TG4ParticlesManager.cxx
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
21 TG4ParticlesManager* TG4ParticlesManager::fgInstance = 0;
22
23 //_____________________________________________________________________________
24 TG4ParticlesManager::TG4ParticlesManager()
25
26 //
27   if (fgInstance) {
28     TG4Globals::Exception(
29       "TG4ParticlesManager: attempt to create two instances of singleton.");
30   }
31       
32   fgInstance = this;  
33 }
34
35 //_____________________________________________________________________________
36 TG4ParticlesManager::TG4ParticlesManager(const TG4ParticlesManager& right) {
37 // 
38   TG4Globals::Exception(
39     "Attempt to copy TG4ParticlesManager singleton.");
40 }
41
42 //_____________________________________________________________________________
43 TG4ParticlesManager::~TG4ParticlesManager() {
44 //
45 }
46
47 // operators
48
49 TG4ParticlesManager& 
50 TG4ParticlesManager::operator=(const TG4ParticlesManager& right)
51 {
52   // check assignement to self
53   if (this == &right) return *this;
54
55   TG4Globals::Exception(
56     "Attempt to assign TG4ParticlesManager singleton.");
57     
58   return *this;  
59 }    
60           
61 // private methods
62
63
64 //_____________________________________________________________________________
65 G4int TG4ParticlesManager::GetPDGEncoding(G4ParticleDefinition* particle)
66 {
67 // Returns the PDG code of particle;
68 // if standard PDG code is not defined the TDatabasePDG
69 // is used.
70 // ---
71
72   // get PDG encoding from G4 particle definition
73   G4int pdgEncoding = particle->GetPDGEncoding();
74
75   if (pdgEncoding == 0) {
76     // get PDG encoding from TDatabasePDG
77   
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);
86     }  
87   
88     // get particle from TDatabasePDG
89     TDatabasePDG* pdgDB = TDatabasePDG::Instance();
90     TParticlePDG* particle = pdgDB->GetParticle(tname);
91     if (!particle) {
92       G4String text = "TG4ParticlesManager::GetPDGEncoding: \n";
93       text = text + "    Particle " + tname;
94       text = text + " was not found in TDatabasePDG.";
95       TG4Globals::Exception(text);
96     }  
97     
98     // get PDG encoding
99     pdgEncoding = particle->PdgCode();
100   }
101     
102   return pdgEncoding;  
103 }  
104      
105
106 //_____________________________________________________________________________
107 G4int TG4ParticlesManager::GetPDGEncoding(G4String particleName)
108 {
109 // Returns the PDG code of particle sepcified by name.
110 // ---
111
112   G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
113
114   G4ParticleDefinition* particle = 0;  
115   particle = particleTable->FindParticle(particleName);
116   if (!particle) {    
117     G4String text = "TG4ParticlesManager::GetPDGEncoding:\n";
118     text = text + "   G4ParticleTable::FindParticle() " + particleName;
119     text = text + " failed.";
120     TG4Globals::Exception(text);
121   }     
122
123   return GetPDGEncoding(particle);
124 }  
125   
126
127 //_____________________________________________________________________________
128 void  TG4ParticlesManager::MapParticles()
129 {
130   // map G4 particle names to TDatabasePDG names
131   // (the map is built only for particles that have not
132   //  defined standard PDG encoding)
133   
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");
141   
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"));
150
151   // add verbose
152   G4cout << "Particle maps have been filled." << G4endl;
153   //fParticleNameMap.PrintAll();
154   //fParticlePDGMap.PrintAll();
155 }    
156
157 // public methods
158
159 G4int TG4ParticlesManager::GetPDGEncodingFast(G4ParticleDefinition* particle)
160 {
161 // Returns the PDG code of particle;
162 // if standard PDG code is not defined the preregistred
163 // fParticlePDGMap is used.
164 // ---
165
166   // get PDG encoding from G4 particle definition
167   G4int pdgEncoding = particle->GetPDGEncoding();
168
169   if (pdgEncoding == 0) {
170     // use FParticlePDGMap if standard PDG code is not defined
171     G4String name = particle->GetParticleName();
172     pdgEncoding = fParticlePDGMap.GetSecond(name);
173   }
174     
175   return pdgEncoding;  
176 }  
177      
178
179 //_____________________________________________________________________________
180 TParticle* TG4ParticlesManager::GetParticle(const TClonesArray* particles, 
181                                             G4int index) const
182 {
183 // Retrives particle with given index from TClonesArray 
184 // and checks type.
185 // ---
186
187 #ifdef TGEANT4_DEBUG
188   TObject* particleTObject = particles->UncheckedAt(index);      
189   TParticle* particle
190     = dynamic_cast<TParticle*>(particleTObject);
191
192   // check particle type
193   if (!particle) 
194     TG4Globals::Exception(
195       "TG4ParticlesManager::GetParticle: Unknown particle type");
196 #else
197   return (TParticle*)particles->UncheckedAt(index);      
198 #endif  
199 }     
200
201
202 //_____________________________________________________________________________
203 G4ParticleDefinition* TG4ParticlesManager::GetParticleDefinition(
204                                const TParticle* particle) const
205 {
206 // Returns G4 particle definition for given TParticle
207 // TO DO: replace with using particles name map    
208 // ---
209
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);
217   else {
218     G4String name = particle->GetName();
219     if (name == "Rootino")      
220       particleDefinition = particleTable->FindParticle("geantino");
221   }     
222   
223   if (particleDefinition==0) {
224     G4cout << "pdgEncoding: " << pdgEncoding << G4endl;
225     G4String text = 
226       "TG4ParticlesManager::GetParticleDefinition:\n";
227     text = text + "   G4ParticleTable::FindParticle() failed.";
228     TG4Globals::Warning(text);
229   }     
230   
231   return particleDefinition;
232 }
233
234
235 //_____________________________________________________________________________
236 G4DynamicParticle* TG4ParticlesManager::CreateDynamicParticle(
237                                    const TParticle* particle) const
238
239 // Creates G4DynamicParticle.
240 // ---
241
242   // get particle properties
243   G4ParticleDefinition* particleDefinition 
244     = GetParticleDefinition(particle);    
245   if (!particleDefinition) return 0;  
246         
247   G4ThreeVector momentum = GetParticleMomentum(particle);
248
249   // create G4DynamicParticle
250   G4DynamicParticle* dynamicParticle 
251     = new G4DynamicParticle(particleDefinition, momentum);
252   
253   return dynamicParticle;
254 }
255
256
257 //_____________________________________________________________________________
258 G4ThreeVector TG4ParticlesManager::GetParticlePosition(
259                                    const TParticle* particle) const 
260 {
261 // Returns particle vertex position.
262 // ---
263
264   G4ThreeVector position 
265      = G4ThreeVector(particle->Vx()*TG4G3Units::Length(),
266                      particle->Vy()*TG4G3Units::Length(),
267                      particle->Vz()*TG4G3Units::Length());
268   return position;
269 }                    
270                         
271                         
272 //_____________________________________________________________________________
273 G4ThreeVector TG4ParticlesManager::GetParticleMomentum(
274                                    const TParticle* particle) const
275 {
276 // Returns particle momentum.
277 // ---
278   G4ThreeVector momentum 
279      = G4ThreeVector(particle->Px()*TG4G3Units::Energy(),
280                      particle->Py()*TG4G3Units::Energy(),
281                      particle->Pz()*TG4G3Units::Energy());
282   return momentum;
283 }
284