- Move to the new attaching cluster to tracklet procedure in the stand
authorhristov <hristov@f7af4fe6-9843-0410-8265-dc069ae4e863>
Mon, 2 Mar 2009 12:56:41 +0000 (12:56 +0000)
committerhristov <hristov@f7af4fe6-9843-0410-8265-dc069ae4e863>
Mon, 2 Mar 2009 12:56:41 +0000 (12:56 +0000)
alone tracker
- revised definition of cluster usage and sharing
- make track/tracklet aware of TPC kinks

Alex and Markus

HLT/TRD/AliHLTTRDTracklet.cxx
HLT/TRD/AliHLTTRDTracklet.h
TRD/AliTRDReconstructor.cxx
TRD/AliTRDseedV1.cxx
TRD/AliTRDseedV1.h
TRD/AliTRDtrackV1.h
TRD/AliTRDtrackerDebug.cxx
TRD/AliTRDtrackerV1.cxx

index 3696ecb..37c9f81 100644 (file)
@@ -13,7 +13,6 @@ AliHLTTRDTracklet::AliHLTTRDTracklet():
   fTilt(-1),
   fPadLength(-1),
   fX0(-1),
-  fUsable(0),
   //fMeanz(-1),
   //fZProb(-1),
   //fN(-1),
@@ -45,7 +44,6 @@ AliHLTTRDTracklet::AliHLTTRDTracklet(AliTRDseedV1 * inTracklet):
   fTilt(-1),
   fPadLength(-1),
   fX0(-1),
-  fUsable(0),
   //fMeanz(-1),
   //fZProb(-1),
   //fN(-1),
@@ -115,7 +113,6 @@ void AliHLTTRDTracklet::CopyDataMembers()
 //     fZ[i] = fTRDtracklet->GetZ(i);
     fIndexes[i] = fTRDtracklet->GetIndexes(i);
   }
-  fUsable = fTRDtracklet->GetUsabilityMap();
 
   for (Int_t i=0; i < 2; i++){
     fYfit[i] = fTRDtracklet->GetYfit(i);
@@ -165,7 +162,6 @@ void AliHLTTRDTracklet::ExportTRDTracklet(AliTRDseedV1 *outTracklet)
 //     outTracklet->SetX(i,fZ[i]);
     outTracklet->SetIndexes(i, fIndexes[i]);
   }
-  outTracklet->SetUsabilityMap(fUsable);
 
 //   for (Int_t i=0; i < 2; i++){
 //     outTracklet->SetYfit(i,fYfit[i]);
@@ -208,7 +204,6 @@ void AliHLTTRDTracklet::InitArrays()
 //     fZ[i] = -1;
     fIndexes[i] = -1;
   }
-  fUsable = 0;
 
   for (Int_t i=0; i < 2; i++){
     fYfit[i] = -1;
index 07177eb..bc19531 100644 (file)
@@ -44,7 +44,6 @@ class AliHLTTRDTracklet
 //  Float_t        fY[knTimebins];        //! Y position
 //  Float_t        fZ[knTimebins];        //! Z position
   Int_t          fIndexes[AliTRDseedV1::kNTimeBins];  //! Indexes
-  Long_t         fUsable;                //  Indication  - usable cluster
   Float_t        fYfit[2];              //  Y fit position +derivation
   //Float_t        fYfitR[2];             //  Y fit position +derivation
   Float_t        fZfit[2];              //  Z fit position
index 1ea05c6..edffd63 100644 (file)
@@ -99,7 +99,7 @@ AliTRDReconstructor::~AliTRDReconstructor()
   if(fgClusters) {
     fgClusters->Delete(); delete fgClusters;
   }
-  if(TESTBIT(fSteerParam, kOwner)){
+  if(fSteerParam&kOwner){
     for(Int_t itask = 0; itask < kNtasks; itask++)
       if(fDebugStream[itask]) delete fDebugStream[itask];
   }
index f028c49..9776967 100644 (file)
@@ -65,7 +65,7 @@ AliTRDseedV1::AliTRDseedV1(Int_t det)
   ,fDiffL(0.)
   ,fDiffT(0.)
   ,fClusterIdx(0)
-  ,fUsable(0)
+//   ,fUsable(0)
   ,fN2(0)
   ,fNUsed(0)
   ,fDet(det)
@@ -99,6 +99,7 @@ AliTRDseedV1::AliTRDseedV1(Int_t det)
   // covariance matrix [diagonal]
   // default sy = 200um and sz = 2.3 cm 
   fCov[0] = 4.e-4; fCov[1] = 0.; fCov[2] = 5.3; 
+  SetStandAlone(kFALSE);
 }
 
 //____________________________________________________________________
@@ -113,7 +114,7 @@ AliTRDseedV1::AliTRDseedV1(const AliTRDseedV1 &ref)
   ,fDiffL(0.)
   ,fDiffT(0.)
   ,fClusterIdx(0)
-  ,fUsable(0)
+//   ,fUsable(0)
   ,fN2(0)
   ,fNUsed(0)
   ,fDet(-1)
@@ -137,6 +138,7 @@ AliTRDseedV1::AliTRDseedV1(const AliTRDseedV1 &ref)
     ref.Copy(*this);
   }
   SetBit(kOwner, kFALSE);
+  SetStandAlone(ref.IsStandAlone());
 }
 
 
@@ -193,7 +195,7 @@ void AliTRDseedV1::Copy(TObject &ref) const
   target.fDiffL         = fDiffL;
   target.fDiffT         = fDiffT;
   target.fClusterIdx    = 0;
-  target.fUsable        = fUsable;
+//   target.fUsable        = fUsable;
   target.fN2            = fN2;
   target.fNUsed         = fNUsed;
   target.fDet           = fDet;
@@ -258,8 +260,8 @@ void AliTRDseedV1::Reset()
   //
   fExB=0.;fVD=0.;fT0=0.;fS2PRF=0.;
   fDiffL=0.;fDiffT=0.;
-  fClusterIdx=0;fUsable=0;
-  fN2=0;fNUsed=0;
+  fClusterIdx=0;//fUsable=0;
+  fN2=0; fNUsed=0;
   fDet=-1;fTilt=0.;fPadLength=0.;
   fMom=0.;
   fdX=0.;fX0=0.; fX=0.; fY=0.; fZ=0.;
@@ -304,14 +306,14 @@ void AliTRDseedV1::UpDate(const AliTRDtrackV1 *trk)
 void AliTRDseedV1::UpdateUsed()
 {
   //
-  // Update used seed
+  // Calculate number of used clusers in the tracklet
   //
 
   fNUsed = 0;
   for (Int_t i = kNTimeBins; i--; ) {
     if (!fClusters[i]) continue;
-    if(!TESTBIT(fUsable, i)) continue;
-    if((fClusters[i]->IsUsed())) fNUsed++;
+    if(fClusters[i]->IsUsed()) fNUsed++;
+    else if(fClusters[i]->IsShared() && IsStandAlone()) fNUsed++;
   }
 }
 
@@ -321,14 +323,37 @@ void AliTRDseedV1::UseClusters()
   //
   // Use clusters
   //
+  // In stand alone mode:
+  // Clusters which are marked as used or shared from another track are
+  // removed from the tracklet
+  //
+  // In barrel mode:
+  // - Clusters which are used by another track become shared
+  // - Clusters which are attached to a kink track become shared
+  //
   AliTRDcluster **c = &fClusters[0];
   for (Int_t ic=kNTimeBins; ic--; c++) {
     if(!(*c)) continue;
-    if(!((*c)->IsUsed())) (*c)->Use();
+    if(IsStandAlone()){
+      if((*c)->IsShared() || (*c)->IsUsed()){ 
+       (*c) = 0x0;
+        fIndexes[ic] = -1;
+        fN2--;
+       continue;
+      }
+    }
+    else{
+      if((*c)->IsUsed() || IsKink()){
+       (*c)->SetShared();
+       continue;
+      }
+    }
+    (*c)->Use();
   }
 }
 
 
+
 //____________________________________________________________________
 void AliTRDseedV1::CookdEdx(Int_t nslices)
 {
@@ -669,134 +694,134 @@ void AliTRDseedV1::SetOwner()
   SetBit(kOwner);
 }
 
