1 /**************************************************************************
2 * Copyright(c) 1998-2007, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 //-------------------------------------------------------------------------
19 // AOD track implementation of AliVTrack
20 // Author: Markus Oldenburg, CERN
21 // Markus.Oldenburg@cern.ch
22 //-------------------------------------------------------------------------
25 #include "AliExternalTrackParam.h"
26 #include "AliVVertex.h"
27 #include "AliAODTrack.h"
31 //______________________________________________________________________________
32 AliAODTrack::AliAODTrack() :
36 fChi2MatchTrigger(0.),
39 fITSMuonClusterMap(0),
47 fCaloIndex(kEMCALNoMatch),
52 // default constructor
55 SetPosition((Float_t*)NULL);
56 SetXYAtDCA(-999., -999.);
57 SetPxPyPzAtDCA(-999., -999., -999.);
58 SetPID((Float_t*)NULL);
61 //______________________________________________________________________________
62 AliAODTrack::AliAODTrack(Short_t id,
68 Double_t covMatrix[21],
72 AliAODVertex *prodVertex,
74 Bool_t usedForPrimVtxFit,
80 fChi2perNDF(chi2perNDF),
81 fChi2MatchTrigger(0.),
84 fITSMuonClusterMap(0),
85 fFilterMap(selectInfo),
92 fCaloIndex(kEMCALNoMatch),
95 fProdVertex(prodVertex)
100 SetPosition(x, isDCA);
101 SetXYAtDCA(-999., -999.);
102 SetPxPyPzAtDCA(-999., -999., -999.);
103 SetUsedForVtxFit(usedForVtxFit);
104 SetUsedForPrimVtxFit(usedForPrimVtxFit);
105 if(covMatrix) SetCovMatrix(covMatrix);
107 SetITSClusterMap(itsClusMap);
110 //______________________________________________________________________________
111 AliAODTrack::AliAODTrack(Short_t id,
117 Float_t covMatrix[21],
121 AliAODVertex *prodVertex,
122 Bool_t usedForVtxFit,
123 Bool_t usedForPrimVtxFit,
126 Float_t chi2perNDF) :
129 fChi2perNDF(chi2perNDF),
130 fChi2MatchTrigger(0.),
133 fITSMuonClusterMap(0),
134 fFilterMap(selectInfo),
141 fCaloIndex(kEMCALNoMatch),
144 fProdVertex(prodVertex)
149 SetPosition(x, isDCA);
150 SetXYAtDCA(-999., -999.);
151 SetPxPyPzAtDCA(-999., -999., -999.);
152 SetUsedForVtxFit(usedForVtxFit);
153 SetUsedForPrimVtxFit(usedForPrimVtxFit);
154 if(covMatrix) SetCovMatrix(covMatrix);
156 SetITSClusterMap(itsClusMap);
159 //______________________________________________________________________________
160 AliAODTrack::~AliAODTrack()
168 //______________________________________________________________________________
169 AliAODTrack::AliAODTrack(const AliAODTrack& trk) :
171 fRAtAbsorberEnd(trk.fRAtAbsorberEnd),
172 fChi2perNDF(trk.fChi2perNDF),
173 fChi2MatchTrigger(trk.fChi2MatchTrigger),
176 fITSMuonClusterMap(trk.fITSMuonClusterMap),
177 fFilterMap(trk.fFilterMap),
178 fTPCClusterMap(trk.fTPCClusterMap),
179 fTPCSharedMap(trk.fTPCSharedMap),
180 fTPCnclsF(trk.fTPCnclsF),
182 fCharge(trk.fCharge),
184 fCaloIndex(trk.fCaloIndex),
187 fProdVertex(trk.fProdVertex)
192 trk.GetPosition(fPosition);
193 SetXYAtDCA(trk.XAtDCA(), trk.YAtDCA());
194 SetPxPyPzAtDCA(trk.PxAtDCA(), trk.PyAtDCA(), trk.PzAtDCA());
195 SetUsedForVtxFit(trk.GetUsedForVtxFit());
196 SetUsedForPrimVtxFit(trk.GetUsedForPrimVtxFit());
197 if(trk.fCovMatrix) fCovMatrix=new AliAODRedCov<6>(*trk.fCovMatrix);
198 if(trk.fDetPid) fDetPid=new AliAODPid(*trk.fDetPid);
202 //______________________________________________________________________________
203 AliAODTrack& AliAODTrack::operator=(const AliAODTrack& trk)
205 // Assignment operator
208 AliVTrack::operator=(trk);
211 trk.GetPosition(fPosition);
214 SetXYAtDCA(trk.XAtDCA(), trk.YAtDCA());
215 SetPxPyPzAtDCA(trk.PxAtDCA(), trk.PyAtDCA(), trk.PzAtDCA());
217 fRAtAbsorberEnd = trk.fRAtAbsorberEnd;
219 fChi2perNDF = trk.fChi2perNDF;
220 fChi2MatchTrigger = trk.fChi2MatchTrigger;
225 fITSMuonClusterMap = trk.fITSMuonClusterMap;
226 fFilterMap = trk.fFilterMap;
230 fCharge = trk.fCharge;
233 fCaloIndex = trk.fCaloIndex;
236 if(trk.fCovMatrix) fCovMatrix=new AliAODRedCov<6>(*trk.fCovMatrix);
237 else fCovMatrix=NULL;
238 fProdVertex = trk.fProdVertex;
240 SetUsedForVtxFit(trk.GetUsedForVtxFit());
241 SetUsedForPrimVtxFit(trk.GetUsedForPrimVtxFit());
244 if(trk.fDetPid) fDetPid=new AliAODPid(*trk.fDetPid);
251 //______________________________________________________________________________
252 Double_t AliAODTrack::M(AODTrkPID_t pid) const
255 // Masses for nuclei don't exist in the PDG tables, therefore they were put by hand.
260 return 0.000510999; //TDatabasePDG::Instance()->GetParticle(11/*::kElectron*/)->Mass();
264 return 0.1056584; //TDatabasePDG::Instance()->GetParticle(13/*::kMuonMinus*/)->Mass();
268 return 0.13957; //TDatabasePDG::Instance()->GetParticle(211/*::kPiPlus*/)->Mass();
272 return 0.4937; //TDatabasePDG::Instance()->GetParticle(321/*::kKPlus*/)->Mass();
276 return 0.9382720; //TDatabasePDG::Instance()->GetParticle(2212/*::kProton*/)->Mass();
280 return 1.8756; //TDatabasePDG::Instance()->GetParticle(1000010020)->Mass();
284 return 2.8089; //TDatabasePDG::Instance()->GetParticle(1000010030)->Mass();
288 return 2.8084; //TDatabasePDG::Instance()->GetParticle(1000020030)->Mass();
292 return 3.7274; //TDatabasePDG::Instance()->GetParticle(1000020040)->Mass();
304 //______________________________________________________________________________
305 Double_t AliAODTrack::E(AODTrkPID_t pid) const
307 // Returns the energy of the particle of a given pid.
309 if (pid != kUnknown) { // particle was identified
311 return TMath::Sqrt(P()*P() + m*m);
312 } else { // pid unknown
317 //______________________________________________________________________________
318 Double_t AliAODTrack::Y(AODTrkPID_t pid) const
320 // Returns the rapidity of a particle of a given pid.
322 if (pid != kUnknown) { // particle was identified
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
330 } else { // pid unknown
335 //______________________________________________________________________________
336 Double_t AliAODTrack::Y(Double_t m) const
338 // Returns the rapidity of a particle of a given mass.
340 if (m >= 0.) { // mass makes sense
343 if (e>=0 && e!=pz) { // energy was positive (e.g. not -999.) and not equal to pz
344 return 0.5*TMath::Log((e+pz)/(e-pz));
345 } else { // energy not known or equal to pz
348 } else { // pid unknown
353 //______________________________________________________________________________
354 AliAODTrack::AODTrkPID_t AliAODTrack::GetMostProbablePID() const
356 // Returns the most probable PID array element.
359 AODTrkPID_t loc = kUnknown;
361 Bool_t allTheSame = kTRUE;
363 for (Int_t iPID = 0; iPID < nPID; iPID++) {
364 if (fPID[iPID] >= max) {
365 if (fPID[iPID] > max) {
368 loc = (AODTrkPID_t)iPID;
374 return allTheSame ? kUnknown : loc;
377 //______________________________________________________________________________
378 void AliAODTrack::ConvertAliPIDtoAODPID()
380 // Converts AliPID array.
381 // The numbering scheme is the same for electrons, muons, pions, kaons, and protons.
382 // Everything else has to be set to zero.
384 fPID[kDeuteron] = 0.;
394 //______________________________________________________________________________
395 template <class T> void AliAODTrack::SetP(const T *p, const Bool_t cartesian)
401 Double_t pt2 = p[0]*p[0] + p[1]*p[1];
402 Double_t pp = TMath::Sqrt(pt2 + p[2]*p[2]);
404 fMomentum[0] = TMath::Sqrt(pt2); // pt
405 fMomentum[1] = (pt2 != 0.) ? TMath::Pi()+TMath::ATan2(-p[1], -p[0]) : -999; // phi
406 fMomentum[2] = (pp != 0.) ? TMath::ACos(p[2] / pp) : -999.; // theta
408 fMomentum[0] = p[0]; // pt
409 fMomentum[1] = p[1]; // phi
410 fMomentum[2] = p[2]; // theta
413 fMomentum[0] = -999.;
414 fMomentum[1] = -999.;
415 fMomentum[2] = -999.;
419 //______________________________________________________________________________
420 template <class T> void AliAODTrack::SetPosition(const T *x, const Bool_t dca)
433 // don't know any better yet
434 fPosition[0] = -999.;
435 fPosition[1] = -999.;
436 fPosition[2] = -999.;
441 fPosition[0] = -999.;
442 fPosition[1] = -999.;
443 fPosition[2] = -999.;
447 //______________________________________________________________________________
448 void AliAODTrack::SetDCA(Double_t d, Double_t z)
457 //______________________________________________________________________________
458 void AliAODTrack::Print(Option_t* /* option */) const
460 // prints information about AliAODTrack
462 printf("Object name: %s Track type: %s\n", GetName(), GetTitle());
463 printf(" px = %f\n", Px());
464 printf(" py = %f\n", Py());
465 printf(" pz = %f\n", Pz());
466 printf(" pt = %f\n", Pt());
467 printf(" 1/pt = %f\n", OneOverPt());
468 printf(" theta = %f\n", Theta());
469 printf(" phi = %f\n", Phi());
470 printf(" chi2/NDF = %f\n", Chi2perNDF());
471 printf(" charge = %d\n", Charge());
474 //______________________________________________________________________________
475 void AliAODTrack::SetMatchTrigger(Int_t matchTrig)
477 // Set the MUON trigger information
479 case 0: // 0 track does not match trigger
480 fITSMuonClusterMap=fITSMuonClusterMap&0x3fffffff;
482 case 1: // 1 track match but does not pass pt cut
483 fITSMuonClusterMap=(fITSMuonClusterMap&0x3fffffff)|0x40000000;
485 case 2: // 2 track match Low pt cut
486 fITSMuonClusterMap=(fITSMuonClusterMap&0x3fffffff)|0x80000000;
488 case 3: // 3 track match High pt cut
489 fITSMuonClusterMap=fITSMuonClusterMap|0xc0000000;
492 fITSMuonClusterMap=fITSMuonClusterMap&0x3fffffff;
493 AliWarning(Form("unknown case for matchTrig: %d\n",matchTrig));
497 //______________________________________________________________________________
498 Bool_t AliAODTrack::HitsMuonChamber(Int_t MuonChamber, Int_t cathode) const
500 // return kTRUE if the track fires the given tracking or trigger chamber.
501 // If the chamber is a trigger one:
502 // - if cathode = 0 or 1, the track matches the corresponding cathode
503 // - if cathode = -1, the track matches both cathodes
505 if (MuonChamber < 0) return kFALSE;
507 if (MuonChamber < 10) return TESTBIT(GetMUONClusterMap(), MuonChamber);
509 if (MuonChamber < 14) {
511 if (cathode < 0) return TESTBIT(GetHitsPatternInTrigCh(), 13-MuonChamber) &&
512 TESTBIT(GetHitsPatternInTrigCh(), 13-MuonChamber+4);
514 if (cathode < 2) return TESTBIT(GetHitsPatternInTrigCh(), 13-MuonChamber+(1-cathode)*4);
521 //______________________________________________________________________________
522 Bool_t AliAODTrack::MatchTriggerDigits() const
524 // return kTRUE if the track matches a digit on both planes of at least 2 trigger chambers
526 Int_t nMatchedChambers = 0;
527 for (Int_t ich=10; ich<14; ich++) if (HitsMuonChamber(ich)) nMatchedChambers++;
529 return (nMatchedChambers >= 2);
532 //______________________________________________________________________________
533 Bool_t AliAODTrack::PropagateToDCA(const AliVVertex *vtx,
534 Double_t b, Double_t maxd, Double_t dz[2], Double_t covar[3])
536 // compute impact parameters to the vertex vtx and their covariance matrix
537 // b is the Bz, needed to propagate correctly the track to vertex
538 // only the track parameters are update after the propagation (pos and mom),
539 // not the covariance matrix. This is OK for propagation over short distance
540 // inside the beam pipe.
541 // return kFALSE is something went wrong
543 // convert to AliExternalTrackParam
544 AliExternalTrackParam etp; etp.CopyFromVTrack(this);
546 Float_t xstart = etp.GetX();
548 AliError("This method can be used only for propagation inside the beam pipe");
552 if(!etp.PropagateToDCA(vtx,b,maxd,dz,covar)) return kFALSE;
554 // update track position and momentum
559 SetPosition(mom,kFALSE);
565 //______________________________________________________________________________
566 Bool_t AliAODTrack::GetPxPyPz(Double_t p[3]) const
568 //---------------------------------------------------------------------
569 // This function returns the global track momentum components
570 //---------------------------------------------------------------------
571 p[0]=Px(); p[1]=Py(); p[2]=Pz();
575 //______________________________________________________________________________
576 Float_t AliAODTrack::GetTPCClusterInfo(Int_t nNeighbours/*=3*/, Int_t type/*=0*/, Int_t row0, Int_t row1) const
579 // TPC cluster information
580 // type 0: get fraction of found/findable clusters with neighbourhood definition
581 // 1: findable clusters with neighbourhood definition
584 // definition of findable clusters:
585 // a cluster is defined as findable if there is another cluster
586 // within +- nNeighbours pad rows. The idea is to overcome threshold
587 // effects with a very simple algorithm.
590 if (type==2) return fTPCClusterMap.CountBits();
594 Int_t last=-nNeighbours;
596 for (Int_t i=row0; i<row1; ++i){
597 //look to current row
598 if (fTPCClusterMap[i]) {
604 //look to nNeighbours before
605 if ((i-last)<=nNeighbours) {
609 //look to nNeighbours after
610 for (Int_t j=i+1; j<i+1+nNeighbours; ++j){
611 if (fTPCClusterMap[j]){
617 if (type==1) return findable;
622 fraction=(Float_t)found/(Float_t)findable;
627 return 0; // undefined type - default value
630 //______________________________________________________________________________
631 Double_t AliAODTrack::GetTRDslice(Int_t plane, Int_t slice) const {
633 // return TRD Pid information
635 if (!fDetPid) return -1;
636 Double32_t *trdSlices=fDetPid->GetTRDsignal();
637 if (!trdSlices) return -1;
638 if ((plane<0) || (plane>=kTRDnPlanes)) {
642 Int_t ns=fDetPid->GetTRDnSlices()/kTRDnPlanes;
643 if ((slice<-1) || (slice>=ns)) {
647 if(slice>=0) return trdSlices[plane*ns + slice];
649 // return average of the dEdx measurements
650 Double_t q=0.; Double32_t *s = &trdSlices[plane*ns];
651 for (Int_t i=0; i<ns; i++, s++) if((*s)>0.) q+=(*s);
655 //______________________________________________________________________________
656 UChar_t AliAODTrack::GetTRDntrackletsPID() const{
658 // return number of tracklets calculated from the slices
660 if(!fDetPid) return -1;
661 return fDetPid->GetTRDntrackletsPID();
664 //______________________________________________________________________________
665 UChar_t AliAODTrack::GetTRDncls(Int_t layer) const {
667 // return number of TRD clusters
669 if(!fDetPid || layer > 5) return -1;
670 if(layer < 0) return fDetPid->GetTRDncls();
671 else return fDetPid->GetTRDncls(layer);
674 //______________________________________________________________________________
675 Double_t AliAODTrack::GetTRDmomentum(Int_t plane, Double_t */*sp*/) const
677 //Returns momentum estimation
678 // in TRD layer "plane".
680 if (!fDetPid) return -1;
681 const Float_t *trdMomentum=fDetPid->GetTRDmomentum();
686 if ((plane<0) || (plane>=kTRDnPlanes)) {
690 return trdMomentum[plane];
693 //_______________________________________________________________________
694 Int_t AliAODTrack::GetTOFBunchCrossing(Double_t b) const
696 // Returns the number of bunch crossings after trigger (assuming 25ns spacing)
697 const double kSpacing = 25e3; // min interbanch spacing
698 const double kShift = 0;
699 Int_t bcid = kTOFBCNA; // defualt one
700 if (!IsOn(kTOFout) || !IsOn(kESDpid)) return bcid; // no info
702 double tdif = GetTOFsignal();
703 if (IsOn(kTIME)) { // integrated time info is there
704 int pid = (int)GetMostProbablePID();
706 GetIntegratedTimes(ttimes);
709 else { // assume integrated time info from TOF radius and momentum
710 const double kRTOF = 385.;
711 const double kCSpeed = 3.e-2; // cm/ps
713 if (p<0.001) p = 1.0;
715 double path = kRTOF; // mean TOF radius
716 if (TMath::Abs(b)>kAlmost0) { // account for curvature
717 double curv = Pt()/(b*kB2C);
719 double tgl = Pz()/Pt();
720 path = 2./curv*TMath::ASin(kRTOF*curv/2.)*TMath::Sqrt(1.+tgl*tgl);
723 tdif -= path/kCSpeed*TMath::Sqrt(1.+m*m/(p*p));
725 bcid = TMath::Nint((tdif - kShift)/kSpacing);