]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TRD/AliTRDtrackV1.cxx
CSP registers depend of FEE firmware, not RCU firmware
[u/mrichter/AliRoot.git] / TRD / AliTRDtrackV1.cxx
index 8be1deeb24066a56a74ab568bcd1a5daacd3be48..ac1edff63a4618a2ff2c95b3a93290c70fcddcee 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
@@ -99,7 +107,8 @@ AliTRDtrackV1::AliTRDtrackV1(const AliESDtrack &t) : AliKalmanTrack()
 
   SetLabel(t.GetLabel());
   SetChi2(0.0);
-  SetMass(t.GetMass());
+
+  SetMass(t.GetMass()/*0.000510*/);
   AliKalmanTrack::SetNumberOfClusters(t.GetTRDncls()); 
   Int_t ti[kNplane]; t.GetTRDtracklets(&ti[0]);
   for(int ip=0; ip<kNplane; ip++){ 
@@ -136,10 +145,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 +211,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 +227,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 +240,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 +268,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 +284,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,6 +307,58 @@ Bool_t AliTRDtrackV1::CookPID()
   return kTRUE;
 }
 
+//___________________________________________________________
+UChar_t AliTRDtrackV1::GetNumberOfTrackletsPID() const
+{
+// Retrieve number of tracklets used for PID calculation. 
+
+  UChar_t nPID = 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))) continue;
+    
+    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;
+    
+    fTracklet[ip]->SetPID();
+    nPID++;
+  }
+  return nPID;
+}
+
+//___________________________________________________________
+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.
+
+  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;
+}
+
 //_______________________________________________________________
 AliTRDcluster* AliTRDtrackV1::GetCluster(Int_t id)
 {
@@ -326,7 +370,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;}
@@ -347,7 +391,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;}
@@ -358,21 +402,29 @@ Int_t  AliTRDtrackV1::GetClusterIndex(Int_t id) const
 }
 
 //_______________________________________________________________
