]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TRD/AliTRDseedV1.cxx
propagate modifications from time container to the tracklet debug stream
[u/mrichter/AliRoot.git] / TRD / AliTRDseedV1.cxx
index f4a00faee45f786c955720da6cf71c58ba8bdc93..60d4dc8d929f4f22403f6d66c5c3c0d3e9254b7c 100644 (file)
@@ -1,17 +1,17 @@
 /**************************************************************************
- * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
- *                                                                        *
- * Author: The ALICE Off-line Project.                                    *
- * Contributors are mentioned in the code where appropriate.              *
- *                                                                        *
- * Permission to use, copy, modify and distribute this software and its   *
- * documentation strictly for non-commercial purposes is hereby granted   *
- * without fee, provided that the above copyright notice appears in all   *
- * copies and that both the copyright notice and this permission notice   *
- * appear in the supporting documentation. The authors make no claims     *
- * about the suitability of this software for any purpose. It is          *
- * provided "as is" without express or implied warranty.                  *
- **************************************************************************/
+* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+*                                                                        *
+* Author: The ALICE Off-line Project.                                    *
+* Contributors are mentioned in the code where appropriate.              *
+*                                                                        *
+* Permission to use, copy, modify and distribute this software and its   *
+* documentation strictly for non-commercial purposes is hereby granted   *
+* without fee, provided that the above copyright notice appears in all   *
+* copies and that both the copyright notice and this permission notice   *
+* appear in the supporting documentation. The authors make no claims     *
+* about the suitability of this software for any purpose. It is          *
+* provided "as is" without express or implied warranty.                  *
+**************************************************************************/
 
 /* $Id$ */
 
 #include "AliTRDtrackerV1.h"
 #include "AliTRDReconstructor.h"
 #include "AliTRDrecoParam.h"
-#include "AliTRDgeometry.h"
 #include "Cal/AliTRDCalPID.h"
 
 ClassImp(AliTRDseedV1)
 
 //____________________________________________________________________
-AliTRDseedV1::AliTRDseedV1(Int_t plane
+AliTRDseedV1::AliTRDseedV1(Int_t det
   :AliTRDseed()
   ,fReconstructor(0x0)
-  ,fPlane(plane)
+  ,fClusterIter(0x0)
+  ,fClusterIdx(0)
+  ,fDet(det)
   ,fMom(0.)
   ,fSnp(0.)
   ,fTgl(0.)
@@ -60,17 +61,19 @@ AliTRDseedV1::AliTRDseedV1(Int_t plane)
   //
   // Constructor
   //
-       //printf("AliTRDseedV1::AliTRDseedV1()\n");
+  //printf("AliTRDseedV1::AliTRDseedV1()\n");
 
-       for(int islice=0; islice < knSlices; islice++) fdEdx[islice] = 0.;
-       for(int ispec=0; ispec<AliPID::kSPECIES; ispec++) fProb[ispec]  = -1.;
+  for(int islice=0; islice < knSlices; islice++) fdEdx[islice] = 0.;
+  for(int ispec=0; ispec<AliPID::kSPECIES; ispec++) fProb[ispec]  = -1.;
 }
 
 //____________________________________________________________________
 AliTRDseedV1::AliTRDseedV1(const AliTRDseedV1 &ref)
   :AliTRDseed((AliTRDseed&)ref)
   ,fReconstructor(ref.fReconstructor)
-  ,fPlane(ref.fPlane)
+  ,fClusterIter(0x0)
+  ,fClusterIdx(0)
+  ,fDet(ref.fDet)
   ,fMom(ref.fMom)
   ,fSnp(ref.fSnp)
   ,fTgl(ref.fTgl)
@@ -80,9 +83,10 @@ AliTRDseedV1::AliTRDseedV1(const AliTRDseedV1 &ref)
   // Copy Constructor performing a deep copy
   //
 
-       //printf("AliTRDseedV1::AliTRDseedV1(const AliTRDseedV1 &)\n");
-       for(int islice=0; islice < knSlices; islice++) fdEdx[islice] = ref.fdEdx[islice];
-       for(int ispec=0; ispec<AliPID::kSPECIES; ispec++) fProb[ispec] = ref.fProb[ispec];
+  //printf("AliTRDseedV1::AliTRDseedV1(const AliTRDseedV1 &)\n");
+  SetBit(kOwner, kFALSE);
+  for(int islice=0; islice < knSlices; islice++) fdEdx[islice] = ref.fdEdx[islice];
+  for(int ispec=0; ispec<AliPID::kSPECIES; ispec++) fProb[ispec] = ref.fProb[ispec];
 }
 
 
@@ -93,10 +97,10 @@ AliTRDseedV1& AliTRDseedV1::operator=(const AliTRDseedV1 &ref)
   // Assignment Operator using the copy function
   //
 
-       if(this != &ref){
-               ref.Copy(*this);
-       }
-       return *this;
+  if(this != &ref){
+    ref.Copy(*this);
+  }
+  return *this;
 
 }
 
@@ -107,15 +111,15 @@ AliTRDseedV1::~AliTRDseedV1()
   // Destructor. The RecoParam object belongs to the underlying tracker.
   //
 
-       //printf("I-AliTRDseedV1::~AliTRDseedV1() : Owner[%s]\n", IsOwner()?"YES":"NO");
+  //printf("I-AliTRDseedV1::~AliTRDseedV1() : Owner[%s]\n", IsOwner()?"YES":"NO");
 
-       if(IsOwner()) 
-               for(int itb=0; itb<knTimebins; itb++){
-                       if(!fClusters[itb]) continue; 
-                       //AliInfo(Form("deleting c %p @ %d", fClusters[itb], itb));
-                       delete fClusters[itb];
-                       fClusters[itb] = 0x0;
-               }
+  if(IsOwner()) 
+    for(int itb=0; itb<knTimebins; itb++){
+      if(!fClusters[itb]) continue; 
+      //AliInfo(Form("deleting c %p @ %d", fClusters[itb], itb));
+      delete fClusters[itb];
+      fClusters[itb] = 0x0;
+    }
 }
 
 //____________________________________________________________________
