]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TRD/AliTRDtrackerV1.cxx
skip the calculation in AliTRDCluster::GetYloc for HLT
[u/mrichter/AliRoot.git] / TRD / AliTRDtrackerV1.cxx
index e905b45a3751570036c4f8bbe06362ac81a7925d..e5e32081c0ec38a6ead0ac8d1daee6912d010aee 100644 (file)
 //                                                                           //
 ///////////////////////////////////////////////////////////////////////////////
 
-// #include <Riostream.h>
-// #include <stdio.h>
-// #include <string.h>
-
 #include <TBranch.h>
 #include <TDirectory.h>
 #include <TLinearFitter.h>
@@ -53,6 +49,7 @@
 #include "AliTRDrecoParam.h"
 
 #include "AliTRDcluster.h" 
+#include "AliTRDdigitsParam.h"
 #include "AliTRDseedV1.h"
 #include "AliTRDtrackV1.h"
 #include "AliTRDtrackerV1.h"
 #include "AliTRDtrackingChamber.h"
 #include "AliTRDchamberTimeBin.h"
 
-
-
 ClassImp(AliTRDtrackerV1)
-
+ClassImp(AliTRDtrackerV1::AliTRDLeastSquare)
+ClassImp(AliTRDtrackerV1::AliTRDtrackFitterRieman)
 
 const  Float_t  AliTRDtrackerV1::fgkMinClustersInTrack =  0.5;  //
 const  Float_t  AliTRDtrackerV1::fgkLabelFraction      =  0.8;  //
@@ -71,23 +67,25 @@ const  Double_t AliTRDtrackerV1::fgkMaxChi2            = 12.0;  //
 const  Double_t AliTRDtrackerV1::fgkMaxSnp             =  0.95; // Maximum local sine of the azimuthal angle
 const  Double_t AliTRDtrackerV1::fgkMaxStep            =  2.0;  // Maximal step size in propagation 
 Double_t AliTRDtrackerV1::fgTopologicQA[kNConfigs] = {
-  0.1112, 0.1112, 0.1112, 0.0786, 0.0786,
+  0.5112, 0.5112, 0.5112, 0.0786, 0.0786,
   0.0786, 0.0786, 0.0579, 0.0579, 0.0474,
   0.0474, 0.0408, 0.0335, 0.0335, 0.0335
-};
+};  
+const Double_t AliTRDtrackerV1::fgkX0[kNPlanes]    = {
+  300.2, 312.8, 325.4, 338.0, 350.6, 363.2};
 Int_t AliTRDtrackerV1::fgNTimeBins = 0;
-AliRieman* AliTRDtrackerV1::fgRieman = 0x0;
-TLinearFitter* AliTRDtrackerV1::fgTiltedRieman = 0x0;
-TLinearFitter* AliTRDtrackerV1::fgTiltedRiemanConstrained = 0x0;
+AliRieman* AliTRDtrackerV1::fgRieman = NULL;
+TLinearFitter* AliTRDtrackerV1::fgTiltedRieman = NULL;
+TLinearFitter* AliTRDtrackerV1::fgTiltedRiemanConstrained = NULL;
 
 //____________________________________________________________________
 AliTRDtrackerV1::AliTRDtrackerV1(AliTRDReconstructor *rec) 
   :AliTracker()
-  ,fReconstructor(0x0)
-  ,fGeom(0x0)
-  ,fClusters(0x0)
-  ,fTracklets(0x0)
-  ,fTracks(0x0)
+  ,fkReconstructor(NULL)
+  ,fGeom(NULL)
+  ,fClusters(NULL)
+  ,fTracklets(NULL)
+  ,fTracks(NULL)
   ,fSieveSeeding(0)
 {
   //
@@ -102,25 +100,21 @@ AliTRDtrackerV1::AliTRDtrackerV1(AliTRDReconstructor *rec)
   }
   fGeom = new AliTRDgeometry();
   fGeom->CreateClusterMatrixArray();
-  TGeoHMatrix *matrix = 0x0;
+  TGeoHMatrix *matrix = NULL;
   Double_t loc[] = {0., 0., 0.};
   Double_t glb[] = {0., 0., 0.};
   for(Int_t ily=kNPlanes; ily--;){
-    if(!(matrix = fGeom->GetClusterMatrix(AliTRDgeometry::GetDetector(ily, 2, 0)))){
-      AliFatal(Form("Could not get matrix for chamber @ 0 2 %d.", ily));
+    Int_t ism = 0;
+    while(!(matrix = fGeom->GetClusterMatrix(AliTRDgeometry::GetDetector(ily, 2, ism)))) ism++;
+    if(!matrix){
+      AliError(Form("Could not get transformation matrix for layer %d. Use default.", ily));
+      fR[ily] = fgkX0[ily];
       continue;
     }
     matrix->LocalToMaster(loc, glb);
     fR[ily] = glb[0]+ AliTRDgeometry::AnodePos()-.5*AliTRDgeometry::AmThick() - AliTRDgeometry::DrThick();
   }
 
-  // initialize calibration values
-  AliTRDcalibDB *trd = 0x0;
-  if (!(trd = AliTRDcalibDB::Instance())) {
-    AliFatal("Could not get calibration.");
-  }
-  if(!fgNTimeBins) fgNTimeBins = trd->GetNumberOfTimeBins();
-
   // initialize cluster containers
   for (Int_t isector = 0; isector < AliTRDgeometry::kNsector; isector++) new(&fTrSec[isector]) AliTRDtrackingSector(fGeom, isector);
   
@@ -137,9 +131,9 @@ AliTRDtrackerV1::~AliTRDtrackerV1()
   // Destructor
   //
   
-  if(fgRieman) delete fgRieman; fgRieman = 0x0;
-  if(fgTiltedRieman) delete fgTiltedRieman; fgTiltedRieman = 0x0;
-  if(fgTiltedRiemanConstrained) delete fgTiltedRiemanConstrained; fgTiltedRiemanConstrained = 0x0;
+  if(fgRieman) delete fgRieman; fgRieman = NULL;
+  if(fgTiltedRieman) delete fgTiltedRieman; fgTiltedRieman = NULL;
+  if(fgTiltedRiemanConstrained) delete fgTiltedRiemanConstrained; fgTiltedRiemanConstrained = NULL;
   for(Int_t isl =0; isl<kNSeedPlanes; isl++) if(fSeedTB[isl]) delete fSeedTB[isl];
   if(fTracks) {fTracks->Delete(); delete fTracks;}
   if(fTracklets) {fTracklets->Delete(); delete fTracklets;}
@@ -167,7 +161,7 @@ Int_t AliTRDtrackerV1::Clusters2Tracks(AliESDEvent *esd)
   //    See AliTRDtrackerV1::Clusters2TracksSM() for details.
   //
 
-  if(!fReconstructor->GetRecoParam() ){
+  if(!fkReconstructor->GetRecoParam() ){
     AliError("Reconstruction configuration not initialized. Call first AliTRDReconstructor::SetRecoParam().");
     return 0;
   }
@@ -179,7 +173,7 @@ Int_t AliTRDtrackerV1::Clusters2Tracks(AliESDEvent *esd)
     //AliInfo(Form("Processing supermodule %i ...", ism));
     ntracks += Clusters2TracksSM(ism, esd);
   }
-  AliInfo(Form("Number of found tracks : %d", ntracks));
+  AliInfo(Form("Number of tracks: !TRDin[%d]", ntracks));
   return ntracks;
 }
 
@@ -195,40 +189,32 @@ Bool_t AliTRDtrackerV1::GetTrackPoint(Int_t index, AliTrackPoint &p) const
   if (!tracklet) return kFALSE;
 
   // get detector for this tracklet
-  Int_t  idet     = tracklet->GetDetector();
-    
+  Int_t det = tracklet->GetDetector();
+  Int_t sec = fGeom->GetSector(det);
+  Double_t alpha = (sec+.5)*AliTRDgeometry::GetAlpha(),
+           sinA  = TMath::Sin(alpha),
+           cosA  = TMath::Cos(alpha);
   Double_t local[3];
-  local[0] = tracklet->GetX0(); 
-  local[1] = tracklet->GetYfit(0);
-  local[2] = tracklet->GetZfit(0);
+  local[0] = tracklet->GetX(); 
+  local[1] = tracklet->GetY();
+  local[2] = tracklet->GetZ();
   Double_t global[3];
-  fGeom->RotateBack(idet, local, global);
-  p.SetXYZ(global[0],global[1],global[2]);
-  
+  fGeom->RotateBack(det, local, global);
+
+  Double_t cov2D[3]; Float_t cov[6];
+  tracklet->GetCovAt(local[0], cov2D);
+  cov[0] = cov2D[0]*sinA*sinA;
+  cov[1] =-cov2D[0]*sinA*cosA;
+  cov[2] =-cov2D[1]*sinA;
+  cov[3] = cov2D[0]*cosA*cosA;
+  cov[4] = cov2D[1]*cosA;
+  cov[5] = cov2D[2];
+  // store the global position of the tracklet and its covariance matrix in the track point 
+  p.SetXYZ(global[0],global[1],global[2], cov);
   
   // setting volume id
-  AliGeomManager::ELayerID iLayer = AliGeomManager::kTRD1;
-  switch (fGeom->GetLayer(idet)) {
-  case 0:
-    iLayer = AliGeomManager::kTRD1;
-    break;
-  case 1:
-    iLayer = AliGeomManager::kTRD2;
-    break;
-  case 2:
-    iLayer = AliGeomManager::kTRD3;
-    break;
-  case 3:
-    iLayer = AliGeomManager::kTRD4;
-    break;
-  case 4:
-    iLayer = AliGeomManager::kTRD5;
-    break;
-  case 5:
-    iLayer = AliGeomManager::kTRD6;
-    break;
-  };
-  Int_t    modId = fGeom->GetSector(idet) * fGeom->Nstack() + fGeom->GetStack(idet);
+  AliGeomManager::ELayerID iLayer = AliGeomManager::ELayerID(AliGeomManager::kTRD1+fGeom->GetLayer(det));
+  Int_t    modId = fGeom->GetSector(det) * AliTRDgeometry::kNstack + fGeom->GetStack(det);
   UShort_t volid = AliGeomManager::LayerToVolUID(iLayer, modId);
   p.SetVolumeID(volid);
     
