]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
TRD seeding without vertex constrain implemented (M.Ivanov)
authorhristov <hristov@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 24 Nov 2005 09:29:17 +0000 (09:29 +0000)
committerhristov <hristov@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 24 Nov 2005 09:29:17 +0000 (09:29 +0000)
TRD/AliTRDtracker.cxx
TRD/AliTRDtracker.h

index 81502d8e65bad1989c3245a91ee99a40ed2b24cd..68e972fc952da6ba89a69b2f3a678fe667c54cdc 100644 (file)
@@ -20,6 +20,7 @@
 //  The standard TRD tracker                                                 //
 //                                                                           //
 ///////////////////////////////////////////////////////////////////////////////
+#include <malloc.h>
 
 #include <Riostream.h>
 #include <TFile.h>
 #include "TTreeStream.h"
 #include "TGraph.h"
 #include "AliTRDtracker.h"
+#include "TLinearFitter.h"
+#include "AliRieman.h"
 
 //
 
 ClassImp(AliTRDtracker) 
+ClassImp(AliTRDseed)
 
   const  Float_t     AliTRDtracker::fgkSeedDepth          = 0.5; 
   const  Float_t     AliTRDtracker::fgkSeedStep           = 0.10;   
@@ -51,7 +55,7 @@ ClassImp(AliTRDtracker)
   const  Float_t     AliTRDtracker::fgkMaxSeedDeltaZ      = 25.;  
   const  Float_t     AliTRDtracker::fgkMaxSeedC           = 0.0052; 
   const  Float_t     AliTRDtracker::fgkMaxSeedTan         = 1.2;  
 const  Float_t     AliTRDtracker::fgkMaxSeedVertexZ     = 150.; 
+ const  Float_t     AliTRDtracker::fgkMaxSeedVertexZ     = 150.; 
 
   const  Double_t    AliTRDtracker::fgkSeedErrorSY        = 0.2;
   const  Double_t    AliTRDtracker::fgkSeedErrorSY3       = 2.5;
@@ -75,11 +79,12 @@ ClassImp(AliTRDtracker)
 //   const  Double_t    AliTRDtracker::fgkDriftCorrection    = 1.07;
 //   const  Double_t    AliTRDtracker::fgkExB                = 0.072;
 
-  const  Double_t    AliTRDtracker::fgkOffset             = -0.015;
-const  Double_t    AliTRDtracker::fgkOffsetX            = 0.26;       // "time offset"  
-  const  Double_t    AliTRDtracker::fgkCoef               = 0.0096;   // angular shift 
+  const  Double_t    AliTRDtracker::fgkOffset             = -0.019;
+  const  Double_t    AliTRDtracker::fgkOffsetX            = 0.26;       // "time offset"  
+//  const  Double_t    AliTRDtracker::fgkCoef               = 0.0096;   // angular shift 
+  const  Double_t    AliTRDtracker::fgkCoef               = 0.0106;   // angular shift 
   const  Double_t    AliTRDtracker::fgkMean               = 0.;
-  const  Double_t    AliTRDtracker::fgkDriftCorrection    = 1.04;   // drift coefficient correction
+  const  Double_t    AliTRDtracker::fgkDriftCorrection    = 1.055;   // drift coefficient correction
   const  Double_t    AliTRDtracker::fgkExB                = 0.072;  // ExB angle - for error parameterization
 
 
@@ -173,6 +178,9 @@ AliTRDtracker::AliTRDtracker(const TFile *geomfile):AliTracker()
   fNtracks   = 0;
   fTracks    = new TObjArray(1000);
 
+  static struct mallinfo memdebug;
+  memdebug = mallinfo();
+  printf("Before: %i in bytes\n",memdebug.uordblks);
   for(Int_t geomS = 0; geomS < kTrackingSectors; geomS++) {
     Int_t trS = CookSectorIndex(geomS);
     fTrSec[trS] = new AliTRDtrackingSector(fGeom, geomS, fPar);
@@ -180,6 +188,8 @@ AliTRDtracker::AliTRDtracker(const TFile *geomfile):AliTracker()
       fHoles[icham][trS]=fGeom->IsHole(0,icham,geomS);
     }
   }
+  memdebug = mallinfo();
+  printf("After: %i in bytes\n",memdebug.uordblks);
   AliTRDpadPlane *padPlane = fPar->GetPadPlane(0,0);
   Float_t tiltAngle = TMath::Abs(padPlane->GetTiltingAngle());
   //  Float_t tiltAngle = TMath::Abs(fPar->GetTiltingAngle()); 
@@ -537,6 +547,7 @@ Int_t AliTRDtracker::PropagateBack(AliESD* event) {
        track->CookdEdx(); 
        CookdEdxTimBin(*track);
        CookLabel(track, 1-fgkLabelFraction);
+       if (track->GetBackupTrack()) UseClusters(track->GetBackupTrack());
        if(track->GetChi2()/track->GetNumberOfClusters()<4) {   // sign only gold tracks
          if (seed->GetKinkIndex(0)==0&&TMath::Abs(track->GetPt())<1.5 ) UseClusters(track);
        }
@@ -564,8 +575,6 @@ Int_t AliTRDtracker::PropagateBack(AliESD* event) {
        }
       }
     }
-  
-    //
     // Debug part of tracking
     TTreeSRedirector& cstream = *fDebugStreamer;
     Int_t eventNr = event->GetEventNumber();
@@ -654,8 +663,8 @@ Int_t AliTRDtracker::PropagateBack(AliESD* event) {
   
   cerr<<"Number of seeds: "<<fNseeds<<endl;  
   cerr<<"Number of back propagated TRD tracks: "<<found<<endl;
-
-  //  MakeSeedsMI(3,5); //new seeding
+  
+  //  MakeSeedsMI(3,5,event); //new seeding
 
 
   fSeeds->Clear(); fNseeds=0;
@@ -1298,6 +1307,7 @@ Int_t AliTRDtracker::FollowBackProlongation(AliTRDtrack& t)
 }         
 
 
+
 //___________________________________________________________________
 Int_t AliTRDtracker::FollowBackProlongationG(AliTRDtrack& t)
 {
@@ -1778,6 +1788,10 @@ Int_t AliTRDtracker::LoadClusters(TTree *cTree)
     Int_t layer = fTrSec[trackingSector]->GetLayerNumber(gtb);
 
     index=ncl;
+    //
+    // apply pos correction
+    Float_t poscor =  fgkCoef*(c->GetLocalTimeBin() - fgkMean)+fgkOffset; 
+    c->SetY(c->GetY()-poscor);
     fTrSec[trackingSector]->GetLayer(layer)->InsertCluster(c,index);
   }    
   //  printf("\r\n");
@@ -1834,17 +1848,13 @@ void AliTRDtracker::MakeSeeds(Int_t inner, Int_t outer, Int_t turn)
   }
 
   Double_t x[5], c[15];
-  Int_t maxSec=AliTRDgeometry::kNsect;
-  
+  Int_t maxSec=AliTRDgeometry::kNsect;  
   Double_t alpha=AliTRDgeometry::GetAlpha();
   Double_t shift=AliTRDgeometry::GetAlpha()/2.;
   Double_t cs=cos(alpha), sn=sin(alpha);
-  Double_t cs2=cos(2.*alpha), sn2=sin(2.*alpha);
-    
-      
+  Double_t cs2=cos(2.*alpha), sn2=sin(2.*alpha);          
   Int_t i2 = fTrSec[0]->GetLayerNumber(inner);
-  Int_t i1 = fTrSec[0]->GetLayerNumber(outer);
-      
+  Int_t i1 = fTrSec[0]->GetLayerNumber(outer);      
   Double_t x1 =fTrSec[0]->GetX(i1);
   Double_t xx2=fTrSec[0]->GetX(i2);
       
@@ -1994,23 +2004,39 @@ void AliTRDtracker::MakeSeeds(Int_t inner, Int_t outer, Int_t turn)
   }
 }            
 //__________________________________________________________________________