@@ -125,20 +129,22 @@ void AliTRDseedV1::Copy(TObject &ref) const
   // Copy function
   //
 
-       //AliInfo("");
-       AliTRDseedV1 &target = (AliTRDseedV1 &)ref; 
-
-       target.fPlane         = fPlane;
-       target.fMom           = fMom;
-       target.fSnp           = fSnp;
-       target.fTgl           = fTgl;
-       target.fdX            = fdX;
-       target.fReconstructor = fReconstructor;
-       
-       for(int islice=0; islice < knSlices; islice++) target.fdEdx[islice] = fdEdx[islice];
-       for(int ispec=0; ispec<AliPID::kSPECIES; ispec++) target.fProb[ispec] = fProb[ispec];
-       
-       AliTRDseed::Copy(target);
+  //AliInfo("");
+  AliTRDseedV1 &target = (AliTRDseedV1 &)ref; 
+
+  target.fClusterIter   = 0x0;
+  target.fClusterIdx    = 0;
+  target.fDet           = fDet;
+  target.fMom           = fMom;
+  target.fSnp           = fSnp;
+  target.fTgl           = fTgl;
+  target.fdX            = fdX;
+  target.fReconstructor = fReconstructor;
+  
+  for(int islice=0; islice < knSlices; islice++) target.fdEdx[islice] = fdEdx[islice];
+  for(int ispec=0; ispec<AliPID::kSPECIES; ispec++) target.fProb[ispec] = fProb[ispec];
+  
+  AliTRDseed::Copy(target);
 }
 
 
@@ -159,15 +165,15 @@ Bool_t AliTRDseedV1::Init(AliTRDtrackV1 *track)
 // chamber where the tracklet will be constructed
 //
 
-       Double_t y, z; 
-       if(!track->GetProlongation(fX0, y, z)) return kFALSE;
-       fYref[0] = y;
-       fYref[1] = track->GetSnp()/(1. - track->GetSnp()*track->GetSnp());
-       fZref[0] = z;
-       fZref[1] = track->GetTgl();
+  Double_t y, z; 
+  if(!track->GetProlongation(fX0, y, z)) return kFALSE;
+  fYref[0] = y;
+  fYref[1] = track->GetSnp()/(1. - track->GetSnp()*track->GetSnp());
+  fZref[0] = z;
+  fZref[1] = track->GetTgl();
 
-       //printf("Tracklet ref x[%7.3f] y[%7.3f] z[%7.3f], snp[%f] tgl[%f]\n", fX0, fYref[0], fZref[0], track->GetSnp(), track->GetTgl());
-       return kTRUE;
+  //printf("Tracklet ref x[%7.3f] y[%7.3f] z[%7.3f], snp[%f] tgl[%f]\n", fX0, fYref[0], fZref[0], track->GetSnp(), track->GetTgl());
+  return kTRUE;
 }
 
 
@@ -195,49 +201,50 @@ void AliTRDseedV1::CookdEdx(Int_t nslices)
 // 3. cluster size
 //
 
-       Int_t nclusters[knSlices];
-       for(int i=0; i<knSlices; i++){ 
-               fdEdx[i]     = 0.;
-               nclusters[i] = 0;
-       }
-       Float_t clength = (/*.5 * */AliTRDgeometry::AmThick() + AliTRDgeometry::DrThick());
-
-       AliTRDcluster *cluster = 0x0;
-       for(int ic=0; ic<AliTRDtrackerV1::GetNTimeBins(); ic++){
-               if(!(cluster = fClusters[ic])) continue;
-               Float_t x = cluster->GetX();
-               
-               // Filter clusters for dE/dx calculation
-               
-               // 1.consider calibration effects for slice determination
-               Int_t slice; 
-               if(cluster->IsInChamber()) slice = Int_t(TMath::Abs(fX0 - x) * nslices / clength);
-               else slice = x < fX0 ? 0 : nslices-1;
-               
-               // 2. take sharing into account
-               Float_t w = cluster->IsShared() ? .5 : 1.;
-               
-               // 3. take into account large clusters TODO
-               //w *= c->GetNPads() > 3 ? .8 : 1.;
-               
-               //CHECK !!!
-               fdEdx[slice]   += w * GetdQdl(ic); //fdQdl[ic];
-               nclusters[slice]++;
-       } // End of loop over clusters
-
-       if(fReconstructor->GetPIDMethod() == AliTRDReconstructor::kLQPID){
-       // calculate mean charge per slice (only LQ PID)
-               for(int is=0; is<nslices; is++){ 
-           if(nclusters[is]) fdEdx[is] /= nclusters[is];
-         }
-       }
+  Int_t nclusters[knSlices];
+  for(int i=0; i<knSlices; i++){ 
+    fdEdx[i]     = 0.;
+    nclusters[i] = 0;
+  }
+  Float_t clength = (/*.5 * */AliTRDgeometry::AmThick() + AliTRDgeometry::DrThick());
+
+  AliTRDcluster *cluster = 0x0;
+  for(int ic=0; ic<AliTRDtrackerV1::GetNTimeBins(); ic++){
+    if(!(cluster = fClusters[ic])) continue;
+    Float_t x = cluster->GetX();
+    
+    // Filter clusters for dE/dx calculation
+    
+    // 1.consider calibration effects for slice determination
+    Int_t slice; 
+    if(cluster->IsInChamber()) slice = Int_t(TMath::Abs(fX0 - x) * nslices / clength);
+    else slice = x < fX0 ? 0 : nslices-1;
+    
+    // 2. take sharing into account
+    Float_t w = cluster->IsShared() ? .5 : 1.;
+    
+    // 3. take into account large clusters TODO
+    //w *= c->GetNPads() > 3 ? .8 : 1.;
+    
+    //CHECK !!!
+    fdEdx[slice]   += w * GetdQdl(ic); //fdQdl[ic];
+    nclusters[slice]++;
+  } // End of loop over clusters
+
+  //if(fReconstructor->GetPIDMethod() == AliTRDReconstructor::kLQPID){
+  if(nslices == AliTRDReconstructor::kLQslices){
+  // calculate mean charge per slice (only LQ PID)
+    for(int is=0; is<nslices; is++){ 
+      if(nclusters[is]) fdEdx[is] /= nclusters[is];
+    }
+  }
 }
 
 
 //____________________________________________________________________
 Float_t AliTRDseedV1::GetdQdl(Int_t ic) const
 {
-       return fClusters[ic] ? TMath::Abs(fClusters[ic]->GetQ()) /fdX / TMath::Sqrt(1. + fYfit[1]*fYfit[1] + fZref[1]*fZref[1]) : 0.;
+  return fClusters[ic] ? TMath::Abs(fClusters[ic]->GetQ()) /fdX / TMath::Sqrt(1. + fYfit[1]*fYfit[1] + fZref[1]*fZref[1]) : 0.;
 }
 
 //____________________________________________________________________