@@ -259,19 +245,30 @@ AliRieman* AliTRDtrackerV1::GetRiemanFitter()
 //_____________________________________________________________________________
 Int_t AliTRDtrackerV1::PropagateBack(AliESDEvent *event) 
 {
-  //
-  // Gets seeds from ESD event. The seeds are AliTPCtrack's found and
-  // backpropagated by the TPC tracker. Each seed is first propagated 
-  // to the TRD, and then its prolongation is searched in the TRD.
-  // If sufficiently long continuation of the track is found in the TRD
-  // the track is updated, otherwise it's stored as originaly defined 
-  // by the TPC tracker.   
-  //  
-
-  // Calibration monitor
-  AliTRDCalibraFillHisto *calibra = AliTRDCalibraFillHisto::Instance();
+// Propagation of ESD tracks from TPC to TOF detectors and building of the TRD track. For building
+// a TRD track an ESD track is used as seed. The informations obtained on the TRD track (measured points,
+// covariance, PID, etc.) are than used to update the corresponding ESD track.
+// Each track seed is first propagated to the geometrical limit of the TRD detector. 
+// Its prolongation is searched in the TRD and if corresponding clusters are found tracklets are 
+// constructed out of them (see AliTRDseedV1::AttachClusters()) and the track is updated. 
+// Otherwise the ESD track is left unchanged.
+// 
+// The following steps are performed:
+// 1. Selection of tracks based on the variance in the y-z plane.
+// 2. Propagation to the geometrical limit of the TRD volume. If track propagation fails the AliESDtrack::kTRDStop is set.
+// 3. Prolongation inside the fiducial volume (see AliTRDtrackerV1::FollowBackProlongation()) and marking
+// the following status bits:
+//   - AliESDtrack::kTRDin - if the tracks enters the TRD fiducial volume
+//   - AliESDtrack::kTRDStop - if the tracks fails propagation
+//   - AliESDtrack::kTRDbackup - if the tracks fulfills chi2 conditions and qualify for refitting
+// 4. Writting to friends, PID, MC label, quality etc. Setting status bit AliESDtrack::kTRDout.
+// 5. Propagation to TOF. If track propagation fails the AliESDtrack::kTRDStop is set.
+//  
+
+  AliTRDCalibraFillHisto *calibra = AliTRDCalibraFillHisto::Instance(); // Calibration monitor
   if (!calibra) AliInfo("Could not get Calibra instance\n");
-  
+  if(!fgNTimeBins) CookNTimeBins();
+
   // Define scalers
   Int_t nFound   = 0, // number of tracks found
         nSeeds   = 0, // total number of ESD seeds
@@ -279,8 +276,8 @@ Int_t AliTRDtrackerV1::PropagateBack(AliESDEvent *event)
         nTPCseeds= 0; // number of TPC seeds
   Float_t foundMin = 20.0;
   
-  Float_t *quality = 0x0;
-  Int_t   *index   = 0x0;
+  Float_t *quality = NULL;
+  Int_t   *index   = NULL;
   nSeeds   = event->GetNumberOfTracks();
   // Sort tracks according to quality 
   // (covariance in the yz plane)
@@ -331,7 +328,7 @@ Int_t AliTRDtrackerV1::PropagateBack(AliESDEvent *event)
     seed->UpdateTrackParams(&track, AliESDtrack::kTRDbackup);
 
     // prepare track and do propagation in the TRD
-    track.SetReconstructor(fReconstructor);
+    track.SetReconstructor(fkReconstructor);
     track.SetKink(Bool_t(seed->GetKinkIndex(0)));
     expectedClr = FollowBackProlongation(track);
     // check if track entered the TRD fiducial volume
@@ -352,7 +349,7 @@ Int_t AliTRDtrackerV1::PropagateBack(AliESDEvent *event)
       // update calibration references using this track
       if(calibra->GetHisto2d()) calibra->UpdateHistogramsV1(&track);
       // save calibration object
-      if (fReconstructor->GetStreamLevel(AliTRDReconstructor::kTracker) > 0){ 
+      if (fkReconstructor->GetRecoParam()->GetStreamLevel(AliTRDrecoParam::kTracker) > 0){ 
         AliTRDtrackV1 *calibTrack = new AliTRDtrackV1(track);
         calibTrack->SetOwner();
         seed->AddCalibObject(calibTrack);
@@ -415,7 +412,7 @@ Int_t AliTRDtrackerV1::PropagateBack(AliESDEvent *event)
       //(with the help of Annalisa de Caro Mar-17-2009)
       if(gGeoManager){
         gGeoManager->cd(Form("/ALIC_1/B077_1/BSEGMO%d_1/BTOF%d_1", sm, sm));
-        TGeoHMatrix *m = 0x0;
+        TGeoHMatrix *m = NULL;
         Double_t loc[]={0., 0., -.5*29.05}, glob[3];
         
         if((m=gGeoManager->GetCurrentMatrix())){
@@ -443,13 +440,12 @@ Int_t AliTRDtrackerV1::PropagateBack(AliESDEvent *event)
   }
   if(index) delete [] index;
   if(quality) delete [] quality;
-  
 
-  AliInfo(Form("Number of TPC seeds: %d (%d)", nTRDseeds, nTPCseeds));
-  AliInfo(Form("Number of propagated TRD tracks: %d", nFound));
-      
+  AliInfo(Form("Number of seeds: TPCout[%d] TRDin[%d]", nTPCseeds, nTRDseeds));
+  AliInfo(Form("Number of tracks: TRDout[%d]", nFound));
+
   // run stand alone tracking
-  if (fReconstructor->IsSeeding()) Clusters2Tracks(event);
+  if (fkReconstructor->IsSeeding()) Clusters2Tracks(event);
   
   return 0;
 }
@@ -501,9 +497,9 @@ Int_t AliTRDtrackerV1::RefitInward(AliESDEvent *event)
       }
 
       // Update the friend track
-      if (fReconstructor->GetStreamLevel(AliTRDReconstructor::kTracker) > 0){ 
-        TObject *o = 0x0; Int_t ic = 0;
-        AliTRDtrackV1 *calibTrack = 0x0
+      if (fkReconstructor->GetRecoParam()->GetStreamLevel(AliTRDrecoParam::kTracker) > 0){ 
+        TObject *o = NULL; Int_t ic = 0;
+        AliTRDtrackV1 *calibTrack = NULL
         while((o = seed->GetCalibObject(ic++))){
           if(!(calibTrack = dynamic_cast<AliTRDtrackV1*>(o))) continue;
           calibTrack->SetTrackHigh(track.GetTrackHigh());
@@ -517,8 +513,8 @@ Int_t AliTRDtrackerV1::RefitInward(AliESDEvent *event)
       if (PropagateToX(tt, xTPC, fgkMaxStep)) seed->UpdateTrackParams(&tt, AliESDtrack::kTRDbackup);
     }
   }
-  AliInfo(Form("Number of loaded seeds: %d",nseed));
-  AliInfo(Form("Number of found tracks from loaded seeds: %d",found));
+  AliInfo(Form("Number of seeds: TRDout[%d]", nseed));
+  AliInfo(Form("Number of tracks: TRDrefit[%d]", found));
   
   return 0;
 }
@@ -553,11 +549,14 @@ Int_t AliTRDtrackerV1::FollowProlongation(AliTRDtrackV1 &t)
   Bool_t kStoreIn = kTRUE;
   Int_t    nClustersExpected = 0;
   for (Int_t iplane = kNPlanes; iplane--;) {
-    Int_t   index   = 0;
+    Int_t   index(-1);
     AliTRDseedV1 *tracklet = GetTracklet(&t, iplane, index);
+    AliDebug(2, Form("Tracklet[%p] ly[%d] idx[%d]", (void*)tracklet, iplane, index));
     if(!tracklet) continue;
-    if(!tracklet->IsOK()) AliWarning("tracklet not OK");
-    
+    if(!tracklet->IsOK()){ 
+      AliDebug(1, Form("Tracklet Det[%d] !OK", tracklet->GetDetector()));
+      continue;
+    }
     Double_t x  = tracklet->GetX();//GetX0();
     // reject tracklets which are not considered for inward refit
     if(x > t.GetX()+fgkMaxStep) continue;
@@ -601,13 +600,15 @@ Int_t AliTRDtrackerV1::FollowProlongation(AliTRDtrackV1 &t)
       kStoreIn = kFALSE;
     }
 
-    Double_t maxChi2 = t.GetPredictedChi2(tracklet);
-    if (maxChi2 < 1e+10 && t.Update(tracklet, maxChi2)){ 
+    Double_t cov[3]; tracklet->GetCovAt(x, cov);
+    Double_t p[2] = { tracklet->GetY(), tracklet->GetZ()};
+    Double_t chi2 = ((AliExternalTrackParam)t).GetPredictedChi2(p, cov);
+    if (chi2 < 1e+10 && t.Update(p, cov, chi2)){ 
       nClustersExpected += tracklet->GetN();
     }
   }
 
-  if(fReconstructor->GetStreamLevel(AliTRDReconstructor::kTracker) > 1){
+  if(fkReconstructor->GetRecoParam()->GetStreamLevel(AliTRDrecoParam::kTracker) > 1){
     Int_t index;
     for(int iplane=0; iplane<AliTRDgeometry::kNlayer; iplane++){
       AliTRDseedV1 *tracklet = GetTracklet(&t, iplane, index);
@@ -615,17 +616,18 @@ Int_t AliTRDtrackerV1::FollowProlongation(AliTRDtrackV1 &t)
       t.SetTracklet(tracklet, index);
     }
 
-    Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
-    TTreeSRedirector &cstreamer = *fReconstructor->GetDebugStream(AliTRDReconstructor::kTracker);
-    AliTRDtrackV1 track(t);
-    track.SetOwner();
-    cstreamer << "FollowProlongation"
-        << "EventNumber="      << eventNumber
-        << "ncl="                                      << nClustersExpected
-        << "track.="                   << &track
-        << "\n";
+    if(fkReconstructor->IsDebugStreaming()){
+      Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
+      TTreeSRedirector &cstreamer = *fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
+      AliTRDtrackV1 track(t);
+      track.SetOwner();
+      cstreamer << "FollowProlongation"
+          << "EventNumber="    << eventNumber
+          << "ncl="                                    << nClustersExpected
+          << "track.="                 << &track
+          << "\n";
+    }
   }
-
   return nClustersExpected;
 
 }
@@ -633,35 +635,53 @@ Int_t AliTRDtrackerV1::FollowProlongation(AliTRDtrackV1 &t)
 //_____________________________________________________________________________
 Int_t AliTRDtrackerV1::FollowBackProlongation(AliTRDtrackV1 &t)
 {
-  // Extrapolates the TRD track in the TOF direction.
-  //
-  // Parameters
-  //   t : the TRD track which has to be extrapolated
-  // 
-  // Output
-  //   number of clusters attached to the track
-  //
-  // Detailed description
-  //
-  // Starting from current radial position of track <t> this function
-  // extrapolates the track through the 6 TRD layers. The following steps
-  // are being performed for each plane:
-  // 1. prepare track:
-  //   a. get plane limits in the local x direction
-  //   b. check crossing sectors 
-  //   c. check track inclination
-  // 2. build tracklet (see AliTRDseed::AttachClusters() for details)
-  // 3. evaluate material budget using the geo manager
-  // 4. propagate and update track using the tracklet information.
-  //
-  // Debug level 2
-  //
+// Extrapolates/Build the TRD track in the TOF direction.
+//
+// Parameters
+//   t : the TRD track which has to be extrapolated
+// 
+// Output
+//   number of clusters attached to the track
+//
+// Starting from current radial position of track <t> this function
+// extrapolates the track through the 6 TRD layers. The following steps
+// are being performed for each plane:
+// 1. Propagate track to the entrance of the next chamber:
+//   - get chamber limits in the radial direction
+//   - check crossing sectors 
+//   - check track inclination
+//   - check track prolongation against boundary conditions (see exclusion boundaries on AliTRDgeometry::IsOnBoundary())
+// 2. Build tracklet (see AliTRDseed::AttachClusters() for details) for this layer if needed. If only 
+//    Kalman filter is needed and tracklets are already linked to the track this step is skipped.
+// 3. Fit tracklet using the information from the Kalman filter.
+// 4. Propagate and update track at reference radial position of the tracklet.
+// 5. Register tracklet with the tracker and track; update pulls monitoring.
+//
+// Observation
+//   1. During the propagation a bit map is filled detailing the status of the track in each TRD chamber. The following errors are being registered for each tracklet:
+// - AliTRDtrackV1::kProlongation : track prolongation failed
+// - AliTRDtrackV1::kPropagation : track prolongation failed
+// - AliTRDtrackV1::kAdjustSector : failed during sector crossing
+// - AliTRDtrackV1::kSnp : too large bending
+// - AliTRDtrackV1::kTrackletInit : fail to initialize tracklet
+// - AliTRDtrackV1::kUpdate : fail to attach clusters or fit the tracklet
+// - AliTRDtrackV1::kUnknown : anything which is not covered before
+//   2. By default the status of the track before first TRD update is saved. 
+// 
+// Debug level 2
+//
+// Author
+//   Alexandru Bercuci <A.Bercuci@gsi.de>
+//
 
   Int_t n = 0;
   Double_t driftLength = .5*AliTRDgeometry::AmThick() + AliTRDgeometry::DrThick();
-  AliTRDtrackingChamber *chamber = 0x0;
+  AliTRDtrackingChamber *chamber = NULL;
   
-  AliTRDseedV1 tracklet, *ptrTracklet = 0x0;
+  Int_t debugLevel = fkReconstructor->IsDebugStreaming() ? fkReconstructor->GetRecoParam()->GetStreamLevel(AliTRDrecoParam::kTracker) : 0;
+  TTreeSRedirector *cstreamer = fkReconstructor->IsDebugStreaming() ? fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker) : 0x0;
+
+  AliTRDseedV1 tracklet, *ptrTracklet = NULL;
   // in case of stand alone tracking we store all the pointers to the tracklets in a temporary array
   AliTRDseedV1 *tracklets[kNPlanes];
   memset(tracklets, 0, sizeof(AliTRDseedV1 *) * kNPlanes);
@@ -669,16 +689,19 @@ Int_t AliTRDtrackerV1::FollowBackProlongation(AliTRDtrackV1 &t)
     tracklets[ip] = t.GetTracklet(ip);
     t.UnsetTracklet(ip);
   } 
-  Bool_t kStoreIn = kTRUE;
+  Bool_t kStoreIn = kTRUE, kPropagateIn = kTRUE;
 
   // Loop through the TRD layers
-  TGeoHMatrix *matrix = 0x0;
+  TGeoHMatrix *matrix = NULL;
   Double_t x, y, z;
   for (Int_t ily=0, sm=-1, stk=-1, det=-1; ily < AliTRDgeometry::kNlayer; ily++) {
+    AliDebug(2, Form("Propagate to x[%d] = %7.2f", ily, fR[ily]));
+
     // rough estimate of the entry point
     if (!t.GetProlongation(fR[ily], y, z)){
       n=-1; 
       t.SetStatus(AliTRDtrackV1::kProlongation);
+      AliDebug(4, Form("Failed Rough Prolongation to ly[%d] x[%7.2f] y[%7.2f] z[%7.2f]", ily, fR[ily], y, z));
       break;
     }
 
@@ -687,27 +710,32 @@ Int_t AliTRDtrackerV1::FollowBackProlongation(AliTRDtrackV1 &t)
     // TODO cross check with y value !
     stk = fGeom->GetStack(z, ily);
     det = stk>=0 ? AliTRDgeometry::GetDetector(ily, stk, sm) : -1;
-    matrix = det>=0 ? fGeom->GetClusterMatrix(det) : 0x0;
+    matrix = det>=0 ? fGeom->GetClusterMatrix(det) : NULL;
+    AliDebug(3, Form("Propagate to det[%3d]", det));
 
     // check if supermodule/chamber is installed
     if( !fGeom->GetSMstatus(sm) ||
         stk<0. ||
         fGeom->IsHole(ily, stk, sm) ||
         !matrix ){ 
+      AliDebug(4, Form("Missing Geometry ly[%d]. Guess radial position", ily));
       // propagate to the default radial position
       if(fR[ily] > (fgkMaxStep + t.GetX()) && !PropagateToX(t, fR[ily], fgkMaxStep)){
         n=-1; 
         t.SetStatus(AliTRDtrackV1::kPropagation);
+        AliDebug(4, "Failed Propagation [Missing Geometry]");
         break;
       }
       if(!AdjustSector(&t)){
         n=-1; 
         t.SetStatus(AliTRDtrackV1::kAdjustSector);
+        AliDebug(4, "Failed Adjust Sector [Missing Geometry]");
         break;
       }
       if(TMath::Abs(t.GetSnp()) > fgkMaxSnp){
         n=-1; 
         t.SetStatus(AliTRDtrackV1::kSnp);
+        AliDebug(4, "Failed Max Snp [Missing Geometry]");
         break;
       }
       t.SetStatus(AliTRDtrackV1::kGeometry, ily);
@@ -724,31 +752,35 @@ Int_t AliTRDtrackerV1::FollowBackProlongation(AliTRDtrackV1 &t)
     if(x > (fgkMaxStep + t.GetX()) && !PropagateToX(t, x, fgkMaxStep)){
       n=-1; 
       t.SetStatus(AliTRDtrackV1::kPropagation);
+      AliDebug(4, Form("Failed Initial Propagation to x[%7.2f]", x));
       break;
     }
     if(!AdjustSector(&t)){
       n=-1; 
       t.SetStatus(AliTRDtrackV1::kAdjustSector);
+      AliDebug(4, "Failed Adjust Sector Start");
       break;
     }
     if(TMath::Abs(t.GetSnp()) > fgkMaxSnp) {
       n=-1; 
       t.SetStatus(AliTRDtrackV1::kSnp);
+      AliDebug(4, Form("Failed Max Snp[%f] MaxSnp[%f]", t.GetSnp(), fgkMaxSnp));
       break;
     }
-    Bool_t RECALCULATE = kFALSE;
+    Bool_t doRecalculate = kFALSE;
     if(sm != t.GetSector()){
       sm = t.GetSector(); 
-      RECALCULATE = kTRUE;
+      doRecalculate = kTRUE;
     }
     if(stk != fGeom->GetStack(z, ily)){
       stk = fGeom->GetStack(z, ily);
-      RECALCULATE = kTRUE;
+      doRecalculate = kTRUE;
     }
-    if(RECALCULATE){
+    if(doRecalculate){
       det = AliTRDgeometry::GetDetector(ily, stk, sm);
       if(!(matrix = fGeom->GetClusterMatrix(det))){ 
         t.SetStatus(AliTRDtrackV1::kGeometry, ily);
+        AliDebug(4, Form("Failed Geometry Matrix ly[%d]", ily));
         continue;
       }
       matrix->LocalToMaster(loc, glb);
@@ -759,10 +791,12 @@ Int_t AliTRDtrackerV1::FollowBackProlongation(AliTRDtrackV1 &t)
     if (!t.GetProlongation(x+fgkMaxStep, y, z)) {
       n=-1; 
       t.SetStatus(AliTRDtrackV1::kProlongation);
+      AliDebug(4, Form("Failed Prolongation to x[%7.2f] y[%7.2f] z[%7.2f]", x+fgkMaxStep, y, z));
       break;
     }
     if(fGeom->IsOnBoundary(det, y, z, .5)){ 
       t.SetStatus(AliTRDtrackV1::kBoundary, ily);
+      AliDebug(4, "Failed Track on Boundary");
       continue;
     }
     // mark track as entering the FIDUCIAL volume of TRD
@@ -773,88 +807,150 @@ Int_t AliTRDtrackerV1::FollowBackProlongation(AliTRDtrackV1 &t)
 
     ptrTracklet  = tracklets[ily];
     if(!ptrTracklet){ // BUILD TRACKLET
+      AliDebug(3, Form("Building tracklet det[%d]", det));
       // check data in supermodule
       if(!fTrSec[sm].GetNChambers()){ 
         t.SetStatus(AliTRDtrackV1::kNoClusters, ily);
+        AliDebug(4, "Failed NoClusters");
         continue;
       }
       if(fTrSec[sm].GetX(ily) < 1.){ 
         t.SetStatus(AliTRDtrackV1::kNoClusters, ily);
+        AliDebug(4, "Failed NoX");
         continue;
       }
       
       // check data in chamber
       if(!(chamber = fTrSec[sm].GetChamber(stk, ily))){ 
         t.SetStatus(AliTRDtrackV1::kNoClusters, ily);
+        AliDebug(4, "Failed No Detector");
         continue;
       }
-      if(chamber->GetNClusters() < fgNTimeBins*fReconstructor->GetRecoParam() ->GetFindableClusters()){ 
+      if(chamber->GetNClusters() < fgNTimeBins*fkReconstructor->GetRecoParam() ->GetFindableClusters()){ 
         t.SetStatus(AliTRDtrackV1::kNoClusters, ily);
+        AliDebug(4, "Failed Not Enough Clusters in Detector");
         continue;
       }      
       // build tracklet
       ptrTracklet = new(&tracklet) AliTRDseedV1(det);
-      ptrTracklet->SetReconstructor(fReconstructor);
+      ptrTracklet->SetReconstructor(fkReconstructor);
       ptrTracklet->SetKink(t.IsKink());
       ptrTracklet->SetPadPlane(fGeom->GetPadPlane(ily, stk));
       ptrTracklet->SetX0(glb[0]+driftLength);
       if(!tracklet.Init(&t)){
         n=-1; 
         t.SetStatus(AliTRDtrackV1::kTrackletInit);
+        AliDebug(4, "Failed Tracklet Init");
         break;
       }
       if(!tracklet.AttachClusters(chamber, kTRUE)){   
         t.SetStatus(AliTRDtrackV1::kNoAttach, ily);
+        if(debugLevel>3){
+          AliTRDseedV1 trackletCp(*ptrTracklet);
+          UChar_t status(t.GetStatusTRD(ily));
+          (*cstreamer)   << "FollowBackProlongation2"
+          <<"status="    << status
+          <<"tracklet.=" << &trackletCp
+          << "\n";
+        }
+        AliDebug(4, "Failed Attach Clusters");
         continue;
       }
-      if(tracklet.GetN() < fgNTimeBins*fReconstructor->GetRecoParam() ->GetFindableClusters()){
+      AliDebug(3, Form("Number of Clusters in Tracklet: %d", tracklet.GetN()));
+      if(tracklet.GetN() < fgNTimeBins*fkReconstructor->GetRecoParam() ->GetFindableClusters()){
         t.SetStatus(AliTRDtrackV1::kNoClustersTracklet, ily);
+        if(debugLevel>3){
+          AliTRDseedV1 trackletCp(*ptrTracklet);
+          UChar_t status(t.GetStatusTRD(ily));
+          (*cstreamer)   << "FollowBackProlongation2"
+          <<"status="    << status
+          <<"tracklet.=" << &trackletCp
+          << "\n";
+        }
+        AliDebug(4, "Failed N Clusters Attached");
         continue;
       }
       ptrTracklet->UpdateUsed();
-    }
-
+    } else AliDebug(2, Form("Use external tracklet ly[%d]", ily));
     // propagate track to the radial position of the tracklet
     ptrTracklet->UseClusters(); // TODO ? do we need this here ?
     // fit tracklet no tilt correction
     if(!ptrTracklet->Fit(kFALSE)){
       t.SetStatus(AliTRDtrackV1::kNoFit, ily);
+      AliDebug(4, "Failed Tracklet Fit");
       continue;
     } 
     x = ptrTracklet->GetX(); //GetX0();
     if(x > (fgkMaxStep + t.GetX()) && !PropagateToX(t, x, fgkMaxStep)) {
       n=-1; 
       t.SetStatus(AliTRDtrackV1::kPropagation);
+      AliDebug(4, Form("Failed Propagation to Tracklet x[%7.2f]", x));
       break;
     }
     if(!AdjustSector(&t)) {
       n=-1; 
       t.SetStatus(AliTRDtrackV1::kAdjustSector);
+      AliDebug(4, "Failed Adjust Sector");
       break;
     }
     if(TMath::Abs(t.GetSnp()) > fgkMaxSnp) {
       n=-1; 
       t.SetStatus(AliTRDtrackV1::kSnp);
+      AliDebug(4, Form("Failed Max Snp[%f] MaxSnp[%f]", t.GetSnp(), fgkMaxSnp));
       break;
     }
-  
+    if(kPropagateIn){
+      t.SetTrackLow(); 
+      kPropagateIn = kFALSE;
+    }
+    Double_t cov[3]; ptrTracklet->GetCovAt(x, cov);
+    Double_t p[2] = { ptrTracklet->GetY(), ptrTracklet->GetZ()};
+    Double_t chi2 = ((AliExternalTrackParam)t).GetPredictedChi2(p, cov);
     // update Kalman with the TRD measurement
-    Double_t chi2 = t.GetPredictedChi2(ptrTracklet);
-    if(chi2>1e+10){
+    if(chi2>1e+10){ // TODO
       t.SetStatus(AliTRDtrackV1::kChi2, ily);
+      if(debugLevel > 2){
+        UChar_t status(t.GetStatusTRD());
+        AliTRDseedV1  trackletCp(*ptrTracklet);
+        AliTRDtrackV1 trackCp(t);
+        trackCp.SetOwner();
+        (*cstreamer) << "FollowBackProlongation1"
+            << "status="      << status
+            << "tracklet.="   << &trackletCp
+            << "track.="      << &trackCp
+            << "\n";
+      }
+      AliDebug(4, Form("Failed Chi2[%f]", chi2));
       continue; 
     }
-    if(!t.Update(ptrTracklet, chi2)) {
+    if(!t.Update(p, cov, chi2)) {
       n=-1; 
       t.SetStatus(AliTRDtrackV1::kUpdate);
+      if(debugLevel > 2){
+        UChar_t status(t.GetStatusTRD());
+        AliTRDseedV1  trackletCp(*ptrTracklet);
+        AliTRDtrackV1 trackCp(t);
+        trackCp.SetOwner();
+        (*cstreamer) << "FollowBackProlongation1"
+            << "status="      << status
+            << "tracklet.="   << &trackletCp
+            << "track.="      << &trackCp
+            << "\n";
+      }
+      AliDebug(4, Form("Failed Track Update @ y[%7.2f] z[%7.2f] s2y[%f] s2z[%f] covyz[%f]", p[0], p[1], cov[0], cov[2], cov[1]));
       break;
     }
+    // fill residuals ?!
+    AliTracker::FillResiduals(&t, p, cov, ptrTracklet->GetVolumeId());
+  
 
     // load tracklet to the tracker
-    ptrTracklet->UpDate(&t);
+    ptrTracklet->Update(&t);
     ptrTracklet = SetTracklet(ptrTracklet);
-    t.SetTracklet(ptrTracklet, fTracklets->GetEntriesFast()-1);
+    Int_t index(fTracklets->GetEntriesFast()-1);
+    t.SetTracklet(ptrTracklet, index);
     n += ptrTracklet->GetN();
+    AliDebug(2, Form("Setting Tracklet[%d] @ Idx[%d]", ily, index));
 
     // Reset material budget if 2 consecutive gold
 //     if(ilayer>0 && t.GetTracklet(ilayer-1) && ptrTracklet->GetN() + t.GetTracklet(ilayer-1)->GetN() > 20) t.SetBudget(2, 0.);
@@ -878,12 +974,11 @@ Int_t AliTRDtrackerV1::FollowBackProlongation(AliTRDtrackV1 &t)
   //printf("clusters[%d] chi2[%f] x[%f] status[%d ", n, t.GetChi2(), t.GetX(), t.GetStatusTRD());
   //for(int i=0; i<6; i++) printf("%d ", t.GetStatusTRD(i)); printf("]\n");
 
-  if(fReconstructor->GetStreamLevel(AliTRDReconstructor::kTracker) > 1){
-    TTreeSRedirector &cstreamer = *fReconstructor->GetDebugStream(AliTRDReconstructor::kTracker);
+  if(debugLevel > 1){
     Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
     AliTRDtrackV1 track(t);
     track.SetOwner();
-    cstreamer << "FollowBackProlongation"
+    (*cstreamer) << "FollowBackProlongation0"
         << "EventNumber=" << eventNumber
         << "ncl="         << n
         << "track.="      << &track
@@ -894,7 +989,7 @@ Int_t AliTRDtrackerV1::FollowBackProlongation(AliTRDtrackV1 &t)
 }
 
 //_________________________________________________________________________
-Float_t AliTRDtrackerV1::FitRieman(AliTRDseedV1 *tracklets, Double_t *chi2, Int_t *planes){
+Float_t AliTRDtrackerV1::FitRieman(AliTRDseedV1 *tracklets, Double_t *chi2, Int_t *const planes){
   //
   // Fits a Riemann-circle to the given points without tilting pad correction.
   // The fit is performed using an instance of the class AliRieman (equations 
@@ -950,8 +1045,9 @@ void AliTRDtrackerV1::FitRieman(AliTRDcluster **seedcl, Double_t chi2[2])
   //
   AliRieman *fitter = AliTRDtrackerV1::GetRiemanFitter();
   fitter->Reset();
-  for(Int_t i = 0; i < 4; i++)
-    fitter->AddPoint(seedcl[i]->GetX(), seedcl[i]->GetY(), seedcl[i]->GetZ(), 1, 10);
+  for(Int_t i = 0; i < 4; i++){
+    fitter->AddPoint(seedcl[i]->GetX(), seedcl[i]->GetY(), seedcl[i]->GetZ(), 1., 10.);
+  }
   fitter->Update();
   
   
@@ -997,7 +1093,7 @@ Float_t AliTRDtrackerV1::FitTiltedRiemanConstraint(AliTRDseedV1 *tracklets, Doub
   TLinearFitter *fitter = GetTiltedRiemanFitterConstraint();
   fitter->StoreData(kTRUE);
   fitter->ClearPoints();
-  AliTRDcluster *cl = 0x0;
+  AliTRDcluster *cl = NULL;
   
   Float_t x, y, z, w, t, error, tilt;
   Double_t uvt[2];
@@ -1007,6 +1103,7 @@ Float_t AliTRDtrackerV1::FitTiltedRiemanConstraint(AliTRDseedV1 *tracklets, Doub
     for(Int_t itb = 0; itb < AliTRDseedV1::kNclusters; itb++){
       if(!tracklets[ilr].IsUsable(itb)) continue;
       cl = tracklets[ilr].GetClusters(itb);
+      if(!cl->IsInChamber()) continue;
       x = cl->GetX();
       y = cl->GetY();
       z = cl->GetZ();
@@ -1016,7 +1113,7 @@ Float_t AliTRDtrackerV1::FitTiltedRiemanConstraint(AliTRDseedV1 *tracklets, Doub
       uvt[0] = 2. * x * t;
       uvt[1] = 2. * x * t * tilt ;
       w = 2. * (y + tilt * (z - zVertex)) * t;
-      error = 2. * TMath::Sqrt(cl->GetSigmaY2()) * t;
+      error = 2. * TMath::Sqrt(cl->GetSigmaY2()+tilt*tilt*cl->GetSigmaZ2()) * t;
       fitter->AddPoint(uvt, w, error);
       nPoints++;
     }
@@ -1032,7 +1129,7 @@ Float_t AliTRDtrackerV1::FitTiltedRiemanConstraint(AliTRDseedV1 *tracklets, Doub
   for(Int_t ip = 0; ip < AliTRDtrackerV1::kNPlanes; ip++)
     tracklets[ip].SetC(curvature);
 
-/*  if(fReconstructor->GetStreamLevel() >= 5){
+/*  if(fkReconstructor->GetRecoParam()->GetStreamLevel(AliTRDrecoParam::kTracker()) >= 5){
     //Linear Model on z-direction
     Double_t xref = CalculateReferenceX(tracklets);            // Relative to the middle of the stack
     Double_t slope = fitter->GetParameter(2);
@@ -1040,7 +1137,7 @@ Float_t AliTRDtrackerV1::FitTiltedRiemanConstraint(AliTRDseedV1 *tracklets, Doub
     Float_t chi2Z = CalculateChi2Z(tracklets, zref, slope, xref);
     Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
     Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
-    TTreeSRedirector &treeStreamer = *fReconstructor->GetDebugStream(AliTRDReconstructor::kTracker);
+    TTreeSRedirector &treeStreamer = *fkReconstructor->GetDebugStream(AliTRDReconstructor::kTracker);
     treeStreamer << "FitTiltedRiemanConstraint"
     << "EventNumber="          << eventNumber
     << "CandidateNumber="      << candidateNumber
@@ -1089,11 +1186,13 @@ Float_t AliTRDtrackerV1::FitTiltedRieman(AliTRDseedV1 *tracklets, Bool_t sigErro
   fitter->StoreData(kTRUE);
   fitter->ClearPoints();
   AliTRDLeastSquare zfitter;
-  AliTRDcluster *cl = 0x0;
+  AliTRDcluster *cl = NULL;
 
   Double_t xref = CalculateReferenceX(tracklets);
-  Double_t x, y, z, t, tilt, dx, w, we;
-  Double_t uvt[4];
+  Double_t x, y, z, t, tilt, dx, w, we, erry, errz;
+  Double_t uvt[4], sumPolY[5], sumPolZ[3];
+  memset(sumPolY, 0, sizeof(Double_t) * 5);
+  memset(sumPolZ, 0, sizeof(Double_t) * 3);
   Int_t nPoints = 0;
   // Containers for Least-square fitter
   for(Int_t ipl = 0; ipl < kNPlanes; ipl++){
@@ -1101,6 +1200,7 @@ Float_t AliTRDtrackerV1::FitTiltedRieman(AliTRDseedV1 *tracklets, Bool_t sigErro
     tilt = tracklets[ipl].GetTilt();
     for(Int_t itb = 0; itb < AliTRDseedV1::kNclusters; itb++){
       if(!(cl = tracklets[ipl].GetClusters(itb))) continue;
+      if(!cl->IsInChamber()) continue;
       if (!tracklets[ipl].IsUsable(itb)) continue;
       x = cl->GetX();
       y = cl->GetY();
@@ -1115,9 +1215,21 @@ Float_t AliTRDtrackerV1::FitTiltedRieman(AliTRDseedV1 *tracklets, Bool_t sigErro
       w = 2. * (y + tilt*z) * t;
       // error definition changes for the different calls
       we = 2. * t;
-      we *= sigError ? TMath::Sqrt(cl->GetSigmaY2()) : 0.2;
+      we *= sigError ? TMath::Sqrt(cl->GetSigmaY2()+tilt*tilt*cl->GetSigmaZ2()) : 0.2;
       fitter->AddPoint(uvt, w, we);
       zfitter.AddPoint(&x, z, static_cast<Double_t>(TMath::Sqrt(cl->GetSigmaZ2())));
+      // adding points for covariance matrix estimation
+      erry = 1./(TMath::Sqrt(cl->GetSigmaY2()) + 0.1);  // 0.1 is a systematic error (due to misalignment and miscalibration)
+      erry *= erry;
+      errz = 1./cl->GetSigmaZ2();
+      for(Int_t ipol = 0; ipol < 5; ipol++){
+        sumPolY[ipol] += erry;
+        erry *= x;
+        if(ipol < 3){
+          sumPolZ[ipol] += errz;
+          errz *= x;
+        }
+      }
       nPoints++;
     }
   }
@@ -1159,16 +1271,45 @@ Float_t AliTRDtrackerV1::FitTiltedRieman(AliTRDseedV1 *tracklets, Bool_t sigErro
 
   Double_t chi2track = fitter->GetChisquare()/Double_t(nPoints);
 
+  // Prepare error calculation
+  TMatrixD covarPolY(3,3);
+  covarPolY(0,0) = sumPolY[0]; covarPolY(1,1) = sumPolY[2]; covarPolY(2,2) = sumPolY[4];
+  covarPolY(0,1) = covarPolY(1,0) = sumPolY[1];
+  covarPolY(0,2) = covarPolY(2,0) = sumPolY[2];
+  covarPolY(2,1) = covarPolY(1,2) = sumPolY[3];
+  covarPolY.Invert();
+  TMatrixD covarPolZ(2,2);
+  covarPolZ(0,0) = sumPolZ[0]; covarPolZ(1,1) = sumPolZ[2];
+  covarPolZ(1,0) = covarPolZ(0,1) = sumPolZ[1];
+  covarPolZ.Invert();
+
   // Update the tracklets
-  Double_t dy, dz;
+  Double_t x1, dy, dz;
+  Double_t cov[15];
+  memset(cov, 0, sizeof(Double_t) * 15);
   for(Int_t iLayer = 0; iLayer < AliTRDtrackerV1::kNPlanes; iLayer++) {
 
     x  = tracklets[iLayer].GetX0();
+    x1 = x - xref;
     y  = 0;
     z  = 0;
     dy = 0;
     dz = 0;
-
+    memset(cov, 0, sizeof(Double_t) * 3);
+    TMatrixD transform(3,3);
+    transform(0,0) = 1;
+    transform(0,1) = x;
+    transform(0,2) = x*x;
+    transform(1,1) = 1;
+    transform(1,2) = x;
+    transform(2,2) = 1;
+    TMatrixD covariance(transform, TMatrixD::kMult, covarPolY);
+    covariance *= transform.T();
+    TMatrixD transformZ(2,2);
+    transformZ(0,0) = transformZ(1,1) = 1;
+    transformZ(0,1) = x;
+    TMatrixD covarZ(transformZ, TMatrixD::kMult, covarPolZ);
+    covarZ *= transformZ.T();
     // y:     R^2 = (x - x0)^2 + (y - y0)^2
     //     =>   y = y0 +/- Sqrt(R^2 - (x - x0)^2)
     //          R = Sqrt() = 1/Curvature
@@ -1180,6 +1321,9 @@ Float_t AliTRDtrackerV1::FitTiltedRieman(AliTRDseedV1 *tracklets, Bool_t sigErro
       res = TMath::Sqrt(res);
       y    = (1.0 - res) / a;
     }
+    cov[0] = covariance(0,0);
+    cov[2] = covarZ(0,0);
+    cov[1] = 0.;
 
     // dy:      R^2 = (x - x0)^2 + (y - y0)^2
     //     =>     y = +/- Sqrt(R^2 - (x - x0)^2) + y0
@@ -1189,9 +1333,9 @@ Float_t AliTRDtrackerV1::FitTiltedRieman(AliTRDseedV1 *tracklets, Bool_t sigErro
     Double_t x0 = -b / a;
     if (-c * a + b * b + 1 > 0) {
       if (1.0/(curvature * curvature) - (x - x0) * (x - x0) > 0.0) {
-  Double_t yderiv = (x - x0) / TMath::Sqrt(1.0/(curvature * curvature) - (x - x0) * (x - x0));
-  if (a < 0) yderiv *= -1.0;
-  dy = yderiv;
+       Double_t yderiv = (x - x0) / TMath::Sqrt(1.0/(curvature * curvature) - (x - x0) * (x - x0));
+        if (a < 0) yderiv *= -1.0;
+        dy = yderiv;
       }
     }
     z  = offset + slope * (x - xref);
@@ -1201,11 +1345,12 @@ Float_t AliTRDtrackerV1::FitTiltedRieman(AliTRDseedV1 *tracklets, Bool_t sigErro
     tracklets[iLayer].SetZref(0, z);
     tracklets[iLayer].SetZref(1, dz);
     tracklets[iLayer].SetC(curvature);
+    tracklets[iLayer].SetCovRef(cov);
     tracklets[iLayer].SetChi2(chi2track);
   }
   
-/*  if(fReconstructor->GetStreamLevel() >=5){
-    TTreeSRedirector &cstreamer = *fReconstructor->GetDebugStream(AliTRDReconstructor::kTracker);
+/*  if(fkReconstructor->GetRecoParam()->GetStreamLevel(AliTRDrecoParam::kTracker) >=5){
+    TTreeSRedirector &cstreamer = *fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
     Int_t eventNumber                  = AliTRDtrackerDebug::GetEventNumber();
     Int_t candidateNumber      = AliTRDtrackerDebug::GetCandidateNumber();
     Double_t chi2z = CalculateChi2Z(tracklets, offset, slope, xref);
@@ -1223,10 +1368,15 @@ Float_t AliTRDtrackerV1::FitTiltedRieman(AliTRDseedV1 *tracklets, Bool_t sigErro
 //____________________________________________________________________
 Double_t AliTRDtrackerV1::FitLine(const AliTRDtrackV1 *track, AliTRDseedV1 *tracklets, Bool_t err, Int_t np, AliTrackPoint *points)
 {
+  //
+  // Fit track with a staight line
+  // Fills an AliTrackPoint array with np points
+  // Function should be used to refit tracks when no magnetic field was on
+  //
   AliTRDLeastSquare yfitter, zfitter;
-  AliTRDcluster *cl = 0x0;
+  AliTRDcluster *cl = NULL;
 
-  AliTRDseedV1 work[kNPlanes], *tracklet = 0x0;
+  AliTRDseedV1 work[kNPlanes], *tracklet = NULL;
   if(!tracklets){
     for(Int_t ipl = 0; ipl < kNPlanes; ipl++){
       if(!(tracklet = track->GetTracklet(ipl))) continue;
@@ -1291,42 +1441,63 @@ Double_t AliTRDtrackerV1::FitLine(const AliTRDtrackV1 *track, AliTRDseedV1 *trac
 //_________________________________________________________________________
 Double_t AliTRDtrackerV1::FitRiemanTilt(const AliTRDtrackV1 *track, AliTRDseedV1 *tracklets, Bool_t sigError, Int_t np, AliTrackPoint *points)
 {
-  //
-  // Performs a Riemann fit taking tilting pad correction into account
-  // The equation of a Riemann circle, where the y position is substituted by the 
-  // measured y-position taking pad tilting into account, has to be transformed
-  // into a 4-dimensional hyperplane equation
-  // Riemann circle: (x-x0)^2 + (y-y0)^2 -R^2 = 0
-  // Measured y-Position: ymeas = y - tan(phiT)(zc - zt)
-  //          zc: center of the pad row
-  //          zt: z-position of the track
-  // The z-position of the track is assumed to be linear dependent on the x-position
-  // Transformed equation: a + b * u + c * t + d * v  + e * w - 2 * (ymeas + tan(phiT) * zc) * t = 0
-  // Transformation:       u = 2 * x * t
-  //                       v = 2 * tan(phiT) * t
-  //                       w = 2 * tan(phiT) * (x - xref) * t
-  //                       t = 1 / (x^2 + ymeas^2)
-  // Parameters:           a = -1/y0
-  //                       b = x0/y0
-  //                       c = (R^2 -x0^2 - y0^2)/y0
-  //                       d = offset
-  //                       e = dz/dx
-  // If the offset respectively the slope in z-position is impossible, the parameters are fixed using 
-  // results from the simple riemann fit. Afterwards the fit is redone.
-  // The curvature is calculated according to the formula:
-  //                       curv = a/(1 + b^2 + c*a) = 1/R
-  //
-  // Paramters:   - Array of tracklets (connected to the track candidate)
-  //              - Flag selecting the error definition
-  // Output:      - Chi2 values of the track (in Parameter list)
-  //
+//
+// Performs a Riemann fit taking tilting pad correction into account
+//
+// Paramters:   - Array of tracklets (connected to the track candidate)
+//              - Flag selecting the error definition
+// Output:      - Chi2 values of the track (in Parameter list)
+//
+// The equations which has to be solved simultaneously are:
+// BEGIN_LATEX
+// R^{2} = (x-x_{0})^{2} + (y^{*}-y_{0})^{2}
+// y^{*} = y - tg(h)(z - z_{t})
+// z_{t} = z_{0}+dzdx*(x-x_{r})
+// END_LATEX
+// with (x, y, z) the coordinate of the cluster, (x_0, y_0, z_0) the coordinate of the center of the Riemann circle,
+// R its radius, x_r a constant refrence radial position in the middle of the TRD stack  and dzdx the slope of the 
+// track in the x-z plane. Using the following transformations
+// BEGIN_LATEX
+// t = 1 / (x^{2} + y^{2})
+// u = 2 * x * t
+// v = 2 * tan(h) * t
+// w = 2 * tan(h) * (x - x_{r}) * t
+// END_LATEX
+// One gets the following linear equation
+// BEGIN_LATEX
+// a + b * u + c * t + d * v  + e * w = 2 * (y + tg(h) * z) * t
+// END_LATEX
+// where the coefficients have the following meaning 
+// BEGIN_LATEX
+// a = -1/y_{0}
+// b = x_{0}/y_{0}
+// c = (R^{2} -x_{0}^{2} - y_{0}^{2})/y_{0}
+// d = z_{0}
+// e = dz/dx
+// END_LATEX
+// The error calculation for the free term is thus
+// BEGIN_LATEX
+// #sigma = 2 * #sqrt{#sigma^{2}_{y} + (tilt corr ...) + tg^{2}(h) * #sigma^{2}_{z}} * t
+// END_LATEX
+//
+// From this simple model one can compute chi^2 estimates and a rough approximation of pt from the curvature according 
+// to the formula:
+// BEGIN_LATEX
+// C = 1/R = a/(1 + b^{2} + c*a)
+// END_LATEX
+//
+// Authors
+//   M.Ivanov <M.Ivanov@gsi.de>
+//   A.Bercuci <A.Bercuci@gsi.de>
+//   M.Fasel <M.Fasel@gsi.de>
+
   TLinearFitter *fitter = GetTiltedRiemanFitter();
   fitter->StoreData(kTRUE);
   fitter->ClearPoints();
   AliTRDLeastSquare zfitter;
-  AliTRDcluster *cl = 0x0;
+  AliTRDcluster *cl = NULL;
 
-  AliTRDseedV1 work[kNPlanes], *tracklet = 0x0;
+  AliTRDseedV1 work[kNPlanes], *tracklet = NULL;
   if(!tracklets){
     for(Int_t ipl = 0; ipl < kNPlanes; ipl++){
       if(!(tracklet = track->GetTracklet(ipl))) continue;
@@ -1403,9 +1574,9 @@ Double_t AliTRDtrackerV1::FitRiemanTilt(const AliTRDtrackV1 *track, AliTRDseedV1
   Double_t x0   = -b * y0;
   Double_t tmp  = y0*y0 + x0*x0 - c*y0;
   if(tmp<=0.) return 1.E10;
-  Double_t R    = TMath::Sqrt(tmp);
-  Double_t C    =  1.0 + b*b - c*a;
-  if (C > 0.0) C  =  a / TMath::Sqrt(C);
+  Double_t radius    = TMath::Sqrt(tmp);
+  Double_t curvature    =  1.0 + b*b - c*a;
+  if (curvature > 0.0)  curvature  =  a / TMath::Sqrt(curvature);
 
   // Calculate chi2 of the fit 
   Double_t chi2 = fitter->GetChisquare()/Double_t(nPoints);
@@ -1414,7 +1585,7 @@ Double_t AliTRDtrackerV1::FitRiemanTilt(const AliTRDtrackV1 *track, AliTRDseedV1
   if(!track){
     for(Int_t ip = 0; ip < kNPlanes; ip++) {
       x = tracklets[ip].GetX0();
-      tmp = R*R-(x-x0)*(x-x0);  
+      tmp = radius*radius-(x-x0)*(x-x0);  
       if(tmp <= 0.) continue;
       tmp = TMath::Sqrt(tmp);  
 
@@ -1425,7 +1596,7 @@ Double_t AliTRDtrackerV1::FitRiemanTilt(const AliTRDtrackV1 *track, AliTRDseedV1
       tracklets[ip].SetYref(1, (x - x0) / tmp);
       tracklets[ip].SetZref(0, z0 + dzdx * (x - xref));
       tracklets[ip].SetZref(1, dzdx);
-      tracklets[ip].SetC(C);
+      tracklets[ip].SetC(curvature);
       tracklets[ip].SetChi2(chi2);
     }
   }
@@ -1434,7 +1605,7 @@ Double_t AliTRDtrackerV1::FitRiemanTilt(const AliTRDtrackV1 *track, AliTRDseedV1
     Float_t xyz[3];
     for(int ip=0; ip<np; ip++){
       points[ip].GetXYZ(xyz);
-      xyz[1] = TMath::Abs(xyz[0] - x0) > R ? 100. : y0 - (y0>0.?1.:-1.)*TMath::Sqrt((R-(xyz[0]-x0))*(R+(xyz[0]-x0)));
+      xyz[1] = TMath::Abs(xyz[0] - x0) > radius ? 100. : y0 - (y0>0.?1.:-1.)*TMath::Sqrt((radius-(xyz[0]-x0))*(radius+(xyz[0]-x0)));
       xyz[2] = z0 + dzdx * (xyz[0] - xref);
       points[ip].SetXYZ(xyz);
     }
@@ -1445,7 +1616,7 @@ Double_t AliTRDtrackerV1::FitRiemanTilt(const AliTRDtrackV1 *track, AliTRDseedV1
 
 
 //____________________________________________________________________
-Double_t AliTRDtrackerV1::FitKalman(AliTRDtrackV1 *track, AliTRDseedV1 *tracklets, Bool_t up, Int_t np, AliTrackPoint *points)
+Double_t AliTRDtrackerV1::FitKalman(AliTRDtrackV1 *track, AliTRDseedV1 * const tracklets, Bool_t up, Int_t np, AliTrackPoint *points)
 {
 //   Kalman filter implementation for the TRD.
 //   It returns the positions of the fit in the array "points"
@@ -1464,7 +1635,7 @@ Double_t AliTRDtrackerV1::FitKalman(AliTRDtrackV1 *track, AliTRDseedV1 *tracklet
   //if(points) printf("First marker point @ x[%d] = %f\n", ip, points[ip].GetX());
 
 
-  AliTRDseedV1 tracklet, *ptrTracklet = 0x0;
+  AliTRDseedV1 tracklet, *ptrTracklet = NULL;
 
   //Loop through the TRD planes
   for (Int_t jplane = 0; jplane < kNPlanes; jplane++) {
@@ -1474,8 +1645,8 @@ Double_t AliTRDtrackerV1::FitKalman(AliTRDtrackV1 *track, AliTRDseedV1 *tracklet
       if(!(ptrTracklet = &tracklets[iplane])) continue;
     }else{
       if(!(ptrTracklet  = track->GetTracklet(iplane))){ 
-      /*AliTRDtrackerV1 *tracker = 0x0;
-        if(!(tracker = dynamic_cast<AliTRDtrackerV1*>( AliTRDReconstructor::Tracker()))) continue;
+      /*AliTRDtrackerV1 *tracker = NULL;
+        if(!(tracker = dynamic_cast<AliTRDtrackerV1*>( AliTRDrecoParam:Tracker()))) continue;
         ptrTracklet = new(&tracklet) AliTRDseedV1(iplane);
         if(!tracker->MakeTracklet(ptrTracklet, track)) */
         continue;
@@ -1539,8 +1710,10 @@ Double_t AliTRDtrackerV1::FitKalman(AliTRDtrackV1 *track, AliTRDseedV1 *tracklet
     if (!AdjustSector(track)) break;
   
     //Update track
-    Double_t chi2 = track->GetPredictedChi2(ptrTracklet);
-    if(chi2<1e+10) track->Update(ptrTracklet, chi2);
+    Double_t cov[3]; ptrTracklet->GetCovAt(x, cov);
+    Double_t p[2] = { ptrTracklet->GetY(), ptrTracklet->GetZ()};
+    Double_t chi2 = ((AliExternalTrackParam*)track)->GetPredictedChi2(p, cov);
+    if(chi2<1e+10) track->Update(p, cov, chi2);
     if(!up) continue;
 
                //Reset material budget if 2 consecutive gold
@@ -1621,9 +1794,7 @@ Int_t AliTRDtrackerV1::PropagateToX(AliTRDtrackV1 &t, Double_t xToGo, Double_t m
     x = xpos + step;
 
     // Get local Y and Z at the X-position of the next step
-    if (!t.GetProlongation(x,y,z)) {
-      return 0; // No prolongation possible
-    }
+    if(t.GetProlongation(x,y,z)<0) return 0; // No prolongation possible
 
     // The global position of the end point of this prolongation step
     xyz1[0] =  x * TMath::Cos(t.GetAlpha()) - y * TMath::Sin(t.GetAlpha()); 
@@ -1670,8 +1841,8 @@ Int_t AliTRDtrackerV1::ReadClusters(TClonesArray* &array, TTree *clusterTree) co
   branch->SetAddress(&clusterArray); 
   
   if(!fClusters){ 
-    Float_t nclusters =  fReconstructor->GetRecoParam()->GetNClusters();
-    if(fReconstructor->IsHLT()) nclusters /= AliTRDgeometry::kNsector;
+    Float_t nclusters =  fkReconstructor->GetRecoParam()->GetNClusters();
+    if(fkReconstructor->IsHLT()) nclusters /= AliTRDgeometry::kNsector;
     array = new TClonesArray("AliTRDcluster", Int_t(nclusters));
     array->SetOwner(kTRUE);
   }
@@ -1680,7 +1851,7 @@ Int_t AliTRDtrackerV1::ReadClusters(TClonesArray* &array, TTree *clusterTree) co
   Int_t nEntries   = (Int_t) clusterTree->GetEntries();
   Int_t nbytes     = 0;
   Int_t ncl        = 0;
-  AliTRDcluster *c = 0x0;
+  AliTRDcluster *c = NULL;
   for (Int_t iEntry = 0; iEntry < nEntries; iEntry++) {
     // Import the tree
     nbytes += clusterTree->GetEvent(iEntry);  
@@ -1689,7 +1860,6 @@ Int_t AliTRDtrackerV1::ReadClusters(TClonesArray* &array, TTree *clusterTree) co
     Int_t nCluster = clusterArray->GetEntriesFast();  
     for (Int_t iCluster = 0; iCluster < nCluster; iCluster++) { 
       if(!(c = (AliTRDcluster *) clusterArray->UncheckedAt(iCluster))) continue;
-      c->SetInChamber();
       new((*fClusters)[ncl++]) AliTRDcluster(*c);
       delete (clusterArray->RemoveAt(iCluster)); 
     }
@@ -1707,7 +1877,7 @@ Int_t AliTRDtrackerV1::LoadClusters(TTree *cTree)
   // Fills clusters into TRD tracking sectors
   //
   
-  if(!fReconstructor->IsWritingClusters()){ 
+  if(!fkReconstructor->IsWritingClusters()){ 
     fClusters = AliTRDReconstructor::GetClusters();
   } else {
     if (ReadClusters(fClusters, cTree)) {
@@ -1732,7 +1902,7 @@ Int_t AliTRDtrackerV1::LoadClusters(TTree *cTree)
 }
 
 //_____________________________________________________________________________
-Int_t AliTRDtrackerV1::LoadClusters(TClonesArray *clusters)
+Int_t AliTRDtrackerV1::LoadClusters(TClonesArray * const clusters)
 {
   //
   // Fills clusters into TRD tracking sectors
@@ -1765,6 +1935,7 @@ Int_t AliTRDtrackerV1::BuildTrackingContainers()
   while (icl--) {
     AliTRDcluster *c = (AliTRDcluster *) fClusters->UncheckedAt(icl);
     if(c->IsInChamber()) nin++;
+    if(fkReconstructor->IsHLT()) c->SetRPhiMethod(AliTRDcluster::kCOG);
     Int_t detector       = c->GetDetector();
     Int_t sector         = fGeom->GetSector(detector);
     Int_t stack          = fGeom->GetStack(detector);
@@ -1776,7 +1947,7 @@ Int_t AliTRDtrackerV1::BuildTrackingContainers()
   const AliTRDCalDet *cal = AliTRDcalibDB::Instance()->GetT0Det();
   for(int isector =0; isector<AliTRDgeometry::kNsector; isector++){ 
     if(!fTrSec[isector].GetNChambers()) continue;
-    fTrSec[isector].Init(fReconstructor, cal);
+    fTrSec[isector].Init(fkReconstructor, cal);
   }
 
   return nin;
@@ -1787,20 +1958,27 @@ Int_t AliTRDtrackerV1::BuildTrackingContainers()
 //____________________________________________________________________
 void AliTRDtrackerV1::UnloadClusters() 
 { 
-  //
-  // Clears the arrays of clusters and tracks. Resets sectors and timebins 
-  //
-
-  if(fTracks) fTracks->Delete(); 
-  if(fTracklets) fTracklets->Delete();
+//
+// Clears the arrays of clusters and tracks. Resets sectors and timebins 
+// If option "force" is also set the containers are also deleted. This is useful 
+// in case of HLT
+
+  if(fTracks){ 
+    fTracks->Delete(); 
+    if(HasRemoveContainers()){delete fTracks; fTracks = NULL;}
+  }
+  if(fTracklets){ 
+    fTracklets->Delete();
+    if(HasRemoveContainers()){delete fTracklets; fTracklets = NULL;}
+  }
   if(fClusters){ 
     if(IsClustersOwner()) fClusters->Delete();
     
     // save clusters array in the reconstructor for further use.
-    if(!fReconstructor->IsWritingClusters()){
+    if(!fkReconstructor->IsWritingClusters()){
       AliTRDReconstructor::SetClusters(fClusters);
       SetClustersOwner(kFALSE);
-    } else AliTRDReconstructor::SetClusters(0x0);
+    } else AliTRDReconstructor::SetClusters(NULL);
   }
 
   for (int i = 0; i < AliTRDgeometry::kNsector; i++) fTrSec[i].Clear();
@@ -1815,10 +1993,10 @@ void AliTRDtrackerV1::UnloadClusters()
 //   const AliTRDtrackV1 *track = dynamic_cast<const AliTRDtrackV1*>(t);
 //   if(!track) return;
 // 
-//   AliTRDseedV1 *tracklet = 0x0;
+//   AliTRDseedV1 *tracklet = NULL;
 //   for(Int_t ily=AliTRDgeometry::kNlayer; ily--;){
 //     if(!(tracklet = track->GetTracklet(ily))) continue;
-//     AliTRDcluster *c = 0x0;
+//     AliTRDcluster *c = NULL;
 //     for(Int_t ic=AliTRDseed::kNclusters; ic--;){
 //       if(!(c=tracklet->GetClusters(ic))) continue;
 //       c->Use();
@@ -1828,7 +2006,7 @@ void AliTRDtrackerV1::UnloadClusters()
 // 
 
 //_____________________________________________________________________________
-Bool_t AliTRDtrackerV1::AdjustSector(AliTRDtrackV1 *track) 
+Bool_t AliTRDtrackerV1::AdjustSector(AliTRDtrackV1 *const track) 
 {
   //
   // Rotates the track when necessary
@@ -1855,7 +2033,7 @@ Bool_t AliTRDtrackerV1::AdjustSector(AliTRDtrackV1 *track)
 
 
 //____________________________________________________________________
-AliTRDseedV1* AliTRDtrackerV1::GetTracklet(AliTRDtrackV1 *track, Int_t p, Int_t &idx)
+AliTRDseedV1* AliTRDtrackerV1::GetTracklet(AliTRDtrackV1 *const track, Int_t p, Int_t &idx)
 {
   // Find tracklet for TRD track <track>
   // Parameters
@@ -1869,13 +2047,13 @@ AliTRDseedV1* AliTRDtrackerV1::GetTracklet(AliTRDtrackV1 *track, Int_t p, Int_t
   // Detailed description
   //
   idx = track->GetTrackletIndex(p);
-  AliTRDseedV1 *tracklet = (idx==0xffff) ? 0x0 : (AliTRDseedV1*)fTracklets->UncheckedAt(idx);
+  AliTRDseedV1 *tracklet = (idx<0) ? NULL : (AliTRDseedV1*)fTracklets->UncheckedAt(idx);
 
   return tracklet;
 }
 
 //____________________________________________________________________
-AliTRDseedV1* AliTRDtrackerV1::SetTracklet(AliTRDseedV1 *tracklet)
+AliTRDseedV1* AliTRDtrackerV1::SetTracklet(const AliTRDseedV1 * const tracklet)
 {
   // Add this tracklet to the list of tracklets stored in the tracker
   //
@@ -1898,7 +2076,34 @@ AliTRDseedV1* AliTRDtrackerV1::SetTracklet(AliTRDseedV1 *tracklet)
 }
 
 //____________________________________________________________________
-AliTRDtrackV1* AliTRDtrackerV1::SetTrack(AliTRDtrackV1 *track)
+void AliTRDtrackerV1::CookNTimeBins()
+{ 
+  // Initialize number of time bins
+
+  if(fgNTimeBins){
+    // first look if set by hand
+    AliDebug(2, Form("NTimeBins [%d] (set by user)", fgNTimeBins));
+  } else if(fkReconstructor && fkReconstructor->HasDigitsParam()) {
+    // second look into digits param to avoid DB query
+    fgNTimeBins = fkReconstructor->GetDigitsParam()->GetNTimeBins();
+    AliDebug(2, Form("NTimeBins [%d] (set from digits param)", fgNTimeBins));
+  } else { // third query DB
+    AliTRDcalibDB *trd(NULL);
+    if((trd = AliTRDcalibDB::Instance())) {
+      if((fgNTimeBins = trd->GetNumberOfTimeBinsDCS()) <= 0){
+        AliError("Corrupted DCS Object in OCDB");
+        fgNTimeBins = 24;
+        AliDebug(2, Form("NTimeBins [%d] (set to default)", fgNTimeBins));
+      } else AliDebug(2, Form("NTimeBins [%d] (set from DB)", fgNTimeBins));
+    } else AliFatal("Could not get DB.");
+  }
+  if(fgNTimeBins<=0){
+    AliFatal("Could not get number of time bins.");
+  }
+}
+
+//____________________________________________________________________
+AliTRDtrackV1* AliTRDtrackerV1::SetTrack(const AliTRDtrackV1 * const track)
 {
   // Add this track to the list of tracks stored in the tracker
   //
@@ -1950,13 +2155,13 @@ Int_t AliTRDtrackerV1::Clusters2TracksSM(Int_t sector, AliESDEvent *esd)
   
   Int_t nTracks   = 0;
   Int_t nChambers = 0;
-  AliTRDtrackingChamber **stack = 0x0, *chamber = 0x0;
+  AliTRDtrackingChamber **stack = NULL, *chamber = NULL;
   for(int istack = 0; istack<AliTRDgeometry::kNstack; istack++){
     if(!(stack = fTrSec[sector].GetStack(istack))) continue;
     nChambers = 0;
     for(int ilayer=0; ilayer<AliTRDgeometry::kNlayer; ilayer++){
       if(!(chamber = stack[ilayer])) continue;
-      if(chamber->GetNClusters() < fgNTimeBins * fReconstructor->GetRecoParam() ->GetFindableClusters()) continue;
+      if(chamber->GetNClusters() < fgNTimeBins * fkReconstructor->GetRecoParam() ->GetFindableClusters()) continue;
       nChambers++;
       //AliInfo(Form("sector %d stack %d layer %d clusters %d", sector, istack, ilayer, chamber->GetNClusters()));
     }
@@ -1976,7 +2181,7 @@ Int_t AliTRDtrackerV1::Clusters2TracksSM(Int_t sector, AliESDEvent *esd)
 }
 
 //____________________________________________________________________
-Int_t AliTRDtrackerV1::Clusters2TracksStack(AliTRDtrackingChamber **stack, TClonesArray *esdTrackList)
+Int_t AliTRDtrackerV1::Clusters2TracksStack(AliTRDtrackingChamber **stack, TClonesArray * const esdTrackList)
 {
   //
   // Make tracks in one TRD stack.
@@ -2005,8 +2210,8 @@ Int_t AliTRDtrackerV1::Clusters2TracksStack(AliTRDtrackingChamber **stack, TClon
   //
 
   const AliTRDCalDet *cal = AliTRDcalibDB::Instance()->GetT0Det();
-  AliTRDtrackingChamber *chamber = 0x0;
-  AliTRDtrackingChamber **ci = 0x0;
+  AliTRDtrackingChamber *chamber = NULL;
+  AliTRDtrackingChamber **ci = NULL;
   AliTRDseedV1 sseed[kMaxTracksStack*6]; // to be initialized
   Int_t pars[4]; // MakeSeeds parameters
 
@@ -2023,7 +2228,7 @@ Int_t AliTRDtrackerV1::Clusters2TracksStack(AliTRDtrackingChamber **stack, TClon
 
   // Build initial seeding configurations
   Double_t quality = BuildSeedingConfigs(stack, configs);
-  if(fReconstructor->GetStreamLevel(AliTRDReconstructor::kTracker) > 10){
+  if(fkReconstructor->GetRecoParam()->GetStreamLevel(AliTRDrecoParam::kTracker) > 10){
     AliInfo(Form("Plane config %d %d %d Quality %f"
     , configs[0], configs[1], configs[2], quality));
   }
@@ -2049,9 +2254,10 @@ Int_t AliTRDtrackerV1::Clusters2TracksStack(AliTRDtrackingChamber **stack, TClon
       pars[1] = ntracks;
       pars[2] = istack;
       ntracks = MakeSeeds(stack, &sseed[6*ntracks], pars);
+      //AliInfo(Form("Number of Tracks after iteration step %d: %d\n", iconf, ntracks));
       if(ntracks == kMaxTracksStack) break;
     }
-    if(fReconstructor->GetStreamLevel(AliTRDReconstructor::kTracker) > 10) AliInfo(Form("Candidate TRD tracks %d in iteration %d.", ntracks, fSieveSeeding));
+    AliDebug(2, Form("Candidate TRD tracks %d in iteration %d.", ntracks, fSieveSeeding));
     
     if(!ntracks) break;
     
@@ -2071,7 +2277,7 @@ Int_t AliTRDtrackerV1::Clusters2TracksStack(AliTRDtrackingChamber **stack, TClon
     
     // Sieve clusters in decreasing order of track quality
     Double_t trackParams[7];
-    //                 AliTRDseedV1 *lseed = 0x0;
+    //                 AliTRDseedV1 *lseed = NULL;
     Int_t jSieve = 0, candidates;
     do{
       //AliInfo(Form("\t\tITER = %i ", jSieve));
@@ -2162,18 +2368,17 @@ Int_t AliTRDtrackerV1::Clusters2TracksStack(AliTRDtrackingChamber **stack, TClon
         Int_t ich = 0; while(!(chamber = stack[ich])) ich++;
         trackParams[6] = fGeom->GetSector(chamber->GetDetector());/* *alpha+shift;     // Supermodule*/
 
-        if(fReconstructor->GetStreamLevel(AliTRDReconstructor::kTracker) > 1){
+        if(fkReconstructor->GetRecoParam()->GetStreamLevel(AliTRDrecoParam::kTracker) > 1 && fkReconstructor->IsDebugStreaming()){
           //AliInfo(Form("Track %d [%d] nlayers %d trackQuality = %e nused %d, yref = %3.3f", itrack, trackIndex, nlayers, fTrackQuality[trackIndex], nused, trackParams[1]));
 
           AliTRDseedV1 *dseed[6];
           for(Int_t iseed = AliTRDgeometry::kNlayer; iseed--;) dseed[iseed] = new AliTRDseedV1(lseed[iseed]);
 
           //Int_t eventNrInFile = esd->GetEventNumberInFile();
-          //AliInfo(Form("Number of clusters %d.", nclusters));
           Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
           Int_t trackNumber = AliTRDtrackerDebug::GetTrackNumber();
           Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
-          TTreeSRedirector &cstreamer = *fReconstructor->GetDebugStream(AliTRDReconstructor::kTracker);
+          TTreeSRedirector &cstreamer = *fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
           cstreamer << "Clusters2TracksStack"
               << "EventNumber="                << eventNumber
               << "TrackNumber="                << trackNumber
@@ -2202,7 +2407,7 @@ Int_t AliTRDtrackerV1::Clusters2TracksStack(AliTRDtrackingChamber **stack, TClon
 
         AliTRDtrackV1 *track = MakeTrack(&sseed[trackIndex*kNPlanes], trackParams);
         if(!track){
-          AliWarning("Fail to build a TRD Track.");
+          AliDebug(1, "Track building failed.");
           continue;
         }
       
@@ -2212,7 +2417,7 @@ Int_t AliTRDtrackerV1::Clusters2TracksStack(AliTRDtrackingChamber **stack, TClon
         esdTrack->SetLabel(track->GetLabel());
         track->UpdateESDtrack(esdTrack);
         // write ESD-friends if neccessary
-        if (fReconstructor->GetStreamLevel(AliTRDReconstructor::kTracker) > 0){
+        if (fkReconstructor->GetRecoParam()->GetStreamLevel(AliTRDrecoParam::kTracker) > 0){
           AliTRDtrackV1 *calibTrack = new AliTRDtrackV1(*track);
           calibTrack->SetOwner();
           esdTrack->AddCalibObject(calibTrack);
@@ -2228,19 +2433,19 @@ Int_t AliTRDtrackerV1::Clusters2TracksStack(AliTRDtrackingChamber **stack, TClon
     // increment counters
     ntracks2 += ntracks1;
 
-    if(fReconstructor->IsHLT()) break;
+    if(fkReconstructor->IsHLT()) break;
     fSieveSeeding++;
 
     // Rebuild plane configurations and indices taking only unused clusters into account
     quality = BuildSeedingConfigs(stack, configs);
-    if(quality < 1.E-7) break; //fReconstructor->GetRecoParam() ->GetPlaneQualityThreshold()) break;
+    if(quality < 1.E-7) break; //fkReconstructor->GetRecoParam() ->GetPlaneQualityThreshold()) break;
     
     for(Int_t ip = 0; ip < kNPlanes; ip++){ 
       if(!(chamber = stack[ip])) continue;
       chamber->Build(fGeom, cal);//Indices(fSieveSeeding);
     }
 
-    if(fReconstructor->GetStreamLevel(AliTRDReconstructor::kTracker) > 10){ 
+    if(fkReconstructor->GetRecoParam()->GetStreamLevel(AliTRDrecoParam::kTracker) > 10){ 
       AliInfo(Form("Sieve level %d Plane config %d %d %d Quality %f", fSieveSeeding, configs[0], configs[1], configs[2], quality));
     }
   } while(fSieveSeeding<10); // end stack clusters sieve
@@ -2280,7 +2485,7 @@ Double_t AliTRDtrackerV1::BuildSeedingConfigs(AliTRDtrackingChamber **stack, Int
   // 
 
   Double_t chamberQ[kNPlanes];memset(chamberQ, 0, kNPlanes*sizeof(Double_t));
-  AliTRDtrackingChamber *chamber = 0x0;
+  AliTRDtrackingChamber *chamber = NULL;
   for(int iplane=0; iplane<kNPlanes; iplane++){
     if(!(chamber = stack[iplane])) continue;
     chamberQ[iplane] = (chamber = stack[iplane]) ?  chamber->GetQuality() : 0.;
@@ -2303,59 +2508,70 @@ Double_t AliTRDtrackerV1::BuildSeedingConfigs(AliTRDtrackingChamber **stack, Int
 }
 
 //____________________________________________________________________
-Int_t AliTRDtrackerV1::MakeSeeds(AliTRDtrackingChamber **stack, AliTRDseedV1 *sseed, Int_t *ipar)
+Int_t AliTRDtrackerV1::MakeSeeds(AliTRDtrackingChamber **stack, AliTRDseedV1 * const sseed, const Int_t * const ipar)
 {
-  //
-  // Make tracklet seeds in the TRD stack.
-  //
-  // Parameters :
-  //   layers : Array of stack propagation layers containing clusters
-  //   sseed  : Array of empty tracklet seeds. On exit they are filled.
-  //   ipar   : Control parameters:
-  //       ipar[0] -> seeding chambers configuration
-  //       ipar[1] -> stack index
-  //       ipar[2] -> number of track candidates found so far
-  //
-  // Output :
-  //   Number of tracks candidates found.
-  // 
-  // Detailed description
-  //
-  // The following steps are performed:
-  // 1. Select seeding layers from seeding chambers
-  // 2. Select seeding clusters from the seeding AliTRDpropagationLayerStack.
-  //   The clusters are taken from layer 3, layer 0, layer 1 and layer 2, in
-  //   this order. The parameters controling the range of accepted clusters in
-  //   layer 0, 1, and 2 are defined in AliTRDchamberTimeBin::BuildCond().
-  // 3. Helix fit of the cluster set. (see AliTRDtrackerFitter::FitRieman(AliTRDcluster**))
-  // 4. Initialize seeding tracklets in the seeding chambers.
-  // 5. Filter 0.
-  //   Chi2 in the Y direction less than threshold ... (1./(3. - sLayer))
-  //   Chi2 in the Z direction less than threshold ... (1./(3. - sLayer))
-  // 6. Attach clusters to seeding tracklets and find linear approximation of
-  //   the tracklet (see AliTRDseedV1::AttachClustersIter()). The number of used
-  //   clusters used by current seeds should not exceed ... (25).
-  // 7. Filter 1.
-  //   All 4 seeding tracklets should be correctly constructed (see
-  //   AliTRDseedV1::AttachClustersIter())
-  // 8. Helix fit of the seeding tracklets
-  // 9. Filter 2.
-  //   Likelihood calculation of the fit. (See AliTRDtrackerV1::CookLikelihood() for details)
-  // 10. Extrapolation of the helix fit to the other 2 chambers:
-  //    a) Initialization of extrapolation tracklet with fit parameters
-  //    b) Helix fit of tracklets
-  //    c) Attach clusters and linear interpolation to extrapolated tracklets
-  //    d) Helix fit of tracklets
-  // 11. Improve seeding tracklets quality by reassigning clusters.
-  //      See AliTRDtrackerV1::ImproveSeedQuality() for details.
-  // 12. Helix fit of all 6 seeding tracklets and chi2 calculation
-  // 13. Hyperplane fit and track quality calculation. See AliTRDtrackerFitter::FitHyperplane() for details.
-  // 14. Cooking labels for tracklets. Should be done only for MC
-  // 15. Register seeds.
-  //
-
-  AliTRDtrackingChamber *chamber = 0x0;
-  AliTRDcluster *c[kNSeedPlanes] = {0x0, 0x0, 0x0, 0x0}; // initilize seeding clusters
+//
+// Seed tracklets and build candidate TRD tracks. The procedure is used during barrel tracking to account for tracks which are 
+// either missed by TPC prolongation or conversions inside the TRD volume. 
+// For stand alone tracking the procedure is used to estimate all tracks measured by TRD. 
+//
+// Parameters :
+//   layers : Array of stack propagation layers containing clusters
+//   sseed  : Array of empty tracklet seeds. On exit they are filled.
+//   ipar   : Control parameters:
+//       ipar[0] -> seeding chambers configuration
+//       ipar[1] -> stack index
+//       ipar[2] -> number of track candidates found so far
+//
+// Output :
+//   Number of tracks candidates found.
+// 
+// The following steps are performed:
+// 1. Build seeding layers by collapsing all time bins from each of the four seeding chambers along the 
+// radial coordinate. See AliTRDtrackingChamber::GetSeedingLayer() for details. The chambers selection for seeding
+// is described in AliTRDtrackerV1::Clusters2TracksStack().
+// 2. Using the seeding clusters from the seeding layer (step 1) build combinatorics using the following algorithm:
+// - for each seeding cluster in the lower seeding layer find
+// - all seeding clusters in the upper seeding layer inside a road defined by a given phi angle. The angle 
+//   is calculated on the minimum pt of tracks from vertex accesible to the stand alone tracker.
+// - for each pair of two extreme seeding clusters select middle upper cluster using roads defined externally by the 
+//   reco params
+// - select last seeding cluster as the nearest to the linear approximation of the track described by the first three
+//   seeding clusters.
+//   The implementation of road calculation and cluster selection can be found in the functions AliTRDchamberTimeBin::BuildCond()
+//   and AliTRDchamberTimeBin::GetClusters().   
+// 3. Helix fit of the seeding clusters set. (see AliTRDtrackerFitter::FitRieman(AliTRDcluster**)). No tilt correction is 
+//    performed at this level 
+// 4. Initialize seeding tracklets in the seeding chambers.
+// 5. *Filter 0* Chi2 cut on the Y and Z directions. The threshold is set externally by the reco params.
+// 6. Attach (true) clusters to seeding tracklets (see AliTRDseedV1::AttachClusters()) and fit tracklet (see 
+//    AliTRDseedV1::Fit()). The number of used clusters used by current seeds should not exceed ... (25).
+// 7. *Filter 1* Check if all 4 seeding tracklets are correctly constructed.
+// 8. Helix fit of the clusters from the seeding tracklets with tilt correction. Refit tracklets using the new 
+//    approximation of the track.
+// 9. *Filter 2* Calculate likelihood of the track. (See AliTRDtrackerV1::CookLikelihood()). The following quantities are
+//    checked against the Riemann fit:
+//      - position resolution in y
+//      - angular resolution in the bending plane
+//      - likelihood of the number of clusters attached to the tracklet
+// 10. Extrapolation of the helix fit to the other 2 chambers *non seeding* chambers:
+//      - Initialization of extrapolation tracklets with the fit parameters
+//      - Attach clusters to extrapolated tracklets
+//      - Helix fit of tracklets
+// 11. Improve seeding tracklets quality by reassigning clusters based on the last parameters of the track
+//      See AliTRDtrackerV1::ImproveSeedQuality() for details.
+// 12. Helix fit of all 6 seeding tracklets and chi2 calculation
+// 13. Hyperplane fit and track quality calculation. See AliTRDtrackerFitter::FitHyperplane() for details.
+// 14. Cooking labels for tracklets. Should be done only for MC
+// 15. Register seeds.
+//
+// Authors:
+//   Marian Ivanov <M.Ivanov@gsi.de>
+//   Alexandru Bercuci <A.Bercuci@gsi.de>
+//   Markus Fasel <M.Fasel@gsi.de>
+
+  AliTRDtrackingChamber *chamber = NULL;
+  AliTRDcluster *c[kNSeedPlanes] = {NULL, NULL, NULL, NULL}; // initilize seeding clusters
   AliTRDseedV1 *cseed = &sseed[0]; // initialize tracklets for first track
   Int_t ncl, mcl; // working variable for looping over clusters
   Int_t index[AliTRDchamberTimeBin::kMaxClustersLayer], jndex[AliTRDchamberTimeBin::kMaxClustersLayer];
@@ -2364,7 +2580,7 @@ Int_t AliTRDtrackerV1::MakeSeeds(AliTRDtrackingChamber **stack, AliTRDseedV1 *ss
   // chi2[1] = tracklet chi2 on the R direction
   Double_t chi2[4];
 
-  // this should be data member of AliTRDtrack
+  // this should be data member of AliTRDtrack TODO
   Double_t seedQuality[kMaxTracksStack];
   
   // unpack control parameters
@@ -2372,14 +2588,14 @@ Int_t AliTRDtrackerV1::MakeSeeds(AliTRDtrackingChamber **stack, AliTRDseedV1 *ss
   Int_t ntracks = ipar[1];
   Int_t istack  = ipar[2];
   Int_t planes[kNSeedPlanes]; GetSeedingConfig(config, planes);        
-  Int_t planesExt[kNPlanes-kNSeedPlanes];         GetExtrapolationConfig(config, planesExt);
+  Int_t planesExt[kNPlanes-kNSeedPlanes]; GetExtrapolationConfig(config, planesExt);
 
 
   // Init chambers geometry
   Double_t hL[kNPlanes];       // Tilting angle
   Float_t padlength[kNPlanes]; // pad lenghts
   Float_t padwidth[kNPlanes];  // pad widths
-  AliTRDpadPlane *pp = 0x0;
+  AliTRDpadPlane *pp = NULL;
   for(int iplane=0; iplane<kNPlanes; iplane++){
     pp                = fGeom->GetPadPlane(iplane, istack);
     hL[iplane]        = TMath::Tan(TMath::DegToRad()*pp->GetTiltingAngle());
@@ -2388,29 +2604,30 @@ Int_t AliTRDtrackerV1::MakeSeeds(AliTRDtrackingChamber **stack, AliTRDseedV1 *ss
   }
   
   // Init anode wire position for chambers
-  Double_t x0[kNPlanes] = {300.2, 312.8, 325.4, 338.0, 350.6, 363.2},       // anode wire position
+  Double_t x0[kNPlanes],       // anode wire position
            driftLength = .5*AliTRDgeometry::AmThick() - AliTRDgeometry::DrThick(); // drift length
-  TGeoHMatrix *matrix = 0x0;
+  TGeoHMatrix *matrix = NULL;
   Double_t loc[] = {AliTRDgeometry::AnodePos(), 0., 0.};
   Double_t glb[] = {0., 0., 0.};
   AliTRDtrackingChamber **cIter = &stack[0];
-  for(int iLayer=kNPlanes; iLayer--; cIter++){
+  for(int iLayer=0; iLayer<kNPlanes; iLayer++,cIter++){
     if(!(*cIter)) continue;
-    if(!(matrix = fGeom->GetClusterMatrix((*cIter)->GetDetector()))) continue;
+    if(!(matrix = fGeom->GetClusterMatrix((*cIter)->GetDetector()))){ 
+      continue;
+      x0[iLayer] = fgkX0[iLayer];
+    }
     matrix->LocalToMaster(loc, glb);
     x0[iLayer] = glb[0];
   }
 
-  if(fReconstructor->GetStreamLevel(AliTRDReconstructor::kTracker) > 10){
-    AliInfo(Form("Making seeds Stack[%d] Config[%d] Tracks[%d]...", istack, config, ntracks));
-  }
+  AliDebug(2, Form("Making seeds Stack[%d] Config[%d] Tracks[%d]...", istack, config, ntracks));
 
   // Build seeding layers
   ResetSeedTB();
   Int_t nlayers = 0;
   for(int isl=0; isl<kNSeedPlanes; isl++){ 
     if(!(chamber = stack[planes[isl]])) continue;
-    if(!chamber->GetSeedingLayer(fSeedTB[isl], fGeom, fReconstructor)) continue;
+    if(!chamber->GetSeedingLayer(fSeedTB[isl], fGeom, fkReconstructor)) continue;
     nlayers++;
   }
   if(nlayers < kNSeedPlanes) return ntracks;
@@ -2429,9 +2646,9 @@ Int_t AliTRDtrackerV1::MakeSeeds(AliTRDtrackingChamber **stack, AliTRDseedV1 *ss
       c[0] = (*fSeedTB[0])[index[jcl++]];
       if(!c[0]) continue;
       Double_t dx    = c[3]->GetX() - c[0]->GetX();
-      Double_t theta = (c[3]->GetZ() - c[0]->GetZ())/dx;
-      Double_t phi   = (c[3]->GetY() - c[0]->GetY())/dx;
-      fSeedTB[1]->BuildCond(c[0], cond1, 1, theta, phi);
+      Double_t dzdx = (c[3]->GetZ() - c[0]->GetZ())/dx;
+      Double_t dydx   = (c[3]->GetY() - c[0]->GetY())/dx;
+      fSeedTB[1]->BuildCond(c[0], cond1, 1, dzdx, dydx);
       fSeedTB[1]->GetClusters(cond1, jndex, mcl);
       //printf("Found c[0] candidates 1 %d\n", mcl);
 
@@ -2439,34 +2656,37 @@ Int_t AliTRDtrackerV1::MakeSeeds(AliTRDtrackingChamber **stack, AliTRDseedV1 *ss
       while(kcl<mcl) {
         c[1] = (*fSeedTB[1])[jndex[kcl++]];
         if(!c[1]) continue;
-        fSeedTB[2]->BuildCond(c[1], cond2, 2, theta, phi);
+        fSeedTB[2]->BuildCond(c[1], cond2, 2, dzdx, dydx);
         c[2] = fSeedTB[2]->GetNearestCluster(cond2);
         //printf("Found c[1] candidate 2 %p\n", c[2]);
         if(!c[2]) continue;
-              
-        //                             AliInfo("Seeding clusters found. Building seeds ...");
-        //                             for(Int_t i = 0; i < kNSeedPlanes; i++) printf("%i. coordinates: x = %6.3f, y = %6.3f, z = %6.3f\n", i, c[i]->GetX(), c[i]->GetY(), c[i]->GetZ());
+
+               AliDebug(3, Form("Seeding clusters\n 0[%6.3f %6.3f %6.3f]\n 1[%6.3f %6.3f %6.3f]\n 2[%6.3f %6.3f %6.3f]\n 3[%6.3f %6.3f %6.3f].",
+          c[0]->GetX(), c[0]->GetY(), c[0]->GetZ(),
+          c[1]->GetX(), c[1]->GetY(), c[1]->GetZ(),
+          c[2]->GetX(), c[2]->GetY(), c[2]->GetZ(),
+          c[3]->GetX(), c[3]->GetY(), c[3]->GetZ()));
               
         for (Int_t il = 0; il < kNPlanes; il++) cseed[il].Reset();
       
         FitRieman(c, chi2);
       
         AliTRDseedV1 *tseed = &cseed[0];
-        AliTRDtrackingChamber **cIter1 = &stack[0];
-        for(int iLayer=0; iLayer<kNPlanes; iLayer++, tseed++, cIter1++){
-          Int_t det = (*cIter1) ? (*cIter1)->GetDetector() : -1;
+        cIter = &stack[0];
+        for(int iLayer=0; iLayer<kNPlanes; iLayer++, tseed++, cIter++){
+          Int_t det = (*cIter) ? (*cIter)->GetDetector() : -1;
           tseed->SetDetector(det);
           tseed->SetTilt(hL[iLayer]);
           tseed->SetPadLength(padlength[iLayer]);
           tseed->SetPadWidth(padwidth[iLayer]);
-          tseed->SetReconstructor(fReconstructor);
+          tseed->SetReconstructor(fkReconstructor);
           tseed->SetX0(det<0 ? fR[iLayer]+driftLength : x0[iLayer]);
           tseed->Init(GetRiemanFitter());
           tseed->SetStandAlone(kTRUE);
         }
       
         Bool_t isFake = kFALSE;
-        if(fReconstructor->GetStreamLevel(AliTRDReconstructor::kTracker) >= 2){
+        if(fkReconstructor->GetRecoParam()->GetStreamLevel(AliTRDrecoParam::kTracker) >= 2 && fkReconstructor->IsDebugStreaming()){
           if (c[0]->GetLabel(0) != c[3]->GetLabel(0)) isFake = kTRUE;
           if (c[1]->GetLabel(0) != c[3]->GetLabel(0)) isFake = kTRUE;
           if (c[2]->GetLabel(0) != c[3]->GetLabel(0)) isFake = kTRUE;
@@ -2479,7 +2699,7 @@ Int_t AliTRDtrackerV1::MakeSeeds(AliTRDtrackingChamber **stack, AliTRDseedV1 *ss
           Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
           Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
           AliRieman *rim = GetRiemanFitter();
-          TTreeSRedirector &cs0 = *fReconstructor->GetDebugStream(AliTRDReconstructor::kTracker);
+          TTreeSRedirector &cs0 = *fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
           cs0 << "MakeSeeds0"
               <<"EventNumber="         << eventNumber
               <<"CandidateNumber="     << candidateNumber
@@ -2509,41 +2729,55 @@ Int_t AliTRDtrackerV1::MakeSeeds(AliTRDtrackingChamber **stack, AliTRDseedV1 *ss
               <<"RiemanFitter.="               << rim
               <<"\n";
         }
-        if(chi2[0] > fReconstructor->GetRecoParam() ->GetChi2Z()/*7./(3. - sLayer)*//*iter*/){
-//          //AliInfo(Form("Failed chi2 filter on chi2Z [%f].", chi2[0]));
+        if(chi2[0] > fkReconstructor->GetRecoParam() ->GetChi2Z()/*7./(3. - sLayer)*//*iter*/){
+          AliDebug(3, Form("Filter on chi2Z [%f].", chi2[0]));
           AliTRDtrackerDebug::SetCandidateNumber(AliTRDtrackerDebug::GetCandidateNumber() + 1);
           continue;
         }
-        if(chi2[1] > fReconstructor->GetRecoParam() ->GetChi2Y()/*1./(3. - sLayer)*//*iter*/){
-//          //AliInfo(Form("Failed chi2 filter on chi2Y [%f].", chi2[1]));
+        if(chi2[1] > fkReconstructor->GetRecoParam() ->GetChi2Y()/*1./(3. - sLayer)*//*iter*/){
+          AliDebug(3, Form("Filter on chi2Y [%f].", chi2[1]));
           AliTRDtrackerDebug::SetCandidateNumber(AliTRDtrackerDebug::GetCandidateNumber() + 1);
           continue;
         }
         //AliInfo("Passed chi2 filter.");
       
         // try attaching clusters to tracklets
-        Int_t mlayers = 0;
+        Int_t mlayers = 0; 
+        AliTRDcluster *cl = NULL;
         for(int iLayer=0; iLayer<kNSeedPlanes; iLayer++){
           Int_t jLayer = planes[iLayer];
+          Int_t nNotInChamber = 0;
           if(!cseed[jLayer].AttachClusters(stack[jLayer], kTRUE)) continue;
-          cseed[jLayer].UpdateUsed();
-          if(!cseed[jLayer].IsOK()) continue;
+          if(/*fkReconstructor->IsHLT()*/kFALSE){ 
+            cseed[jLayer].UpdateUsed();
+            if(!cseed[jLayer].IsOK()) continue;
+          }else{
+            cseed[jLayer].Fit();
+            cseed[jLayer].UpdateUsed();
+            cseed[jLayer].ResetClusterIter();
+            while((cl = cseed[jLayer].NextCluster())){
+              if(!cl->IsInChamber()) nNotInChamber++;
+            }
+            //printf("clusters[%d], used[%d], not in chamber[%d]\n", cseed[jLayer].GetN(), cseed[jLayer].GetNUsed(), nNotInChamber);
+            if(cseed[jLayer].GetN() - (cseed[jLayer].GetNUsed() + nNotInChamber) < 5) continue; // checking for Cluster which are not in chamber is a much stronger restriction on real data
+          }
           mlayers++;
         }
 
         if(mlayers < kNSeedPlanes){ 
-          //AliInfo(Form("Failed updating all seeds %d [%d].", mlayers, kNSeedPlanes));
+          AliDebug(2, Form("Found only %d tracklets out of %d. Skip.", mlayers, kNSeedPlanes));
           AliTRDtrackerDebug::SetCandidateNumber(AliTRDtrackerDebug::GetCandidateNumber() + 1);
           continue;
         }
 
         // temporary exit door for the HLT
-        if(fReconstructor->IsHLT()){ 
+        if(fkReconstructor->IsHLT()){ 
           // attach clusters to extrapolation chambers
           for(int iLayer=0; iLayer<kNPlanes-kNSeedPlanes; iLayer++){
             Int_t jLayer = planesExt[iLayer];
             if(!(chamber = stack[jLayer])) continue;
-            cseed[jLayer].AttachClusters(chamber, kTRUE);
+            if(!cseed[jLayer].AttachClusters(chamber, kTRUE)) continue;
+            cseed[jLayer].Fit();
           }
           fTrackQuality[ntracks] = 1.; // dummy value
           ntracks++;
@@ -2562,8 +2796,8 @@ Int_t AliTRDtrackerV1::MakeSeeds(AliTRDtrackingChamber **stack, AliTRDseedV1 *ss
         }
         Double_t like = CookLikelihood(&cseed[0], planes); // to be checked
       
-        if (TMath::Log(1.E-9 + like) < fReconstructor->GetRecoParam() ->GetTrackLikelihood()){
-          //AliInfo(Form("Failed likelihood %f[%e].", TMath::Log(1.E-9 + like), like));
+        if (TMath::Log(1.E-9 + like) < fkReconstructor->GetRecoParam() ->GetTrackLikelihood()){
+          AliDebug(3, Form("Filter on likelihood %f[%e].", TMath::Log(1.E-9 + like), like));
           AliTRDtrackerDebug::SetCandidateNumber(AliTRDtrackerDebug::GetCandidateNumber() + 1);
           continue;
         }
@@ -2574,6 +2808,7 @@ Int_t AliTRDtrackerV1::MakeSeeds(AliTRDtrackingChamber **stack, AliTRDseedV1 *ss
         fSeedLayer[ntracks]  = config;/*sLayer;*/
       
         // attach clusters to the extrapolation seeds
+        Int_t elayers(0);
         for(int iLayer=0; iLayer<kNPlanes-kNSeedPlanes; iLayer++){
           Int_t jLayer = planesExt[iLayer];
           if(!(chamber = stack[jLayer])) continue;
@@ -2587,12 +2822,13 @@ Int_t AliTRDtrackerV1::MakeSeeds(AliTRDtrackingChamber **stack, AliTRDseedV1 *ss
           cseed[jLayer] = pseed;
           FitTiltedRieman(cseed,  kTRUE);
           cseed[jLayer].Fit(kTRUE);
+          elayers++;
         }
       
         // AliInfo("Extrapolation done.");
         // Debug Stream containing all the 6 tracklets
-        if(fReconstructor->GetStreamLevel(AliTRDReconstructor::kTracker) >= 2){
-          TTreeSRedirector &cstreamer = *fReconstructor->GetDebugStream(AliTRDReconstructor::kTracker);
+        if(fkReconstructor->GetRecoParam()->GetStreamLevel(AliTRDrecoParam::kTracker) >= 2 && fkReconstructor->IsDebugStreaming()){
+          TTreeSRedirector &cstreamer = *fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
           TLinearFitter *tiltedRieman = GetTiltedRiemanFitter();
           Int_t eventNumber            = AliTRDtrackerDebug::GetEventNumber();
           Int_t candidateNumber        = AliTRDtrackerDebug::GetCandidateNumber();
@@ -2609,9 +2845,17 @@ Int_t AliTRDtrackerV1::MakeSeeds(AliTRDtrackingChamber **stack, AliTRDseedV1 *ss
               << "\n";
         }
               
-        if(fReconstructor->GetRecoParam()->HasImproveTracklets() && ImproveSeedQuality(stack, cseed) < 4){
-          AliTRDtrackerDebug::SetCandidateNumber(AliTRDtrackerDebug::GetCandidateNumber() + 1);
-          continue;
+        if(fkReconstructor->GetRecoParam()->HasImproveTracklets()){ 
+          AliTRDseedV1 bseed[AliTRDgeometry::kNlayer];
+          for(Int_t jLayer=AliTRDgeometry::kNlayer; jLayer--;) bseed[jLayer] = cseed[jLayer];
+
+          if(ImproveSeedQuality(stack, cseed) < mlayers+elayers){
+            AliTRDtrackerDebug::SetCandidateNumber(AliTRDtrackerDebug::GetCandidateNumber() + 1);
+            AliDebug(3, "Filter on improve seeds.");
+          } else {
+            // store results
+            for(Int_t jLayer=AliTRDgeometry::kNlayer; jLayer--;) cseed[jLayer] = bseed[jLayer];
+          }
         }
         //AliInfo("Improve seed quality done.");
       
@@ -2622,8 +2866,8 @@ Int_t AliTRDtrackerV1::MakeSeeds(AliTRDtrackingChamber **stack, AliTRDseedV1 *ss
       
         // do the final track fitting (Once with vertex constraint and once without vertex constraint)
         Double_t chi2Vals[3];
-        chi2Vals[0] = FitTiltedRieman(&cseed[0], kFALSE);
-        if(fReconstructor->GetRecoParam()->IsVertexConstrained())
+        chi2Vals[0] = FitTiltedRieman(&cseed[0], kTRUE);
+        if(fkReconstructor->GetRecoParam()->IsVertexConstrained())
           chi2Vals[1] = FitTiltedRiemanConstraint(&cseed[0], GetZ()); // Do Vertex Constrained fit if desired
         else
           chi2Vals[1] = 1.;
@@ -2633,8 +2877,8 @@ Int_t AliTRDtrackerV1::MakeSeeds(AliTRDtrackingChamber **stack, AliTRDseedV1 *ss
         fTrackQuality[ntracks] = CalculateTrackLikelihood(&cseed[0], &chi2Vals[0]);
         //AliInfo("Hyperplane fit done\n");
                   
-        if(fReconstructor->GetStreamLevel(AliTRDReconstructor::kTracker) >= 2){
-          TTreeSRedirector &cstreamer = *fReconstructor->GetDebugStream(AliTRDReconstructor::kTracker);
+        if(fkReconstructor->GetRecoParam()->GetStreamLevel(AliTRDrecoParam::kTracker) >= 2 && fkReconstructor->IsDebugStreaming()){
+          TTreeSRedirector &cstreamer = *fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
           Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
           Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
           TLinearFitter *fitterTC = GetTiltedRiemanFitterConstraint();
@@ -2677,64 +2921,76 @@ Int_t AliTRDtrackerV1::MakeSeeds(AliTRDtrackingChamber **stack, AliTRDseedV1 *ss
 }
 
 //_____________________________________________________________________________
-AliTRDtrackV1* AliTRDtrackerV1::MakeTrack(AliTRDseedV1 *seeds, Double_t *params)
+AliTRDtrackV1* AliTRDtrackerV1::MakeTrack(AliTRDseedV1 * const seeds, Double_t *params)
 {
-  //
-  // Build a TRD track out of tracklet candidates
-  //
-  // Parameters :
-  //   seeds  : array of tracklets
-  //   params : track parameters (see MakeSeeds() function body for a detailed description)
-  //
-  // Output :
-  //   The TRD track.
-  //
-  // Detailed description
-  //
-  // To be discussed with Marian !!
-  //
-
+//
+// Build a TRD track out of tracklet candidates
+//
+// Parameters :
+//   seeds  : array of tracklets
+//   params : array of track parameters as they are estimated by stand alone tracker. 7 elements.
+//     [0] - radial position of the track at reference point
+//     [1] - y position of the fit at [0]
+//     [2] - z position of the fit at [0]
+//     [3] - snp of the first tracklet
+//     [4] - tgl of the first tracklet
+//     [5] - curvature of the Riemann fit - 1/pt
+//     [6] - sector rotation angle
+//
+// Output :
+//   The TRD track.
+//
+// Initialize the TRD track based on the parameters of the fit and a parametric covariance matrix 
+// (diagonal with constant variance terms TODO - correct parameterization) 
+// 
+// In case of HLT just register the tracklets in the tracker and return values of the Riemann fit. For the
+// offline case perform a full Kalman filter on the already found tracklets (see AliTRDtrackerV1::FollowBackProlongation() 
+// for details). Do also MC label calculation and PID if propagation successfully.
 
   Double_t alpha = AliTRDgeometry::GetAlpha();
   Double_t shift = AliTRDgeometry::GetAlpha()/2.0;
   Double_t c[15];
 
-  c[ 0] = 0.2;
-  c[ 1] = 0.0; c[ 2] = 2.0;
-  c[ 3] = 0.0; c[ 4] = 0.0; c[ 5] = 0.02;
-  c[ 6] = 0.0; c[ 7] = 0.0; c[ 8] = 0.0;  c[ 9] = 0.1;
-  c[10] = 0.0; c[11] = 0.0; c[12] = 0.0;  c[13] = 0.0; c[14] = params[5]*params[5]*0.01;
+  c[ 0] = 0.2; // s^2_y
+  c[ 1] = 0.0; c[ 2] = 2.0; // s^2_z
+  c[ 3] = 0.0; c[ 4] = 0.0; c[ 5] = 0.02; // s^2_snp
+  c[ 6] = 0.0; c[ 7] = 0.0; c[ 8] = 0.0;  c[ 9] = 0.1; // s^2_tgl
+  c[10] = 0.0; c[11] = 0.0; c[12] = 0.0;  c[13] = 0.0; c[14] = params[5]*params[5]*0.01; // s^2_1/pt
 
   AliTRDtrackV1 track(seeds, &params[1], c, params[0], params[6]*alpha+shift);
   track.PropagateTo(params[0]-5.0);
-  AliTRDseedV1 *ptrTracklet = 0x0;
-  // Sign clusters
-  for (Int_t jLayer = 0; jLayer < AliTRDgeometry::kNlayer; jLayer++) {
-    ptrTracklet = &seeds[jLayer];
-    if(!ptrTracklet->IsOK()) continue;
-    if(TMath::Abs(ptrTracklet->GetYref(1) - ptrTracklet->GetYfit(1)) >= .2) continue; // check this condition with Marian
-  }
-  // 
-  if(fReconstructor->IsHLT()){ 
-    for(Int_t ip=0; ip<kNPlanes; ip++){
-      track.UnsetTracklet(ip);
-      ptrTracklet = SetTracklet(&seeds[ip]);
+  AliTRDseedV1 *ptrTracklet = NULL;
+
+  // skip Kalman filter for HLT
+  if(/*fkReconstructor->IsHLT()*/kFALSE){ 
+    for (Int_t jLayer = 0; jLayer < AliTRDgeometry::kNlayer; jLayer++) {
+      track.UnsetTracklet(jLayer);
+      ptrTracklet = &seeds[jLayer];
+      if(!ptrTracklet->IsOK()) continue;
+      if(TMath::Abs(ptrTracklet->GetYref(1) - ptrTracklet->GetYfit(1)) >= .2) continue; // check this condition with Marian
+      ptrTracklet = SetTracklet(ptrTracklet);
       ptrTracklet->UseClusters();
       track.SetTracklet(ptrTracklet, fTracklets->GetEntriesFast()-1);
     }
     AliTRDtrackV1 *ptrTrack = SetTrack(&track);
-    ptrTrack->SetReconstructor(fReconstructor);
+    ptrTrack->CookPID();
+    ptrTrack->CookLabel(.9);
+    ptrTrack->SetReconstructor(fkReconstructor);
     return ptrTrack;
   }
 
+  if(TMath::Abs(track.GetY())>1000) 
+    return NULL;
+
   track.ResetCovariance(1);
   Int_t nc = TMath::Abs(FollowBackProlongation(track));
-  if(fReconstructor->GetStreamLevel(AliTRDReconstructor::kTracker) > 5){
+  if(fkReconstructor->GetRecoParam()->GetStreamLevel(AliTRDrecoParam::kTracker) > 5 && fkReconstructor->IsDebugStreaming()){
     Int_t eventNumber          = AliTRDtrackerDebug::GetEventNumber();
     Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
     Double_t p[5]; // Track Params for the Debug Stream
     track.GetExternalParameters(params[0], p);
-    TTreeSRedirector &cs = *fReconstructor->GetDebugStream(AliTRDReconstructor::kTracker);
+    TTreeSRedirector &cs = *fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
     cs << "MakeTrack"
     << "EventNumber="     << eventNumber
     << "CandidateNumber=" << candidateNumber
@@ -2753,10 +3009,10 @@ AliTRDtrackV1* AliTRDtrackerV1::MakeTrack(AliTRDseedV1 *seeds, Double_t *params)
     << "track.=" << &track
     << "\n";
   }
-  if (nc < 30) return 0x0;
+  if (nc < 30) return NULL;
 
   AliTRDtrackV1 *ptrTrack = SetTrack(&track);
-  ptrTrack->SetReconstructor(fReconstructor);
+  ptrTrack->SetReconstructor(fkReconstructor);
   ptrTrack->CookLabel(.9);
   
   // computes PID for track
@@ -2794,66 +3050,87 @@ Int_t AliTRDtrackerV1::ImproveSeedQuality(AliTRDtrackingChamber **stack, AliTRDs
   //
   
   // make a local working copy
-  AliTRDtrackingChamber *chamber = 0x0;
-  AliTRDseedV1 bseed[6];
-  Int_t nLayers = 0;
-  for (Int_t jLayer = 0; jLayer < 6; jLayer++) bseed[jLayer] = cseed[jLayer];
-  
-  Float_t lastquality = 10000.0;
-  Float_t lastchi2    = 10000.0;
-  Float_t chi2        =  1000.0;
+  AliTRDtrackingChamber *chamber = NULL;
+  AliTRDseedV1 bseed[AliTRDgeometry::kNlayer];
+
+  Float_t quality(0.), 
+          lQuality[] = {1.e3, 1.e3, 1.e3, 1.e3, 1.e3, 1.e3};
+  Int_t rLayers(0);
+  for(Int_t jLayer=AliTRDgeometry::kNlayer; jLayer--;){ 
+    bseed[jLayer] = cseed[jLayer];
+    if(!bseed[jLayer].IsOK()) continue;
+    rLayers++;
+    lQuality[jLayer] = bseed[jLayer].GetQuality(kTRUE);
+    quality    += lQuality[jLayer];
+  }
+  Float_t chi2 = FitTiltedRieman(bseed, kTRUE);
 
   for (Int_t iter = 0; iter < 4; iter++) {
-    Float_t sumquality = 0.0;
-    Float_t squality[6];
-    Int_t   sortindexes[6];
-
-    for (Int_t jLayer = 0; jLayer < 6; jLayer++) {
-      squality[jLayer]  = bseed[jLayer].IsOK() ? bseed[jLayer].GetQuality(kTRUE) : 1000.;
-      sumquality += squality[jLayer];
-    }
-    if ((sumquality >= lastquality) || (chi2       >     lastchi2)) break;
-
-    nLayers = 0;
-    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];
+    AliDebug(2, Form("Iter[%d] Q[%f] chi2[%f]", iter, quality, chi2));
+
+    // Try better cluster set
+    Int_t nLayers(0); Float_t qualitynew(0.);
+    Int_t  indexes[6];
+    TMath::Sort(Int_t(AliTRDgeometry::kNlayer), lQuality, indexes, kFALSE);
+    for(Int_t jLayer=AliTRDgeometry::kNlayer; jLayer--;) {
+      Int_t bLayer = indexes[jLayer];
+      bseed[bLayer].Reset("c");
       if(!(chamber = stack[bLayer])) continue;
-      bseed[bLayer].AttachClusters(chamber, kTRUE);
+      if(!bseed[bLayer].AttachClusters(chamber, kTRUE)) continue;
       bseed[bLayer].Fit(kTRUE);
-      if(bseed[bLayer].IsOK()) nLayers++;
+      if(!bseed[bLayer].IsOK()) continue;
+      nLayers++;
+      lQuality[jLayer] = bseed[jLayer].GetQuality(kTRUE);
+      qualitynew    += lQuality[jLayer];
     }
+    if(rLayers > nLayers){
+      AliDebug(1, Form("Lost %d tracklets while improving.", rLayers-nLayers));
+      break;
+    } else rLayers=nLayers;
+
+    if(qualitynew >= quality){ 
+      AliDebug(4, Form("Quality worsen in iter[%d].", iter));
+      break;
+    } else quality = qualitynew;
+
+    // try improve track parameters
+    AliTRDseedV1 tseed[AliTRDgeometry::kNlayer];
+    for(Int_t jLayer=AliTRDgeometry::kNlayer; jLayer--;) tseed[jLayer]=bseed[jLayer];
+    Float_t chi2new = FitTiltedRieman(tseed, kTRUE);
+    if(chi2new > chi2){ 
+      AliDebug(4, Form("Chi2 worsen in iter[%d].", iter));
+      break;
+    } else chi2 = chi2new;
 
-    chi2 = FitTiltedRieman(bseed, kTRUE);
-    if(fReconstructor->GetStreamLevel(AliTRDReconstructor::kTracker) >= 7){
+    // store better tracklets
+    for(Int_t jLayer=AliTRDgeometry::kNlayer; jLayer--;) bseed[jLayer]=tseed[jLayer];
+
+
+    if(fkReconstructor->GetRecoParam()->GetStreamLevel(AliTRDrecoParam::kTracker) >= 7 && fkReconstructor->IsDebugStreaming()){
       Int_t eventNumber                = AliTRDtrackerDebug::GetEventNumber();
       Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
       TLinearFitter *tiltedRieman = GetTiltedRiemanFitter();
-      TTreeSRedirector &cstreamer = *fReconstructor->GetDebugStream(AliTRDReconstructor::kTracker);
+      TTreeSRedirector &cstreamer = *fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
       cstreamer << "ImproveSeedQuality"
-    << "EventNumber="          << eventNumber
-    << "CandidateNumber="      << candidateNumber
-    << "Iteration="                            << iter
-    << "S0.="                                                  << &bseed[0]
-    << "S1.="                                                  << &bseed[1]
-    << "S2.="                                                  << &bseed[2]
-    << "S3.="                                                  << &bseed[3]
-    << "S4.="                                                  << &bseed[4]
-    << "S5.="                                                  << &bseed[5]
-    << "FitterT.="                             << tiltedRieman
-    << "\n";
+        << "EventNumber="              << eventNumber
+        << "CandidateNumber="  << candidateNumber
+        << "Iteration="                                << iter
+        << "S0.="                                                      << &bseed[0]
+        << "S1.="                                                      << &bseed[1]
+        << "S2.="                                                      << &bseed[2]
+        << "S3.="                                                      << &bseed[3]
+        << "S4.="                                                      << &bseed[4]
+        << "S5.="                                                      << &bseed[5]
+        << "FitterT.="                         << tiltedRieman
+        << "\n";
     }
   } // Loop: iter
   // we are sure that at least 2 tracklets are OK !
-  return nLayers+2;
+  return rLayers;
 }
 
 //_________________________________________________________________________
-Double_t AliTRDtrackerV1::CalculateTrackLikelihood(AliTRDseedV1 *tracklets, Double_t *chi2){
+Double_t AliTRDtrackerV1::CalculateTrackLikelihood(const AliTRDseedV1 *const tracklets, Double_t *chi2){
   //
   // Calculates the Track Likelihood value. This parameter serves as main quality criterion for 
   // the track selection
@@ -2881,16 +3158,16 @@ Double_t AliTRDtrackerV1::CalculateTrackLikelihood(AliTRDseedV1 *tracklets, Doub
   chi2phi /= Float_t (nLayers - 2.0);
   
   Double_t likeChi2Z  = TMath::Exp(-chi2[2] * 0.14);                   // Chi2Z 
-  Double_t likeChi2TC = (fReconstructor->GetRecoParam() ->IsVertexConstrained()) ? 
+  Double_t likeChi2TC = (fkReconstructor->GetRecoParam()->IsVertexConstrained()) ? 
                                                                                        TMath::Exp(-chi2[1] * 0.677) : 1;                       // Constrained Tilted Riemann
-  Double_t likeChi2TR = TMath::Exp(-chi2[0] * 0.78);                   // Non-constrained Tilted Riemann
-  Double_t likeChi2Phi= TMath::Exp(-chi2phi * 3.23);
+  Double_t likeChi2TR = TMath::Exp(-chi2[0] * 0.0078);                 // Non-constrained Tilted Riemann
+  Double_t likeChi2Phi= TMath::Exp(-chi2phi * 3.23);//3.23
   Double_t trackLikelihood     = likeChi2Z * likeChi2TR * likeChi2Phi;
 
-  if(fReconstructor->GetStreamLevel(AliTRDReconstructor::kTracker) >= 2){
+  if(fkReconstructor->GetRecoParam()->GetStreamLevel(AliTRDrecoParam::kTracker) >= 2 && fkReconstructor->IsDebugStreaming()){
     Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
     Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
-    TTreeSRedirector &cstreamer = *fReconstructor->GetDebugStream(AliTRDReconstructor::kTracker);
+    TTreeSRedirector &cstreamer = *fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
     cstreamer << "CalculateTrackLikelihood0"
         << "EventNumber="                      << eventNumber
         << "CandidateNumber="  << candidateNumber
@@ -2901,7 +3178,7 @@ Double_t AliTRDtrackerV1::CalculateTrackLikelihood(AliTRDseedV1 *tracklets, Doub
         << "TrackLikelihood=" << trackLikelihood
         << "\n";
   }
-
+  
   return trackLikelihood;
 }
 
@@ -2933,7 +3210,7 @@ Double_t AliTRDtrackerV1::CookLikelihood(AliTRDseedV1 *cseed, Int_t planes[4])
   //
 
   // ratio of the total number of clusters/track which are expected to be found by the tracker.
-  const AliTRDrecoParam *fRecoPars = fReconstructor->GetRecoParam();
+  const AliTRDrecoParam *fRecoPars = fkReconstructor->GetRecoParam();
   
        Double_t chi2y = GetChi2Y(&cseed[0]);
   Double_t chi2z = GetChi2Z(&cseed[0]);
@@ -2949,24 +3226,23 @@ Double_t AliTRDtrackerV1::CookLikelihood(AliTRDseedV1 *cseed, Int_t planes[4])
 
   Double_t likea     = TMath::Exp(-sumda * fRecoPars->GetPhiSlope());
   Double_t likechi2y  = 0.0000000001;
-  if (fReconstructor->IsCosmic() || chi2y < fRecoPars->GetChi2YCut()) likechi2y += TMath::Exp(-TMath::Sqrt(chi2y) * fRecoPars->GetChi2YSlope());
+  if (fkReconstructor->IsCosmic() || chi2y < fRecoPars->GetChi2YCut()) likechi2y += TMath::Exp(-TMath::Sqrt(chi2y) * fRecoPars->GetChi2YSlope());
   Double_t likechi2z = TMath::Exp(-chi2z * fRecoPars->GetChi2ZSlope());
   Double_t likeN     = TMath::Exp(-(fRecoPars->GetNMeanClusters() - nclusters) / fRecoPars->GetNSigmaClusters());
   Double_t like      = likea * likechi2y * likechi2z * likeN;
 
-  //   AliInfo(Form("sumda(%f) chi2[0](%f) chi2[1](%f) likea(%f) likechi2y(%f) likechi2z(%f) nclusters(%d) likeN(%f)", sumda, chi2[0], chi2[1], likea, likechi2y, likechi2z, nclusters, likeN));
-  if(fReconstructor->GetStreamLevel(AliTRDReconstructor::kTracker) >= 2){
+  if(fkReconstructor->GetRecoParam()->GetStreamLevel(AliTRDrecoParam::kTracker) >= 2 && fkReconstructor->IsDebugStreaming()){
     Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
     Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
-    Int_t nTracklets = 0; Float_t mean_ncls = 0;
+    Int_t nTracklets = 0; Float_t meanNcls = 0;
     for(Int_t iseed=0; iseed < kNPlanes; iseed++){
        if(!cseed[iseed].IsOK()) continue;
        nTracklets++;
-       mean_ncls += cseed[iseed].GetN2();
+       meanNcls += cseed[iseed].GetN2();
     }
-    if(nTracklets) mean_ncls /= nTracklets;
+    if(nTracklets) meanNcls /= nTracklets;
     // The Debug Stream contains the seed 
-    TTreeSRedirector &cstreamer = *fReconstructor->GetDebugStream(AliTRDReconstructor::kTracker);
+    TTreeSRedirector &cstreamer = *fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
     cstreamer << "CookLikelihood"
         << "EventNumber="                      << eventNumber
         << "CandidateNumber=" << candidateNumber
@@ -2985,7 +3261,7 @@ Double_t AliTRDtrackerV1::CookLikelihood(AliTRDseedV1 *cseed, Int_t planes[4])
         << "nclusters="                                << nclusters
         << "likeN="                                            << likeN
         << "like="                                             << like
-        << "meanncls="        << mean_ncls
+        << "meanncls="        << meanNcls
         << "\n";
   }
 
@@ -3217,75 +3493,24 @@ void AliTRDtrackerV1::GetExtrapolationConfig(Int_t iconfig, Int_t planes[2])
 AliCluster* AliTRDtrackerV1::GetCluster(Int_t idx) const
 {
   Int_t ncls = fClusters->GetEntriesFast();
-  return idx >= 0 && idx < ncls ? (AliCluster*)fClusters->UncheckedAt(idx) : 0x0;
+  return idx >= 0 && idx < ncls ? (AliCluster*)fClusters->UncheckedAt(idx) : NULL;
 }
 
 //____________________________________________________________________
 AliTRDseedV1* AliTRDtrackerV1::GetTracklet(Int_t idx) const
 {
   Int_t ntrklt = fTracklets->GetEntriesFast();
-  return idx >= 0 && idx < ntrklt ? (AliTRDseedV1*)fTracklets->UncheckedAt(idx) : 0x0;
+  return idx >= 0 && idx < ntrklt ? (AliTRDseedV1*)fTracklets->UncheckedAt(idx) : NULL;
 }
 
 //____________________________________________________________________
 AliKalmanTrack* AliTRDtrackerV1::GetTrack(Int_t idx) const
 {
   Int_t ntrk = fTracks->GetEntriesFast();
-  return idx >= 0 && idx < ntrk ? (AliKalmanTrack*)fTracks->UncheckedAt(idx) : 0x0;
+  return idx >= 0 && idx < ntrk ? (AliKalmanTrack*)fTracks->UncheckedAt(idx) : NULL;
 }
 
-//____________________________________________________________________
-Float_t AliTRDtrackerV1::CalculateReferenceX(AliTRDseedV1 *tracklets){
-  //
-  // Calculates the reference x-position for the tilted Rieman fit defined as middle
-  // of the stack (middle between layers 2 and 3). For the calculation all the tracklets
-  // are taken into account
-  // 
-  // Parameters:       - Array of tracklets(AliTRDseedV1)
-  //
-  // Output:           - The reference x-position(Float_t)
-  //
-  Int_t nDistances = 0;
-  Float_t meanDistance = 0.;
-  Int_t startIndex = 5;
-  for(Int_t il =5; il > 0; il--){
-    if(tracklets[il].IsOK() && tracklets[il -1].IsOK()){
-      Float_t xdiff = tracklets[il].GetX0() - tracklets[il -1].GetX0();
-      meanDistance += xdiff;
-      nDistances++;
-    }
-    if(tracklets[il].IsOK()) startIndex = il;
-  }
-  if(tracklets[0].IsOK()) startIndex = 0;
-  if(!nDistances){
-    // We should normally never get here
-    Float_t xpos[2]; memset(xpos, 0, sizeof(Float_t) * 2);
-    Int_t iok = 0, idiff = 0;
-    // This attempt is worse and should be avoided:
-    // check for two chambers which are OK and repeat this without taking the mean value
-    // Strategy avoids a division by 0;
-    for(Int_t il = 5; il >= 0; il--){
-      if(tracklets[il].IsOK()){
-  xpos[iok] = tracklets[il].GetX0();
-  iok++;
-  startIndex = il;
-      }
-      if(iok) idiff++; // to get the right difference;
-      if(iok > 1) break;
-    }
-    if(iok > 1){
-      meanDistance = (xpos[0] - xpos[1])/idiff;
-    }
-    else{
-      // we have do not even have 2 layers which are OK? The we do not need to fit at all
-      return 331.;
-    }
-  }
-  else{
-    meanDistance /= nDistances;
-  }
-  return tracklets[startIndex].GetX0() + (2.5 - startIndex) * meanDistance - 0.5 * (AliTRDgeometry::AmThick() + AliTRDgeometry::DrThick());
-}
+
 
 // //_____________________________________________________________________________
 // Int_t AliTRDtrackerV1::Freq(Int_t n, const Int_t *inlist
@@ -3361,7 +3586,7 @@ void AliTRDtrackerV1::ResetSeedTB()
 
 
 //_____________________________________________________________________________
-Float_t AliTRDtrackerV1::GetChi2Y(AliTRDseedV1 *tracklets) const
+Float_t AliTRDtrackerV1::GetChi2Y(const AliTRDseedV1 * const tracklets) const
 {
   //   Calculates normalized chi2 in y-direction
   // chi2 = Sum chi2 / n_tracklets
@@ -3376,7 +3601,7 @@ Float_t AliTRDtrackerV1::GetChi2Y(AliTRDseedV1 *tracklets) const
 }
 
 //_____________________________________________________________________________
-Float_t AliTRDtrackerV1::GetChi2Z(AliTRDseedV1 *tracklets) const 
+Float_t AliTRDtrackerV1::GetChi2Z(const AliTRDseedV1 *const tracklets) const 
 {
   //   Calculates normalized chi2 in z-direction
   // chi2 = Sum chi2 / n_tracklets
@@ -3390,6 +3615,88 @@ Float_t AliTRDtrackerV1::GetChi2Z(AliTRDseedV1 *tracklets) const
   return n ? chi2/n : 0.;
 }
 
+//____________________________________________________________________
+Float_t AliTRDtrackerV1::CalculateReferenceX(const AliTRDseedV1 *const tracklets){
+       //
+       // Calculates the reference x-position for the tilted Rieman fit defined as middle
+       // of the stack (middle between layers 2 and 3). For the calculation all the tracklets
+       // are taken into account
+       //
+       // Parameters: - Array of tracklets(AliTRDseedV1)
+       //
+       // Output: - The reference x-position(Float_t)
+  // Only kept for compatibility with the old code
+       //
+       Int_t nDistances = 0;
+       Float_t meanDistance = 0.;
+       Int_t startIndex = 5;
+       for(Int_t il =5; il > 0; il--){
+       if(tracklets[il].IsOK() && tracklets[il -1].IsOK()){
+       Float_t xdiff = tracklets[il].GetX0() - tracklets[il -1].GetX0();
+           meanDistance += xdiff;
+           nDistances++;
+         }
+         if(tracklets[il].IsOK()) startIndex = il;
+       }
+       if(tracklets[0].IsOK()) startIndex = 0;
+       if(!nDistances){
+         // We should normally never get here
+         Float_t xpos[2]; memset(xpos, 0, sizeof(Float_t) * 2);
+         Int_t iok = 0, idiff = 0;
+         // This attempt is worse and should be avoided:
+         // check for two chambers which are OK and repeat this without taking the mean value
+         // Strategy avoids a division by 0;
+         for(Int_t il = 5; il >= 0; il--){
+           if(tracklets[il].IsOK()){
+             xpos[iok] = tracklets[il].GetX0();
+             iok++;
+             startIndex = il;
+           }
+           if(iok) idiff++; // to get the right difference;
+           if(iok > 1) break;
+         }
+         if(iok > 1){
+           meanDistance = (xpos[0] - xpos[1])/idiff;
+         }
+         else{
+           // we have do not even have 2 layers which are OK? The we do not need to fit at all
+           return 331.;
+       }
+       }
+       else{
+         meanDistance /= nDistances;
+       }
+       return tracklets[startIndex].GetX0() + (2.5 - startIndex) * meanDistance - 0.5 * (AliTRDgeometry::AmThick() + AliTRDgeometry::DrThick());
+}
+
+//_____________________________________________________________________________
+Double_t AliTRDtrackerV1::FitTiltedRiemanV1(AliTRDseedV1 *const tracklets){
+  //
+  // Track Fitter Function using the new class implementation of 
+  // the Rieman fit
+  //
+  AliTRDtrackFitterRieman fitter;
+  fitter.SetRiemanFitter(GetTiltedRiemanFitter());
+  fitter.Reset();
+  for(Int_t il = 0; il < AliTRDgeometry::kNlayer; il++) fitter.SetTracklet(il, &tracklets[il]);
+  Double_t chi2 = fitter.Eval();
+  // Update the tracklets
+  Double_t cov[15]; Double_t x0;
+  memset(cov, 0, sizeof(Double_t) * 15);
+  for(Int_t il = 0; il < AliTRDgeometry::kNlayer; il++){
+    x0 = tracklets[il].GetX0();
+    tracklets[il].SetYref(0, fitter.GetYat(x0));
+    tracklets[il].SetZref(0, fitter.GetZat(x0));
+    tracklets[il].SetYref(1, fitter.GetDyDxAt(x0));
+    tracklets[il].SetZref(1, fitter.GetDzDx());
+    tracklets[il].SetC(fitter.GetCurvature());
+    fitter.GetCovAt(x0, cov);
+    tracklets[il].SetCovRef(cov);
+    tracklets[il].SetChi2(chi2);
+  }
+  return chi2;
+}
+
 ///////////////////////////////////////////////////////
 //                                                   //
 // Resources of class AliTRDLeastSquare              //
@@ -3398,22 +3705,41 @@ Float_t AliTRDtrackerV1::GetChi2Z(AliTRDseedV1 *tracklets) const
 
 //_____________________________________________________________________________
 AliTRDtrackerV1::AliTRDLeastSquare::AliTRDLeastSquare(){
-  //
-  // Constructor of the nested class AliTRDtrackFitterLeastSquare
-  //
+//
+// Constructor of the nested class AliTRDtrackFitterLeastSquare
+//
+// Fast solving linear regresion in 2D
+//         y=a + bx
+// The data members have the following meaning
+// fParams[0] : a
+// fParams[1] : b
+// 
+// fSums[0] : S
+// fSums[1] : Sx
+// fSums[2] : Sy
+// fSums[3] : Sxy
+// fSums[4] : Sxx
+// fSums[5] : Syy
+// 
+// fCovarianceMatrix[0] : s2a
+// fCovarianceMatrix[1] : s2b
+// fCovarianceMatrix[2] : cov(ab)
+
   memset(fParams, 0, sizeof(Double_t) * 2);
-  memset(fSums, 0, sizeof(Double_t) * 5);
+  memset(fSums, 0, sizeof(Double_t) * 6);
   memset(fCovarianceMatrix, 0, sizeof(Double_t) * 3);
 
 }
 
 //_____________________________________________________________________________
-void AliTRDtrackerV1::AliTRDLeastSquare::AddPoint(Double_t *x, Double_t y, Double_t sigmaY){
+void AliTRDtrackerV1::AliTRDLeastSquare::AddPoint(const Double_t *const x, Double_t y, Double_t sigmaY){
   //
   // Adding Point to the fitter
   //
-  Double_t weight = 1/(sigmaY * sigmaY);
-  Double_t &xpt = *x;
+  
+  Double_t weight = 1/(sigmaY > 1e-9 ? sigmaY : 1e-9);
+  weight *= weight;
+  const Double_t &xpt = *x;
   //   printf("Adding point x = %f, y = %f, sigma = %f\n", xpt, y, sigmaY);
   fSums[0] += weight;
   fSums[1] += weight * xpt;
@@ -3424,12 +3750,14 @@ void AliTRDtrackerV1::AliTRDLeastSquare::AddPoint(Double_t *x, Double_t y, Doubl
 }
 
 //_____________________________________________________________________________
-void AliTRDtrackerV1::AliTRDLeastSquare::RemovePoint(Double_t *x, Double_t y, Double_t sigmaY){
+void AliTRDtrackerV1::AliTRDLeastSquare::RemovePoint(const Double_t *const x, Double_t y, Double_t sigmaY){
   //
   // Remove Point from the sample
   //
-  Double_t weight = 1/(sigmaY * sigmaY);
-  Double_t &xpt = *x; 
+
+  Double_t weight = 1/(sigmaY > 1e-9 ? sigmaY : 1e-9);
+  weight *= weight;
+  const Double_t &xpt = *x; 
   fSums[0] -= weight;
   fSums[1] -= weight * xpt;
   fSums[2] -= weight * y;
@@ -3439,31 +3767,39 @@ void AliTRDtrackerV1::AliTRDLeastSquare::RemovePoint(Double_t *x, Double_t y, Do
 }
 
 //_____________________________________________________________________________
-void AliTRDtrackerV1::AliTRDLeastSquare::Eval(){
+Bool_t AliTRDtrackerV1::AliTRDLeastSquare::Eval(){
   //
   // Evaluation of the fit:
   // Calculation of the parameters
   // Calculation of the covariance matrix
   //
   
-  Double_t denominator = fSums[0] * fSums[4] - fSums[1] *fSums[1];
-  if(denominator==0) return;
+  Double_t det = fSums[0] * fSums[4] - fSums[1] *fSums[1];
+  if(det==0) return kFALSE;
 
   //   for(Int_t isum = 0; isum < 5; isum++)
   //           printf("fSums[%d] = %f\n", isum, fSums[isum]);
   //   printf("denominator = %f\n", denominator);
-  fParams[0] = (fSums[2] * fSums[4] - fSums[1] * fSums[3])/ denominator;
-  fParams[1] = (fSums[0] * fSums[3] - fSums[1] * fSums[2]) / denominator;
+  fParams[0] = (fSums[2] * fSums[4] - fSums[1] * fSums[3])/det;
+  fParams[1] = (fSums[0] * fSums[3] - fSums[1] * fSums[2])/det;
   //   printf("fParams[0] = %f, fParams[1] = %f\n", fParams[0], fParams[1]);
   
   // Covariance matrix
-  fCovarianceMatrix[0] = fSums[4] - fSums[1] * fSums[1] / fSums[0];
-  fCovarianceMatrix[1] = fSums[5] - fSums[2] * fSums[2] / fSums[0];
-  fCovarianceMatrix[2] = fSums[3] - fSums[1] * fSums[2] / fSums[0];
+  Double_t den = fSums[0]*fSums[4] - fSums[1]*fSums[1];
+  fCovarianceMatrix[0] = fSums[4] / den;
+  fCovarianceMatrix[1] = fSums[0] / den;
+  fCovarianceMatrix[2] = -fSums[1] / den;
+/*  fCovarianceMatrix[0] = fSums[4] / fSums[0] - fSums[1] * fSums[1] / (fSums[0] * fSums[0]);
+  fCovarianceMatrix[1] = fSums[5] / fSums[0] - fSums[2] * fSums[2] / (fSums[0] * fSums[0]);
+  fCovarianceMatrix[2] = fSums[3] / fSums[0] - fSums[1] * fSums[2] / (fSums[0] * fSums[0]);*/
+
+
+
+  return kTRUE;
 }
 
 //_____________________________________________________________________________
-Double_t AliTRDtrackerV1::AliTRDLeastSquare::GetFunctionValue(Double_t *xpos) const {
+Double_t AliTRDtrackerV1::AliTRDLeastSquare::GetFunctionValue(const Double_t *const xpos) const {
   //
   // Returns the Function value of the fitted function at a given x-position
   //
@@ -3478,3 +3814,335 @@ void AliTRDtrackerV1::AliTRDLeastSquare::GetCovarianceMatrix(Double_t *storage)
   memcpy(storage, fCovarianceMatrix, sizeof(Double_t) * 3);
 }
 
+//_____________________________________________________________________________
+void AliTRDtrackerV1::AliTRDLeastSquare::Reset(){
+  //
+  // Reset the fitter
+  //
+  memset(fParams, 0, sizeof(Double_t) * 2);
+  memset(fCovarianceMatrix, 0, sizeof(Double_t) * 3);
+  memset(fSums, 0, sizeof(Double_t) * 6);
+}
+
+///////////////////////////////////////////////////////
+//                                                   //
+// Resources of class AliTRDtrackFitterRieman        //
+//                                                   //
+///////////////////////////////////////////////////////
+
+//_____________________________________________________________________________
+AliTRDtrackerV1::AliTRDtrackFitterRieman::AliTRDtrackFitterRieman():
+  fTrackFitter(NULL),
+  fZfitter(NULL),
+  fCovarPolY(NULL),
+  fCovarPolZ(NULL),
+  fXref(0.),
+  fSysClusterError(0.)
+{
+  //
+  // Default constructor
+  //
+  fZfitter = new AliTRDLeastSquare;
+  fCovarPolY = new TMatrixD(3,3);
+  fCovarPolZ = new TMatrixD(2,2);
+  memset(fTracklets, 0, sizeof(AliTRDseedV1 *) * 6);
+  memset(fParameters, 0, sizeof(Double_t) * 5);
+  memset(fSumPolY, 0, sizeof(Double_t) * 5);
+  memset(fSumPolZ, 0, sizeof(Double_t) * 2);
+}
+
+//_____________________________________________________________________________
+AliTRDtrackerV1::AliTRDtrackFitterRieman::~AliTRDtrackFitterRieman(){
+  //
+  // Destructor
+  //
+  if(fZfitter) delete fZfitter;
+  if(fCovarPolY) delete fCovarPolY;
+  if(fCovarPolZ) delete fCovarPolZ;
+}
+
+//_____________________________________________________________________________
+void AliTRDtrackerV1::AliTRDtrackFitterRieman::Reset(){
+  //
+  // Reset the Fitter
+  //
+  if(fTrackFitter){
+    fTrackFitter->StoreData(kTRUE);
+    fTrackFitter->ClearPoints();
+  }
+  if(fZfitter){
+    fZfitter->Reset();
+  }
+  fXref = 0.;
+  memset(fTracklets, 0, sizeof(AliTRDseedV1 *) * AliTRDgeometry::kNlayer);
+  memset(fParameters, 0, sizeof(Double_t) * 5);
+  memset(fSumPolY, 0, sizeof(Double_t) * 5);
+  memset(fSumPolZ, 0, sizeof(Double_t) * 2);
+  for(Int_t irow = 0; irow < fCovarPolY->GetNrows(); irow++)
+    for(Int_t icol = 0; icol < fCovarPolY->GetNcols(); icol++){
+      (*fCovarPolY)(irow, icol) = 0.;
+      if(irow < 2 && icol < 2)
+        (*fCovarPolZ)(irow, icol) = 0.;
+    }
+}
+
+//_____________________________________________________________________________
+void AliTRDtrackerV1::AliTRDtrackFitterRieman::SetTracklet(Int_t itr, AliTRDseedV1 *tracklet){ 
+  //
+  // Add tracklet into the fitter
+  //
+  if(itr >= AliTRDgeometry::kNlayer) return;
+  fTracklets[itr] = tracklet; 
+}
+
+//_____________________________________________________________________________
+Double_t AliTRDtrackerV1::AliTRDtrackFitterRieman::Eval(){
+  //
+  // Perform the fit
+  // 1. Apply linear transformation and store points in the fitter
+  // 2. Evaluate the fit
+  // 3. Check if the result of the fit in z-direction is reasonable
+  // if not
+  // 3a. Fix the parameters 3 and 4 with the results of a simple least
+  //     square fit
+  // 3b. Redo the fit with the fixed parameters
+  // 4. Store fit results (parameters and errors)
+  //
+  if(!fTrackFitter){
+    return 1e10;
+  }
+  fXref = CalculateReferenceX();
+  for(Int_t il = 0; il < AliTRDgeometry::kNlayer; il++) UpdateFitters(fTracklets[il]);
+  if(!fTrackFitter->GetNpoints()) return 1e10;
+  // perform the fit
+  fTrackFitter->Eval();
+  fZfitter->Eval();
+  fParameters[3] = fTrackFitter->GetParameter(3);
+  fParameters[4] = fTrackFitter->GetParameter(4);
+  if(!CheckAcceptable(fParameters[3], fParameters[4])) {
+    fTrackFitter->FixParameter(3, fZfitter->GetFunctionValue(&fXref));
+    fTrackFitter->FixParameter(4, fZfitter->GetFunctionParameter(1));
+    fTrackFitter->Eval();
+    fTrackFitter->ReleaseParameter(3);
+    fTrackFitter->ReleaseParameter(4);
+    fParameters[3] = fTrackFitter->GetParameter(3);
+    fParameters[4] = fTrackFitter->GetParameter(4);
+  }
+  // Update the Fit Parameters and the errors
+  fParameters[0] = fTrackFitter->GetParameter(0);
+  fParameters[1] = fTrackFitter->GetParameter(1);
+  fParameters[2] = fTrackFitter->GetParameter(2);
+
+  // Prepare Covariance estimation
+  (*fCovarPolY)(0,0) = fSumPolY[0]; (*fCovarPolY)(1,1) = fSumPolY[2]; (*fCovarPolY)(2,2) = fSumPolY[4];
+  (*fCovarPolY)(1,0) = (*fCovarPolY)(0,1) = fSumPolY[1];
+  (*fCovarPolY)(2,0) = (*fCovarPolY)(0,2) = fSumPolY[2];
+  (*fCovarPolY)(2,1) = (*fCovarPolY)(1,2) = fSumPolY[3];
+  fCovarPolY->Invert();
+  (*fCovarPolZ)(0,0) = fSumPolZ[0]; (*fCovarPolZ)(1,1) = fSumPolZ[2];
+  (*fCovarPolZ)(1,0) = (*fCovarPolZ)(0,1) = fSumPolZ[1];
+  fCovarPolZ->Invert();
+  return fTrackFitter->GetChisquare() / fTrackFitter->GetNpoints();
+}
+
+//_____________________________________________________________________________
+void AliTRDtrackerV1::AliTRDtrackFitterRieman::UpdateFitters(AliTRDseedV1 * const tracklet){
+  //
+  // Does the transformations and updates the fitters
+  // The following transformation is applied
+  //
+  AliTRDcluster *cl = NULL;
+  Double_t x, y, z, dx, t, w, we, yerr, zerr;
+  Double_t uvt[4];
+  if(!tracklet || !tracklet->IsOK()) return; 
+  Double_t tilt = tracklet->GetTilt();
+  for(Int_t itb = 0; itb < AliTRDseedV1::kNclusters; itb++){
+    if(!(cl = tracklet->GetClusters(itb))) continue;
+    if(!cl->IsInChamber()) continue;
+    if (!tracklet->IsUsable(itb)) continue;
+    x = cl->GetX();
+    y = cl->GetY();
+    z = cl->GetZ();
+    dx = x - fXref;
+    // Transformation
+    t = 1./(x*x + y*y);
+    uvt[0] = 2. * x * t;
+    uvt[1] = t;
+    uvt[2] = 2. * tilt * t;
+    uvt[3] = 2. * tilt * dx * t;
+    w = 2. * (y + tilt*z) * t;
+    // error definition changes for the different calls
+    we = 2. * t;
+    we *= TMath::Sqrt(cl->GetSigmaY2()+tilt*tilt*cl->GetSigmaZ2());
+    // Update sums for error calculation
+    yerr = 1./(TMath::Sqrt(cl->GetSigmaY2()) + fSysClusterError);
+    yerr *= yerr;
+    zerr = 1./cl->GetSigmaZ2();
+    for(Int_t ipol = 0; ipol < 5; ipol++){
+      fSumPolY[ipol] += yerr;
+      yerr *= x;
+      if(ipol < 3){
+        fSumPolZ[ipol] += zerr;
+        zerr *= x;
+      }
+    }
+    fTrackFitter->AddPoint(uvt, w, we);
+    fZfitter->AddPoint(&x, z, static_cast<Double_t>(TMath::Sqrt(cl->GetSigmaZ2())));
+  }
+}
+
+//_____________________________________________________________________________
+Bool_t AliTRDtrackerV1::AliTRDtrackFitterRieman::CheckAcceptable(Double_t offset, Double_t slope){
+  // 
+  // Check whether z-results are acceptable
+  // Definition: Distance between tracklet fit and track fit has to be
+  // less then half a padlength
+  // Point of comparision is at the anode wire
+  //
+  Bool_t acceptablez = kTRUE;
+  Double_t zref = 0.0;
+  for (Int_t iLayer = 0; iLayer < kNPlanes; iLayer++) {
+    if(!fTracklets[iLayer]->IsOK()) continue;
+    zref = offset + slope * (fTracklets[iLayer]->GetX0() - fXref);
+    if (TMath::Abs(fTracklets[iLayer]->GetZfit(0) - zref) > fTracklets[iLayer]->GetPadLength() * 0.5 + 1.0) 
+      acceptablez = kFALSE;
+  }
+  return acceptablez;
+}
+
+//_____________________________________________________________________________
+Double_t AliTRDtrackerV1::AliTRDtrackFitterRieman::GetYat(Double_t x) const {
+  //
+  // Calculate y position out of the track parameters
+  // y:     R^2 = (x - x0)^2 + (y - y0)^2
+  //     =>   y = y0 +/- Sqrt(R^2 - (x - x0)^2)
+  //          R = Sqrt() = 1/Curvature
+  //     =>   y = y0 +/- Sqrt(1/Curvature^2 - (x - x0)^2)
+  //
+  Double_t y = 0;
+  Double_t disc = (x * fParameters[0] + fParameters[1]);
+  disc = 1 - fParameters[0]*fParameters[2] + fParameters[1]*fParameters[1] - disc*disc;
+  if (disc >= 0) {
+    disc = TMath::Sqrt(disc);
+    y    = (1.0 - disc) / fParameters[0];
+  }
+  return y;
+}
+
+//_____________________________________________________________________________
+Double_t AliTRDtrackerV1::AliTRDtrackFitterRieman::GetZat(Double_t x) const {
+  //
+  // Return z position for a given x position
+  // Simple linear function
+  //
+  return fParameters[3] + fParameters[4] * (x - fXref);
+}
+
+//_____________________________________________________________________________
+Double_t AliTRDtrackerV1::AliTRDtrackFitterRieman::GetDyDxAt(Double_t x) const {
+  //
+  // Calculate dydx at a given radial position out of the track parameters
+  // dy:      R^2 = (x - x0)^2 + (y - y0)^2
+  //     =>     y = +/- Sqrt(R^2 - (x - x0)^2) + y0
+  //     => dy/dx = (x - x0)/Sqrt(R^2 - (x - x0)^2) 
+  // Curvature: cr = 1/R = a/Sqrt(1 + b^2 - c*a)
+  //     => dy/dx =  (x - x0)/(1/(cr^2) - (x - x0)^2) 
+  //
+  Double_t x0 = -fParameters[1] / fParameters[0];
+  Double_t curvature = GetCurvature();
+  Double_t dy = 0;
+  if (-fParameters[2] * fParameters[0] + fParameters[1] * fParameters[1] + 1 > 0) {
+    if (1.0/(curvature * curvature) - (x - x0) * (x - x0) > 0.0) {
+     Double_t yderiv = (x - x0) / TMath::Sqrt(1.0/(curvature * curvature) - (x - x0) * (x - x0));
+      if (fParameters[0] < 0) yderiv *= -1.0;
+      dy = yderiv;
+    }
+  }
+  return dy;
+}
+
+//_____________________________________________________________________________
+Double_t AliTRDtrackerV1::AliTRDtrackFitterRieman::GetCurvature() const {
+  //
+  // Calculate track curvature
+  //
+  //
+  Double_t curvature =  1.0 + fParameters[1]*fParameters[1] - fParameters[2]*fParameters[0];
+  if (curvature > 0.0) 
+    curvature  =  fParameters[0] / TMath::Sqrt(curvature);
+  return curvature;
+}
+
+//_____________________________________________________________________________
+void AliTRDtrackerV1::AliTRDtrackFitterRieman::GetCovAt(Double_t x, Double_t *cov) const {
+  //
+  // Error Definition according to gauss error propagation
+  //  
+  TMatrixD transform(3,3);
+  transform(0,0) = transform(1,1) = transform(2,2) = 1;
+  transform(0,1) = transform(1,2) = x;
+  transform(0,2) = x*x;
+  TMatrixD covariance(transform, TMatrixD::kMult, *fCovarPolY);
+  covariance *= transform.T();
+  cov[0] = covariance(0,0);
+  TMatrixD transformZ(2,2);
+  transformZ(0,0) = transformZ(1,1) = 1;
+  transformZ(0,1) = x;
+  TMatrixD covarZ(transformZ, TMatrixD::kMult, *fCovarPolZ);
+  covarZ *= transformZ.T();
+  cov[1] = covarZ(0,0);
+  cov[2] = 0;
+}
+
+//____________________________________________________________________
+Double_t AliTRDtrackerV1::AliTRDtrackFitterRieman::CalculateReferenceX(){
+  //
+  // Calculates the reference x-position for the tilted Rieman fit defined as middle
+  // of the stack (middle between layers 2 and 3). For the calculation all the tracklets
+  // are taken into account
+  // 
+  // Parameters:       - Array of tracklets(AliTRDseedV1)
+  //
+  // Output:           - The reference x-position(Float_t)
+  //
+  Int_t nDistances = 0;
+  Float_t meanDistance = 0.;
+  Int_t startIndex = 5;
+  for(Int_t il =5; il > 0; il--){
+    if(fTracklets[il]->IsOK() && fTracklets[il -1]->IsOK()){
+      Float_t xdiff = fTracklets[il]->GetX0() - fTracklets[il -1]->GetX0();
+      meanDistance += xdiff;
+      nDistances++;
+    }
+    if(fTracklets[il]->IsOK()) startIndex = il;
+  }
+  if(fTracklets[0]->IsOK()) startIndex = 0;
+  if(!nDistances){
+    // We should normally never get here
+    Float_t xpos[2]; memset(xpos, 0, sizeof(Float_t) * 2);
+    Int_t iok = 0, idiff = 0;
+    // This attempt is worse and should be avoided:
+    // check for two chambers which are OK and repeat this without taking the mean value
+    // Strategy avoids a division by 0;
+    for(Int_t il = 5; il >= 0; il--){
+      if(fTracklets[il]->IsOK()){
+        xpos[iok] = fTracklets[il]->GetX0();
+        iok++;
+        startIndex = il;
+      }
+      if(iok) idiff++; // to get the right difference;
+      if(iok > 1) break;
+    }
+    if(iok > 1){
+      meanDistance = (xpos[0] - xpos[1])/idiff;
+    }
+    else{
+      // we have do not even have 2 layers which are OK? The we do not need to fit at all
+      return 331.;
+    }
+  }
+  else{
+    meanDistance /= nDistances;
+  }
+  return fTracklets[startIndex]->GetX0() + (2.5 - startIndex) * meanDistance - 0.5 * (AliTRDgeometry::AmThick() + AliTRDgeometry::DrThick());
+}