Fit mathematics improved, obsollete GBTracker cleaned up
[u/mrichter/AliRoot.git] / HLT / TPCLib / tracking-ca / AliTPCtrackerCA.cxx
index d92ff85..88a7f98 100644 (file)
@@ -1,5 +1,5 @@
 // $Id$
-//***************************************************************************
+// **************************************************************************
 // This file is property of and copyright by the ALICE HLT Project          * 
 // ALICE Experiment at CERN, All rights reserved.                           *
 //                                                                          *
 // appear in the supporting documentation. The authors make no claims       *
 // about the suitability of this software for any purpose. It is            *
 // provided "as is" without express or implied warranty.                    *
+//                                                                          *
 //***************************************************************************
 
 #include "AliTPCtrackerCA.h"
 
-#include <TTree.h>
-#include <Riostream.h>
-#include "AliCluster.h"
+#include "TTree.h"
+#include "Riostream.h"
+//#include "AliCluster.h"
 #include "AliTPCClustersRow.h"
 #include "AliTPCParam.h"
+#include "AliTPCClusterParam.h"
+
 #include "AliRun.h"
 #include "AliRunLoader.h"
 #include "AliStack.h"
 
-#include "AliHLTTPCCATracker.h"
-#include "AliHLTTPCCAGBHit.h"
 #include "AliHLTTPCCAGBTracker.h"
+#include "AliHLTTPCCAGBHit.h"
 #include "AliHLTTPCCAGBTrack.h"
-#include "AliHLTTPCCAMCTrack.h"
-#include "AliHLTTPCCAOutTrack.h"
 #include "AliHLTTPCCAPerformance.h"
 #include "AliHLTTPCCAParam.h"
 #include "AliHLTTPCCATrackConvertor.h"
+#include "AliHLTTPCCATracker.h"
 
 #include "TMath.h"
 #include "AliTPCLoader.h"
 #include "AliTPCclusterMI.h"
 #include "AliTPCTransform.h"
 #include "AliTPCcalibDB.h"
-#include "AliTPCReconstructor.h"
 #include "AliTPCtrack.h"
+#include "AliTPCseed.h"
 #include "AliESDtrack.h"
 #include "AliESDEvent.h"
 #include "AliTrackReference.h"
+#include "TStopwatch.h"
+#include "AliTPCReconstructor.h"
 
-#include <fstream.h>
+//#include <fstream.h>
 
 ClassImp(AliTPCtrackerCA)
 
 AliTPCtrackerCA::AliTPCtrackerCA()
-  :AliTracker(),fParam(0), fClusters(0), fNClusters(0), fHLTTracker(0),fHLTPerformance(0),fDoHLTPerformance(0),fDoHLTPerformanceClusters(0),fStatNEvents(0)
+  :AliTracker(),fkParam(0), fClusters(0), fNClusters(0), fHLTTracker(0),fDoHLTPerformance(0),fDoHLTPerformanceClusters(0),fStatNEvents(0)
 {
   //* default constructor
 }
 
 AliTPCtrackerCA::AliTPCtrackerCA(const AliTPCtrackerCA &):
-  AliTracker(),fParam(0), fClusters(0), fNClusters(0), fHLTTracker(0),fHLTPerformance(0),fDoHLTPerformance(0),fDoHLTPerformanceClusters(0),fStatNEvents(0)
+  AliTracker(),fkParam(0), fClusters(0), fNClusters(0), fHLTTracker(0),fDoHLTPerformance(0),fDoHLTPerformanceClusters(0),fStatNEvents(0)
 {
   //* dummy
 }
 
-AliTPCtrackerCA & AliTPCtrackerCA::operator=(const AliTPCtrackerCA& )
+const AliTPCtrackerCA & AliTPCtrackerCA::operator=(const AliTPCtrackerCA& ) const
 {
   //* dummy 
   return *this;
@@ -77,33 +80,35 @@ AliTPCtrackerCA::~AliTPCtrackerCA()
   //* destructor
   if( fClusters ) delete[] fClusters;
   if( fHLTTracker ) delete fHLTTracker;
-  if( fHLTPerformance ) delete fHLTPerformance;
 }
 