@@ -252,8 +259,8 @@ Double_t* AliTRDseedV1::GetProbability()
 //
 // Detailed description
 
-       
-       // retrive calibration db
+  
+  // retrive calibration db
   AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
   if (!calibration) {
     AliError("No access to calibration data");
@@ -271,9 +278,9 @@ Double_t* AliTRDseedV1::GetProbability()
     AliError("No access to AliTRDCalPID object");
     return 0x0;
   }
-       //AliInfo(Form("Method[%d] : %s", fReconstructor->GetRecoParam() ->GetPIDMethod(), pd->IsA()->GetName()));
+  //AliInfo(Form("Method[%d] : %s", fReconstructor->GetRecoParam() ->GetPIDMethod(), pd->IsA()->GetName()));
 
-       // calculate tracklet length TO DO
+  // calculate tracklet length TO DO
   Float_t length = (AliTRDgeometry::AmThick() + AliTRDgeometry::DrThick());
   /// TMath::Sqrt((1.0 - fSnp[iPlane]*fSnp[iPlane]) / (1.0 + fTgl[iPlane]*fTgl[iPlane]));
   
@@ -282,10 +289,10 @@ Double_t* AliTRDseedV1::GetProbability()
   
   // Sets the a priori probabilities
   for(int ispec=0; ispec<AliPID::kSPECIES; ispec++) {
-    fProb[ispec] = pd->GetProbability(ispec, fMom, &fdEdx[0], length, fPlane); 
+    fProb[ispec] = pd->GetProbability(ispec, fMom, &fdEdx[0], length, GetPlane());     
   }
 
-       return &fProb[0];
+  return &fProb[0];
 }
 
 //____________________________________________________________________
@@ -295,12 +302,12 @@ Float_t AliTRDseedV1::GetQuality(Bool_t kZcorr) const
   // Returns a quality measurement of the current seed
   //
 
-       Float_t zcorr = kZcorr ? fTilt * (fZProb - fZref[0]) : 0.;
-       return 
-                 .5 * TMath::Abs(18.0 - fN2)
-               + 10.* TMath::Abs(fYfit[1] - fYref[1])
-               + 5. * TMath::Abs(fYfit[0] - fYref[0] + zcorr)
-               + 2. * TMath::Abs(fMeanz - fZref[0]) / fPadLength;
+  Float_t zcorr = kZcorr ? fTilt * (fZProb - fZref[0]) : 0.;
+  return 
+      .5 * TMath::Abs(18.0 - fN2)
+    + 10.* TMath::Abs(fYfit[1] - fYref[1])
+    + 5. * TMath::Abs(fYfit[0] - fYref[0] + zcorr)
+    + 2. * TMath::Abs(fMeanz - fZref[0]) / fPadLength;
 }
 
 //____________________________________________________________________
