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