-//____________________________________________________________________
-Bool_t AliTRDseedV1::AttachClustersIter(AliTRDtrackingChamber *chamber, Float_t quality, Bool_t kZcorr, AliTRDcluster *c)
-{
-  //
-  // Iterative process to register clusters to the seed.
-  // In iteration 0 we try only one pad-row and if quality not
-  // sufficient we try 2 pad-rows (about 5% of tracks cross 2 pad-rows)
-  //
-  // debug level 7
-  //
-  
-  if(!fReconstructor->GetRecoParam() ){
-    AliError("Seed can not be used without a valid RecoParam.");
-    return kFALSE;
-  }
-
-  AliTRDchamberTimeBin *layer = 0x0;
-  if(fReconstructor->GetStreamLevel(AliTRDReconstructor::kTracker)>=7){
-    AliTRDtrackingChamber ch(*chamber);
-    ch.SetOwner(); 
-    TTreeSRedirector &cstreamer = *fReconstructor->GetDebugStream(AliTRDReconstructor::kTracker);
-    cstreamer << "AttachClustersIter"
-      << "chamber.="   << &ch
-      << "tracklet.="  << this
-      << "\n"; 
-  }
-
-  Float_t  tquality;
-  Double_t kroady = fReconstructor->GetRecoParam() ->GetRoad1y();
-  Double_t kroadz = fPadLength * .5 + 1.;
-  
-  // initialize configuration parameters
-  Float_t zcorr = kZcorr ? fTilt * (fZfit[0] - fZref[0]) : 0.;
-  Int_t   niter = kZcorr ? 1 : 2;
-  
-  Double_t yexp, zexp;
-  Int_t ncl = 0;
-  // start seed update
-  for (Int_t iter = 0; iter < niter; iter++) {
-    ncl = 0;
-    for (Int_t iTime = 0; iTime < AliTRDtrackerV1::GetNTimeBins(); iTime++) {
-      if(!(layer = chamber->GetTB(iTime))) continue;
-      if(!Int_t(*layer)) continue;
-      
-      // define searching configuration
-      Double_t dxlayer = layer->GetX() - fX0;
-      if(c){
-        zexp = c->GetZ();
-        //Try 2 pad-rows in second iteration
-        if (iter > 0) {
-          zexp = fZref[0] + fZref[1] * dxlayer - zcorr;
-          if (zexp > c->GetZ()) zexp = c->GetZ() + fPadLength*0.5;
-          if (zexp < c->GetZ()) zexp = c->GetZ() - fPadLength*0.5;
-        }
-      } else zexp = fZref[0] + (kZcorr ? fZref[1] * dxlayer : 0.);
-      yexp  = fYref[0] + fYref[1] * dxlayer - zcorr;
-      
-      // Get and register cluster
-      Int_t    index = layer->SearchNearestCluster(yexp, zexp, kroady, kroadz);
-      if (index < 0) continue;
-      AliTRDcluster *cl = (*layer)[index];
-      
-      fIndexes[iTime]  = layer->GetGlobalIndex(index);
-      fClusters[iTime] = cl;
-//       fY[iTime]        = cl->GetY();
-//       fZ[iTime]        = cl->GetZ();
-      ncl++;
-    }
-    if(fReconstructor->GetStreamLevel(AliTRDReconstructor::kTracker)>=7) AliInfo(Form("iter = %d ncl [%d] = %d", iter, fDet, ncl));
-    
-    if(ncl>1){ 
-      // calculate length of the time bin (calibration aware)
-      Int_t irp = 0; Float_t x[2]={0., 0.}; Int_t tb[2] = {0,0};
-      for (Int_t iTime = 0; iTime < AliTRDtrackerV1::GetNTimeBins(); iTime++) {
-        if(!fClusters[iTime]) continue;
-        x[irp]  = fClusters[iTime]->GetX();
-        tb[irp] = iTime;
-        irp++;
-        if(irp==2) break;
-      } 
-      Int_t dtb = tb[1] - tb[0];
-      fdX = dtb ? (x[0] - x[1]) / dtb : 0.15;
-
-      // update X0 from the clusters (calibration/alignment aware)
-      for (Int_t iTime = 0; iTime < AliTRDtrackerV1::GetNTimeBins(); iTime++) {
-        if(!(layer = chamber->GetTB(iTime))) continue;
-        if(!layer->IsT0()) continue;
-        if(fClusters[iTime]){ 
-          fX0 = fClusters[iTime]->GetX();
-          break;
-        } else { // we have to infere the position of the anode wire from the other clusters
-          for (Int_t jTime = iTime+1; jTime < AliTRDtrackerV1::GetNTimeBins(); jTime++) {
-            if(!fClusters[jTime]) continue;
-            fX0 = fClusters[jTime]->GetX() + fdX * (jTime - iTime);
-            break;
-          }
-        }
-      }        
-      
-      // update YZ reference point
-      // TODO
-      
-      // update x reference positions (calibration/alignment aware)
+// //____________________________________________________________________
+// Bool_t      AliTRDseedV1::AttachClustersIter(AliTRDtrackingChamber *chamber, Float_t quality, Bool_t kZcorr, AliTRDcluster *c)
+// {
+//   //
+//   // Iterative process to register clusters to the seed.
+//   // In iteration 0 we try only one pad-row and if quality not
+//   // sufficient we try 2 pad-rows (about 5% of tracks cross 2 pad-rows)
+//   //
+//   // debug level 7
+//   //
+//   
+//   if(!fReconstructor->GetRecoParam() ){
+//     AliError("Seed can not be used without a valid RecoParam.");
+//     return kFALSE;
+//   }
+// 
+//   AliTRDchamberTimeBin *layer = 0x0;
+//   if(fReconstructor->GetStreamLevel(AliTRDReconstructor::kTracker)>=7){
+//     AliTRDtrackingChamber ch(*chamber);
+//     ch.SetOwner(); 
+//     TTreeSRedirector &cstreamer = *fReconstructor->GetDebugStream(AliTRDReconstructor::kTracker);
+//     cstreamer << "AttachClustersIter"
+//       << "chamber.="   << &ch
+//       << "tracklet.="  << this
+//       << "\n";      
+//   }
+// 
+//   Float_t  tquality;
+//   Double_t kroady = fReconstructor->GetRecoParam() ->GetRoad1y();
+//   Double_t kroadz = fPadLength * .5 + 1.;
+//   
+//   // initialize configuration parameters
+//   Float_t zcorr = kZcorr ? fTilt * (fZfit[0] - fZref[0]) : 0.;
+//   Int_t   niter = kZcorr ? 1 : 2;
+//   
+//   Double_t yexp, zexp;
+//   Int_t ncl = 0;
+//   // start seed update
+//   for (Int_t iter = 0; iter < niter; iter++) {
+//     ncl = 0;
+//     for (Int_t iTime = 0; iTime < AliTRDtrackerV1::GetNTimeBins(); iTime++) {
+//       if(!(layer = chamber->GetTB(iTime))) continue;
+//       if(!Int_t(*layer)) continue;
+//       
+//       // define searching configuration
+//       Double_t dxlayer = layer->GetX() - fX0;
+//       if(c){
+//         zexp = c->GetZ();
+//         //Try 2 pad-rows in second iteration
+//         if (iter > 0) {
+//           zexp = fZref[0] + fZref[1] * dxlayer - zcorr;
+//           if (zexp > c->GetZ()) zexp = c->GetZ() + fPadLength*0.5;
+//           if (zexp < c->GetZ()) zexp = c->GetZ() - fPadLength*0.5;
+//         }
+//       } else zexp = fZref[0] + (kZcorr ? fZref[1] * dxlayer : 0.);
+//       yexp  = fYref[0] + fYref[1] * dxlayer - zcorr;
+//       
+//       // Get and register cluster
+//       Int_t    index = layer->SearchNearestCluster(yexp, zexp, kroady, kroadz);
+//       if (index < 0) continue;
+//       AliTRDcluster *cl = (*layer)[index];
+//       
+//       fIndexes[iTime]  = layer->GetGlobalIndex(index);
+//       fClusters[iTime] = cl;
+// //       fY[iTime]        = cl->GetY();
+// //       fZ[iTime]        = cl->GetZ();
+//       ncl++;
+//     }
+//     if(fReconstructor->GetStreamLevel(AliTRDReconstructor::kTracker)>=7) AliInfo(Form("iter = %d ncl [%d] = %d", iter, fDet, ncl));
+//     
+//     if(ncl>1){      
+//       // calculate length of the time bin (calibration aware)
+//       Int_t irp = 0; Float_t x[2]={0., 0.}; Int_t tb[2] = {0,0};
 //       for (Int_t iTime = 0; iTime < AliTRDtrackerV1::GetNTimeBins(); iTime++) {
 //         if(!fClusters[iTime]) continue;
-//         fX[iTime] = fX0 - fClusters[iTime]->GetX();
+//         x[irp]  = fClusters[iTime]->GetX();
+//         tb[irp] = iTime;
+//         irp++;
+//         if(irp==2) break;
 //       } 
-      
-      FitMI();
-    }
-    if(fReconstructor->GetStreamLevel(AliTRDReconstructor::kTracker)>=7) AliInfo(Form("iter = %d nclFit [%d] = %d", iter, fDet, fN2));
-    
-    if(IsOK()){
-      tquality = GetQuality(kZcorr);
-      if(tquality < quality) break;
-      else quality = tquality;
-    }
-    kroadz *= 2.;
-  } // Loop: iter
-  if (!IsOK()) return kFALSE;
-
-  if(fReconstructor->GetStreamLevel(AliTRDReconstructor::kTracker)>=1) CookLabels();
-
-  // load calibration params
-  Calibrate();
-  UpdateUsed();
-  return kTRUE;        
-}
+//       Int_t dtb = tb[1] - tb[0];
+//       fdX = dtb ? (x[0] - x[1]) / dtb : 0.15;
+// 
+//       // update X0 from the clusters (calibration/alignment aware)
+//       for (Int_t iTime = 0; iTime < AliTRDtrackerV1::GetNTimeBins(); iTime++) {
+//         if(!(layer = chamber->GetTB(iTime))) continue;
+//         if(!layer->IsT0()) continue;
+//         if(fClusters[iTime]){ 
+//           fX0 = fClusters[iTime]->GetX();
+//           break;
+//         } else { // we have to infere the position of the anode wire from the other clusters
+//           for (Int_t jTime = iTime+1; jTime < AliTRDtrackerV1::GetNTimeBins(); jTime++) {
+//             if(!fClusters[jTime]) continue;
+//             fX0 = fClusters[jTime]->GetX() + fdX * (jTime - iTime);
+//             break;
+//           }
+//         }
+//       }     
+//       
+//       // update YZ reference point
+//       // TODO
+//       
+//       // update x reference positions (calibration/alignment aware)
+// //       for (Int_t iTime = 0; iTime < AliTRDtrackerV1::GetNTimeBins(); iTime++) {
+// //         if(!fClusters[iTime]) continue;
+// //         fX[iTime] = fX0 - fClusters[iTime]->GetX();
+// //       } 
+//       
+//       FitMI();
+//     }
+//     if(fReconstructor->GetStreamLevel(AliTRDReconstructor::kTracker)>=7) AliInfo(Form("iter = %d nclFit [%d] = %d", iter, fDet, fN2));
+//     
+//     if(IsOK()){
+//       tquality = GetQuality(kZcorr);
+//       if(tquality < quality) break;
+//       else quality = tquality;
+//     }
+//     kroadz *= 2.;
+//   } // Loop: iter
+//   if (!IsOK()) return kFALSE;
+// 
+//   if(fReconstructor->GetStreamLevel(AliTRDReconstructor::kTracker)>=1) CookLabels();
+// 
+//   // load calibration params
+//   Calibrate();
+//   UpdateUsed();
+//   return kTRUE;     
+// }
 
 //____________________________________________________________________
 Bool_t AliTRDseedV1::AttachClusters(AliTRDtrackingChamber *chamber, Bool_t tilt)