@@ -308,19 +315,19 @@ void AliTRDseedV1::GetCovAt(Double_t /*x*/, Double_t *cov) const
 {
 // Computes covariance in the y-z plane at radial point x
 
-       Int_t ic = 0; while (!fClusters[ic]) ic++; 
+  Int_t ic = 0; while (!fClusters[ic]) ic++; 
   AliTRDcalibDB *fCalib = AliTRDcalibDB::Instance();
-       Double_t exB         = fCalib->GetOmegaTau(fCalib->GetVdriftAverage(fClusters[ic]->GetDetector()), -AliTracker::GetBz()*0.1);
+  Double_t exB         = fCalib->GetOmegaTau(fCalib->GetVdriftAverage(fClusters[ic]->GetDetector()), -AliTracker::GetBz()*0.1);
 
-       Double_t sy2    = fSigmaY2*fSigmaY2 + .2*(fYfit[1]-exB)*(fYfit[1]-exB);
-       Double_t sz2    = fPadLength/12.;
+  Double_t sy2    = fSigmaY2*fSigmaY2 + .2*(fYfit[1]-exB)*(fYfit[1]-exB);
+  Double_t sz2    = fPadLength/12.;
 
 
-       //printf("Yfit[1] %f sy20 %f SigmaY2 %f\n", fYfit[1], sy20, fSigmaY2);
+  //printf("Yfit[1] %f sy20 %f SigmaY2 %f\n", fYfit[1], sy20, fSigmaY2);
 
-       cov[0] = sy2;
-       cov[1] = fTilt*(sy2-sz2);
-       cov[2] = sz2;
+  cov[0] = sy2;
+  cov[1] = fTilt*(sy2-sz2);
+  cov[2] = sz2;
 
   // insert systematic uncertainties calibration and misalignment
   Double_t sys[15];
@@ -331,26 +338,16 @@ void AliTRDseedV1::GetCovAt(Double_t /*x*/, Double_t *cov) const
 
 
 //____________________________________________________________________
-void AliTRDseedV1::SetOwner(Bool_t own)
+void AliTRDseedV1::SetOwner()
 {
-       //AliInfo(Form("own [%s] fOwner[%s]", own?"YES":"NO", fOwner?"YES":"NO"));
-       
-       if(own){
-               for(int ic=0; ic<knTimebins; ic++){
-                       if(!fClusters[ic]) continue;
-                       fClusters[ic] = new AliTRDcluster(*fClusters[ic]);
-               }
-               SetBit(kOwner);
-       } else {
-               if(IsOwner()){
-                       for(int ic=0; ic<knTimebins; ic++){
-                               if(!fClusters[ic]) continue;
-                               delete fClusters[ic];
-                               //fClusters[ic] = tracker->GetClusters(index) TODO
-                       }
-               }
-               SetBit(kOwner, kFALSE);
-       }
+  //AliInfo(Form("own [%s] fOwner[%s]", own?"YES":"NO", fOwner?"YES":"NO"));
+  
+  if(TestBit(kOwner)) return;
+  for(int ic=0; ic<knTimebins; ic++){
+    if(!fClusters[ic]) continue;
+    fClusters[ic] = new AliTRDcluster(*fClusters[ic]);
+  }
+  SetBit(kOwner);
 }
 
 //____________________________________________________________________
@@ -361,143 +358,125 @@ Bool_t  AliTRDseedV1::AttachClustersIter(AliTRDtrackingChamber *chamber, Float_t
   // 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 && c){
-               TClonesArray clusters("AliTRDcluster", 24);
-               clusters.SetOwner(kTRUE);
-               AliTRDcluster *cc = 0x0;
-               Int_t det=-1, ncl, ncls = 0;
-               for (Int_t iTime = 0; iTime < AliTRDtrackerV1::GetNTimeBins(); iTime++) {
-                       if(!(layer = chamber->GetTB(iTime))) continue;
-                       if(!(ncl = Int_t(*layer))) continue;
-                       for(int ic=0; ic<ncl; ic++){ 
-                               cc = (*layer)[ic];
-                               det = cc->GetDetector();
-                               new(clusters[ncls++]) AliTRDcluster(*cc);
-                       }
-               }
-               AliInfo(Form("N clusters[%d] = %d", fPlane, ncls));
-               
-               Int_t ref = c ? 1 : 0;
-               TTreeSRedirector &cstreamer = *AliTRDtrackerV1::DebugStreamer();
-               cstreamer << "AttachClustersIter"
-                       << "det="        << det 
-                       << "ref="        << ref 
-                       << "clusters.="  << &clusters
-                       << "tracklet.="  << this
-                       << "cl.="        << c
-                       << "\n";        
-       }
-
-       Float_t  tquality;
-       Double_t kroady = fReconstructor->GetRecoParam() ->GetRoad1y();
-       Double_t kroadz = fPadLength * .5 + 1.;
-       
-       // initialize configuration parameters
-       Float_t zcorr = kZcorr ? fTilt * (fZProb - 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, fPlane, ncl));
-               
-               if(ncl>1){      
-                       // calculate length of the time bin (calibration aware)
-                       Int_t irp = 0; Float_t x[2]; Int_t tb[2];
-                       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;
-                       } 
-                       fdX = (x[1] - x[0]) / (tb[0] - tb[1]);
-       
-                       // 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] = fClusters[iTime]->GetX() - fX0;
-                       } 
-                       
-                       AliTRDseed::Update();
-               }
-       if(fReconstructor->GetStreamLevel(AliTRDReconstructor::kTracker)>=7) AliInfo(Form("iter = %d nclFit [%d] = %d", iter, fPlane, fN2));
-               
-               if(IsOK()){
-                       tquality = GetQuality(kZcorr);
-                       if(tquality < quality) break;
-                       else quality = tquality;
-               }
-               kroadz *= 2.;
-       } // Loop: iter
-       if (!IsOK()) return kFALSE;
-
-       CookLabels();
-       UpdateUsed();
-       return kTRUE;   
+  // 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(); 
+    (*AliTRDtrackerV1::DebugStreamer()) << "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 * (fZProb - 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]; Int_t tb[2];
+      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;
+      } 
+      fdX = (x[1] - x[0]) / (tb[0] - tb[1]);
+  
+      // 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] = fClusters[iTime]->GetX() - fX0;
+      } 
+      
+      AliTRDseed::Update();
+    }
+    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();
+  UpdateUsed();
+  return kTRUE;        
 }
 
 //____________________________________________________________________
 Bool_t AliTRDseedV1::AttachClusters(AliTRDtrackingChamber *chamber
-                                       ,Bool_t kZcorr)
+                                      ,Bool_t kZcorr)
 {
   //
   // Projective algorithm to attach clusters to seeding tracklets
@@ -515,131 +494,131 @@ Bool_t  AliTRDseedV1::AttachClusters(AliTRDtrackingChamber *chamber
   // 6. fit tracklet
   //   
 
-       if(!fReconstructor->GetRecoParam() ){
-               AliError("Seed can not be used without a valid RecoParam.");
-               return kFALSE;
-       }
-
-       const Int_t kClusterCandidates = 2 * knTimebins;
-       
-       //define roads
-       Double_t kroady = fReconstructor->GetRecoParam() ->GetRoad1y();
-       Double_t kroadz = fPadLength * 1.5 + 1.;
-       // correction to y for the tilting angle
-       Float_t zcorr = kZcorr ? fTilt * (fZProb - fZref[0]) : 0.;
-
-       // working variables
-       AliTRDcluster *clusters[kClusterCandidates];
-       Double_t cond[4], yexp[knTimebins], zexp[knTimebins],
-               yres[kClusterCandidates], zres[kClusterCandidates];
-       Int_t ncl, *index = 0x0, tboundary[knTimebins];
-       
-       // Do cluster projection
-       AliTRDchamberTimeBin *layer = 0x0;
-       Int_t nYclusters = 0; Bool_t kEXIT = kFALSE;
-       for (Int_t iTime = 0; iTime < AliTRDtrackerV1::GetNTimeBins(); iTime++) {
-               if(!(layer = chamber->GetTB(iTime))) continue;
-               if(!Int_t(*layer)) continue;
-               
-               fX[iTime] = layer->GetX() - fX0;
-               zexp[iTime] = fZref[0] + fZref[1] * fX[iTime];
-               yexp[iTime] = fYref[0] + fYref[1] * fX[iTime] - zcorr;
-               
-               // build condition and process clusters
-               cond[0] = yexp[iTime] - kroady; cond[1] = yexp[iTime] + kroady;
-               cond[2] = zexp[iTime] - kroadz; cond[3] = zexp[iTime] + kroadz;
-               layer->GetClusters(cond, index, ncl);
-               for(Int_t ic = 0; ic<ncl; ic++){
-                       AliTRDcluster *c = layer->GetCluster(index[ic]);
-                       clusters[nYclusters] = c;
-                       yres[nYclusters++] = c->GetY() - yexp[iTime];
-                       if(nYclusters >= kClusterCandidates) {
-                               AliWarning(Form("Cluster candidates reached limit %d. Some may be lost.", kClusterCandidates));
-                               kEXIT = kTRUE;
-                               break;
-                       }
-               }
-               tboundary[iTime] = nYclusters;
-               if(kEXIT) break;
-       }
-       
-       // Evaluate truncated mean on the y direction
-       Double_t mean, sigma;
-       AliMathBase::EvaluateUni(nYclusters, yres, mean, sigma, Int_t(nYclusters*.8)-2);
-       // purge cluster candidates
-       Int_t nZclusters = 0;
-       for(Int_t ic = 0; ic<nYclusters; ic++){
-               if(yres[ic] - mean > 4. * sigma){
-                       clusters[ic] = 0x0;
-                       continue;
-               }
-               zres[nZclusters++] = clusters[ic]->GetZ() - zexp[clusters[ic]->GetLocalTimeBin()];
-       }
-       
-       // Evaluate truncated mean on the z direction
-       AliMathBase::EvaluateUni(nZclusters, zres, mean, sigma, Int_t(nZclusters*.8)-2);
-       // purge cluster candidates
-       for(Int_t ic = 0; ic<nZclusters; ic++){
-               if(zres[ic] - mean > 4. * sigma){
-                       clusters[ic] = 0x0;
-                       continue;
-               }
-       }
-
-       
-       // Select only one cluster/TimeBin
-       Int_t lastCluster = 0;
-       fN2 = 0;
-       for (Int_t iTime = 0; iTime < AliTRDtrackerV1::GetNTimeBins(); iTime++) {
-               ncl = tboundary[iTime] - lastCluster;
-               if(!ncl) continue;
-               Int_t iptr = lastCluster;
-               if(ncl > 1){
-                       Float_t dold = 9999.;
-                       for(int ic=lastCluster; ic<tboundary[iTime]; ic++){
-                               if(!clusters[ic]) continue;
-                               Float_t y = yexp[iTime] - clusters[ic]->GetY();
-                               Float_t z = zexp[iTime] - clusters[ic]->GetZ();
-                               Float_t d = y * y + z * z;
-                               if(d > dold) continue;
-                               dold = d;
-                               iptr = ic;
-                       }
-               }
-               fIndexes[iTime]  = chamber->GetTB(iTime)->GetGlobalIndex(iptr);
-               fClusters[iTime] = clusters[iptr];
-               fY[iTime]        = clusters[iptr]->GetY();
-               fZ[iTime]        = clusters[iptr]->GetZ();
-               lastCluster      = tboundary[iTime];
-               fN2++;
-       }
-       
-       // number of minimum numbers of clusters expected for the tracklet
-       Int_t kClmin = Int_t(fReconstructor->GetRecoParam() ->GetFindableClusters()*AliTRDtrackerV1::GetNTimeBins());
+  if(!fReconstructor->GetRecoParam() ){
+    AliError("Seed can not be used without a valid RecoParam.");
+    return kFALSE;
+  }
+
+  const Int_t kClusterCandidates = 2 * knTimebins;
+  
+  //define roads
+  Double_t kroady = fReconstructor->GetRecoParam() ->GetRoad1y();
+  Double_t kroadz = fPadLength * 1.5 + 1.;
+  // correction to y for the tilting angle
+  Float_t zcorr = kZcorr ? fTilt * (fZProb - fZref[0]) : 0.;
+
+  // working variables
+  AliTRDcluster *clusters[kClusterCandidates];
+  Double_t cond[4], yexp[knTimebins], zexp[knTimebins],
+    yres[kClusterCandidates], zres[kClusterCandidates];
+  Int_t ncl, *index = 0x0, tboundary[knTimebins];
+  
+  // Do cluster projection
+  AliTRDchamberTimeBin *layer = 0x0;
+  Int_t nYclusters = 0; Bool_t kEXIT = kFALSE;
+  for (Int_t iTime = 0; iTime < AliTRDtrackerV1::GetNTimeBins(); iTime++) {
+    if(!(layer = chamber->GetTB(iTime))) continue;
+    if(!Int_t(*layer)) continue;
+    
+    fX[iTime] = layer->GetX() - fX0;
+    zexp[iTime] = fZref[0] + fZref[1] * fX[iTime];
+    yexp[iTime] = fYref[0] + fYref[1] * fX[iTime] - zcorr;
+    
+    // build condition and process clusters
+    cond[0] = yexp[iTime] - kroady; cond[1] = yexp[iTime] + kroady;
+    cond[2] = zexp[iTime] - kroadz; cond[3] = zexp[iTime] + kroadz;
+    layer->GetClusters(cond, index, ncl);
+    for(Int_t ic = 0; ic<ncl; ic++){
+      AliTRDcluster *c = layer->GetCluster(index[ic]);
+      clusters[nYclusters] = c;
+      yres[nYclusters++] = c->GetY() - yexp[iTime];
+      if(nYclusters >= kClusterCandidates) {
+        AliWarning(Form("Cluster candidates reached limit %d. Some may be lost.", kClusterCandidates));
+        kEXIT = kTRUE;
+        break;
+      }
+    }
+    tboundary[iTime] = nYclusters;
+    if(kEXIT) break;
+  }
+  
+  // Evaluate truncated mean on the y direction
+  Double_t mean, sigma;
+  AliMathBase::EvaluateUni(nYclusters, yres, mean, sigma, Int_t(nYclusters*.8)-2);
+  // purge cluster candidates
+  Int_t nZclusters = 0;
+  for(Int_t ic = 0; ic<nYclusters; ic++){
+    if(yres[ic] - mean > 4. * sigma){
+      clusters[ic] = 0x0;
+      continue;
+    }
+    zres[nZclusters++] = clusters[ic]->GetZ() - zexp[clusters[ic]->GetLocalTimeBin()];
+  }
+  
+  // Evaluate truncated mean on the z direction
+  AliMathBase::EvaluateUni(nZclusters, zres, mean, sigma, Int_t(nZclusters*.8)-2);
+  // purge cluster candidates
+  for(Int_t ic = 0; ic<nZclusters; ic++){
+    if(zres[ic] - mean > 4. * sigma){
+      clusters[ic] = 0x0;
+      continue;
+    }
+  }
+
+  
+  // Select only one cluster/TimeBin
+  Int_t lastCluster = 0;
+  fN2 = 0;
+  for (Int_t iTime = 0; iTime < AliTRDtrackerV1::GetNTimeBins(); iTime++) {
+    ncl = tboundary[iTime] - lastCluster;
+    if(!ncl) continue;
+    Int_t iptr = lastCluster;
+    if(ncl > 1){
+      Float_t dold = 9999.;
+      for(int ic=lastCluster; ic<tboundary[iTime]; ic++){
+        if(!clusters[ic]) continue;
+        Float_t y = yexp[iTime] - clusters[ic]->GetY();
+        Float_t z = zexp[iTime] - clusters[ic]->GetZ();
+        Float_t d = y * y + z * z;
+        if(d > dold) continue;
+        dold = d;
+        iptr = ic;
+      }
+    }
+    fIndexes[iTime]  = chamber->GetTB(iTime)->GetGlobalIndex(iptr);
+    fClusters[iTime] = clusters[iptr];
+    fY[iTime]        = clusters[iptr]->GetY();
+    fZ[iTime]        = clusters[iptr]->GetZ();
+    lastCluster      = tboundary[iTime];
+    fN2++;
+  }
+  
+  // number of minimum numbers of clusters expected for the tracklet
+  Int_t kClmin = Int_t(fReconstructor->GetRecoParam() ->GetFindableClusters()*AliTRDtrackerV1::GetNTimeBins());
   if (fN2 < kClmin){
-               AliWarning(Form("Not enough clusters to fit the tracklet %d [%d].", fN2, kClmin));
+    AliWarning(Form("Not enough clusters to fit the tracklet %d [%d].", fN2, kClmin));
     fN2 = 0;
     return kFALSE;
   }
 
-       // update used clusters
-       fNUsed = 0;
-       for (Int_t iTime = 0; iTime < AliTRDtrackerV1::GetNTimeBins(); iTime++) {
-               if(!fClusters[iTime]) continue;
-               if((fClusters[iTime]->IsUsed())) fNUsed++;
-       }
+  // update used clusters
+  fNUsed = 0;
+  for (Int_t iTime = 0; iTime < AliTRDtrackerV1::GetNTimeBins(); iTime++) {
+    if(!fClusters[iTime]) continue;
+    if((fClusters[iTime]->IsUsed())) fNUsed++;
+  }
 
   if (fN2-fNUsed < kClmin){
-               AliWarning(Form("Too many clusters already in use %d (from %d).", fNUsed, fN2));
+    AliWarning(Form("Too many clusters already in use %d (from %d).", fNUsed, fN2));
     fN2 = 0;
     return kFALSE;
   }
-       
-       return kTRUE;
+  
+  return kTRUE;
 }
 
 //____________________________________________________________________
-Bool_t AliTRDseedV1::Fit()
+Bool_t AliTRDseedV1::Fit(Bool_t tilt)
 {
   //
   // Linear fit of the tracklet
@@ -655,122 +634,130 @@ Bool_t AliTRDseedV1::Fit()
   // 3. Do a Least Square Fit to the data
   //
 
-       const Int_t kClmin = 8;
-       const Int_t kNtb = AliTRDtrackerV1::GetNTimeBins();
-       AliTRDtrackerV1::AliTRDLeastSquare fitterY, fitterZ;
-
-       // convertion factor from square to gauss distribution for sigma
-       Double_t convert = 1./TMath::Sqrt(12.);
-
-       // book cluster information
-       Double_t xc[knTimebins+1], yc[knTimebins], zc[knTimebins+1], sy[knTimebins], sz[knTimebins+1];
-       Int_t zRow[knTimebins];
-       AliTRDcluster *c = 0x0;
-       Int_t nc = 0;
-       for (Int_t ic=0; ic<kNtb; ic++) {
-               zRow[ic] = -1;
-               xc[ic]  = -1.;
-               yc[ic]  = 999.;
-               zc[ic]  = 999.;
-               sy[ic]  = 0.;
-               sz[ic]  = 0.;
-               if(!(c = fClusters[ic])) continue;
-               if(!c->IsInChamber()) continue;
-               Float_t w = 1.;
-               if(c->GetNPads()>4) w = .5;
-               if(c->GetNPads()>5) w = .2;
-               zRow[nc] = c->GetPadRow();
-               xc[nc]   = fX0 - c->GetX();
-               yc[nc]   = c->GetY();
-               zc[nc]   = c->GetZ();
-               sy[ic]   = w; // all clusters have the same sigma
-               sz[ic]   = fPadLength*convert;
-               fitterZ.AddPoint(&xc[ic], zc[ic], sz[ic]);
-               nc++;
-       }
+  const Int_t kClmin = 8;
+  const Float_t q0 = 100.;
+  const Float_t clSigma0 = 2.E-2;    //[cm]
+  const Float_t clSlopeQ = -1.19E-2; //[1/cm]
+
+  // get track direction
+  Double_t y0   = fYref[0];
+  Double_t dydx = fYref[1]; 
+  Double_t z0   = fZref[0];
+  Double_t dzdx = fZref[1];
+  Double_t yt, zt;
+
+  const Int_t kNtb = AliTRDtrackerV1::GetNTimeBins();
+  AliTRDtrackerV1::AliTRDLeastSquare fitterY, fitterZ;
+
+  // convertion factor from square to gauss distribution for sigma
+  Double_t convert = 1./TMath::Sqrt(12.);
+  
+  // book cluster information
+  Double_t xc[knTimebins], yc[knTimebins], zc[knTimebins], sy[knTimebins], sz[knTimebins];
+  Int_t zRow[knTimebins];
+
+
+  fN = 0;
+  AliTRDcluster *c=0x0, **jc = &fClusters[0];
+  for (Int_t ic=0; ic<kNtb; ic++, ++jc) {
+    zRow[ic] = -1;
+    xc[ic]  = -1.;
+    yc[ic]  = 999.;
+    zc[ic]  = 999.;
+    sy[ic]  = 0.;
+    sz[ic]  = 0.;
+    if(!(c = (*jc))) continue;
+    if(!c->IsInChamber()) continue;
+    Float_t w = 1.;
+    if(c->GetNPads()>4) w = .5;
+    if(c->GetNPads()>5) w = .2;
+    zRow[fN] = c->GetPadRow();
+    xc[fN]   = fX0 - c->GetX();
+    yc[fN]   = c->GetY();
+    zc[fN]   = c->GetZ();
+
+    // extrapolated y value for the track
+    yt = y0 - xc[fN]*dydx; 
+    // extrapolated z value for the track
+    zt = z0 - xc[fN]*dzdx; 
+    // tilt correction
+    if(tilt) yc[fN] -= fTilt*(zc[fN] - zt); 
+
+    // elaborate cluster error
+    Float_t qr = c->GetQ() - q0;
+    sy[fN]   = qr < 0. ? clSigma0*TMath::Exp(clSlopeQ*qr) : clSigma0;
+
+    fitterY.AddPoint(&xc[fN], yc[fN]-yt, sy[fN]);
+
+    sz[fN]   = fPadLength*convert;
+    fitterZ.AddPoint(&xc[fN], zc[fN], sz[fN]);
+    fN++;
+  }
   // to few clusters
-       if (nc < kClmin) return kFALSE; 
-       
-
-       Int_t zN[2*35];
-  Int_t nz = AliTRDtrackerV1::Freq(nc, zRow, zN, kFALSE);
-       // more than one pad row crossing
-       if(nz>2) return kFALSE; 
-       
-       // estimate reference parameter at average x
-       Double_t y0 = fYref[0];
-       Double_t dydx = fYref[1]; 
-       Double_t dzdx = fZref[1];
-       zc[nc]  = fZref[0];
-
-       // determine z offset of the fit
-       Int_t nchanges = 0, nCross = 0;
-       if(nz==2){ // tracklet is crossing pad row
-               // Find the break time allowing one chage on pad-rows
-               // with maximal number of accepted clusters
-               Int_t padRef = zRow[0];
-               for (Int_t ic=1; ic<nc; ic++) {
-                       if(zRow[ic] == padRef) continue;
-                       
-                       // debug
-                       if(zRow[ic-1] == zRow[ic]){
-                               printf("ERROR in pad row change!!!\n");
-                       }
-               
-                       // evaluate parameters of the crossing point
-                       Float_t sx = (xc[ic-1] - xc[ic])*convert;
-                       xc[nc] = .5 * (xc[ic-1] + xc[ic]);
-                       zc[nc] = .5 * (zc[ic-1] + zc[ic]);
-                       sz[nc] = TMath::Max(dzdx * sx, .01);
-                       dzdx   = zc[ic-1] > zc[ic] ? 1. : -1.;
-                       padRef = zRow[ic];
-                       nCross = ic;
-                       nchanges++;
-               }
-       }
-
-       // condition on nCross and reset nchanges TODO
-
-       if(nchanges==1){
-               if(dzdx * fZref[1] < 0.){
-                       AliInfo("tracklet direction does not correspond to the track direction. TODO.");
-               }
-               SetBit(kRowCross, kTRUE); // mark pad row crossing
-               fCross[0] = xc[nc]; fCross[2] = zc[nc]; fCross[3] = sz[nc]; 
-               fitterZ.AddPoint(&xc[nc], zc[nc], sz[nc]);
-               fitterZ.Eval();
-               dzdx = fZref[1]; // we don't trust Parameter[1] ??;
-               zc[nc] = fitterZ.GetFunctionParameter(0); 
-       } else if(nchanges > 1){ // debug
-               AliInfo("ERROR in n changes!!!");
-               return kFALSE;
-       }
-
-       
-       // estimate deviation from reference direction
-       dzdx *= fTilt;
-       for (Int_t ic=0; ic<nc; ic++) {
-               yc[ic] -= y0 + xc[ic]*(dydx + dzdx) + fTilt * (zc[ic] - zc[nc]);
-               fitterY.AddPoint(&xc[ic], yc[ic], sy[ic]);
-       }
-       fitterY.Eval();
-       fYfit[0] = y0+fitterY.GetFunctionParameter(0);
-       fYfit[1] = dydx+fitterY.GetFunctionParameter(1);
-       if(nchanges) fCross[1] = fYfit[0] + fCross[0] * fYfit[1];
-
-//     printf("\nnz = %d\n", nz);
-//     for(int ic=0; ic<35; ic++) printf("%d row[%d]\n", ic, zRow[ic]);        
-// 
-//     for(int ic=0; ic<nz; ic++) printf("%d n[%d]\n", ic, zN[ic]);    
+  if (fN < kClmin) return kFALSE; 
+
+  // fit XY plane
+  fitterY.Eval();
+  fYfit[0] = y0+fitterY.GetFunctionParameter(0);
+  fYfit[1] = dydx-fitterY.GetFunctionParameter(1);
+
+  // check par row crossing
+  Int_t zN[2*AliTRDseed::knTimebins];
+  Int_t nz = AliTRDtrackerV1::Freq(fN, zRow, zN, kFALSE);
+  // more than one pad row crossing
+  if(nz>2) return kFALSE; 
+
+
+  // determine z offset of the fit
+  Float_t zslope = 0.;
+  Int_t nchanges = 0, nCross = 0;
+  if(nz==2){ // tracklet is crossing pad row
+    // Find the break time allowing one chage on pad-rows
+    // with maximal number of accepted clusters
+    Int_t padRef = zRow[0];
+    for (Int_t ic=1; ic<fN; ic++) {
+      if(zRow[ic] == padRef) continue;
+      
+      // debug
+      if(zRow[ic-1] == zRow[ic]){
+        printf("ERROR in pad row change!!!\n");
+      }
+    
+      // evaluate parameters of the crossing point
+      Float_t sx = (xc[ic-1] - xc[ic])*convert;
+      fCross[0] = .5 * (xc[ic-1] + xc[ic]);
+      fCross[2] = .5 * (zc[ic-1] + zc[ic]);
+      fCross[3] = TMath::Max(dzdx * sx, .01);
+      zslope    = zc[ic-1] > zc[ic] ? 1. : -1.;
+      padRef    = zRow[ic];
+      nCross    = ic;
+      nchanges++;
+    }
+  }
 
-       return kTRUE;
-}
+  // condition on nCross and reset nchanges TODO
+
+  if(nchanges==1){
+    if(dzdx * zslope < 0.){
+      AliInfo("tracklet direction does not correspond to the track direction. TODO.");
+    }
+    SetBit(kRowCross, kTRUE); // mark pad row crossing
+    fitterZ.AddPoint(&fCross[0], fCross[2], fCross[3]);
+    fitterZ.Eval();
+    //zc[nc] = fitterZ.GetFunctionParameter(0); 
+    fCross[1] = fYfit[0] - fCross[0] * fYfit[1];
+    fCross[0] = fX0 - fCross[0];
+  } else if(nchanges > 1){ // debug
+    AliError("N pad row crossing > 1.");
+    return kFALSE;
+  }
 
-//___________________________________________________________________
-void AliTRDseedV1::Draw(Option_t*)
-{
+  UpdateUsed();
+
+  return kTRUE;
 }
 
+
 //___________________________________________________________________
 void AliTRDseedV1::Print(Option_t*) const
 {
@@ -778,43 +765,35 @@ void AliTRDseedV1::Print(Option_t*) const
   // Printing the seedstatus
   //
 
-       printf("Seed status :\n");
-       printf("  fTilt      = %f\n", fTilt);
-       printf("  fPadLength = %f\n", fPadLength);
-       printf("  fX0        = %f\n", fX0);
-       for(int ic=0; ic<AliTRDtrackerV1::GetNTimeBins(); ic++) {
-          const Char_t *isUsable = fUsable[ic]?"Yes":"No";
-         printf("  %d X[%f] Y[%f] Z[%f] Indexes[%d] clusters[%p] usable[%s]\n"
-                , ic
-                , fX[ic]
-                , fY[ic]
-                , fZ[ic]
-                , fIndexes[ic]
-                , ((void*) fClusters[ic])
-                , isUsable);
-        }
+  AliInfo(Form("Tracklet X0[%7.2f] Det[%d]", fX0, fDet));
+  printf("  Tilt[%+6.2f] PadLength[%5.2f]\n", fTilt, fPadLength);
+  AliTRDcluster* const* jc = &fClusters[0];
+  for(int ic=0; ic<AliTRDtrackerV1::GetNTimeBins(); ic++, jc++) {
+    if(!(*jc)) continue;
+    printf("  %2d X[%7.2f] Y[%7.2f] Z[%7.2f] Idx[%d] c[%p] usable[%s]\n", 
+      ic, (*jc)->GetX(), (*jc)->GetY(), (*jc)->GetZ(), 
+      fIndexes[ic], (void*)(*jc), fUsable[ic]?"y":"n");
+  }
 
-       printf("  fYref[0] =%f fYref[1] =%f\n", fYref[0], fYref[1]);
-       printf("  fZref[0] =%f fZref[1] =%f\n", fZref[0], fZref[1]);
-       printf("  fYfit[0] =%f fYfit[1] =%f\n", fYfit[0], fYfit[1]);
-       printf("  fYfitR[0]=%f fYfitR[1]=%f\n", fYfitR[0], fYfitR[1]);
-       printf("  fZfit[0] =%f fZfit[1] =%f\n", fZfit[0], fZfit[1]);
-       printf("  fZfitR[0]=%f fZfitR[1]=%f\n", fZfitR[0], fZfitR[1]);
-       printf("  fSigmaY =%f\n", fSigmaY);
-       printf("  fSigmaY2=%f\n", fSigmaY2);            
-       printf("  fMeanz  =%f\n", fMeanz);
-       printf("  fZProb  =%f\n", fZProb);
-       printf("  fLabels[0]=%d fLabels[1]=%d\n", fLabels[0], fLabels[1]);
-       printf("  fN      =%d\n", fN);
-       printf("  fN2     =%d (>8 isOK)\n",fN2);
-       printf("  fNUsed  =%d\n", fNUsed);
-       printf("  fFreq   =%d\n", fFreq);
-       printf("  fNChange=%d\n",  fNChange);
-       printf("  fMPads  =%f\n", fMPads);
-       
-       printf("  fC      =%f\n", fC);        
-       printf("  fCC     =%f\n",fCC);      
-       printf("  fChi2   =%f\n", fChi2);  
-       printf("  fChi2Z  =%f\n", fChi2Z);
+  printf("  fYref[0] =%f fYref[1] =%f\n", fYref[0], fYref[1]);
+  printf("  fZref[0] =%f fZref[1] =%f\n", fZref[0], fZref[1]);
+  printf("  fYfit[0] =%f fYfit[1] =%f\n", fYfit[0], fYfit[1]);
+  printf("  fZfit[0] =%f fZfit[1] =%f\n", fZfit[0], fZfit[1]);
+  printf("  fSigmaY =%f\n", fSigmaY);
+  printf("  fSigmaY2=%f\n", fSigmaY2);            
+  printf("  fMeanz  =%f\n", fMeanz);
+  printf("  fZProb  =%f\n", fZProb);
+  printf("  fLabels[0]=%d fLabels[1]=%d\n", fLabels[0], fLabels[1]);
+  printf("  fN      =%d\n", fN);
+  printf("  fN2     =%d (>4 isOK - to be redesigned)\n",fN2);
+  printf("  fNUsed  =%d\n", fNUsed);
+  printf("  fFreq   =%d\n", fFreq);
+  printf("  fNChange=%d\n",  fNChange);
+  printf("  fMPads  =%f\n", fMPads);
+  
+  printf("  fC      =%f\n", fC);        
+  printf("  fCC     =%f\n",fCC);      
+  printf("  fChi2   =%f\n", fChi2);  
+  printf("  fChi2Z  =%f\n", fChi2Z);
 }