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