@@ -969,18 +994,6 @@ Bool_t     AliTRDseedV1::AttachClusters(AliTRDtrackingChamber *chamber, Bool_t tilt)
     return kFALSE;
   }
 
-  // update used clusters and select
-  fNUsed = 0;
-  for (Int_t it = 0; it < AliTRDtrackerV1::GetNTimeBins(); it++) {
-    if(fClusters[it] && fClusters[it]->IsUsed()) fNUsed++;
-    if(fClusters[it+kNtb] && fClusters[it+kNtb]->IsUsed()) fNUsed++;
-  }
-  if (fN2-fNUsed < kClmin){
-    //AliWarning(Form("Too many clusters already in use %d (from %d).", fNUsed, fN2));
-    fN2 = 0;
-    return kFALSE;
-  }
-
   // Load calibration parameters for this tracklet  
   Calibrate();
 
@@ -1218,15 +1231,18 @@ Bool_t AliTRDseedV1::Fit(Bool_t tilt, Int_t errors)
   fCov[2] = p[3]; // variance of dydx
   // the ref radial position is set at the minimum of 
   // the y variance of the tracklet
-  fX = -fCov[1]/fCov[2]; //fXref = fX0 - fXref;
+  fX   = -fCov[1]/fCov[2]; //fXref = fX0 - fXref;
+  fS2Y = fCov[0] +2.*fX*fCov[1] + fX*fX*fCov[2];
 
   // fit XZ
   if(IsRowCross()){ 
     // TODO pad row cross position estimation !!!
     //AliInfo(Form("Padrow cross in detector %d", fDet));
     fZfit[0] = .5*(zc[0]+zc[fN-1]); fZfit[1] = 0.;
+    fS2Z     = 0.02+1.55*fZref[1]; fS2Z *= fS2Z;
   } else {
     fZfit[0] = zc[0]; fZfit[1] = 0.;
+    fS2Z     = fPadLength*fPadLength/12.;
   }
 
 
@@ -1275,10 +1291,7 @@ Bool_t AliTRDseedV1::Fit(Bool_t tilt, Int_t errors)
 }
 
 
-
-
-
-
+/*
 //_____________________________________________________________________________
 void AliTRDseedV1::FitMI()
 {
@@ -1424,12 +1437,12 @@ void AliTRDseedV1::FitMI()
       if(!fClusters[i]->IsInChamber()) continue;
       if (TMath::Abs(fZ[i] - allowedz[i]) > 2) continue;
       // Residual y
-      //yres[i] = fY[i] - fYref[0] - (fYref[1] + anglecor) * fX[i] /*+ fTilt*(fZ[i] - fZref[0])*/;   
+      //yres[i] = fY[i] - fYref[0] - (fYref[1] + anglecor) * fX[i] + fTilt*(fZ[i] - fZref[0]);   
       yres[i] = fY[i] - fTilt*(fZ[i] - (fZref[0] - fX[i]*fZref[1]));
-/*      if (TMath::Abs(fZ[i] - fZProb) > 2) {
-        if (fZ[i] > fZProb) yres[i] += fTilt * fPadLength;
-        if (fZ[i] < fZProb) yres[i] -= fTilt * fPadLength;
-      }*/
+//       if (TMath::Abs(fZ[i] - fZProb) > 2) {
+//         if (fZ[i] > fZProb) yres[i] += fTilt * fPadLength;
+//         if (fZ[i] < fZProb) yres[i] -= fTilt * fPadLength;
+      }
     }
   }
   
@@ -1528,8 +1541,7 @@ void AliTRDseedV1::FitMI()
   fYfit[1]   = -fYfit[1];
 
   UpdateUsed();
-}
-
+}*/
 
 //___________________________________________________________________
 void AliTRDseedV1::Print(Option_t *o) const
@@ -1539,7 +1551,7 @@ void AliTRDseedV1::Print(Option_t *o) const
   //
 
   AliInfo(Form("Det[%3d] Tilt[%+6.2f] Pad[%5.2f]", fDet, fTilt, fPadLength));
-  AliInfo(Form("N[%2d] Nuse[%2d]", fN2, fNUsed));
+  AliInfo(Form("N[%2d] ", fN2));
   AliInfo(Form("x[%7.2f] y[%7.2f] z[%7.2f] dydx[%5.2f] dzdx[%5.2f]", fX0, fYfit[0], fZfit[0], fYfit[1], fZfit[1]));
   AliInfo(Form("Ref        y[%7.2f] z[%7.2f] dydx[%5.2f] dzdx[%5.2f]", fYref[0], fZref[0], fYref[1], fZref[1]))
 
@@ -1579,7 +1591,7 @@ Bool_t AliTRDseedV1::IsEqual(const TObject *o) const
 //     if ( fZ[i] != inTracklet->GetZ(i) ) return kFALSE;
     if ( fIndexes[i] != inTracklet->fIndexes[i] ) return kFALSE;
   }
