]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TGeant4/TG4ParticlesManager.cxx
Add MEVSIM and TMEVSIM
[u/mrichter/AliRoot.git] / TGeant4 / TG4ParticlesManager.cxx
CommitLineData
17929791 1// $Id$
2// Category: physics
3//
4// See the class description in the header file.
5
6#include "TG4ParticlesManager.h"
7#include "TG4G3Units.h"
8
9#include <G4ParticleDefinition.hh>
10#include <G4DynamicParticle.hh>
11#include <G4ParticleTable.hh>
12
13#include <TDatabasePDG.h>
14#include <TParticle.h>
15#include <TClonesArray.h>
16
17TG4ParticlesManager* TG4ParticlesManager::fgInstance = 0;
18
19TG4ParticlesManager::TG4ParticlesManager()
20{
21//
22 if (fgInstance) {
23 TG4Globals::Exception(
24 "TG4ParticlesManager: attempt to create two instances of singleton.");
25 }
26
27 fgInstance = this;
28}
29
30TG4ParticlesManager::TG4ParticlesManager(const TG4ParticlesManager& right) {
31//
32 TG4Globals::Exception(
33 "Attempt to copy TG4ParticlesManager singleton.");
34}
35
36TG4ParticlesManager::~TG4ParticlesManager() {
37//
38}
39
40// operators
41
42TG4ParticlesManager&
43TG4ParticlesManager::operator=(const TG4ParticlesManager& right)
44{
45 // check assignement to self
46 if (this == &right) return *this;
47
48 TG4Globals::Exception(
49 "Attempt to assign TG4ParticlesManager singleton.");
50
51 return *this;
52}
53
54// private methods
55
56G4int TG4ParticlesManager::GetPDGEncoding(G4ParticleDefinition* particle)
57{
58// Returns the PDG code of particle;
59// if standard PDG code is not defined the TDatabasePDG
60// is used.
61// ---
62
63 // get PDG encoding from G4 particle definition
64 G4int pdgEncoding = particle->GetPDGEncoding();
65
66 if (pdgEncoding == 0) {
67 // get PDG encoding from TDatabasePDG
68
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);
77 }
78
79 // get particle from TDatabasePDG
80 TDatabasePDG* pdgDB = TDatabasePDG::Instance();
81 TParticlePDG* particle = pdgDB->GetParticle(tname);
82 if (!particle) {
83 G4String text = "TG4ParticlesManager::GetPDGEncoding: \n";
84 text = text + " Particle " + tname;
85 text = text + " was not found in TDatabasePDG.";
86 TG4Globals::Exception(text);
87 }
88
89 // get PDG encoding
90 pdgEncoding = particle->PdgCode();
91 }
92
93 return pdgEncoding;
94}
95
96G4int TG4ParticlesManager::GetPDGEncoding(G4String particleName)
97{
98// Returns the PDG code of particle sepcified by name.
99// ---
100
101 G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
102
103 G4ParticleDefinition* particle = 0;
104 particle = particleTable->FindParticle(particleName);
105 if (!particle) {
106 G4String text = "TG4ParticlesManager::GetPDGEncoding:\n";
107 text = text + " G4ParticleTable::FindParticle() " + particleName;
108 text = text + " failed.";
109 TG4Globals::Exception(text);
110 }
111
112 return GetPDGEncoding(particle);
113}
114
115void TG4ParticlesManager::MapParticles()
116{
117 // map G4 particle names to TDatabasePDG names
118 // (the map is built only for particles that have not
119 // defined standard PDG encoding)
120
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");
128
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"));
137
138 // add verbose
139 G4cout << "Particle maps have been filled." << G4endl;
140 //fParticleNameMap.PrintAll();
141 //fParticlePDGMap.PrintAll();
142}
143
144// public methods
145
146G4int TG4ParticlesManager::GetPDGEncodingFast(G4ParticleDefinition* particle)
147{
148// Returns the PDG code of particle;
149// if standard PDG code is not defined the preregistred
150// fParticlePDGMap is used.
151// ---
152
153 // get PDG encoding from G4 particle definition
154 G4int pdgEncoding = particle->GetPDGEncoding();
155
156 if (pdgEncoding == 0) {
157 // use FParticlePDGMap if standard PDG code is not defined
158 G4String name = particle->GetParticleName();
159 pdgEncoding = fParticlePDGMap.GetSecond(name);
160 }
161
162 return pdgEncoding;
163}
164
165
166TParticle* TG4ParticlesManager::GetParticle(const TClonesArray* particles,
167 G4int index) const
168{
169// Retrives particle with given index from TClonesArray
170// and checks type.
171// ---
172
173 TObject* particleTObject = particles->UncheckedAt(index);
174 TParticle* particle
175 = dynamic_cast<TParticle*>(particleTObject);
176
177 // check particle type
178 if (!particle)
179 TG4Globals::Exception(
180 "TG4ParticlesManager::GetParticle: Unknown particle type");
181
182 return particle;
183}
184
185
186G4ParticleDefinition* TG4ParticlesManager::GetParticleDefinition(
187 const TParticle* particle) const
188{
189// Returns G4 particle definition for given TParticle
190// TO DO: replace with using particles name map
191// ---
192
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);
200 else {
201 G4String name = particle->GetName();
202 if (name == "Rootino")
203 particleDefinition = particleTable->FindParticle("geantino");
204 }
205
206 if (particleDefinition==0) {
207 G4cout << "pdgEncoding: " << pdgEncoding << G4endl;
208 G4String text =
209 "TG4ParticlesManager::GetParticleDefinition:\n";
210 text = text + " G4ParticleTable::FindParticle() failed.";
211 TG4Globals::Warning(text);
212 }
213
214 return particleDefinition;
215}
216
217G4DynamicParticle* TG4ParticlesManager::CreateDynamicParticle(
218 const TParticle* particle) const
219{
220// Creates G4DynamicParticle.
221// ---
222
223 // get particle properties
224 G4ParticleDefinition* particleDefinition
225 = GetParticleDefinition(particle);
226 if (!particleDefinition) return 0;
227
228 G4ThreeVector momentum = GetParticleMomentum(particle);
229
230 // create G4DynamicParticle
231 G4DynamicParticle* dynamicParticle
232 = new G4DynamicParticle(particleDefinition, momentum);
233
234 return dynamicParticle;
235}
236
237G4ThreeVector TG4ParticlesManager::GetParticlePosition(
238 const TParticle* particle) const
239{
240// Returns particle vertex position.
241// ---
242
243 G4ThreeVector position
244 = G4ThreeVector(particle->Vx()*TG4G3Units::Length(),
245 particle->Vy()*TG4G3Units::Length(),
246 particle->Vz()*TG4G3Units::Length());
247 return position;
248}
249
250
251G4ThreeVector TG4ParticlesManager::GetParticleMomentum(
252 const TParticle* particle) const
253{
254// Returns particle momentum.
255// ---
256 G4ThreeVector momentum
257 = G4ThreeVector(particle->Px()*TG4G3Units::Energy(),
258 particle->Py()*TG4G3Units::Energy(),
259 particle->Pz()*TG4G3Units::Energy());
260 return momentum;
261}
262