+//#include "AliHLTTPCCADisplay.h"
+
 AliTPCtrackerCA::AliTPCtrackerCA(const AliTPCParam *par): 
-  AliTracker(),fParam(par), fClusters(0), fNClusters(0), fHLTTracker(0), fHLTPerformance(0),fDoHLTPerformance(0),fDoHLTPerformanceClusters(0),fStatNEvents(0)
+  AliTracker(),fkParam(par), fClusters(0), fNClusters(0), fHLTTracker(0),fDoHLTPerformance(0),fDoHLTPerformanceClusters(0),fStatNEvents(0)
 {
   //* constructor
-
-  DoHLTPerformance() = 1;
-  DoHLTPerformanceClusters() = 1;
+  fDoHLTPerformance = 0;
+  fDoHLTPerformanceClusters = 0;
 
   fHLTTracker = new AliHLTTPCCAGBTracker;
-  fHLTTracker->SetNSlices( fParam->GetNSector()/2 );
+  fHLTTracker->SetNSlices( fkParam->GetNSector()/2 );
 
   if( fDoHLTPerformance ){
-    fHLTPerformance = new AliHLTTPCCAPerformance;
-    fHLTPerformance->SetTracker( fHLTTracker );
+    AliHLTTPCCAPerformance::Instance().SetTracker( fHLTTracker );
   }
 
-  for( int iSlice=0; iSlice<fHLTTracker->NSlices(); iSlice++ ){
-  
-    Float_t bz = AliTracker::GetBz();
+  for( Int_t iSlice=0; iSlice<fHLTTracker->NSlices(); iSlice++ ){
+
+    const Double_t kCLight = 0.000299792458;
 
-    Float_t inRmin = fParam->GetInnerRadiusLow();
-    //Float_t inRmax = fParam->GetInnerRadiusUp();
-    //Float_t outRmin = fParam->GetOuterRadiusLow(); 
-    Float_t outRmax = fParam->GetOuterRadiusUp();
+    Float_t bz = AliTracker::GetBz()*kCLight;
+
+    Float_t inRmin = fkParam->GetInnerRadiusLow();
+    //Float_t inRmax = fkParam->GetInnerRadiusUp();
+    //Float_t outRmin = fkParam->GetOuterRadiusLow(); 
+    Float_t outRmax = fkParam->GetOuterRadiusUp();
     Float_t plusZmin = 0.0529937; 
     Float_t plusZmax = 249.778; 
     Float_t minusZmin = -249.645; 
@@ -121,68 +126,79 @@ AliTPCtrackerCA::AliTPCtrackerCA(const AliTPCParam *par):
     Float_t padPitch = 0.4;
     Float_t sigmaZ = 0.228808;
 
-    Int_t NRows = fParam->GetNRowLow()+fParam->GetNRowUp();
-
+    Int_t nRows = fkParam->GetNRowLow()+fkParam->GetNRowUp();
     Float_t rowX[200];
-    for( Int_t irow=0; irow<fParam->GetNRowLow(); irow++){
-      rowX[irow] = fParam->GetPadRowRadiiLow(irow);
+    for( Int_t irow=0; irow<fkParam->GetNRowLow(); irow++){
+      rowX[irow] = fkParam->GetPadRowRadiiLow(irow);
     }     
-    for( Int_t irow=0; irow<fParam->GetNRowUp(); irow++){
-      rowX[fParam->GetNRowLow()+irow] = fParam->GetPadRowRadiiUp(irow);
-    }      
+    for( Int_t irow=0; irow<fkParam->GetNRowUp(); irow++){
+      rowX[fkParam->GetNRowLow()+irow] = fkParam->GetPadRowRadiiUp(irow);
+    }
     AliHLTTPCCAParam param;
-    param.Initialize( iSlice, NRows, rowX, alpha, dalpha,
+    param.Initialize( iSlice, nRows, rowX, alpha, dalpha,
                      inRmin, outRmax, zMin, zMax, padPitch, sigmaZ, bz );
-    param.YErrorCorrection() = 1.;//.33;
-    param.ZErrorCorrection() = 1.;//.33;
-    param.MaxTrackMatchDRow() = 5;
-    param.TrackConnectionFactor() = 3.5;
+    param.SetHitPickUpFactor( 1. );
+    param.SetMaxTrackMatchDRow( 5 );
+    param.SetTrackConnectionFactor( 3.5 );
+
+    AliTPCClusterParam * clparam = AliTPCcalibDB::Instance()->GetClusterParam();
+    for( Int_t iRow=0; iRow<nRows; iRow++ ){
+      Int_t    type = (iRow<63) ? 0: ( (iRow>126) ? 1:2 );
+      for( int iyz=0; iyz<2; iyz++ ){
+       for( int k=0; k<7; k++ ){
+         //std::cout<<param.fParamS0Par[iyz][type][k]<<" "<<clparam->fParamS0Par[iyz][type][k] - param.fParamS0Par[iyz][type][k]<<std::endl;
+         param.SetParamS0Par(iyz,type,k,clparam->fParamS0Par[iyz][type][k]);
+       }
+      }
+    }
     fHLTTracker->Slices()[iSlice].Initialize( param ); 
   }
 }
 
 
 
-Int_t AliTPCtrackerCA::LoadClusters (TTree * tree)
+Int_t AliTPCtrackerCA::LoadClusters (TTree * fromTree)
 { 
+  // load clusters to the local arrays
   fNClusters = 0;
   if( fClusters ) delete[] fClusters;
 
   fHLTTracker->StartEvent();
-  if( fDoHLTPerformance ) fHLTPerformance->StartEvent();
+  if( fDoHLTPerformance ) AliHLTTPCCAPerformance::Instance().StartEvent();
 
-  if( !fParam ) return 1;
+  if( !fkParam ) return 1;
 
   // load mc tracks
   while( fDoHLTPerformance ){
     if( !gAlice ) break;
-    AliRunLoader *rl = gAlice->GetRunLoader(); 
+    AliRunLoader *rl = AliRunLoader::Instance();//gAlice->GetRunLoader(); 
     if( !rl ) break;
     rl->LoadKinematics();
     AliStack *stack = rl->Stack();
     if( !stack ) break;
 
-    fHLTPerformance->SetNMCTracks( stack->GetNtrack() );
+    AliHLTTPCCAPerformance::Instance().SetNMCTracks( stack->GetNtrack() );
     
     for( Int_t itr=0; itr<stack->GetNtrack(); itr++ ){
       TParticle *part = stack->Particle(itr);
-      fHLTPerformance->ReadMCTrack( itr, part );
+      AliHLTTPCCAPerformance::Instance().ReadMCTrack( itr, part );
     }
 
     { // check for MC tracks at the TPC entrance
+
       Bool_t *isTPC = 0;
       isTPC = new Bool_t [stack->GetNtrack()];
       for( Int_t i=0; i<stack->GetNtrack(); i++ ) isTPC[i] = 0;
       rl->LoadTrackRefs();
-      TTree *TR = rl->TreeTR();
-      if( !TR ) break;
-      TBranch *branch=TR->GetBranch("TrackReferences");
+      TTree *mcTree = rl->TreeTR();
+      if( !mcTree ) break;
+      TBranch *branch=mcTree->GetBranch("TrackReferences");
       if (!branch ) break;     
       TClonesArray tpcdummy("AliTrackReference",1000), *tpcRefs=&tpcdummy;
       branch->SetAddress(&tpcRefs);
-      Int_t nr=(Int_t)TR->GetEntries();
+      Int_t nr=(Int_t)mcTree->GetEntries();
       for (Int_t r=0; r<nr; r++) {
-       TR->GetEvent(r);
+       mcTree->GetEvent(r);
        Int_t nref = tpcRefs->GetEntriesFast();
        if (!nref) continue;
        AliTrackReference *tpcRef= 0x0;  
@@ -195,7 +211,7 @@ Int_t AliTPCtrackerCA::LoadClusters (TTree * tree)
 
        if( isTPC[tpcRef->Label()] ) continue;  
 
-       fHLTPerformance->ReadMCTPCTrack(tpcRef->Label(),
+       AliHLTTPCCAPerformance::Instance().ReadMCTPCTrack(tpcRef->Label(),
                                        tpcRef->X(),tpcRef->Y(),tpcRef->Z(),
                                        tpcRef->Px(),tpcRef->Py(),tpcRef->Pz() );
        isTPC[tpcRef->Label()] = 1;
@@ -221,14 +237,14 @@ Int_t AliTPCtrackerCA::LoadClusters (TTree * tree)
        AliTPChit *phit = (AliTPChit*)tpc->FirstHit(-1);
        for ( ; phit; phit=(AliTPChit*)tpc->NextHit() ) nPoints++;
       }
-      fHLTPerformance->SetNMCPoints( nPoints );
+      AliHLTTPCCAPerformance::Instance().SetNMCPoints( nPoints );
 
       for (Int_t iEnt=0; iEnt<nEnt; iEnt++) {    
        tpc->ResetHits();
        tpcl->TreeH()->GetEvent(iEnt);
        AliTPChit *phit = (AliTPChit*)tpc->FirstHit(-1);
        for ( ; phit; phit=(AliTPChit*)tpc->NextHit() ){
-         fHLTPerformance->ReadMCPoint( phit->GetTrack(),phit->X(), phit->Y(),phit->Z(),phit->Time(), phit->fSector%36);
+         AliHLTTPCCAPerformance::Instance().ReadMCPoint( phit->GetTrack(),phit->X(), phit->Y(),phit->Z(),phit->Time(), phit->fSector%36);
        }      
       }
       break;
@@ -236,7 +252,7 @@ Int_t AliTPCtrackerCA::LoadClusters (TTree * tree)
     break;
   }
   
-  TBranch * br = tree->GetBranch("Segment");
+  TBranch * br = fromTree->GetBranch("Segment");
   if( !br ) return 1;
 
   AliTPCClustersRow *clrow = new AliTPCClustersRow;
@@ -247,27 +263,27 @@ Int_t AliTPCtrackerCA::LoadClusters (TTree * tree)
   br->SetAddress(&clrow);
   
   //
-  Int_t NEnt=Int_t(tree->GetEntries());
+  Int_t nEnt=Int_t(fromTree->GetEntries());
 
   fNClusters = 0;
-  for (Int_t i=0; i<NEnt; i++) {
+  for (Int_t i=0; i<nEnt; i++) {
     br->GetEntry(i);
     Int_t sec,row;
-    fParam->AdjustSectorRow(clrow->GetID(),sec,row);
+    fkParam->AdjustSectorRow(clrow->GetID(),sec,row);
     fNClusters += clrow->GetArray()->GetEntriesFast();
   }
 
   fClusters = new AliTPCclusterMI [fNClusters];
   fHLTTracker->SetNHits( fNClusters );
-  if( fDoHLTPerformance ) fHLTPerformance->SetNHits( fNClusters );
-  int ind=0;
-  for (Int_t i=0; i<NEnt; i++) {
+  if( fDoHLTPerformance ) AliHLTTPCCAPerformance::Instance().SetNHits( fNClusters );
+  Int_t ind=0;
+  for (Int_t i=0; i<nEnt; i++) {
     br->GetEntry(i);
     Int_t sec,row;
-    fParam->AdjustSectorRow(clrow->GetID(),sec,row);
-    int NClu = clrow->GetArray()->GetEntriesFast();
-    Float_t x = fParam->GetPadRowRadii(sec,row);
-    for (Int_t icl=0; icl<NClu; icl++){
+    fkParam->AdjustSectorRow(clrow->GetID(),sec,row);
+    Int_t nClu = clrow->GetArray()->GetEntriesFast();
+    Float_t x = fkParam->GetPadRowRadii(sec,row);
+    for (Int_t icl=0; icl<nClu; icl++){
       Int_t lab0 = -1;
       Int_t lab1 = -1;
       Int_t lab2 = -1;
@@ -285,16 +301,16 @@ Int_t AliTPCtrackerCA::LoadClusters (TTree * tree)
       Int_t id[1]={cluster->GetDetector()};
       transform->Transform(xx,id,0,1);  
       //if (!AliTPCReconstructor::GetRecoParam()->GetBYMirror()){
-      if (cluster->GetDetector()%36>17){
-       xx[1]*=-1;
-      }
+      //if (cluster->GetDetector()%36>17){
+      //xx[1]*=-1;
+      //}
       //}
 
       cluster->SetX(xx[0]);
       cluster->SetY(xx[1]);
       cluster->SetZ(xx[2]);
 
-      TGeoHMatrix  *mat = fParam->GetClusterMatrix(cluster->GetDetector());
+      TGeoHMatrix  *mat = fkParam->GetClusterMatrix(cluster->GetDetector());
       Double_t pos[3]= {cluster->GetX(),cluster->GetY(),cluster->GetZ()};
       Double_t posC[3]={cluster->GetX(),cluster->GetY(),cluster->GetZ()};
       if (mat) mat->LocalToMaster(pos,posC);
@@ -305,12 +321,13 @@ Int_t AliTPCtrackerCA::LoadClusters (TTree * tree)
       cluster->SetY(posC[1]);
       cluster->SetZ(posC[2]);
 
+      x = cluster->GetX();
       Float_t y = cluster->GetY();
       Float_t z = cluster->GetZ();        
 
       if( sec>=36 ){
        sec = sec - 36;
-       row = row + fParam->GetNRowLow(); 
+       row = row + fkParam->GetNRowLow(); 
       }
       
       Int_t index = ind++;
@@ -318,7 +335,7 @@ Int_t AliTPCtrackerCA::LoadClusters (TTree * tree)
       fHLTTracker->ReadHit( x, y, z, 
                            TMath::Sqrt(cluster->GetSigmaY2()), TMath::Sqrt(cluster->GetSigmaZ2()),                         
                            cluster->GetMax(), index, sec, row );
-      if( fDoHLTPerformance ) fHLTPerformance->ReadHitLabel(index, lab0, lab1, lab2 );
+      if( fDoHLTPerformance ) AliHLTTPCCAPerformance::Instance().ReadHitLabel(index, lab0, lab1, lab2 );
     }
   }
   delete clrow;
@@ -332,10 +349,13 @@ AliCluster * AliTPCtrackerCA::GetCluster(Int_t index) const
 
 Int_t AliTPCtrackerCA::Clusters2Tracks( AliESDEvent *event )
 {
+  // reconstruction
   //cout<<"Start of AliTPCtrackerCA"<<endl;
+  TStopwatch timer;
 
   fHLTTracker->FindTracks();
-  if( fDoHLTPerformance ) fHLTPerformance->Performance();
+  //cout<<"Do performance.."<<endl;
+  if( fDoHLTPerformance ) AliHLTTPCCAPerformance::Instance().Performance();
 
   if( 0 ) {// Write Event    
     if( fStatNEvents == 0 ){
@@ -347,31 +367,31 @@ Int_t AliTPCtrackerCA::Clusters2Tracks( AliESDEvent *event )
       geo.close();
     }
 
-    fstream event;
+    fstream hits;
     char name[255];
     sprintf( name,"CAEvents/%i.event.dat",fStatNEvents ); 
-    event.open(name, ios::out);
-    if( event.is_open() ){
-      fHLTTracker->WriteEvent(event);  
+    hits.open(name, ios::out);
+    if( hits.is_open() ){
+      fHLTTracker->WriteEvent(hits);   
       fstream tracks;
       sprintf( name,"CAEvents/%i.tracks.dat",fStatNEvents ); 
       tracks.open(name, ios::out);
       fHLTTracker->WriteTracks(tracks);        
     }
-    event.close();   
+    hits.close();   
     if( fDoHLTPerformance ){
       fstream mcevent, mcpoints;
       char mcname[255];
       sprintf( mcname,"CAEvents/%i.mcevent.dat",fStatNEvents ); 
       mcevent.open(mcname, ios::out);
       if( mcevent.is_open() ){      
-       fHLTPerformance->WriteMCEvent(mcevent);
+       AliHLTTPCCAPerformance::Instance().WriteMCEvent(mcevent);
       }
-      if(fDoHLTPerformanceClusters ){
+      if(1 && fDoHLTPerformanceClusters ){
        sprintf( mcname,"CAEvents/%i.mcpoints.dat",fStatNEvents ); 
        mcpoints.open(mcname, ios::out);
        if( mcpoints.is_open() ){      
-         fHLTPerformance->WriteMCPoints(mcpoints);
+         AliHLTTPCCAPerformance::Instance().WriteMCPoints(mcpoints);
        }
        mcpoints.close();
       }
@@ -382,47 +402,90 @@ Int_t AliTPCtrackerCA::Clusters2Tracks( AliESDEvent *event )
 
   if( event ){
    
-    Float_t bz = fHLTTracker->Slices()[0].Param().Bz();
-
     for( Int_t itr=0; itr<fHLTTracker->NTracks(); itr++ ){
-      AliTPCtrack tTPC;
+      //AliTPCtrack tTPC;
+      AliTPCseed tTPC;
       AliHLTTPCCAGBTrack &tCA = fHLTTracker->Tracks()[itr];
-      AliHLTTPCCATrackParam &par = tCA.Param();        
-      AliHLTTPCCATrackConvertor::GetExtParam( par, tTPC, tCA.Alpha(), bz );
+      AliHLTTPCCATrackParam par = tCA.Param(); 
+      AliHLTTPCCATrackConvertor::GetExtParam( par, tTPC, tCA.Alpha() );
       tTPC.SetMass(0.13957);
       tTPC.SetdEdx( tCA.DeDx() );
-      if( TMath::Abs(tTPC.GetSigned1Pt())>1./0.1 ) continue;
-      int nhits = tCA.NHits();
-      if( nhits>kMaxRow ) nhits = kMaxRow;
-      tTPC.SetNumberOfClusters(nhits);      
+      if( TMath::Abs(tTPC.GetSigned1Pt())>1./0.02 ) continue;
+      Int_t nhits = tCA.NHits();
+      Int_t firstHit=0;
+      if( nhits>160 ){
+       firstHit = nhits-160;
+       nhits=160;
+      }
+
+      tTPC.SetNumberOfClusters(nhits);
+      Float_t alpha = tCA.Alpha();      
+      AliHLTTPCCATrackParam t0 = par;
       for( Int_t ih=0; ih<nhits; ih++ ){
-       Int_t index = fHLTTracker->TrackHits()[tCA.FirstHitRef()+ih];
-       Int_t ext_index = fHLTTracker->Hits()[index].ID();
-       tTPC.SetClusterIndex(ih, ext_index);
+       Int_t index = fHLTTracker->TrackHits()[tCA.FirstHitRef()+firstHit+ih];
+       AliHLTTPCCAGBHit &h = fHLTTracker->Hits()[index];
+       Int_t extIndex = h.ID();
+       tTPC.SetClusterIndex(ih, extIndex);
+               
+       AliTPCclusterMI *c = &(fClusters[extIndex]);
+       tTPC.SetClusterPointer(h.IRow(), c );
+       AliTPCTrackerPoint &point = *(tTPC.GetTrackPoint(h.IRow()));
+       {
+         Int_t iSlice = h.ISlice();
+         AliHLTTPCCATracker &slice = fHLTTracker->Slices()[iSlice];
+         if( slice.Param().Alpha()!=alpha ){
+           if( ! t0.Rotate(  slice.Param().Alpha() - alpha, .999 ) ) continue;
+           alpha = slice.Param().Alpha();
+         }
+         Float_t x = slice.Row(h.IRow()).X();
+         if( !t0.TransportToX( x, fHLTTracker->Slices()[0].Param().GetBz(t0),.999 ) ) continue;
+         Float_t sy2, sz2;
+         slice.GetErrors2( h.IRow(), t0, sy2, sz2 );
+         point.SetSigmaY(c->GetSigmaY2()/sy2);
+         point.SetSigmaZ(c->GetSigmaZ2()/sz2);
+         point.SetAngleY(TMath::Abs(t0.GetSinPhi()/t0.GetCosPhi()));
+         point.SetAngleZ(TMath::Abs(t0.GetDzDs()));    
+       }       
       }
+      tTPC.CookdEdx(0.02,0.6);
+
       CookLabel(&tTPC,0.1);          
-      {
-       Double_t xTPC=fParam->GetInnerRadiusLow();
-       Double_t dAlpha = fParam->GetInnerAngle()/180.*TMath::Pi();
-       if (tTPC.AliExternalTrackParam::PropagateTo(xTPC,bz)) {   
-         Double_t y=tTPC.GetY();
-         Double_t ymax=xTPC*TMath::Tan(dAlpha/2.); 
-         if (y > ymax) {
-           if (tTPC.Rotate(dAlpha)) tTPC.AliExternalTrackParam::PropagateTo(xTPC,bz);
-         } else if (y <-ymax) {
-           if (tTPC.Rotate(-dAlpha)) tTPC.AliExternalTrackParam::PropagateTo(xTPC,bz);
-         }         
-       }
+
+      if(1){ // correction like in off-line --- Adding systematic error
+
+       const Double_t *param = AliTPCReconstructor::GetRecoParam()->GetSystematicError();
+       Double_t covar[15];
+       for (Int_t i=0;i<15;i++) covar[i]=0;
+       covar[0] = param[0]*param[0];
+       covar[2] = param[1]*param[1];
+       covar[5] = param[2]*param[2];
+       covar[9] = param[3]*param[3];
+       Double_t facC =  AliTracker::GetBz()*kB2C;
+       covar[14]= param[4]*param[4]*facC*facC;
+       tTPC.AddCovariance(covar);       
       }
 
       AliESDtrack tESD;
       tESD.UpdateTrackParams( &(tTPC),AliESDtrack::kTPCin);
       //tESD.SetStatus( AliESDtrack::kTPCrefit );
       //tESD.SetTPCPoints(tTPC.GetPoints());
+      Int_t   ndedx = tTPC.GetNCDEDX(0);
+      Float_t sdedx = tTPC.GetSDEDX(0);
+      Float_t dedx  = tTPC.GetdEdx();
+      tESD.SetTPCsignal(dedx, sdedx, ndedx); 
       //tESD.myTPC = tTPC;            
+
       event->AddTrack(&tESD);
     }
   }
+  timer.Stop();
+  static double time=0, time1 = 0;
+  static Int_t ncalls = 0;
+  time+=timer.CpuTime();
+  time1+=timer.RealTime();
+  ncalls++;
+  //cout<<"\n\nCA tracker speed: cpu = "<<time/ncalls*1.e3<<" [ms/ev], real = "<<time1/ncalls*1.e3<<" [ms/ev], n calls = "<<ncalls<<endl<<endl;
 
   //cout<<"End of AliTPCtrackerCA"<<endl;
   return 0;
@@ -431,44 +494,87 @@ Int_t AliTPCtrackerCA::Clusters2Tracks( AliESDEvent *event )
 
 Int_t AliTPCtrackerCA::RefitInward (AliESDEvent *event)
 { 
-  //* back propagation of ESD tracks (not fully functional)
+  //* forward propagation of ESD tracks 
 
-  Float_t bz = fHLTTracker->Slices()[0].Param().Bz();
-  Float_t xTPC = fParam->GetInnerRadiusLow();
-  Float_t dAlpha = fParam->GetInnerAngle()/180.*TMath::Pi();
+  //Float_t bz = fHLTTracker->Slices()[0].Param().Bz();
+  Float_t xTPC = fkParam->GetInnerRadiusLow();
+  Float_t dAlpha = fkParam->GetInnerAngle()/180.*TMath::Pi();
   Float_t yMax = xTPC*TMath::Tan(dAlpha/2.); 
 
   Int_t nentr=event->GetNumberOfTracks();
      
-  for (Int_t i=0; i<nentr; i++) {
-    AliESDtrack *esd=event->GetTrack(i);
-    ULong_t status=esd->GetStatus();
+  for (Int_t itr=0; itr<nentr; itr++) {
+    AliESDtrack *esd=event->GetTrack(itr);
+    ULong_t status=esd->GetStatus(); 
     if (!(status&AliESDtrack::kTPCin)) continue;
     AliHLTTPCCATrackParam t0;
-    AliHLTTPCCATrackConvertor::SetExtParam(t0,*esd, bz );
+    AliHLTTPCCATrackConvertor::SetExtParam(t0,*esd );
+    AliHLTTPCCATrackParam t = t0;
     Float_t alpha = esd->GetAlpha();
-    if( t0.TransportToXWithMaterial( xTPC, bz) ){
-      if (t0.GetY() > yMax) {
-       if (t0.Rotate(dAlpha)){ 
-         alpha+=dAlpha;  
-         t0.TransportToXWithMaterial( xTPC, bz);
-       }
-      } else if (t0.GetY() <-yMax) {
-       if (t0.Rotate(-dAlpha)){
-         alpha+=-dAlpha;
-         t0.TransportToXWithMaterial( xTPC, bz);
-       }
-      }    
+    //Float_t dEdX=0;    
+    Int_t hits[1000];
+    Int_t nHits = esd->GetTPCclusters(hits);
+    
+    // convert clluster indices to AliHLTTPCCAGBHit indices
+
+    for( Int_t i=0; i<nHits; i++ ) hits[i] = fHLTTracker->Ext2IntHitID(hits[i]);
+   
+    Bool_t ok = fHLTTracker->FitTrack( t, t0, alpha, hits, nHits, 0 );
+    if( ok &&  nHits>15){
+      if( t.TransportToXWithMaterial( xTPC, fHLTTracker->Slices()[0].Param().GetBz(t)) ){
+       if (t.GetY() > yMax) {
+         if (t.Rotate(dAlpha)){ 
+           alpha+=dAlpha;  
+           t.TransportToXWithMaterial( xTPC, fHLTTracker->Slices()[0].Param().GetBz(t));
+         }
+       } else if (t.GetY() <-yMax) {
+         if (t.Rotate(-dAlpha)){
+           alpha+=-dAlpha;
+           t.TransportToXWithMaterial( xTPC, fHLTTracker->Slices()[0].Param().GetBz(t));
+         }
+       }    
+      }
+    
+      AliTPCtrack tt(*esd);
+      AliHLTTPCCATrackConvertor::GetExtParam(t,tt,alpha );
+      esd->UpdateTrackParams( &tt,AliESDtrack::kTPCrefit); 
     }
-    AliTPCtrack tt(*esd);
-    AliHLTTPCCATrackConvertor::GetExtParam(t0,tt,alpha,bz);
-    esd->UpdateTrackParams( &tt,AliESDtrack::kTPCrefit); 
   }
   return 0;
 }
 
-Int_t AliTPCtrackerCA::PropagateBack(AliESDEvent *)
+Int_t AliTPCtrackerCA::PropagateBack(AliESDEvent *event)
 { 
-  //* not implemented yet
-  return 0; 
+
+  //* backward propagation of ESD tracks 
+
+  //Float_t bz = fHLTTracker->Slices()[0].Param().Bz();
+  Int_t nentr=event->GetNumberOfTracks();
+     
+  for (Int_t itr=0; itr<nentr; itr++) {
+
+    AliESDtrack *esd=event->GetTrack(itr);
+    ULong_t status=esd->GetStatus(); 
+    if (!(status&AliESDtrack::kTPCin)) continue;
+
+    AliHLTTPCCATrackParam t0;
+    AliHLTTPCCATrackConvertor::SetExtParam(t0,*esd  );
+    AliHLTTPCCATrackParam t = t0;
+    Float_t alpha = esd->GetAlpha();
+    //Float_t dEdX=0;    
+    Int_t hits[1000];
+    Int_t nHits = esd->GetTPCclusters(hits);
+    
+    // convert clluster indices to AliHLTTPCCAGBHit indices
+
+    for( Int_t i=0; i<nHits; i++ ) hits[i] = fHLTTracker->Ext2IntHitID(hits[i]);
+   
+    Bool_t ok = fHLTTracker->FitTrack( t, t0, alpha, hits, nHits, 1 );
+    if( ok &&  nHits>15){
+      AliTPCtrack tt(*esd);
+      AliHLTTPCCATrackConvertor::GetExtParam(t,tt,alpha );
+      esd->UpdateTrackParams( &tt,AliESDtrack::kTPCout); 
+    }
+  }
+  return 0;
 }