-  if ( fUsable != inTracklet->fUsable ) return kFALSE;
+//   if ( fUsable != inTracklet->fUsable ) return kFALSE;
 
   for (Int_t i=0; i < 2; i++){
     if ( fYfit[i] != inTracklet->fYfit[i] ) return kFALSE;
index 8d0707a..7f56488 100644 (file)
 #include "AliRieman.h"
 #endif
 
+#ifndef ALITRDCLUSTER_H 
+#include "AliTRDcluster.h"
+#endif
+
 class TTreeSRedirector;
 
 class AliRieman;
 
 class AliTRDtrackingChamber;
-class AliTRDcluster;
 class AliTRDtrackV1;
 class AliTRDReconstructor;
 class AliTRDseedV1 : public TObject //TODO we should inherit 
@@ -50,9 +53,11 @@ public:
 
   // bits from 0-13 are reserved by ROOT (see TObject.h)
   enum ETRDtrackletStatus {
-    kOwner    = BIT(14) // owner of its clusters
-   ,kRowCross = BIT(15) // pad row cross tracklet
-   ,kCalib    = BIT(16) // calibrated tracklet
+    kOwner      = BIT(14) // owner of its clusters
+   ,kRowCross   = BIT(15) // pad row cross tracklet
+   ,kCalib      = BIT(16) // calibrated tracklet
+   ,kKink       = BIT(17) // kink prolongation tracklet
+   ,kStandAlone = BIT(18)
   };
 
   AliTRDseedV1(Int_t det = -1);
@@ -60,9 +65,9 @@ public:
   AliTRDseedV1(const AliTRDseedV1 &ref);
   AliTRDseedV1& operator=(const AliTRDseedV1 &ref);
 
-  Bool_t         AttachClustersIter(
+/*  Bool_t       AttachClustersIter(
               AliTRDtrackingChamber *chamber, Float_t quality, 
-              Bool_t kZcorr = kFALSE, AliTRDcluster *c=0x0);
+              Bool_t kZcorr = kFALSE, AliTRDcluster *c=0x0);*/
   Bool_t         AttachClusters(
               AliTRDtrackingChamber *chamber, Bool_t tilt = kFALSE);
   void      Bootstrap(const AliTRDReconstructor *rec);
@@ -70,20 +75,23 @@ public:
   void      CookdEdx(Int_t nslices);
   void      CookLabels();
   Bool_t    Fit(Bool_t tilt=kTRUE, Int_t errors = 2);
-  void      FitMI();
+//   void      FitMI();
   Bool_t    Init(AliTRDtrackV1 *track);
   inline void      Init(const AliRieman *fit);
   Bool_t    IsEqual(const TObject *inTracklet) const;
   Bool_t    IsCalibrated() const     { return TestBit(kCalib);}
   Bool_t    IsOwner() const          { return TestBit(kOwner);}
-  Bool_t    IsOK() const             { return fN2 > 4;}
+  Bool_t    IsKink() const           { return TestBit(kKink);}
+  Bool_t    IsOK() const             { return fN2 > 4 && fNUsed < 4;}
   Bool_t    IsRowCross() const       { return TestBit(kRowCross);}
-  Bool_t    IsUsable(Int_t i) const  { return TESTBIT(fUsable, i);}
+  Bool_t    IsUsable(Int_t i) const  { return fClusters[i] && !fClusters[i]->IsUsed();}
+  Bool_t    IsStandAlone() const     { return TestBit(kStandAlone);}
 
   Float_t   GetC() const             { return fC; }
   Float_t   GetChi2() const          { return fChi2; }
   inline Float_t   GetChi2Z() const;
   inline Float_t   GetChi2Y() const;
+  inline Float_t   GetChi2Phi() const;
   static void      GetClusterXY(const AliTRDcluster *c, Double_t &x, Double_t &y);
   void      GetCovAt(Double_t x, Double_t *cov) const;
   void      GetCovXY(Double_t *cov) const { memcpy(cov, &fCov[0], 3*sizeof(Double_t));}
@@ -122,7 +130,7 @@ public:
   Double_t  GetZat(Double_t x) const { return fZfit[0] - fZfit[1] * (fX0-x);}
   Float_t   GetZfit(Int_t id) const { return fZfit[id];}
   Float_t   GetZref(Int_t id) const { return fZref[id];}
-  Long_t    GetUsabilityMap() const { return fUsable; }
+//   Long_t    GetUsabilityMap() const { return fUsable; }
 
   inline AliTRDcluster* NextCluster();
   inline AliTRDcluster* PrevCluster();
@@ -135,6 +143,8 @@ public:
   void      SetCovRef(const Double_t *cov) { memcpy(&fRefCov[0], cov, 3*sizeof(Double_t));}
   void      SetIndexes(Int_t i, Int_t idx) { fIndexes[i]  = idx; }
   void      SetLabels(Int_t *lbls)   { memcpy(fLabels, lbls, 3*sizeof(Int_t)); }
+  void      SetKink(Bool_t k)        { SetBit(kKink, k);}
+  void      SetStandAlone(Bool_t st) { SetBit(kStandAlone, st); }
   void      SetMomentum(Double_t mom){ fMom = mom;}
   void      SetOwner();
   void      SetTilt(Float_t tilt)    { fTilt = tilt; }
@@ -145,7 +155,7 @@ public:
   void      SetX0(Float_t x0)        { fX0 = x0; }
   void      SetYref(Int_t i, Float_t y) { fYref[i]     = y;}
   void      SetZref(Int_t i, Float_t z) { fZref[i]     = z;}
-  void      SetUsabilityMap(Long_t um)  { fUsable = um; }
+//   void      SetUsabilityMap(Long_t um)  { fUsable = um; }
   void      UpDate(const AliTRDtrackV1* trk);
   void      UpdateUsed();
   void      UseClusters();
@@ -164,9 +174,9 @@ private:
   Float_t          fDiffL;                  //! longitudinal diffusion coefficient
   Float_t          fDiffT;                  //! transversal diffusion coefficient
   Char_t           fClusterIdx;             //! clusters iterator
-  Long_t           fUsable;                 //! bit map of usable clusters
+//  ULong_t          fUsable;                 //! bit map of usable clusters
   UChar_t          fN2;                     // number of clusters attached
-  UChar_t          fNUsed;                  // number of used usable clusters
+ UChar_t          fNUsed;                  // number of used usable clusters
   Short_t          fDet;                    // TRD detector
   Float_t          fTilt;                   // local tg of the tilt angle 
   Float_t          fPadLength;              // local pad length 
@@ -213,6 +223,15 @@ inline Float_t AliTRDseedV1::GetChi2Y() const
 }
 
 //____________________________________________________________
+inline Float_t AliTRDseedV1::GetChi2Phi() const
+{
+  Double_t dphi = fYref[1]-fYfit[1]; dphi*=dphi;
+  Double_t cov[3]; GetCovAt(fX, cov);
+  Double_t s2 = fRefCov[2]+cov[2];
+  return s2 > 0. ? dphi/s2 : 0.; 
+}
+
+//____________________________________________________________
 inline void AliTRDseedV1::Init(const AliRieman *rieman)
 {
   fZref[0] = rieman->GetZat(fX0);
index 524773d..72e2eeb 100644 (file)
@@ -44,6 +44,7 @@ public:
   enum ETRDtrackV1Status {
     kOwner   = BIT(14)
    ,kStopped = BIT(15) 
+   ,kKink    = BIT(16) 
   };
 
   AliTRDtrackV1();
@@ -78,8 +79,9 @@ public:
   UShort_t*      GetTrackletIndexes() { return &fTrackletIndex[0];}
   
   Bool_t         IsEqual(const TObject *inTrack) const;
-  Bool_t         IsOwner() const {return TestBit(kOwner);};
-  Bool_t         IsStopped() const {return TestBit(kStopped);};
+  Bool_t         IsKink() const    { return TestBit(kKink);}
+  Bool_t         IsOwner() const   { return TestBit(kOwner);};
+  Bool_t         IsStopped() const { return TestBit(kStopped);};
   Bool_t         IsElectron() const;
   
   void           MakeBackupTrack();
@@ -90,6 +92,7 @@ public:
   Bool_t         Rotate(Double_t angle, Bool_t absolute = kFALSE);
   void           SetBudget(Int_t i, Double_t b) {if(i>=0 && i<3) fBudget[i] = b;}
   void           SetEdep(Double32_t inDE){fDE = inDE;};
+  void           SetKink(Bool_t k)        { SetBit(kKink, k);}
   void           SetNumberOfClusters();
   void           SetOwner();
   void           SetPID(Short_t is, Double_t inPID){if (is >=0 && is < AliPID::kSPECIES) fPID[is]=inPID;};
index 4e704a4..f91ee07 100644 (file)
@@ -290,7 +290,7 @@ void AliTRDtrackerDebug::ResidualsTrackletsTrack() const
     AliTRDseedV1 ts(tracklet[ip]);
     ts.SetYref(0, y0); ts.SetYref(1, dydx);
     ts.SetZref(0, z0); ts.SetZref(1, dzdx);
-    ts.FitMI();
+    ts.Fit(kTRUE);
 
     // save results for plotting
     Int_t plane   = tracklet[ip].GetPlane();
index 042f4d8..d922f57 100644 (file)
@@ -282,7 +282,7 @@ Int_t AliTRDtrackerV1::PropagateBack(AliESDEvent *event)
     // Do the back prolongation
     new(&track) AliTRDtrackV1(*seed);
     track.SetReconstructor(fReconstructor);
-
+    track.SetKink(Bool_t(seed->GetKinkIndex(0)));
     //Int_t   lbl         = seed->GetLabel();
     //track.SetSeedLabel(lbl);
 
@@ -319,13 +319,11 @@ Int_t AliTRDtrackerV1::PropagateBack(AliESDEvent *event)
       Int_t foundClr = track.GetNumberOfClusters();
       if (foundClr >= foundMin) {
         track.CookLabel(1. - fgkLabelFraction);
-        if(track.GetBackupTrack()) UseClusters(track.GetBackupTrack());
+        //if(track.GetBackupTrack()) UseClusters(track.GetBackupTrack());
 
         // Sign only gold tracks
         if (track.GetChi2() / track.GetNumberOfClusters() < 4) {
-          if ((seed->GetKinkIndex(0)      ==   0) && (track.Pt() <  1.5)){
-            //UseClusters(&track);
-          }
+          //if ((seed->GetKinkIndex(0)      ==   0) && (track.Pt() <  1.5)) UseClusters(&track);
         }
         Bool_t isGold = kFALSE;
   
@@ -638,6 +636,7 @@ Int_t AliTRDtrackerV1::FollowBackProlongation(AliTRDtrackV1 &t)
     if(!ptrTracklet){
       ptrTracklet = new(&tracklet) AliTRDseedV1(ilayer);
       ptrTracklet->SetReconstructor(fReconstructor);
+      ptrTracklet->SetKink(t.IsKink());
       alpha = t.GetAlpha();
       Int_t sector = Int_t(alpha/AliTRDgeometry::GetAlpha() + (alpha>0. ? 0 : AliTRDgeometry::kNsector));
 
@@ -683,9 +682,10 @@ Int_t AliTRDtrackerV1::FollowBackProlongation(AliTRDtrackV1 &t)
       
         break;
       }
-      //ptrTracklet->UseClusters();
-    }// else ptrTracklet->Init(&t);
+      ptrTracklet->UpdateUsed();
+    }
     if(!ptrTracklet->IsOK()){
+      ptrTracklet->Reset();
       if(x < 1.) continue; //temporary
       if(!PropagateToX(t, x-fgkMaxStep, fgkMaxStep)) return -1/*nClustersExpected*/;
       if(!AdjustSector(&t)) return -1/*nClustersExpected*/;
@@ -700,6 +700,7 @@ Int_t AliTRDtrackerV1::FollowBackProlongation(AliTRDtrackV1 &t)
     if (TMath::Abs(t.GetSnp()) > fgkMaxSnp) return -1/*nClustersExpected*/;
     
     // load tracklet to the tracker and the track
+    ptrTracklet->UseClusters();
     ptrTracklet->Fit(kFALSE); // no tilt correction
     ptrTracklet = SetTracklet(ptrTracklet);
     t.SetTracklet(ptrTracklet, fTracklets->GetEntriesFast()-1);
@@ -891,7 +892,7 @@ Float_t AliTRDtrackerV1::FitTiltedRiemanConstraint(AliTRDseedV1 *tracklets, Doub
   Int_t nPoints = 0;
   for(Int_t ilr = 0; ilr < AliTRDgeometry::kNlayer; ilr++){
     if(!tracklets[ilr].IsOK()) continue;
-    for(Int_t itb = 0; itb < fgNTimeBins; itb++){
+    for(Int_t itb = 0; itb < AliTRDseedV1::kNTimeBins; itb++){
       if(!tracklets[ilr].IsUsable(itb)) continue;
       cl = tracklets[ilr].GetClusters(itb);
       x = cl->GetX();
@@ -903,7 +904,7 @@ Float_t AliTRDtrackerV1::FitTiltedRiemanConstraint(AliTRDseedV1 *tracklets, Doub
       uvt[0] = 2. * x * t;
       uvt[1] = 2. * x * t * tilt ;
       w = 2. * (y + tilt * (z - zVertex)) * t;
-      error = 2. * 0.2 * t;
+      error = 2. * TMath::Sqrt(cl->GetSigmaY2()) * t;
       fitter->AddPoint(uvt, w, error);
       nPoints++;
     }
@@ -985,7 +986,7 @@ Float_t AliTRDtrackerV1::FitTiltedRieman(AliTRDseedV1 *tracklets, Bool_t sigErro
   // Containers for Least-square fitter
   for(Int_t ipl = 0; ipl < kNPlanes; ipl++){
     if(!tracklets[ipl].IsOK()) continue;
-    for(Int_t itb = 0; itb < fgNTimeBins; itb++){
+    for(Int_t itb = 0; itb < AliTRDseedV1::kNTimeBins; itb++){
       if(!(cl = tracklets[ipl].GetClusters(itb))) continue;
       if (!tracklets[ipl].IsUsable(itb)) continue;
       x = cl->GetX();
@@ -1002,7 +1003,7 @@ Float_t AliTRDtrackerV1::FitTiltedRieman(AliTRDseedV1 *tracklets, Bool_t sigErro
       w = 2. * (y + tilt*z) * t;
       // error definition changes for the different calls
       we = 2. * t;
-      we *= sigError ? tracklets[ipl].GetSigmaY() : 0.2;
+      we *= sigError ? TMath::Sqrt(cl->GetSigmaY2()) : 0.2;
       fitter->AddPoint(uvt, w, we);
       zfitter.AddPoint(&x, z, static_cast<Double_t>(TMath::Sqrt(cl->GetSigmaZ2())));
       nPoints++;
@@ -1230,7 +1231,7 @@ Double_t AliTRDtrackerV1::FitRiemanTilt(const AliTRDtrackV1 *track, AliTRDseedV1
   // Containers for Least-square fitter
   for(Int_t ipl = 0; ipl < kNPlanes; ipl++){
     if(!tracklets[ipl].IsOK()) continue;
-    for(Int_t itb = 0; itb < fgNTimeBins; itb++){
+    for(Int_t itb = 0; itb < AliTRDseedV1::kNTimeBins; itb++){
       if(!(cl = tracklets[ipl].GetClusters(itb))) continue;
       if (!tracklets[ipl].IsUsable(itb)) continue;
       x = cl->GetX();
@@ -1247,7 +1248,7 @@ Double_t AliTRDtrackerV1::FitRiemanTilt(const AliTRDtrackV1 *track, AliTRDseedV1
       w = 2. * (y + tilt*z) * t;
       // error definition changes for the different calls
       we = 2. * t;
-      we *= sigError ? tracklets[ipl].GetSigmaY() : 0.2;
+      we *= sigError ? TMath::Sqrt(cl->GetSigmaY2()) : 0.2;
       fitter->AddPoint(uvt, w, we);
       zfitter.AddPoint(&x, z, static_cast<Double_t>(TMath::Sqrt(cl->GetSigmaZ2())));
       nPoints++;
@@ -1970,7 +1971,7 @@ Int_t AliTRDtrackerV1::Clusters2TracksStack(AliTRDtrackingChamber **stack, TClon
         for (Int_t jLayer = 0; jLayer < kNPlanes; jLayer++) {
           Int_t jseed = kNPlanes*trackIndex+jLayer;
           if(!sseed[jseed].IsOK()) continue;
-          if (TMath::Abs(sseed[jseed].GetYref(0) / sseed[jseed].GetX0()) < 0.15) findable++;
+          if (TMath::Abs(sseed[jseed].GetYref(0) / sseed[jseed].GetX0()) < 0.158) findable++;
         
           sseed[jseed].UpdateUsed();
           ncl   += sseed[jseed].GetN2();
@@ -1978,188 +1979,172 @@ Int_t AliTRDtrackerV1::Clusters2TracksStack(AliTRDtrackingChamber **stack, TClon
           nlayers++;
         }
 
-  // Filter duplicated tracks
-  if (nused > 30){
-    //printf("Skip %d nused %d\n", trackIndex, nused);
-    fakeTrack[trackIndex] = kTRUE;
-    continue;
-  }
-  if (Float_t(nused)/ncl >= .25){
-    //printf("Skip %d nused/ncl >= .25\n", trackIndex);
-    fakeTrack[trackIndex] = kTRUE;
-    continue;
-  }
-        
-  // Classify tracks
-  Bool_t skip = kFALSE;
-  switch(jSieve){
-  case 0:
-    if(nlayers < 6) {skip = kTRUE; break;}
-    if(TMath::Log(1.E-9+fTrackQuality[trackIndex]) < -5.){skip = kTRUE; break;}
-    break;
-  
-  case 1:
-    if(nlayers < findable){skip = kTRUE; break;}
-    if(TMath::Log(1.E-9+fTrackQuality[trackIndex]) < -4.){skip = kTRUE; break;}
-    break;
-  
-  case 2:
-    if ((nlayers == findable) || (nlayers == 6)) { skip = kTRUE; break;}
-    if (TMath::Log(1.E-9+fTrackQuality[trackIndex]) < -6.0){skip = kTRUE; break;}
-    break;
-  
-  case 3:
-    if (TMath::Log(1.E-9+fTrackQuality[trackIndex]) < -5.){skip = kTRUE; break;}
-    break;
-  
-  case 4:
-    if (nlayers == 3){skip = kTRUE; break;}
-    //if (TMath::Log(1.E-9+fTrackQuality[trackIndex]) - nused/(nlayers-3.0) < -15.0){skip = kTRUE; break;}
-    break;
-  }
-  if(skip){
-    candidates++;
-    //printf("REJECTED : %d [%d] nlayers %d trackQuality = %e nused %d\n", itrack, trackIndex, nlayers, fTrackQuality[trackIndex], nused);
-    continue;
-  }
-  signedTrack[trackIndex] = kTRUE;
-            
-        
-  // Sign clusters
-  AliTRDcluster *cl = 0x0; Int_t clusterIndex = -1;
-  for (Int_t jLayer = 0; jLayer < kNPlanes; jLayer++) {
-    Int_t jseed = kNPlanes*trackIndex+jLayer;
-    if(!sseed[jseed].IsOK()) continue;
-    if(TMath::Abs(sseed[jseed].GetYfit(1) - sseed[jseed].GetYfit(1)) >= .2) continue; // check this condition with Marian
-    sseed[jseed].UseClusters();
-    if(!cl){
-      ic = 0;
-      while(!(cl = sseed[jseed].GetClusters(ic))) ic++;
-      clusterIndex =  sseed[jseed].GetIndexes(ic);
-    }
-  }
-  if(!cl) continue;
-
-        
-  // Build track parameters
-  AliTRDseedV1 *lseed =&sseed[trackIndex*6];
-/*  Int_t idx = 0;
-  while(idx<3 && !lseed->IsOK()) {
-    idx++;
-    lseed++;
-  }*/
-  Double_t x = lseed->GetX0();// - 3.5;
-  trackParams[0] = x; //NEW AB
-  trackParams[1] = lseed->GetYref(0); // lseed->GetYat(x);  
-  trackParams[2] = lseed->GetZref(0); // lseed->GetZat(x); 
-  trackParams[3] = TMath::Sin(TMath::ATan(lseed->GetYref(1)));
-  trackParams[4] = lseed->GetZref(1) / TMath::Sqrt(1. + lseed->GetYref(1) * lseed->GetYref(1));
-  trackParams[5] = lseed->GetC();
-  Int_t ich = 0; while(!(chamber = stack[ich])) ich++;
-  trackParams[6] = fGeom->GetSector(chamber->GetDetector());/* *alpha+shift;   // Supermodule*/
+        // Filter duplicated tracks
+        if (nused > 30){
+          //printf("Skip %d nused %d\n", trackIndex, nused);
+          fakeTrack[trackIndex] = kTRUE;
+          continue;
+        }
+        if (Float_t(nused)/ncl >= .25){
+          //printf("Skip %d nused/ncl >= .25\n", trackIndex);
+          fakeTrack[trackIndex] = kTRUE;
+          continue;
+        }
 
-  if(fReconstructor->GetStreamLevel(AliTRDReconstructor::kTracker) > 1){
-    AliInfo(Form("Track %d [%d] nlayers %d trackQuality = %e nused %d, yref = %3.3f", itrack, trackIndex, nlayers, fTrackQuality[trackIndex], nused, trackParams[1]));
-          
-    Int_t nclusters = 0;
-    AliTRDseedV1 *dseed[6];
-
-    // Build track label - what happens if measured data ???
-    Int_t labels[1000];
-    Int_t outlab[1000];
-    Int_t nlab = 0;
-
-    Int_t labelsall[1000];
-    Int_t nlabelsall = 0;
-    Int_t naccepted  = 0;
-
-    for (Int_t iLayer = 0; iLayer < kNPlanes; iLayer++) {
-      Int_t jseed = kNPlanes*trackIndex+iLayer;
-      dseed[iLayer] = new AliTRDseedV1(sseed[jseed]);
-      dseed[iLayer]->SetOwner();
-      nclusters += sseed[jseed].GetN2();
-      if(!sseed[jseed].IsOK()) continue;
-      for(int ilab=0; ilab<2; ilab++){
-        if(sseed[jseed].GetLabels(ilab) < 0) continue;
-        labels[nlab] = sseed[jseed].GetLabels(ilab);
-        nlab++;
-      }
+        // Classify tracks
+        Bool_t skip = kFALSE;
+        switch(jSieve){
+          case 0:
+            if(nlayers < 6) {skip = kTRUE; break;}
+            if(TMath::Log(1.E-9+fTrackQuality[trackIndex]) < -5.){skip = kTRUE; break;}
+            break;
+
+          case 1:
+            if(nlayers < findable){skip = kTRUE; break;}
+            if(TMath::Log(1.E-9+fTrackQuality[trackIndex]) < -4.){skip = kTRUE; break;}
+            break;
+
+          case 2:
+            if ((nlayers == findable) || (nlayers == 6)) { skip = kTRUE; break;}
+            if (TMath::Log(1.E-9+fTrackQuality[trackIndex]) < -6.0){skip = kTRUE; break;}
+            break;
+
+          case 3:
+            if (TMath::Log(1.E-9+fTrackQuality[trackIndex]) < -5.){skip = kTRUE; break;}
+            break;
+
+          case 4:
+            if (nlayers == 3){skip = kTRUE; break;}
+            //if (TMath::Log(1.E-9+fTrackQuality[trackIndex]) - nused/(nlayers-3.0) < -15.0){skip = kTRUE; break;}
+            break;
+        }
+        if(skip){
+          candidates++;
+          //printf("REJECTED : %d [%d] nlayers %d trackQuality = %e nused %d\n", itrack, trackIndex, nlayers, fTrackQuality[trackIndex], nused);
+          continue;
+        }
+        signedTrack[trackIndex] = kTRUE;
+
+        // Build track parameters
+        AliTRDseedV1 *lseed =&sseed[trackIndex*6];
+      /*  Int_t idx = 0;
+        while(idx<3 && !lseed->IsOK()) {
+          idx++;
+          lseed++;
+        }*/
+        Double_t x = lseed->GetX0();// - 3.5;
+        trackParams[0] = x; //NEW AB
+        trackParams[1] = lseed->GetYref(0); // lseed->GetYat(x);  
+        trackParams[2] = lseed->GetZref(0); // lseed->GetZat(x); 
+        trackParams[3] = TMath::Sin(TMath::ATan(lseed->GetYref(1)));
+        trackParams[4] = lseed->GetZref(1) / TMath::Sqrt(1. + lseed->GetYref(1) * lseed->GetYref(1));
+        trackParams[5] = lseed->GetC();
+        Int_t ich = 0; while(!(chamber = stack[ich])) ich++;
+        trackParams[6] = fGeom->GetSector(chamber->GetDetector());/* *alpha+shift;     // Supermodule*/
+
+        if(fReconstructor->GetStreamLevel(AliTRDReconstructor::kTracker) > 1){
+          AliInfo(Form("Track %d [%d] nlayers %d trackQuality = %e nused %d, yref = %3.3f", itrack, trackIndex, nlayers, fTrackQuality[trackIndex], nused, trackParams[1]));
+
+          Int_t nclusters = 0;
+          AliTRDseedV1 *dseed[6];
+
+          // Build track label - what happens if measured data ???
+          Int_t labels[1000];
+          Int_t outlab[1000];
+          Int_t nlab = 0;
+
+          Int_t labelsall[1000];
+          Int_t nlabelsall = 0;
+          Int_t naccepted  = 0;
+
+          for (Int_t iLayer = 0; iLayer < kNPlanes; iLayer++) {
+            Int_t jseed = kNPlanes*trackIndex+iLayer;
+            dseed[iLayer] = new AliTRDseedV1(sseed[jseed]);
+            dseed[iLayer]->SetOwner();
+            printf("Layer[%d], NClusters[%d]\n", iLayer, sseed[jseed].GetN2());
+            nclusters += sseed[jseed].GetN2();
+            if(!sseed[jseed].IsOK()) continue;
+            for(int ilab=0; ilab<2; ilab++){
+              if(sseed[jseed].GetLabels(ilab) < 0) continue;
+              labels[nlab] = sseed[jseed].GetLabels(ilab);
+              nlab++;
+            }
+
+            // Cooking label
+            for (Int_t itime = 0; itime < fgNTimeBins; itime++) {
+              if(!sseed[jseed].IsUsable(itime)) continue;
+              naccepted++;
+              Int_t tindex = 0, ilab = 0;
+              while(ilab<3 && (tindex = sseed[jseed].GetClusters(itime)->GetLabel(ilab)) >= 0){
+                labelsall[nlabelsall++] = tindex;
+                ilab++;
+              }
+            }
+          }
+          Freq(nlab,labels,outlab,kFALSE);
+          Int_t   label     = outlab[0];
+          Int_t   frequency = outlab[1];
+          Freq(nlabelsall,labelsall,outlab,kFALSE);
+          Int_t   label1    = outlab[0];
+          Int_t   label2    = outlab[2];
+          Float_t fakeratio = (naccepted - outlab[1]) / Float_t(naccepted);
+
+          //Int_t eventNrInFile = esd->GetEventNumberInFile();
+          //AliInfo(Form("Number of clusters %d.", nclusters));
+          Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
+          Int_t trackNumber = AliTRDtrackerDebug::GetTrackNumber();
+          Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
+          TTreeSRedirector &cstreamer = *fReconstructor->GetDebugStream(AliTRDReconstructor::kTracker);
+          cstreamer << "Clusters2TracksStack"
+              << "EventNumber="                << eventNumber
+              << "TrackNumber="                << trackNumber
+              << "CandidateNumber="    << candidateNumber
+              << "Iter="                               << fSieveSeeding
+              << "Like="                               << fTrackQuality[trackIndex]
+              << "S0.="                                << dseed[0]
+              << "S1.="                                << dseed[1]
+              << "S2.="                                << dseed[2]
+              << "S3.="                                << dseed[3]
+              << "S4.="                                << dseed[4]
+              << "S5.="                                << dseed[5]
+              << "p0="                         << trackParams[0]
+              << "p1="                         << trackParams[1]
+              << "p2="                         << trackParams[2]
+              << "p3="                         << trackParams[3]
+              << "p4="                         << trackParams[4]
+              << "p5="                         << trackParams[5]
+              << "p6="                         << trackParams[6]
+              << "Label="                              << label
+              << "Label1="                     << label1
+              << "Label2="                     << label2
+              << "FakeRatio="                  << fakeratio
+              << "Freq="                               << frequency
+              << "Ncl="                                << ncl
+              << "NLayers="                    << nlayers
+              << "Findable="                   << findable
+              << "NUsed="                              << nused
+              << "\n";
+        }
 
-      // Cooking label
-      for (Int_t itime = 0; itime < fgNTimeBins; itime++) {
-        if(!sseed[jseed].IsUsable(itime)) continue;
-        naccepted++;
-        Int_t tindex = 0, ilab = 0;
-        while(ilab<3 && (tindex = sseed[jseed].GetClusters(itime)->GetLabel(ilab)) >= 0){
-          labelsall[nlabelsall++] = tindex;
-          ilab++;
+        AliTRDtrackV1 *track = MakeTrack(&sseed[trackIndex*kNPlanes], trackParams);
+        if(!track){
+          AliWarning("Fail to build a TRD Track.");
+          continue;
         }
-      }
-    }
-    Freq(nlab,labels,outlab,kFALSE);
-    Int_t   label     = outlab[0];
-    Int_t   frequency = outlab[1];
-    Freq(nlabelsall,labelsall,outlab,kFALSE);
-    Int_t   label1    = outlab[0];
-    Int_t   label2    = outlab[2];
-    Float_t fakeratio = (naccepted - outlab[1]) / Float_t(naccepted);
-
-    //Int_t eventNrInFile = esd->GetEventNumberInFile();
-    //AliInfo(Form("Number of clusters %d.", nclusters));
-    Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
-    Int_t trackNumber = AliTRDtrackerDebug::GetTrackNumber();
-    Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
-    TTreeSRedirector &cstreamer = *fReconstructor->GetDebugStream(AliTRDReconstructor::kTracker);
-    cstreamer << "Clusters2TracksStack"
-        << "EventNumber="              << eventNumber
-        << "TrackNumber="              << trackNumber
-        << "CandidateNumber="  << candidateNumber
-        << "Iter="                             << fSieveSeeding
-        << "Like="                             << fTrackQuality[trackIndex]
-        << "S0.="                              << dseed[0]
-        << "S1.="                              << dseed[1]
-        << "S2.="                              << dseed[2]
-        << "S3.="                              << dseed[3]
-        << "S4.="                              << dseed[4]
-        << "S5.="                              << dseed[5]
-        << "p0="                               << trackParams[0]
-        << "p1="                               << trackParams[1]
-        << "p2="                               << trackParams[2]
-        << "p3="                               << trackParams[3]
-        << "p4="                               << trackParams[4]
-        << "p5="                               << trackParams[5]
-        << "p6="                               << trackParams[6]
-        << "Label="                            << label
-        << "Label1="                   << label1
-        << "Label2="                   << label2
-        << "FakeRatio="                        << fakeratio
-        << "Freq="                             << frequency
-        << "Ncl="                              << ncl
-        << "NLayers="                  << nlayers
-        << "Findable="                 << findable
-        << "NUsed="                            << nused
-        << "\n";
-  }
       
-  AliTRDtrackV1 *track = MakeTrack(&sseed[trackIndex*kNPlanes], trackParams);
-  if(!track){
-    AliWarning("Fail to build a TRD Track.");
-    continue;
-  }
-
-  //AliInfo("End of MakeTrack()");
-  AliESDtrack *esdTrack = new ((*esdTrackList)[ntracks0++]) AliESDtrack();
-  esdTrack->UpdateTrackParams(track, AliESDtrack::kTRDout);
-  esdTrack->SetLabel(track->GetLabel());
-  track->UpdateESDtrack(esdTrack);
-  // write ESD-friends if neccessary
-  if (fReconstructor->GetStreamLevel(AliTRDReconstructor::kTracker) > 0){
-    AliTRDtrackV1 *calibTrack = new AliTRDtrackV1(*track);
-    calibTrack->SetOwner();
-    esdTrack->AddCalibObject(calibTrack);
-  }
-  ntracks1++;
-  AliTRDtrackerDebug::SetTrackNumber(AliTRDtrackerDebug::GetTrackNumber() + 1);
+        //AliInfo("End of MakeTrack()");
+        AliESDtrack *esdTrack = new ((*esdTrackList)[ntracks0++]) AliESDtrack();
+        esdTrack->UpdateTrackParams(track, AliESDtrack::kTRDout);
+        esdTrack->SetLabel(track->GetLabel());
+        track->UpdateESDtrack(esdTrack);
+        // write ESD-friends if neccessary
+        if (fReconstructor->GetStreamLevel(AliTRDReconstructor::kTracker) > 0){
+          AliTRDtrackV1 *calibTrack = new AliTRDtrackV1(*track);
+          calibTrack->SetOwner();
+          esdTrack->AddCalibObject(calibTrack);
+        }
+        ntracks1++;
+        AliTRDtrackerDebug::SetTrackNumber(AliTRDtrackerDebug::GetTrackNumber() + 1);
       }
 
       jSieve++;
@@ -2389,6 +2374,7 @@ Int_t AliTRDtrackerV1::MakeSeeds(AliTRDtrackingChamber **stack, AliTRDseedV1 *ss
           tseed->SetReconstructor(fReconstructor);
           tseed->SetX0((*cIter) ? (*cIter)->GetX() : x_def[iLayer]);
           tseed->Init(GetRiemanFitter());
+          tseed->SetStandAlone(kTRUE);
         }
       
         Bool_t isFake = kFALSE;
@@ -2448,13 +2434,12 @@ Int_t AliTRDtrackerV1::MakeSeeds(AliTRDtrackingChamber **stack, AliTRDseedV1 *ss
         //AliInfo("Passed chi2 filter.");
       
         // try attaching clusters to tracklets
-        Int_t nUsedCl = 0;
         Int_t mlayers = 0;
         for(int iLayer=0; iLayer<kNSeedPlanes; iLayer++){
           Int_t jLayer = planes[iLayer];
-          if(!cseed[jLayer].AttachClustersIter(stack[jLayer], 5., kFALSE, c[iLayer])) continue;
-          nUsedCl += cseed[jLayer].GetNUsed();
-          if(nUsedCl > 25) break;
+          if(!cseed[jLayer].AttachClusters(stack[jLayer], kTRUE)) continue;
+          cseed[jLayer].UpdateUsed();
+          if(!cseed[jLayer].IsOK()) continue;
           mlayers++;
         }
 
@@ -2470,7 +2455,7 @@ Int_t AliTRDtrackerV1::MakeSeeds(AliTRDtrackingChamber **stack, AliTRDseedV1 *ss
           for(int iLayer=0; iLayer<kNPlanes-kNSeedPlanes; iLayer++){
             Int_t jLayer = planesExt[iLayer];
             if(!(chamber = stack[jLayer])) continue;
-            cseed[jLayer].AttachClustersIter(chamber, 1000.);
+            cseed[jLayer].AttachClusters(chamber, kTRUE);
           }
           fTrackQuality[ntracks] = 1.; // dummy value
           ntracks++;
@@ -2480,8 +2465,13 @@ Int_t AliTRDtrackerV1::MakeSeeds(AliTRDtrackingChamber **stack, AliTRDseedV1 *ss
         }
 
 
+        // Update Seeds and calculate Likelihood
         // fit tracklets and cook likelihood
-        FitTiltedRieman(&cseed[0], kTRUE);// Update Seeds and calculate Likelihood
+        FitTiltedRieman(&cseed[0], kTRUE);
+        for(int iLayer=0; iLayer<kNSeedPlanes; iLayer++){
+          Int_t jLayer = planes[iLayer];
+          cseed[jLayer].Fit(kTRUE);
+        }
         Double_t like = CookLikelihood(&cseed[0], planes); // to be checked
       
         if (TMath::Log(1.E-9 + like) < fReconstructor->GetRecoParam() ->GetTrackLikelihood()){
@@ -2496,7 +2486,6 @@ Int_t AliTRDtrackerV1::MakeSeeds(AliTRDtrackingChamber **stack, AliTRDseedV1 *ss
         fSeedLayer[ntracks]  = config;/*sLayer;*/
       
         // attach clusters to the extrapolation seeds
-        Int_t nusedf   = 0; // debug value
         for(int iLayer=0; iLayer<kNPlanes-kNSeedPlanes; iLayer++){
           Int_t jLayer = planesExt[iLayer];
           if(!(chamber = stack[jLayer])) continue;
@@ -2505,10 +2494,11 @@ Int_t AliTRDtrackerV1::MakeSeeds(AliTRDtrackingChamber **stack, AliTRDseedV1 *ss
           if ((jLayer == 0) && !(cseed[1].IsOK())) continue;
           if ((jLayer == 5) && !(cseed[4].IsOK())) continue;
           AliTRDseedV1 pseed = cseed[jLayer];
-          if(!pseed.AttachClustersIter(chamber, 1000.)) continue;
+          if(!pseed.AttachClusters(chamber, kTRUE)) continue;
+          pseed.Fit(kTRUE);
           cseed[jLayer] = pseed;
-          nusedf += cseed[jLayer].GetNUsed(); // debug value
           FitTiltedRieman(cseed,  kTRUE);
+          cseed[jLayer].Fit(kTRUE);
         }
       
         // AliInfo("Extrapolation done.");
@@ -2597,8 +2587,6 @@ Int_t AliTRDtrackerV1::MakeSeeds(AliTRDtrackingChamber **stack, AliTRDseedV1 *ss
               << "Chi2TC="                     << chi2Vals[1]
               << "Nlayers="                    << mlayers
               << "NClusters="   << ncls
-              << "NUsedS="                     << nUsedCl
-              << "NUsed="                              << nusedf
               << "Like="                               << like
               << "S0.="                                << &cseed[0]
               << "S1.="                                << &cseed[1]
@@ -2658,11 +2646,19 @@ AliTRDtrackV1* AliTRDtrackerV1::MakeTrack(AliTRDseedV1 *seeds, Double_t *params)
 
   AliTRDtrackV1 track(seeds, &params[1], c, params[0], params[6]*alpha+shift);
   track.PropagateTo(params[0]-5.0);
+  AliTRDseedV1 *ptrTracklet = 0x0;
+  // Sign clusters
+  for (Int_t jLayer = 0; jLayer < AliTRDgeometry::kNlayer; jLayer++) {
+    ptrTracklet = &seeds[jLayer];
+    if(!ptrTracklet->IsOK()) continue;
+    if(TMath::Abs(ptrTracklet->GetYref(1) - ptrTracklet->GetYfit(1)) >= .2) continue; // check this condition with Marian
+  }
+  // 
   if(fReconstructor->IsHLT()){ 
-    AliTRDseedV1 *ptrTracklet = 0x0;
     for(Int_t ip=0; ip<kNPlanes; ip++){
       track.UnsetTracklet(ip);
       ptrTracklet = SetTracklet(&seeds[ip]);
+      ptrTracklet->UseClusters();
       track.SetTracklet(ptrTracklet, fTracklets->GetEntriesFast()-1);
     }
     AliTRDtrackV1 *ptrTrack = SetTrack(&track);
@@ -2724,7 +2720,7 @@ Int_t AliTRDtrackerV1::ImproveSeedQuality(AliTRDtrackingChamber **stack, AliTRDs
   //  layers : Array of propagation layers for a stack/supermodule
   //  cseed  : Array of 6 seeding tracklets which has to be improved
   // 
-  // Output :
+  // Output : 
   //   cssed : Improved seeds
   // 
   // Detailed description
@@ -2766,7 +2762,8 @@ Int_t AliTRDtrackerV1::ImproveSeedQuality(AliTRDtrackingChamber **stack, AliTRDs
     for (Int_t jLayer = 5; jLayer > 1; jLayer--) {
       Int_t bLayer = sortindexes[jLayer];
       if(!(chamber = stack[bLayer])) continue;
-      bseed[bLayer].AttachClustersIter(chamber, squality[bLayer], kTRUE);
+      bseed[bLayer].AttachClusters(chamber, kTRUE);
+      bseed[bLayer].Fit(kTRUE);
       if(bseed[bLayer].IsOK()) nLayers++;
     }
 
@@ -2790,7 +2787,6 @@ Int_t AliTRDtrackerV1::ImproveSeedQuality(AliTRDtrackingChamber **stack, AliTRDs
     << "\n";
     }
   } // Loop: iter
-  
   // we are sure that at least 2 tracklets are OK !
   return nLayers+2;
 }
@@ -2815,20 +2811,20 @@ Double_t AliTRDtrackerV1::CalculateTrackLikelihood(AliTRDseedV1 *tracklets, Doub
   // debug level 2
   //
 
-  Double_t sumdaf = 0, nLayers = 0;
+  Double_t chi2phi = 0, nLayers = 0;
   for (Int_t iLayer = 0; iLayer < kNPlanes; iLayer++) {
     if(!tracklets[iLayer].IsOK()) continue;
-    sumdaf += TMath::Abs((tracklets[iLayer].GetYfit(1) - tracklets[iLayer].GetYref(1))/ tracklets[iLayer].GetS2Y());
+    chi2phi += tracklets[iLayer].GetChi2Phi();
     nLayers++;
   }
-  sumdaf /= Float_t (nLayers - 2.0);
+  chi2phi /= Float_t (nLayers - 2.0);
   
   Double_t likeChi2Z  = TMath::Exp(-chi2[2] * 0.14);                   // Chi2Z 
   Double_t likeChi2TC = (fReconstructor->GetRecoParam() ->IsVertexConstrained()) ? 
                                                                                        TMath::Exp(-chi2[1] * 0.677) : 1;                       // Constrained Tilted Riemann
   Double_t likeChi2TR = TMath::Exp(-chi2[0] * 0.78);                   // Non-constrained Tilted Riemann
-  Double_t likeAF     = TMath::Exp(-sumdaf * 3.23);
-  Double_t trackLikelihood     = likeChi2Z * likeChi2TR * likeAF;
+  Double_t likeChi2Phi= TMath::Exp(-chi2phi * 3.23);
+  Double_t trackLikelihood     = likeChi2Z * likeChi2TR * likeChi2Phi;
 
   if(fReconstructor->GetStreamLevel(AliTRDReconstructor::kTracker) >= 2){
     Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
@@ -2840,7 +2836,7 @@ Double_t AliTRDtrackerV1::CalculateTrackLikelihood(AliTRDseedV1 *tracklets, Doub
         << "LikeChi2Z="                                << likeChi2Z
         << "LikeChi2TR="                       << likeChi2TR
         << "LikeChi2TC="                       << likeChi2TC
-        << "LikeAF="                                   << likeAF
+        << "LikeChi2Phi="              << likeChi2Phi
         << "TrackLikelihood=" << trackLikelihood
         << "\n";
   }