]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliAODTrack.cxx
Coverity
[u/mrichter/AliRoot.git] / STEER / AliAODTrack.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-2007, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /* $Id$ */
17
18 //-------------------------------------------------------------------------
19 //     AOD track implementation of AliVTrack
20 //     Author: Markus Oldenburg, CERN
21 //     Markus.Oldenburg@cern.ch
22 //-------------------------------------------------------------------------
23
24 #include "AliLog.h"
25 #include "AliExternalTrackParam.h"
26 #include "AliVVertex.h"
27 #include "AliAODTrack.h"
28
29 ClassImp(AliAODTrack)
30
31 //______________________________________________________________________________
32 AliAODTrack::AliAODTrack() : 
33   AliVTrack(),
34   fRAtAbsorberEnd(0.),
35   fChi2perNDF(-999.),
36   fChi2MatchTrigger(0.),
37   fFlags(0),
38   fLabel(-999),
39   fITSMuonClusterMap(0),
40   fFilterMap(0),
41   fTPCClusterMap(),
42   fTPCSharedMap(),
43   fID(-999),
44   fCharge(-99),
45   fType(kUndef),
46   fCovMatrix(NULL),
47   fDetPid(NULL),
48   fProdVertex(NULL)
49 {
50   // default constructor
51
52   SetP();
53   SetPosition((Float_t*)NULL);
54   SetXYAtDCA(-999., -999.);
55   SetPxPyPzAtDCA(-999., -999., -999.);
56   SetPID((Float_t*)NULL);
57 }
58
59 //______________________________________________________________________________
60 AliAODTrack::AliAODTrack(Short_t id,
61                          Int_t label, 
62                          Double_t p[3],
63                          Bool_t cartesian,
64                          Double_t x[3],
65                          Bool_t isDCA,
66                          Double_t covMatrix[21],
67                          Short_t charge,
68                          UChar_t itsClusMap,
69                          Double_t pid[10],
70                          AliAODVertex *prodVertex,
71                          Bool_t usedForVtxFit,
72                          Bool_t usedForPrimVtxFit,
73                          AODTrk_t ttype,
74                          UInt_t selectInfo,
75                          Float_t chi2perNDF) :
76   AliVTrack(),
77   fRAtAbsorberEnd(0.),
78   fChi2perNDF(chi2perNDF),
79   fChi2MatchTrigger(0.),
80   fFlags(0),
81   fLabel(label),
82   fITSMuonClusterMap(0),
83   fFilterMap(selectInfo),
84   fTPCClusterMap(),
85   fTPCSharedMap(),
86   fID(id),
87   fCharge(charge),
88   fType(ttype),
89   fCovMatrix(NULL),
90   fDetPid(NULL),
91   fProdVertex(prodVertex)
92 {
93   // constructor
94  
95   SetP(p, cartesian);
96   SetPosition(x, isDCA);
97   SetXYAtDCA(-999., -999.);
98   SetPxPyPzAtDCA(-999., -999., -999.);
99   SetUsedForVtxFit(usedForVtxFit);
100   SetUsedForPrimVtxFit(usedForPrimVtxFit);
101   if(covMatrix) SetCovMatrix(covMatrix);
102   SetPID(pid);
103   SetITSClusterMap(itsClusMap);
104 }
105
106 //______________________________________________________________________________
107 AliAODTrack::AliAODTrack(Short_t id,
108                          Int_t label, 
109                          Float_t p[3],
110                          Bool_t cartesian,
111                          Float_t x[3],
112                          Bool_t isDCA,
113                          Float_t covMatrix[21],
114                          Short_t charge,
115                          UChar_t itsClusMap,
116                          Float_t pid[10],
117                          AliAODVertex *prodVertex,
118                          Bool_t usedForVtxFit,
119                          Bool_t usedForPrimVtxFit,
120                          AODTrk_t ttype,
121                          UInt_t selectInfo,
122                          Float_t chi2perNDF) :
123   AliVTrack(),
124   fRAtAbsorberEnd(0.),
125   fChi2perNDF(chi2perNDF),
126   fChi2MatchTrigger(0.),
127   fFlags(0),
128   fLabel(label),
129   fITSMuonClusterMap(0),
130   fFilterMap(selectInfo),
131   fTPCClusterMap(),
132   fTPCSharedMap(),
133   fID(id),
134   fCharge(charge),
135   fType(ttype),
136   fCovMatrix(NULL),
137   fDetPid(NULL),
138   fProdVertex(prodVertex)
139 {
140   // constructor
141  
142   SetP(p, cartesian);
143   SetPosition(x, isDCA);
144   SetXYAtDCA(-999., -999.);
145   SetPxPyPzAtDCA(-999., -999., -999.);
146   SetUsedForVtxFit(usedForVtxFit);
147   SetUsedForPrimVtxFit(usedForPrimVtxFit);
148   if(covMatrix) SetCovMatrix(covMatrix);
149   SetPID(pid);
150   SetITSClusterMap(itsClusMap);
151 }
152
153 //______________________________________________________________________________
154 AliAODTrack::~AliAODTrack() 
155 {
156   // destructor
157   delete fCovMatrix;
158   delete fDetPid;
159 }
160
161
162 //______________________________________________________________________________
163 AliAODTrack::AliAODTrack(const AliAODTrack& trk) :
164   AliVTrack(trk),
165   fRAtAbsorberEnd(trk.fRAtAbsorberEnd),
166   fChi2perNDF(trk.fChi2perNDF),
167   fChi2MatchTrigger(trk.fChi2MatchTrigger),
168   fFlags(trk.fFlags),
169   fLabel(trk.fLabel),
170   fITSMuonClusterMap(trk.fITSMuonClusterMap),
171   fFilterMap(trk.fFilterMap),
172   fTPCClusterMap(trk.fTPCClusterMap),
173   fTPCSharedMap(trk.fTPCSharedMap),
174   fID(trk.fID),
175   fCharge(trk.fCharge),
176   fType(trk.fType),
177   fCovMatrix(NULL),
178   fDetPid(NULL),
179   fProdVertex(trk.fProdVertex)
180 {
181   // Copy constructor
182
183   trk.GetP(fMomentum);
184   trk.GetPosition(fPosition);
185   SetXYAtDCA(trk.XAtDCA(), trk.YAtDCA());
186   SetPxPyPzAtDCA(trk.PxAtDCA(), trk.PyAtDCA(), trk.PzAtDCA());
187   SetUsedForVtxFit(trk.GetUsedForVtxFit());
188   SetUsedForPrimVtxFit(trk.GetUsedForPrimVtxFit());
189   if(trk.fCovMatrix) fCovMatrix=new AliAODRedCov<6>(*trk.fCovMatrix);
190   if(trk.fDetPid) fDetPid=new AliAODPid(*trk.fDetPid);
191   SetPID(trk.fPID);
192 }
193
194 //______________________________________________________________________________
195 AliAODTrack& AliAODTrack::operator=(const AliAODTrack& trk)
196 {
197   // Assignment operator
198   if(this!=&trk) {
199
200     AliVTrack::operator=(trk);
201
202     trk.GetP(fMomentum);
203     trk.GetPosition(fPosition);
204     trk.GetPID(fPID);
205
206     SetXYAtDCA(trk.XAtDCA(), trk.YAtDCA());
207     SetPxPyPzAtDCA(trk.PxAtDCA(), trk.PyAtDCA(), trk.PzAtDCA());
208     
209     fRAtAbsorberEnd = trk.fRAtAbsorberEnd;
210     
211     fChi2perNDF = trk.fChi2perNDF;
212     fChi2MatchTrigger = trk.fChi2MatchTrigger;
213
214     fFlags = trk.fFlags;
215     fLabel = trk.fLabel;    
216     
217     fITSMuonClusterMap = trk.fITSMuonClusterMap;
218     fFilterMap = trk.fFilterMap;
219
220     fID = trk.fID;
221
222     fCharge = trk.fCharge;
223     fType = trk.fType;
224
225     delete fCovMatrix;
226     if(trk.fCovMatrix) fCovMatrix=new AliAODRedCov<6>(*trk.fCovMatrix);
227     else fCovMatrix=NULL;
228     fProdVertex = trk.fProdVertex;
229
230     SetUsedForVtxFit(trk.GetUsedForVtxFit());
231     SetUsedForPrimVtxFit(trk.GetUsedForPrimVtxFit());
232
233     delete fDetPid;
234     if(trk.fDetPid) fDetPid=new AliAODPid(*trk.fDetPid);
235     else fDetPid=NULL;
236   }
237
238   return *this;
239 }
240
241 //______________________________________________________________________________
242 Double_t AliAODTrack::M(AODTrkPID_t pid) const
243 {
244   // Returns the mass.
245   // Masses for nuclei don't exist in the PDG tables, therefore they were put by hand.
246
247   switch (pid) {
248
249   case kElectron :
250     return 0.000510999; //TDatabasePDG::Instance()->GetParticle(11/*::kElectron*/)->Mass();
251     break;
252
253   case kMuon :
254     return 0.1056584; //TDatabasePDG::Instance()->GetParticle(13/*::kMuonMinus*/)->Mass();
255     break;
256
257   case kPion :
258     return 0.13957; //TDatabasePDG::Instance()->GetParticle(211/*::kPiPlus*/)->Mass();
259     break;
260
261   case kKaon :
262     return 0.4937; //TDatabasePDG::Instance()->GetParticle(321/*::kKPlus*/)->Mass();
263     break;
264
265   case kProton :
266     return 0.9382720; //TDatabasePDG::Instance()->GetParticle(2212/*::kProton*/)->Mass();
267     break;
268
269   case kDeuteron :
270     return 1.8756; //TDatabasePDG::Instance()->GetParticle(1000010020)->Mass();
271     break;
272
273   case kTriton :
274     return 2.8089; //TDatabasePDG::Instance()->GetParticle(1000010030)->Mass();
275     break;
276
277   case kHelium3 :
278     return 2.8084; //TDatabasePDG::Instance()->GetParticle(1000020030)->Mass();
279     break;
280
281   case kAlpha :
282     return 3.7274; //TDatabasePDG::Instance()->GetParticle(1000020040)->Mass();
283     break;
284
285   case kUnknown :
286     return -999.;
287     break;
288
289   default :
290     return -999.;
291   }
292 }
293
294 //______________________________________________________________________________
295 Double_t AliAODTrack::E(AODTrkPID_t pid) const
296 {
297   // Returns the energy of the particle of a given pid.
298   
299   if (pid != kUnknown) { // particle was identified
300     Double_t m = M(pid);
301     return TMath::Sqrt(P()*P() + m*m);
302   } else { // pid unknown
303     return -999.;
304   }
305 }
306
307 //______________________________________________________________________________
308 Double_t AliAODTrack::Y(AODTrkPID_t pid) const
309 {
310   // Returns the rapidity of a particle of a given pid.
311   
312   if (pid != kUnknown) { // particle was identified
313     Double_t e = E(pid);
314     Double_t pz = Pz();
315     if (e>=0 && e!=pz) { // energy was positive (e.g. not -999.) and not equal to pz
316       return 0.5*TMath::Log((e+pz)/(e-pz));
317     } else { // energy not known or equal to pz
318       return -999.;
319     }
320   } else { // pid unknown
321     return -999.;
322   }
323 }
324
325 //______________________________________________________________________________
326 Double_t AliAODTrack::Y(Double_t m) const
327 {
328   // Returns the rapidity of a particle of a given mass.
329   
330   if (m >= 0.) { // mass makes sense
331     Double_t e = E(m);
332     Double_t pz = Pz();
333     if (e>=0 && e!=pz) { // energy was positive (e.g. not -999.) and not equal to pz
334       return 0.5*TMath::Log((e+pz)/(e-pz));
335     } else { // energy not known or equal to pz
336       return -999.;
337     }
338   } else { // pid unknown
339     return -999.;
340   }
341 }
342
343 //______________________________________________________________________________
344 AliAODTrack::AODTrkPID_t AliAODTrack::GetMostProbablePID() const 
345 {
346   // Returns the most probable PID array element.
347   
348   Int_t nPID = 10;
349   AODTrkPID_t loc = kUnknown;
350   Double_t max = 0.;
351   Bool_t allTheSame = kTRUE;
352   
353   for (Int_t iPID = 0; iPID < nPID; iPID++) {
354     if (fPID[iPID] >= max) {
355       if (fPID[iPID] > max) {
356         allTheSame = kFALSE;
357         max = fPID[iPID];
358         loc = (AODTrkPID_t)iPID;
359       } else {
360         allTheSame = kTRUE;
361       }
362     }
363   }
364   return allTheSame ? kUnknown : loc;
365 }
366
367 //______________________________________________________________________________
368 void AliAODTrack::ConvertAliPIDtoAODPID()
369 {
370   // Converts AliPID array.
371   // The numbering scheme is the same for electrons, muons, pions, kaons, and protons.
372   // Everything else has to be set to zero.
373
374   fPID[kDeuteron] = 0.;
375   fPID[kTriton]   = 0.;
376   fPID[kHelium3]  = 0.;
377   fPID[kAlpha]    = 0.;
378   fPID[kUnknown]  = 0.;
379   
380   return;
381 }
382
383
384 //______________________________________________________________________________
385 template <class T> void AliAODTrack::SetP(const T *p, const Bool_t cartesian) 
386 {
387   // Set the momentum
388
389   if (p) {
390     if (cartesian) {
391       Double_t pt2 = p[0]*p[0] + p[1]*p[1];
392       Double_t pp  = TMath::Sqrt(pt2 + p[2]*p[2]);
393       
394       fMomentum[0] = TMath::Sqrt(pt2); // pt
395       fMomentum[1] = (pt2 != 0.) ? TMath::Pi()+TMath::ATan2(-p[1], -p[0]) : -999; // phi
396       fMomentum[2] = (pp != 0.) ? TMath::ACos(p[2] / pp) : -999.; // theta
397     } else {
398       fMomentum[0] = p[0];  // pt
399       fMomentum[1] = p[1];  // phi
400       fMomentum[2] = p[2];  // theta
401     }
402   } else {
403     fMomentum[0] = -999.;
404     fMomentum[1] = -999.;
405     fMomentum[2] = -999.;
406   }
407 }
408
409 //______________________________________________________________________________
410 template <class T> void AliAODTrack::SetPosition(const T *x, const Bool_t dca) 
411 {
412   // set the position
413
414   if (x) {
415     if (!dca) {
416       ResetBit(kIsDCA);
417
418       fPosition[0] = x[0];
419       fPosition[1] = x[1];
420       fPosition[2] = x[2];
421     } else {
422       SetBit(kIsDCA);
423       // don't know any better yet
424       fPosition[0] = -999.;
425       fPosition[1] = -999.;
426       fPosition[2] = -999.;
427     }
428   } else {
429     ResetBit(kIsDCA);
430
431     fPosition[0] = -999.;
432     fPosition[1] = -999.;
433     fPosition[2] = -999.;
434   }
435 }
436
437 //______________________________________________________________________________
438 void AliAODTrack::SetDCA(Double_t d, Double_t z) 
439 {
440   // set the dca
441   fPosition[0] = d;
442   fPosition[1] = z;
443   fPosition[2] = 0.;
444   SetBit(kIsDCA);
445 }
446
447 //______________________________________________________________________________
448 void AliAODTrack::Print(Option_t* /* option */) const
449 {
450   // prints information about AliAODTrack
451
452   printf("Object name: %s   Track type: %s\n", GetName(), GetTitle()); 
453   printf("        px = %f\n", Px());
454   printf("        py = %f\n", Py());
455   printf("        pz = %f\n", Pz());
456   printf("        pt = %f\n", Pt());
457   printf("      1/pt = %f\n", OneOverPt());
458   printf("     theta = %f\n", Theta());
459   printf("       phi = %f\n", Phi());
460   printf("  chi2/NDF = %f\n", Chi2perNDF());
461   printf("    charge = %d\n", Charge());
462 }
463
464 //______________________________________________________________________________
465 void AliAODTrack::SetMatchTrigger(Int_t matchTrig)
466 {
467   // Set the MUON trigger information
468   switch(matchTrig){
469     case 0: // 0 track does not match trigger
470       fITSMuonClusterMap=fITSMuonClusterMap&0x3fffffff;
471       break;
472     case 1: // 1 track match but does not pass pt cut
473       fITSMuonClusterMap=(fITSMuonClusterMap&0x3fffffff)|0x40000000;
474       break;
475     case 2: // 2 track match Low pt cut
476       fITSMuonClusterMap=(fITSMuonClusterMap&0x3fffffff)|0x80000000;
477       break;
478     case 3: // 3 track match High pt cut
479       fITSMuonClusterMap=fITSMuonClusterMap|0xc0000000;
480       break;
481     default:
482       fITSMuonClusterMap=fITSMuonClusterMap&0x3fffffff;
483       AliWarning(Form("unknown case for matchTrig: %d\n",matchTrig));
484   }
485 }
486
487 //______________________________________________________________________________
488 Bool_t AliAODTrack::HitsMuonChamber(Int_t MuonChamber, Int_t cathode) const
489 {
490   // return kTRUE if the track fires the given tracking or trigger chamber.
491   // If the chamber is a trigger one:
492   // - if cathode = 0 or 1, the track matches the corresponding cathode
493   // - if cathode = -1, the track matches both cathodes
494   
495   if (MuonChamber < 0) return kFALSE;
496   
497   if (MuonChamber < 10) return TESTBIT(GetMUONClusterMap(), MuonChamber);
498   
499   if (MuonChamber < 14) {
500     
501     if (cathode < 0) return TESTBIT(GetHitsPatternInTrigCh(), 13-MuonChamber) &&
502                             TESTBIT(GetHitsPatternInTrigCh(), 13-MuonChamber+4);
503     
504     if (cathode < 2) return TESTBIT(GetHitsPatternInTrigCh(), 13-MuonChamber+(1-cathode)*4);
505     
506   }
507   
508   return kFALSE;
509 }
510
511 //______________________________________________________________________________
512 Bool_t AliAODTrack::MatchTriggerDigits() const
513 {
514   // return kTRUE if the track matches a digit on both planes of at least 2 trigger chambers
515   
516   Int_t nMatchedChambers = 0;
517   for (Int_t ich=10; ich<14; ich++) if (HitsMuonChamber(ich)) nMatchedChambers++;
518   
519   return (nMatchedChambers >= 2);
520 }
521
522 //______________________________________________________________________________
523 Bool_t AliAODTrack::PropagateToDCA(const AliVVertex *vtx, 
524     Double_t b, Double_t maxd, Double_t dz[2], Double_t covar[3])
525 {
526   // compute impact parameters to the vertex vtx and their covariance matrix
527   // b is the Bz, needed to propagate correctly the track to vertex 
528   // only the track parameters are update after the propagation (pos and mom),
529   // not the covariance matrix. This is OK for propagation over short distance
530   // inside the beam pipe.
531   // return kFALSE is something went wrong
532
533   // convert to AliExternalTrackParam
534   AliExternalTrackParam etp(this);  
535
536   Float_t xstart = etp.GetX();
537   if(xstart>3.) {
538     AliError("This method can be used only for propagation inside the beam pipe");
539     return kFALSE; 
540   }
541
542   if(!etp.PropagateToDCA(vtx,b,maxd,dz,covar)) return kFALSE;
543
544   // update track position and momentum
545   Double_t mom[3];
546   etp.GetPxPyPz(mom);
547   SetP(mom,kTRUE);
548   etp.GetXYZ(mom);
549   SetPosition(mom,kFALSE);
550
551
552   return kTRUE;
553 }
554
555 //______________________________________________________________________________
556 Bool_t AliAODTrack::GetPxPyPz(Double_t p[3]) const 
557 {
558     //---------------------------------------------------------------------
559     // This function returns the global track momentum components
560     //---------------------------------------------------------------------
561   p[0]=Px(); p[1]=Py(); p[2]=Pz();
562   return kTRUE;
563 }