]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliAODTrack.cxx
1) corrections for 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(),
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;
349 if (fPID) {
350 AODTrkPID_t loc = kUnknown;
351 Double_t max = 0.;
352 Bool_t allTheSame = kTRUE;
353
354 for (Int_t iPID = 0; iPID < nPID; iPID++) {
355 if (fPID[iPID] >= max) {
356 if (fPID[iPID] > max) {
357 allTheSame = kFALSE;
358 max = fPID[iPID];
359 loc = (AODTrkPID_t)iPID;
360 } else {
361 allTheSame = kTRUE;
362 }
363 }
364 }
365
366 return allTheSame ? kUnknown : loc;
367 } else {
368 return kUnknown;
369 }
370}
371
372//______________________________________________________________________________
373void AliAODTrack::ConvertAliPIDtoAODPID()
374{
375 // Converts AliPID array.
376 // The numbering scheme is the same for electrons, muons, pions, kaons, and protons.
377 // Everything else has to be set to zero.
378
379 fPID[kDeuteron] = 0.;
8a1418dc 380 fPID[kTriton] = 0.;
381 fPID[kHelium3] = 0.;
382 fPID[kAlpha] = 0.;
383 fPID[kUnknown] = 0.;
4697e4fb 384
385 return;
386}
387
388
df9db588 389//______________________________________________________________________________
390template <class T> void AliAODTrack::SetP(const T *p, const Bool_t cartesian)
391{
8a1418dc 392 // Set the momentum
df9db588 393
394 if (p) {
395 if (cartesian) {
16b65f2a 396 Double_t pt2 = p[0]*p[0] + p[1]*p[1];
0c5f89fb 397 Double_t pp = TMath::Sqrt(pt2 + p[2]*p[2]);
df9db588 398
16b65f2a 399 fMomentum[0] = TMath::Sqrt(pt2); // pt
b1a9edc8 400 fMomentum[1] = (pt2 != 0.) ? TMath::Pi()+TMath::ATan2(-p[1], -p[0]) : -999; // phi
0c5f89fb 401 fMomentum[2] = (pp != 0.) ? TMath::ACos(p[2] / pp) : -999.; // theta
df9db588 402 } else {
16b65f2a 403 fMomentum[0] = p[0]; // pt
df9db588 404 fMomentum[1] = p[1]; // phi
405 fMomentum[2] = p[2]; // theta
406 }
407 } else {
408 fMomentum[0] = -999.;
409 fMomentum[1] = -999.;
410 fMomentum[2] = -999.;
411 }
412}
413
414//______________________________________________________________________________
415template <class T> void AliAODTrack::SetPosition(const T *x, const Bool_t dca)
416{
417 // set the position
418
419 if (x) {
420 if (!dca) {
421 ResetBit(kIsDCA);
422
423 fPosition[0] = x[0];
424 fPosition[1] = x[1];
425 fPosition[2] = x[2];
426 } else {
427 SetBit(kIsDCA);
428 // don't know any better yet
429 fPosition[0] = -999.;
430 fPosition[1] = -999.;
431 fPosition[2] = -999.;
432 }
433 } else {
434 ResetBit(kIsDCA);
435
436 fPosition[0] = -999.;
437 fPosition[1] = -999.;
438 fPosition[2] = -999.;
439 }
440}
441
442//______________________________________________________________________________
443void AliAODTrack::SetDCA(Double_t d, Double_t z)
444{
445 // set the dca
446 fPosition[0] = d;
447 fPosition[1] = z;
448 fPosition[2] = 0.;
449 SetBit(kIsDCA);
450}
451
452//______________________________________________________________________________
453void AliAODTrack::Print(Option_t* /* option */) const
454{
455 // prints information about AliAODTrack
456
457 printf("Object name: %s Track type: %s\n", GetName(), GetTitle());
458 printf(" px = %f\n", Px());
459 printf(" py = %f\n", Py());
460 printf(" pz = %f\n", Pz());
461 printf(" pt = %f\n", Pt());
462 printf(" 1/pt = %f\n", OneOverPt());
463 printf(" theta = %f\n", Theta());
464 printf(" phi = %f\n", Phi());
1912763f 465 printf(" chi2/NDF = %f\n", Chi2perNDF());
df9db588 466 printf(" charge = %d\n", Charge());
df9db588 467}
468
2200238e 469//______________________________________________________________________________
470void AliAODTrack::SetMatchTrigger(Int_t matchTrig)
471{
472 // Set the MUON trigger information
8ac4fa64 473 switch(matchTrig){
e1c744ca 474 case 0: // 0 track does not match trigger
475 fITSMuonClusterMap=fITSMuonClusterMap&0x3fffffff;
476 break;
477 case 1: // 1 track match but does not pass pt cut
478 fITSMuonClusterMap=(fITSMuonClusterMap&0x3fffffff)|0x40000000;
479 break;
480 case 2: // 2 track match Low pt cut
481 fITSMuonClusterMap=(fITSMuonClusterMap&0x3fffffff)|0x80000000;
482 break;
483 case 3: // 3 track match High pt cut
484 fITSMuonClusterMap=fITSMuonClusterMap|0xc0000000;
485 break;
486 default:
487 fITSMuonClusterMap=fITSMuonClusterMap&0x3fffffff;
8ac4fa64 488 AliWarning(Form("unknown case for matchTrig: %d\n",matchTrig));
e1c744ca 489 }
490}
491
2200238e 492//______________________________________________________________________________
493Bool_t AliAODTrack::HitsMuonChamber(Int_t MuonChamber, Int_t cathode) const
494{
495 // return kTRUE if the track fires the given tracking or trigger chamber.
496 // If the chamber is a trigger one:
497 // - if cathode = 0 or 1, the track matches the corresponding cathode
498 // - if cathode = -1, the track matches both cathodes
499
500 if (MuonChamber < 0) return kFALSE;
501
502 if (MuonChamber < 10) return TESTBIT(GetMUONClusterMap(), MuonChamber);
503
504 if (MuonChamber < 14) {
505
506 if (cathode < 0) return TESTBIT(GetHitsPatternInTrigCh(), 13-MuonChamber) &&
507 TESTBIT(GetHitsPatternInTrigCh(), 13-MuonChamber+4);
508
509 if (cathode < 2) return TESTBIT(GetHitsPatternInTrigCh(), 13-MuonChamber+(1-cathode)*4);
510
e1c744ca 511 }
2200238e 512
513 return kFALSE;
e1c744ca 514}
515
2200238e 516//______________________________________________________________________________
517Bool_t AliAODTrack::MatchTriggerDigits() const
518{
519 // return kTRUE if the track matches a digit on both planes of at least 2 trigger chambers
6c954176 520
2200238e 521 Int_t nMatchedChambers = 0;
522 for (Int_t ich=10; ich<14; ich++) if (HitsMuonChamber(ich)) nMatchedChambers++;
523
524 return (nMatchedChambers >= 2);
e1c744ca 525}
c683ddc2 526
6dc40b1c 527//______________________________________________________________________________
528Bool_t AliAODTrack::PropagateToDCA(const AliVVertex *vtx,
529 Double_t b, Double_t maxd, Double_t dz[2], Double_t covar[3])
530{
531 // compute impact parameters to the vertex vtx and their covariance matrix
532 // b is the Bz, needed to propagate correctly the track to vertex
533 // only the track parameters are update after the propagation (pos and mom),
534 // not the covariance matrix. This is OK for propagation over short distance
535 // inside the beam pipe.
536 // return kFALSE is something went wrong
537
538 // convert to AliExternalTrackParam
539 AliExternalTrackParam etp(this);
540
541 Float_t xstart = etp.GetX();
542 if(xstart>3.) {
543 AliError("This method can be used only for propagation inside the beam pipe");
544 return kFALSE;
545 }
546
547 if(!etp.PropagateToDCA(vtx,b,maxd,dz,covar)) return kFALSE;
548
549 // update track position and momentum
550 Double_t mom[3];
551 etp.GetPxPyPz(mom);
552 SetP(mom,kTRUE);
553 etp.GetXYZ(mom);
554 SetPosition(mom,kFALSE);
555
556
557 return kTRUE;
558}
559
c8fe2783 560//______________________________________________________________________________
561Bool_t AliAODTrack::GetPxPyPz(Double_t p[3]) const
562{
563 //---------------------------------------------------------------------
564 // This function returns the global track momentum components
565 //---------------------------------------------------------------------
566 p[0]=Px(); p[1]=Py(); p[2]=Pz();
567 return kTRUE;
568}