]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/RESONANCES/AliRsnDaughter.cxx
fixed warnings
[u/mrichter/AliRoot.git] / PWG2 / RESONANCES / AliRsnDaughter.cxx
1 //
2 // Class AliRsnDaughter
3 //
4 // Light-weight AOD object which contains all required track details
5 // which are used for resonance analysis.
6 // Provides converters from all kinds of input track type: ESD, AOD and MC.
7 //
8 // authors: A. Pulvirenti (alberto.pulvirenti@ct.infn.it)
9 //          M. Vala (martin.vala@cern.ch)
10 //
11
12 #include <Riostream.h>
13
14 #include <TParticle.h>
15 #include <TString.h>
16
17 #include "AliLog.h"
18 #include "AliESDtrack.h"
19 #include "AliAODTrack.h"
20 #include "AliMCParticle.h"
21
22 #include "AliRsnPIDDefESD.h"
23 #include "AliRsnMCInfo.h"
24 #include "AliRsnDaughter.h"
25
26 ClassImp(AliRsnDaughter)
27
28 AliRsnDaughter::EPIDMethod AliRsnDaughter::fgPIDMethod = AliRsnDaughter::kRealistic;
29
30 //_____________________________________________________________________________
31 AliRsnDaughter::AliRsnDaughter() :
32   AliVParticle(),
33   fIndex(-1),
34   fLabel(-1),
35   fCharge(0),
36   fFlags(0),
37   fKink(0),
38   fMass(0.0),
39   fChi2(0.0),
40   fNSigmaToVertex(-1.0),
41   fITSnum(0),
42   fTPCnum(0),
43   fAssignedPID(AliRsnPID::kUnknown),
44   fRealisticPID(AliRsnPID::kUnknown),
45   fMCInfo(0x0)
46 {
47 //
48 // Default constructor.
49 // Initializes all data-members with meaningless values.
50 //
51
52   Int_t i;
53   for (i = 0; i < AliRsnPID::kSpecies; i++)
54   {
55     if (i < 3)
56     {
57       fP[i] = 0.0;
58       fV[i] = 0.0;
59     }
60     fPIDWeight[i] = 0.0;
61     fPIDProb[i] = 0.0;
62   }
63 }
64
65 //_____________________________________________________________________________
66 AliRsnDaughter::AliRsnDaughter(const AliRsnDaughter &copy) :
67   AliVParticle(copy),
68   fIndex(copy.fIndex),
69   fLabel(copy.fLabel),
70   fCharge(copy.fCharge),
71   fFlags(copy.fFlags),
72   fKink(copy.fKink),
73   fMass(copy.fMass),
74   fChi2(copy.fChi2),
75   fNSigmaToVertex(copy.fNSigmaToVertex),
76   fITSnum(copy.fITSnum),
77   fTPCnum(copy.fTPCnum),
78   fAssignedPID(copy.fAssignedPID),
79   fRealisticPID(copy.fRealisticPID),
80   fMCInfo(0x0)
81 {
82 //
83 // Copy constructor.
84 //
85
86   Int_t i;
87   for (i = 0; i < AliRsnPID::kSpecies; i++)
88   {
89     if (i < 3)
90     {
91       fP[i] = copy.fP[i];
92       fV[i] = copy.fV[i];
93     }
94     fPIDWeight[i] = copy.fPIDWeight[i];
95     fPIDProb[i] = copy.fPIDProb[i];
96   }
97
98   // initialize particle object
99   // only if it is present in the template object
100   if (copy.fMCInfo) fMCInfo = new AliRsnMCInfo(*(copy.fMCInfo));
101 }
102
103 //_____________________________________________________________________________
104 AliRsnDaughter& AliRsnDaughter::operator=(const AliRsnDaughter &copy)
105 {
106 //
107 // Assignment operator.
108 // Works like the copy constructor and returns a reference
109 // to the initialized object for which it is called.
110 //
111
112   fIndex  = copy.fIndex;
113   fLabel  = copy.fLabel;
114   fCharge = copy.fCharge;
115   fFlags  = copy.fFlags;
116   fKink   = copy.fKink;
117   fChi2   = copy.fChi2;
118   fNSigmaToVertex = copy.fNSigmaToVertex;
119   fITSnum = copy.fITSnum;
120   fTPCnum = copy.fTPCnum;
121
122   Int_t i;
123   for (i = 0; i < AliRsnPID::kSpecies; i++)
124   {
125     if (i < 3)
126     {
127       fP[i] = copy.fP[i];
128       fV[i] = copy.fV[i];
129     }
130     fPIDWeight[i] = copy.fPIDWeight[i];
131     fPIDProb[i] = copy.fPIDProb[i];
132   }
133
134   fMass = copy.fMass;
135   fAssignedPID = copy.fAssignedPID;
136   fRealisticPID = copy.fRealisticPID;
137
138   // initialize particle object
139   // only if it is present in the template object;
140   // otherwise, it is just cleared and not replaced with anything
141   if (fMCInfo)
142   {
143     delete fMCInfo;
144     fMCInfo = 0x0;
145   }
146   if (copy.fMCInfo) fMCInfo = new AliRsnMCInfo(*(copy.fMCInfo));
147
148   return (*this);
149 }
150
151 //_____________________________________________________________________________
152 AliRsnDaughter::~AliRsnDaughter()
153 {
154 //
155 // Destructor
156 //
157
158   if (fMCInfo)
159   {
160     delete fMCInfo;
161     fMCInfo = 0;
162   }
163 }
164
165 //_____________________________________________________________________________
166 void AliRsnDaughter::RotateP(Double_t angle, Bool_t isDegrees)
167 {
168 //
169 // Rotate the transverse momentum by an angle (in DEGREES)
170 // around Z axis (does not change the Z component)
171 //
172
173   if (isDegrees) angle *= TMath::DegToRad();
174
175   Double_t s = TMath::Sin(angle);
176   Double_t c = TMath::Cos(angle);
177   Double_t xx = fP[0];
178   fP[0] = c*xx - s*fP[1];
179   fP[1] = s*xx + c*fP[1];
180 }
181
182 //_____________________________________________________________________________
183 Double_t AliRsnDaughter::AngleTo(AliRsnDaughter *d, Bool_t outInDegrees)
184 {
185 //
186 // Compute angle between the vector momentum of this
187 // and the one of argument.
188 //
189
190   Double_t arg, dot, ptot2 = P2() * d->P2();
191
192   if(ptot2 <= 0) {
193     return 0.0;
194   }
195   else {
196     dot = Px()*d->Px() + Py()*d->Py() + Pz()*d->Pz();
197     arg = dot / TMath::Sqrt(ptot2);
198     if (arg >  1.0) arg =  1.0;
199     if (arg < -1.0) arg = -1.0;
200     if (outInDegrees) return TMath::ACos(arg) * TMath::RadToDeg();
201     else return TMath::ACos(arg);
202   }
203 }
204
205 //_____________________________________________________________________________
206 void  AliRsnDaughter::RealisticPID()
207 {
208 //
209 // Assign realistic PID from largest probability
210 //
211
212   Int_t i, imax = 0;
213   Double_t pmax = fPIDProb[0];
214
215   // search for maximum
216   for (i = 1; i < AliRsnPID::kSpecies; i++)
217   {
218     if (fPIDProb[i] > pmax)
219     {
220       imax = i;
221       pmax = fPIDProb[i];
222     }
223   }
224
225   fRealisticPID = (AliRsnPID::EType)imax;
226 }
227
228 //_____________________________________________________________________________
229 AliRsnPID::EType AliRsnDaughter::PIDType(Double_t &prob) const
230 {
231 //
232 // Return the PID type according to the selected method
233 // in the argument passed by reference, the probability is stored.
234 // It will be realistic for realistic PID and 1 for perfect PID.
235 //
236
237   switch (fgPIDMethod)
238   {
239     case kNoPID:
240       AliWarning("Requested a PIDtype call in NoPID mode");
241       prob = 1.0;
242       return AliRsnPID::kUnknown;
243     case kPerfect:
244       prob = 1.0;
245       if (fMCInfo) return AliRsnPID::InternalType(fMCInfo->PDG());
246       else return AliRsnPID::kUnknown;
247     default:
248       if (fRealisticPID >= 0 && fRealisticPID < AliRsnPID::kSpecies)
249       {
250         prob = fPIDProb[fRealisticPID];
251         return fRealisticPID;
252       }
253       else
254       {
255         prob = 1.0;
256         return AliRsnPID::kUnknown;
257       }
258   }
259 }
260
261 //_____________________________________________________________________________
262 void AliRsnDaughter::Print(Option_t *option) const
263 {
264 //
265 // Prints the values of data members, using the options:
266 // - P --> momentum
267 // - V --> DCA vertex
268 // - C --> electric charge
269 // - F --> flags
270 // - I --> identification (PID, probability and mass)
271 // - W --> PID weights
272 // - M --> Montecarlo (from AliRsnMCInfo)
273 // - L --> index & label
274 // - A --> angles
275 // - ALL --> All oprions switched on
276 //
277 // Index and label are printed by default.
278 //
279
280   TString opt(option);
281   opt.ToUpper();
282
283   if (opt.Contains("L") || opt.Contains("ALL"))
284   {
285     cout << ".......Index            : " << fIndex << endl;
286     cout << ".......Label            : " << fLabel << endl;
287   }
288   if (opt.Contains("P") || opt.Contains("ALL"))
289   {
290     cout << ".......Px, Py, Pz, Pt   : " << Px() << ' ' << Py() << ' ' << Pz() << ' ' << Pt() << endl;
291   }
292   if (opt.Contains("A") || opt.Contains("ALL"))
293   {
294     cout << ".......Phi, Theta       : " << Phi() << ' ' << Theta() << endl;
295   }
296   if (opt.Contains("V") || opt.Contains("ALL"))
297   {
298     cout << ".......Vx, Vy, Vz       : " << Xv() << ' ' << Yv() << ' ' << Zv() << endl;
299   }
300   if (opt.Contains("I") || opt.Contains("ALL"))
301   {
302     AliRsnPID::EType type;
303     Double_t prob;
304     type = PIDType(prob);
305     cout << ".......PID & prob       : " << AliRsnPID::ParticleName(type) << ' ' << prob << endl;
306   }
307   if (opt.Contains("C") || opt.Contains("ALL"))
308   {
309     cout << ".......Charge           : " << fCharge << endl;
310   }
311   if (opt.Contains("F") || opt.Contains("ALL"))
312   {
313     cout << ".......Flags            : " << fFlags << endl;
314   }
315   if (opt.Contains("W") || opt.Contains("ALL"))
316   {
317     cout << ".......Weights          : ";
318     Int_t i;
319     for (i = 0; i < AliRsnPID::kSpecies; i++) cout << fPIDWeight[i] << ' ';
320     cout << endl;
321   }
322   if (opt.Contains("M") || opt.Contains("ALL"))
323   {
324     if (fMCInfo)
325     {
326       cout << ".......PDG code         : " << fMCInfo->PDG() << endl;
327       cout << ".......Mother (label)   : " << fMCInfo->Mother() << endl;
328       cout << ".......Mother (PDG code): " << fMCInfo->MotherPDG() << endl;
329     }
330     else
331     {
332       cout << ".......MC info not present" << endl;
333     }
334   }
335 }
336
337 //_____________________________________________________________________________
338 void AliRsnDaughter::InitMCInfo()
339 {
340 //
341 // Initializes the particle object with default constructor.
342 //
343
344   fMCInfo = new AliRsnMCInfo;
345 }
346
347 //_____________________________________________________________________________
348 Bool_t AliRsnDaughter::InitMCInfo(TParticle *particle)
349 {
350 //
351 // Copies data from an MC particle into the object which
352 // contains all MC details taken from kinematics info.
353 // If requested by second argument, momentum and vertex
354 // of the Particle are copied into the 'fP' and 'fV'
355 // data members, to simulate a perfect reconstruction.
356 // If something goes wrong, returns kFALSE,
357 // otherwise returns kTRUE.
358 //
359
360   // retrieve the TParticle object pointed by this MC track
361   if (!particle)
362   {
363     AliError("Passed NULL particle object");
364     return kFALSE;
365   }
366
367   // initialize object if not initialized yet
368   if (fMCInfo) delete fMCInfo;
369   fMCInfo = new AliRsnMCInfo;
370   fMCInfo->Adopt(particle);
371
372   return kTRUE;
373 }
374
375 //_____________________________________________________________________________
376 Int_t AliRsnDaughter::Compare(const TObject* obj) const
377 {
378 //
379 // Compare two tracks with respect to their transverse momentum.
380 // Citation from ROOT reference:
381 // "Must return -1 if this is smaller than obj, 0 if objects are equal
382 //  and 1 if this is larger than obj".
383 //
384
385   AliRsnDaughter *that = (AliRsnDaughter*)obj;
386   if (Pt() < that->Pt()) return 1;
387   else if (Pt() > that->Pt()) return -1;
388   else return 0;
389 }