]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TRD/AliTRDtrackV1.cxx
- Prepare covariance matrix manipulation in the tracklet for resolution
[u/mrichter/AliRoot.git] / TRD / AliTRDtrackV1.cxx
index 16294af0e5d60a2ee6eed1532cefc9005ae1cfe2..cd86f2238ff0f4835672e74ff45a024290e309ea 100644 (file)
@@ -40,10 +40,12 @@ ClassImp(AliTRDtrackV1)
 
 //_______________________________________________________________
 AliTRDtrackV1::AliTRDtrackV1() : AliKalmanTrack()
-  ,fPIDquality(0)
+  ,fStatus(0)
   ,fDE(0.)
   ,fReconstructor(0x0)
   ,fBackupTrack(0x0)
+  ,fTrackLow(0x0)
+  ,fTrackHigh(0x0)
 {
   //
   // Default constructor
@@ -63,10 +65,12 @@ AliTRDtrackV1::AliTRDtrackV1() : AliKalmanTrack()
 
 //_______________________________________________________________
 AliTRDtrackV1::AliTRDtrackV1(const AliTRDtrackV1 &ref) : AliKalmanTrack(ref)
-  ,fPIDquality(ref.fPIDquality)
+  ,fStatus(ref.fStatus)
   ,fDE(ref.fDE)
   ,fReconstructor(ref.fReconstructor)
   ,fBackupTrack(0x0)
+  ,fTrackLow(0x0)
+  ,fTrackHigh(0x0)
 {
   //
   // Copy constructor
@@ -78,7 +82,9 @@ AliTRDtrackV1::AliTRDtrackV1(const AliTRDtrackV1 &ref) : AliKalmanTrack(ref)
     fTrackletIndex[ip] = ref.fTrackletIndex[ip];
     fTracklet[ip]      = ref.fTracklet[ip];
   }
-
+  if(ref.fTrackLow) fTrackLow = new AliExternalTrackParam(*ref.fTrackLow);
+  if(ref.fTrackHigh) fTrackHigh = new AliExternalTrackParam(*ref.fTrackHigh);
   for (Int_t i = 0; i < 3;i++) fBudget[i]      = ref.fBudget[i];
 
        for(Int_t is = 0; is<AliPID::kSPECIES; is++) fPID[is] = ref.fPID[is];
@@ -88,10 +94,12 @@ AliTRDtrackV1::AliTRDtrackV1(const AliTRDtrackV1 &ref) : AliKalmanTrack(ref)
 
 //_______________________________________________________________
 AliTRDtrackV1::AliTRDtrackV1(const AliESDtrack &t) : AliKalmanTrack()
-  ,fPIDquality(0)
+  ,fStatus(0)
   ,fDE(0.)
   ,fReconstructor(0x0)
   ,fBackupTrack(0x0)
+  ,fTrackLow(0x0)
+  ,fTrackHigh(0x0)
 {
   //
   // Constructor from AliESDtrack
@@ -136,10 +144,12 @@ AliTRDtrackV1::AliTRDtrackV1(const AliESDtrack &t) : AliKalmanTrack()
 //_______________________________________________________________
 AliTRDtrackV1::AliTRDtrackV1(AliTRDseedV1 *trklts, const Double_t p[5], const Double_t cov[15]
              , Double_t x, Double_t alpha) : AliKalmanTrack()
-  ,fPIDquality(0)
+  ,fStatus(0)
   ,fDE(0.)
   ,fReconstructor(0x0)
   ,fBackupTrack(0x0)
+  ,fTrackLow(0x0)
+  ,fTrackHigh(0x0)
 {
   //
   // The stand alone tracking constructor
@@ -200,8 +210,10 @@ AliTRDtrackV1::~AliTRDtrackV1()
   //AliInfo("");
   //printf("I-AliTRDtrackV1::~AliTRDtrackV1() : Owner[%s]\n", TestBit(kOwner)?"YES":"NO");
 
-  if(fBackupTrack) delete fBackupTrack;
-  fBackupTrack = 0x0;
+  if(fBackupTrack) delete fBackupTrack; fBackupTrack = 0x0;
+
+  if(fTrackLow) delete fTrackLow; fTrackLow = 0x0;
+  if(fTrackHigh) delete fTrackHigh; fTrackHigh = 0x0;
 
   for(Int_t ip=0; ip<kNplane; ip++){
     if(TestBit(kOwner) && fTracklet[ip]) delete fTracklet[ip];
@@ -214,7 +226,8 @@ AliTRDtrackV1::~AliTRDtrackV1()
 Bool_t AliTRDtrackV1::CookLabel(Float_t wrong)
 {
   // set MC label for this track
-  
+  if(!GetNumberOfClusters()) return kFALSE;
+
   Int_t s[kMAXCLUSTERSPERTRACK][2];
   for (Int_t i = 0; i < kMAXCLUSTERSPERTRACK; i++) {
     s[i][0] = -1;
@@ -226,7 +239,7 @@ Bool_t AliTRDtrackV1::CookLabel(Float_t wrong)
   AliTRDcluster *c    = 0x0;
   for (Int_t ip = 0; ip < kNplane; ip++) {
     if(fTrackletIndex[ip] == 0xffff) continue;
-    for (Int_t ic = 0; ic < AliTRDseed::knTimebins; ic++) {
+    for (Int_t ic = 0; ic < AliTRDseedV1::kNclusters; ic++) {
       if(!(c = fTracklet[ip]->GetClusters(ic))) continue;
       for (Int_t k = 0; k < 3; k++) { 
         label      = c->GetLabel(k);
@@ -254,7 +267,6 @@ Bool_t AliTRDtrackV1::CookLabel(Float_t wrong)
     max   = s[i][1]; 
     label = s[i][0];
   }
-  
   if ((1. - Float_t(max)/GetNumberOfClusters()) > wrong) label = -label;
   
   SetLabel(label); 
@@ -271,35 +283,14 @@ Bool_t AliTRDtrackV1::CookPID()
   
   // Reset the a priori probabilities
   Double_t pid = 1. / AliPID::kSPECIES;
-  for(int ispec=0; ispec<AliPID::kSPECIES; ispec++) {
-    fPID[ispec] = pid; 
-  }
-  fPIDquality = 0;
-  
-  // steer PID calculation @ tracklet level
-  Double_t *prob = 0x0;
-  for(int ip=0; ip<kNplane; ip++){
-    if(fTrackletIndex[ip] == 0xffff) continue;
-    if(!fTracklet[ip]->IsOK()) continue;
-    if(!(prob = fTracklet[ip]->GetProbability())) return kFALSE;
-    
-    Int_t nspec = 0; // quality check of tracklet dEdx
-    for(int ispec=0; ispec<AliPID::kSPECIES; ispec++){
-      if(prob[ispec] < 0.) continue;
-      fPID[ispec] *= prob[ispec];
-      nspec++;
-    }
-    if(!nspec) continue;
-    
-    fPIDquality++;
-  }
-  
+  for(int ispec=0; ispec<AliPID::kSPECIES; ispec++) fPID[ispec] = pid; 
+
+  UChar_t fPIDquality = SetNumberOfTrackletsPID(kTRUE);
   // no tracklet found for PID calculations
-  if(!fPIDquality) return kTRUE;
+  if(!fPIDquality) return kFALSE;
   
   // slot for PID calculation @ track level
   
-  
   // normalize probabilities
   Double_t probTotal = 0.0;
   for (Int_t is = 0; is < AliPID::kSPECIES; is++) probTotal += fPID[is];
@@ -315,18 +306,55 @@ Bool_t AliTRDtrackV1::CookPID()
   return kTRUE;
 }
 
-//_____________________________________________________________________________
-Double_t AliTRDtrackV1::GetBz() const 
+//___________________________________________________________
+UChar_t AliTRDtrackV1::GetNumberOfTrackletsPID() const
 {
-  //
-  // Returns Bz component of the magnetic field (kG)
-  //
+// Retrieve number of tracklets used for PID calculation. 
+
+  UChar_t fPIDquality = 0;
+  Float_t *prob = 0x0;
+  for(int ip=0; ip<kNplane; ip++){
+    if(fTrackletIndex[ip] == 0xffff) continue;
+    if(!fTracklet[ip]->IsOK()) continue;
+    if(!(prob = fTracklet[ip]->GetProbability(kFALSE))) return 0;
+    
+    Int_t nspec = 0; // quality check of tracklet dEdx
+    for(int ispec=0; ispec<AliPID::kSPECIES; ispec++){
+      if(prob[ispec] < 0.) continue;
+      nspec++;
+    }
+    if(!nspec) continue;
+    
+    fPIDquality++;
+  }
+  return fPIDquality;
+}
 
-  if (AliTracker::UniformField()) return AliTracker::GetBz();
+//___________________________________________________________
+UChar_t AliTRDtrackV1::SetNumberOfTrackletsPID(Bool_t recalc)
+{
+// Retrieve number of tracklets used for PID calculation. // Recalculated PID at tracklet level by quering the PID DB.
 
-  Double_t r[3]; 
-  GetXYZ(r);
-  return AliTracker::GetBz(r);
+  UChar_t fPIDquality = 0;
+  
+  // steer PID calculation @ tracklet level
+  Float_t *prob = 0x0;
+  for(int ip=0; ip<kNplane; ip++){
+    if(fTrackletIndex[ip] == 0xffff) continue;
+    if(!fTracklet[ip]->IsOK()) continue;
+    if(!(prob = fTracklet[ip]->GetProbability(recalc))) return 0;
+    
+    Int_t nspec = 0; // quality check of tracklet dEdx
+    for(int ispec=0; ispec<AliPID::kSPECIES; ispec++){
+      if(prob[ispec] < 0.) continue;
+      fPID[ispec] *= prob[ispec];
+      nspec++;
+    }
+    if(!nspec) continue;
+    
+    fPIDquality++;
+  }
+  return fPIDquality;
 }
 
 //_______________________________________________________________
@@ -340,7 +368,7 @@ AliTRDcluster* AliTRDtrackV1::GetCluster(Int_t id)
       continue;
     }
     AliTRDcluster *c = 0x0;
-    for(Int_t ic=AliTRDseed::knTimebins-1; ic>=0; ic--){
+    for(Int_t ic=AliTRDseedV1::kNclusters; ic--;){
       if(!(c = fTracklet[ip]->GetClusters(ic))) continue;
 
       if(n<id){n++; continue;}
@@ -361,7 +389,7 @@ Int_t  AliTRDtrackV1::GetClusterIndex(Int_t id) const
       continue;
     }
     AliTRDcluster *c = 0x0;
-    for(Int_t ic=AliTRDseed::knTimebins-1; ic>=0; ic--){
+    for(Int_t ic=AliTRDseedV1::kNclusters; ic--;){
       if(!(c = fTracklet[ip]->GetClusters(ic))) continue;
 
       if(n<id){n++; continue;}
@@ -374,19 +402,28 @@ Int_t  AliTRDtrackV1::GetClusterIndex(Int_t id) const
 //_______________________________________________________________
 Double_t AliTRDtrackV1::GetPredictedChi2(const AliTRDseedV1 *trklt) const
 {
-  //
-  // Get the predicted chi2
-  //
-  
-  Double_t x      = trklt->GetX0();
-  Double_t p[2]   = { trklt->GetYat(x)
-                    , trklt->GetZat(x) };
-  Double_t cov[3];
-  trklt->GetCovAt(x, cov);
-  
+// Compute chi2 between tracklet and track. The value is calculated at the radial position of the track
+// equal to the reference radial position of the tracklet (see AliTRDseedV1)
+// 
+// The chi2 estimator is computed according to the following formula
+// BEGIN_LATEX
+// #chi^{2}=(X_{trklt}-X_{track})(C_{trklt}+C_{track})^{-1}(X_{trklt}-X_{track})^{T}
+// END_LATEX
+// where X=(y z), the position of the track/tracklet in the yz plane
+// 
+
+  Double_t x = GetX();
+  Double_t p[2]   = { trklt->GetYat(x), trklt->GetZat(x)};
+  Double_t cov[3]; trklt->GetCovAt(x, cov);
   return AliExternalTrackParam::GetPredictedChi2(p, cov);
 }
 
+//_______________________________________________________________
+Int_t AliTRDtrackV1::GetSector() const
+{
+  return Int_t(GetAlpha()/AliTRDgeometry::GetAlpha() + (GetAlpha()>0. ? 0 : AliTRDgeometry::kNsector));
+}
+
 //_______________________________________________________________
 Bool_t AliTRDtrackV1::IsEqual(const TObject *o) const
 {
@@ -394,7 +431,7 @@ Bool_t AliTRDtrackV1::IsEqual(const TObject *o) const
   const AliTRDtrackV1 *inTrack = dynamic_cast<const AliTRDtrackV1*>(o);
   if (!inTrack) return kFALSE;
   
-  if ( fPIDquality != inTrack->GetPIDquality() ) return kFALSE;
+  //if ( fPIDquality != inTrack->GetPIDquality() ) return kFALSE;
   
   for(Int_t i = 0; i < AliPID::kSPECIES; i++){
     if ( fPID[i] != inTrack->GetPID(i) ) return kFALSE;
@@ -529,9 +566,8 @@ Bool_t AliTRDtrackV1::PropagateTo(Double_t xk, Double_t xx0, Double_t xrho)
     }
   }
 
-  if (!AliExternalTrackParam::CorrectForMeanMaterial(xx0,xrho,GetMass())) { 
-    return kFALSE;
-  }
+  if (!AliExternalTrackParam::CorrectForMeanMaterial(xx0, xrho, GetMass())) return kFALSE;
+
 
   {
 
@@ -629,11 +665,11 @@ Int_t   AliTRDtrackV1::PropagateToR(Double_t r,Double_t step)
 //_____________________________________________________________________________
 void AliTRDtrackV1::Print(Option_t *o) const
 {
-  AliInfo(Form("PID q[%d] [%4.1f %4.1f %4.1f %4.1f %4.1f]", fPIDquality, 1.E2*fPID[0], 1.E2*fPID[1], 1.E2*fPID[2], 1.E2*fPID[3], 1.E2*fPID[4]));
+  AliInfo(Form("PID [%4.1f %4.1f %4.1f %4.1f %4.1f]", 1.E2*fPID[0], 1.E2*fPID[1], 1.E2*fPID[2], 1.E2*fPID[3], 1.E2*fPID[4]));
   AliInfo(Form("Material[%5.2f %5.2f %5.2f]", fBudget[0], fBudget[1], fBudget[2]));
 
   AliInfo(Form("x[%7.2f] t[%7.4f] alpha[%f] mass[%f]", GetX(), GetIntegratedLength(), GetAlpha(), fMass));
-  AliInfo(Form("Ntr[%1d] Ncl[%3d] lab[%3d]", GetNumberOfTracklets(), fN, fLab));
+  AliInfo(Form("Ntr[%1d] NtrPID[%1d] Ncl[%3d] lab[%3d]", GetNumberOfTracklets(), GetNumberOfTrackletsPID(), fN, fLab));
 
   if(strcmp(o, "a")!=0) return;
   printf("|X| = (");
@@ -714,6 +750,20 @@ void AliTRDtrackV1::SetTracklet(AliTRDseedV1 *trklt, Int_t index)
   fTrackletIndex[plane] = index;
 }
 
+//_______________________________________________________________
+void AliTRDtrackV1::SetTrackLow()
+{
+  const AliExternalTrackParam *op = dynamic_cast<const AliExternalTrackParam*>(this);
+  fTrackLow = fTrackLow ? new(fTrackLow) AliExternalTrackParam(*op) : new AliExternalTrackParam(*op);
+}
+
+//_______________________________________________________________
+void AliTRDtrackV1::SetTrackHigh(const AliExternalTrackParam *op)
+{
+  if(!op) op = dynamic_cast<const AliExternalTrackParam*>(this);
+  fTrackHigh = fTrackHigh ? new(fTrackHigh) AliExternalTrackParam(*op) : new AliExternalTrackParam(*op);
+}
+
 //_______________________________________________________________
 void AliTRDtrackV1::UnsetTracklet(Int_t plane)
 {
@@ -733,7 +783,7 @@ Bool_t  AliTRDtrackV1::Update(AliTRDseedV1 *trklt, Double_t chisq)
   Double_t x      = GetX();
   Double_t p[2]   = { trklt->GetYat(x)
                     , trklt->GetZat(x) };
-  Double_t cov[3], covR[3], cov0[3];
+  Double_t cov[3]/*, covR[3], cov0[3]*/;
 
 //   printf("\tD[%3d] Ly[%d] Trk: x[%f] y[%f] z[%f]\n", trklt->GetDetector(), trklt->GetPlane(), GetX(), GetY(), GetZ());
 // //   
@@ -773,19 +823,24 @@ void AliTRDtrackV1::UpdateESDtrack(AliESDtrack *track)
   // Update the TRD PID information in the ESD track
   //
 
-  Int_t nslices = fReconstructor->IsEightSlices() ? (Int_t)AliTRDReconstructor::kNNslices : (Int_t)AliTRDReconstructor::kLQslices;
+  Int_t nslices = fReconstructor->IsEightSlices() ? (Int_t)AliTRDpidUtil::kNNslices : (Int_t)AliTRDpidUtil::kLQslices;
   track->SetNumberOfTRDslices(nslices);
 
+  Int_t n = 0;
   for (Int_t ip = 0; ip < kNplane; ip++) {
     if(fTrackletIndex[ip] == 0xffff) continue;
+    n++;
     if(!fTracklet[ip]->IsOK()) continue;
     fTracklet[ip]->CookdEdx(nslices);
     Float_t *dedx = fTracklet[ip]->GetdEdx();
     for (Int_t js = 0; js < nslices; js++, dedx++) track->SetTRDslice(*dedx, ip, js);
   }
 
-  // copy PID to ESD
-  if(!fPIDquality) return;
-  track->SetTRDpid(fPID);
-  track->SetTRDpidQuality(fPIDquality);
+  UChar_t nPID = GetNumberOfTrackletsPID();
+  if(!nPID) track->SetTRDntracklets(n);
+  else {
+    track->SetTRDpid(fPID);
+    n |= (nPID<<3);
+    track->SetTRDntracklets(n);
+  }
 }