]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliAODTrack.cxx
Coverity fixes
[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(),
02153d58 43 fID(-999),
9333290e 44 fCharge(-99),
e1c744ca 45 fType(kUndef),
9333290e 46 fCovMatrix(NULL),
7be1db84 47 fDetPid(NULL),
48 fProdVertex(NULL)
df9db588 49{
50 // default constructor
51
52 SetP();
53 SetPosition((Float_t*)NULL);
6c954176 54 SetXYAtDCA(-999., -999.);
55 SetPxPyPzAtDCA(-999., -999., -999.);
df9db588 56 SetPID((Float_t*)NULL);
57}
58
59//______________________________________________________________________________
02153d58 60AliAODTrack::AliAODTrack(Short_t id,
df9db588 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,
1912763f 71 Bool_t usedForVtxFit,
dc825b15 72 Bool_t usedForPrimVtxFit,
ec40c484 73 AODTrk_t ttype,
862ce351 74 UInt_t selectInfo,
75 Float_t chi2perNDF) :
4f6e22bd 76 AliVTrack(),
f43586f0 77 fRAtAbsorberEnd(0.),
862ce351 78 fChi2perNDF(chi2perNDF),
9333290e 79 fChi2MatchTrigger(0.),
6efb741f 80 fFlags(0),
df9db588 81 fLabel(label),
6c954176 82 fITSMuonClusterMap(0),
9333290e 83 fFilterMap(selectInfo),
d999f2e6 84 fTPCClusterMap(),
85 fTPCSharedMap(),
02153d58 86 fID(id),
9333290e 87 fCharge(charge),
e1c744ca 88 fType(ttype),
9333290e 89 fCovMatrix(NULL),
7be1db84 90 fDetPid(NULL),
9333290e 91 fProdVertex(prodVertex)
df9db588 92{
93 // constructor
94
95 SetP(p, cartesian);
96 SetPosition(x, isDCA);
6c954176 97 SetXYAtDCA(-999., -999.);
98 SetPxPyPzAtDCA(-999., -999., -999.);
1912763f 99 SetUsedForVtxFit(usedForVtxFit);
dc825b15 100 SetUsedForPrimVtxFit(usedForPrimVtxFit);
df9db588 101 if(covMatrix) SetCovMatrix(covMatrix);
102 SetPID(pid);
6c954176 103 SetITSClusterMap(itsClusMap);
df9db588 104}
105
106//______________________________________________________________________________
02153d58 107AliAODTrack::AliAODTrack(Short_t id,
df9db588 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,
1912763f 118 Bool_t usedForVtxFit,
dc825b15 119 Bool_t usedForPrimVtxFit,
ec40c484 120 AODTrk_t ttype,
862ce351 121 UInt_t selectInfo,
122 Float_t chi2perNDF) :
4f6e22bd 123 AliVTrack(),
f43586f0 124 fRAtAbsorberEnd(0.),
862ce351 125 fChi2perNDF(chi2perNDF),
9333290e 126 fChi2MatchTrigger(0.),
6efb741f 127 fFlags(0),
df9db588 128 fLabel(label),
6c954176 129 fITSMuonClusterMap(0),
9333290e 130 fFilterMap(selectInfo),
d999f2e6 131 fTPCClusterMap(),
132 fTPCSharedMap(),
02153d58 133 fID(id),
9333290e 134 fCharge(charge),
e1c744ca 135 fType(ttype),
9333290e 136 fCovMatrix(NULL),
7be1db84 137 fDetPid(NULL),
9333290e 138 fProdVertex(prodVertex)
df9db588 139{
140 // constructor
141
142 SetP(p, cartesian);
143 SetPosition(x, isDCA);
6c954176 144 SetXYAtDCA(-999., -999.);
145 SetPxPyPzAtDCA(-999., -999., -999.);
1912763f 146 SetUsedForVtxFit(usedForVtxFit);
dc825b15 147 SetUsedForPrimVtxFit(usedForPrimVtxFit);
df9db588 148 if(covMatrix) SetCovMatrix(covMatrix);
149 SetPID(pid);
6c954176 150 SetITSClusterMap(itsClusMap);
df9db588 151}
152
df9db588 153//______________________________________________________________________________
154AliAODTrack::~AliAODTrack()
155{
156 // destructor
157 delete fCovMatrix;
7450f8ab 158 delete fDetPid;
df9db588 159}
160
161
162//______________________________________________________________________________
163AliAODTrack::AliAODTrack(const AliAODTrack& trk) :
4f6e22bd 164 AliVTrack(trk),
f43586f0 165 fRAtAbsorberEnd(trk.fRAtAbsorberEnd),
1912763f 166 fChi2perNDF(trk.fChi2perNDF),
9333290e 167 fChi2MatchTrigger(trk.fChi2MatchTrigger),
6efb741f 168 fFlags(trk.fFlags),
df9db588 169 fLabel(trk.fLabel),
1912763f 170 fITSMuonClusterMap(trk.fITSMuonClusterMap),
9333290e 171 fFilterMap(trk.fFilterMap),
d999f2e6 172 fTPCClusterMap(trk.fTPCClusterMap),
173 fTPCSharedMap(trk.fTPCSharedMap),
02153d58 174 fID(trk.fID),
9333290e 175 fCharge(trk.fCharge),
e1c744ca 176 fType(trk.fType),
9333290e 177 fCovMatrix(NULL),
7be1db84 178 fDetPid(NULL),
9333290e 179 fProdVertex(trk.fProdVertex)
df9db588 180{
181 // Copy constructor
182
183 trk.GetP(fMomentum);
184 trk.GetPosition(fPosition);
6c954176 185 SetXYAtDCA(trk.XAtDCA(), trk.YAtDCA());
186 SetPxPyPzAtDCA(trk.PxAtDCA(), trk.PyAtDCA(), trk.PzAtDCA());
1912763f 187 SetUsedForVtxFit(trk.GetUsedForVtxFit());
dc825b15 188 SetUsedForPrimVtxFit(trk.GetUsedForPrimVtxFit());
5d62ce04 189 if(trk.fCovMatrix) fCovMatrix=new AliAODRedCov<6>(*trk.fCovMatrix);
7be1db84 190 if(trk.fDetPid) fDetPid=new AliAODPid(*trk.fDetPid);
df9db588 191 SetPID(trk.fPID);
df9db588 192}
193
194//______________________________________________________________________________
195AliAODTrack& AliAODTrack::operator=(const AliAODTrack& trk)
196{
197 // Assignment operator
198 if(this!=&trk) {
199
4f6e22bd 200 AliVTrack::operator=(trk);
df9db588 201
202 trk.GetP(fMomentum);
203 trk.GetPosition(fPosition);
204 trk.GetPID(fPID);
205
6c954176 206 SetXYAtDCA(trk.XAtDCA(), trk.YAtDCA());
207 SetPxPyPzAtDCA(trk.PxAtDCA(), trk.PyAtDCA(), trk.PzAtDCA());
208
f43586f0 209 fRAtAbsorberEnd = trk.fRAtAbsorberEnd;
210
1912763f 211 fChi2perNDF = trk.fChi2perNDF;
9333290e 212 fChi2MatchTrigger = trk.fChi2MatchTrigger;
df9db588 213
6efb741f 214 fFlags = trk.fFlags;
df9db588 215 fLabel = trk.fLabel;
216
9333290e 217 fITSMuonClusterMap = trk.fITSMuonClusterMap;
218 fFilterMap = trk.fFilterMap;
219
6efb741f 220 fID = trk.fID;
221
9333290e 222 fCharge = trk.fCharge;
223 fType = trk.fType;
224
df9db588 225 delete fCovMatrix;
5d62ce04 226 if(trk.fCovMatrix) fCovMatrix=new AliAODRedCov<6>(*trk.fCovMatrix);
df9db588 227 else fCovMatrix=NULL;
228 fProdVertex = trk.fProdVertex;
229
1912763f 230 SetUsedForVtxFit(trk.GetUsedForVtxFit());
dc825b15 231 SetUsedForPrimVtxFit(trk.GetUsedForPrimVtxFit());
7be1db84 232
233 delete fDetPid;
234 if(trk.fDetPid) fDetPid=new AliAODPid(*trk.fDetPid);
235 else fDetPid=NULL;
df9db588 236 }
237
238 return *this;
239}
240
4697e4fb 241//______________________________________________________________________________
242Double_t AliAODTrack::M(AODTrkPID_t pid) const
243{
244 // Returns the mass.
9861edc0 245 // Masses for nuclei don't exist in the PDG tables, therefore they were put by hand.
4697e4fb 246
247 switch (pid) {
248
249 case kElectron :
9861edc0 250 return 0.000510999; //TDatabasePDG::Instance()->GetParticle(11/*::kElectron*/)->Mass();
4697e4fb 251 break;
252
253 case kMuon :
9861edc0 254 return 0.1056584; //TDatabasePDG::Instance()->GetParticle(13/*::kMuonMinus*/)->Mass();
4697e4fb 255 break;
256
257 case kPion :
9861edc0 258 return 0.13957; //TDatabasePDG::Instance()->GetParticle(211/*::kPiPlus*/)->Mass();
4697e4fb 259 break;
260
261 case kKaon :
9861edc0 262 return 0.4937; //TDatabasePDG::Instance()->GetParticle(321/*::kKPlus*/)->Mass();
4697e4fb 263 break;
264
265 case kProton :
9861edc0 266 return 0.9382720; //TDatabasePDG::Instance()->GetParticle(2212/*::kProton*/)->Mass();
4697e4fb 267 break;
268
269 case kDeuteron :
9861edc0 270 return 1.8756; //TDatabasePDG::Instance()->GetParticle(1000010020)->Mass();
4697e4fb 271 break;
272
273 case kTriton :
9861edc0 274 return 2.8089; //TDatabasePDG::Instance()->GetParticle(1000010030)->Mass();
4697e4fb 275 break;
276
277 case kHelium3 :
9861edc0 278 return 2.8084; //TDatabasePDG::Instance()->GetParticle(1000020030)->Mass();
4697e4fb 279 break;
280
281 case kAlpha :
9861edc0 282 return 3.7274; //TDatabasePDG::Instance()->GetParticle(1000020040)->Mass();
4697e4fb 283 break;
284
285 case kUnknown :
286 return -999.;
287 break;
288
289 default :
290 return -999.;
291 }
292}
293
294//______________________________________________________________________________
295Double_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//______________________________________________________________________________
308Double_t AliAODTrack::Y(AODTrkPID_t pid) const
309{
9861edc0 310 // Returns the rapidity of a particle of a given pid.
4697e4fb 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//______________________________________________________________________________
326Double_t AliAODTrack::Y(Double_t m) const
327{
9861edc0 328 // Returns the rapidity of a particle of a given mass.
4697e4fb 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//______________________________________________________________________________
344AliAODTrack::AODTrkPID_t AliAODTrack::GetMostProbablePID() const
345{
346 // Returns the most probable PID array element.
347
348 Int_t nPID = 10;
7ba6f91a 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;
4697e4fb 361 }
362 }
4697e4fb 363 }
7ba6f91a 364 return allTheSame ? kUnknown : loc;
4697e4fb 365}
366
367//______________________________________________________________________________
368void 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.;
8a1418dc 375 fPID[kTriton] = 0.;
376 fPID[kHelium3] = 0.;
377 fPID[kAlpha] = 0.;
378 fPID[kUnknown] = 0.;
4697e4fb 379
380 return;
381}
382
383
df9db588 384//______________________________________________________________________________
385template <class T> void AliAODTrack::SetP(const T *p, const Bool_t cartesian)
386{
8a1418dc 387 // Set the momentum
df9db588 388
389 if (p) {
390 if (cartesian) {
16b65f2a 391 Double_t pt2 = p[0]*p[0] + p[1]*p[1];
0c5f89fb 392 Double_t pp = TMath::Sqrt(pt2 + p[2]*p[2]);
df9db588 393
16b65f2a 394 fMomentum[0] = TMath::Sqrt(pt2); // pt
b1a9edc8 395 fMomentum[1] = (pt2 != 0.) ? TMath::Pi()+TMath::ATan2(-p[1], -p[0]) : -999; // phi
0c5f89fb 396 fMomentum[2] = (pp != 0.) ? TMath::ACos(p[2] / pp) : -999.; // theta
df9db588 397 } else {
16b65f2a 398 fMomentum[0] = p[0]; // pt
df9db588 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//______________________________________________________________________________
410template <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//______________________________________________________________________________
438void 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//______________________________________________________________________________
448void 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());
1912763f 460 printf(" chi2/NDF = %f\n", Chi2perNDF());
df9db588 461 printf(" charge = %d\n", Charge());
df9db588 462}
463
2200238e 464//______________________________________________________________________________
465void AliAODTrack::SetMatchTrigger(Int_t matchTrig)
466{
467 // Set the MUON trigger information
8ac4fa64 468 switch(matchTrig){
e1c744ca 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;
8ac4fa64 483 AliWarning(Form("unknown case for matchTrig: %d\n",matchTrig));
e1c744ca 484 }
485}
486
2200238e 487//______________________________________________________________________________
488Bool_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
e1c744ca 506 }
2200238e 507
508 return kFALSE;
e1c744ca 509}
510
2200238e 511//______________________________________________________________________________
512Bool_t AliAODTrack::MatchTriggerDigits() const
513{
514 // return kTRUE if the track matches a digit on both planes of at least 2 trigger chambers
6c954176 515
2200238e 516 Int_t nMatchedChambers = 0;
517 for (Int_t ich=10; ich<14; ich++) if (HitsMuonChamber(ich)) nMatchedChambers++;
518
519 return (nMatchedChambers >= 2);
e1c744ca 520}
c683ddc2 521
6dc40b1c 522//______________________________________________________________________________
523Bool_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
c8fe2783 555//______________________________________________________________________________
556Bool_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}