-void AliTRDtracker::MakeSeedsMI(Int_t /*inner*/, Int_t /*outer*/)
+void AliTRDtracker::MakeSeedsMI(Int_t /*inner*/, Int_t /*outer*/, AliESD * esd)
 {
   //
   // Creates  seeds using clusters between  position inner plane  and outer plane 
   //
+  const Double_t maxtheta = 1;
+  const Double_t maxphi   = 2.0;
+  //
+  const Double_t kRoad0y  =  6;     // road for middle cluster 
+  const Double_t kRoad0z  =  8.5;   // road for middle cluster 
+  //
+  const Double_t kRoad1y  =  2;    // road in y for seeded cluster
+  const Double_t kRoad1z  =  20;    // road in z for seeded cluster
+  //
+  const Double_t kRoad2y  =  3;    // road in y for extrapolated cluster
+  const Double_t kRoad2z  =  20;   // road in z for extrapolated cluster
+  const Int_t    maxseed  = 3000;
+  Int_t maxSec=AliTRDgeometry::kNsect;  
 
-  const Double_t maxtheta = 2;
-  const Double_t maxphi   = 1.5;
-  Int_t maxSec=AliTRDgeometry::kNsect;
-
+  //
+  // linear fitters in planes
+  TLinearFitter fitterTC(2,"hyp2");  // fitting with tilting pads - kz fixed - kz= Z/x, + vertex const
+  TLinearFitter fitterT2(4,"hyp4");  // fitting with tilting pads - kz not fixed
+  fitterTC.StoreData(kTRUE);
+  fitterT2.StoreData(kTRUE);
+  AliRieman rieman(1000);   // rieman fitter
+  AliRieman rieman2(1000);   // rieman fitter
   //  
   // find the maximal and minimal layer for the planes
-  // fucking "object oriented" geometry - find the time bin range for different planes
   //
   Int_t layers[6][2];
+  AliTRDpropagationLayer* reflayers[6];
   for (Int_t i=0;i<6;i++){layers[i][0]=10000; layers[i][1]=0;}
-
   for (Int_t ns=0;ns<maxSec;ns++){
     for (Int_t ilayer=0;ilayer<fTrSec[ns]->GetNumberOfLayers();ilayer++){
       AliTRDpropagationLayer& layer=*(fTrSec[ns]->GetLayer(ilayer));
@@ -2022,143 +2048,910 @@ void AliTRDtracker::MakeSeedsMI(Int_t /*inner*/, Int_t /*outer*/)
     }
   }
   //
-      
-  Int_t ilayer1 = layers[5][1];  // time bin in mplification region
-  Int_t ilayer2 = layers[3][1];  //
-  Int_t ilayerM = layers[4][1];  //
-  //    
-  Double_t x1 = fTrSec[0]->GetX(ilayer1);
-  Double_t x2 = fTrSec[0]->GetX(ilayer2);
-  Double_t xm = fTrSec[0]->GetX(ilayerM);
-  Double_t dist = x2-x1;
-  //  Int_t indexes1[20];
-  //Int_t indexes2[20];
-  AliTRDcluster *clusters1[15],*clusters2[15],*clustersM[15];
-  //
-  //      
-  for (Int_t ns=0; ns<maxSec; ns++) {
-    AliTRDpropagationLayer& layer1=*(fTrSec[ns]->GetLayer(ilayer1));  //select propagation layers
-    AliTRDpropagationLayer& layer2=*(fTrSec[ns]->GetLayer(ilayer2));
-    //  
-    for (Int_t icl1=0;icl1<layer1;icl1++){
-      AliTRDcluster *cl1 = layer1[icl1];
-      if (!cl1) continue;
-      Double_t y1 = cl1->GetY();
-      Double_t z1 = cl1->GetZ();
+  AliTRDpadPlane *padPlane = fPar->GetPadPlane(0,0);
+  Double_t h01 = TMath::Tan(-TMath::Pi() / 180.0 * padPlane->GetTiltingAngle());
+  Double_t hL[6];         // tilting angle
+  Double_t xcl[6];        // x - position of reference cluster
+  Double_t ycl[6];        // y - position of reference cluster
+  Double_t zcl[6];        // z - position of reference cluster
+  AliTRDcluster *cl[6]={0,0,0,0,0,0};    // seeding clusters
+  Float_t padlength[6]={10,10,10,10,10,10};   //current pad-length 
+  Double_t chi2R =0, chi2Z=0;
+  Double_t chi2RF =0, chi2ZF=0;
+  //
+  Int_t nclusters;     // total number of clusters
+  for (Int_t i=0;i<6;i++) {hL[i]=h01; if (i%2==1) hL[i]*=-1.;}
+  //
+  //
+  //         registered seed
+  AliTRDseed *pseed = new AliTRDseed[maxseed*6];
+  AliTRDseed *seed[maxseed];
+  for (Int_t iseed=0;iseed<maxseed;iseed++) seed[iseed]= &pseed[iseed*6];
+  AliTRDseed *cseed = seed[0];
+  // 
+  Double_t   seedquality[maxseed];  
+  Double_t   seedquality2[maxseed];  
+  Double_t   seedparams[maxseed][7];
+  Int_t      seedlayer[maxseed];
+  Int_t      registered =0;
+  Int_t      sort[maxseed];
+  //
+  // seeding part
+  //
+  for (Int_t ns = 0; ns<maxSec; ns++){         //loop over sectors
+  //for (Int_t ns = 0; ns<5; ns++){         //loop over sectors
+    registered = 0;   // reset registerd seed counter
+    cseed      = seed[registered];
+    Float_t iter=0;
+    for (Int_t sLayer=2; sLayer>=0;sLayer--){
+      //for (Int_t dseed=5;dseed<15; dseed+=3){  //loop over central seeding time bins 
+      iter+=1.;
+      Int_t dseed = 5+Int_t(iter)*3;
+      // Initialize seeding layers
+      for (Int_t ilayer=0;ilayer<6;ilayer++){
+       reflayers[ilayer] = fTrSec[ns]->GetLayer(layers[ilayer][1]-dseed);
+       xcl[ilayer]       = reflayers[ilayer]->GetX();
+      }      
       //
-      for (Int_t icl2=0;icl2<layer2;icl2++){
-       AliTRDcluster *cl2 = layer2[icl2];
-       if (!cl2) continue;
-       Double_t y2 = cl2->GetY();
-       Double_t z2 = cl2->GetZ();      
-       Double_t tanphi   = (y2-y1)/dist; 
-       Double_t tantheta = (z2-z1)/dist; 
-       if (TMath::Abs(tanphi)>maxphi) continue;
-       if (TMath::Abs(tantheta)>maxtheta) continue;
+      Double_t xref                 = (xcl[sLayer+1] + xcl[sLayer+2])*0.5;      
+      AliTRDpropagationLayer& layer0=*reflayers[sLayer+0];
+      AliTRDpropagationLayer& layer1=*reflayers[sLayer+1];
+      AliTRDpropagationLayer& layer2=*reflayers[sLayer+2];
+      AliTRDpropagationLayer& layer3=*reflayers[sLayer+3];
+      //
+      Int_t maxn3  = layer3;
+      for (Int_t icl3=0;icl3<maxn3;icl3++){
+       AliTRDcluster *cl3 = layer3[icl3];
+       if (!cl3) continue;     
+       padlength[sLayer+3] = TMath::Sqrt(cl3->GetSigmaZ2()*12.);
+       ycl[sLayer+3] = cl3->GetY();
+       zcl[sLayer+3] = cl3->GetZ();
+       Float_t yymin0 = ycl[sLayer+3] - 1- maxphi *(xcl[sLayer+3]-xcl[sLayer+0]);
+       Float_t yymax0 = ycl[sLayer+3] + 1+ maxphi *(xcl[sLayer+3]-xcl[sLayer+0]);
+       Int_t   maxn0 = layer0;  // 
+       for (Int_t icl0=layer0.Find(yymin0);icl0<maxn0;icl0++){
+         AliTRDcluster *cl0 = layer0[icl0];
+         if (!cl0) continue;
+         if (cl3->IsUsed()&&cl0->IsUsed()) continue;
+         ycl[sLayer+0] = cl0->GetY();
+         zcl[sLayer+0] = cl0->GetZ();
+         if ( ycl[sLayer+0]>yymax0) break;
+         Double_t tanphi   = (ycl[sLayer+3]-ycl[sLayer+0])/(xcl[sLayer+3]-xcl[sLayer+0]); 
+         if (TMath::Abs(tanphi)>maxphi) continue;
+         Double_t tantheta = (zcl[sLayer+3]-zcl[sLayer+0])/(xcl[sLayer+3]-xcl[sLayer+0]); 
+         if (TMath::Abs(tantheta)>maxtheta) continue; 
+         padlength[sLayer+0] = TMath::Sqrt(cl0->GetSigmaZ2()*12.);
+         //
+         // expected position in 1 layer
+         Double_t y1exp = ycl[sLayer+0]+(tanphi)  *(xcl[sLayer+1]-xcl[sLayer+0]);        
+         Double_t z1exp = zcl[sLayer+0]+(tantheta)*(xcl[sLayer+1]-xcl[sLayer+0]);        
+         Float_t yymin1 = y1exp - kRoad0y-tanphi;
+         Float_t yymax1 = y1exp + kRoad0y+tanphi;
+         Int_t   maxn1  = layer1;  // 
+         //
+         for (Int_t icl1=layer1.Find(yymin1);icl1<maxn1;icl1++){
+           AliTRDcluster *cl1 = layer1[icl1];
+           if (!cl1) continue;
+           Int_t nusedCl = 0;
+           if (cl3->IsUsed()) nusedCl++;
+           if (cl0->IsUsed()) nusedCl++;
+           if (cl1->IsUsed()) nusedCl++;
+           if (nusedCl>1) continue;
+           ycl[sLayer+1] = cl1->GetY();
+           zcl[sLayer+1] = cl1->GetZ();
+           if ( ycl[sLayer+1]>yymax1) break;
+           if (TMath::Abs(ycl[sLayer+1]-y1exp)>kRoad0y+tanphi) continue;
+           if (TMath::Abs(zcl[sLayer+1]-z1exp)>kRoad0z)        continue;
+           padlength[sLayer+1] = TMath::Sqrt(cl1->GetSigmaZ2()*12.);
+           //
+           Double_t y2exp  = ycl[sLayer+0]+(tanphi)  *(xcl[sLayer+2]-xcl[sLayer+0])+(ycl[sLayer+1]-y1exp);       
+           Double_t z2exp  = zcl[sLayer+0]+(tantheta)*(xcl[sLayer+2]-xcl[sLayer+0]);
+           Int_t    index2 = layer2.FindNearestCluster(y2exp,z2exp,kRoad1y,  kRoad1z);
+           if (index2<=0) continue; 
+           AliTRDcluster *cl2 = (AliTRDcluster*)GetCluster(index2);
+           padlength[sLayer+2] = TMath::Sqrt(cl2->GetSigmaZ2()*12.);
+           ycl[sLayer+2] = cl2->GetY();
+           zcl[sLayer+2] = cl2->GetZ();
+           if (TMath::Abs(cl2->GetZ()-z2exp)>kRoad0z)        continue;
+           //
+           rieman.Reset();
+           rieman.AddPoint(xcl[sLayer+0],ycl[sLayer+0],zcl[sLayer+0],1,10);
+           rieman.AddPoint(xcl[sLayer+1],ycl[sLayer+1],zcl[sLayer+1],1,10);
+           rieman.AddPoint(xcl[sLayer+3],ycl[sLayer+3],zcl[sLayer+3],1,10);        
+           rieman.AddPoint(xcl[sLayer+2],ycl[sLayer+2],zcl[sLayer+2],1,10);
+           rieman.Update();
+           //
+           // reset fitter
+           for (Int_t iLayer=0;iLayer<6;iLayer++){
+             cseed[iLayer].Reset();
+           }     
+           chi2Z =0.; chi2R=0.;
+           for (Int_t iLayer=0;iLayer<4;iLayer++){
+             cseed[sLayer+iLayer].fZref[0] = rieman.GetZat(xcl[sLayer+iLayer]);
+             chi2Z += (cseed[sLayer+iLayer].fZref[0]- zcl[sLayer+iLayer])*
+               (cseed[sLayer+iLayer].fZref[0]- zcl[sLayer+iLayer]);
+             cseed[sLayer+iLayer].fZref[1] = rieman.GetDZat(xcl[sLayer+iLayer]);             
+             cseed[sLayer+iLayer].fYref[0] = rieman.GetYat(xcl[sLayer+iLayer]);
+             chi2R += (cseed[sLayer+iLayer].fYref[0]- ycl[sLayer+iLayer])*
+               (cseed[sLayer+iLayer].fYref[0]- ycl[sLayer+iLayer]);
+             cseed[sLayer+iLayer].fYref[1] = rieman.GetDYat(xcl[sLayer+iLayer]);
+           }
+           if (TMath::Sqrt(chi2R)>1./iter) continue;
+           if (TMath::Sqrt(chi2Z)>7./iter) continue;
+           //
+           //
+           //
+           Float_t minmax[2]={-100,100};
+           for (Int_t iLayer=0;iLayer<4;iLayer++){
+             Float_t max = zcl[sLayer+iLayer]+padlength[sLayer+iLayer]*0.5+1 -cseed[sLayer+iLayer].fZref[0];
+             if (max<minmax[1]) minmax[1]=max; 
+             Float_t min = zcl[sLayer+iLayer]-padlength[sLayer+iLayer]*0.5-1 -cseed[sLayer+iLayer].fZref[0];
+             if (min>minmax[0]) minmax[0]=min; 
+           }
+           Bool_t isFake = kFALSE; 
+           if (cl0->GetLabel(0)!=cl3->GetLabel(0)) isFake = kTRUE;
+           if (cl1->GetLabel(0)!=cl3->GetLabel(0)) isFake = kTRUE;
+           if (cl2->GetLabel(0)!=cl3->GetLabel(0)) isFake = kTRUE;
+           if ((!isFake) || (icl3%10)==0 ){  //debugging print
+             TTreeSRedirector& cstream = *fDebugStreamer;
+             cstream<<"Seeds0"<<
+               "isFake="<<isFake<<
+               "Cl0.="<<cl0<<
+               "Cl1.="<<cl1<<
+               "Cl2.="<<cl2<<
+               "Cl3.="<<cl3<<
+               "Xref="<<xref<<
+               "X0="<<xcl[sLayer+0]<<
+               "X1="<<xcl[sLayer+1]<<
+               "X2="<<xcl[sLayer+2]<<
+               "X3="<<xcl[sLayer+3]<<
+               "Y2exp="<<y2exp<<
+               "Z2exp="<<z2exp<<
+               "Chi2R="<<chi2R<<
+               "Chi2Z="<<chi2Z<<               
+               "Seed0.="<<&cseed[sLayer+0]<<
+               "Seed1.="<<&cseed[sLayer+1]<<
+               "Seed2.="<<&cseed[sLayer+2]<<
+               "Seed3.="<<&cseed[sLayer+3]<<
+               "Zmin="<<minmax[0]<<
+               "Zmax="<<minmax[1]<<
+               "\n";
+           }
+           
+           //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+           //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+           //<<<<<<<<<<<<<<<<<<    FIT SEEDING PART                  <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+           //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+           cl[sLayer+0] = cl0;
+           cl[sLayer+1] = cl1;
+           cl[sLayer+2] = cl2;
+           cl[sLayer+3] = cl3;
+           Bool_t isOK=kTRUE;
+           for (Int_t jLayer=0;jLayer<4;jLayer++){
+             cseed[sLayer+jLayer].fTilt = hL[sLayer+jLayer];
+             cseed[sLayer+jLayer].fPadLength = padlength[sLayer+jLayer];
+             cseed[sLayer+jLayer].fX0   = xcl[sLayer+jLayer];
+             for (Int_t iter=0; iter<2; iter++){
+               //
+               // in iteration 0 we try only one pad-row
+               // if quality not sufficient we try 2 pad-rows - about 5% of tracks cross 2 pad-rows
+               //
+               AliTRDseed tseed = cseed[sLayer+jLayer];
+               Float_t    roadz  = padlength[sLayer+jLayer]*0.5;
+               if (iter>0) roadz = padlength[sLayer+jLayer];
+               //
+               Float_t quality =10000;
+               for (Int_t iTime=2;iTime<20;iTime++){ 
+                 AliTRDpropagationLayer& layer = *(fTrSec[ns]->GetLayer(layers[sLayer+jLayer][1]-iTime));
+                 Double_t dxlayer= layer.GetX()-xcl[sLayer+jLayer];             
+                 Double_t zexp   = cl[sLayer+jLayer]->GetZ() ;
+                 if (iter>0){
+                   // try 2 pad-rows in second iteration
+                   zexp  = tseed.fZref[0]+ tseed.fZref[1]*dxlayer;
+                   if (zexp>cl[sLayer+jLayer]->GetZ()) zexp = cl[sLayer+jLayer]->GetZ()+padlength[sLayer+jLayer]*0.5;
+                   if (zexp<cl[sLayer+jLayer]->GetZ()) zexp = cl[sLayer+jLayer]->GetZ()-padlength[sLayer+jLayer]*0.5;
+                 }
+                 //
+                 Double_t yexp  =  tseed.fYref[0]+ 
+                   tseed.fYref[1]*dxlayer;
+                 Int_t    index = layer.FindNearestCluster(yexp,zexp,kRoad1y, roadz);
+                 if (index<=0) continue; 
+                 AliTRDcluster *cl = (AliTRDcluster*)GetCluster(index);              
+                 //
+                 tseed.fIndexes[iTime]  = index;
+                 tseed.fClusters[iTime] = cl;   // register cluster
+                 tseed.fX[iTime] = dxlayer;     // register cluster
+                 tseed.fY[iTime] = cl->GetY();  // register cluster
+                 tseed.fZ[iTime] = cl->GetZ();  // register cluster
+               } 
+               tseed.Update();
+               //count the number of clusters and distortions into quality
+               Float_t dangle = tseed.fYfit[1]-tseed.fYref[1];
+               Float_t tquality   = (18-tseed.fN2)/2. + TMath::Abs(dangle)/0.1+
+                 TMath::Abs(tseed.fYfit[0]-tseed.fYref[0])/0.2+
+                 2.*TMath::Abs(tseed.fMeanz-tseed.fZref[0])/padlength[jLayer];
+               if (iter==0 && tseed.isOK()) {
+                 cseed[sLayer+jLayer] = tseed;
+                 quality = tquality;
+                 if (tquality<5) break;  
+               }
+               if (tseed.isOK() && tquality<quality)
+                 cseed[sLayer+jLayer] = tseed;                         
+             }
+             if (!cseed[sLayer+jLayer].isOK()){
+               isOK = kFALSE;
+               break;
+             }                   
+             cseed[sLayer+jLayer].CookLabels();
+             cseed[sLayer+jLayer].UpdateUsed();
+             nusedCl+= cseed[sLayer+jLayer].fNUsed;
+             if (nusedCl>25){
+               isOK = kFALSE;
+               break;
+             }     
+           }
+           //
+           if (!isOK) continue;
+           nclusters=0;
+           for (Int_t iLayer=0;iLayer<4;iLayer++){
+             if (cseed[sLayer+iLayer].isOK()){
+               nclusters+=cseed[sLayer+iLayer].fN2;        
+             }
+           }
+           // 
+           // iteration 0
+           rieman.Reset();
+           for (Int_t iLayer=0;iLayer<4;iLayer++){
+             rieman.AddPoint(xcl[sLayer+iLayer],cseed[sLayer+iLayer].fYfitR[0],
+                             cseed[sLayer+iLayer].fZProb,1,10);
+           }
+           rieman.Update();
+           //
+           //
+           chi2R =0; chi2Z=0;
+           for (Int_t iLayer=0;iLayer<4;iLayer++){
+             cseed[sLayer+iLayer].fYref[0] = rieman.GetYat(xcl[sLayer+iLayer]);
+             chi2R += (cseed[sLayer+iLayer].fYref[0]-cseed[sLayer+iLayer].fYfitR[0])*
+               (cseed[sLayer+iLayer].fYref[0]-cseed[sLayer+iLayer].fYfitR[0]);
+             cseed[sLayer+iLayer].fYref[1] = rieman.GetDYat(xcl[sLayer+iLayer]);
+             cseed[sLayer+iLayer].fZref[0] = rieman.GetZat(xcl[sLayer+iLayer]);
+             chi2Z += (cseed[sLayer+iLayer].fZref[0]- cseed[sLayer+iLayer].fMeanz)*
+               (cseed[sLayer+iLayer].fZref[0]- cseed[sLayer+iLayer].fMeanz);
+             cseed[sLayer+iLayer].fZref[1] = rieman.GetDZat(xcl[sLayer+iLayer]);
+           }
+           Double_t curv = rieman.GetC();
+           //
+           // likelihoods
+           //
+           Double_t sumda = 
+             TMath::Abs(cseed[sLayer+0].fYfitR[1]- cseed[sLayer+0].fYref[1])+
+             TMath::Abs(cseed[sLayer+1].fYfitR[1]- cseed[sLayer+1].fYref[1])+
+             TMath::Abs(cseed[sLayer+2].fYfitR[1]- cseed[sLayer+2].fYref[1])+
+             TMath::Abs(cseed[sLayer+3].fYfitR[1]- cseed[sLayer+3].fYref[1]);
+           Double_t likea = TMath::Exp(-sumda*10.6);
+           Double_t likechi2 = 0.0000000001;
+           if (chi2R<0.5) likechi2+=TMath::Exp(-TMath::Sqrt(chi2R)*7.73);
+           Double_t likechi2z = TMath::Exp(-chi2Z*0.088)/TMath::Exp(-chi2Z*0.019);
+           Double_t likeN    = TMath::Exp(-(72-nclusters)*0.19);
+           Double_t like     = likea*likechi2*likechi2z*likeN;
+           //
+           Double_t likePrimY = TMath::Exp(-TMath::Abs(cseed[sLayer+0].fYref[1]-130*curv)*1.9);
+           Double_t likePrimZ = TMath::Exp(-TMath::Abs(cseed[sLayer+0].fZref[1]-
+                                                       cseed[sLayer+0].fZref[0]/xcl[sLayer+0])*5.9);
+           Double_t likePrim  = TMath::Max(likePrimY*likePrimZ,0.0005);
+                                           
+           seedquality[registered]  = like; 
+           seedlayer[registered]    = sLayer;
+           if (TMath::Log(0.000000000000001+like)<-15) continue;
+           AliTRDseed seedb[6];
+           for (Int_t iLayer=0;iLayer<6;iLayer++){
+             seedb[iLayer] = cseed[iLayer]; 
+           }
+           //
+           //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+           //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+           //<<<<<<<<<<<<<<<   FULL TRACK FIT PART         <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+           //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+           //
+           Int_t nlayers            = 0;
+           Int_t nusedf             = 0;
+           Int_t findable           = 0;
+           //
+           // add new layers  - avoid long extrapolation
+           //
+           Int_t tLayer[2]={0,0};
+           if (sLayer==2) {tLayer[0]=1; tLayer[1]=0;}
+           if (sLayer==1) {tLayer[0]=5; tLayer[1]=0;}
+           if (sLayer==0) {tLayer[0]=4; tLayer[1]=5;}
+           //
+           for (Int_t iLayer=0;iLayer<2;iLayer++){
+             Int_t jLayer = tLayer[iLayer];      // set tracking layer       
+             cseed[jLayer].Reset();
+             cseed[jLayer].fTilt    = hL[jLayer];
+             cseed[jLayer].fPadLength = padlength[jLayer];
+             cseed[jLayer].fX0      = xcl[jLayer];
+             // get pad length and rough cluster
+             Int_t    indexdummy = reflayers[jLayer]->FindNearestCluster(cseed[jLayer].fYref[0], 
+                                                                         cseed[jLayer].fZref[0],kRoad2y,kRoad2z);
+             if (indexdummy<=0) continue; 
+             AliTRDcluster *cldummy = (AliTRDcluster*)GetCluster(indexdummy);
+             padlength[jLayer]      = TMath::Sqrt(cldummy->GetSigmaZ2()*12.);
+           }
+           AliTRDseed::FitRiemanTilt(cseed, kTRUE);
+           //
+           for (Int_t iLayer=0;iLayer<2;iLayer++){
+             Int_t jLayer = tLayer[iLayer];      // set tracking layer 
+             if ( (jLayer==0) && !(cseed[1].isOK())) continue;  // break not allowed
+             if ( (jLayer==5) && !(cseed[4].isOK())) continue;  // break not allowed
+             Float_t  zexp  = cseed[jLayer].fZref[0];
+             Double_t zroad =  padlength[jLayer]*0.5+1.;
+             //
+             // 
+             for (Int_t iter=0;iter<2;iter++){
+               AliTRDseed tseed = cseed[jLayer];
+               Float_t quality = 10000;
+               for (Int_t iTime=2;iTime<20;iTime++){ 
+                 AliTRDpropagationLayer& layer = *(fTrSec[ns]->GetLayer(layers[jLayer][1]-iTime));
+                 Double_t dxlayer     = layer.GetX()-xcl[jLayer];
+                 Double_t yexp        = tseed.fYref[0]+tseed.fYref[1]*dxlayer;
+                 Float_t  yroad       = kRoad1y;
+                 Int_t    index = layer.FindNearestCluster(yexp,zexp, yroad, zroad);
+                 if (index<=0) continue; 
+                 AliTRDcluster *cl = (AliTRDcluster*)GetCluster(index);              
+                 //
+                 tseed.fIndexes[iTime]  = index;
+                 tseed.fClusters[iTime] = cl;   // register cluster
+                 tseed.fX[iTime] = dxlayer;     // register cluster
+                 tseed.fY[iTime] = cl->GetY();  // register cluster
+                 tseed.fZ[iTime] = cl->GetZ();  // register cluster
+               }             
+               tseed.Update();
+               if (tseed.isOK()){
+                 Float_t dangle = tseed.fYfit[1]-tseed.fYref[1];
+                 Float_t tquality   = (18-tseed.fN2)/2. + TMath::Abs(dangle)/0.1+                
+                   TMath::Abs(tseed.fYfit[0]-tseed.fYref[0])/0.2+ 
+                   2.*TMath::Abs(tseed.fMeanz-tseed.fZref[0])/padlength[jLayer];
+                 //
+                 if (tquality<quality){
+                   cseed[jLayer]=tseed;
+                   quality = tquality;
+                 }
+               }
+               zroad*=2.;
+             }
+             if ( cseed[jLayer].isOK()){
+               cseed[jLayer].CookLabels();
+               cseed[jLayer].UpdateUsed();
+               nusedf+= cseed[jLayer].fNUsed;
+               AliTRDseed::FitRiemanTilt(cseed, kTRUE);
+             }
+           }
+           //
+           //
+           // make copy
+           AliTRDseed bseed[6];
+           for (Int_t jLayer=0;jLayer<6;jLayer++){
+             bseed[jLayer] = cseed[jLayer];
+           }       
+           Float_t lastquality = 10000;
+           Float_t lastchi2    = 10000;
+           Float_t chi2        = 1000;
+
+           //
+           for (Int_t iter =0; iter<4;iter++){
+             //
+             // sort tracklets according "quality", try to "improve" 4 worst 
+             //
+             Float_t sumquality = 0;
+             Float_t squality[6];
+             Int_t   sortindexes[6];
+             for (Int_t jLayer=0;jLayer<6;jLayer++){
+               if (bseed[jLayer].isOK()){ 
+                 AliTRDseed &tseed = bseed[jLayer];
+                 Double_t zcor  =  tseed.fTilt*(tseed.fZProb-tseed.fZref[0]);
+                 Float_t dangle = tseed.fYfit[1]-tseed.fYref[1];
+                 Float_t tquality  = (18-tseed.fN2)/2. + TMath::Abs(dangle)/0.1+                 
+                   TMath::Abs(tseed.fYfit[0]-(tseed.fYref[0]-zcor))/0.2+ 
+                   2.*TMath::Abs(tseed.fMeanz-tseed.fZref[0])/padlength[jLayer];
+                 squality[jLayer] = tquality;
+               }
+               else  squality[jLayer]=-1;
+               sumquality +=squality[jLayer];
+             }
+
+             if (sumquality>=lastquality ||  chi2>lastchi2) break;
+             lastquality = sumquality;  
+             lastchi2    = chi2;
+             if (iter>0){
+               for (Int_t jLayer=0;jLayer<6;jLayer++){
+                 cseed[jLayer] = bseed[jLayer];
+               }
+             }
+             TMath::Sort(6,squality,sortindexes,kFALSE);
+             //
+             //
+             for (Int_t jLayer=5;jLayer>1;jLayer--){
+               Int_t bLayer = sortindexes[jLayer];
+               AliTRDseed tseed = bseed[bLayer];
+               for (Int_t iTime=2;iTime<20;iTime++){ 
+                 AliTRDpropagationLayer& layer = *(fTrSec[ns]->GetLayer(layers[bLayer][1]-iTime));
+                 Double_t dxlayer= layer.GetX()-xcl[bLayer];
+                 //
+                 Double_t zexp  =  tseed.fZref[0];
+                 Double_t zcor  =  tseed.fTilt*(tseed.fZProb-tseed.fZref[0]);
+                 //
+                 Float_t  roadz = padlength[bLayer]+1;
+                 if (TMath::Abs(tseed.fZProb-zexp)> padlength[bLayer]*0.5) {roadz = padlength[bLayer]*0.5;}
+                 if (tseed.fZfit[1]*tseed.fZref[1]<0) {roadz = padlength[bLayer]*0.5;}
+                 if (TMath::Abs(tseed.fZProb-zexp)<0.1*padlength[bLayer]) {
+                   zexp = tseed.fZProb; 
+                   roadz = padlength[bLayer]*0.5;
+                 }
+                 //
+                 Double_t yexp  =  tseed.fYref[0]+ 
+                   tseed.fYref[1]*dxlayer-zcor;
+                 Int_t    index = layer.FindNearestCluster(yexp,zexp,kRoad1y, roadz);
+                 if (index<=0) continue; 
+                 AliTRDcluster *cl = (AliTRDcluster*)GetCluster(index);              
+                 //
+                 tseed.fIndexes[iTime]  = index;
+                 tseed.fClusters[iTime] = cl;   // register cluster
+                 tseed.fX[iTime] = dxlayer;     // register cluster
+                 tseed.fY[iTime] = cl->GetY();  // register cluster
+                 tseed.fZ[iTime] = cl->GetZ();  // register cluster
+               } 
+               tseed.Update();
+               if (tseed.isOK()) {
+                 Float_t dangle = tseed.fYfit[1]-tseed.fYref[1];
+                 Double_t zcor  =  tseed.fTilt*(tseed.fZProb-tseed.fZref[0]);
+                 //
+                 Float_t tquality   = (18-tseed.fN2)/2. + TMath::Abs(dangle)/0.1+                
+                   TMath::Abs(tseed.fYfit[0]-(tseed.fYref[0]-zcor))/0.2+ 
+                   2.*TMath::Abs(tseed.fMeanz-tseed.fZref[0])/padlength[jLayer];
+                 //
+                 if (tquality<squality[bLayer])
+                   bseed[bLayer] = tseed;
+               }
+             }
+             chi2 = AliTRDseed::FitRiemanTilt(bseed, kTRUE);
+           }
+           //
+           //
+           //
+           nclusters  = 0;
+           nlayers    = 0;
+           findable   = 0;
+           for (Int_t iLayer=0;iLayer<6;iLayer++) {
+             if (TMath::Abs(cseed[iLayer].fYref[0]/cseed[iLayer].fX0)<0.15)
+               findable++;
+             if (cseed[iLayer].isOK()){
+               nclusters+=cseed[iLayer].fN2;       
+               nlayers++;
+             }
+           }
+           if (nlayers<3) continue;
+           rieman.Reset();
+           for (Int_t iLayer=0;iLayer<6;iLayer++){
+             if (cseed[iLayer].isOK()) rieman.AddPoint(xcl[iLayer],cseed[iLayer].fYfitR[0],
+                                                                  cseed[iLayer].fZProb,1,10);
+           }
+           rieman.Update();
+           //
+           chi2RF =0;
+           chi2ZF =0;
+           for (Int_t iLayer=0;iLayer<6;iLayer++){
+             if (cseed[iLayer].isOK()){
+               cseed[iLayer].fYref[0] = rieman.GetYat(xcl[iLayer]);
+               chi2RF += (cseed[iLayer].fYref[0]-cseed[iLayer].fYfitR[0])*
+                 (cseed[iLayer].fYref[0]-cseed[iLayer].fYfitR[0]);
+               cseed[iLayer].fYref[1] = rieman.GetDYat(xcl[iLayer]);
+               cseed[iLayer].fZref[0] = rieman.GetZat(xcl[iLayer]);
+               chi2ZF += (cseed[iLayer].fZref[0]- cseed[iLayer].fMeanz)*
+                 (cseed[iLayer].fZref[0]- cseed[iLayer].fMeanz);
+               cseed[iLayer].fZref[1] = rieman.GetDZat(xcl[iLayer]);
+             }
+           }
+           chi2RF/=TMath::Max((nlayers-3.),1.);
+           chi2ZF/=TMath::Max((nlayers-3.),1.);
+           curv = rieman.GetC();
+           
+           //
+
+           Double_t xref2    = (xcl[2]+xcl[3])*0.5;  // middle of the chamber
+           Double_t dzmf     = rieman.GetDZat(xref2);
+           Double_t zmf      = rieman.GetZat(xref2);
+           //
+           // fit hyperplane
+           //
+           Int_t npointsT =0;
+           fitterTC.ClearPoints();
+           fitterT2.ClearPoints();
+           rieman2.Reset();
+           for (Int_t iLayer=0; iLayer<6;iLayer++){
+             if (!cseed[iLayer].isOK()) continue;
+             for (Int_t itime=0;itime<25;itime++){
+               if (!cseed[iLayer].fUsable[itime]) continue;
+               Double_t x   = cseed[iLayer].fX[itime]+cseed[iLayer].fX0-xref2;  // x relative to the midle chamber
+               Double_t y   = cseed[iLayer].fY[itime];
+               Double_t z   = cseed[iLayer].fZ[itime];
+               // ExB correction to the correction
+               // tilted rieman
+               //
+               Double_t uvt[6];
+               Double_t x2 = cseed[iLayer].fX[itime]+cseed[iLayer].fX0;      // global x
+               //              
+               Double_t t = 1./(x2*x2+y*y);
+               uvt[1]  = t;    // t
+               uvt[0]  = 2.*x2*uvt[1];      // u 
+               //
+               uvt[2]  = 2.0*hL[iLayer]*uvt[1];
+               uvt[3]  = 2.0*hL[iLayer]*x*uvt[1];            
+               uvt[4]  = 2.0*(y+hL[iLayer]*z)*uvt[1];
+               //
+               Double_t error = 2*0.2*uvt[1];
+               fitterT2.AddPoint(uvt,uvt[4],error);
+               //
+               // constrained rieman
+               // 
+               z =cseed[iLayer].fZ[itime];
+               uvt[0]  = 2.*x2*t;           // u 
+               uvt[1]  = 2*hL[iLayer]*x2*uvt[1];             
+               uvt[2]  = 2*(y+hL[iLayer]*(z-GetZ()))*t;
+               fitterTC.AddPoint(uvt,uvt[2],error);
+               //              
+               rieman2.AddPoint(x2,y,z,1,10);
+               npointsT++;
+             }
+           }
+           rieman2.Update();
+           fitterTC.Eval();
+           fitterT2.Eval();
+           Double_t rpolz0 = fitterT2.GetParameter(3);
+           Double_t rpolz1 = fitterT2.GetParameter(4);     
+           //
+           // linear fitter  - not possible to make boundaries
+           // non accept non possible z and dzdx combination
+           //      
+           Bool_t   acceptablez =kTRUE;
+           for (Int_t iLayer=0; iLayer<6;iLayer++){
+             if (cseed[iLayer].isOK()){
+               Double_t zT2 =  rpolz0+rpolz1*(xcl[iLayer] - xref2);
+               if (TMath::Abs(cseed[iLayer].fZProb-zT2)>padlength[iLayer]*0.5+1)
+                 acceptablez = kFALSE;
+             }
+           }
+           if (!acceptablez){
+             fitterT2.FixParameter(3,zmf);
+             fitterT2.FixParameter(4,dzmf);
+             fitterT2.Eval();
+             fitterT2.ReleaseParameter(3);
+             fitterT2.ReleaseParameter(4);
+             rpolz0 = fitterT2.GetParameter(3);
+             rpolz1 = fitterT2.GetParameter(4);
+           }
+           //
+           Double_t chi2TR = fitterT2.GetChisquare()/Float_t(npointsT);
+           Double_t chi2TC = fitterTC.GetChisquare()/Float_t(npointsT);
+           //
+           Double_t polz1c = fitterTC.GetParameter(2);
+           Double_t polz0c = polz1c*xref2;
+           //
+           Double_t aC     =  fitterTC.GetParameter(0);
+           Double_t bC     =  fitterTC.GetParameter(1);
+           Double_t CC     =  aC/TMath::Sqrt(bC*bC+1.);     // curvature
+           //
+           Double_t aR     =  fitterT2.GetParameter(0);
+           Double_t bR     =  fitterT2.GetParameter(1);
+           Double_t dR     =  fitterT2.GetParameter(2);            
+           Double_t CR     =  1+bR*bR-dR*aR;
+           Double_t dca    =  0.;          
+           if (CR>0){
+             dca = -dR/(TMath::Sqrt(1+bR*bR-dR*aR)+TMath::Sqrt(1+bR*bR)); 
+             CR  = aR/TMath::Sqrt(CR);
+           }
+           //
+           Double_t chi2ZT2=0, chi2ZTC=0;
+           for (Int_t iLayer=0; iLayer<6;iLayer++){
+             if (cseed[iLayer].isOK()){
+               Double_t zT2 =  rpolz0+rpolz1*(xcl[iLayer] - xref2);
+               Double_t zTC =  polz0c+polz1c*(xcl[iLayer] - xref2);
+               chi2ZT2 += TMath::Abs(cseed[iLayer].fMeanz-zT2);
+               chi2ZTC += TMath::Abs(cseed[iLayer].fMeanz-zTC);
+             }
+           }
+           chi2ZT2/=TMath::Max((nlayers-3.),1.);
+           chi2ZTC/=TMath::Max((nlayers-3.),1.);           
+           //
+           //
+           //
+           AliTRDseed::FitRiemanTilt(cseed, kTRUE);
+           Float_t sumdaf = 0;
+           for (Int_t iLayer=0;iLayer<6;iLayer++){
+             if (cseed[iLayer].isOK())
+               sumdaf += TMath::Abs((cseed[iLayer].fYfit[1]-cseed[iLayer].fYref[1])/cseed[iLayer].fSigmaY2);
+           }  
+           sumdaf /= Float_t (nlayers-2.);
+           //
+           // likelihoods for full track
+           //
+           Double_t likezf      = TMath::Exp(-chi2ZF*0.14);
+           Double_t likechi2C   = TMath::Exp(-chi2TC*0.677);
+           Double_t likechi2TR  = TMath::Exp(-chi2TR*0.78);
+           Double_t likeaf      = TMath::Exp(-sumdaf*3.23);
+           seedquality2[registered] = likezf*likechi2TR*likeaf; 
+//         Bool_t isGold = kFALSE;
+//         
+//         if (nlayers == 6        && TMath::Log(0.000000001+seedquality2[index])<-5.) isGold =kTRUE;   // gold
+//         if (nlayers == findable && TMath::Log(0.000000001+seedquality2[index])<-4.) isGold =kTRUE;   // gold
+//         if (isGold &&nusedf<10){
+//           for (Int_t jLayer=0;jLayer<6;jLayer++){
+//             if ( seed[index][jLayer].isOK()&&TMath::Abs(seed[index][jLayer].fYfit[1]-seed[index][jLayer].fYfit[1])<0.1)
+//               seed[index][jLayer].UseClusters();  //sign gold
+//           }
+//         }
+           //
+           //
+           //
+           Int_t index0=0;
+           if (!cseed[0].isOK()){
+             index0 = 1;
+             if (!cseed[1].isOK()) index0 = 2;
+           }
+           seedparams[registered][0] = cseed[index0].fX0;
+           seedparams[registered][1] = cseed[index0].fYref[0];
+           seedparams[registered][2] = cseed[index0].fZref[0];
+           seedparams[registered][5] = CR;
+           seedparams[registered][3] = cseed[index0].fX0*CR - TMath::Sin(TMath::ATan(cseed[0].fYref[1]));
+           seedparams[registered][4] = cseed[index0].fZref[1]/       
+             TMath::Sqrt(1+cseed[index0].fYref[1]*cseed[index0].fYref[1]);
+           seedparams[registered][6] = ns;
+           //
+           //
+           Int_t labels[12], outlab[24];
+           Int_t nlab=0;
+           for (Int_t iLayer=0;iLayer<6;iLayer++){
+             if (!cseed[iLayer].isOK()) continue;
+             if (cseed[iLayer].fLabels[0]>=0) {
+               labels[nlab] = cseed[iLayer].fLabels[0];
+               nlab++;
+             }
+             if (cseed[iLayer].fLabels[1]>=0) {
+               labels[nlab] = cseed[iLayer].fLabels[1];
+               nlab++;
+             }       
+           }
+           Freq(nlab,labels,outlab,kFALSE);
+           Int_t label = outlab[0];
+           Int_t frequency  = outlab[1];
+           for (Int_t iLayer=0;iLayer<6;iLayer++){
+             cseed[iLayer].fFreq  = frequency;
+             cseed[iLayer].fC     = CR;
+             cseed[iLayer].fCC     = CC;
+             cseed[iLayer].fChi2  = chi2TR;
+             cseed[iLayer].fChi2Z = chi2ZF;
+           }
+           //
+           if (1||(!isFake)){  //debugging print
+             Float_t zvertex = GetZ();
+             TTreeSRedirector& cstream = *fDebugStreamer;
+             cstream<<"Seeds1"<<
+               "isFake="<<isFake<<
+               "Vertex="<<zvertex<<
+               "Rieman2.="<<&rieman2<<
+               "Rieman.="<<&rieman<<
+               "Xref="<<xref<<
+               "X0="<<xcl[0]<<
+               "X1="<<xcl[1]<<
+               "X2="<<xcl[2]<<
+               "X3="<<xcl[3]<<
+               "X4="<<xcl[4]<<
+               "X5="<<xcl[5]<<
+               "Chi2R="<<chi2R<<
+               "Chi2Z="<<chi2Z<<
+               "Chi2RF="<<chi2RF<<                          //chi2 of trackletes on full track
+               "Chi2ZF="<<chi2ZF<<                          //chi2 z on tracklets on full track
+               "Chi2ZT2="<<chi2ZT2<<                        //chi2 z on tracklets on full track  - rieman tilt
+               "Chi2ZTC="<<chi2ZTC<<                        //chi2 z on tracklets on full track  - rieman tilt const
+               //
+               "Chi2TR="<<chi2TR<<                           //chi2 without vertex constrain
+               "Chi2TC="<<chi2TC<<                           //chi2 with    vertex constrain
+               "C="<<curv<<                                  // non constrained - no tilt correction
+               "DR="<<dR<<                                   // DR parameter          - tilt correction
+               "DCA="<<dca<<                                 // DCA                   - tilt correction
+               "CR="<<CR<<                                   // non constrained curvature - tilt correction
+               "CC="<<CC<<                                   // constrained curvature
+               "Polz0="<<polz0c<<
+               "Polz1="<<polz1c<<
+               "RPolz0="<<rpolz0<<
+               "RPolz1="<<rpolz1<<
+               "Ncl="<<nclusters<<
+               "Nlayers="<<nlayers<<
+               "NUsedS="<<nusedCl<<
+               "NUsed="<<nusedf<<
+               "Findable="<<findable<<
+               "Like="<<like<<
+               "LikePrim="<<likePrim<<
+               "Likechi2C="<<likechi2C<<
+               "Likechi2TR="<<likechi2TR<<
+               "Likezf="<<likezf<<
+               "LikeF="<<seedquality2[registered]<<
+               "S0.="<<&cseed[0]<<
+               "S1.="<<&cseed[1]<<
+               "S2.="<<&cseed[2]<<
+               "S3.="<<&cseed[3]<<
+               "S4.="<<&cseed[4]<<
+               "S5.="<<&cseed[5]<<
+               "SB0.="<<&seedb[0]<<
+               "SB1.="<<&seedb[1]<<
+               "SB2.="<<&seedb[2]<<
+               "SB3.="<<&seedb[3]<<
+               "SB4.="<<&seedb[4]<<
+               "SB5.="<<&seedb[5]<<
+               "Label="<<label<<
+               "Freq="<<frequency<<
+               "sLayer="<<sLayer<<
+               "\n";
+           }
+           if (registered<maxseed-1) {
+             registered++;
+             cseed = seed[registered];
+           }
+         }// end of loop over layer 1
+       }  // end of loop over layer 0 
+      }    // end of loop over layer 3     
+    }      // end of loop over seeding time bins 
+    //
+    // choos best
+    //
+    TMath::Sort(registered,seedquality2,sort,kTRUE);
+    Bool_t signedseed[maxseed];
+    for (Int_t i=0;i<registered;i++){
+      signedseed[i]= kFALSE;
+    }
+    for (Int_t iter=0; iter<5; iter++){
+      for (Int_t iseed=0;iseed<registered;iseed++){      
+       Int_t index = sort[iseed];
+       if (signedseed[index]) continue;
+       Int_t labelsall[1000];
+       Int_t nlabelsall=0;
+       Int_t naccepted=0;;
+       Int_t sLayer = seedlayer[index];
+       Int_t ncl   = 0;
+       Int_t nused = 0;
+       Int_t nlayers =0;
+       Int_t findable   = 0;
+       for (Int_t jLayer=0;jLayer<6;jLayer++){
+         if (TMath::Abs(seed[index][jLayer].fYref[0]/xcl[jLayer])<0.15)
+           findable++;
+         if (seed[index][jLayer].isOK()){
+           seed[index][jLayer].UpdateUsed();
+           ncl   +=seed[index][jLayer].fN2;
+           nused +=seed[index][jLayer].fNUsed;
+           nlayers++;
+           //cooking label
+           for (Int_t itime=0;itime<25;itime++){
+             if (seed[index][jLayer].fUsable[itime]){
+               naccepted++;
+               for (Int_t ilab=0;ilab<3;ilab++){
+                 Int_t tindex = seed[index][jLayer].fClusters[itime]->GetLabel(ilab);
+                 if (tindex>=0){
+                   labelsall[nlabelsall] = tindex;
+                   nlabelsall++;
+                 }
+               }
+             }
+           }
+         }
+       }
        //
-       clusters1[0] = cl1;
-       clusters2[0] = cl2;
-       Double_t road =  0.5+TMath::Abs(tanphi)*1;
-       Int_t ncl=0;
-       Double_t sum1=0, sumx1=0,sum2x1=0,sumxy1=0, sumy1=0;
-       Double_t sum2=0, sumx2=0,sum2x2=0,sumxy2=0, sumy2=0;
+       if (nused>30) continue;
        //
-       for (Int_t dlayer=1;dlayer<15;dlayer++){
-         clusters1[dlayer]=0;
-         clusters2[dlayer]=0;
-         AliTRDpropagationLayer& layer1C=*(fTrSec[ns]->GetLayer(ilayer1-dlayer));  //select propagation layers
-         AliTRDpropagationLayer& layer2C=*(fTrSec[ns]->GetLayer(ilayer2-dlayer));  //
-         Double_t yy1 = y1+(tanphi)  *(layer1C.GetX()-x1);
-         Double_t zz1 = z1+(tantheta)*(layer1C.GetX()-x1);
-         Double_t yy2 = y1+(tanphi)  *(layer2C.GetX()-x1);
-         Double_t zz2 = z1+(tantheta)*(layer2C.GetX()-x1);
-         Int_t index1 = layer1C.FindNearestCluster(yy1,zz1,road);
-         Int_t index2 = layer2C.FindNearestCluster(yy2,zz2,road);
-         if (index1>=0) {
-           clusters1[dlayer]= (AliTRDcluster*)GetCluster(index1);
-           ncl++;
-           sum1++;
-           Double_t dx = layer1C.GetX()-x1;
-           sumx1 +=dx;
-           sum2x1+=dx*dx;
-           sumxy1+=dx*clusters1[dlayer]->GetY();       
-           sumy1 +=clusters1[dlayer]->GetY();
-         }
-         if (index2>=0) {
-           clusters2[dlayer]= (AliTRDcluster*)GetCluster(index2);
-           ncl++;
-           sum2++;
-           Double_t dx = layer2C.GetX()-x2;
-           sumx2 +=dx;
-           sum2x2+=dx*dx;
-           sumxy2+=dx*clusters2[dlayer]->GetY();
-           sumy2 +=clusters2[dlayer]->GetY();
-         }
+       if (iter==0){
+         if (nlayers<6) continue;
+         if (TMath::Log(0.000000001+seedquality2[index])<-5.) continue;   // gold
+       }
+       //
+       if (iter==1){
+         if (nlayers<findable) continue;
+         if (TMath::Log(0.000000001+seedquality2[index])<-4.) continue;  //
        }
-       if (sum1<10) continue;
-       if (sum2<10) continue;
        //
-       Double_t det1   = sum1*sum2x1-sumx1*sumx1;
-       Double_t angle1 = (sum1*sumxy1-sumx1*sumy1)/det1;
-       Double_t pos1   = (sum2x1*sumy1-sumx1*sumxy1)/det1;  // at x1 
        //
-       Double_t det2   = sum2*sum2x2-sumx2*sumx2;
-       Double_t angle2 = (sum2*sumxy2-sumx2*sumy2)/det2;
-       Double_t pos2   = (sum2x2*sumy2-sumx2*sumxy2)/det2;  // at x2
+       if (iter==2){
+         if (nlayers==findable || nlayers==6) continue;
+         if (TMath::Log(0.000000001+seedquality2[index])<-6.) continue;
+       }
        //
+       if (iter==3){
+         if (TMath::Log(0.000000001+seedquality2[index])<-5.) continue;
+       }
        //
-
-       Double_t sumM=0, sumxM=0,sum2xM=0,sumxyM=0, sumyM=0;
+       if (iter==4){
+         if (TMath::Log(0.000000001+seedquality2[index])-nused/(nlayers-3.)<-15.) continue;
+       }
        //
-       for (Int_t dlayer=1;dlayer<15;dlayer++){
-         clustersM[dlayer]=0;
-         AliTRDpropagationLayer& layerM=*(fTrSec[ns]->GetLayer(ilayerM-dlayer));  //select propagation layers
-         Double_t yyM = y1+(tanphi)  *(layerM.GetX()-x1);
-         Double_t zzM = z1+(tantheta)*(layerM.GetX()-x1);
-         Int_t indexM = layerM.FindNearestCluster(yyM,zzM,road);
-         if (indexM>=0) {
-           clustersM[dlayer]= (AliTRDcluster*)GetCluster(indexM);
-           ncl++;
-           sumM++;
-           Double_t dx = layerM.GetX()-xm;
-           sumxM +=dx;
-           sum2xM+=dx*dx;
-           sumxyM+=dx*clustersM[dlayer]->GetY();       
-           sumyM +=clustersM[dlayer]->GetY();
-         }
+       signedseed[index] = kTRUE;
+       //
+       Int_t labels[1000], outlab[1000];
+       Int_t nlab=0;
+       for (Int_t iLayer=0;iLayer<6;iLayer++){
+         if (seed[index][iLayer].isOK()){
+           if (seed[index][iLayer].fLabels[0]>=0) {
+             labels[nlab] = seed[index][iLayer].fLabels[0];
+             nlab++;
+           }
+           if (seed[index][iLayer].fLabels[1]>=0) {
+             labels[nlab] = seed[index][iLayer].fLabels[1];
+             nlab++;
+           }    
+         }     
        }
-       Double_t detM   = sumM*sum2xM-sumxM*sumxM;
-       Double_t posM=0, angleM=0;
-       if (TMath::Abs(detM)>0.0000001){
-         angleM = (sumM*sumxyM-sumxM*sumyM)/detM;
-         posM   = (sum2xM*sumyM-sumxM*sumxyM)/detM;  // at xm
+       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);
+       Float_t ratio = Float_t(nused)/Float_t(ncl);
+       if (ratio<0.25){
+         for (Int_t jLayer=0;jLayer<6;jLayer++){
+           if ( seed[index][jLayer].isOK()&&TMath::Abs(seed[index][jLayer].fYfit[1]-seed[index][jLayer].fYfit[1])<0.2 )
+             seed[index][jLayer].UseClusters();  //sign gold
+         }
        }
        //
-
-       if (ncl>15){
+       Int_t eventNr = esd->GetEventNumber();
+       TTreeSRedirector& cstream = *fDebugStreamer;
+       //
+       // register seed
+       //
+       AliTRDtrack * track = RegisterSeed(seed[index],seedparams[index]);
+       AliTRDtrack dummy;
+       if (!track) track=&dummy;
+       else{
+         AliESDtrack esdtrack;
+         esdtrack.UpdateTrackParams(track, AliESDtrack::kTRDout);
+         esdtrack.SetLabel(label);
+         esd->AddTrack(&esdtrack);     
          TTreeSRedirector& cstream = *fDebugStreamer;
-         cstream<<"Seeds"<<
-           "Ncl="<<ncl<<
-           "SumM="<<sumM<<
-           "x1="<<x1<<
-           "x2="<<x2<<
-           "Cl1.="<<cl1<<
-           "Cl2.="<<cl2<<
-           "Phi="<<tanphi<<
-           "Theta="<<tantheta<<
-           "Pos1="<<pos1<<
-           "Pos2="<<pos2<<
-           "PosM="<<posM<<
-           "Angle1="<<angle1<<
-           "Angle2="<<angle2<<
-           "AngleM="<<angleM<<
+         cstream<<"Tracks"<<
+           "EventNr="<<eventNr<<
+           "ESD.="<<&esdtrack<<
+           "trd.="<<track<<
+           "trdback.="<<track<<
            "\n";
        }
+
+       cstream<<"Seeds2"<<
+         "Iter="<<iter<<
+         "Track.="<<track<<
+         "Like="<<seedquality[index]<<
+         "LikeF="<<seedquality2[index]<<
+         "S0.="<<&seed[index][0]<<
+         "S1.="<<&seed[index][1]<<
+         "S2.="<<&seed[index][2]<<
+         "S3.="<<&seed[index][3]<<
+         "S4.="<<&seed[index][4]<<
+         "S5.="<<&seed[index][5]<<
+         "Label="<<label<<
+         "Label1="<<label1<<
+         "Label2="<<label2<<
+         "FakeRatio="<<fakeratio<<
+         "Freq="<<frequency<<
+         "Ncl="<<ncl<< 
+         "Nlayers="<<nlayers<<
+         "Findable="<<findable<<
+         "NUsed="<<nused<<
+         "sLayer="<<sLayer<<
+         "EventNr="<<eventNr<<
+         "\n";
       }
     }
-  }
-}            
-
+  }        // end of loop over sectors
+  delete [] pseed;
+}
+          
 //_____________________________________________________________________________
 Int_t AliTRDtracker::ReadClusters(TObjArray *array, TTree *ClusterTree) const
 {
@@ -2297,12 +3090,19 @@ void AliTRDtracker::UseClusters(const AliKalmanTrack* t, Int_t from) const
   //
   // Use clusters, but don't abuse them!
   //
-
+  const Float_t kmaxchi2 =18;
+  const Float_t kmincl   =10;
+  AliTRDtrack * track  = (AliTRDtrack*)t;
+  //
   Int_t ncl=t->GetNumberOfClusters();
   for (Int_t i=from; i<ncl; i++) {
     Int_t index = t->GetClusterIndex(i);
     AliTRDcluster *c=(AliTRDcluster*)fClusters->UncheckedAt(index);
-    c->Use();
+    //
+    Int_t iplane = fGeom->GetPlane(c->GetDetector());
+    if (track->fTracklets[iplane].GetChi2()>kmaxchi2) continue; 
+    if (track->fTracklets[iplane].GetN()<kmincl) continue; 
+    if (!(c->IsUsed())) c->Use();
   }
 }
 
@@ -2996,10 +3796,11 @@ void AliTRDtracker::AliTRDpropagationLayer::InsertCluster(AliTRDcluster* c,
 
 //______________________________________________________
 
-Int_t AliTRDtracker::AliTRDpropagationLayer::Find(Double_t y) const {
+Int_t AliTRDtracker::AliTRDpropagationLayer::Find(Float_t y) const {
 
 // Returns index of the cluster nearest in Y    
 
+  if (fN<=0) return 0;
   if (y <= fClusters[0]->GetY()) return 0;
   if (y > fClusters[fN-1]->GetY()) return fN;
   Int_t b=0, e=fN-1, m=(b+e)/2;
@@ -3010,27 +3811,24 @@ Int_t AliTRDtracker::AliTRDpropagationLayer::Find(Double_t y) const {
   return m;
 }    
 
-Int_t AliTRDtracker::AliTRDpropagationLayer::FindNearestCluster(Double_t y, Double_t z, Double_t maxroad) const 
+Int_t AliTRDtracker::AliTRDpropagationLayer::FindNearestCluster(Float_t y, Float_t z, Float_t maxroad, Float_t maxroadz) const 
 {
   //
   // Returns index of the cluster nearest to the given y,z
   //
   Int_t index = -1;
   Int_t maxn = fN;
-  Double_t mindist = maxroad;                  
-  Float_t padlength =-1;
+  Float_t mindist = maxroad;                   
   //
   for (Int_t i=Find(y-maxroad); i<maxn; i++) {
     AliTRDcluster* c=(AliTRDcluster*)(fClusters[i]);
-    if (padlength<0){
-      padlength = TMath::Sqrt(c->GetSigmaZ2()*12); 
-    }
+    Float_t ycl = c->GetY();
     //
-    if (c->GetY() > y+maxroad) break;
-    if((c->GetZ()-z)*(c->GetZ()-z) > padlength*0.75) continue;      
-    if (TMath::Abs(c->GetY()-y)<mindist){
-      mindist = TMath::Abs(c->GetY()-y);
-      index = GetIndex(i);
+    if (ycl > y+maxroad) break;
+    if (TMath::Abs(c->GetZ()-z) > maxroadz) continue;      
+    if (TMath::Abs(ycl-y)<mindist){
+      mindist = TMath::Abs(ycl-y);
+      index = fIndex[i];
     }        
   }                                            
   return index;
@@ -3140,8 +3938,7 @@ Int_t AliTRDtracker::FindClusters(Int_t sector, Int_t t0, Int_t t1, AliTRDtrack
   Int_t    best[10][100];       // index of best matching cluster 
   //
   //
-  TClonesArray array0("AliTRDcluster",1);
-  TClonesArray array1("AliTRDcluster",1);
+
   for (Int_t it=0;it<=t1-t0; it++){
     x[it]=0;
     yt[it]=0;
@@ -3160,7 +3957,7 @@ Int_t AliTRDtracker::FindClusters(Int_t sector, Int_t t0, Int_t t1, AliTRDtrack
   }  
   //
   Double_t x0 = track->GetX();
-  Double_t sigmaz = TMath::Sqrt(track->GetSigmaZ2());
+  Double_t sigmaz = TMath::Sqrt(TMath::Abs(track->GetSigmaZ2()));
   Int_t nall=0;
   Int_t nfound=0;
   Double_t h01 =0;
@@ -3301,7 +4098,9 @@ Int_t AliTRDtracker::FindClusters(Int_t sector, Int_t t0, Int_t t1, AliTRDtrack
       dz[ih][it]=-100;
       dy[ih][it]=-100;
       if (!cl[ih][it]) continue;
-      Float_t poscor =  fgkCoef*(cl[ih][it]->GetLocalTimeBin() - fgkMean)+fgkOffset;      
+      //Float_t poscor =  fgkCoef*(cl[ih][it]->GetLocalTimeBin() - fgkMean)+fgkOffset;      
+      Float_t poscor =  0;   // applied during loading of clusters      
+      if (cl[ih][it]->IsUsed()) poscor=0;  // correction already applied
       dz[ih][it]  = cl[ih][it]->GetZ()- zt[it];                               // calculate distance from track  in z
       dy[ih][it]  = cl[ih][it]->GetY()+ dz[ih][it]*h01 - poscor  -yt[it];     //                                in y
     }
@@ -3398,9 +4197,9 @@ Int_t AliTRDtracker::FindClusters(Int_t sector, Int_t t0, Int_t t1, AliTRDtrack
       if (!cl[best[iter][it]][it]) continue;
       //
       Double_t sigmatr2 = smoffset[iter]+0.5*tany*tany;             //add unisochronity + angular effect contribution
-      Double_t sweight  = 1./sigmatr2+1./track->fCyy;
+      Double_t sweight  = 1./sigmatr2+1./track->GetSigmaY2();
       Double_t weighty  = (moffset[iter]/sigmatr2)/sweight;         // weighted mean
-      Double_t sigmacl  = TMath::Sqrt(sigma1*sigma1+track->fCyy);   //
+      Double_t sigmacl  = TMath::Sqrt(sigma1*sigma1+track->GetSigmaY2());   //
       Double_t mindist=100000; 
       Int_t ihbest=0;
       for (Int_t ih=0;ih<10;ih++){
@@ -3417,7 +4216,7 @@ Int_t AliTRDtracker::FindClusters(Int_t sector, Int_t t0, Int_t t1, AliTRDtrack
     //
     //  update best hypothesy if better chi2 according tracklet position and angle
     //
-    Double_t sy2 = smean[iter]  + track->fCyy;
+    Double_t sy2 = smean[iter]  + track->GetSigmaY2();
     Double_t sa2 = sangle[iter] + track->fCee;
     Double_t say = track->fCey;
     //    Double_t chi20 = mean[bestiter]*mean[bestiter]/sy2+angle[bestiter]*angle[bestiter]/sa2;
@@ -3458,11 +4257,31 @@ Int_t AliTRDtracker::FindClusters(Int_t sector, Int_t t0, Int_t t1, AliTRDtrack
   //expectederr+=10000;
   for (Int_t it=0;it<t1-t0;it++){
     if (!cl[best[bestiter][it]][it]) continue;
-    Float_t poscor =  fgkCoef*(cl[best[bestiter][it]][it]->GetLocalTimeBin() - fgkMean)+fgkOffset;          
+    //    Float_t poscor =  fgkCoef*(cl[best[bestiter][it]][it]->GetLocalTimeBin() - fgkMean)+fgkOffset;          
+    Float_t poscor =  0;           //applied during loading of cluster
     cl[best[bestiter][it]][it]->SetSigmaY2(expectederr);  // set cluster error
     if (!cl[best[bestiter][it]][it]->IsUsed()){
       cl[best[bestiter][it]][it]->SetY( cl[best[bestiter][it]][it]->GetY()-poscor);  // ExB corrction correction    
-      cl[best[bestiter][it]][it]->Use();
+      //      cl[best[bestiter][it]][it]->Use();
+    }
+    //
+    //  time bins with maximal charge
+    if (TMath::Abs(cl[best[bestiter][it]][it]->GetQ())> maxcharge){
+      maxcharge = TMath::Abs(cl[best[bestiter][it]][it]->GetQ());
+      maxpos = cl[best[bestiter][it]][it]->GetLocalTimeBin();
+    }
+    
+    if (TMath::Abs(cl[best[bestiter][it]][it]->GetQ())> maxcharge4){
+      if (cl[best[bestiter][it]][it]->GetLocalTimeBin()>=4){
+       maxcharge4 = TMath::Abs(cl[best[bestiter][it]][it]->GetQ());
+       maxpos4 = cl[best[bestiter][it]][it]->GetLocalTimeBin();
+      }
+    }
+    if (TMath::Abs(cl[best[bestiter][it]][it]->GetQ())> maxcharge5){
+      if (cl[best[bestiter][it]][it]->GetLocalTimeBin()>=5){
+       maxcharge5 = TMath::Abs(cl[best[bestiter][it]][it]->GetQ());
+       maxpos5 = cl[best[bestiter][it]][it]->GetLocalTimeBin();
+      }
     }
     //
     //  time bins with maximal charge
@@ -3484,6 +4303,7 @@ Int_t AliTRDtracker::FindClusters(Int_t sector, Int_t t0, Int_t t1, AliTRDtrack
       }
     }
     clusters[it+t0] = indexes[best[bestiter][it]][it];    
+    //if (cl[best[bestiter][it]][it]->GetLocalTimeBin()>4 && cl[best[bestiter][it]][it]->GetLocalTimeBin()<18) clusters[it+t0] = indexes[best[bestiter][it]][it];    //Test
   } 
   //
   // set tracklet parameters
@@ -3509,6 +4329,10 @@ Int_t AliTRDtracker::FindClusters(Int_t sector, Int_t t0, Int_t t1, AliTRDtrack
   //
   // Debuging part
   //
+  TClonesArray array0("AliTRDcluster");
+  TClonesArray array1("AliTRDcluster");
+  array0.ExpandCreateFast(t1-t0+1);
+  array1.ExpandCreateFast(t1-t0+1);
   TTreeSRedirector& cstream = *fDebugStreamer;
   AliTRDcluster dummy;
   Double_t dy0[100];
@@ -3551,8 +4375,8 @@ Int_t AliTRDtracker::FindClusters(Int_t sector, Int_t t0, Int_t t1, AliTRDtrack
     "graph1.="<<&graph1<<                                    // x - y = dy for second closest cluster    
     "graphy.="<<&graphy<<                                    // y position of the track
     "graphz.="<<&graphz<<                                    // z position of the track
-    "fCl.="<<&array0<<                                       // closest cluster
-    "fCl2.="<<&array1<<                                      // second closest cluster
+    //    "fCl.="<<&array0<<                                       // closest cluster
+    // "fCl2.="<<&array1<<                                      // second closest cluster
     "maxpos="<<maxpos<<                                      // maximal charge postion
     "maxcharge="<<maxcharge<<                                // maximal charge 
     "maxpos4="<<maxpos4<<                                    // maximal charge postion - after bin 4
@@ -3598,3 +4422,545 @@ Int_t AliTRDtracker::FindClusters(Int_t sector, Int_t t0, Int_t t1, AliTRDtrack
 }
 
 
+Int_t  AliTRDtracker::Freq(Int_t n, const Int_t *inlist, Int_t *outlist, Bool_t down)
+{    
+  //
+  //  Sort eleements according occurancy 
+  //  The size of output array has is 2*n 
+  //
+  Int_t * sindexS = new Int_t[n];     // temp array for sorting
+  Int_t * sindexF = new Int_t[2*n];   
+  for (Int_t i=0;i<n;i++) sindexF[i]=0;
+  //
+  TMath::Sort(n,inlist, sindexS, down);  
+  Int_t last      = inlist[sindexS[0]];
+  Int_t val       = last;
+  sindexF[0]      = 1;
+  sindexF[0+n]    = last;
+  Int_t countPos  = 0;
+  //
+  //  find frequency
+  for(Int_t i=1;i<n; i++){
+    val = inlist[sindexS[i]];
+    if (last == val)   sindexF[countPos]++;
+    else{      
+      countPos++;
+      sindexF[countPos+n] = val;
+      sindexF[countPos]++;
+      last =val;
+    }
+  }
+  if (last==val) countPos++;
+  // sort according frequency
+  TMath::Sort(countPos, sindexF, sindexS, kTRUE);
+  for (Int_t i=0;i<countPos;i++){
+    outlist[2*i  ] = sindexF[sindexS[i]+n];
+    outlist[2*i+1] = sindexF[sindexS[i]];
+  }
+  delete [] sindexS;
+  delete [] sindexF;
+  
+  return countPos;
+}
+
+AliTRDtrack * AliTRDtracker::RegisterSeed(AliTRDseed * seeds, Double_t * params)
+{
+  //
+  //
+  //
+  Double_t alpha=AliTRDgeometry::GetAlpha();
+  Double_t shift=AliTRDgeometry::GetAlpha()/2.;
+  Double_t c[15];
+  c[0] = 0.2;
+  c[1] = 0  ; c[2] = 2;
+  c[3] = 0  ; c[4] = 0; c[5] = 0.02;
+  c[6] = 0  ; c[7] = 0; c[8] = 0;      c[9] = 0.1;
+  c[10] = 0  ; c[11] = 0; c[12] = 0;   c[13] = 0.0; c[14] = params[5]*params[5]*0.01;
+  //
+  Int_t index =0;
+  AliTRDcluster *cl =0;
+  for (Int_t ilayer=0;ilayer<6;ilayer++){
+    if (seeds[ilayer].isOK()){
+      for (Int_t itime=22;itime>0;itime--){
+       if (seeds[ilayer].fIndexes[itime]>0){
+         index = seeds[ilayer].fIndexes[itime];
+         cl = seeds[ilayer].fClusters[itime];
+         break;
+       }
+      }
+    }
+    if (index>0) break;
+  }
+  if (cl==0) return 0;
+  AliTRDtrack * track  = new AliTRDtrack(cl,index,&params[1],c, params[0],params[6]*alpha+shift);
+  track->PropagateTo(params[0]-5.);
+  track->ResetCovariance(1);
+  //
+  Int_t rc=FollowBackProlongationG(*track);
+  if (rc<30) {
+    delete track;
+    track =0;
+  }else{
+    track->CookdEdx();
+    CookdEdxTimBin(*track);
+    CookLabel(track, 0.9);
+  }
+  return track;
+}
+
+
+
+
+
+
+AliTRDseed::AliTRDseed()
+{
+  //
+  //  
+  fTilt =0;         // tilting angle
+  fPadLength = 0;   // pad length
+  fX0 = 0;           // x0 position
+  for (Int_t i=0;i<25;i++){
+    fX[i]=0;        // !x position
+    fY[i]=0;        // !y position
+    fZ[i]=0;        // !z position
+    fIndexes[i]=0;  // !indexes
+    fClusters[i]=0; // !clusters
+  }
+  for (Int_t i=0;i<2;i++){
+    fYref[i]=0;      // reference y
+    fZref[i]=0;      // reference z
+    fYfit[i]=0;      // y fit position +derivation
+    fYfitR[i]=0;      // y fit position +derivation
+    fZfit[i]=0;      // z fit position
+    fZfitR[i]=0;      // z fit position
+    fLabels[i]=0;    // labels
+  }
+  fSigmaY  = 0;       
+  fSigmaY2 = 0;       
+  fMeanz=0;         // mean vaue of z
+  fZProb=0;         // max probbable z
+  fMPads=0;
+  //
+  fN=0;            // number of associated clusters
+  fN2=0;            // number of not crossed
+  fNUsed=0;        // number of used clusters
+  fNChange=0;      // change z counter
+}
+
+void AliTRDseed::Reset(){
+  //
+  // reset seed
+  //
+  for (Int_t i=0;i<25;i++){
+    fX[i]=0;        // !x position
+    fY[i]=0;        // !y position
+    fZ[i]=0;        // !z position
+    fIndexes[i]=0;  // !indexes
+    fClusters[i]=0; // !clusters
+    fUsable[i]  = kFALSE;    
+  }
+  for (Int_t i=0;i<2;i++){
+    fYref[i]=0;      // reference y
+    fZref[i]=0;      // reference z
+    fYfit[i]=0;      // y fit position +derivation
+    fYfitR[i]=0;      // y fit position +derivation
+    fZfit[i]=0;      // z fit position
+    fZfitR[i]=0;      // z fit position
+    fLabels[i]=-1;    // labels
+  }
+  fSigmaY =0;         //"robust" sigma in y
+  fSigmaY2=0;         //"robust" sigma in y
+  fMeanz =0;         // mean vaue of z
+  fZProb =0;         // max probbable z
+  fMPads =0;
+  //
+  fN=0;            // number of associated clusters
+  fN2=0;            // number of not crossed
+  fNUsed=0;        // number of used clusters
+  fNChange=0;      // change z counter
+}
+
+void AliTRDseed::CookLabels(){
+  //
+  // cook 2 labels for seed
+  //
+  Int_t labels[200];
+  Int_t out[200];
+  Int_t nlab =0;
+  for (Int_t i=0;i<25;i++){
+    if (!fClusters[i]) continue;
+    for (Int_t ilab=0;ilab<3;ilab++){
+      if (fClusters[i]->GetLabel(ilab)>=0){
+       labels[nlab] = fClusters[i]->GetLabel(ilab);
+       nlab++;
+      }
+    }
+  }
+  Int_t nlab2 = AliTRDtracker::Freq(nlab,labels,out,kTRUE);
+  fLabels[0] = out[0];
+  if (nlab2>1 && out[3]>1) fLabels[1] =out[2];
+}
+
+void   AliTRDseed::UseClusters()
+{
+  //
+  // use clusters
+  //
+   for (Int_t i=0;i<25;i++){
+     if (!fClusters[i]) continue;
+     if (!(fClusters[i]->IsUsed())) fClusters[i]->Use();
+   }
+}
+
+
+void        AliTRDseed::Update(){
+  //
+  //
+  //
+  const Float_t ratio = 0.8;
+  const Int_t   kClmin        = 6;
+  const Float_t kmaxtan  = 2;
+  if (TMath::Abs(fYref[1])>kmaxtan) return;             // too much inclined track
+  //
+  Float_t  sigmaexp = 0.05+TMath::Abs(fYref[1]*0.25);   // expected r.m.s in y direction
+  Float_t  ycrosscor = fPadLength*fTilt*0.5;             // y correction for crossing 
+  fNChange =0;
+  //
+  Double_t sumw, sumwx,sumwx2;
+  Double_t sumwy, sumwxy, sumwz,sumwxz;
+  Int_t    zints[25];        // histograming of the z coordinate - get 1 and second max probable coodinates in z
+  Int_t    zouts[50];        //
+  Float_t  allowedz[25];     // allowed z for given time bin
+  Float_t  yres[25];         // residuals from reference
+  Float_t  anglecor = fTilt*fZref[1];  //correction to the angle
+  //
+  //
+  fN=0; fN2 =0;
+  for (Int_t i=0;i<25;i++){
+    yres[i] =10000;
+    if (!fClusters[i]) continue;
+    yres[i] = fY[i]-fYref[0]-(fYref[1]+anglecor)*fX[i];   // residual y
+    zints[fN] = Int_t(fZ[i]);
+    fN++;    
+  }
+  if (fN<kClmin) return;
+  Int_t nz = AliTRDtracker::Freq(fN,zints,zouts,kFALSE);
+  fZProb   = zouts[0];
+  if (nz<=1) zouts[3]=0;
+  if (zouts[1]+zouts[3]<kClmin) return;
+  //
+  if (TMath::Abs(zouts[0]-zouts[2])>12.) zouts[3]=0;   // z distance bigger than pad - length
+  //
+  Int_t  breaktime = -1;
+  Bool_t mbefore   = kFALSE;
+  Int_t  cumul[25][2];
+  Int_t  counts[2]={0,0};
+  //
+  if (zouts[3]>=3){
+    //
+    // find the break time allowing one chage on pad-rows with maximal numebr of accepted clusters
+    //
+    fNChange=1;
+    for (Int_t i=0;i<25;i++){
+      cumul[i][0] = counts[0];
+      cumul[i][1] = counts[1];
+      if (TMath::Abs(fZ[i]-zouts[0])<2) counts[0]++;
+      if (TMath::Abs(fZ[i]-zouts[2])<2) counts[1]++;
+    }
+    Int_t  maxcount  = 0;
+    for (Int_t i=0;i<24;i++) {
+      Int_t after  = cumul[24][0]-cumul[i][0];
+      Int_t before = cumul[i][1];
+      if (after+before>maxcount) { 
+       maxcount=after+before; 
+       breaktime=i;
+       mbefore=kFALSE;
+      }
+      after  = cumul[24][1]-cumul[i][1];
+      before = cumul[i][0];
+      if (after+before>maxcount) { 
+       maxcount=after+before; 
+       breaktime=i;
+       mbefore=kTRUE;
+      }
+    }
+    breaktime-=1;
+  }
+  for (Int_t i=0;i<25;i++){
+    if (i>breaktime)  allowedz[i] =   mbefore  ? zouts[2]:zouts[0];
+    if (i<=breaktime) allowedz[i] = (!mbefore) ? zouts[2]:zouts[0];
+  }  
+  if ( (allowedz[0]>allowedz[24] && fZref[1]<0) || (allowedz[0]<allowedz[24] &&  fZref[1]>0)){
+    //
+    // tracklet z-direction not in correspondance with track z direction 
+    //
+    fNChange =0;
+    for (Int_t i=0;i<25;i++){
+      allowedz[i] =  zouts[0];  //only longest taken
+    } 
+  }
+  //
+  if (fNChange>0){
+    //
+    // cross pad -row tracklet  - take the step change into account
+    //
+    for (Int_t i=0;i<25;i++){
+      if (!fClusters[i]) continue; 
+      if (TMath::Abs(fZ[i]-allowedz[i])>2) continue;
+      yres[i] = fY[i]-fYref[0]-(fYref[1]+anglecor)*fX[i];   // residual y
+      if (TMath::Abs(fZ[i]-fZProb)>2){
+       if (fZ[i]>fZProb) yres[i]+=fTilt*fPadLength;
+       if (fZ[i]<fZProb) yres[i]-=fTilt*fPadLength;
+      }
+    }
+  }
+  //
+  Double_t yres2[25];
+  Double_t mean,sigma;
+  for (Int_t i=0;i<25;i++){
+    if (!fClusters[i]) continue;
+    if (TMath::Abs(fZ[i]-allowedz[i])>2) continue;
+    yres2[fN2] =  yres[i];
+    fN2++;
+  }
+  if (fN2<kClmin){
+    fN2 = 0;
+    return;
+  }
+  EvaluateUni(fN2,yres2,mean,sigma,Int_t(fN2*ratio-2));
+  if (sigma<sigmaexp*0.8) sigma=sigmaexp;
+  fSigmaY = sigma;
+  //
+  //
+  // reset sums
+  sumw=0; sumwx=0; sumwx2=0;
+  sumwy=0; sumwxy=0; sumwz=0;sumwxz=0;
+  fN2 =0;
+  fMeanz =0;
+  fMPads =0;
+  //
+  for (Int_t i=0;i<25;i++){
+    fUsable[i]=kFALSE;
+    if (!fClusters[i]) continue;
+    if (TMath::Abs(fZ[i]-allowedz[i])>2)  continue;
+    if (TMath::Abs(yres[i]-mean)>4.*sigma) continue;
+    fUsable[i] = kTRUE;
+    fN2++;
+    fMPads+=fClusters[i]->GetNPads();
+    Float_t weight =1;
+    if (fClusters[i]->GetNPads()>4) weight=0.5;
+    if (fClusters[i]->GetNPads()>5) weight=0.2;
+    //
+    Double_t x = fX[i];
+    sumw+=weight; sumwx+=x*weight; sumwx2+=x*x*weight;
+    sumwy+=weight*yres[i];  sumwxy+=weight*(yres[i])*x;
+    sumwz+=weight*fZ[i];    sumwxz+=weight*fZ[i]*x;
+  }
+  if (fN2<kClmin){
+    fN2 = 0;
+    return;
+  }
+  fMeanz       = sumwz/sumw;
+  Float_t correction =0;
+  if (fNChange>0){
+    // tracklet on boundary
+    if (fMeanz<fZProb) correction =   ycrosscor;
+    if (fMeanz>fZProb) correction =  -ycrosscor;
+  }
+  Double_t det = sumw*sumwx2-sumwx*sumwx;
+  fYfitR[0]    = (sumwx2*sumwy-sumwx*sumwxy)/det;
+  fYfitR[1]    = (sumw*sumwxy-sumwx*sumwy)/det;
+  //
+  fSigmaY2     =0;
+  for (Int_t i=0;i<25;i++){    
+    if (!fUsable[i]) continue;
+    Float_t delta = yres[i]-fYfitR[0]-fYfitR[1]*fX[i];
+    fSigmaY2+=delta*delta;
+  }
+  fSigmaY2 = TMath::Sqrt(fSigmaY2/Float_t(fN2-2));
+  //
+  fZfitR[0]    = (sumwx2*sumwz-sumwx*sumwxz)/det;
+  fZfitR[1]    = (sumw*sumwxz-sumwx*sumwz)/det;
+  fZfit[0]     = (sumwx2*sumwz-sumwx*sumwxz)/det;
+  fZfit[1]     = (sumw*sumwxz-sumwx*sumwz)/det;
+  fYfitR[0]   += fYref[0]+correction;
+  fYfitR[1]   += fYref[1];
+  fYfit[0]     = fYfitR[0];
+  fYfit[1]     = fYfitR[1];
+  //
+  //  
+  UpdateUsed();
+}
+
+
+
+
+
+
+void AliTRDseed::UpdateUsed(){
+  //
+  fNUsed =0;
+  for (Int_t i=0;i<25;i++){
+     if (!fClusters[i]) continue;
+     if ((fClusters[i]->IsUsed())) fNUsed++;
+  }
+}
+
+
+void AliTRDseed::EvaluateUni(Int_t nvectors, Double_t *data, Double_t &mean, Double_t &sigma, Int_t hh)
+{
+  //
+  // robust estimator in 1D case MI version
+  //
+  //for the univariate case
+  //estimates of location and scatter are returned in mean and sigma parameters
+  //the algorithm works on the same principle as in multivariate case -
+  //it finds a subset of size hh with smallest sigma, and then returns mean and
+  //sigma of this subset
+
+  if (hh==0)
+    hh=(nvectors+2)/2;
+  Double_t faclts[]={2.6477,2.5092,2.3826,2.2662,2.1587,2.0589,1.9660,1.879,1.7973,1.7203,1.6473};
+  Int_t *index=new Int_t[nvectors];
+  TMath::Sort(nvectors, data, index, kFALSE);
+  //
+  Int_t    nquant = TMath::Min(Int_t(Double_t(((hh*1./nvectors)-0.5)*40))+1, 11);
+  Double_t factor = faclts[nquant-1];
+  //
+  //
+  Double_t sumx  =0;
+  Double_t sumx2 =0;
+  Int_t    bestindex = -1;
+  Double_t bestmean  = 0; 
+  Double_t bestsigma = data[index[nvectors-1]]-data[index[0]];   // maximal possible sigma
+  for (Int_t i=0; i<hh; i++){
+    sumx  += data[index[i]];
+    sumx2 += data[index[i]]*data[index[i]];
+  }
+  //
+  Double_t norm = 1./Double_t(hh);
+  Double_t norm2 = 1./Double_t(hh-1);
+  for (Int_t i=hh; i<nvectors; i++){
+    Double_t cmean  = sumx*norm;
+    Double_t csigma = (sumx2 - hh*cmean*cmean)*norm2;
+    if (csigma<bestsigma){
+      bestmean  = cmean;
+      bestsigma = csigma;
+      bestindex = i-hh;
+    }
+    //
+    //
+    sumx  += data[index[i]]-data[index[i-hh]];
+    sumx2 += data[index[i]]*data[index[i]]-data[index[i-hh]]*data[index[i-hh]];
+  }
+  
+  Double_t bstd=factor*TMath::Sqrt(TMath::Abs(bestsigma));
+  mean  = bestmean;
+  sigma = bstd;
+  delete [] index;
+}
+
+
+Float_t   AliTRDseed::FitRiemanTilt(AliTRDseed * cseed, Bool_t terror){
+  //
+  //
+  //
+  TLinearFitter fitterT2(4,"hyp4");  // fitting with tilting pads - kz not fixed
+  fitterT2.StoreData(kTRUE);
+  Float_t xref2 = (cseed[2].fX0+cseed[3].fX0)*0.5; // reference x0 for z
+  //
+  Int_t npointsT =0;
+  fitterT2.ClearPoints();
+  for (Int_t iLayer=0; iLayer<6;iLayer++){
+    if (!cseed[iLayer].isOK()) continue;
+    Double_t tilt = cseed[iLayer].fTilt;
+
+    for (Int_t itime=0;itime<25;itime++){
+      if (!cseed[iLayer].fUsable[itime]) continue;
+      Double_t x   = cseed[iLayer].fX[itime]+cseed[iLayer].fX0-xref2;  // x relative to the midle chamber
+      Double_t y   = cseed[iLayer].fY[itime];
+      Double_t z   = cseed[iLayer].fZ[itime];
+      // tilted rieman
+      //
+      Double_t uvt[6];
+      Double_t x2 = cseed[iLayer].fX[itime]+cseed[iLayer].fX0;      // global x
+      Double_t t = 1./(x2*x2+y*y);
+      uvt[1]  = t;    // t
+      uvt[0]  = 2.*x2*uvt[1];      // u 
+      uvt[2]  = 2.0*tilt*uvt[1];
+      uvt[3]  = 2.0*tilt*x*uvt[1];           
+      uvt[4]  = 2.0*(y+tilt*z)*uvt[1];
+      //
+      Double_t error = 2*uvt[1];
+      if (terror) error*=cseed[iLayer].fSigmaY;
+      else {error *=0.2;} //default error
+      fitterT2.AddPoint(uvt,uvt[4],error);
+      npointsT++;
+    }
+  }
+  fitterT2.Eval();
+  Double_t rpolz0 = fitterT2.GetParameter(3);
+  Double_t rpolz1 = fitterT2.GetParameter(4);      
+  //
+  // linear fitter  - not possible to make boundaries
+  // non accept non possible z and dzdx combination
+  //       
+  Bool_t   acceptablez =kTRUE;
+  for (Int_t iLayer=0; iLayer<6;iLayer++){
+    if (cseed[iLayer].isOK()){
+      Double_t zT2 =  rpolz0+rpolz1*(cseed[iLayer].fX0 - xref2);
+      if (TMath::Abs(cseed[iLayer].fZProb-zT2)>cseed[iLayer].fPadLength*0.5+1)
+       acceptablez = kFALSE;
+    }
+  }
+  if (!acceptablez){
+    Double_t zmf  = cseed[2].fZref[0]+cseed[2].fZref[1]*(xref2-cseed[2].fX0);
+    Double_t dzmf = (cseed[2].fZref[1]+ cseed[3].fZref[1])*0.5;
+    fitterT2.FixParameter(3,zmf);
+    fitterT2.FixParameter(4,dzmf);
+    fitterT2.Eval();
+    fitterT2.ReleaseParameter(3);
+    fitterT2.ReleaseParameter(4);
+    rpolz0 = fitterT2.GetParameter(3);
+    rpolz1 = fitterT2.GetParameter(4);
+  }
+  //
+  Double_t chi2TR = fitterT2.GetChisquare()/Float_t(npointsT);  
+  Double_t params[3];
+  params[0]     =  fitterT2.GetParameter(0);
+  params[1]     =  fitterT2.GetParameter(1);
+  params[2]     =  fitterT2.GetParameter(2);       
+  Double_t CR     =  1+params[1]*params[1]-params[2]*params[0];
+  for (Int_t iLayer = 0; iLayer<6;iLayer++){
+    Double_t  x = cseed[iLayer].fX0;
+    Double_t  y=0,dy=0, z=0, dz=0;
+    // y
+    Double_t res2 = (x*params[0]+params[1]);
+    res2*=res2;
+    res2 = 1.-params[2]*params[0]+params[1]*params[1]-res2;
+    if (res2>=0){
+      res2 = TMath::Sqrt(res2);
+      y    = (1-res2)/params[0];
+    }
+    //dy
+    Double_t x0 = -params[1]/params[0];
+    if (-params[2]*params[0]+params[1]*params[1]+1>0){
+      Double_t Rm1  = params[0]/TMath::Sqrt(-params[2]*params[0]+params[1]*params[1]+1); 
+      if ( 1./(Rm1*Rm1)-(x-x0)*(x-x0)>0){
+       Double_t res = (x-x0)/TMath::Sqrt(1./(Rm1*Rm1)-(x-x0)*(x-x0));
+       if (params[0]<0) res*=-1.;
+       dy = res;
+      }
+    }
+    z  = rpolz0+rpolz1*(x-xref2);
+    dz = rpolz1;
+    cseed[iLayer].fYref[0] = y;
+    cseed[iLayer].fYref[1] = dy;
+    cseed[iLayer].fZref[0] = z;
+    cseed[iLayer].fZref[1] = dz;
+    cseed[iLayer].fC  = CR;
+    //
+  }
+  return chi2TR;
+}
index 7537f1981a252cbf34768992cb896f5358d82ad1..7cdd31a837a70cc9b722312f15e3bdca73c9eff9 100644 (file)
@@ -26,7 +26,55 @@ const unsigned kMaxClusterPerTimeBin = 7000;
 const unsigned kZones = 5; 
 const Int_t    kTrackingSectors = 18; 
 
-
+class AliTRDseed : public TObject{
+  friend class AliTRDtracker;
+ public:
+  AliTRDseed();                 // default constructor
+  ~AliTRDseed(){};              // default constructor
+  static  void EvaluateUni(Int_t nvectors, Double_t *data, Double_t &mean, Double_t &sigma, Int_t hh);
+  static  Float_t   FitRiemanTilt(AliTRDseed * seed, Bool_t error);
+  void           UseClusters(); // use clusters
+  void           Update();      // update information - without tilt correction
+  void           CookLabels();  // cook label
+  void           UpdateUsed();
+  void           Reset();       // reset seed
+  Bool_t         isOK(){return fN2>8;}
+ private:
+  Float_t        fTilt;         // tilting angle
+  Float_t        fPadLength;    // pad length
+  Float_t        fX0;           // x0 position
+  Float_t        fX[25];        // !x position
+  Float_t        fY[25];        // !y position
+  Float_t        fZ[25];        // !z position
+  Int_t          fIndexes[25];  // !indexes
+  AliTRDcluster *fClusters[25]; // !clusters
+  Bool_t         fUsable[25];   // !indication  - usable cluster
+  Float_t        fYref[2];      // reference y
+  Float_t        fZref[2];      // reference z
+  Float_t        fYfit[2];      // y fit position +derivation
+  Float_t        fYfitR[2];      // y fit position +derivation
+  Float_t        fZfit[2];      // z fit position
+  Float_t        fZfitR[2];      // z fit position
+  Float_t        fSigmaY;        // "robust" sigma in Y - constant fit
+  Float_t        fSigmaY2;       // "robust" sigma in Y - line fit
+  Float_t        fMeanz;         // mean vaue of z
+  Float_t        fZProb;         // max probbable z
+  Int_t          fLabels[2];    // labels
+  Int_t          fN;            // number of associated clusters
+  Int_t          fN2;            // number of not crossed
+  Int_t          fNUsed;        // number of used clusters
+  Int_t          fFreq;         // freq
+  Int_t          fNChange;      // change z counter
+  Float_t        fMPads;        // mean number of pads per cluster
+  // global
+  //
+  Float_t        fC;            // curvature
+  Float_t        fCC;           // curvature with constrain
+  Float_t        fChi2;         // global chi2
+  Float_t        fChi2Z;        // global chi2
+ private:
+  ClassDef(AliTRDseed,1)  
+};
 
 
 class AliTRDtracker : public AliTracker { 
@@ -37,7 +85,7 @@ class AliTRDtracker : public AliTracker {
   AliTRDtracker();
   AliTRDtracker(const TFile *in);
   virtual ~AliTRDtracker(); 
-
+  static        Int_t  Freq(Int_t n, const Int_t *inlist, Int_t *outlist, Bool_t down);    
   Int_t         Clusters2Tracks(AliESD* event);
   Int_t         PropagateBack(AliESD* event);
   Int_t         RefitInward(AliESD* event);
@@ -111,8 +159,8 @@ class AliTRDtracker : public AliTracker {
                                 Double_t &dx, Double_t &rho, Double_t &x0, 
                                             Bool_t &lookForCluster) const;
      Int_t          GetZone( Double_t z) const;
-     Int_t          Find(Double_t y) const; 
-     Int_t          FindNearestCluster(Double_t y, Double_t z, Double_t maxroad) const;
+     Int_t          Find(Float_t y) const; 
+     Int_t          FindNearestCluster(Float_t y, Float_t z, Float_t maxroad, Float_t maxroad) const;
      void           SetZmax(Int_t cham, Double_t center, Double_t w)
                       { fZc[cham] = center;  fZmax[cham] = w; }
      void           SetZ(Double_t* center, Double_t *w, Double_t *wsensitive);
@@ -263,9 +311,9 @@ class AliTRDtracker : public AliTracker {
   static const Int_t fgkLastPlane;    // Id of the last (outermost) reference plane
 
  private:
-
+  AliTRDtrack *   RegisterSeed(AliTRDseed * seeds, Double_t *params);
   virtual void  MakeSeeds(Int_t inner, Int_t outer, Int_t turn);
-  void  MakeSeedsMI(Int_t inner, Int_t outer);
+  void  MakeSeedsMI(Int_t inner, Int_t outer, AliESD *esd=0);
 
   Int_t         FollowProlongation(AliTRDtrack& t, Int_t rf);
   Int_t         FollowProlongationG(AliTRDtrack& t, Int_t rf);