EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FairParticle.cxx
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file FairParticle.cxx
1 // -------------------------------------------------------------------------
2 // ----- FairParticle source file -----
3 // ----- Created 06/01/04 by M. Al-Turany -----
4 // -------------------------------------------------------------------------
5 
6 
7 // Extended TParticle with pointers to mother and daughters
8 // particles
9 
10 #include "FairParticle.h"
11 
12 #include "TParticle.h"
13 #include "TMCParticleType.h"
14 #include <iostream>
15 #include "TParticlePDG.h"
16 #include "TDatabasePDG.h"
17 using std::cout;
18 using std::endl;
19 
21 //_____________________________________________________________________________
22 FairParticle::FairParticle(Int_t id, TParticle* particle)
23  : TObject(),
24  fpdg(id),
25  fParticle(particle),
26  fMother(0),
27  fDaughters(0),
28  fname(particle->GetName()),
29  fmcType(kPTIon),
30  fmass(particle->GetMass()),
31  fcharge(particle->GetPDG()->Charge()),
32  fDecayTime(particle->GetPDG()->Lifetime()),
33  fpType("Ion"),
34  fwidth(particle->GetPDG()->Width()),
35  fiSpin((Int_t)particle->GetPDG()->Spin()),
36  fiParity(particle->GetPDG()->Parity()),
37  fiConjugation(0),
38  fiIsospin((Int_t)particle->GetPDG()->Isospin()),
39  fiIsospinZ(0),
40  fgParity(0),
41  flepton(0),
42  fbaryon(0),
43  fstable(particle->GetPDG()->Stable())
44 {
45 }
46 //_____________________________________________________________________________
47 
48 FairParticle::FairParticle(const char* name, Int_t z, Int_t a, Int_t s,Double_t mass ,Int_t q, Bool_t stable, Double_t decaytime)
49  : TObject(),
50  fpdg(1000000000+10000000*s+10000* z +10 * a),
51  fParticle(0),
52  fMother(0),
53  fDaughters(0),
54  fname(name),
55  fmcType(kPTIon),
56  fmass(0),
57  fcharge(0),
58  fDecayTime(decaytime),
59  fpType("Ion"),
60  fwidth(0),
61  fiSpin(0),
62  fiParity(0),
63  fiConjugation(0),
64  fiIsospin(0),
65  fiIsospinZ(0),
66  fgParity(0),
67  flepton(0),
68  fbaryon(0),
69  fstable(stable)
70 {
71 
72  TDatabasePDG* pdgDB = TDatabasePDG::Instance();
73  if (!pdgDB->GetParticle(fpdg)) {
74  if(mass == 0 ) {
75  TParticlePDG* kProton = pdgDB->GetParticle(2212);
76  Double_t kProtonMass=kProton->Mass();
77  mass = a*kProtonMass;
78  }
79  pdgDB->AddParticle(name, name, mass, stable, 0, q, "kPTHadron", fpdg);
80 
81  }
82 
83  fParticle = new TParticle();
84  fParticle->SetPdgCode(fpdg);
85 
86  fmcType= kPTHadron;
87  fmass= mass;
88  fcharge= fParticle->GetPDG()->Charge();
89  fDecayTime=decaytime ;
90  fwidth= fParticle->GetPDG()->Width();
91  fiSpin= (Int_t)fParticle->GetPDG()->Spin();
92  fiParity= fParticle->GetPDG()->Parity();
93  fiConjugation= 0;
94  fiIsospin= (Int_t) fParticle->GetPDG()->Isospin();
95  fiIsospinZ= 0;
96  fgParity= 0;
97  flepton= 0;
98  fbaryon= 0;
99  fstable= fParticle->GetPDG()->Stable();
100 
101 
102 }
103 //_____________________________________________________________________________
104 
105 FairParticle::FairParticle(const char* name, Int_t z, Int_t a, Double_t mass ,Int_t q, Bool_t stable, Double_t decaytime)
106  : TObject(),
107  fpdg(10000000+10000* z +10 * a),
108  fParticle(0),
109  fMother(0),
110  fDaughters(0),
111  fname(name),
112  fmcType(kPTIon),
113  fmass(0),
114  fcharge(0),
115  fDecayTime(decaytime),
116  fpType("Ion"),
117  fwidth(0),
118  fiSpin(0),
119  fiParity(0),
120  fiConjugation(0),
121  fiIsospin(0),
122  fiIsospinZ(0),
123  fgParity(0),
124  flepton(0),
125  fbaryon(0),
126  fstable(stable)
127 {
128  // fpdg= 10000000+10000* z +10 * a;
129 
130  // fDecayTime= decaytime;
131  TDatabasePDG* pdgDB = TDatabasePDG::Instance();
132 
133  if (!pdgDB->GetParticle(fpdg)) {
134  if(mass == 0 ) {
135  TParticlePDG* kProton = pdgDB->GetParticle(2212);
136  Double_t kProtonMass=kProton->Mass();
137  mass = a*kProtonMass;
138  }
139  pdgDB->AddParticle(name, name, mass, stable, 0, q, "kPTHadron", fpdg);
140 
141  }
142 
143  fParticle = new TParticle();
144  fParticle->SetPdgCode(fpdg);
145 
146  fmcType= kPTHadron;
147  fmass= mass;
148  fcharge= fParticle->GetPDG()->Charge();
149  fDecayTime=decaytime ;
150  fwidth= fParticle->GetPDG()->Width();
151  fiSpin= (Int_t)fParticle->GetPDG()->Spin();
152  fiParity= fParticle->GetPDG()->Parity();
153  fiConjugation= 0;
154  fiIsospin= (Int_t) fParticle->GetPDG()->Isospin();
155  fiIsospinZ= 0;
156  fgParity= 0;
157  flepton= 0;
158  fbaryon= 0;
159  fstable= fParticle->GetPDG()->Stable();
160 
161 
162 }
163 
164 //_____________________________________________________________________________
165 FairParticle::FairParticle(Int_t id, TParticle* particle, FairParticle* mother)
166  : TObject(),
167  fpdg(id),
168  fParticle(particle),
169  fMother(mother),
170  fDaughters(),
171  fname(particle->GetName()),
172  fmcType (kPTIon),
173  fmass (0),
174  fcharge(0),
175  fDecayTime(0),
176  fpType("Ion"),
177  fwidth(0),
178  fiSpin(0),
179  fiParity(0),
180  fiConjugation(0),
181  fiIsospin(0),
182  fiIsospinZ(0),
183  fgParity(0),
184  flepton(0),
185  fbaryon(0),
186  fstable(kTRUE)
187 
188 {
189 //
190 }
191 
192 //_____________________________________________________________________________
194  const TString name,
195  TMCParticleType mcType,
196  Double_t mass,
197  Double_t charge,
198  Double_t lifetime,
199  const TString pType,
200  Double_t width,
201  Int_t iSpin,
202  Int_t iParity,
203  Int_t iConjugation,
204  Int_t iIsospin,
205  Int_t iIsospinZ,
206  Int_t gParity,
207  Int_t lepton,
208  Int_t baryon,
209  Bool_t stable )
210  : TObject(),
211  fpdg (pdg),
212  fParticle( new TParticle()),
213  fMother(0),
214  fDaughters(0),
215  fname(name),
216  fmcType (mcType),
217  fmass (mass),
218  fcharge( charge),
219  fDecayTime( lifetime),
220  fpType( pType),
221  fwidth( width),
222  fiSpin( iSpin),
223  fiParity( iParity),
224  fiConjugation( iConjugation),
225  fiIsospin( iIsospin),
226  fiIsospinZ( iIsospinZ),
227  fgParity( gParity),
228  flepton( lepton),
229  fbaryon( baryon),
230  fstable( stable)
231 {
232 
233  if (!TDatabasePDG::Instance()->GetParticle(fpdg)) {
234  TDatabasePDG::Instance()
235  ->AddParticle(fname, fname, fmass, fstable, fwidth,fcharge ,pType, fpdg);
236 
237  }
238 
239  fParticle->SetPdgCode(fpdg);
240 
241 }
242 
243 //_____________________________________________________________________________
245  : TObject(),
246  fpdg(0),
247  fParticle(0),
248  fMother(0),
249  fDaughters(),
250  fname("ion"),
251  fmcType (kPTIon),
252  fmass (0),
253  fcharge(0),
254  fDecayTime(0),
255  fpType("Ion"),
256  fwidth(0),
257  fiSpin(0),
258  fiParity(0),
259  fiConjugation(0),
260  fiIsospin(0),
261  fiIsospinZ(0),
262  fgParity(0),
263  flepton(0),
264  fbaryon(0),
265  fstable(kTRUE)
266 {
267 //
268 }
269 
270 //_____________________________________________________________________________
272 {
273 //
274  delete fParticle;
275 }
276 
277 //
278 // public methods
279 //
280 
281 //_____________________________________________________________________________
283 {
284 // Adds particles daughter
285 // ---
286 
287  fMother.SetObject(particle);
288 }
289 
290 //_____________________________________________________________________________
292 {
293 // Adds particles daughter
294 // ---
295 
296  fDaughters.Add(particle);
297 }
298 
299 //_____________________________________________________________________________
300 void FairParticle::Print(Option_t* option) const
301 {
302 // Prints particle properties.
303 // ---
304 // return;
305 
306  cout << "Particle: " << fParticle->GetName() << " with ID: " << fpdg << endl;
307 
308  // fParticle->Print();
309 
310  if (GetMother()) {
311  cout << "Mother: " << GetMother()->GetParticle()->GetName()
312  << " with ID: " << GetMother()->GetPDG() << endl;
313  } else {
314  cout << "Primary " << endl;
315  }
316 
317  cout << "Number of daughters: " << GetNofDaughters() << endl;
318  cout << endl;
319 }
320 
321 //_____________________________________________________________________________
323 {
324 // Prints particles daughters.
325 // ---
326 
327  for (Int_t i=0; i<GetNofDaughters(); i++) {
328  cout << i << "th daughter: " << endl;
329  GetDaughter(i)->Print();
330  }
331 }
332 
333 //_____________________________________________________________________________
334 Int_t FairParticle::GetPDG() const
335 {
336 // Returs particle ID.
337 // ---
338 
339  return fpdg;
340 }
341 
342 
343 //_____________________________________________________________________________
344 TParticle* FairParticle::GetParticle() const
345 {
346 // Returns particle definition (TParticle).
347 // ---
348 
349  return fParticle;
350 }
351 
352 //_____________________________________________________________________________
354 {
355 // Returns particle definition (TParticle).
356 // ---
357 
358  return (FairParticle*) fMother.GetObject();
359 }
360 
361 //_____________________________________________________________________________
363 {
364 // Returns number of daughters.
365 // ---
366 
367  return fDaughters.GetEntriesFast();
368 }
369 
370 //_____________________________________________________________________________
372 {
373 // Returns i-th daughter.
374 // ---
375 
376  if (i < 0 || i >= GetNofDaughters()) {
377  Fatal("GetDaughter", "Index out of range");
378  }
379 
380  return (FairParticle*) fDaughters.At(i);
381 }
382