-Double_t AliTRDtrackV1::GetPredictedChi2(const AliTRDseedV1 *trklt) const
+Double_t AliTRDtrackV1::GetPredictedChi2(const AliTRDseedV1 *trklt, Double_t *cov) 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 p[2]   = { trklt->GetY(), trklt->GetZ()};
+  trklt->GetCovAt(trklt->GetX(), 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
 {
@@ -380,7 +432,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;
@@ -457,12 +509,12 @@ Int_t AliTRDtrackV1::GetProlongation(Double_t xk, Double_t &y, Double_t &z)
 {
   //
   // Find a prolongation at given x
-  // Return 0 if it does not exist
+  // Return -1 if it does not exist
   //  
 
   Double_t bz = GetBz();
-  if (!AliExternalTrackParam::GetYAt(xk,bz,y)) return 0;
-  if (!AliExternalTrackParam::GetZAt(xk,bz,z)) return 0;
+  if (!AliExternalTrackParam::GetYAt(xk,bz,y)) return -1;
+  if (!AliExternalTrackParam::GetZAt(xk,bz,z)) return -1;
 
   return 1;  
 
@@ -578,7 +630,7 @@ Int_t   AliTRDtrackV1::PropagateToR(Double_t r,Double_t step)
     Double_t alpha = TMath::ATan2(xyz0[1],xyz0[0]);
     Rotate(alpha,kTRUE);
     GetXYZ(xyz0);      
-    GetProlongation(x,y,z);
+    if(GetProlongation(x,y,z)<0) return -1;
     xyz1[0] = x * TMath::Cos(alpha) + y * TMath::Sin(alpha); 
     xyz1[1] = x * TMath::Sin(alpha) - y * TMath::Cos(alpha);
     xyz1[2] = z;
@@ -595,7 +647,7 @@ Int_t   AliTRDtrackV1::PropagateToR(Double_t r,Double_t step)
   Double_t alpha = TMath::ATan2(xyz0[1],xyz0[0]);
   Rotate(alpha,kTRUE);
   GetXYZ(xyz0);        
-  GetProlongation(r,y,z);
+  if(GetProlongation(r,y,z)<0) return -1;
   xyz1[0] = r * TMath::Cos(alpha) + y * TMath::Sin(alpha); 
   xyz1[1] = r * TMath::Sin(alpha) - y * TMath::Cos(alpha);
   xyz1[2] = z;
@@ -614,11 +666,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| = (");
@@ -699,6 +751,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)
 {
@@ -709,45 +775,16 @@ void AliTRDtrackV1::UnsetTracklet(Int_t plane)
 
 
 //_______________________________________________________________
-Bool_t  AliTRDtrackV1::Update(AliTRDseedV1 *trklt, Double_t chisq)
+Bool_t  AliTRDtrackV1::Update(Double_t *p, Double_t *cov, Double_t chi2)
 {
   //
-  // Update track and tracklet parameters 
+  // Update track 
   //
-  
-  Double_t x      = GetX();
-  Double_t p[2]   = { trklt->GetYat(x)
-                    , trklt->GetZat(x) };
-  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());
-// //   
-//   Double_t xref = trklt->GetXref();
-//   trklt->GetCovAt(xref, covR);
-//   printf("xr=%5.3f y=%f+-%f z=%f+-%f (covYZ=%f)\n", xref, trklt->GetYat(xref), TMath::Sqrt(covR[0]), trklt->GetZat(xref), TMath::Sqrt(covR[2]), covR[1]);
-// 
-//   Double_t x0 = trklt->GetX0();
-//   trklt->GetCovAt(x0, cov0);
-//   printf("x0=%5.3f y=%f+-%f z=%f+-%f (covYZ=%f)\n", x0, trklt->GetYat(x0), TMath::Sqrt(cov0[0]), trklt->GetZat(x0), TMath::Sqrt(cov0[2]), cov0[1]);
-// 
-//   trklt->GetCovAt(x, cov);
-//   printf("x =%5.3f y=%f+-%f z=%f+-%f (covYZ=%f)\n", x, p[0], TMath::Sqrt(cov[0]), p[1], TMath::Sqrt(cov[2]), cov[1]);
-// 
-//   const Double_t *cc = GetCovariance();
-//   printf("yklm[0] = %f +- %f\n", GetY(), TMath::Sqrt(cc[0]));
-
-  trklt->GetCovAt(x, cov); 
   if(!AliExternalTrackParam::Update(p, cov)) return kFALSE;
-//   cc = GetCovariance();
-//   printf("yklm[1] = %f +- %f\n", GetY(), TMath::Sqrt(cc[0]));
 
-  AliTRDcluster *c = 0x0;
-  Int_t ic = 0; while(!(c = trklt->GetClusters(ic))) ic++;
-  AliTracker::FillResiduals(this, p, cov, c->GetVolumeId());
-  
   // Register info to track
   SetNumberOfClusters();
-  SetChi2(GetChi2() + chisq);
+  SetChi2(GetChi2() + chi2);
   return kTRUE;
 }
 
@@ -759,18 +796,24 @@ void AliTRDtrackV1::UpdateESDtrack(AliESDtrack *track)
   //
 
   Int_t nslices = fReconstructor->IsEightSlices() ? (Int_t)AliTRDpidUtil::kNNslices : (Int_t)AliTRDpidUtil::kLQslices;
-  track->SetNumberOfTRDslices(nslices);
-
+  // number of tracklets used for PID calculation
+  UChar_t nPID = GetNumberOfTrackletsPID();
+  // number of tracklets attached to the track
+  UChar_t nTrk = GetNumberOfTracklets();
+  // pack the two numbers together and store them in the ESD
+  track->SetTRDntracklets(nPID | (nTrk<<3));
+  // allocate space to store raw PID signals dEdx & momentum
+  track->SetNumberOfTRDslices((nslices+2)*AliTRDgeometry::kNlayer);
+  // store raw signals
+  Float_t p, sp; Double_t spd;
   for (Int_t ip = 0; ip < kNplane; ip++) {
     if(fTrackletIndex[ip] == 0xffff) continue;
-    if(!fTracklet[ip]->IsOK()) continue;
-    fTracklet[ip]->CookdEdx(nslices);
+    if(!fTracklet[ip]->HasPID()) continue;
     Float_t *dedx = fTracklet[ip]->GetdEdx();
     for (Int_t js = 0; js < nslices; js++, dedx++) track->SetTRDslice(*dedx, ip, js);
+    p = fTracklet[ip]->GetMomentum(&sp); spd = sp;
+    track->SetTRDmomentum(p, ip, &spd);
   }
-
-  // copy PID to ESD
-  if(!fPIDquality) return;
+  // store PID probabilities
   track->SetTRDpid(fPID);
-  track->SetTRDpidQuality(fPIDquality);
 }