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