]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
Fit mathematics improved, obsollete GBTracker cleaned up
authorsgorbuno <sgorbuno@f7af4fe6-9843-0410-8265-dc069ae4e863>
Mon, 13 Apr 2009 20:33:47 +0000 (20:33 +0000)
committersgorbuno <sgorbuno@f7af4fe6-9843-0410-8265-dc069ae4e863>
Mon, 13 Apr 2009 20:33:47 +0000 (20:33 +0000)
22 files changed:
HLT/TPCLib/tracking-ca/AliHLTTPCCADef.h
HLT/TPCLib/tracking-ca/AliHLTTPCCADisplay.cxx
HLT/TPCLib/tracking-ca/AliHLTTPCCAGBTracker.cxx
HLT/TPCLib/tracking-ca/AliHLTTPCCAGBTracker.h
HLT/TPCLib/tracking-ca/AliHLTTPCCAGlobalMergerComponent.cxx
HLT/TPCLib/tracking-ca/AliHLTTPCCAMerger.cxx
HLT/TPCLib/tracking-ca/AliHLTTPCCAMerger.h
HLT/TPCLib/tracking-ca/AliHLTTPCCAParam.cxx
HLT/TPCLib/tracking-ca/AliHLTTPCCAParam.h
HLT/TPCLib/tracking-ca/AliHLTTPCCAPerformance.cxx
HLT/TPCLib/tracking-ca/AliHLTTPCCASliceOutput.h
HLT/TPCLib/tracking-ca/AliHLTTPCCATrackConvertor.cxx
HLT/TPCLib/tracking-ca/AliHLTTPCCATrackConvertor.h
HLT/TPCLib/tracking-ca/AliHLTTPCCATrackLinearisation.h [new file with mode: 0644]
HLT/TPCLib/tracking-ca/AliHLTTPCCATrackParam.cxx
HLT/TPCLib/tracking-ca/AliHLTTPCCATrackParam.h
HLT/TPCLib/tracking-ca/AliHLTTPCCATracker.cxx
HLT/TPCLib/tracking-ca/AliHLTTPCCATracker.h
HLT/TPCLib/tracking-ca/AliHLTTPCCATrackerComponent.cxx
HLT/TPCLib/tracking-ca/AliHLTTPCCATrackletConstructor.cxx
HLT/TPCLib/tracking-ca/AliHLTTPCCATrackletSelector.cxx
HLT/TPCLib/tracking-ca/AliTPCtrackerCA.cxx

index 8464b1852bc34c586577b651654c7e2392ddb59d..7c2fab3604de7d7d74ec1d9c46345d2c3c674066 100644 (file)
@@ -82,7 +82,6 @@ typedef float          Size_t;      //Attribute size (float)
 #else 
 
 #include "Rtypes.h"
-
 #include "AliHLTDataTypes.h"
 
 namespace AliHLTTPCCADefinitions
index 7f467479e45f8f49188682f4d58f3bec2c13f191..d89a15ad5895e0d1912f9b32004666ad812c02bc 100644 (file)
@@ -699,12 +699,9 @@ Bool_t AliHLTTPCCADisplay::DrawTrack( AliHLTTPCCATrackParam t, Double_t Alpha, c
       if( mc.P()>=1. ) color = kRed;   
     }  
   }
-  std::cout<<"mark 1"<<std::endl;
+
   if( t.SinPhi()>.999 )  t.SetSinPhi( .999 );
   else if( t.SinPhi()<-.999 )  t.SetSinPhi( -.999 );
-  if( t.CosPhi()>=0 ) t.SetCosPhi( TMath::Sqrt(1-t.SinPhi()*t.SinPhi() ));
-  else t.SetCosPhi( -TMath::Sqrt(1-t.SinPhi()*t.SinPhi() ));
-  std::cout<<"mark 2"<<std::endl;
 
   //  Int_t iSlice = fSlice->Param().ISlice();
 
@@ -983,7 +980,7 @@ void AliHLTTPCCADisplay::DrawGBTrackFast( AliHLTTPCCAGBTracker &tracker, Int_t i
     Slice2View(h1.X(), h1.Y(), &gx1, &gy1 );
     Slice2View(h2.X(), h2.Y(), &gx2, &gy2 );
     if( colorY<0 ) colorY = GetColorY( (gy1+gy2)/2. );
-    color = colorY = GetColorK(t.GetKappa());
+    color = colorY = GetColorK(t.GetQPt());
   }
 
   fMarker.SetMarkerColor(color);//kBlue);
@@ -1013,7 +1010,7 @@ void AliHLTTPCCADisplay::DrawGBTrackFast( AliHLTTPCCAGBTracker &tracker, Int_t i
       alpha = tracker.Slices()[h1.ISlice()].Param().Alpha();
       SetSliceTransform( &(tracker.Slices()[oldSlice]) );
     }
-    t.GetDCAPoint( h1.X(), h1.Y(), h1.Z(), x1, y1, z1 );  
+    t.GetDCAPoint( h1.X(), h1.Y(), h1.Z(), x1, y1, z1, fSlice->Param().Bz()  );  
     Slice2View(x1, y1, &vx1, &vy1 );
 
     if( h2.ISlice() != oldSlice ){
@@ -1022,13 +1019,13 @@ void AliHLTTPCCADisplay::DrawGBTrackFast( AliHLTTPCCAGBTracker &tracker, Int_t i
       alpha = tracker.Slices()[h2.ISlice()].Param().Alpha();
       SetSliceTransform( &(tracker.Slices()[oldSlice]) );
     }
-    t.GetDCAPoint( h2.X(), h2.Y(), h2.Z(), x2, y2, z2 );
+    t.GetDCAPoint( h2.X(), h2.Y(), h2.Z(), x2, y2, z2, fSlice->Param().Bz()  );
     Slice2View(x2, y2, &vx2, &vy2 );
     
     Double_t x0 = t.GetX();
     Double_t y0 = t.GetY();
     Double_t sinPhi = t.GetSinPhi();
-    Double_t k = t.GetKappa();
+    Double_t k = t.GetKappa( fSlice->Param().Bz() );
     Double_t ex = t.GetCosPhi();
     Double_t ey = sinPhi;
  
@@ -1078,7 +1075,7 @@ void AliHLTTPCCADisplay::DrawGBTrackFast( AliHLTTPCCAGBTracker &tracker, Int_t i
       alpha = tracker.Slices()[h1.ISlice()].Param().Alpha();
       SetSliceTransform( &(tracker.Slices()[oldSlice]) );
     }
-    t.GetDCAPoint( h1.X(), h1.Y(), h1.Z(), x1, y1, z1 );  
+    t.GetDCAPoint( h1.X(), h1.Y(), h1.Z(), x1, y1, z1, fSlice->Param().Bz()  );  
     Slice2View(x1, y1, &vx1, &vy1 );
     py[iHit] = vy1;
     pz[iHit] = z1;
@@ -1224,8 +1221,8 @@ void AliHLTTPCCADisplay::DrawTrack( AliHLTTPCCATrack &track, Int_t color, Bool_t
     AliHLTTPCCARow &row1 = fSlice->ID2Row(vHits[iHit].ID());
     AliHLTTPCCARow &row2 = fSlice->ID2Row(vHits[iHit+1].ID());
     Float_t x1, y1, z1, x2, y2, z2;    
-    t.GetDCAPoint( row1.X(), c1.Y(), c1.Z(), x1, y1, z1 );
-    t.GetDCAPoint( row2.X(), c2.Y(), c2.Z(), x2, y2, z2 );
+    t.GetDCAPoint( row1.X(), c1.Y(), c1.Z(), x1, y1, z1,fSlice->Param().Bz()  );
+    t.GetDCAPoint( row2.X(), c2.Y(), c2.Z(), x2, y2, z2,fSlice->Param().Bz()  );
 
     //if( color<0 ) color = GetColorZ( (z1+z2)/2. );
     Double_t vx1, vy1, vx2, vy2;
@@ -1287,8 +1284,8 @@ void AliHLTTPCCADisplay::DrawTrack( AliHLTTPCCATrack &track, Int_t color, Bool_t
     //if( DrawHits ) ConnectHits( fSlice->ID2IRow(vHits[iHit].ID()),c1,
     //fSlice->ID2IRow(vHits[iHit+1].ID()),c2, color );
     Float_t x1, y1, z1, x2, y2, z2;
-    t.GetDCAPoint( row1.X(), c1.Y(), c1.Z(), x1, y1, z1 );
-    t.GetDCAPoint( row2.X(), c2.Y(), c2.Z(), x2, y2, z2 );
+    t.GetDCAPoint( row1.X(), c1.Y(), c1.Z(), x1, y1, z1,fSlice->Param().Bz()  );
+    t.GetDCAPoint( row2.X(), c2.Y(), c2.Z(), x2, y2, z2,fSlice->Param().Bz()  );
 
     Double_t vx1, vy1, vx2, vy2;
     Slice2View(x1, y1, &vx1, &vy1 );
index 2cf096012d030513b745bf86ba561d23cb20d970..b93889c8e7157d4c8fe6ff1f5a7b4dd7de248f1a 100644 (file)
@@ -28,6 +28,7 @@
 #include "AliHLTTPCCAMergerOutput.h"
 #include "AliHLTTPCCADataCompressor.h"
 #include "AliHLTTPCCAMath.h"
+#include "AliHLTTPCCATrackLinearisation.h"
 #include "TStopwatch.h"
 
 //#define DRAW
@@ -47,13 +48,14 @@ AliHLTTPCCAGBTracker::AliHLTTPCCAGBTracker()
     fTrackHits(0), 
     fTracks(0), 
     fNTracks(0),
-    fSliceTrackInfos(0),
+    fMerger(0),    
     fTime(0),
     fStatNEvents(0),
     fSliceTrackerTime(0)
 {
   //* constructor
   for( Int_t i=0; i<20; i++ ) fStatTime[i] = 0;
+  fMerger = new AliHLTTPCCAMerger;
 }
 
 AliHLTTPCCAGBTracker::AliHLTTPCCAGBTracker(const AliHLTTPCCAGBTracker&)
@@ -66,7 +68,7 @@ AliHLTTPCCAGBTracker::AliHLTTPCCAGBTracker(const AliHLTTPCCAGBTracker&)
     fTrackHits(0), 
     fTracks(0), 
     fNTracks(0),
-    fSliceTrackInfos(0),
+    fMerger(0),
     fTime(0),
     fStatNEvents(0),
     fSliceTrackerTime(0)
@@ -84,49 +86,24 @@ AliHLTTPCCAGBTracker::~AliHLTTPCCAGBTracker()
 {
   //* destructor
   StartEvent();
-  if( fSliceTrackInfos ){
-    for( Int_t iSlice=0; iSlice<fNSlices; iSlice++ ){
-      if( fSliceTrackInfos[iSlice] ) delete[] fSliceTrackInfos[iSlice];
-      fSliceTrackInfos[iSlice] = 0;
-    }
-    delete[] fSliceTrackInfos;
-  }
-  fSliceTrackInfos = 0;
   if( fSlices ) delete[] fSlices;
   fSlices=0;
+  delete fMerger;
 }
 
 void AliHLTTPCCAGBTracker::SetNSlices( Int_t N )
 {
   //* set N of slices
   StartEvent();
-  if( fSliceTrackInfos ){
-    for( Int_t iSlice=0; iSlice<fNSlices; iSlice++ ){
-      if( fSliceTrackInfos[iSlice] ) delete[] fSliceTrackInfos[iSlice];
-      fSliceTrackInfos[iSlice] = 0;
-    }
-    delete[] fSliceTrackInfos;
-  }
-  fSliceTrackInfos = 0;
   fNSlices = N;
   if( fSlices ) delete[] fSlices;
   fSlices=0;
   fSlices = new AliHLTTPCCATracker[N];
-  fSliceTrackInfos = new AliHLTTPCCAGBSliceTrackInfo *[N];
-  for( Int_t iSlice=0; iSlice<fNSlices; iSlice++ ){
-    fSliceTrackInfos[iSlice] = 0;
-  }
 }
 
 void AliHLTTPCCAGBTracker::StartEvent()
 {
   //* clean up track and hit arrays
-  if( fSliceTrackInfos ){
-    for( Int_t iSlice=0; iSlice<fNSlices; iSlice++ ){      
-      if( fSliceTrackInfos[iSlice] ) delete[] fSliceTrackInfos[iSlice];
-      fSliceTrackInfos[iSlice] = 0;
-    }
-  }
   if( fTrackHits ) delete[] fTrackHits;
   fTrackHits = 0;
   if( fTracks ) delete[] fTracks;
@@ -194,6 +171,7 @@ void AliHLTTPCCAGBTracker::FindTracks()
   // Read hits, row by row
 
   Int_t nHitsTotal = fNHits;
+  Float_t *hitX = new Float_t [nHitsTotal];
   Float_t *hitY = new Float_t [nHitsTotal];
   Float_t *hitZ = new Float_t [nHitsTotal];
 
@@ -221,12 +199,13 @@ void AliHLTTPCCAGBTracker::FindTracks()
       rowFirstHits[ir] = firstRowHit;
       for( Int_t ih=0; ih<rowNHits[is][ir]; ih++){
        AliHLTTPCCAGBHit &h = fHits[firstSliceHit + firstRowHit + ih];    
+       hitX[firstRowHit + ih] = h.X();
        hitY[firstRowHit + ih] = h.Y();
        hitZ[firstRowHit + ih] = h.Z(); 
       }
       firstRowHit+=rowNHits[is][ir];
     }    
-    fSlices[is].ReadEvent( rowFirstHits, &*rowNHits[is], hitY, hitZ, sliceNHits[is] );
+    fSlices[is].ReadEvent( rowFirstHits, &*rowNHits[is], hitX, hitY, hitZ, sliceNHits[is] );
    
     //Int_t data[ rowNHits[is]]
     //AliHLTTPCCAEventHeader event;
@@ -239,6 +218,9 @@ void AliHLTTPCCAGBTracker::FindTracks()
     for( Int_t i=0; i<fNSlices; i++ ) delete[] rowNHits[i];
     delete[] rowNHits;
   }
+
+  delete[] hitX;
+  hitX = 0;
   if( hitY ) delete[] hitY;
   hitY=0;
   if( hitZ ) delete[] hitZ;
@@ -272,31 +254,10 @@ void AliHLTTPCCAGBTracker::FindTracks()
   //std::cout<<"blaTime = "<<timer2.CpuTime()*1.e3<<std::endl;
   fSliceTrackerTime = timer2.CpuTime();
   
-  for( Int_t iSlice=0; iSlice<fNSlices; iSlice++ ){
-    AliHLTTPCCATracker &iS = fSlices[iSlice];
-    if( fSliceTrackInfos[iSlice] ) delete[] fSliceTrackInfos[iSlice];
-    fSliceTrackInfos[iSlice]=0;
-    Int_t iNTracks = *iS.NOutTracks();
-    fSliceTrackInfos[iSlice] = new AliHLTTPCCAGBSliceTrackInfo[iNTracks];
-
-    for( Int_t itr=0; itr<iNTracks; itr++ ){
-      fSliceTrackInfos[iSlice][itr].fPrevNeighbour = -1;
-      fSliceTrackInfos[iSlice][itr].fNextNeighbour = -1; 
-      fSliceTrackInfos[iSlice][itr].fUsed = 0;
-    }
-  }
-  
   //std::cout<<"Start CA merging"<<std::endl;
-  TStopwatch timerM;
-  Refit(); 
-  timerM.Stop();
-  fStatTime[9]+=timerM.CpuTime();  
-  //fTime+=timerMerge.CpuTime();
-  //std::cout<<"Refit time = "<<timerM.CpuTime()*1.e3<<"ms"<<std::endl;
 
   TStopwatch timerMerge;
-  //Merging(); 
-  Merging1(); 
+  Merge(); 
   timerMerge.Stop();
   fStatTime[9]+=timerMerge.CpuTime();  
   //fTime+=timerMerge.CpuTime();
@@ -310,7 +271,7 @@ void AliHLTTPCCAGBTracker::FindTracks()
 #endif //DRAW
 }
 
-void AliHLTTPCCAGBTracker::Merging1()
+void AliHLTTPCCAGBTracker::Merge()
 {
   // test 
 
@@ -333,7 +294,9 @@ void AliHLTTPCCAGBTracker::Merging1()
 #endif //DRAW  
 
 
-  AliHLTTPCCAMerger merger;
+  AliHLTTPCCAMerger &merger = *fMerger;
+
+  merger.Clear();
   merger.SetSliceParam( fSlices[0].Param() );
 
   for( Int_t i=0; i<fNSlices; i++ ) {
@@ -393,335 +356,47 @@ void AliHLTTPCCAGBTracker::Merging1()
 }
 
 
-void AliHLTTPCCAGBTracker::Refit()
-{
-  //* Refit the slice tracks
-
-  Int_t maxNRows = fSlices[0].Param().NRows();
-  
-  for( Int_t iSlice = 0; iSlice<fNSlices; iSlice++ ){
-    
-    AliHLTTPCCATracker &slice = fSlices[iSlice];
-
-    for( Int_t itr=0; itr<*slice.NOutTracks(); itr++ ){
-
-      AliHLTTPCCAOutTrack &iTr = slice.OutTracks()[itr];
-
-      struct FitPoint{    
-       Int_t fISlice;
-       Int_t fHitID;
-       Float_t fX, fY, fZ, fErr2Y, fErr2Z, fAmp;
-      } fitPoints[300];
-      for( Int_t i=0; i<maxNRows; i++ ) fitPoints[i].fISlice = -1;
-      
-      Int_t nHits = 0;
-
-      for( Int_t ihit=0; ihit<iTr.NHits(); ihit++){
-       Int_t id = fFirstSliceHit[iSlice] + slice.OutTrackHits()[iTr.FirstHitRef()+ihit];
-       AliHLTTPCCAGBHit &h = fHits[id];
-       FitPoint &p =  fitPoints[h.IRow()];
-       if( p.fISlice >=0 ) continue;
-       p.fISlice = h.ISlice();
-       p.fHitID = id;
-       p.fX = slice.Row(h.IRow()).X();
-       p.fY = h.Y();
-       p.fZ = h.Z();
-       p.fAmp = h.Amp();
-       nHits++;            
-      }
-     
-      //if( nHits < 10 ) continue; SG!!!
-
-      Int_t firstRow = 0, lastRow = maxNRows-1;
-      for( firstRow=0; firstRow<maxNRows; firstRow++ ){
-       if( fitPoints[firstRow].fISlice>=0 ) break;
-      }
-      for( lastRow=maxNRows-1; lastRow>=0; lastRow-- ){
-       if( fitPoints[lastRow].fISlice>=0 ) break;
-      }
-      Int_t mmidRow = (firstRow + lastRow )/2;
-      Int_t midRow = firstRow;
-      for( Int_t i=firstRow+1; i<=lastRow; i++ ){
-       if( fitPoints[i].fISlice<0 ) continue;  
-       if( CAMath::Abs(i-mmidRow)>=CAMath::Abs(midRow-mmidRow) ) continue;
-       midRow = i;
-      }
-      if( midRow==firstRow || midRow==lastRow ) continue;
-      
-      Int_t searchRows[300];
-      Int_t nSearchRows = 0;
-
-      for( Int_t i=firstRow; i<=lastRow; i++ ) searchRows[nSearchRows++] = i;
-      
-      //std::cout<<"\nRefit slice "<<iSlice<<" track "<<itr<<": "<<std::endl;
-
-     // refit down 
-      {
-       AliHLTTPCCATrackParam t0 = iTr.StartPoint();
-       /*
-         {     
-         
-         {
-         FitPoint &p0 =  fitPoints[firstRow];
-         FitPoint &p1 =  fitPoints[midRow];
-         FitPoint &p2 =  fitPoints[lastRow];
-         Float_t x0=p0.fX, y0=p0.fY, z0=p0.fZ;
-         Float_t x1=p1.fX, y1=p1.fY, z1=p1.fZ;
-         Float_t x2=p2.fX, y2=p2.fY, z2=p2.fZ;
-         Float_t sp0[5] = {x0, y0, z0, .5, .5 };       
-         Float_t sp1[5] = {x1, y1, z1, .5, .5 };
-         Float_t sp2[5] = {x2, y2, z2, .5, .5 };
-         t0.ConstructXYZ3(sp0,sp1,sp2,1., 0);
-       }
-               
-       for( Int_t rowID=0; rowID<nSearchRows; rowID++ ){
-         Int_t iRow = searchRows[rowID];         
-         FitPoint &p =  fitPoints[iRow];         
-         if( p.fISlice<0 ) continue;
-         if( !t0.TransportToX( p.fX, .99 ) ) continue;
-         GetErrors2( p.fISlice, iRow, t0, p.fErr2Y, p.fErr2Z );
-         t0.Filter2( p.fY, p.fZ, p.fErr2Y, p.fErr2Z, .99 );      
-       }
-       */
-       //* final refit, dE/dx calculation
-       //std::cout<<"\n\nstart refit..\n"<<std::endl;
-
-       AliHLTTPCCATrackParam t00 = t0;
-       AliHLTTPCCATrackParam::AliHLTTPCCATrackFitParam fitPar;
-       if(1){
-         Double_t sumDeDx = 0;
-         Int_t nDeDx = 0;
-         
-         t0.CalculateFitParameters( fitPar, fSlices[0].Param().Bz() );
-         /*
-           t0.Cov()[ 0] = .1;
-           t0.Cov()[ 1] = 0;
-           t0.Cov()[ 2] = .1;
-           t0.Cov()[ 3] = 0;
-           t0.Cov()[ 4] = 0;
-           t0.Cov()[ 5] = .1;
-           t0.Cov()[ 6] = 0;
-           t0.Cov()[ 7] = 0;
-           t0.Cov()[ 8] = 0;
-           t0.Cov()[ 9] = .1;
-           t0.Cov()[10] = 0;
-           t0.Cov()[11] = 0;
-           t0.Cov()[12] = 0;
-           t0.Cov()[13] = 0;
-           t0.Cov()[14] = .1;
-         */
-         t0.SetChi2( 0 );
-         t0.SetNDF( -5 );      
-         Bool_t first = 1;
-         for( Int_t iRow = maxNRows-1; iRow>=0; iRow-- ){
-           FitPoint &p =  fitPoints[iRow];
-           if( p.fISlice<0 ) continue;
-           //std::cout<<" row "<<iRow<<std::endl;         
-           //t00.Print();
-           //t0.Print();
-           //if( !t0.TransportToX( p.fX, t00, .99 ) ){
-           if( !t0.TransportToXWithMaterial( p.fX, t00, fitPar ) ){
-             //std::cout<<"row "<<iRow<<": can not transport!!!"<<std::endl;
-             //t00.Print();
-             //t0.Print();
-             continue;     
-           }
-           
-           //* Update the track
-           
-           if( first ){
-             t0.SetCov( 0, 10 );
-             t0.SetCov( 1,  0 );
-             t0.SetCov( 2, 10 );
-             t0.SetCov( 3,  0 );
-             t0.SetCov( 4,  0 );
-             t0.SetCov( 5,  1 );
-             t0.SetCov( 6,  0 );
-             t0.SetCov( 7,  0 );
-             t0.SetCov( 8,  0 );
-             t0.SetCov( 9,  1 );
-             t0.SetCov(10,  0 );
-             t0.SetCov(11,  0 );
-             t0.SetCov(12,  0 );
-             t0.SetCov(13,  0 );
-             t0.SetCov(14,  1 );
-             t0.SetChi2( 0 );
-             t0.SetNDF( -5 );
-           }
-           
-           slice.GetErrors2( iRow, t00, p.fErr2Y, p.fErr2Z );
-
-           if( !t0.Filter2NoCos( p.fY, p.fZ, p.fErr2Y, p.fErr2Z ) ){
-             //std::cout<<"row "<<iRow<<": can not filter!!!"<<std::endl;
-             //t00.Print();
-             //t0.Print();
-             continue;   
-           }
-           first = 0;
-           
-           if( CAMath::Abs( t00.CosPhi() )>1.e-4 ){
-             Float_t dLdX = CAMath::Sqrt(1.+t00.DzDs()*t00.DzDs())/CAMath::Abs(t00.CosPhi());
-             sumDeDx+=p.fAmp/dLdX;
-             nDeDx++;
-           }
-           
-         }
-         //t.DeDx() = 0;
-         //if( nDeDx >0 ) t.DeDx() = sumDeDx/nDeDx;
-         if( t0.GetErr2Y()<=0 ){
-           //std::cout<<"nhits = "<<t.NHits()<<", t0.GetErr2Y() = "<<t0.GetErr2Y()<<std::endl;
-           //t0.Print();
-           //exit(1);
-         }
-       }
-       
-       {
-         Bool_t ok=1;
-         
-         const Float_t *c = t0.Cov();
-         for( Int_t i=0; i<15; i++ ) ok = ok && finite(c[i]);
-         for( Int_t i=0; i<5; i++ ) ok = ok && finite(t0.Par()[i]);
-         ok = ok && (t0.GetX()>50);
-         
-         if( c[0]<=0 || c[2]<=0 || c[5]<=0 || c[9]<=0 || c[14]<=0 ) ok = 0;
-         //if( c[0]>5. || c[2]>5. || c[5]>2. || c[9]>2 || c[14]>2 ) ok = 0;
-
-         if( CAMath::Abs(t0.SinPhi())>.99 ) ok = 0;
-         else t0.SetCosPhi( CAMath::Sqrt(1.-t0.SinPhi()*t0.SinPhi()) );
-
-         if(!ok){
-           //std::cout<<" nan check: track rejected"<<std::endl;
-           //nRejected++;
-           //std::cout<<"\n\nRejected: "<<nRejected<<"\n"<<std::endl;
-           continue;
-         }
-       }
-       
-       if( CAMath::Abs(t0.Kappa())<1.e-8 ) t0.SetKappa( 1.e-8 );       
-       t0.TransportToX( slice.Row(firstRow).X(), .99 );
-       iTr.SetStartPoint( t0 );
-      }
-
-      // refit up 
-      {
-       AliHLTTPCCATrackParam t0 = iTr.StartPoint();
-
-       AliHLTTPCCATrackParam t00 = t0;
-       AliHLTTPCCATrackParam::AliHLTTPCCATrackFitParam fitPar;
-       if(1){
-         
-         t0.CalculateFitParameters( fitPar, fSlices[0].Param().Bz() );
-         t0.SetChi2( 0 );
-         t0.SetNDF( -5 );      
-         Bool_t first = 1;
-         for( Int_t iRow = 0; iRow<maxNRows; iRow++ ){
-           FitPoint &p =  fitPoints[iRow];
-           if( p.fISlice<0 ) continue;
-           if( !t0.TransportToXWithMaterial( p.fX, t00, fitPar ) ){
-             //std::cout<<"row "<<iRow<<": can not transport!!!"<<std::endl;
-             //t00.Print();
-             //t0.Print();
-             continue;     
-           }
-           
-           //* Update the track
-           
-           if( first ){
-             t0.SetCov( 0, 10 );
-             t0.SetCov( 1,  0 );
-             t0.SetCov( 2, 10 );
-             t0.SetCov( 3,  0 );
-             t0.SetCov( 4,  0 );
-             t0.SetCov( 5,  1 );
-             t0.SetCov( 6,  0 );
-             t0.SetCov( 7,  0 );
-             t0.SetCov( 8,  0 );
-             t0.SetCov( 9,  1 );
-             t0.SetCov(10,  0 );
-             t0.SetCov(11,  0 );
-             t0.SetCov(12,  0 );
-             t0.SetCov(13,  0 );
-             t0.SetCov(14,  1 );
-             t0.SetChi2( 0 );
-             t0.SetNDF( -5 );
-           }
-           
-           slice.GetErrors2( iRow, t00, p.fErr2Y, p.fErr2Z );
-
-           if( !t0.Filter2NoCos( p.fY, p.fZ, p.fErr2Y, p.fErr2Z ) ){
-             //std::cout<<"row "<<iRow<<": can not filter!!!"<<std::endl;
-             //t00.Print();
-             //t0.Print();
-             continue;   
-           }
-           first = 0;
-         }
-       }
-       
-       {
-         Bool_t ok=1;
-         
-         const Float_t *c = t0.Cov();
-         for( Int_t i=0; i<15; i++ ) ok = ok && finite(c[i]);
-         for( Int_t i=0; i<5; i++ ) ok = ok && finite(t0.Par()[i]);
-         ok = ok && (t0.GetX()>50);
-         
-         if( c[0]<=0 || c[2]<=0 || c[5]<=0 || c[9]<=0 || c[14]<=0 ) ok = 0;
-         //if( c[0]>5. || c[2]>5. || c[5]>2. || c[9]>2 || c[14]>2 ) ok = 0;
-
-         if( CAMath::Abs(t0.SinPhi())>.99 ) ok = 0;
-         else t0.SetCosPhi( CAMath::Sqrt(1.-t0.SinPhi()*t0.SinPhi()) );
-
-         if(!ok){
-           //std::cout<<" refit: nan check: track rejected"<<std::endl;
-           //nRejected++;
-           //std::cout<<"\n\nRejected: "<<nRejected<<"\n"<<std::endl;
-           continue;
-         }
-       }
-       
-       if( CAMath::Abs(t0.Kappa())<1.e-8 ) t0.SetKappa( 1.e-8 );       
-       t0.TransportToX( slice.Row(lastRow).X(), .99 );
-       iTr.SetEndPoint( t0 );          
-
-      }
-    }
-  }
-}
-
 
 Bool_t AliHLTTPCCAGBTracker::FitTrack( AliHLTTPCCATrackParam &T, AliHLTTPCCATrackParam t0, 
-                                      Float_t &Alpha, Int_t hits[], Int_t &NTrackHits, Float_t &DeDx,
+                                      Float_t &Alpha, Int_t hits[], Int_t &NTrackHits,
                                       Bool_t dir )
 {
   // Fit the track
+  
+  //return fMerger->FitTrack( T, Alpha, t0, Alpha, hits, NTrackHits, dir );
+
+  Float_t alpha0 = Alpha;
 
   AliHLTTPCCATrackParam::AliHLTTPCCATrackFitParam fitPar;
-  Double_t sumDeDx = 0;
-  Int_t nDeDx = 0;
   AliHLTTPCCATrackParam t = t0;
+  AliHLTTPCCATrackLinearisation l(t0);
+
   Bool_t first = 1;
  
-  t0.CalculateFitParameters( fitPar, fSlices[0].Param().Bz() );
+  t.CalculateFitParameters( fitPar );
 
   Int_t hitsNew[1000];
   Int_t nHitsNew = 0;
 
   for( Int_t ihit=0; ihit<NTrackHits; ihit++){
+    
     Int_t jhit = dir ?(NTrackHits-1-ihit) :ihit;
     AliHLTTPCCAGBHit &h = fHits[hits[jhit]];
+
     Int_t iSlice = h.ISlice();
-    AliHLTTPCCATracker &slice = fSlices[iSlice];
 
-    if( CAMath::Abs( slice.Param().Alpha()-Alpha)>1.e-4 ){
-      if( ! t.RotateNoCos(  slice.Param().Alpha() - Alpha, t0, .999 ) ) continue;
-      Alpha = slice.Param().Alpha();
+    Float_t sliceAlpha =  fSlices[0].Param().Alpha( iSlice );
+
+    if( CAMath::Abs( sliceAlpha - alpha0)>1.e-4 ){
+      if( ! t.Rotate(  sliceAlpha - alpha0, l, .999 ) ) continue;
+      alpha0 = sliceAlpha;
     }
 
-    Float_t x = slice.Row(h.IRow()).X();
+    //Float_t x = fSliceParam.RowX( h.IRow() );
+    Float_t x = h.X();
+    
+    if( !t.TransportToXWithMaterial( x, l, fitPar, fSlices[0].Param().GetBz(t) ) ) continue;
     
-    if( !t.TransportToXWithMaterial( x, t0, fitPar ) ) continue;
-
     if( first ){
       t.SetCov( 0, 10 );
       t.SetCov( 1,  0 );
@@ -737,30 +412,23 @@ Bool_t AliHLTTPCCAGBTracker::FitTrack( AliHLTTPCCATrackParam &T, AliHLTTPCCATrac
       t.SetCov(11,  0 );
       t.SetCov(12,  0 );
       t.SetCov(13,  0 );
-      t.SetCov(14,  1 );
+      t.SetCov(14,  10 );
       t.SetChi2( 0 );
       t.SetNDF( -5 );
-      t0.CalculateFitParameters( fitPar, fSlices[0].Param().Bz() );
+      t.CalculateFitParameters( fitPar );
     }
-  
+
+    
     Float_t err2Y, err2Z;
-    slice.GetErrors2( h.IRow(), t0, err2Y, err2Z );
-    if( !t.Filter2NoCos( h.Y(), h.Z(), err2Y, err2Z ) ) continue;                  
+    fSlices[0].Param().GetClusterErrors2( h.IRow(), h.Z(), l.SinPhi(), l.CosPhi(), l.DzDs(), err2Y, err2Z );
+    if( !t.Filter( h.Y(), h.Z(), err2Y, err2Z ) ) continue;                
+
     first = 0;
 
-    if( CAMath::Abs( t0.CosPhi() )>1.e-4 ){
-      Float_t dLdX = CAMath::Sqrt(1.+t0.DzDs()*t0.DzDs())/CAMath::Abs(t0.CosPhi());
-      sumDeDx+=h.Amp()/dLdX;
-      nDeDx++;
-    }
     hitsNew[nHitsNew++] = hits[jhit];
   }
   
-
-  DeDx = 0;
-  if( nDeDx >0 ) DeDx = sumDeDx/nDeDx;
-       
-  if( CAMath::Abs(t.Kappa())<1.e-8 ) t.SetKappa( 1.e-8 );
+  if( CAMath::Abs(t.QPt())<1.e-8 ) t.SetQPt( 1.e-8 );
   
   Bool_t ok=1;
   
@@ -770,14 +438,15 @@ Bool_t AliHLTTPCCAGBTracker::FitTrack( AliHLTTPCCATrackParam &T, AliHLTTPCCATrac
   ok = ok && (t.GetX()>50);
   
   if( c[0]<=0 || c[2]<=0 || c[5]<=0 || c[9]<=0 || c[14]<=0 ) ok = 0;
-  if( c[0]>5. || c[2]>5. || c[5]>2. || c[9]>2 || c[14]>2 ) ok = 0;
+  if( c[0]>5. || c[2]>5. || c[5]>2. || c[9]>2 || c[14]>2. ) ok = 0;
   
   if( CAMath::Abs(t.SinPhi())>.99 ) ok = 0;
-  else if( t0.CosPhi()>=0 ) t.SetCosPhi( CAMath::Sqrt(1.-t.SinPhi()*t.SinPhi()) );
-  else t.SetCosPhi( -CAMath::Sqrt(1.-t.SinPhi()*t.SinPhi()) );
-
+  else if( l.CosPhi()>=0 ) t.SetSignCosPhi( 1 );
+  else t.SetSignCosPhi( -1 );
+  
   if( ok ){
     T = t;
+    Alpha = alpha0;
     NTrackHits = nHitsNew;
     for( Int_t i=0; i<NTrackHits; i++ ){
       hits[dir ?(NTrackHits-1-i) :i] = hitsNew[i];
@@ -787,749 +456,6 @@ Bool_t AliHLTTPCCAGBTracker::FitTrack( AliHLTTPCCATrackParam &T, AliHLTTPCCATrac
 }
 
 
-Float_t AliHLTTPCCAGBTracker::GetChi2( Float_t x1, Float_t y1, Float_t a00, Float_t a10, Float_t a11, 
-                                      Float_t x2, Float_t y2, Float_t b00, Float_t b10, Float_t b11  )
-{
-  //* Calculate Chi2/ndf deviation   
-
-  Float_t d[2]={ x1-x2, y1-y2 };
-
-  Float_t mSi[3] = { a00 + b00, a10 + b10, a11 + b11 };
-
-  Float_t s = ( mSi[0]*mSi[2] - mSi[1]*mSi[1] );
-
-  if( s < 1.E-10 ) return 10000.;
-    
-  Float_t mS[3] = { mSi[2], -mSi[1], mSi[0] };      
-
-  return TMath::Abs( ( ( mS[0]*d[0] + mS[1]*d[1] )*d[0]
-                      +(mS[1]*d[0] + mS[2]*d[1] )*d[1] )/s/2);
-
-}
-
-  
-void AliHLTTPCCAGBTracker::MakeBorderTracks( Int_t iSlice, Int_t iBorder, AliHLTTPCCABorderTrack B[], Int_t &nB )
-{
-  //* prepare slice tracks for merging
-  static int statAll=0, statOK=0;  
-  nB = 0;
-  AliHLTTPCCATracker &slice = fSlices[iSlice];
-  Float_t dAlpha = ( fSlices[1].Param().Alpha() - fSlices[0].Param().Alpha() )/2;
-  Float_t x0 = 0;
-
-  if( iBorder==0 ){
-    dAlpha = dAlpha - CAMath::Pi()/2 ;
-  } else if( iBorder==1 ){
-    dAlpha = -dAlpha - CAMath::Pi()/2 ;  
-  } else if( iBorder==2 ){
-    dAlpha = dAlpha;
-    x0 = slice.Row(63).X();
-  }else if( iBorder==3 ){
-    dAlpha = -dAlpha;
-    x0 = slice.Row(63).X();
-  } else if( iBorder==4 ){
-    dAlpha = 0;
-    x0 = slice.Row(63).X();
-  }
-
-  for (Int_t itr=0; itr<*slice.NOutTracks(); itr++) {
-    AliHLTTPCCAOutTrack &t = slice.OutTracks()[itr];
-
-    AliHLTTPCCATrackParam t0 = t.StartPoint();
-    AliHLTTPCCATrackParam t1 = t.EndPoint();
-    //const Float_t maxSin = .9;
-
-    const Float_t maxSin = CAMath::Sin(60./180.*CAMath::Pi());
-
-    Bool_t ok0 = t0.Rotate( dAlpha, maxSin );
-    Bool_t ok1 = t1.Rotate( dAlpha, maxSin );
-
-    Bool_t do0 = ok0;
-    Bool_t do1 = ok1 && ( !ok0 || t1.CosPhi()*t0.CosPhi()<0 );
-    
-    if( ok0 && !do1 && ok1 && (t1.X() < t0.X()) ){
-      do0 = 0;
-      do1 = 1;
-    }
-
-    if( do0 ){
-      AliHLTTPCCABorderTrack &b = B[nB];
-      b.fOK = 1;
-      b.fITrack = itr;
-      b.fNHits = t.NHits();
-      b.fIRow = fHits[ fFirstSliceHit[iSlice] + slice.OutTrackHits()[t.FirstHitRef()+0]].IRow();
-      b.fParam = t0;
-      b.fX = t0.GetX();
-      if( b.fParam.TransportToX( x0, maxSin ) ) nB++;
-      //else std::cout<<"0: can not transport to x="<<x0<<std::endl;
-
-    }
-    if( do1 ){
-      AliHLTTPCCABorderTrack &b = B[nB];
-      b.fOK = 1;
-      b.fITrack = itr;
-      b.fNHits = t.NHits();
-      b.fIRow = fHits[ fFirstSliceHit[iSlice] + slice.OutTrackHits()[t.FirstHitRef()+t.NHits()-1]].IRow();
-      b.fParam = t1;    
-      b.fX = t0.GetX();
-      if( b.fParam.TransportToX( x0, maxSin ) ) nB++;
-      //else std::cout<<"1: can not transport to x="<<x0<<std::endl;
-    }
-    if( do0 || do1 ) statOK++;
-    statAll++;
-  }
-  //std::cout<<"\n\n Stat all, stat ok = "<<statAll<<" "<<statOK<<std::endl;
-}
-
-
-void AliHLTTPCCAGBTracker::SplitBorderTracks( Int_t iSlice1, AliHLTTPCCABorderTrack B1[], Int_t N1,
-                                             Int_t iSlice2, AliHLTTPCCABorderTrack B2[], Int_t N2, 
-                                             Float_t Alpha 
-                                             )
-{
-  //* split two sets of tracks
-
-  Float_t factor2y = 10;//2.6;
-  Float_t factor2z = 10;//4.0;
-  Float_t factor2s = 10;//2.6;
-  Float_t factor2t = 10;//2.0;
-  Float_t factor2k = 2.0;//2.2;
-
-  Float_t factor2ys = 1.;//1.5;//SG!!!
-  Float_t factor2zt = 1.;//1.5;//SG!!!
-
-  AliHLTTPCCATracker &slice1 = fSlices[iSlice1];
-  AliHLTTPCCATracker &slice2 = fSlices[iSlice2];
-  factor2y = 3.5*3.5*factor2y*factor2y;
-  factor2z = 3.5*3.5*factor2z*factor2z;
-  factor2s = 3.5*3.5*factor2s*factor2s;
-  factor2t = 3.5*3.5*factor2t*factor2t;
-  factor2k = 3.5*3.5*factor2k*factor2k;
-  factor2ys = 3.5*3.5*factor2ys*factor2ys;
-  factor2zt = 3.5*3.5*factor2zt*factor2zt;
-
-  Int_t minNPartHits = 10;//SG!!!
-  Int_t minNTotalHits = 20;
-  //Float_t maxDX = slice1.Row(40).X() -  slice1.Row(0).X();
-
-  for (Int_t i1=0; i1<N1; i1++) {      
-    AliHLTTPCCABorderTrack &b1 = B1[i1];
-    if( !b1.fOK ) continue;
-    if( b1.fNHits < minNPartHits ) continue;
-    AliHLTTPCCATrackParam &t1 = b1.fParam;
-    Int_t iBest2 = -1;
-    Int_t lBest2 = 0;
-    Int_t start2 = (iSlice1!=iSlice2) ?0 :i1+1;
-    for (Int_t i2=start2; i2<N2; i2++) {
-      AliHLTTPCCABorderTrack &b2 = B2[i2];
-      if( !b2.fOK ) continue;  
-      if( b2.fNHits < minNPartHits ) continue;
-      if( b2.fNHits < lBest2 ) continue;       
-      if( b1.fNHits + b2.fNHits < minNTotalHits ) continue;
-      //if( TMath::Abs(b1.fX - b2.fX)>maxDX ) continue;
-      AliHLTTPCCATrackParam &t2 = b2.fParam;         
-
-      if( Alpha!=-1 ){
-#ifdef DRAW
-       std::cout<<"Try to merge tracks "<<i1<<" and "<<i2<<":"<<std::endl;
-       t1.Print();
-       t2.Print();
-
-       Float_t c= t2.CosPhi()*t1.CosPhi()>0 ?1 :-1;
-       Float_t dy = t2.GetY() - t1.GetY();
-       Float_t dz = t2.GetZ() - t1.GetZ();
-       Float_t ds = t2.GetSinPhi() - c*t1.GetSinPhi();
-       Float_t dt = t2.GetDzDs() - c*t1.GetDzDs();
-       Float_t dk = t2.GetKappa() - c*t1.GetKappa(); 
-       
-       Float_t chi2ys = GetChi2( t1.GetY(),t1.GetSinPhi(),t1.GetCov()[0],t1.GetCov()[3],t1.GetCov()[5], 
-                                 t2.GetY(),t2.GetSinPhi(),t2.GetCov()[0],t2.GetCov()[3],t2.GetCov()[5] );
-       Float_t chi2zt = GetChi2( t1.GetZ(),t1.GetDzDs(),t1.GetCov()[2],t1.GetCov()[7],t1.GetCov()[9], 
-                                 t2.GetZ(),t2.GetDzDs(),t2.GetCov()[2],t2.GetCov()[7],t2.GetCov()[9] );
-
-
-
-       Float_t sy2 = t2.GetErr2Y() + t1.GetErr2Y();
-       Float_t sz2 = t2.GetErr2Z() + t1.GetErr2Z();
-       Float_t ss2 = t2.GetErr2SinPhi() + t1.GetErr2SinPhi();
-       Float_t st2 = t2.GetErr2DzDs() + t1.GetErr2DzDs();
-       Float_t sk2 = t2.GetErr2Kappa() + t1.GetErr2Kappa();
-       
-       std::cout<<"dy, sy= "<<dy<<" "<<CAMath::Sqrt(factor2y*sy2)<<std::endl;
-       std::cout<<"dz, sz= "<<dz<<" "<<CAMath::Sqrt(factor2z*sz2)<<std::endl;
-       std::cout<<"ds, ss= "<<ds<<" "<<CAMath::Sqrt(factor2s*ss2)<<std::endl;
-       std::cout<<"dt, st= "<<dt<<" "<<CAMath::Sqrt(factor2t*st2)<<std::endl;
-       std::cout<<"dk, sk= "<<dk<<" "<<CAMath::Sqrt(factor2k*sk2)<<std::endl;
-
-       std::cout<<"dys, sy= "<<CAMath::Sqrt(chi2ys)<<" "<<CAMath::Sqrt(factor2y)<<std::endl;
-       std::cout<<"dzt, st= "<<CAMath::Sqrt(chi2zt)<<" "<<CAMath::Sqrt(factor2z)<<std::endl;
-
-       if( dy*dy<factor2y*sy2
-           && dz*dz<factor2z*sz2 
-           && ds*ds<factor2s*ss2 
-           && dt*dt<factor2t*st2 
-           && dk*dk<factor2k*sk2 
-           ){      
-         std::cout<<"tracks are merged"<<std::endl;
-       } else std::cout<<"tracks are not merged"<<std::endl;
-
-       AliHLTTPCCADisplay::Instance().ClearView();
-       AliHLTTPCCADisplay::Instance().SetTPCView();
-       AliHLTTPCCADisplay::Instance().DrawTPC();
-       AliHLTTPCCADisplay::Instance().DrawGBHits( *this, kGreen, 1. );
-       AliHLTTPCCADisplay::Instance().SetCurrentSlice(&slice1);
-       AliHLTTPCCADisplay::Instance().DrawSliceOutTrack( t1, Alpha, b1.fITrack, kRed, 2. );    
-       AliHLTTPCCADisplay::Instance().SetCurrentSlice(&slice2);
-       AliHLTTPCCADisplay::Instance().DrawSliceOutTrack( t2, Alpha, b2.fITrack, kBlue, 2. );          
-       AliHLTTPCCADisplay::Instance().Ask();
-#endif
-      }
-
-      Float_t chi2ys = GetChi2( t1.GetY(),t1.GetSinPhi(),t1.GetCov()[0],t1.GetCov()[3],t1.GetCov()[5], 
-                               t2.GetY(),t2.GetSinPhi(),t2.GetCov()[0],t2.GetCov()[3],t2.GetCov()[5] );
-      Float_t chi2zt = GetChi2( t1.GetZ(),t1.GetDzDs(),t1.GetCov()[2],t1.GetCov()[7],t1.GetCov()[9], 
-                               t2.GetZ(),t2.GetDzDs(),t2.GetCov()[2],t2.GetCov()[7],t2.GetCov()[9] );
-      if( chi2ys>factor2ys ) continue;
-      if( chi2zt>factor2zt ) continue;
-
-      Float_t dy = t2.GetY() - t1.GetY();
-      Float_t sy2 = t2.GetErr2Y() + t1.GetErr2Y();
-      if( dy*dy>factor2y*sy2 ) continue;
-       
-      Float_t dz = t2.GetZ() - t1.GetZ();
-      Float_t sz2 = t2.GetErr2Z() + t1.GetErr2Z();
-      if( dz*dz>factor2z*sz2 ) continue;       
-       
-      Float_t d, s2;
-      Float_t c= t2.CosPhi()*t1.CosPhi()>0 ?1 :-1;
-
-      d = t2.GetSinPhi() - c*t1.GetSinPhi();
-      s2 = t2.GetErr2SinPhi() + t1.GetErr2SinPhi();
-      if( d*d>factor2s*s2 ) continue;
-      d = t2.GetDzDs() - c*t1.GetDzDs();
-      s2 = t2.GetErr2DzDs() + t1.GetErr2DzDs();
-      if( d*d>factor2t*s2 ) continue;
-      d = t2.GetKappa() - c*t1.GetKappa(); 
-      s2 = t2.GetErr2Kappa() + t1.GetErr2Kappa();
-      if( d*d>factor2k*s2 ) continue;
-       
-      lBest2 = b2.fNHits;
-      iBest2 = b2.fITrack;
-    }
-      
-    if( iBest2>=0 ){   
-      Int_t old1 = fSliceTrackInfos[iSlice2][iBest2].fPrevNeighbour;
-      if( old1 >= 0 ){
-       if( slice1.OutTracks()[ old1 ].NHits() < slice1.OutTracks()[ b1.fITrack ].NHits() ){
-         fSliceTrackInfos[iSlice2][iBest2].fPrevNeighbour = -1;
-         fSliceTrackInfos[iSlice1][old1].fNextNeighbour = -1;  
-       } else continue;
-      }
-      Int_t old2 = fSliceTrackInfos[iSlice1][b1.fITrack].fNextNeighbour;
-      if( old2 >= 0 ){
-       if( slice2.OutTracks()[ old2 ].NHits() < slice2.OutTracks()[ iBest2 ].NHits() ){
-         fSliceTrackInfos[iSlice2][old2].fPrevNeighbour = -1;
-       } else continue;
-      }
-      fSliceTrackInfos[iSlice1][b1.fITrack].fNextNeighbour = iBest2;
-      fSliceTrackInfos[iSlice2][iBest2].fPrevNeighbour = b1.fITrack;   
-    }  
-  }
-}
-
-
-void AliHLTTPCCAGBTracker::Merging()
-{
-  //* track merging between slices
-
-#ifdef DRAW
-  AliHLTTPCCADisplay &disp = AliHLTTPCCADisplay::Instance();
-  if(0){
-  disp.SetSliceView();
-  for( Int_t iSlice=0; iSlice<fNSlices; iSlice++ ){
-    AliHLTTPCCATracker &slice = fSlices[iSlice];
-    Int_t nh=fFirstSliceHit[iSlice+1]-fFirstSliceHit[iSlice];
-    if( nh<=0 ) continue;
-    disp.SetCurrentSlice(&slice);
-    disp.DrawSlice( &slice );
-    //disp.DrawGBHits( *this, -1, .5 );
-    disp.DrawSliceHits(-1,.5);
-    disp.Ask();
-    std::cout<<"N out tracks = "<<*slice.NOutTracks()<<std::endl;
-    for( Int_t itr=0; itr<*slice.NOutTracks(); itr++ ){
-      std::cout<<"track N "<<itr<<", nhits="<<slice.OutTracks()[itr].NHits()<<std::endl;
-      disp.DrawSliceOutTrack( itr, kRed );
-      disp.Ask();
-      int id = slice.OutTracks()[itr].OrigTrackID();
-      disp.DrawSliceTrack( id, kBlue );
-      disp.Ask();
-    }
-    disp.Ask();
-  }
-  }
-  AliHLTTPCCADisplay::Instance().SetTPCView();
-  AliHLTTPCCADisplay::Instance().DrawTPC();
-  AliHLTTPCCADisplay::Instance().DrawGBHits( *this );
-  disp.Ask(); 
-  std::cout<<"Slice tracks:"<<std::endl;
-  for( Int_t iSlice=0; iSlice<fNSlices; iSlice++ ){
-    AliHLTTPCCATracker &slice = fSlices[iSlice];
-    disp.SetCurrentSlice(&slice);    
-    for( Int_t itr=0; itr<*slice.NOutTracks(); itr++ ){
-      disp.DrawSliceOutTrack( itr, kBlue, 2. );
-    }
-  }
-  //AliHLTTPCCADisplay::Instance().DrawGBHits( *this );
-  disp.Ask(); 
-#endif //DRAW  
-
-  Int_t nextSlice[100], prevSlice[100];
-
-  for( Int_t iSlice=0; iSlice<fNSlices; iSlice++ ){
-    nextSlice[iSlice] = iSlice + 1;
-    prevSlice[iSlice] = iSlice - 1;
-  }
-  Int_t mid = NSlices()/2 - 1 ;
-  Int_t last = NSlices() - 1 ;
-  if( mid<0 ) mid = 0; // to avoid compiler warning
-  if( last<0 ) last = 0; // 
-  nextSlice[ mid ] = 0;
-  prevSlice[ 0 ] = mid;
-  nextSlice[ last ] = fNSlices/2;
-  prevSlice[ fNSlices/2 ] = last;
-  
-  Int_t maxNSliceTracks = 0;
-  for( Int_t iSlice=0; iSlice<fNSlices; iSlice++ ){
-    AliHLTTPCCATracker &iS = fSlices[iSlice];
-    if( maxNSliceTracks < *iS.NOutTracks() ) maxNSliceTracks = *iS.NOutTracks();
-  }
-  
-  if(1){// merging segments withing one slice //SG!!!
-
-    AliHLTTPCCABorderTrack bord[maxNSliceTracks*10];
-
-    for( Int_t iSlice=0; iSlice<fNSlices; iSlice++ ){         
-      //std::cout<<" merging tracks withing slice "<<iSlice<<":"<<std::endl;
-
-#ifdef DRAW
-  if(0){
-    AliHLTTPCCADisplay &disp = AliHLTTPCCADisplay::Instance();
-    std::cout<<" merging tracks withing slice "<<iSlice<<":"<<std::endl;
-    disp.SetSliceView();
-    AliHLTTPCCATracker &slice = fSlices[iSlice];
-    Int_t nh=fFirstSliceHit[iSlice+1]-fFirstSliceHit[iSlice];
-    if( nh>0 ){
-      disp.SetCurrentSlice(&slice);
-      disp.DrawSlice( &slice );
-      disp.DrawSliceHits(-1,.5);
-      std::cout<<"N out tracks = "<<*slice.NOutTracks()<<std::endl;
-      for( Int_t itr=0; itr<*slice.NOutTracks(); itr++ ){
-       std::cout<<"track N "<<itr<<", nhits="<<slice.OutTracks()[itr].NHits()<<std::endl;
-       disp.DrawSliceOutTrack( itr, kRed );
-       //disp.Ask();
-       //int id = slice.OutTracks()[itr].OrigTrackID();
-       //disp.DrawSliceTrack( id, kBlue );
-       //disp.Ask();
-      }
-      disp.Ask();
-    }  
-  }  
-#endif //DRAW  
-
-
-      AliHLTTPCCATracker &iS = fSlices[iSlice];
-      Int_t nBord=0;
-      MakeBorderTracks( iSlice, 4, bord, nBord );
-#ifdef DRAW
-      std::cout<<"\nMerge tracks withing slice "<<iSlice<<":\n"<<std::endl;
-#endif
-      Float_t alph = -1;//iS.Param().Alpha();
-      SplitBorderTracks( iSlice, bord, nBord, iSlice, bord, nBord, alph );    
-
-      AliHLTTPCCAOutTrack tmpT[*iS.NOutTracks()];
-      Int_t tmpH[*iS.NOutTrackHits()];
-      Int_t nTr=0, nH=0;
-      for( Int_t itr=0; itr<*iS.NOutTracks(); itr++ ){
-       fSliceTrackInfos[iSlice][itr].fPrevNeighbour = -1;
-       if( fSliceTrackInfos[iSlice][itr].fNextNeighbour == -2 ){
-         fSliceTrackInfos[iSlice][itr].fNextNeighbour = -1;
-         continue;
-       }
-       AliHLTTPCCAOutTrack &it = iS.OutTracks()[itr];
-       AliHLTTPCCAOutTrack &t = tmpT[nTr];
-       t = it;
-       t.SetFirstHitRef( nH );
-       for( Int_t ih=0; ih<it.NHits(); ih++ ) tmpH[nH+ih] = iS.OutTrackHits()[it.FirstHitRef()+ih];
-       nTr++;
-       nH+=it.NHits();
-
-       int jtr =  fSliceTrackInfos[iSlice][itr].fNextNeighbour;
-
-       if( jtr<0 ) continue;
-       fSliceTrackInfos[iSlice][itr].fNextNeighbour = -1;
-       fSliceTrackInfos[iSlice][jtr].fNextNeighbour = -2;
-
-       AliHLTTPCCAOutTrack &jt = iS.OutTracks()[jtr];
-       for( Int_t ih=0; ih<jt.NHits(); ih++ ) tmpH[nH+ih] = iS.OutTrackHits()[jt.FirstHitRef()+ih];
-       t.SetNHits( t.NHits() + jt.NHits() );
-       nH+=jt.NHits(); 
-       if( jt.StartPoint().X() < it.StartPoint().X() ) t.SetStartPoint( jt.StartPoint() );
-       if( jt.EndPoint().X() > it.EndPoint().X() ) t.SetEndPoint( jt.EndPoint() );
-      }
-      
-      *iS.NOutTracks() = nTr;
-      *iS.NOutTrackHits() = nH;
-      for( Int_t itr=0; itr<nTr; itr++ ) iS.OutTracks()[itr] = tmpT[itr];
-      for( Int_t ih=0; ih<nH; ih++ ) iS.OutTrackHits()[ih] = tmpH[ih];
-      //std::cout<<"\nMerge tracks withing slice "<<iSlice<<" ok\n"<<std::endl;
-
-#ifdef DRAW
-  if(0){
-    AliHLTTPCCADisplay &disp = AliHLTTPCCADisplay::Instance();
-    std::cout<<" merginged tracks withing slice "<<iSlice<<":"<<std::endl;
-    disp.SetSliceView();
-    AliHLTTPCCATracker &slice = fSlices[iSlice];
-    Int_t nh=fFirstSliceHit[iSlice+1]-fFirstSliceHit[iSlice];
-    if( nh>0 ){
-      disp.SetCurrentSlice(&slice);
-      disp.DrawSlice( &slice );
-      disp.DrawSliceHits(-1,.5);
-      std::cout<<"N out tracks = "<<*slice.NOutTracks()<<std::endl;
-      for( Int_t itr=0; itr<*slice.NOutTracks(); itr++ ){
-       std::cout<<"track N "<<itr<<", nhits="<<slice.OutTracks()[itr].NHits()<<std::endl;
-       disp.DrawSliceOutTrack( itr, kRed );
-      }
-      disp.Ask();
-    }  
-  }  
-#endif //DRAW  
-
-         }
-    }
-
-#ifdef DRAW
-    if(0){
-    AliHLTTPCCADisplay &disp = AliHLTTPCCADisplay::Instance();
-    AliHLTTPCCADisplay::Instance().SetTPCView();
-    AliHLTTPCCADisplay::Instance().DrawTPC();
-    AliHLTTPCCADisplay::Instance().DrawGBHits( *this );    
-    std::cout<<"Slice tracks:"<<std::endl;
-    for( Int_t iSlice=0; iSlice<fNSlices; iSlice++ ){
-      AliHLTTPCCATracker &slice = fSlices[iSlice];
-      disp.SetCurrentSlice(&slice);    
-      for( Int_t itr=0; itr<*slice.NOutTracks(); itr++ ){
-       disp.DrawSliceOutTrack( itr, -1, 2. );
-      }
-    }
-    //AliHLTTPCCADisplay::Instance().DrawGBHits( *this );
-    disp.Ask(); 
-  }
-#endif //DRAW  
-
-      
-  //* arrays for the rotated track parameters
-
-
-    AliHLTTPCCABorderTrack 
-      *bCurr0 = new AliHLTTPCCABorderTrack[maxNSliceTracks*10], 
-      *bNext0 = new AliHLTTPCCABorderTrack[maxNSliceTracks*10],
-      *bCurr = new AliHLTTPCCABorderTrack[maxNSliceTracks*10], 
-      *bNext = new AliHLTTPCCABorderTrack[maxNSliceTracks*10];
-
-    for( Int_t iSlice=0; iSlice<fNSlices; iSlice++ ){
-    
-    Int_t jSlice = nextSlice[iSlice];
-
-#ifdef DRAW
-    std::cout<<" Merging slices "<<iSlice<<" and "<<jSlice<<std::endl;
-#endif
-    //AliHLTTPCCATracker &iS = fSlices[iSlice];
-    //AliHLTTPCCATracker &jS = fSlices[jSlice];    
-
-    Int_t nCurr0 = 0, nNext0 = 0;
-    Int_t nCurr = 0, nNext = 0;
-
-    MakeBorderTracks( iSlice, 0, bCurr, nCurr );
-    MakeBorderTracks( jSlice, 1, bNext, nNext );
-    MakeBorderTracks( iSlice, 2, bCurr0, nCurr0 );
-    MakeBorderTracks( jSlice, 3, bNext0, nNext0 );
-
-#ifdef DRAW
-    std::cout<<"\nMerge0 tracks :\n"<<std::endl;
-#endif
-    Float_t alph = -1;//iS.Param().Alpha() + ( fSlices[1].Param().Alpha() - fSlices[0].Param().Alpha() )/2;
-    Float_t alph1 = -1;//alph - CAMath::Pi()/2;
-    SplitBorderTracks( iSlice, bCurr0, nCurr0, jSlice, bNext0, nNext0, alph );   //SG!!!
-#ifdef DRAW
-    std::cout<<"\nMerge1 tracks :\n"<<std::endl;
-#endif
-    SplitBorderTracks( iSlice, bCurr, nCurr, jSlice, bNext, nNext, alph1 );    //SG!!!
-    }
-
-    if( bCurr0 ) delete[] bCurr0;
-    if( bNext0 ) delete[] bNext0;
-    if( bCurr  ) delete[] bCurr;
-    if( bNext  ) delete[] bNext;
-
-  TStopwatch timerMerge2;
-
-  Int_t nTracksTot = 0;
-  for( Int_t iSlice = 0; iSlice<fNSlices; iSlice++ ){    
-    AliHLTTPCCATracker &slice = fSlices[iSlice];
-    nTracksTot+= *slice.NOutTracks();
-  }
-  
-  if( fTrackHits ) delete[] fTrackHits;
-  fTrackHits = 0;
-  if(fTracks ) delete[] fTracks;
-  fTracks = 0;
-  fTrackHits = new Int_t [fNHits*100];//SG!!!
-  fTracks = new AliHLTTPCCAGBTrack[nTracksTot];
-  fNTracks = 0;
-
-  Int_t nTrackHits = 0;
-
-  //std::cout<<"\nStart global track creation...\n"<<std::endl;  
-  
-  //static Int_t nRejected = 0;
-
-  //Int_t maxNRows = fSlices[0].Param().NRows();
-  
-  for( Int_t iSlice = 0; iSlice<fNSlices; iSlice++ ){
-
-    AliHLTTPCCATracker &slice = fSlices[iSlice];
-    for( Int_t itr=0; itr<*slice.NOutTracks(); itr++ ){
-      if( fSliceTrackInfos[iSlice][itr].fUsed ) continue;
-      if( fSliceTrackInfos[iSlice][itr].fPrevNeighbour>=0 ) continue;
-      //std::cout<<"\n slice "<<iSlice<<", track "<<itr<<"\n"<<std::endl;
-      AliHLTTPCCAOutTrack &tCA = slice.OutTracks()[itr];
-      AliHLTTPCCAGBTrack &t = fTracks[fNTracks];
-
-      AliHLTTPCCATrackParam startPoint = tCA.StartPoint(), endPoint = tCA.EndPoint();
-      Float_t startAlpha = slice.Param().Alpha(), endAlpha = slice.Param().Alpha();
-      t.SetNHits( 0 );
-
-      t.SetFirstHitRef( nTrackHits );
-
-      Int_t hits[2000];
-      Int_t firstHit = 1000;
-      Int_t nHits = 0;
-      Int_t jSlice = iSlice;
-      Int_t jtr = itr;
-      {
-       fSliceTrackInfos[jSlice][jtr].fUsed = 1;
-       for( Int_t jhit=0; jhit<tCA.NHits(); jhit++){
-         Int_t id = fFirstSliceHit[iSlice] + slice.OutTrackHits()[tCA.FirstHitRef()+jhit];       
-         hits[firstHit+jhit] = id;
-       }
-       nHits=tCA.NHits();
-       jtr = fSliceTrackInfos[iSlice][itr].fNextNeighbour;
-       jSlice = nextSlice[iSlice];                     
-      } 
-      while( jtr >=0 ){
-       if( fSliceTrackInfos[jSlice][jtr].fUsed ) break;
-       fSliceTrackInfos[jSlice][jtr].fUsed = 1;
-       AliHLTTPCCATracker &jslice = fSlices[jSlice];
-       AliHLTTPCCAOutTrack &jTr = jslice.OutTracks()[jtr];
-       Bool_t dir = 0;
-       Int_t startHit = firstHit+ nHits;
-       Float_t d00 = startPoint.GetDistXZ2(jTr.StartPoint() );
-       Float_t d01 = startPoint.GetDistXZ2(jTr.EndPoint() );
-       Float_t d10 = endPoint.GetDistXZ2(jTr.StartPoint() );
-       Float_t d11 = endPoint.GetDistXZ2(jTr.EndPoint() );
-       if( d00<=d01 && d00<=d10 && d00<=d11 ){
-         startPoint = jTr.EndPoint();
-         startAlpha = jslice.Param().Alpha();
-         dir = 1;
-         firstHit -= jTr.NHits();
-         startHit = firstHit;
-       }else if( d01<=d10 && d01<=d11 ){
-         startPoint = jTr.StartPoint();
-         startAlpha = jslice.Param().Alpha();
-         dir = 0;
-         firstHit -= jTr.NHits();
-         startHit = firstHit;
-       }else if( d10<=d11 ){
-         endPoint = jTr.EndPoint();
-         endAlpha = jslice.Param().Alpha();
-         dir = 0;
-       }else{
-         endPoint = jTr.StartPoint();
-         endAlpha = jslice.Param().Alpha();
-         dir = 1;
-       }
-       
-       for( Int_t jhit=0; jhit<jTr.NHits(); jhit++){
-         Int_t id = fFirstSliceHit[jSlice] + jslice.OutTrackHits()[jTr.FirstHitRef()+jhit];      
-         hits[startHit+(dir ?(jTr.NHits()-1-jhit) :jhit)] = id;
-       }
-       nHits+=jTr.NHits();
-       jtr = fSliceTrackInfos[jSlice][jtr].fNextNeighbour;
-       jSlice = nextSlice[jSlice];                     
-      }
-
-      if( endPoint.X() < startPoint.X() ){ // swap
-       for( Int_t i=0; i<nHits; i++ ) hits[i] = hits[firstHit+nHits-1-i];
-       firstHit = 0;
-      }
-
-      if( nHits < 30 ) continue;     //SG!!!
-
-      // refit 
-      Float_t dEdX=0;
-      if( !FitTrack( endPoint, startPoint, startAlpha, hits+firstHit, nHits, dEdX, 0 ) ) continue;
-      endAlpha = startAlpha;
-      if( !FitTrack( startPoint, endPoint, startAlpha, hits+firstHit, nHits, dEdX, 1 ) ) continue;
-
-      if( nHits < 30 ) continue;     //SG!!!
-    
-      
-      t.SetNHits( nHits );
-      t.SetParam( startPoint );
-      t.SetAlpha( startAlpha );
-      t.SetDeDx( dEdX );
-
-      for( Int_t i = 0; i<nHits; i++ ){
-       fTrackHits[nTrackHits+i] = hits[firstHit+i];
-      }                
-
-      AliHLTTPCCATrackParam p = t.Param();
-      AliHLTTPCCATrackParam::AliHLTTPCCATrackFitParam fitPar;
-      p.CalculateFitParameters( fitPar, fSlices[0].Param().Bz() );
-
-      Double_t dAlpha = 0;
-      {
-       Double_t xTPC=83.65;
-       Double_t ddAlpha = 0.00609235;
-       
-       if( p.TransportToXWithMaterial( xTPC, fitPar ) ){
-         Double_t y=p.GetY();
-         Double_t ymax=xTPC*CAMath::Tan(dAlpha/2.); 
-         if (y > ymax) {
-           if( p.Rotate( ddAlpha ) ){ dAlpha=ddAlpha;  p.TransportToXWithMaterial( xTPC, fitPar ); }
-         } else if (y <-ymax) {
-           if( p.Rotate( -ddAlpha ) ){  dAlpha=-ddAlpha; p.TransportToXWithMaterial( xTPC, fitPar );}
-         }         
-       }
-      }
-      
-      {
-       Bool_t ok=1;
-       
-       const Float_t *c = p.Cov();
-       for( Int_t i=0; i<15; i++ ) ok = ok && finite(c[i]);
-       for( Int_t i=0; i<5; i++ ) ok = ok && finite(p.Par()[i]);
-       ok = ok && (p.GetX()>50);
-       
-       if( c[0]<=0 || c[2]<=0 || c[5]<=0 || c[9]<=0 || c[14]<=0 ) ok = 0;
-       if( c[0]>5. || c[2]>5. || c[5]>2. || c[9]>2 || c[14]>2 ) ok = 0;
-       if(!ok) continue;       
-      }
-      t.SetParam( p );
-      t.SetAlpha( t.Alpha() + dAlpha );
-      nTrackHits+= t.NHits();
-      fNTracks++;   
-    }
-  }
-  
-  //std::cout<<"\n\nRejected: "<<nRejected<<"\n"<<std::endl;
-  timerMerge2.Stop();
-  fStatTime[11]+=timerMerge2.CpuTime();
-
-  TStopwatch timerMerge3;
-
-  //* selection  
-  //std::cout<<"Selection..."<<std::endl;
-  if(0){
-    AliHLTTPCCAGBTrack *vtracks = new AliHLTTPCCAGBTrack [fNTracks];
-    Int_t *vhits = new Int_t [fNHits];
-    AliHLTTPCCAGBTrack **vptracks = new AliHLTTPCCAGBTrack* [fNTracks];
-
-    for( Int_t itr=0; itr<fNTracks; itr++ ){
-      vptracks[itr] = &(fTracks[itr]);
-    }
-    Int_t nTracks = 0;
-    Int_t nHits = 0;
-    std::sort(vptracks, vptracks+fNTracks, AliHLTTPCCAGBTrack::ComparePNClusters );
-    for( Int_t itr=0; itr<fNTracks; itr++ ){
-      AliHLTTPCCAGBTrack &t = *(vptracks[itr]);
-      AliHLTTPCCAGBTrack &to = vtracks[nTracks];
-      to=*(vptracks[itr]);
-      to.SetFirstHitRef( nHits );
-      to.SetNHits( 0 );
-      for( Int_t ih=0; ih<t.NHits(); ih++ ){
-       Int_t jh = fTrackHits[t.FirstHitRef()+ih];
-       AliHLTTPCCAGBHit &h = fHits[jh];
-       if( h.IsUsed() ) continue;
-       vhits[to.FirstHitRef() + to.NHits()] = jh;
-       to.SetNHits( to.NHits()+1);
-       h.SetIsUsed( 1 );
-      }
-      //if( to.NHits()<10 ) continue;//SG!!!
-      nHits+=to.NHits();
-      nTracks++;
-      //std::cout<<to.Param().GetErr2Y()<<" "<<to.Param().GetErr2Z()<<std::endl;
-    }
-    fNTracks = nTracks;
-    if( fTrackHits ) delete[] fTrackHits;
-    if( fTracks ) delete[] fTracks;
-    fTrackHits = vhits;
-    fTracks = vtracks;
-    if( vptracks ) delete[] vptracks;
-  }
-  timerMerge3.Stop();
-  fStatTime[12]+=timerMerge3.CpuTime();
-
-#ifdef DRAW
-  std::cout<<"Global tracks: "<<std::endl;
-  AliHLTTPCCADisplay::Instance().ClearView();
-  AliHLTTPCCADisplay::Instance().SetTPCView();
-  AliHLTTPCCADisplay::Instance().DrawTPC();
-  AliHLTTPCCADisplay::Instance().DrawGBHits( *this );
-  for( Int_t itr=0; itr<fNTracks; itr++ ){
-    std::cout<<itr<<" nhits= "<<fTracks[itr].NHits()<<std::endl;
-    AliHLTTPCCADisplay::Instance().DrawGBTrack( itr, kBlue, 2. );    
-    //AliHLTTPCCADisplay::Instance().Ask();
-  }
-  AliHLTTPCCADisplay::Instance().Ask();
-#endif
-}
-
-
-
-
-
-
-
-void AliHLTTPCCAGBTracker::GetErrors2( Int_t iSlice, Int_t iRow, AliHLTTPCCATrackParam &t, Float_t &Err2Y, Float_t &Err2Z )
-{
-  //
-  // Use calibrated cluster error from OCDB
-  //
-    
-  Float_t z = CAMath::Abs((250.-0.275)-CAMath::Abs(t.GetZ()));
-  Int_t    type = (iRow<63) ? 0: (iRow>126) ? 1:2;
-  Float_t cosPhiInv = CAMath::Abs(t.GetCosPhi())>1.e-2 ?1./t.GetCosPhi() :0;
-  Float_t angleY = t.GetSinPhi()*cosPhiInv ;
-  Float_t angleZ = t.GetDzDs()*cosPhiInv ;
-
-  AliHLTTPCCATracker &slice = fSlices[iSlice];
-
-  Err2Y = slice.Param().GetClusterError2(0,type, z,angleY);  
-  Err2Z = slice.Param().GetClusterError2(1,type, z,angleZ);
-}
-
-
-void AliHLTTPCCAGBTracker::GetErrors2( AliHLTTPCCAGBHit &h, AliHLTTPCCATrackParam &t, Float_t &Err2Y, Float_t &Err2Z )
-{
-  //
-  // Use calibrated cluster error from OCDB
-  //
-
-  GetErrors2( h.ISlice(), h.IRow(), t, Err2Y, Err2Z );
-}
 
 void AliHLTTPCCAGBTracker::WriteSettings( std::ostream &out ) const
 {
@@ -1659,7 +585,7 @@ void AliHLTTPCCAGBTracker::ReadTracks( std::istream &in )
     in>>f;
     p.SetX( f );
     in>>f;
-    p.SetCosPhi( f );
+    p.SetSignCosPhi( f );
     in>>f;
     p.SetChi2( f );
     in>>i;
index 4f1e0a7f6d4ab01226fe43bfe832f830c18c1d8c..1f648815503c234ee2b40eb9b007e53b837416b9 100644 (file)
@@ -22,6 +22,7 @@ class AliHLTTPCCAGBHit;
 class TParticle;
 class TProfile;
 class AliHLTTPCCATrackParam;
+class  AliHLTTPCCAMerger;
 
 /**
  * @class AliHLTTPCCAGBTracker
@@ -58,29 +59,7 @@ public:
 
   void FindTracks();
 
-
-  void Refit();
-
-  struct AliHLTTPCCABorderTrack{
-    AliHLTTPCCABorderTrack(): fParam(), fITrack(0), fIRow(0), fNHits(0), fX(0), fOK(0){};
-    AliHLTTPCCATrackParam fParam; // track parameters at the border
-    Int_t fITrack;               // track index
-    Int_t fIRow;                 // row number of the closest cluster
-    Int_t fNHits;                // n hits
-    Float_t fX;                  // X coordinate of the closest cluster
-    Bool_t fOK;                  // is the trak rotated and extrapolated correctly
-  };
-  
-  void MakeBorderTracks( Int_t iSlice, Int_t iBorder, AliHLTTPCCABorderTrack B[], Int_t &nB);
-  void SplitBorderTracks( Int_t iSlice1, AliHLTTPCCABorderTrack B1[], Int_t N1,
-                         Int_t iSlice2, AliHLTTPCCABorderTrack B2[], Int_t N2, 
-                         Float_t Alpha =-1 );
-
-  static Float_t GetChi2( Float_t x1, Float_t y1, Float_t a00, Float_t a10, Float_t a11, 
-                         Float_t x2, Float_t y2, Float_t b00, Float_t b10, Float_t b11  );
-
-  void Merging();
-  void Merging1();
+  void Merge();
 
   AliHLTTPCCATracker *Slices() const { return fSlices; }
   AliHLTTPCCAGBHit *Hits() const { return fHits; }
@@ -94,8 +73,10 @@ public:
   Int_t NTracks() const { return fNTracks; }
   AliHLTTPCCAGBTrack *Tracks() const { return fTracks; }
   Int_t *TrackHits() const { return fTrackHits; }
-  void GetErrors2( AliHLTTPCCAGBHit &h, AliHLTTPCCATrackParam &t, Float_t &Err2Y, Float_t &Err2Z );
-  void GetErrors2( Int_t iSlice, Int_t iRow, AliHLTTPCCATrackParam &t, Float_t &Err2Y, Float_t &Err2Z );
+
+  Bool_t FitTrack( AliHLTTPCCATrackParam &T, AliHLTTPCCATrackParam t0, 
+                  Float_t &Alpha, Int_t hits[], Int_t &NTrackHits, 
+                  Bool_t dir );
 
   void WriteSettings( std::ostream &out ) const;
   void ReadSettings( std::istream &in );
@@ -108,9 +89,6 @@ public:
   void SetSliceTrackerTime( Double_t v ){ fSliceTrackerTime = v; }
   const Int_t *FirstSliceHit() const { return fFirstSliceHit; }
 
-  Bool_t FitTrack( AliHLTTPCCATrackParam &T, AliHLTTPCCATrackParam t0, 
-                  Float_t &Alpha, Int_t hits[], Int_t &NHits, 
-                  Float_t &DeDx, Bool_t dir=0 );
 
 protected:
 
@@ -122,14 +100,8 @@ protected:
   Int_t *fTrackHits;           //* track->hits reference array
   AliHLTTPCCAGBTrack *fTracks; //* array of tracks
   Int_t fNTracks;              //* N tracks
+  AliHLTTPCCAMerger *fMerger;  //* global merger
 
-  struct AliHLTTPCCAGBSliceTrackInfo{
-    Int_t fPrevNeighbour; //* neighbour in the previous slide
-    Int_t fNextNeighbour; //* neighbour in the next slide
-    Bool_t fUsed;         //* is the slice track used by global tracks
-  };
-
-  AliHLTTPCCAGBSliceTrackInfo **fSliceTrackInfos; //* additional information for slice tracks
   Double_t fTime; //* total time
   Double_t fStatTime[20]; //* timers 
   Int_t fStatNEvents;    //* n events proceed
index 88a502fe9083d05ee77afb0c68ff277e3eaab3a8..1bf13f28e8b5737598c4217894a1c5f968aa9a83 100644 (file)
@@ -242,8 +242,8 @@ int AliHLTTPCCAGlobalMergerComponent::DoEvent( const AliHLTComponentEventData &e
       // first convert to AliExternalTrackParam ( Kappa to Pt )
 
       AliExternalTrackParam tp, tpEnd;
-      AliHLTTPCCATrackConvertor::GetExtParam( track.InnerParam(), tp, 0, fSolenoidBz );      
-      AliHLTTPCCATrackConvertor::GetExtParam( track.OuterParam(), tpEnd, 0, fSolenoidBz );      
+      AliHLTTPCCATrackConvertor::GetExtParam( track.InnerParam(), tp, 0 );      
+      AliHLTTPCCATrackConvertor::GetExtParam( track.OuterParam(), tpEnd, 0 );      
 
       // set parameters, with rotation to global coordinates
       
index eed8890b4d8d4d1c126203e9c87a889224d32c91..869713e197716facaa031d01c87a3219063bdaaa 100644 (file)
@@ -35,7 +35,7 @@
 #include "AliHLTTPCCAMergerOutput.h"
 #include "AliHLTTPCCADataCompressor.h"
 #include "AliHLTTPCCAParam.h"
-
+#include "AliHLTTPCCATrackLinearisation.h"
 
 
 class AliHLTTPCCAMerger::AliHLTTPCCAClusterInfo
@@ -47,6 +47,7 @@ public:
   UInt_t  IRow()      const { return fIRow;      }
   UInt_t  IClu()      const { return fIClu;      }
   UChar_t PackedAmp() const { return fPackedAmp; }
+  Float_t X()         const { return fX;         }
   Float_t Y()         const { return fY;         }
   Float_t Z()         const { return fZ;         }
   Float_t Err2Y()     const { return fErr2Y;     }
@@ -56,6 +57,7 @@ public:
   void SetIRow      ( UInt_t v  ) { fIRow      = v; }
   void SetIClu      ( UInt_t v  ) { fIClu      = v; }
   void SetPackedAmp ( UChar_t v ) { fPackedAmp = v; }
+  void SetX         ( Float_t v ) { fX         = v; } 
   void SetY         ( Float_t v ) { fY         = v; } 
   void SetZ         ( Float_t v ) { fZ         = v; } 
   void SetErr2Y     ( Float_t v ) { fErr2Y     = v; } 
@@ -67,6 +69,7 @@ private:
   UInt_t fIRow;              // row number
   UInt_t fIClu;              // cluster number
   UChar_t fPackedAmp; // packed cluster amplitude
+  Float_t fX;                // x position (slice coord.system)
   Float_t fY;                // y position (slice coord.system)
   Float_t fZ;                // z position (slice coord.system)
   Float_t fErr2Y;            // Squared measurement error of y position
@@ -255,7 +258,7 @@ void AliHLTTPCCAMerger::UnpackSlices()
     const AliHLTTPCCASliceOutput &slice = *(fkSlices[iSlice]);
 
     for( Int_t itr=0; itr<slice.NTracks(); itr++ ){
-  
+
       const AliHLTTPCCASliceTrack &sTrack = slice.Track( itr );
       AliHLTTPCCATrackParam t0 = sTrack.Param();
       Int_t nCluNew = 0;
@@ -272,13 +275,14 @@ void AliHLTTPCCAMerger::UnpackSlices()
        clu.SetIClu( AliHLTTPCCADataCompressor::IDrc2IClu( slice.ClusterIDrc( ic ) ) ); 
        clu.SetPackedAmp( slice.ClusterPackedAmp( ic ) );
        float2 yz = slice.ClusterUnpackedYZ( ic );
+       clu.SetX( slice.ClusterUnpackedX( ic ) );
        clu.SetY( yz.x );
        clu.SetZ( yz.y );
 
-       if( !t0.TransportToX( fSliceParam.RowX( clu.IRow() ), .999 ) ) continue;
-       
+       if( !t0.TransportToX( fSliceParam.RowX( clu.IRow() ), fSliceParam.GetBz(t0), .999 ) ) continue;
+
        Float_t err2Y, err2Z;
-       fSliceParam.GetClusterErrors2( clu.IRow(), clu.Z(), t0.SinPhi(), t0.CosPhi(), t0.DzDs(), err2Y, err2Z );
+       fSliceParam.GetClusterErrors2( clu.IRow(), clu.Z(), t0.SinPhi(), t0.GetCosPhi(), t0.DzDs(), err2Y, err2Z );
        
        clu.SetErr2Y( err2Y );
        clu.SetErr2Z( err2Z );
@@ -297,13 +301,13 @@ void AliHLTTPCCAMerger::UnpackSlices()
       AliHLTTPCCATrackParam endPoint = startPoint;
       Float_t startAlpha = fSliceParam.Alpha( iSlice );
       Float_t endAlpha = startAlpha;
-      
       if( !FitTrack( endPoint, endAlpha, startPoint, startAlpha, hits, nHits, 0 ) ) continue;
-      
+
       startPoint = endPoint;
       startAlpha = endAlpha;
       if( !FitTrack( startPoint, startAlpha, endPoint, endAlpha, hits, nHits, 1 ) ) continue;
-      
+
       if( nHits<.8*sTrack.NClusters() ) continue;
 
       // store the track
@@ -326,6 +330,7 @@ void AliHLTTPCCAMerger::UnpackSlices()
       fSliceNTrackInfos[ iSlice ]++;
       nClustersCurrent+=nHits;      
     }
+    //std::cout<<"Unpack slice "<<iSlice<<": ntracks "<<slice.NTracks()<<"/"<<fSliceNTrackInfos[iSlice]<<std::endl;
   }
 }
 
@@ -339,10 +344,11 @@ Bool_t AliHLTTPCCAMerger::FitTrack( AliHLTTPCCATrackParam &T, Float_t &Alpha,
 
   AliHLTTPCCATrackParam::AliHLTTPCCATrackFitParam fitPar;
   AliHLTTPCCATrackParam t = t0;
-  
+  AliHLTTPCCATrackLinearisation l(t0);
+
   Bool_t first = 1;
  
-  t0.CalculateFitParameters( fitPar, fSliceParam.Bz() );
+  t.CalculateFitParameters( fitPar );
 
   Int_t hitsNew[1000];
   Int_t nHitsNew = 0;
@@ -357,13 +363,14 @@ Bool_t AliHLTTPCCAMerger::FitTrack( AliHLTTPCCATrackParam &T, Float_t &Alpha,
     Float_t sliceAlpha =  fSliceParam.Alpha( iSlice );
 
     if( CAMath::Abs( sliceAlpha - Alpha0)>1.e-4 ){
-      if( ! t.RotateNoCos(  sliceAlpha - Alpha0, t0, .999 ) ) continue;
+      if( ! t.Rotate(  sliceAlpha - Alpha0, l, .999 ) ) continue;
       Alpha0 = sliceAlpha;
     }
 
-    Float_t x = fSliceParam.RowX( h.IRow() );
+    //Float_t x = fSliceParam.RowX( h.IRow() );
+    Float_t x = h.X();
     
-    if( !t.TransportToXWithMaterial( x, t0, fitPar ) ) continue;
+    if( !t.TransportToXWithMaterial( x, l, fitPar, fSliceParam.GetBz(t) ) ) continue;
     
     if( first ){
       t.SetCov( 0, 10 );
@@ -380,20 +387,20 @@ Bool_t AliHLTTPCCAMerger::FitTrack( AliHLTTPCCATrackParam &T, Float_t &Alpha,
       t.SetCov(11,  0 );
       t.SetCov(12,  0 );
       t.SetCov(13,  0 );
-      t.SetCov(14,  1 );
+      t.SetCov(14,  10 );
       t.SetChi2( 0 );
       t.SetNDF( -5 );
-      t0.CalculateFitParameters( fitPar, fSliceParam.Bz() );
+      t.CalculateFitParameters( fitPar );
     }
   
-    if( !t.Filter2NoCos( h.Y(), h.Z(), h.Err2Y(), h.Err2Z() ) ) continue;                  
-    
+    if( !t.Filter( h.Y(), h.Z(), h.Err2Y(), h.Err2Z() ) ) continue;                
+
     first = 0;
 
     hitsNew[nHitsNew++] = hits[jhit];
   }
   
-  if( CAMath::Abs(t.Kappa())<1.e-8 ) t.SetKappa( 1.e-8 );
+  if( CAMath::Abs(t.QPt())<1.e-8 ) t.SetQPt( 1.e-8 );
   
   Bool_t ok=1;
   
@@ -403,11 +410,11 @@ Bool_t AliHLTTPCCAMerger::FitTrack( AliHLTTPCCATrackParam &T, Float_t &Alpha,
   ok = ok && (t.GetX()>50);
   
   if( c[0]<=0 || c[2]<=0 || c[5]<=0 || c[9]<=0 || c[14]<=0 ) ok = 0;
-  if( c[0]>5. || c[2]>5. || c[5]>2. || c[9]>2 || c[14]>2 ) ok = 0;
+  if( c[0]>5. || c[2]>5. || c[5]>2. || c[9]>2 || c[14]>2. ) ok = 0;
   
   if( CAMath::Abs(t.SinPhi())>.99 ) ok = 0;
-  else if( t0.CosPhi()>=0 ) t.SetCosPhi( CAMath::Sqrt(1.-t.SinPhi()*t.SinPhi()) );
-  else t.SetCosPhi( -CAMath::Sqrt(1.-t.SinPhi()*t.SinPhi()) );
+  else if( l.CosPhi()>=0 ) t.SetSignCosPhi( 1 );
+  else t.SetSignCosPhi( -1 );
 
   if( ok ){
     T = t;
@@ -482,7 +489,7 @@ void AliHLTTPCCAMerger::MakeBorderTracks( Int_t iSlice, Int_t iBorder, AliHLTTPC
     Bool_t ok1 = t1.Rotate( dAlpha, maxSin );
     
     Bool_t do0 = ok0;
-    Bool_t do1 = ok1 && ( !ok0 || t1.CosPhi()*t0.CosPhi()<0 );
+    Bool_t do1 = ok1 && ( !ok0 || t1.SignCosPhi()*t0.SignCosPhi()<0 );
     
     if( ok0 && !do1 && ok1 && (t1.X() < t0.X()) ){
       do0 = 0;
@@ -492,7 +499,7 @@ void AliHLTTPCCAMerger::MakeBorderTracks( Int_t iSlice, Int_t iBorder, AliHLTTPC
     if( do0 ){
       AliHLTTPCCABorderTrack &b = B[nB];
       b.SetX( t0.GetX() );
-      if( t0.TransportToX( x0, maxSin ) ){
+      if( t0.TransportToX( x0, fSliceParam.GetBz(t0), maxSin ) ){
        b.SetOK( 1 );
        b.SetTrackID( itr );
        b.SetNClusters( track.NClusters() );
@@ -504,7 +511,7 @@ void AliHLTTPCCAMerger::MakeBorderTracks( Int_t iSlice, Int_t iBorder, AliHLTTPC
     if( do1 ){
       AliHLTTPCCABorderTrack &b = B[nB];
       b.SetX( t1.GetX() );
-      if( t1.TransportToX( x0, maxSin ) ){
+      if( t1.TransportToX( x0, fSliceParam.GetBz(t1), maxSin ) ){
        b.SetOK( 1 );
        b.SetTrackID( itr );
        b.SetNClusters( track.NClusters() );
@@ -558,9 +565,9 @@ void AliHLTTPCCAMerger::SplitBorderTracks( Int_t iSlice1, AliHLTTPCCABorderTrack
 
       const AliHLTTPCCATrackParam &t2 = b2.Param();
 
-      Float_t c= t2.CosPhi()*t1.CosPhi()>=0 ?1 :-1;
-      Float_t dk = t2.Kappa() - c*t1.Kappa(); 
-      Float_t s2k = t2.Err2Kappa() + t1.Err2Kappa();
+      Float_t c= t2.SignCosPhi()*t1.SignCosPhi()>=0 ?1 :-1;
+      Float_t dk = t2.QPt() - c*t1.QPt(); 
+      Float_t s2k = t2.Err2QPt() + t1.Err2QPt();
       
       if( dk*dk>factor2k*s2k ) continue;     
 
@@ -827,20 +834,20 @@ void AliHLTTPCCAMerger::Merging()
       if( nHits < 30 ) continue;     //SG!!!    
       
       AliHLTTPCCATrackParam &p = startPoint;
-      AliHLTTPCCATrackParam::AliHLTTPCCATrackFitParam fitPar;
-      p.CalculateFitParameters( fitPar, fSliceParam.Bz() );
       
       {
        Double_t xTPC=83.65; //SG!!!
        Double_t dAlpha = 0.00609235;
+       AliHLTTPCCATrackParam::AliHLTTPCCATrackFitParam fitPar;
+       p.CalculateFitParameters( fitPar );
        
-       if( p.TransportToXWithMaterial( xTPC, fitPar ) ){
+       if( p.TransportToXWithMaterial( xTPC, fitPar, fSliceParam.GetBz( p ) ) ){
          Double_t y=p.GetY();
          Double_t ymax=xTPC*CAMath::Tan(dAlpha/2.); 
          if (y > ymax) {
-           if( p.Rotate( dAlpha ) ){ startAlpha+=dAlpha;  p.TransportToXWithMaterial( xTPC, fitPar ); }
+           if( p.Rotate( dAlpha ) ){ startAlpha+=dAlpha;  p.TransportToXWithMaterial( xTPC, fitPar, fSliceParam.GetBz(p) ); }
          } else if (y <-ymax) {
-           if( p.Rotate( -dAlpha ) ){  startAlpha-=dAlpha; p.TransportToXWithMaterial( xTPC, fitPar );}
+           if( p.Rotate( -dAlpha ) ){  startAlpha-=dAlpha; p.TransportToXWithMaterial( xTPC, fitPar, fSliceParam.GetBz(p) );}
          }
        }
       }
index ca1c379708ef56e61f6fe74cb6bd91d83083a1b0..eebb864ead4e0687381af187b1a0dc1daf5896a2 100644 (file)
@@ -42,6 +42,9 @@ public:
 
   const AliHLTTPCCAMergerOutput * Output() const { return fOutput; }
   
+  Bool_t FitTrack( AliHLTTPCCATrackParam &T, Float_t &Alpha, 
+                  AliHLTTPCCATrackParam t0, Float_t Alpha0, Int_t hits[], Int_t &NHits,  Bool_t dir=0 );
+
  private:
 
   AliHLTTPCCAMerger(const AliHLTTPCCAMerger&);
@@ -61,8 +64,7 @@ public:
   void UnpackSlices();
   void Merging();
    
-  Bool_t FitTrack( AliHLTTPCCATrackParam &T, Float_t &Alpha, 
-                  AliHLTTPCCATrackParam t0, Float_t Alpha0, Int_t hits[], Int_t &NHits,  Bool_t dir=0 );
+
   
   static const Int_t fgkNSlices = 36;       //* N slices 
   AliHLTTPCCAParam fSliceParam;           //* slice parameters (geometry, calibr, etc.)
index cf90b1927f47b3adf5ab664c1a19b4a4ec7fd6ef..5a25d9e81bdb20324d0990fa10bc17d301ac85cb 100644 (file)
@@ -75,6 +75,15 @@ GPUd() AliHLTTPCCAParam::AliHLTTPCCAParam()
   fParamS0Par[1][2][5] = 0.000425504;
   fParamS0Par[1][2][6] = 20.9294;
 
+  const Double_t kCLight = 0.000299792458;
+  
+  fPolinomialFieldBz[0] = kCLight* 4.99643;
+  fPolinomialFieldBz[1] = kCLight* -2.27193e-06;
+  fPolinomialFieldBz[2] = kCLight* 0.000116475; 
+  fPolinomialFieldBz[3] = kCLight* -1.49956e-06; 
+  fPolinomialFieldBz[4] = kCLight* -1.01721e-07; 
+  fPolinomialFieldBz[5] = kCLight* 4.85701e-07; 
+
   Update();
 }
 #endif
index f6254c3fdf093b8bc25b8c662aca05dca99f6fea..e178430a6d63e1ea2a334216f73b9dad457b87d4 100644 (file)
@@ -11,6 +11,8 @@
 #define ALIHLTTPCCAPARAM_H
 
 #include "AliHLTTPCCADef.h"
+#include "AliHLTTPCCAMath.h"
+#include "AliHLTTPCCATrackParam.h"
 
 #include <iostream>
 
@@ -109,6 +111,10 @@ class AliHLTTPCCAParam
     fParamS0Par[i][j][k] = val;
   }
 
+  GPUd() Float_t GetBz() const { return fBz;}
+  GPUd() Float_t GetBz( float x, float y, float z ) const;
+  GPUd()  Float_t GetBz( const AliHLTTPCCATrackParam &t ) const;
+
   protected:
 
   Int_t fISlice; // slice number
@@ -132,8 +138,23 @@ class AliHLTTPCCAParam
 
   Float_t fRowX[200];// X-coordinate of rows
   Float_t fParamS0Par[2][3][7];    // cluster error parameterization coeficients
+  Float_t fPolinomialFieldBz[6];   // field coefficients
 
 };
 
 
+
+GPUd() inline Float_t AliHLTTPCCAParam::GetBz( float x, float y, float z ) const
+{
+  float r2 = x*x+y*y;
+  float r  = CAMath::Sqrt( r2 );
+  const float *c = fPolinomialFieldBz;
+  return ( c[0] + c[1]*z  + c[2]*r  + c[3]*z*z + c[4]*z*r + c[5]*r2 );
+}
+
+GPUd() inline Float_t AliHLTTPCCAParam::GetBz( const AliHLTTPCCATrackParam &t ) const
+{
+  return GetBz( t.X(), t.Y(), t.Z() );
+}
+
 #endif
index f06d70c15aa2f095f458ded584f40af7f9a1d6d6..cc4112c789599c1d6800ccfe353294e72fa3c98b 100644 (file)
@@ -1490,7 +1490,7 @@ void AliHLTTPCCAPerformance::Performance( fstream *StatFile )
          const Double_t kCLight = 0.000299792458;  
          Double_t k2QPt = 100;
          if( TMath::Abs(bz)>1.e-4 ) k2QPt= 1./(bz*kCLight);
-         Double_t qPt = p.GetKappa()*k2QPt;
+         Double_t qPt = p.GetKappa(bz)*k2QPt;
          Double_t pt = 100;
          if( TMath::Abs(qPt) >1.e-4 ) pt = 1./TMath::Abs(qPt);
          
@@ -1505,11 +1505,11 @@ void AliHLTTPCCAPerformance::Performance( fstream *StatFile )
 
          if( p.GetErr2SinPhi()>0 ) fhPullSinPhi->Fill( (p.GetSinPhi() - mcSinPhi)/TMath::Sqrt(p.GetErr2SinPhi()) ); 
          if( p.GetErr2DzDs()>0 ) fhPullDzDs->Fill( (p.DzDs() - mcDzDs)/TMath::Sqrt(p.GetErr2DzDs()) ); 
-         if( p.GetErr2Kappa()>0 ) fhPullQPt->Fill( (qPt - mcQPt)/TMath::Sqrt(p.GetErr2Kappa()*k2QPt*k2QPt) ); 
-         fhPullYS->Fill( TMath::Sqrt(fTracker->GetChi2( p.GetY(), p.GetSinPhi(), p.GetCov()[0], p.GetCov()[3], p.GetCov()[5], 
-                                            mcY, mcSinPhi, 0,0,0 )));
-         fhPullZT->Fill( TMath::Sqrt(fTracker->GetChi2( p.GetZ(), p.GetDzDs(), p.GetCov()[2], p.GetCov()[7], p.GetCov()[9], 
-                         mcZ, mcDzDs, 0,0,0 ) ));
+         //if( p.GetErr2Kappa()>0 ) fhPullQPt->Fill( (qPt - mcQPt)/TMath::Sqrt(p.GetErr2Kappa()*k2QPt*k2QPt) ); 
+         //fhPullYS->Fill( TMath::Sqrt(fTracker->GetChi2( p.GetY(), p.GetSinPhi(), p.GetCov()[0], p.GetCov()[3], p.GetCov()[5], 
+         //                                 mcY, mcSinPhi, 0,0,0 )));
+  //fhPullZT->Fill( TMath::Sqrt(fTracker->GetChi2( p.GetZ(), p.GetDzDs(), p.GetCov()[2], p.GetCov()[7], p.GetCov()[9], 
+         //      mcZ, mcDzDs, 0,0,0 ) ));
 
          break;
        }
@@ -1656,21 +1656,21 @@ void AliHLTTPCCAPerformance::Performance( fstream *StatFile )
       Double_t dz = p2.Sz() - p1.Sz();
       if( TMath::Abs(dx)>1.e-8 && TMath::Abs(p1.Sx()-hit.X())<2. && TMath::Abs(p2.Sx()-hit.X())<2.  ){
         Double_t sx = hit.X();
-        Double_t sy = p1.Sy() + dy/dx*(sx-p1.Sx());
+        //Double_t sy = p1.Sy() + dy/dx*(sx-p1.Sx());
         Double_t sz = p1.Sz() + dz/dx*(sx-p1.Sx());
        
-       Float_t errY, errZ;
+       //Float_t errY, errZ;
        {
          AliHLTTPCCATrackParam t;
          t.SetZ( sz );
          t.SetSinPhi( dy/TMath::Sqrt(dx*dx+dy*dy) );
-         t.SetCosPhi( dx/TMath::Sqrt(dx*dx+dy*dy) );
+         t.SetSignCosPhi( dx );
          t.SetDzDs( dz/TMath::Sqrt(dx*dx+dy*dy) );
-         fTracker->GetErrors2(hit,t,errY, errZ );
-         errY = TMath::Sqrt(errY);
-         errZ = TMath::Sqrt(errZ);
+         //fTracker->GetErrors2(hit,t,errY, errZ );
+         //errY = TMath::Sqrt(errY);
+         //errZ = TMath::Sqrt(errZ);
        } 
-             
+       /*             
        fhHitResY->Fill((hit.Y()-sy));
        fhHitResZ->Fill((hit.Z()-sz));
        fhHitPullY->Fill((hit.Y()-sy)/errY);
@@ -1681,6 +1681,7 @@ void AliHLTTPCCAPerformance::Performance( fstream *StatFile )
          fhHitPullY1->Fill((hit.Y()-sy)/errY);
          fhHitPullZ1->Fill((hit.Z()-sz)/errZ);
        }
+       */
       }
     }   
   }
index 0e356b6425140794c16bb28d7fef21c9a071b006..05a2a6267d37f66db42d18059079dd88437483fc 100644 (file)
@@ -37,6 +37,7 @@ class AliHLTTPCCASliceOutput
   GPUhd() UShort_t ClusterPackedYZ ( Int_t i )  const { return fClusterPackedYZ[i]; }
   GPUhd() UChar_t  ClusterPackedAmp( Int_t i )  const { return fClusterPackedAmp[i]; }
   GPUhd() float2   ClusterUnpackedYZ ( Int_t i )  const { return fClusterUnpackedYZ[i]; }
+  GPUhd() float    ClusterUnpackedX  ( Int_t i )  const { return fClusterUnpackedX[i]; }
 
   GPUhd() static Int_t EstimateSize( Int_t nOfTracks, Int_t nOfTrackClusters );
   GPUhd() void SetPointers();
@@ -49,11 +50,12 @@ class AliHLTTPCCASliceOutput
   GPUhd() void SetClusterPackedYZ( Int_t i, UShort_t v ) {  fClusterPackedYZ[i] = v; }
   GPUhd() void SetClusterPackedAmp( Int_t i, UChar_t v ) {  fClusterPackedAmp[i] = v; }
   GPUhd() void SetClusterUnpackedYZ( Int_t i, float2 v ) {  fClusterUnpackedYZ[i] = v; }
+  GPUhd() void SetClusterUnpackedX( Int_t i, float v ) {  fClusterUnpackedX[i] = v; }
 
  private:
 
   AliHLTTPCCASliceOutput( const AliHLTTPCCASliceOutput& )
-    : fNTracks(0),fNTrackClusters(0),fTracks(0),fClusterIDrc(0), fClusterPackedYZ(0),fClusterUnpackedYZ(0),fClusterPackedAmp(0){}
+    : fNTracks(0),fNTrackClusters(0),fTracks(0),fClusterIDrc(0), fClusterPackedYZ(0),fClusterUnpackedYZ(0),fClusterUnpackedX(0),fClusterPackedAmp(0){}
 
   const AliHLTTPCCASliceOutput& operator=( const AliHLTTPCCASliceOutput& ) const { return *this; }
 
@@ -63,6 +65,7 @@ class AliHLTTPCCASliceOutput
   UInt_t   *fClusterIDrc;         // pointer to cluster IDs ( packed IRow and ICluster)
   UShort_t *fClusterPackedYZ;     // pointer to packed cluster YZ coordinates 
   float2   *fClusterUnpackedYZ;   // pointer to cluster coordinates (temporary data, for debug proposes)
+  float    *fClusterUnpackedX;   // pointer to cluster coordinates (temporary data, for debug proposes)
   UChar_t  *fClusterPackedAmp;    // pointer to packed cluster amplitudes
 
 };
@@ -73,7 +76,7 @@ GPUhd() inline Int_t AliHLTTPCCASliceOutput::EstimateSize( Int_t nOfTracks, Int_
 {
   // calculate the amount of memory [bytes] needed for the event
 
-  const Int_t kClusterDataSize = sizeof(UInt_t) + sizeof(UShort_t) + sizeof(float2)+ sizeof(UChar_t);
+  const Int_t kClusterDataSize = sizeof(UInt_t) + sizeof(UShort_t) + sizeof(float2) + sizeof(float)+ sizeof(UChar_t);
 
   return sizeof(AliHLTTPCCASliceOutput) + sizeof(AliHLTTPCCASliceTrack)*nOfTracks + kClusterDataSize*nOfTrackClusters;
 }
@@ -85,7 +88,8 @@ GPUhd() inline void AliHLTTPCCASliceOutput::SetPointers()
 
   fTracks            = (AliHLTTPCCASliceTrack*)((&fClusterPackedAmp)+1);
   fClusterUnpackedYZ = (float2*)  ( fTracks   + fNTracks );
-  fClusterIDrc       = (UInt_t*)  ( fClusterUnpackedYZ + fNTrackClusters );
+  fClusterUnpackedX  = (float*)   ( fClusterUnpackedYZ + fNTrackClusters );
+  fClusterIDrc       = (UInt_t*)  ( fClusterUnpackedX  + fNTrackClusters );
   fClusterPackedYZ   = (UShort_t*)( fClusterIDrc       + fNTrackClusters );
   fClusterPackedAmp  = (UChar_t*) ( fClusterPackedYZ + fNTrackClusters );
 }
index 99f7acd38ea198f605b66c829d21a2f4310d0505..aefc531bcfb97dee1c1af95b44c5b9294b582a34 100644 (file)
@@ -24,7 +24,7 @@
 #include "AliHLTTPCCAMath.h"
 
 
-void AliHLTTPCCATrackConvertor::GetExtParam( const AliHLTTPCCATrackParam &T1, AliExternalTrackParam &T2, Double_t alpha, Double_t Bz )
+void AliHLTTPCCATrackConvertor::GetExtParam( const AliHLTTPCCATrackParam &T1, AliExternalTrackParam &T2, Double_t alpha )
 {
   //* Convert from AliHLTTPCCATrackParam to AliExternalTrackParam parameterisation, 
   //* the angle alpha is the global angle of the local X axis 
@@ -36,18 +36,7 @@ void AliHLTTPCCATrackConvertor::GetExtParam( const AliHLTTPCCATrackParam &T1, Al
   if(par[2]>.99 ) par[2]=.99;
   if(par[2]<-.99 ) par[2]=-.99;
 
-  { // kappa => 1/pt
-    const Double_t kCLight = 0.000299792458;  
-    Double_t c = 1.e4;
-    if( CAMath::Abs(Bz)>1.e-4 ) c = 1./(Bz*kCLight);
-    par[4] *= c;
-    cov[10]*= c;
-    cov[11]*= c;
-    cov[12]*= c;
-    cov[13]*= c;
-    cov[14]*= c*c;
-  }
-  if( T1.GetCosPhi()<0 ){ // change direction
+  if( T1.GetSignCosPhi()<0 ){ // change direction
     par[2] = -par[2]; // sin phi
     par[3] = -par[3]; // DzDs
     par[4] = -par[4]; // kappa
@@ -61,7 +50,7 @@ void AliHLTTPCCATrackConvertor::GetExtParam( const AliHLTTPCCATrackParam &T1, Al
   T2.Set( (Double_t) T1.GetX(),alpha,par,cov);
 }
 
-void AliHLTTPCCATrackConvertor::SetExtParam( AliHLTTPCCATrackParam &T1, const AliExternalTrackParam &T2, Double_t Bz )
+void AliHLTTPCCATrackConvertor::SetExtParam( AliHLTTPCCATrackParam &T1, const AliExternalTrackParam &T2 )
 {
   //* Convert from AliExternalTrackParam parameterisation
   
@@ -70,16 +59,6 @@ void AliHLTTPCCATrackConvertor::SetExtParam( AliHLTTPCCATrackParam &T1, const Al
   T1.SetX( T2.GetX() );
   if(T1.SinPhi()>.99 ) T1.SetSinPhi( .99 );
   if(T1.SinPhi()<-.99 ) T1.SetSinPhi( -.99 );
-  T1.SetCosPhi( CAMath::Sqrt(1.-T1.SinPhi()*T1.SinPhi()));
-  const Double_t kCLight = 0.000299792458;  
-  Double_t c = Bz*kCLight;
-  { // 1/pt -> kappa 
-    T1.SetPar( 4, T1.Par()[4]*c );
-    T1.SetCov( 10, T1.Cov()[10]*c );
-    T1.SetCov( 11, T1.Cov()[11]*c );
-    T1.SetCov( 12, T1.Cov()[12]*c );
-    T1.SetCov( 13, T1.Cov()[13]*c );
-    T1.SetCov( 14, T1.Cov()[14]*c*c );
-  }
+  T1.SetSignCosPhi( 1 );
 }
 
index 6b3d6450a83650478986003f180226a266d95946..1685b5879eee0a807670c69a2e78a0f9686f831f 100644 (file)
@@ -27,8 +27,8 @@ class AliHLTTPCCATrackConvertor
 
   AliHLTTPCCATrackConvertor(){}
 
-  static void GetExtParam( const AliHLTTPCCATrackParam &T1, AliExternalTrackParam &T2, Double_t alpha, Double_t Bz );
-  static void SetExtParam( AliHLTTPCCATrackParam &T1, const AliExternalTrackParam &T2, Double_t Bz );
+  static void GetExtParam( const AliHLTTPCCATrackParam &T1, AliExternalTrackParam &T2, Double_t alpha );
+  static void SetExtParam( AliHLTTPCCATrackParam &T1, const AliExternalTrackParam &T2 );
 
 };
 
diff --git a/HLT/TPCLib/tracking-ca/AliHLTTPCCATrackLinearisation.h b/HLT/TPCLib/tracking-ca/AliHLTTPCCATrackLinearisation.h
new file mode 100644 (file)
index 0000000..6541330
--- /dev/null
@@ -0,0 +1,88 @@
+// ************************************************************************
+// This file is property of and copyright by the ALICE HLT Project        * 
+// ALICE Experiment at CERN, All rights reserved.                         *
+// See cxx source for full Copyright notice                               *
+//                                                                        *
+//*************************************************************************
+
+
+#ifndef ALIHLTTPCCATRACKLINEARISATION_H
+#define ALIHLTTPCCATRACKLINEARISATION_H
+
+#include "AliHLTTPCCATrackParam.h"
+
+
+/**
+ * @class AliHLTTPCCATrackLinearisation
+ *
+ * AliHLTTPCCATrackLinearisation class describes the parameters which are used 
+ * to linearise the transport equations for the track trajectory.
+ *
+ * The class is used during track (re)fit, when the AliHLTTPCTrackParam track is only 
+ * partially fitted, and there is some apriory knowledge about trajectory. 
+ * This apriory knowledge is used to linearise the transport equations. 
+ *
+ * In case the track is fully fitted, the best linearisation point is  
+ * the track trajectory itself (AliHLTTPCCATrackLinearisation = AliHLTTPCTrackParam ).
+ *
+ */
+class AliHLTTPCCATrackLinearisation
+{
+ public:
+
+  AliHLTTPCCATrackLinearisation()
+    :fSinPhi( 0 ), fCosPhi( 1 ), fDzDs( 0 ), fQPt( 0 ){}
+
+  AliHLTTPCCATrackLinearisation( Float_t SinPhi1, Float_t CosPhi1, Float_t DzDs1, Float_t QPt1 )
+    : fSinPhi( SinPhi1 ), fCosPhi( CosPhi1 ), fDzDs( DzDs1 ), fQPt( QPt1 )
+    {}
+  
+  AliHLTTPCCATrackLinearisation( const AliHLTTPCCATrackParam &t );
+                                                                                            
+  GPUd() void Set( Float_t SinPhi1, Float_t CosPhi1, Float_t DzDs1, Float_t QPt1 );
+
+
+  GPUd() Float_t SinPhi()const { return fSinPhi; }
+  GPUd() Float_t CosPhi()const { return fCosPhi; }
+  GPUd() Float_t DzDs()  const { return fDzDs; }
+  GPUd() Float_t QPt()   const { return fQPt; }
+
+  GPUd() Float_t GetSinPhi()const { return fSinPhi; }
+  GPUd() Float_t GetCosPhi()const { return fCosPhi; }
+  GPUd() Float_t GetDzDs()  const { return fDzDs; }
+  GPUd() Float_t GetQPt()   const { return fQPt; }
+
+  GPUd() void SetSinPhi( Float_t v ){  fSinPhi = v; }
+  GPUd() void SetCosPhi( Float_t v ){  fCosPhi = v; }
+  GPUd() void SetDzDs( Float_t v )  {  fDzDs   = v; }
+  GPUd() void SetQPt( Float_t v )   {  fQPt = v; }
+
+private:
+
+  Float_t fSinPhi; // SinPhi
+  Float_t fCosPhi; // CosPhi
+  Float_t fDzDs;   // DzDs
+  Float_t fQPt;    // QPt
+};
+
+
+inline AliHLTTPCCATrackLinearisation::AliHLTTPCCATrackLinearisation( const AliHLTTPCCATrackParam &t )
+  : fSinPhi(t.SinPhi()), fCosPhi(0), fDzDs(t.DzDs()), fQPt( t.QPt() )
+{
+  if( fSinPhi > .999 ) fSinPhi = .999;
+  else if( fSinPhi < -.999 ) fSinPhi = -.999;
+  fCosPhi = CAMath::Sqrt(1 - fSinPhi*fSinPhi);
+  if( t.SignCosPhi()<0 ) fCosPhi = -fCosPhi;
+}
+                               
+
+GPUd() inline void AliHLTTPCCATrackLinearisation::Set( Float_t SinPhi1, Float_t CosPhi1, 
+                                                 Float_t DzDs1, Float_t QPt1 )
+{
+  SetSinPhi( SinPhi1 ); 
+  SetCosPhi( CosPhi1 ); 
+  SetDzDs( DzDs1 ); 
+  SetQPt( QPt1 );
+}
+
+#endif
index 640f9bc01023e6d33ae652cb4dca7c96ee4a2102..70674bb92f8df58e4309ca52b2540ecd532c4faa 100644 (file)
 
 #include "AliHLTTPCCATrackParam.h"
 #include "AliHLTTPCCAMath.h"
+#include "AliHLTTPCCATrackLinearisation.h"
 #include <iostream>
 
 //
 // Circle in XY:
-// 
+//
+// kCLight = 0.000299792458; 
+// Kappa = Bz*kCLight*QPt;
 // R  = 1/TMath::Abs(Kappa);
 // Xc = X - sin(Phi)/Kappa;
 // Yc = Y + cos(Phi)/Kappa;
@@ -50,108 +53,11 @@ GPUd() Float_t AliHLTTPCCATrackParam::GetDistXZ2( const AliHLTTPCCATrackParam &t
 }
 
 
-GPUd() void AliHLTTPCCATrackParam::ConstructXY3( const Float_t x[3], const Float_t y[3], 
-                                         const Float_t sigmaY2[3], Float_t CosPhi0 )
-{
-  //* Construct the track in XY plane by 3 points
-
-  Float_t x0 = x[0];
-  Float_t y0 = y[0];
-  Float_t x1 = x[1] - x0;
-  Float_t y1 = y[1] - y0;
-  Float_t x2 = x[2] - x0;
-  Float_t y2 = y[2] - y0;
-  
-  Float_t a1 = x1*x1 + y1*y1;
-  Float_t a2 = x2*x2 + y2*y2;
-  Float_t a = 2*(x1*y2 - y1*x2);
-  Float_t lx =  a1*y2 - a2*y1;
-  Float_t ly = -a1*x2 + a2*x1;
-  Float_t l = CAMath::Sqrt(lx*lx + ly*ly);
-  Float_t li = 1./l;
-  Float_t li2 = li*li;
-  Float_t li3 = li2*li;
-  Float_t cosPhi = ly*li;
-
-  Float_t sinPhi = -lx*li;
-  Float_t kappa = a/l;
-
-  Float_t dlx = a2 - a1;     //  D lx / D y0
-  Float_t dly = -a;          //  D ly / D y0
-  Float_t dA  = 2*(x2 - x1); // D a  / D y0
-  Float_t dl = (lx*dlx + ly*dly)*li;
-  
-  // D sinPhi,kappa / D y0
-
-  Float_t d0[2] = { -(dlx*ly-lx*dly)*ly*li3, (dA*l-a*dl)*li2 };
-
-  // D sinPhi,kappa / D y1 
-
-  dlx = -a2 + 2*y1*y2;
-  dly = -2*x2*y1;
-  dA  = -2*x2;
-  dl = (lx*dlx + ly*dly)*li;
-
-  Float_t d1[2] = { -(dlx*ly-lx*dly)*ly*li3, (dA*l-a*dl)*li2 };
-
-  // D sinPhi,kappa / D y2
-
-  dlx = a1 - 2*y1*y2;
-  dly = -2*x1*y2;
-  dA  = 2*x1;
-  dl = (lx*dlx + ly*dly)*li;
-
-  Float_t d2[2] = { -(dlx*ly-lx*dly)*ly*li3, (dA*l-a*dl)*li2 };
-   
-  if( CosPhi0*cosPhi <0 ){
-    cosPhi = -cosPhi;
-    sinPhi = -sinPhi;
-    kappa = -kappa;   
-    d0[0] = -d0[0];
-    d0[1] = -d0[1];
-    d1[0] = -d1[0];
-    d1[1] = -d1[1];
-    d2[0] = -d2[0];
-    d2[1] = -d2[1];
-  }
-  
-  SetX( x0 );  
-  SetY( y0 );
-  SetSinPhi( sinPhi );
-  SetKappa( kappa );
-  SetCosPhi( cosPhi );
-
-  Float_t s0 = sigmaY2[0];
-  Float_t s1 = sigmaY2[1];
-  Float_t s2 = sigmaY2[2];
-
-  fC[0] = s0;
-  fC[1] = 0;
-  fC[2] = 100.;
-
-  fC[3] = d0[0]*s0;
-  fC[4] = 0;
-  fC[5] = d0[0]*d0[0]*s0 + d1[0]*d1[0]*s1 + d2[0]*d2[0]*s2;
-
-  fC[6] = 0;
-  fC[7] = 0;
-  fC[8] = 0;
-  fC[9] = 100.;
-
-  fC[10] = d0[1]*s0;
-  fC[11] = 0;
-  fC[12] = d0[0]*d0[1]*s0 + d1[0]*d1[1]*s1 + d2[0]*d2[1]*s2;
-  fC[13] = 0;
-  fC[14] = d0[1]*d0[1]*s0 + d1[1]*d1[1]*s1 + d2[1]*d2[1]*s2;
-}
-
-
-GPUd() Float_t  AliHLTTPCCATrackParam::GetS( Float_t x, Float_t y ) const
+GPUd() Float_t  AliHLTTPCCATrackParam::GetS( Float_t x, Float_t y, Float_t Bz ) const
 {
   //* Get XY path length to the given point
 
-  Float_t k  = GetKappa();
+  Float_t k  = GetKappa( Bz );
   Float_t ex = GetCosPhi();
   Float_t ey = GetSinPhi();
   x-= GetX();
@@ -162,13 +68,14 @@ GPUd() Float_t  AliHLTTPCCATrackParam::GetS( Float_t x, Float_t y ) const
 }
 
 GPUd() void  AliHLTTPCCATrackParam::GetDCAPoint( Float_t x, Float_t y, Float_t z,
-                                                Float_t &xp, Float_t &yp, Float_t &zp ) const
+                                                Float_t &xp, Float_t &yp, Float_t &zp, 
+                                                Float_t Bz ) const
 {
   //* Get the track point closest to the (x,y,z)
 
   Float_t x0 = GetX();
   Float_t y0 = GetY();
-  Float_t k  = GetKappa();
+  Float_t k  = GetKappa( Bz );
   Float_t ex = GetCosPhi();
   Float_t ey = GetSinPhi();
   Float_t dx = x - x0;
@@ -178,7 +85,7 @@ GPUd() void  AliHLTTPCCATrackParam::GetDCAPoint( Float_t x, Float_t y, Float_t z
   Float_t a = sqrt( ax*ax+ay*ay );
   xp = x0 + (dx - ey*( (dx*dx+dy*dy)*k - 2*(-dx*ey+dy*ex) )/(a+1) )/a;
   yp = y0 + (dy + ex*( (dx*dx+dy*dy)*k - 2*(-dx*ey+dy*ex) )/(a+1) )/a;
-  Float_t s = GetS(x,y);
+  Float_t s = GetS(x,y, Bz);
   zp = GetZ() + GetDzDs()*s;
   if( CAMath::Abs(k)>1.e-2 ){
     Float_t dZ = CAMath::Abs( GetDzDs()*CAMath::TwoPi()/k );
@@ -188,180 +95,34 @@ GPUd() void  AliHLTTPCCATrackParam::GetDCAPoint( Float_t x, Float_t y, Float_t z
   }
 }
 
-GPUd() void AliHLTTPCCATrackParam::ConstructXYZ3( const Float_t p0[5], const Float_t p1[5], 
-                                          const Float_t p2[5], 
-                                          Float_t CosPhi0, Float_t t0[] )
-{      
-  //* Construct the track in XYZ by 3 points
-
-  Float_t px[3]   = { p0[0], p1[0], p2[0] };
-  Float_t py[3]   = { p0[1], p1[1], p2[1] };
-  Float_t pz[3]   = { p0[2], p1[2], p2[2] };
-  Float_t ps2y[3] = { p0[3]*p0[3], p1[3]*p1[3], p2[3]*p2[3] };
-  Float_t ps2z[3] = { p0[4]*p0[4], p1[4]*p1[4], p2[4]*p2[4] };
-
-  Float_t kold = t0 ?t0[4] :0;
-  ConstructXY3( px, py, ps2y, CosPhi0 );
-
-  Float_t pS[3] = { GetS(px[0],py[0]), GetS(px[1],py[1]), GetS(px[2],py[2]) };
-  Float_t k = Kappa();
-  if( CAMath::Abs(k)>1.e-2 ){    
-    Float_t dS = CAMath::Abs( CAMath::TwoPi()/k );
-    pS[1]+= CAMath::Nint( (pS[0]-pS[1])/dS )*dS; // not more than half turn
-    pS[2]+= CAMath::Nint( (pS[1]-pS[2])/dS )*dS;
-    if( t0 ){
-      Float_t dZ = CAMath::Abs(t0[3]*dS);
-      if( CAMath::Abs(dZ)>1. ){
-       Float_t dsDz = 1./t0[3];
-       if( kold*k<0 ) dsDz = -dsDz;
-       Float_t s0 = (pz[0]-t0[1])*dsDz;
-       Float_t s1 = (pz[1]-t0[1])*dsDz;
-       Float_t s2 = (pz[2]-t0[1])*dsDz;        
-       pS[0]+= CAMath::Nint( (s0-pS[0])/dS )*dS ;
-       pS[1]+= CAMath::Nint( (s1-pS[1])/dS )*dS ;
-       pS[2]+= CAMath::Nint( (s2-pS[2])/dS )*dS ;      
-      }
-    }
-  }
 
-  Float_t s = pS[0] + pS[1] + pS[2];
-  Float_t z = pz[0] + pz[1] + pz[2];
-  Float_t sz = pS[0]*pz[0] + pS[1]*pz[1] + pS[2]*pz[2];
-  Float_t ss = pS[0]*pS[0] + pS[1]*pS[1] + pS[2]*pS[2];
-  
-  Float_t a = 3*ss-s*s;
-  SetZ( (z*ss-sz*s)/a ); // z0
-  SetDzDs( (3*sz-z*s)/a ); // t = dz/ds
-    
-  Float_t dz0[3] = {ss - pS[0]*s,ss - pS[1]*s,ss - pS[2]*s };
-  Float_t dt [3] = {3*pS[0] - s, 3*pS[1] - s, 3*pS[2] - s };
+//*
+//* Transport routines
+//*
 
-  fC[2] = (dz0[0]*dz0[0]*ps2z[0] + dz0[1]*dz0[1]*ps2z[1] + dz0[2]*dz0[2]*ps2z[2])/a/a;
-  fC[7]= (dz0[0]*dt [0]*ps2z[0] + dz0[1]*dt [1]*ps2z[1] + dz0[2]*dt [2]*ps2z[2])/a/a;  
-  fC[9]= (dt [0]*dt [0]*ps2z[0] + dt [1]*dt [1]*ps2z[1] + dt [2]*dt [2]*ps2z[2])/a/a;  
-}
 
-
-GPUd() Int_t  AliHLTTPCCATrackParam::TransportToX( Float_t x, Float_t maxSinPhi )
+GPUd() Bool_t  AliHLTTPCCATrackParam::TransportToX( Float_t x, AliHLTTPCCATrackLinearisation &t0, Float_t Bz,  Float_t maxSinPhi, Float_t *DL )
 {
-  //* Transport the track parameters to X=x 
+  //* Transport the track parameters to X=x, using linearization at t0, and the field value Bz
+  //* maxSinPhi is the max. allowed value for |t0.SinPhi()|
+  //* linearisation of trajectory t0 is also transported to X=x, 
+  //* returns 1 if OK
+  //*
 
-  Float_t x0  = X();
-  //Float_t y0  = Y();
-  Float_t k   = Kappa();
-  Float_t ex = CosPhi();
-  Float_t ey = SinPhi();
-  Float_t dx = x - x0;
+  Float_t ex = t0.CosPhi();
+  Float_t ey = t0.SinPhi();
+  Float_t k   = t0.QPt()*Bz;
+  Float_t dx = x - X();
 
   Float_t ey1 = k*dx + ey;
   Float_t ex1;
-  if( CAMath::Abs(ey1)>maxSinPhi ){ // no intersection 
-    return 0;
-  }else{
-    ex1 = CAMath::Sqrt(1 - ey1*ey1);
-    if( ex<0 ) ex1 = -ex1;  
-  }
-  
-  Float_t dx2 = dx*dx;
-  Float_t ss = ey+ey1;
-  Float_t cc = ex+ex1;  
-
-  if( CAMath::Abs(cc)<1.e-4 || CAMath::Abs(ex)<1.e-4 || CAMath::Abs(ex1)<1.e-4 ) return 0;
-
-  Float_t tg = ss/cc; // tan((phi1+phi)/2)
   
-  Float_t dy = dx*tg;
-  Float_t dl = dx*CAMath::Sqrt(1+tg*tg);
-
-  if( cc<0 ) dl = -dl;
-  Float_t dSin = dl*k/2;
-  if( dSin > 1 ) dSin = 1;
-  if( dSin <-1 ) dSin = -1;
-  Float_t dS = ( CAMath::Abs(k)>1.e-4)  ? (2*CAMath::ASin(dSin)/k) :dl;  
-  Float_t dz = dS*DzDs();
-
-  
-  Float_t cci = 1./cc;
-  Float_t exi = 1./ex;
-  Float_t ex1i = 1./ex1;
-  
-  fCosPhi = ex1;
-  fX += dx;
-  fP[0]+= dy;
-  fP[1]+= dz;
-  fP[2] = ey1;
-  fP[3] = fP[3];
-  fP[4] = fP[4];
-
-  Float_t h2 = dx*(1+ey*ey1 + ex*ex1)*exi*ex1i*cci;
-  Float_t h4 = dx2*(cc + ss*ey1*ex1i )*cci*cci;
-
-  Float_t c00 = fC[0];
-  Float_t c10 = fC[1];
-  Float_t c11 = fC[2];
-  Float_t c20 = fC[3];
-  Float_t c21 = fC[4];
-  Float_t c22 = fC[5];
-  Float_t c30 = fC[6];
-  Float_t c31 = fC[7];
-  Float_t c32 = fC[8];
-  Float_t c33 = fC[9];
-  Float_t c40 = fC[10];
-  Float_t c41 = fC[11];
-  Float_t c42 = fC[12];
-  Float_t c43 = fC[13];
-  Float_t c44 = fC[14];
-
-  //Float_t H0[5] = { 1,0, h2,  0, h4 };
-  //Float_t H1[5] = { 0, 1, 0, dS,  0 };
-  //Float_t H2[5] = { 0, 0, 1,  0, dx };
-  //Float_t H3[5] = { 0, 0, 0,  1,  0 };
-  //Float_t H4[5] = { 0, 0, 0,  0,  1 };
-
-
-  fC[0]=( c00  + h2*h2*c22 + h4*h4*c44 
-         + 2*( h2*c20 + h4*c40 + h2*h4*c42 )  ); 
+  // check for intersection with X=x 
 
-  fC[1]= c10 + h2*c21 + h4*c41 + dS*(c30 + h2*c32 + h4*c43);
-  fC[2]= c11 + 2*dS*c31 + dS*dS*c33;
+  if( CAMath::Abs(ey1)>maxSinPhi ) return 0;
 
-  fC[3]= c20 + h2*c22 + h4*c42 + dx*( c40 + h2*c42 + h4*c44);
-  fC[4]= c21 + dS*c32 + dx*(c41 + dS*c43);
-  fC[5]= c22 +2*dx*c42 + dx2*c44;
-
-  fC[6]= c30 + h2*c32 + h4*c43;
-  fC[7]= c31 + dS*c33;
-  fC[8]= c32 + dx*c43;
-  fC[9]= c33;
-
-  fC[10]= c40 + h2*c42 + h4*c44;
-  fC[11]= c41 + dS*c43;
-  fC[12]= c42 + dx*c44;
-  fC[13]= c43;
-  fC[14]= c44;
-
-  return 1;
-}
-
-
-GPUd() Int_t  AliHLTTPCCATrackParam::TransportToX( Float_t x, AliHLTTPCCATrackParam &t0, Float_t maxSinPhi )
-{
-  //* Transport the track parameters to X=x 
-
-  Float_t x0  = t0.X();  
-  Float_t k   = t0.Kappa();
-  Float_t ex = t0.CosPhi();
-  Float_t ey = t0.SinPhi();
-  Float_t dx = x - x0;
-
-  Float_t ey1 = k*dx + ey;
-  Float_t ex1;
-  if( CAMath::Abs(ey1)>maxSinPhi ){ // no intersection 
-    return 0;
-  }else{
-    ex1 = CAMath::Sqrt(1 - ey1*ey1);
-    if( ex<0 ) ex1 = -ex1;  
-  }
+  ex1 = CAMath::Sqrt(1 - ey1*ey1);
+  if( ex<0 ) ex1 = -ex1;
   
   Float_t dx2 = dx*dx;
   Float_t ss = ey+ey1;
@@ -381,100 +142,35 @@ GPUd() Int_t  AliHLTTPCCATrackParam::TransportToX( Float_t x, AliHLTTPCCATrackPa
   Float_t dS = ( CAMath::Abs(k)>1.e-4)  ? (2*CAMath::ASin(dSin)/k) :dl;  
   Float_t dz = dS*t0.DzDs();
 
-  
+  if( DL ) *DL = -dS*CAMath::Sqrt(1 + t0.DzDs()*t0.DzDs() );
+
   Float_t cci = 1./cc;
   Float_t exi = 1./ex;
   Float_t ex1i = 1./ex1;
   
-  Float_t c00 = fC[0];
-  Float_t c10 = fC[1];
-  Float_t c11 = fC[2];
-  Float_t c20 = fC[3];
-  Float_t c21 = fC[4];
-  Float_t c22 = fC[5];
-  Float_t c30 = fC[6];
-  Float_t c31 = fC[7];
-  Float_t c32 = fC[8];
-  Float_t c33 = fC[9];
-  Float_t c40 = fC[10];
-  Float_t c41 = fC[11];
-  Float_t c42 = fC[12];
-  Float_t c43 = fC[13];
-  Float_t c44 = fC[14];
-
-  Float_t d[5] = { fP[0]-t0.fP[0], 
-                  fP[1]-t0.fP[1], 
-                  fP[2]-t0.fP[2], 
-                  fP[3]-t0.fP[3], 
-                  fP[4]-t0.fP[4] };
+  Float_t d[5] = { 0,
+                  0,
+                  fP[2]-t0.SinPhi(),
+                  fP[3]-t0.DzDs(), 
+                  fP[4]-t0.QPt() };
 
   //Float_t H0[5] = { 1,0, h2,  0, h4 };
   //Float_t H1[5] = { 0, 1, 0, dS,  0 };
-  //Float_t H2[5] = { 0, 0, 1,  0, dx };
+  //Float_t H2[5] = { 0, 0, 1,  0, dxBz };
   //Float_t H3[5] = { 0, 0, 0,  1,  0 };
   //Float_t H4[5] = { 0, 0, 0,  0,  1 };
-
-  Float_t h2 = dx*(1+ey*ey1 + ex*ex1)*exi*ex1i*cci;
-  Float_t h4 = dx2*(cc + ss*ey1*ex1i )*cci*cci;
   
+  Float_t h2 = dx*(1+ey*ey1 + ex*ex1)*exi*ex1i*cci;
+  Float_t h4 = dx2*(cc + ss*ey1*ex1i )*cci*cci*Bz;
+  Float_t dxBz = dx*Bz;
+
   t0.SetCosPhi( ex1 );
-  t0.SetX( t0.GetX() + dx );
-  t0.SetY( t0.GetY() + dy );
-  t0.SetZ( t0.Z() + dz );
   t0.SetSinPhi( ey1 );  
 
-  fX = t0.X();
-  fP[0] = t0.fP[0] + d[0]        + h2*d[2]          + h4*d[4];
-  fP[1] = t0.fP[1]        + d[1]           + dS*d[3];
-  fP[2] = t0.fP[2]               +d[2]              + dx*d[4];
-
-  //CosPhi() = CosPhi()>=0 ?CAMath::Sqrt(1-fP[2]*fP[2]) :-CAMath::Sqrt(1-fP[2]*fP[2]);
-  
-  fC[0]=( c00  + h2*h2*c22 + h4*h4*c44 
-         + 2*( h2*c20 + h4*c40 + h2*h4*c42 )  ); 
-
-  fC[1]= c10 + h2*c21 + h4*c41 + dS*(c30 + h2*c32 + h4*c43);
-  fC[2]= c11 + 2*dS*c31 + dS*dS*c33;
-
-  fC[3]= c20 + h2*c22 + h4*c42 + dx*( c40 + h2*c42 + h4*c44);
-  fC[4]= c21 + dS*c32 + dx*(c41 + dS*c43);
-  fC[5]= c22 +2*dx*c42 + dx2*c44;
-
-  fC[6]= c30 + h2*c32 + h4*c43;
-  fC[7]= c31 + dS*c33;
-  fC[8]= c32 + dx*c43;
-  fC[9]= c33;
-
-  fC[10]= c40 + h2*c42 + h4*c44;
-  fC[11]= c41 + dS*c43;
-  fC[12]= c42 + dx*c44;
-  fC[13]= c43;
-  fC[14]= c44;
-
-  return 1;
-}
-
-
-GPUd() Int_t  AliHLTTPCCATrackParam::TransportToX0( Float_t x, Float_t sinPhi, Float_t cosPhi )
-{
-  //* Transport the track parameters to X=x 
-
-  Float_t ex = cosPhi;
-  Float_t ey = sinPhi;
-  Float_t dx = x - X();  
-
-  if( CAMath::Abs(ex)<1.e-4 ) return 0;
-  Float_t exi = 1./ex;
-  
-  Float_t dl = dx*exi;
-  Float_t dy = dl*ey;
-  Float_t dS = dl;  
-  Float_t dz = dS*DzDs();
-  
-  Float_t h2 = dx*exi*exi*exi;
-  Float_t h4 = dx*h2/2;
-  Float_t h5 = dx;
+  fX    = X() + dx;
+  fP[0] = Y() + dy     + h2*d[2]           +   h4*d[4];
+  fP[1] = Z() + dz               + dS*d[3];
+  fP[2] = t0.SinPhi() +     d[2]           + dxBz*d[4];
 
   Float_t c00 = fC[0];
   Float_t c10 = fC[1];
@@ -492,210 +188,67 @@ GPUd() Int_t  AliHLTTPCCATrackParam::TransportToX0( Float_t x, Float_t sinPhi, F
   Float_t c43 = fC[13];
   Float_t c44 = fC[14];
 
-  //Float_t H0[5] = { 1,0, h2,  0, h4 };
-  //Float_t H1[5] = { 0, 1, 0, dS,  0 };
-  //Float_t H2[5] = { 0, 0, 1,  0, h5 };
-  //Float_t H3[5] = { 0, 0, 0,  1,  0 };
-  //Float_t H4[5] = { 0, 0, 0,  0,  1 };
-
-  Float_t ey1 = SinPhi() + h5*Kappa();
-  //if( TMath::Abs(ey1)>maxSinPhi ){
-  //std::cout<<" TransportToX0 error: sinPhi="<<ey<<" -> "<<ey1<<std::endl;
-  //return 0;
-  //}
-  fX += dx ;
-  fP[0]+= dy  + h2*(SinPhi()-ey) + h4*Kappa();
-  fP[1]+= dz ;
-  fP[2] = ey1;
-
-  //CosPhi() = CAMath::Sqrt(1-ey1*ey1);
-  //if( ex<0 ) CosPhi() = -CosPhi();
-
   fC[0]=( c00  + h2*h2*c22 + h4*h4*c44 
          + 2*( h2*c20 + h4*c40 + h2*h4*c42 )  ); 
 
   fC[1]= c10 + h2*c21 + h4*c41 + dS*(c30 + h2*c32 + h4*c43);
   fC[2]= c11 + 2*dS*c31 + dS*dS*c33;
 
-  fC[3]= c20 + h2*c22 + h4*c42 + h5*( c40 + h2*c42 + h4*c44);
-  fC[4]= c21 + dS*c32 + h5*(c41 + dS*c43);
-  fC[5]= c22 +2*h5*c42 + h5*h5*c44;
+  fC[3]= c20 + h2*c22 + h4*c42 + dxBz*( c40 + h2*c42 + h4*c44);
+  fC[4]= c21 + dS*c32 + dxBz*(c41 + dS*c43);
+  fC[5]= c22 +2*dxBz*c42 + dxBz*dxBz*c44;
 
   fC[6]= c30 + h2*c32 + h4*c43;
   fC[7]= c31 + dS*c33;
-  fC[8]= c32 + h5*c43;
+  fC[8]= c32 + dxBz*c43;
   fC[9]= c33;
 
   fC[10]= c40 + h2*c42 + h4*c44;
   fC[11]= c41 + dS*c43;
-  fC[12]= c42 + h5*c44;
+  fC[12]= c42 + dxBz*c44;
   fC[13]= c43;
   fC[14]= c44;
 
   return 1;
 }
 
-GPUd() Int_t  AliHLTTPCCATrackParam::TransportToX0( Float_t x, Float_t maxSinPhi)
-{
-  //* Transport the track parameters to X=x 
 
-  Float_t ex = CosPhi();
-  Float_t ey = SinPhi();
+GPUd() Bool_t  AliHLTTPCCATrackParam::TransportToX( Float_t x, Float_t sinPhi0, Float_t cosPhi0,  Float_t Bz, Float_t maxSinPhi )
+{
+  //* Transport the track parameters to X=x, using linearization at phi0 with 0 curvature, 
+  //* and the field value Bz
+  //* maxSinPhi is the max. allowed value for |t0.SinPhi()|
+  //* linearisation of trajectory t0 is also transported to X=x, 
+  //* returns 1 if OK
+  //*
+
+  Float_t ex = cosPhi0;
+  Float_t ey = sinPhi0;
   Float_t dx = x - X();
 
   if( CAMath::Abs(ex)<1.e-4 ) return 0;
   Float_t exi = 1./ex;
-  
-  Float_t dl = dx*exi;
-  Float_t dy = dl*ey;
-  Float_t dS = dl;  
-  Float_t dz = dS*DzDs();
-  
-  Float_t h2 = dx*exi*exi*exi;
-  Float_t h4 = dx*h2/2;
-  Float_t h5 = dx;
-
-  Float_t c00 = fC[0];
-  Float_t c10 = fC[1];
-  Float_t c11 = fC[2];
-  Float_t c20 = fC[3];
-  Float_t c21 = fC[4];
-  Float_t c22 = fC[5];
-  Float_t c30 = fC[6];
-  Float_t c31 = fC[7];
-  Float_t c32 = fC[8];
-  Float_t c33 = fC[9];
-  Float_t c40 = fC[10];
-  Float_t c41 = fC[11];
-  Float_t c42 = fC[12];
-  Float_t c43 = fC[13];
-  Float_t c44 = fC[14];
 
+  Float_t dxBz = dx*Bz;
+  Float_t dS = dx*exi;
+  Float_t h2 = dS*exi*exi;
+  Float_t h4 = .5*h2*dxBz;
   //Float_t H0[5] = { 1,0, h2,  0, h4 };
   //Float_t H1[5] = { 0, 1, 0, dS,  0 };
-  //Float_t H2[5] = { 0, 0, 1,  0, h5 };
+  //Float_t H2[5] = { 0, 0, 1,  0, dxBz };
   //Float_t H3[5] = { 0, 0, 0,  1,  0 };
   //Float_t H4[5] = { 0, 0, 0,  0,  1 };
 
-  Float_t ey1 = SinPhi() + h5*Kappa();
-  if( CAMath::Abs(ey1)>maxSinPhi ){
-    //std::cout<<" TransportToX0 error: sinPhi="<<ey<<" -> "<<ey1<<std::endl;
-    return 0;
-  }
-  fX += dx ;
-  fP[0]+= dy + h4*Kappa();
-  fP[1]+= dz;
-  fP[2] = ey1;
-  fP[3] = fP[3];
-  fP[4] = fP[4];
-  fCosPhi = CAMath::Sqrt(1-ey1*ey1);
-  if( ex<0 ) fCosPhi = -fCosPhi;
-
-  fC[0]=( c00  + h2*h2*c22 + h4*h4*c44 
-         + 2*( h2*c20 + h4*c40 + h2*h4*c42 )  ); 
+  Float_t sinPhi = SinPhi() + dxBz*QPt();
+  if( maxSinPhi>0 && CAMath::Abs(sinPhi)>maxSinPhi ) return 0;
 
-  fC[1]= c10 + h2*c21 + h4*c41 + dS*(c30 + h2*c32 + h4*c43);
-  fC[2]= c11 + 2*dS*c31 + dS*dS*c33;
-
-  fC[3]= c20 + h2*c22 + h4*c42 + h5*( c40 + h2*c42 + h4*c44);
-  fC[4]= c21 + dS*c32 + h5*(c41 + dS*c43);
-  fC[5]= c22 +2*h5*c42 + h5*h5*c44;
-
-  fC[6]= c30 + h2*c32 + h4*c43;
-  fC[7]= c31 + dS*c33;
-  fC[8]= c32 + h5*c43;
-  fC[9]= c33;
-
-  fC[10]= c40 + h2*c42 + h4*c44;
-  fC[11]= c41 + dS*c43;
-  fC[12]= c42 + h5*c44;
-  fC[13]= c43;
-  fC[14]= c44;
-
-  return 1;
-}
-
-
-GPUd() Bool_t AliHLTTPCCATrackParam::TransportToXWithMaterial( Float_t Xto, Float_t Bz )
-{
-  //* Transport the track parameters to X=Xto
-  AliHLTTPCCATrackFitParam par;
-  CalculateFitParameters( par, Bz );
-  return TransportToXWithMaterial(Xto, par );
-}
-
-
-GPUd() Bool_t  AliHLTTPCCATrackParam::TransportToXWithMaterial( Float_t x, AliHLTTPCCATrackFitParam &par )
-{
-  //* Transport the track parameters to X=x 
-
-  Bool_t ret = 1;
-
-  Float_t oldX=GetX();
-
-  Float_t x0  = X();
-  //Float_t y0  = Y();
-  Float_t k   = Kappa();
-  Float_t ex = CosPhi();
-  Float_t ey = SinPhi();
-  Float_t dx = x - x0;
-
-  Float_t ey1 = k*dx + ey;
-  Float_t ex1;
-  if( CAMath::Abs(ey1)>.99 ){ // no intersection -> check the border    
-    ey1 = ( ey1>0 ) ?1 :-1;
-    ex1 = 0;
-    dx = ( CAMath::Abs(k)>1.e-4) ? ( (ey1-ey)/k ) :0;
-    
-    Float_t ddx = CAMath::Abs(x0+dx - x)*k*k;
-    Float_t hx[] = {0, -k, 1+ey };
-    Float_t sx2 = hx[1]*hx[1]*fC[ 3] + hx[2]*hx[2]*fC[ 5];
-    if( ddx*ddx>3.5*3.5*sx2 ) ret = 0; // x not withing the error
-    ret = 0; // any case
-    return ret;
-  }else{
-    ex1 = CAMath::Sqrt(1 - ey1*ey1);
-    if( ex<0 ) ex1 = -ex1;  
-  }
-  
-  Float_t dx2 = dx*dx;
-  fCosPhi = ex1;
-  Float_t ss = ey+ey1;
-  Float_t cc = ex+ex1;  
-  Float_t tg = 0;
-  if( CAMath::Abs(cc)>1.e-4 ) tg = ss/cc; // tan((phi1+phi)/2)
-  else ret = 0; 
-  Float_t dy = dx*tg;
-  Float_t dl = dx*CAMath::Sqrt(1+tg*tg);
-
-  if( cc<0 ) dl = -dl;
-  Float_t dSin = dl*k/2;
-  if( dSin > 1 ) dSin = 1;
-  if( dSin <-1 ) dSin = -1;
-  Float_t dS = ( CAMath::Abs(k)>1.e-4)  ? (2*CAMath::ASin(dSin)/k) :dl;
-  Float_t dz = dS*DzDs();
-
-  Float_t cci = 0, exi = 0, ex1i = 0;
-  if( CAMath::Abs(cc)>1.e-4 ) cci = 1./cc;
-  else ret = 0;
-  if( CAMath::Abs(ex)>1.e-4 ) exi = 1./ex;
-  else ret = 0;
-  if( CAMath::Abs(ex1)>1.e-4 ) ex1i = 1./ex1;
-  else ret = 0;
-
-  if( !ret ) return ret;
-
-  fX += dx;
-  fP[0]+= dy;
-  fP[1]+= dz;  
-  fP[2] = ey1;
-  fP[3] = fP[3];
-  fP[4] = fP[4];
-
-  Float_t h2 = dx*(1+ ex*ex1 + ey*ey1 )*cci*exi*ex1i;
-  Float_t h4 = dx2*(cc + ss*ey1*ex1i )*cci*cci;
+  fX    = X() + dx;
+  fP[0]+= dS*ey + h2*( SinPhi() - ey )  +   h4*QPt();
+  fP[1]+= dS*DzDs();
+  fP[2] = sinPhi;
 
   Float_t c00 = fC[0];
   Float_t c10 = fC[1];
   Float_t c11 = fC[2];
@@ -712,12 +265,6 @@ GPUd() Bool_t  AliHLTTPCCATrackParam::TransportToXWithMaterial( Float_t x, AliHL
   Float_t c43 = fC[13];
   Float_t c44 = fC[14];
 
-  //Float_t H0[5] = { 1,0, h2,  0, h4 };
-  //Float_t H1[5] = { 0, 1, 0, dS,  0 };
-  //Float_t H2[5] = { 0, 0, 1,  0, dx };
-  //Float_t H3[5] = { 0, 0, 0,  1,  0 };
-  //Float_t H4[5] = { 0, 0, 0,  0,  1 };
-
 
   fC[0]=( c00  + h2*h2*c22 + h4*h4*c44 
          + 2*( h2*c20 + h4*c40 + h2*h4*c42 )  ); 
@@ -725,172 +272,156 @@ GPUd() Bool_t  AliHLTTPCCATrackParam::TransportToXWithMaterial( Float_t x, AliHL
   fC[1]= c10 + h2*c21 + h4*c41 + dS*(c30 + h2*c32 + h4*c43);
   fC[2]= c11 + 2*dS*c31 + dS*dS*c33;
 
-  fC[3]= c20 + h2*c22 + h4*c42 + dx*( c40 + h2*c42 + h4*c44);
-  fC[4]= c21 + dS*c32 + dx*(c41 + dS*c43);
-  fC[5]= c22 +2*dx*c42 + dx2*c44;
+  fC[3]= c20 + h2*c22 + h4*c42 + dxBz*( c40 + h2*c42 + h4*c44);
+  fC[4]= c21 + dS*c32 + dxBz*(c41 + dS*c43);
+  fC[5]= c22 +2*dxBz*c42 + dxBz*dxBz*c44;
 
   fC[6]= c30 + h2*c32 + h4*c43;
   fC[7]= c31 + dS*c33;
-  fC[8]= c32 + dx*c43;
+  fC[8]= c32 + dxBz*c43;
   fC[9]= c33;
 
   fC[10]= c40 + h2*c42 + h4*c44;
   fC[11]= c41 + dS*c43;
-  fC[12]= c42 + dx*c44;
+  fC[12]= c42 + dxBz*c44;
   fC[13]= c43;
   fC[14]= c44;
 
-  Float_t d = CAMath::Sqrt(dS*dS + dz*dz );
-
-  if (oldX > GetX() ) d = -d;
-  {
-    Float_t rho=0.9e-3; 
-    Float_t radLen=28.94;
-    CorrectForMeanMaterial(d*rho/radLen,d*rho,par);
-  }
-
-  return ret;
+  return 1;
 }
 
 
 
-GPUd() Bool_t  AliHLTTPCCATrackParam::TransportToXWithMaterial( Float_t x, AliHLTTPCCATrackParam &t0, AliHLTTPCCATrackFitParam &par )
-{
-  //* Transport the track parameters to X=x 
 
-  Bool_t ret = 1;
 
-  Float_t oldX=t0.GetX();
 
-  Float_t x0  = t0.X();
-  //Float_t y0  = t0.Y();
-  Float_t k   = t0.Kappa();
-  Float_t ex = t0.CosPhi();
-  Float_t ey = t0.SinPhi();
-  Float_t dx = x - x0;
-
-  Float_t ey1 = k*dx + ey;
-  Float_t ex1;
-  if( CAMath::Abs(ey1)>.99 ){ // no intersection -> check the border    
-    ey1 = ( ey1>0 ) ?1 :-1;
-    ex1 = 0;
-    dx = ( CAMath::Abs(k)>1.e-4) ? ( (ey1-ey)/k ) :0;
-    
-    Float_t ddx = CAMath::Abs(x0+dx - x)*k*k;
-    Float_t hx[] = {0, -k, 1+ey };
-    Float_t sx2 = hx[1]*hx[1]*fC[ 3] + hx[2]*hx[2]*fC[ 5];
-    if( ddx*ddx>3.5*3.5*sx2 ) ret = 0; // x not withing the error
-    ret = 0; // any case
-    return ret;
-  }else{
-    ex1 = CAMath::Sqrt(1 - ey1*ey1);
-    if( ex<0 ) ex1 = -ex1;  
-  }
-  
-  Float_t dx2 = dx*dx;
-  Float_t ss = ey+ey1;
-  Float_t cc = ex+ex1;  
-  Float_t tg = 0;
-  if( CAMath::Abs(cc)>1.e-4 ) tg = ss/cc; // tan((phi1+phi)/2)
-  else ret = 0; 
-  Float_t dy = dx*tg;
-  Float_t dl = dx*CAMath::Sqrt(1+tg*tg);
-
-  if( cc<0 ) dl = -dl;
-  Float_t dSin = dl*k/2;
-  if( dSin > 1 ) dSin = 1;
-  if( dSin <-1 ) dSin = -1;
-  Float_t dS = ( CAMath::Abs(k)>1.e-4)  ? (2*CAMath::ASin(dSin)/k) :dl;
-  Float_t dz = dS*t0.DzDs();
+GPUd() Bool_t  AliHLTTPCCATrackParam::TransportToX( Float_t x, Float_t Bz, Float_t maxSinPhi )
+{
+  //* Transport the track parameters to X=x 
 
-  Float_t cci = 0, exi = 0, ex1i = 0;
-  if( CAMath::Abs(cc)>1.e-4 ) cci = 1./cc;
-  else ret = 0;
-  if( CAMath::Abs(ex)>1.e-4 ) exi = 1./ex;
-  else ret = 0;
-  if( CAMath::Abs(ex1)>1.e-4 ) ex1i = 1./ex1;
-  else ret = 0;
+  AliHLTTPCCATrackLinearisation t0(*this);
 
-  if( !ret ) return ret;
+  return TransportToX( x, t0, Bz, maxSinPhi );
+}
 
-  Float_t h2 = dx*(1+ ex*ex1 + ey*ey1 )*cci*exi*ex1i;
-  Float_t h4 = dx2*(cc + ss*ey1*ex1i )*cci*cci;
 
-  Float_t c00 = fC[0];
-  Float_t c10 = fC[1];
-  Float_t c11 = fC[2];
-  Float_t c20 = fC[3];
-  Float_t c21 = fC[4];
-  Float_t c22 = fC[5];
-  Float_t c30 = fC[6];
-  Float_t c31 = fC[7];
-  Float_t c32 = fC[8];
-  Float_t c33 = fC[9];
-  Float_t c40 = fC[10];
-  Float_t c41 = fC[11];
-  Float_t c42 = fC[12];
-  Float_t c43 = fC[13];
-  Float_t c44 = fC[14];
 
-  //Float_t H0[5] = { 1,0, h2,  0, h4 };
-  //Float_t H1[5] = { 0, 1, 0, dS,  0 };
-  //Float_t H2[5] = { 0, 0, 1,  0, dx };
-  //Float_t H3[5] = { 0, 0, 0,  1,  0 };
-  //Float_t H4[5] = { 0, 0, 0,  0,  1 };
+GPUd() Bool_t  AliHLTTPCCATrackParam::TransportToXWithMaterial( Float_t x,  AliHLTTPCCATrackLinearisation &t0, AliHLTTPCCATrackFitParam &par, Float_t Bz, Float_t maxSinPhi )
+{
+  //* Transport the track parameters to X=x  taking into account material budget
 
-  Float_t d[5] = { fP[0]-t0.fP[0], fP[1]-t0.fP[1], fP[2]-t0.fP[2], 
-                  fP[3]-t0.fP[3], fP[4]-t0.fP[4] };
-  
-  t0.SetCosPhi( ex1 );
-  t0.SetX( t0.X() + dx );
-  t0.SetY( t0.Y() + dy );
-  t0.SetZ( t0.Z() + dz );
-  t0.SetSinPhi( ey1 );
+  const Float_t kRho = 1.025e-3;//0.9e-3; 
+  const Float_t kRadLen=29.532;//28.94;
+  const Float_t kRhoOverRadLen = kRho/kRadLen;
+  Float_t dl;
 
-  fX = t0.X();
-  fP[0] = t0.fP[0] + d[0]        + h2*d[2]          + h4*d[4];
-  fP[1] = t0.fP[1]        + d[1]           + dS*d[3];
-  fP[2] = t0.fP[2]               +d[2]              + dx*d[4];
-  fP[3] = fP[3];
-  fP[4] = fP[4];
+  if( !TransportToX( x, t0, Bz,  maxSinPhi, &dl ) ) return 0;
 
-  //CosPhi() = CAMath::Sqrt(1-fP[2]*fP[2]);
+  CorrectForMeanMaterial(dl*kRhoOverRadLen,dl*kRho,par);  
+  return 1;
+}
 
-  fC[0]=( c00  + h2*h2*c22 + h4*h4*c44 
-         + 2*( h2*c20 + h4*c40 + h2*h4*c42 )  ); 
 
-  fC[1]= c10 + h2*c21 + h4*c41 + dS*(c30 + h2*c32 + h4*c43);
-  fC[2]= c11 + 2*dS*c31 + dS*dS*c33;
+GPUd() Bool_t  AliHLTTPCCATrackParam::TransportToXWithMaterial( Float_t x,  AliHLTTPCCATrackFitParam &par, Float_t Bz, Float_t maxSinPhi )
+{
+  //* Transport the track parameters to X=x  taking into account material budget
 
-  fC[3]= c20 + h2*c22 + h4*c42 + dx*( c40 + h2*c42 + h4*c44);
-  fC[4]= c21 + dS*c32 + dx*(c41 + dS*c43);
-  fC[5]= c22 +2*dx*c42 + dx2*c44;
+  AliHLTTPCCATrackLinearisation t0(*this);
+  return TransportToXWithMaterial( x, t0, par, Bz, maxSinPhi );
+}
 
-  fC[6]= c30 + h2*c32 + h4*c43;
-  fC[7]= c31 + dS*c33;
-  fC[8]= c32 + dx*c43;
-  fC[9]= c33;
+GPUd() Bool_t AliHLTTPCCATrackParam::TransportToXWithMaterial( Float_t x, Float_t Bz, Float_t maxSinPhi )
+{
+  //* Transport the track parameters to X=x taking into account material budget
+
+  AliHLTTPCCATrackFitParam par;
+  CalculateFitParameters( par );
+  return TransportToXWithMaterial(x, par, Bz, maxSinPhi );
+}
 
-  fC[10]= c40 + h2*c42 + h4*c44;
-  fC[11]= c41 + dS*c43;
-  fC[12]= c42 + dx*c44;
-  fC[13]= c43;
-  fC[14]= c44;
 
-  Float_t dd = CAMath::Sqrt(dS*dS + dz*dz );
+//*
+//*  Multiple scattering and energy losses
+//*
 
-  if (oldX > GetX() ) dd = -dd;
-  {
-    Float_t rho=0.9e-3; 
-    Float_t radLen=28.94;
-    CorrectForMeanMaterial(dd*rho/radLen,dd*rho,par);
-    t0.CorrectForMeanMaterial(dd*rho/radLen,dd*rho,par);
+
+Float_t AliHLTTPCCATrackParam::BetheBlochGeant(Float_t bg2,
+                                              Float_t kp0,
+                                              Float_t kp1,
+                                              Float_t kp2,
+                                              Float_t kp3,
+                                              Float_t kp4) 
+{
+  //
+  // This is the parameterization of the Bethe-Bloch formula inspired by Geant.
+  //
+  // bg2  - (beta*gamma)^2
+  // kp0 - density [g/cm^3]
+  // kp1 - density effect first junction point
+  // kp2 - density effect second junction point
+  // kp3 - mean excitation energy [GeV]
+  // kp4 - mean Z/A
+  //
+  // The default values for the kp* parameters are for silicon. 
+  // The returned value is in [GeV/(g/cm^2)].
+  // 
+
+  const Float_t mK  = 0.307075e-3; // [GeV*cm^2/g]
+  const Float_t me  = 0.511e-3;    // [GeV/c^2]
+  const Float_t rho = kp0;
+  const Float_t x0  = kp1*2.303;
+  const Float_t x1  = kp2*2.303;
+  const Float_t mI  = kp3;
+  const Float_t mZA = kp4;
+  const Float_t maxT= 2*me*bg2;    // neglecting the electron mass
+  
+  //*** Density effect
+  Float_t d2=0.; 
+  const Float_t x=0.5*TMath::Log(bg2);
+  const Float_t lhwI=TMath::Log(28.816*1e-9*TMath::Sqrt(rho*mZA)/mI);
+  if (x > x1) {
+    d2 = lhwI + x - 0.5;
+  } else if (x > x0) {
+    const Float_t r=(x1-x)/(x1-x0);
+    d2 = lhwI + x - 0.5 + (0.5 - lhwI - x0)*r*r*r;
   }
 
-  return ret;
+  return mK*mZA*(1+bg2)/bg2*(0.5*TMath::Log(2*me*bg2*maxT/(mI*mI)) - bg2/(1+bg2) - d2);
+}
+
+Float_t AliHLTTPCCATrackParam::BetheBlochSolid(Float_t bg) 
+{
+  //------------------------------------------------------------------
+  // This is an approximation of the Bethe-Bloch formula, 
+  // reasonable for solid materials. 
+  // All the parameters are, in fact, for Si.
+  // The returned value is in [GeV]
+  //------------------------------------------------------------------
+
+  return BetheBlochGeant(bg);
+}
+
+Float_t AliHLTTPCCATrackParam::BetheBlochGas(Float_t bg) 
+{
+  //------------------------------------------------------------------
+  // This is an approximation of the Bethe-Bloch formula, 
+  // reasonable for gas materials.
+  // All the parameters are, in fact, for Ne.
+  // The returned value is in [GeV]
+  //------------------------------------------------------------------
+
+  const Float_t rho = 0.9e-3;
+  const Float_t x0  = 2.;
+  const Float_t x1  = 4.;
+  const Float_t mI  = 140.e-9;
+  const Float_t mZA = 0.49555;
+
+  return BetheBlochGeant(bg,rho,x0,x1,mI,mZA);
 }
 
 
+
+
 GPUd() Float_t AliHLTTPCCATrackParam::ApproximateBetheBloch( Float_t beta2 ) 
 {
   //------------------------------------------------------------------
@@ -906,33 +437,34 @@ GPUd() Float_t AliHLTTPCCATrackParam::ApproximateBetheBloch( Float_t beta2 )
 }
 
 
-GPUd() void AliHLTTPCCATrackParam::CalculateFitParameters( AliHLTTPCCATrackFitParam &par, Float_t Bz, Float_t mass )
+GPUd() void AliHLTTPCCATrackParam::CalculateFitParameters( AliHLTTPCCATrackFitParam &par, Float_t mass )
 {
   //*!
 
-  const Float_t kCLight = 0.000299792458;  
-  Float_t c = Bz*kCLight;
-  Float_t p2 = (1.+ fP[3]*fP[3])*c*c;  
+  Float_t p2 = (1.+ fP[3]*fP[3]);
   Float_t k2 = fP[4]*fP[4];
-  Float_t beta2= p2 / (p2 + mass*mass*k2);
-  Float_t bethe = ApproximateBetheBloch(beta2);
+  Float_t mass2 = mass*mass;
+  Float_t beta2= p2 / (p2 + mass2*k2);
+
+  Float_t pp2 = (k2>1.e-8) ?p2/k2 :10000; // impuls 2  
 
-  Float_t pp2 = (k2>1.e-8) ?p2/k2 :10000; // impuls 2
-  par.fBethe = bethe;
-  par.fE = CAMath::Sqrt( pp2 + mass*mass);
-  par.fTheta2 = 14.1*14.1/(beta2*p2*1e6)*k2;
-  par.fEP2 = par.fE/p2*k2;
+  //par.fBethe = BetheBlochGas( pp2/mass2);
+  par.fBethe = ApproximateBetheBloch( pp2/mass2);
+  par.fE = CAMath::Sqrt( pp2 + mass2);
+  par.fTheta2 = 14.1*14.1/(beta2*pp2*1e6);
+  par.fEP2 = par.fE/pp2;
 
   // Approximate energy loss fluctuation (M.Ivanov)
   
   const Float_t knst=0.07; // To be tuned.  
-  par.fSigmadE2 = knst*par.fEP2*fP[4]; 
+  par.fSigmadE2 = knst*par.fEP2*fP[4];
   par.fSigmadE2 = par.fSigmadE2 * par.fSigmadE2;
-  
   par.fK22 = (1. + fP[3]*fP[3]);
   par.fK33 = par.fK22*par.fK22;
   par.fK43 = fP[3]*fP[4]*par.fK22;
   par.fK44 = fP[3]*fP[3]*fP[4]*fP[4];
+
 }
 
 
@@ -953,11 +485,12 @@ GPUd() Bool_t AliHLTTPCCATrackParam::CorrectForMeanMaterial( Float_t xOverX0,  F
   Float_t &fC44=fC[14]; 
 
   //Energy losses************************
-  
   Float_t dE = par.fBethe*xTimesRho;
   if ( CAMath::Abs(dE) > 0.3*par.fE ) return 0; //30% energy loss is too much!
   Float_t corr = (1.- par.fEP2*dE);
-  if( corr<0.3 ) return 0;
+  if( corr<0.3 || corr>1.3 ) return 0;
+
   fP[4]*= corr;
   fC40*= corr;
   fC41*= corr;
@@ -965,7 +498,6 @@ GPUd() Bool_t AliHLTTPCCATrackParam::CorrectForMeanMaterial( Float_t xOverX0,  F
   fC43*= corr;
   fC44*= corr*corr;
   fC44+= par.fSigmadE2*CAMath::Abs(dE);
-  
 
   //Multiple scattering******************
   
@@ -974,11 +506,15 @@ GPUd() Bool_t AliHLTTPCCATrackParam::CorrectForMeanMaterial( Float_t xOverX0,  F
   fC33 += theta2*par.fK33;
   fC43 += theta2*par.fK43; 
   fC44 += theta2*par.fK44;
-    
+
   return 1;
 }
 
 
+//*
+//* Rotation
+//*
+
 
 GPUd() Bool_t AliHLTTPCCATrackParam::Rotate( Float_t alpha, Float_t maxSinPhi )
 {
@@ -986,7 +522,7 @@ GPUd() Bool_t AliHLTTPCCATrackParam::Rotate( Float_t alpha, Float_t maxSinPhi )
   
   Float_t cA = CAMath::Cos( alpha );
   Float_t sA = CAMath::Sin( alpha );
-  Float_t x = X(), y= Y(), sP= SinPhi(), cP= CosPhi();
+  Float_t x = X(), y= Y(), sP= SinPhi(), cP= GetCosPhi();
   Float_t cosPhi = cP*cA + sP*sA;
   Float_t sinPhi =-cP*sA + sP*cA;
   
@@ -997,7 +533,7 @@ GPUd() Bool_t AliHLTTPCCATrackParam::Rotate( Float_t alpha, Float_t maxSinPhi )
   
   SetX( x*cA +  y*sA );
   SetY(-x*sA +  y*cA );
-  SetCosPhi( cosPhi );
+  SetSignCosPhi( cosPhi );
   SetSinPhi( sinPhi );
 
 
@@ -1023,36 +559,33 @@ GPUd() Bool_t AliHLTTPCCATrackParam::Rotate( Float_t alpha, Float_t maxSinPhi )
   return 1;
 }
 
-
-GPUd() Bool_t AliHLTTPCCATrackParam::RotateNoCos( Float_t alpha, AliHLTTPCCATrackParam &t0, Float_t maxSinPhi )
+GPUd() Bool_t AliHLTTPCCATrackParam::Rotate( Float_t alpha, AliHLTTPCCATrackLinearisation &t0, Float_t maxSinPhi )
 {
   //* Rotate the coordinate system in XY on the angle alpha
   
   Float_t cA = CAMath::Cos( alpha );
   Float_t sA = CAMath::Sin( alpha );
-  Float_t x0 = t0.X(), y0= t0.Y(), sP= t0.SinPhi(), cP= t0.CosPhi();
+  Float_t x0 = X(), y0= Y(), sP= t0.SinPhi(), cP= t0.CosPhi();
   Float_t cosPhi = cP*cA + sP*sA;
   Float_t sinPhi =-cP*sA + sP*cA;
   
   if( CAMath::Abs(sinPhi)> maxSinPhi || CAMath::Abs(cosPhi)<1.e-2 || CAMath::Abs(cP)<1.e-2  ) return 0;
   
+  //Float_t J[5][5] = { { j0, 0, 0,  0,  0 }, // Y
+  //                    {  0, 1, 0,  0,  0 }, // Z
+  //                    {  0, 0, j2, 0,  0 }, // SinPhi
+  //                   {  0, 0, 0,  1,  0 }, // DzDs
+  //                   {  0, 0, 0,  0,  1 } }; // Kappa
+
   Float_t j0 = cP/cosPhi; 
   Float_t j2 = cosPhi/cP;
   Float_t d[2] = {Y() - y0, SinPhi() - sP};
 
-  t0.SetX( x0*cA +  y0*sA );
-  t0.SetY(-x0*sA +  y0*cA );
+  SetX( x0*cA +  y0*sA );
+  SetY(-x0*sA +  y0*cA + j0*d[0] );
   t0.SetCosPhi( cosPhi );
   t0.SetSinPhi( sinPhi );
 
-  //Float_t J[5][5] = { { j0, 0, 0,  0,  0 }, // Y
-  //                    {  0, 1, 0,  0,  0 }, // Z
-  //                    {  0, 0, j2, 0,  0 }, // SinPhi
-  //                   {  0, 0, 0,  1,  0 }, // DzDs
-  //                   {  0, 0, 0,  0,  1 } }; // Kappa
-
-  SetX( t0.X() );
-  SetY( t0.Y() + j0*d[0] );
   SetSinPhi( sinPhi + j2*d[1] );
 
   fC[0]*= j0*j0;
@@ -1071,248 +604,7 @@ GPUd() Bool_t AliHLTTPCCATrackParam::RotateNoCos( Float_t alpha, AliHLTTPCCATrac
 }
 
 
-GPUd() Bool_t AliHLTTPCCATrackParam::Filter2( Float_t y, Float_t z, Float_t err2Y, Float_t err2Z, Float_t maxSinPhi )
-{
-  //* Add the y,z measurement with the Kalman filter 
-
-  Float_t 
-    c00 = fC[ 0],
-    c10 = fC[ 1], c11 = fC[ 2],
-    c20 = fC[ 3], c21 = fC[ 4],
-    c30 = fC[ 6], c31 = fC[ 7],
-    c40 = fC[10], c41 = fC[11];
-  
-  Float_t
-    z0 = y-fP[0],
-    z1 = z-fP[1];
-
-  Float_t v[3] = {err2Y, 0, err2Z};
-
-  Float_t mS[3] = { c00+v[0], c10+v[1], c11+v[2] };
-
-  Float_t mSi[3];
-  Float_t det = (mS[0]*mS[2] - mS[1]*mS[1]);
-
-  if( det < 1.e-8 ) return 0;
-  det = 1./det;
-  mSi[0] = mS[2]*det;
-  mSi[1] = -mS[1]*det;
-  mSi[2] = mS[0]*det;
-  // K = CHtS
-  
-  Float_t k00, k01 , k10, k11, k20, k21, k30, k31, k40, k41;
-    
-  k00 = c00*mSi[0] + c10*mSi[1]; k01 = c00*mSi[1] + c10*mSi[2];
-  k10 = c10*mSi[0] + c11*mSi[1]; k11 = c10*mSi[1] + c11*mSi[2];
-  k20 = c20*mSi[0] + c21*mSi[1]; k21 = c20*mSi[1] + c21*mSi[2];
-  k30 = c30*mSi[0] + c31*mSi[1]; k31 = c30*mSi[1] + c31*mSi[2] ;
-  k40 = c40*mSi[0] + c41*mSi[1]; k41 = c40*mSi[1] + c41*mSi[2] ;
-
-  Float_t sinPhi = fP[2] + k20*z0  + k21*z1  ;
-  if( CAMath::Abs(sinPhi)>= maxSinPhi ) return 0;
-
-  fNDF  += 2;
-  fChi2 += ( +(mSi[0]*z0 + mSi[1]*z1 )*z0
-            +(mSi[1]*z0 + mSi[2]*z1 )*z1 );
-
-  fP[ 0]+= k00*z0  + k01*z1 ;
-  fP[ 1]+= k10*z0  + k11*z1  ;
-  fP[ 2] = sinPhi;
-  fP[ 3]+= k30*z0  + k31*z1  ;
-  fP[ 4]+= k40*z0  + k41*z1  ;
-
-    
-  fC[ 0]-= k00*c00 + k01*c10 ;
-  
-  fC[ 1]-= k10*c00 + k11*c10 ;
-  fC[ 2]-= k10*c10 + k11*c11 ;
-
-  fC[ 3]-= k20*c00 + k21*c10 ;
-  fC[ 4]-= k20*c10 + k21*c11 ;
-  fC[ 5]-= k20*c20 + k21*c21 ;
-
-  fC[ 6]-= k30*c00 + k31*c10 ;
-  fC[ 7]-= k30*c10 + k31*c11 ;
-  fC[ 8]-= k30*c20 + k31*c21 ;
-  fC[ 9]-= k30*c30 + k31*c31 ;
-
-  fC[10]-= k40*c00 + k41*c10 ;
-  fC[11]-= k40*c10 + k41*c11 ;
-  fC[12]-= k40*c20 + k41*c21 ;
-  fC[13]-= k40*c30 + k41*c31 ;
-  fC[14]-= k40*c40 + k41*c41 ;
-    
-  if( fCosPhi >=0 ){
-    fCosPhi = CAMath::Sqrt(1-SinPhi()*SinPhi());
-  }else{
-    fCosPhi = -CAMath::Sqrt(1-SinPhi()*SinPhi());
-  }   
-  return 1;
-}
-
-GPUd() Bool_t AliHLTTPCCATrackParam::Filter2NoCos( Float_t y, Float_t z, Float_t err2Y, Float_t err2Z )
-{
-  //* Add the y,z measurement with the Kalman filter 
-
-  Float_t 
-    c00 = fC[ 0],
-    c10 = fC[ 1], c11 = fC[ 2],
-    c20 = fC[ 3], c21 = fC[ 4],
-    c30 = fC[ 6], c31 = fC[ 7],
-    c40 = fC[10], c41 = fC[11];
-  
-  Float_t
-    z0 = y-fP[0],
-    z1 = z-fP[1];
-
-  Float_t v[3] = {err2Y, 0, err2Z};
-
-  Float_t mS[3] = { c00+v[0], c10+v[1], c11+v[2] };
-
-  Float_t mSi[3];
-  Float_t det = (mS[0]*mS[2] - mS[1]*mS[1]);
-  
-  if( !finite(det) || det > 1.e15 ) return 0;
-  if( det < 1.e-8  ) return 0;
-  det = 1./det;
-  mSi[0] = mS[2]*det;
-  mSi[1] = -mS[1]*det;
-  mSi[2] = mS[0]*det;
-  // K = CHtS
-  
-  Float_t k00, k01 , k10, k11, k20, k21, k30, k31, k40, k41;
-    
-  k00 = c00*mSi[0] + c10*mSi[1]; k01 = c00*mSi[1] + c10*mSi[2];
-  k10 = c10*mSi[0] + c11*mSi[1]; k11 = c10*mSi[1] + c11*mSi[2];
-  k20 = c20*mSi[0] + c21*mSi[1]; k21 = c20*mSi[1] + c21*mSi[2];
-  k30 = c30*mSi[0] + c31*mSi[1]; k31 = c30*mSi[1] + c31*mSi[2] ;
-  k40 = c40*mSi[0] + c41*mSi[1]; k41 = c40*mSi[1] + c41*mSi[2] ;
-
-  Float_t sinPhi = fP[2] + k20*z0  + k21*z1  ;
-  //if( CAMath::Abs(sinPhi)>= maxSinPhi ) return 0;
-
-  fNDF  += 2;
-  fChi2 += ( +(mSi[0]*z0 + mSi[1]*z1 )*z0
-            +(mSi[1]*z0 + mSi[2]*z1 )*z1 );
-
-  fP[ 0]+= k00*z0  + k01*z1 ;
-  fP[ 1]+= k10*z0  + k11*z1  ;
-  fP[ 2] = sinPhi;
-  fP[ 3]+= k30*z0  + k31*z1  ;
-  fP[ 4]+= k40*z0  + k41*z1  ;
-
-    
-  fC[ 0]-= k00*c00 + k01*c10 ;
-  
-  fC[ 1]-= k10*c00 + k11*c10 ;
-  fC[ 2]-= k10*c10 + k11*c11 ;
-
-  fC[ 3]-= k20*c00 + k21*c10 ;
-  fC[ 4]-= k20*c10 + k21*c11 ;
-  fC[ 5]-= k20*c20 + k21*c21 ;
-
-  fC[ 6]-= k30*c00 + k31*c10 ;
-  fC[ 7]-= k30*c10 + k31*c11 ;
-  fC[ 8]-= k30*c20 + k31*c21 ;
-  fC[ 9]-= k30*c30 + k31*c31 ;
-
-  fC[10]-= k40*c00 + k41*c10 ;
-  fC[11]-= k40*c10 + k41*c11 ;
-  fC[12]-= k40*c20 + k41*c21 ;
-  fC[13]-= k40*c30 + k41*c31 ;
-  fC[14]-= k40*c40 + k41*c41 ;
-  /*    
-  if( CosPhi()>=0 ){
-    CosPhi() = CAMath::Sqrt(1-SinPhi()*SinPhi());
-  }else{
-    CosPhi() = -CAMath::Sqrt(1-SinPhi()*SinPhi());
-  }  
-  */ 
-  return 1;
-}
-
-
-GPUd() Bool_t AliHLTTPCCATrackParam::Filter2v1( Float_t y, Float_t z, Float_t err2Y, Float_t err2Z, Float_t maxSinPhi )
-{
-  //* Add the y,z measurement with the Kalman filter 
-
-  Float_t 
-    c00 = fC[ 0],
-    c10 = fC[ 1], c11 = fC[ 2],
-    c20 = fC[ 3], c21 = fC[ 4],
-    c30 = fC[ 6], c31 = fC[ 7],
-    c40 = fC[10], c41 = fC[11];
-
-  err2Y+=c00;
-  err2Z+=c11;
-
-  Float_t
-    z0 = y-fP[0],
-    z1 = z-fP[1];
-  
-  Float_t det = ( err2Y*err2Z - c10*c10);
-  if( det < 1.e-8 ) return 0;
-
-  det = 1./det;
-
-  Float_t mS0 = err2Z*det;
-  Float_t mS1 = -c10*det;
-  Float_t mS2 = err2Y*det;
-  // K = CHtS
-  
-  Float_t k00, k01 , k10, k11, k20, k21, k30, k31, k40, k41;
-    
-  k00 = c00*mS0 + c10*mS1; k01 = c00*mS1 + c10*mS2;
-  k10 = c10*mS0 + c11*mS1; k11 = c10*mS1 + c11*mS2;
-  k20 = c20*mS0 + c21*mS1; k21 = c20*mS1 + c21*mS2;
-  k30 = c30*mS0 + c31*mS1; k31 = c30*mS1 + c31*mS2;
-  k40 = c40*mS0 + c41*mS1; k41 = c40*mS1 + c41*mS2;
-
-  Float_t sinPhi = fP[2] + k20*z0  + k21*z1  ;
-  if( CAMath::Abs(sinPhi)>= maxSinPhi ) return 0;
-
-  fNDF  += 2;
-  fChi2 += (mS0*z0 + mS1*z1 )*z0 + (mS1*z0 + mS2*z1 )*z1 ;
-
-  fP[ 0]+= k00*z0  + k01*z1 ;
-  fP[ 1]+= k10*z0  + k11*z1  ;
-  fP[ 2] = sinPhi;
-  fP[ 3]+= k30*z0  + k31*z1  ;
-  fP[ 4]+= k40*z0  + k41*z1  ;
-
-    
-  fC[ 0]-= k00*c00 + k01*c10 ;
-  
-  fC[ 1]-= k10*c00 + k11*c10 ;
-  fC[ 2]-= k10*c10 + k11*c11 ;
-
-  fC[ 3]-= k20*c00 + k21*c10 ;
-  fC[ 4]-= k20*c10 + k21*c11 ;
-  fC[ 5]-= k20*c20 + k21*c21 ;
-
-  fC[ 6]-= k30*c00 + k31*c10 ;
-  fC[ 7]-= k30*c10 + k31*c11 ;
-  fC[ 8]-= k30*c20 + k31*c21 ;
-  fC[ 9]-= k30*c30 + k31*c31 ;
-
-  fC[10]-= k40*c00 + k41*c10 ;
-  fC[11]-= k40*c10 + k41*c11 ;
-  fC[12]-= k40*c20 + k41*c21 ;
-  fC[13]-= k40*c30 + k41*c31 ;
-  fC[14]-= k40*c40 + k41*c41 ;
-    
-  if( fCosPhi>=0 ){
-    fCosPhi = CAMath::Sqrt(1-sinPhi*sinPhi);
-  }else{
-    fCosPhi = -CAMath::Sqrt(1-sinPhi*sinPhi);
-  }   
-  return 1;
-}
-
-GPUd() Bool_t AliHLTTPCCATrackParam::Filter20( Float_t y, Float_t z, Float_t err2Y, Float_t err2Z, Float_t maxSinPhi )
+GPUd() Bool_t AliHLTTPCCATrackParam::Filter( Float_t y, Float_t z, Float_t err2Y, Float_t err2Z, Float_t maxSinPhi )
 {
   //* Add the y,z measurement with the Kalman filter 
 
@@ -1347,93 +639,9 @@ GPUd() Bool_t AliHLTTPCCATrackParam::Filter20( Float_t y, Float_t z, Float_t err
   k31 = c31*mS2;
 
   Float_t sinPhi = fP[2] + k20*z0  ;
-
-  
-  if( CAMath::Abs(sinPhi)>= maxSinPhi ){
-    std::cout<<"Filter20: sinPhi ="<<fP[2]<<" -> "<<sinPhi<<std::endl;
-    std::cout<<"z0,z1="<<z0<<" "<<z1<<std::endl;
-    std::cout<<"c="<<fC[0]<<std::endl;
-    std::cout<<"  "<<fC[1]<<" "<<fC[2]<<std::endl;
-    std::cout<<"  "<<fC[3]<<" "<<fC[4]<<" "<<fC[5]<<std::endl;
-  }
-  if( CAMath::Abs(sinPhi)>= maxSinPhi ){
-    return 0;
-  }
-  Float_t cosPhi = CAMath::Sqrt(1-sinPhi*sinPhi);
-  fNDF  += 2;
-  fChi2 += mS0*z0*z0 + mS2*z1*z1 ;
-
-  fP[ 0]+= k00*z0 ;
-  fP[ 1]+= k11*z1 ;
-  fP[ 2] = sinPhi ;
-  fP[ 3]+= k31*z1 ;
-  fP[ 4]+= k40*z0 ;
-    
-  fC[ 0]-= k00*c00 ;    
-  fC[ 3]-= k20*c00 ;
-  fC[ 5]-= k20*c20 ;
-  fC[10]-= k40*c00 ;
-  fC[12]-= k40*c20 ;
-  fC[14]-= k40*c40 ;
-  fC[ 2]-= k11*c11 ;
-  fC[ 7]-= k31*c11 ;
-  fC[ 9]-= k31*c31 ;
-   
-  fCosPhi = ( fCosPhi >=0 ) ?cosPhi :-cosPhi;
-  return 1;
-}
-
-
-
-GPUd() Bool_t AliHLTTPCCATrackParam::Filter200( Float_t y, Float_t z, Float_t err2Y, Float_t err2Z )
-{
-  //* Add the y,z measurement with the Kalman filter 
-
-  Float_t 
-    c00 = fC[ 0],
-    c11 = fC[ 2],
-    c20 = fC[ 3],
-    c31 = fC[ 7],
-    c40 = fC[10];
-
-  err2Y+=c00;
-  err2Z+=c11;
-
-  Float_t
-    z0 = y-fP[0],
-    z1 = z-fP[1];
-  
-  if( err2Y < 1.e-8 || err2Z<1.e-8 ) return 0;
-
-  Float_t mS0 = 1./err2Y;
-  Float_t mS2 = 1./err2Z;
-  // K = CHtS
   
-  Float_t k00, k11, k20, k31, k40;
-    
-  k00 = c00*mS0;
-  k20 = c20*mS0;
-  k40 = c40*mS0;
-
-  k11 = c11*mS2;
-  k31 = c31*mS2;
-
-  Float_t sinPhi = fP[2] + k20*z0  ;
-
+  if( maxSinPhi>0 && CAMath::Abs(sinPhi)>= maxSinPhi ) return 0;
   
-  //if( CAMath::Abs(sinPhi)>= maxSinPhi ){
-  //std::cout<<"Filter20: sinPhi ="<<fP[2]<<" -> "<<sinPhi<<std::endl;
-  //std::cout<<"z0,z1="<<z0<<" "<<z1<<std::endl;
-  //std::cout<<"c="<<fC[0]<<std::endl;
-  //std::cout<<"  "<<fC[1]<<" "<<fC[2]<<std::endl;
-  //std::cout<<"  "<<fC[3]<<" "<<fC[4]<<" "<<fC[5]<<std::endl;
-  //}
-  //if( CAMath::Abs(sinPhi)>= maxSinPhi ){
-  //return 0;
-  //}
-  //Float_t cosPhi = CAMath::Sqrt(1-sinPhi*sinPhi);
   fNDF  += 2;
   fChi2 += mS0*z0*z0 + mS2*z1*z1 ;
 
@@ -1454,149 +662,11 @@ GPUd() Bool_t AliHLTTPCCATrackParam::Filter200( Float_t y, Float_t z, Float_t er
   fC[ 7]-= k31*c11 ;
   fC[ 9]-= k31*c31 ;
    
-  //fCosPhi = ( fCosPhi >=0 ) ?cosPhi :-cosPhi;
   return 1;
 }
 
 
-GPUd() void AliHLTTPCCATrackParam::FilterY( Float_t y, Float_t erry )
-{
-  //* Add the y measurement with the Kalman filter 
-
-  Float_t 
-    c00 = fC[ 0],
-    c10 = fC[ 1],
-    c20 = fC[ 3],
-    c30 = fC[ 6],
-    c40 = fC[10];
-  
-  Float_t
-    z0 = y-fP[0];
-
-  Float_t s = { c00+erry*erry };
-  if( CAMath::Abs(s)<1.e-4 ) return;
-
-  Float_t si = 1/s;
-
-  fNDF  += 1;
-  fChi2 += si*z0*z0;        
-
-  // K = CHtS
-  
-  Float_t k0, k1 , k2, k3, k4;
-    
-  k0 = c00*si;
-  k1 = c10*si;
-  k2 = c20*si;
-  k3 = c30*si;
-  k4 = c40*si;
-
-  Float_t sinPhi = fP[2] + k2*z0 ;
-  if( CAMath::Abs(sinPhi)>=0.99 ) return;
-
-  fP[ 0]+= k0*z0 ;
-  fP[ 1]+= k1*z0 ;
-  fP[ 2] = sinPhi;
-  fP[ 3]+= k3*z0 ;
-  fP[ 4]+= k4*z0 ;
-    
-  fC[ 0]-= k0*c00;
-  
-  fC[ 1]-= k1*c00;
-  fC[ 2]-= k1*c10;
-
-  fC[ 3]-= k2*c00;
-  fC[ 4]-= k2*c10;
-  fC[ 5]-= k2*c20;
-
-  fC[ 6]-= k3*c00;
-  fC[ 7]-= k3*c10;
-  fC[ 8]-= k3*c20;
-  fC[ 9]-= k3*c30;
-
-  fC[10]-= k4*c00;
-  fC[11]-= k4*c10;
-  fC[12]-= k4*c20;
-  fC[13]-= k4*c30;
-  fC[14]-= k4*c40;
-    
-  if( fCosPhi>=0 ){
-    fCosPhi = CAMath::Sqrt(1-SinPhi()*SinPhi());
-  }else{
-    fCosPhi = -CAMath::Sqrt(1-SinPhi()*SinPhi());
-  }   
-    
-}
-
-GPUd() void AliHLTTPCCATrackParam::FilterZ( Float_t z, Float_t errz )
-{
-  //* Add the z measurement with the Kalman filter 
-
-  Float_t 
-    c01 = fC[ 1],
-    c11 = fC[ 2],
-    c21 = fC[ 4],
-    c31 = fC[ 7],
-    c41 = fC[11];
-  
-  Float_t
-    z1 = z-fP[1];
-
-  Float_t s = c11 + errz*errz;
-  if( CAMath::Abs(s)<1.e-4 ) return;
-
-  Float_t si = 1./s;
-  fNDF  += 1;
-  fChi2 += si*z1*z1;
-
-  // K = CHtS
-  
-  Float_t k0, k1 , k2, k3, k4;
-    
-  k0 = 0;//c01*si;
-  k1 = c11*si;
-  k2 = 0;//c21*si;
-  k3 = c31*si;
-  k4 = 0;//c41*si;
-
-  Float_t sinPhi = fP[2] + k2*z1  ;
-  if( CAMath::Abs(sinPhi)>=0.99 ) return;
-
-  fP[ 0]+= k0*z1 ;
-  fP[ 1]+= k1*z1 ;
-  fP[ 2] = sinPhi;
-  fP[ 3]+= k3*z1 ;
-  fP[ 4]+= k4*z1 ;
 
-    
-  fC[ 0]-= k0*c01 ;
-  
-  fC[ 1]-= k1*c01 ;
-  fC[ 2]-= k1*c11 ;
-
-  fC[ 3]-= k2*c01 ;
-  fC[ 4]-= k2*c11 ;
-  fC[ 5]-= k2*c21 ;
-
-  fC[ 6]-= k3*c01 ;
-  fC[ 7]-= k3*c11 ;
-  fC[ 8]-= k3*c21 ;
-  fC[ 9]-= k3*c31 ;
-
-  fC[10]-= k4*c01 ;
-  fC[11]-= k4*c11 ;
-  fC[12]-= k4*c21 ;
-  fC[13]-= k4*c31 ;
-  fC[14]-= k4*c41 ;
-    
-  if( fCosPhi>=0 ){
-    fCosPhi = CAMath::Sqrt(1-SinPhi()*SinPhi());
-  }else{
-    fCosPhi = -CAMath::Sqrt(1-SinPhi()*SinPhi());
-  }   
-    
-}
 
 #if !defined(HLTCA_GPUCODE)
 #include <iostream>
@@ -1607,7 +677,8 @@ GPUd() void AliHLTTPCCATrackParam::Print() const
   //* print parameters
  
 #if !defined(HLTCA_GPUCODE)
-  std::cout<<"track: x="<<GetX()<<" c="<<GetCosPhi()<<", P= "<<GetY()<<" "<<GetZ()<<" "<<GetSinPhi()<<" "<<GetDzDs()<<" "<<GetKappa()<<std::endl;
-  std::cout<<"errs2: "<<GetErr2Y()<<" "<<GetErr2Z()<<" "<<GetErr2SinPhi()<<" "<<GetErr2DzDs()<<" "<<GetErr2Kappa()<<std::endl;
+  std::cout<<"track: x="<<GetX()<<" c="<<GetSignCosPhi()<<", P= "<<GetY()<<" "<<GetZ()<<" "<<GetSinPhi()<<" "<<GetDzDs()<<" "<<GetQPt()<<std::endl;
+  std::cout<<"errs2: "<<GetErr2Y()<<" "<<GetErr2Z()<<" "<<GetErr2SinPhi()<<" "<<GetErr2DzDs()<<" "<<GetErr2QPt()<<std::endl;
 #endif
 }
+
index 7e20cd20c6ada7485296bbbbf573cbb2d1e44b33..90a7418c2a718341840cc9ccd5c37efcc1bf22cc 100644 (file)
@@ -12,7 +12,9 @@
 #define ALIHLTTPCCATRACKPARAM_H
 
 #include "AliHLTTPCCADef.h"
+#include "AliHLTTPCCAMath.h"
 
+class AliHLTTPCCATrackLinearisation;
 
 /**
  * @class AliHLTTPCCATrackParam
@@ -30,13 +32,13 @@ class AliHLTTPCCATrackParam
     Float_t fBethe, fE,fTheta2, fEP2, fSigmadE2, fK22,fK33,fK43,fK44;// parameters
   };
 
-  GPUd() Float_t X()     const { return fX;    }
-  GPUd() Float_t Y()     const { return fP[0]; }
-  GPUd() Float_t Z()     const { return fP[1]; }
-  GPUd() Float_t SinPhi()const { return fP[2]; }
-  GPUd() Float_t DzDs()  const { return fP[3]; }
-  GPUd() Float_t Kappa() const { return fP[4]; }
-  GPUd() Float_t CosPhi()const { return fCosPhi; }
+  GPUd() Float_t X()      const { return fX;    }
+  GPUd() Float_t Y()      const { return fP[0]; }
+  GPUd() Float_t Z()      const { return fP[1]; }
+  GPUd() Float_t SinPhi() const { return fP[2]; }
+  GPUd() Float_t DzDs()   const { return fP[3]; }
+  GPUd() Float_t QPt()    const { return fP[4]; }
+  GPUd() Float_t SignCosPhi() const { return fSignCosPhi; }
   GPUd() Float_t Chi2()  const { return fChi2; }
   GPUd() Int_t   NDF()   const { return fNDF; }
 
@@ -44,23 +46,26 @@ class AliHLTTPCCATrackParam
   Float_t Err2Z()      const { return fC[2]; }
   Float_t Err2SinPhi() const { return fC[5]; }
   Float_t Err2DzDs()   const { return fC[9]; }
-  Float_t Err2Kappa()  const { return fC[14]; }
+  Float_t Err2QPt()    const { return fC[14]; }
 
   GPUd() Float_t GetX()      const { return fX; }
   GPUd() Float_t GetY()      const { return fP[0]; }
   GPUd() Float_t GetZ()      const { return fP[1]; }
   GPUd() Float_t GetSinPhi() const { return fP[2]; }
   GPUd() Float_t GetDzDs()   const { return fP[3]; }
-  GPUd() Float_t GetKappa()  const { return fP[4]; }
-  GPUd() Float_t GetCosPhi() const { return fCosPhi; }
+  GPUd() Float_t GetQPt()    const { return fP[4]; }
+  GPUd() Float_t GetSignCosPhi() const { return fSignCosPhi; }
   GPUd() Float_t GetChi2()   const { return fChi2; }
   GPUd() Int_t   GetNDF()    const { return fNDF; }
 
+  GPUd() Float_t GetKappa( Float_t Bz ) const { return fP[4]*Bz; }
+  GPUd() Float_t GetCosPhi() const { return fSignCosPhi*CAMath::Sqrt(1-SinPhi()*SinPhi()); }
+
   GPUd() Float_t GetErr2Y()      const { return fC[0]; }
   GPUd() Float_t GetErr2Z()      const { return fC[2]; }
   GPUd() Float_t GetErr2SinPhi() const { return fC[5]; }
   GPUd() Float_t GetErr2DzDs()   const { return fC[9]; }
-  GPUd() Float_t GetErr2Kappa()  const { return fC[14]; }
+  GPUd() Float_t GetErr2QPt()    const { return fC[14]; }
 
   GPUhd() const Float_t *Par() const { return fP; }
   GPUhd() const Float_t *Cov() const { return fC; }
@@ -76,8 +81,8 @@ class AliHLTTPCCATrackParam
   GPUd() void SetZ( Float_t v )     {  fP[1] = v; }
   GPUd() void SetSinPhi( Float_t v ){  fP[2] = v; }
   GPUd() void SetDzDs( Float_t v )  {  fP[3] = v; }
-  GPUd() void SetKappa( Float_t v ) {  fP[4] = v; }
-  GPUd() void SetCosPhi( Float_t v ){  fCosPhi = v; }
+  GPUd() void SetQPt( Float_t v )   {  fP[4] = v; }
+  GPUd() void SetSignCosPhi( Float_t v ){  fSignCosPhi = v; }
   GPUd() void SetChi2( Float_t v )  {  fChi2 = v; }
   GPUd() void SetNDF( Int_t v )   { fNDF = v; }  
 
@@ -85,51 +90,60 @@ class AliHLTTPCCATrackParam
   GPUd() Float_t GetDist2( const AliHLTTPCCATrackParam &t ) const;
   GPUd() Float_t GetDistXZ2( const AliHLTTPCCATrackParam &t ) const;
 
-  GPUd() void ConstructXY3( const Float_t x[3], const Float_t y[3], const Float_t sigmaY2[3], Float_t CosPhi0 );
-
-  GPUd() void ConstructXYZ3( const Float_t p0[5], const Float_t p1[5], const Float_t p2[5], 
-                             Float_t CosPhi0, Float_t t0[]=0 );
 
-  GPUd() Float_t GetS( Float_t x, Float_t y ) const;
+  GPUd() Float_t GetS( Float_t x, Float_t y, Float_t Bz  ) const;
 
   GPUd() void GetDCAPoint( Float_t x, Float_t y, Float_t z,
-                          Float_t &px, Float_t &py, Float_t &pz ) const;
+                          Float_t &px, Float_t &py, Float_t &pz, Float_t Bz  ) const;
+
   
-  GPUd() Int_t TransportToX( Float_t X, Float_t maxSinPhi );
-  GPUd() Int_t TransportToX( Float_t X, AliHLTTPCCATrackParam &t0, Float_t maxSinPhi );
+  GPUd() Bool_t TransportToX( Float_t x, Float_t Bz, Float_t maxSinPhi=.999 );
+  GPUd() Bool_t TransportToXWithMaterial( Float_t x, Float_t Bz, Float_t maxSinPhi=.999 );
+
+  GPUd() Bool_t  TransportToX( Float_t x, AliHLTTPCCATrackLinearisation &t0, 
+                              Float_t Bz,  Float_t maxSinPhi=.999, Float_t *DL=0 ); 
+
+  GPUd() Bool_t  TransportToX( Float_t x, Float_t sinPhi0, Float_t cosPhi0,  Float_t Bz, Float_t maxSinPhi=.999 );
 
-  GPUd() Bool_t TransportToXWithMaterial( Float_t X, AliHLTTPCCATrackFitParam &par );
-  GPUd() Bool_t TransportToXWithMaterial( Float_t X, AliHLTTPCCATrackParam &t0, AliHLTTPCCATrackFitParam &par );
-  GPUd() Bool_t TransportToXWithMaterial( Float_t X, Float_t Bz );
-  GPUd() Bool_t Rotate( Float_t alpha, Float_t maxSinPhi=.99 );
-  GPUd() Bool_t RotateNoCos( Float_t alpha, AliHLTTPCCATrackParam &t0, Float_t maxSinPhi=.99 );
+  GPUd() Bool_t  TransportToXWithMaterial( Float_t x,  AliHLTTPCCATrackLinearisation &t0, 
+                                          AliHLTTPCCATrackFitParam &par, Float_t Bz, Float_t maxSinPhi=.999 );
 
-  GPUd() Bool_t Filter2( Float_t y, Float_t z, Float_t err2Y, Float_t err2Z, Float_t maxSinPhi=.99 );
-  GPUd() Bool_t Filter2NoCos( Float_t y, Float_t z, Float_t err2Y, Float_t err2Z );
+  GPUd() Bool_t  TransportToXWithMaterial( Float_t x, 
+                                          AliHLTTPCCATrackFitParam &par, Float_t Bz, Float_t maxSinPhi=.999 );
 
-  GPUd() Int_t TransportToX0( Float_t X, Float_t sinPhi, Float_t cosPhi );
-  GPUd() Int_t TransportToX0( Float_t X, Float_t maxSinPhi );
-  GPUd() Bool_t Filter20( Float_t y, Float_t z, Float_t err2Y, Float_t err2Z, Float_t maxSinPhi=.99 );
-  GPUd() Bool_t Filter200( Float_t y, Float_t z, Float_t err2Y, Float_t err2Z );
 
-  GPUd() Bool_t Filter2v1( Float_t y, Float_t z, Float_t err2Y, Float_t err2Z, Float_t maxSinPhi=.99 );
-  GPUd() void FilterY( Float_t y, Float_t erry );
-  GPUd() void FilterZ( Float_t z, Float_t errz );
 
   GPUd() static Float_t ApproximateBetheBloch( Float_t beta2 );
-  GPUd() void CalculateFitParameters( AliHLTTPCCATrackFitParam &par, Float_t Bz, Float_t mass = 0.13957 );
+  GPUd() static Float_t BetheBlochGeant(Float_t bg,
+                                       Float_t kp0=2.33,
+                                       Float_t kp1=0.20,
+                                       Float_t kp2=3.00,
+                                       Float_t kp3=173e-9,
+                                       Float_t kp4=0.49848
+                                       );    
+  GPUd() static Float_t BetheBlochSolid(Float_t bg);
+  GPUd() static Float_t BetheBlochGas(Float_t bg);
+
+
+  GPUd() void CalculateFitParameters( AliHLTTPCCATrackFitParam &par, Float_t mass= 0.13957 );
   GPUd() Bool_t CorrectForMeanMaterial( Float_t xOverX0,  Float_t xTimesRho, const AliHLTTPCCATrackFitParam &par );
+
+  GPUd() Bool_t Rotate( Float_t alpha, Float_t maxSinPhi = .999 );
+  GPUd() Bool_t Rotate( Float_t alpha, AliHLTTPCCATrackLinearisation &t0, Float_t maxSinPhi=.999 );
+  GPUd() Bool_t Filter( Float_t y, Float_t z, Float_t err2Y, Float_t err2Z, Float_t maxSinPhi=.999 );
+
+
   GPUd() void Print() const;
 
 private:
 
   Float_t fX;      // x position
-  Float_t fCosPhi; // cosPhi
-  Float_t fP[5];   // 'active' track parameters: Y, Z, SinPhi, DzDs, Kappa
+  Float_t fSignCosPhi; // sign of cosPhi
+  Float_t fP[5];   // 'active' track parameters: Y, Z, SinPhi, DzDs, q/Pt
   Float_t fC[15];  // the covariance matrix for Y,Z,SinPhi,..
   Float_t fChi2;   // the chi^2 value
   Int_t   fNDF;    // the Number of Degrees of Freedom
 };
 
-
 #endif
index 05ae8b9b7cb5b88a3f4cbca14a83eafff7bff6a9..8b80c9fcb0c9f07a20d555a13ed07ab10f37b3ed 100644 (file)
@@ -230,7 +230,7 @@ GPUhd() void  AliHLTTPCCATracker::SetPointersHits( Int_t MaxNHits )
 
   mem = ( mem/s4 + 1 )*s4;
   fInputEvent = (Char_t*) mem;  
-  fInputEventSize = (1+fParam.NRows()*2 + 1)*sI + (MaxNHits*2)*sF;
+  fInputEventSize = (1+fParam.NRows()*2 + 1)*sI + (MaxNHits*3)*sF;
   mem+= fInputEventSize;
 
   // set cluster data for TPC rows
@@ -309,7 +309,7 @@ GPUhd() void  AliHLTTPCCATracker::SetPointersTracks( Int_t MaxNTracks, Int_t Max
 
 
 
-GPUd() void AliHLTTPCCATracker::ReadEvent( const Int_t *RowFirstHit, const Int_t *RowNHits, const Float_t *Y, const Float_t *Z, Int_t NHits )
+GPUd() void AliHLTTPCCATracker::ReadEvent( const Int_t *RowFirstHit, const Int_t *RowNHits, const Float_t *X, const Float_t *Y, const Float_t *Z, Int_t NHits )
 {
   //* Read event
 
@@ -330,14 +330,15 @@ GPUd() void AliHLTTPCCATracker::ReadEvent( const Int_t *RowFirstHit, const Int_t
   reinterpret_cast<Int_t*>( fInputEvent )[0] = fParam.NRows();
   reinterpret_cast<Int_t*>( fInputEvent )[1+fParam.NRows()*2] = NHits;
   Int_t *rowHeaders = reinterpret_cast<Int_t*>( fInputEvent ) +1;
-  Float_t *hitsYZ = reinterpret_cast<Float_t*>( fInputEvent ) + 1+fParam.NRows()*2+1;
+  Float_t *hitsXYZ = reinterpret_cast<Float_t*>( fInputEvent ) + 1+fParam.NRows()*2+1;
   for( Int_t iRow=0; iRow<fParam.NRows(); iRow++ ){
     rowHeaders[iRow*2  ] = RowFirstHit[iRow];
     rowHeaders[iRow*2+1] = RowNHits[iRow];
   }
   for( Int_t iHit=0; iHit<NHits; iHit++ ){
-    hitsYZ[iHit*2  ] = Y[iHit];
-    hitsYZ[iHit*2+1] = Z[iHit];
+    hitsXYZ[iHit*3  ] = X[iHit];
+    hitsXYZ[iHit*3+1] = Y[iHit];
+    hitsXYZ[iHit*3+2] = Z[iHit];
   }
 
   //SG cell finder - test code
@@ -357,8 +358,10 @@ GPUd() void AliHLTTPCCATracker::ReadEvent( const Int_t *RowFirstHit, const Int_t
     Int_t oldRowLastHit = oldRowFirstHit + RowNHits[iRow];
     for( Int_t iHit=oldRowFirstHit; iHit<oldRowLastHit; iHit++ ){
       if( usedHits[iHit] ) continue;
+      Float_t x0 = X[iHit];
       Float_t y0 = Y[iHit];
       Float_t z0 = Z[iHit];
+      Float_t cx = x0;
       Float_t cy = y0;
       Float_t cz = z0;
       Int_t nclu = 1;
@@ -368,6 +371,7 @@ GPUd() void AliHLTTPCCATracker::ReadEvent( const Int_t *RowFirstHit, const Int_t
        Float_t dy = Y[jHit] - y0;
        Float_t dz = Z[jHit] - z0;
        if( CAMath::Abs(dy)<areaY && CAMath::Abs(dz)<areaZ ){
+         cx+=X[jHit];
          cy+=Y[jHit];
          cz+=Z[jHit];
          nclu++;
@@ -375,8 +379,9 @@ GPUd() void AliHLTTPCCATracker::ReadEvent( const Int_t *RowFirstHit, const Int_t
        }
       }
       Int_t id = newRowNHitsTotal+newRowNHits;
-      hitsYZ[id*2  ] = cy/nclu;
-      hitsYZ[id*2+1] = cz/nclu;
+      hitsXYZ[id*3+0 ] = cx/nclu;
+      hitsXYZ[id*3+1 ] = cy/nclu;
+      hitsXYZ[id*3+2 ] = cz/nclu;
       fTmpHitInputIDs[id] = iHit;
       newRowNHits++;
     }
@@ -394,10 +399,10 @@ GPUd() void AliHLTTPCCATracker::ReadEvent( const Int_t *RowFirstHit, const Int_t
 GPUd() void AliHLTTPCCATracker::SetupRowData()
 {
   //* Convert input hits, create grids, etc.
-
+  
   fNHitsTotal = reinterpret_cast<Int_t*>( fInputEvent )[1+fParam.NRows()*2];
   Int_t *rowHeaders = reinterpret_cast<Int_t*>( fInputEvent ) +1;
-  Float_t *hitsYZ = reinterpret_cast<Float_t*>( fInputEvent ) + 1+fParam.NRows()*2+1;
+  Float_t *hitsXYZ = reinterpret_cast<Float_t*>( fInputEvent ) + 1+fParam.NRows()*2+1;
 
   for( Int_t iRow=0; iRow<fParam.NRows(); iRow++ ){
     
@@ -408,8 +413,8 @@ GPUd() void AliHLTTPCCATracker::SetupRowData()
     Int_t nGrid =  row.NHits();
     for( Int_t i=0; i<row.NHits(); i++ ){
       Int_t j = row.FirstHit()+i;
-      Float_t y = hitsYZ[j*2];
-      Float_t z = hitsYZ[j*2+1];
+      Float_t y = hitsXYZ[j*3+1];
+      Float_t z = hitsXYZ[j*3+2];
       if( yMax < y ) yMax = y;
       if( yMin > y ) yMin = y;
       if( zMax < z ) zMax = z;
@@ -456,7 +461,7 @@ GPUd() void AliHLTTPCCATracker::SetupRowData()
 
     for( Int_t i=0; i<row.NHits(); i++ ){
       Int_t j = row.FirstHit()+i;
-      Int_t bin = row.Grid().GetBin( hitsYZ[2*j], hitsYZ[2*j+1] );
+      Int_t bin = row.Grid().GetBin( hitsXYZ[3*j+1], hitsXYZ[3*j+2] );
       bins[i] = bin;
       filled[bin]++;
     }
@@ -475,8 +480,8 @@ GPUd() void AliHLTTPCCATracker::SetupRowData()
 
      AliHLTTPCCAHit &h = ffHits[row.FirstHit()+ind];
       fHitInputIDs[row.FirstHit()+ind] = fTmpHitInputIDs[row.FirstHit()+i];
-      h.SetY( hitsYZ[2*(row.FirstHit()+i)] );
-      h.SetZ( hitsYZ[2*(row.FirstHit()+i)+1] );
+      h.SetY( hitsXYZ[3*(row.FirstHit()+i)+1] );
+      h.SetZ( hitsXYZ[3*(row.FirstHit()+i)+2] );
       filled[bin]--;
     }
 
@@ -579,7 +584,7 @@ GPUh() void AliHLTTPCCATracker::Reconstruct()
   AliHLTTPCCADisplay::Instance().SetCurrentSlice( this );
   AliHLTTPCCADisplay::Instance().DrawSlice( this, 1 );  
   if( fNHitsTotal>0 ){
-    AliHLTTPCCADisplay::Instance().DrawSliceHits( kRed, 1.);  
+    AliHLTTPCCADisplay::Instance().DrawSliceHits( kRed, .5);  
     AliHLTTPCCADisplay::Instance().Ask();
   }
 #endif
@@ -721,6 +726,8 @@ GPUh() void AliHLTTPCCATracker::WriteOutput()
   fOutput->SetNTrackClusters( *fNTrackHits );
   fOutput->SetPointers();
 
+  Float_t *hitsXYZ = reinterpret_cast<Float_t*>( fInputEvent ) + 1+fParam.NRows()*2+1;
+
   Int_t nStoredHits = 0;
 
   for( Int_t iTr=0; iTr<*fNTracks; iTr++){
@@ -738,33 +745,39 @@ GPUh() void AliHLTTPCCATracker::WriteOutput()
       Int_t ic = (fTrackHits[iID+ith]);
       Int_t iRow = ID2IRow(ic);
       Int_t ih = ID2IHit(ic);
+
       const AliHLTTPCCARow &row = fRows[iRow];      
   
-      Float_t y0 = row.Grid().YMin();
-      Float_t z0 = row.Grid().ZMin();
-      Float_t stepY = row.HstepY();
-      Float_t stepZ = row.HstepZ();      
+      //Float_t y0 = row.Grid().YMin();
+      //Float_t z0 = row.Grid().ZMin();
+      //Float_t stepY = row.HstepY();
+      //Float_t stepZ = row.HstepZ();      
       //Float_t x = row.X();
 
-      const uint4 *tmpint4 = RowData() + row.FullOffset();
-      const ushort2 *hits = reinterpret_cast<const ushort2*>(tmpint4);
-      ushort2 hh = hits[ih];
-
-      Float_t y = y0 + hh.x*stepY;
-      Float_t z = z0 + hh.y*stepZ;
+      //const uint4 *tmpint4 = RowData() + row.FullOffset();
+      //const ushort2 *hits = reinterpret_cast<const ushort2*>(tmpint4);
+      //ushort2 hh = hits[ih];
+      //Float_t y = y0 + hh.x*stepY;
+      //Float_t z = z0 + hh.y*stepZ;
 
       Int_t inpIDtot = fHitInputIDs[row.FirstHit()+ih];
       Int_t inpID = inpIDtot - row.FirstHit();
 
+      float origX = hitsXYZ[inpIDtot*3+0];
+      float origY = hitsXYZ[inpIDtot*3+1];
+      float origZ = hitsXYZ[inpIDtot*3+2];
+
       UInt_t hIDrc = AliHLTTPCCADataCompressor::IRowIClu2IDrc(iRow,inpID);
       UShort_t hPackedYZ = 0;
       UChar_t hPackedAmp = 0;
-      float2 hUnpackedYZ = CAMath::MakeFloat2(y,z);
-      
+      float2 hUnpackedYZ = CAMath::MakeFloat2(origY,origZ);
+      float hUnpackedX = origX;
+
       fOutput->SetClusterIDrc( nStoredHits, hIDrc  );
       fOutput->SetClusterPackedYZ( nStoredHits, hPackedYZ );
       fOutput->SetClusterPackedAmp( nStoredHits, hPackedAmp);
       fOutput->SetClusterUnpackedYZ( nStoredHits, hUnpackedYZ );
+      fOutput->SetClusterUnpackedX( nStoredHits, hUnpackedX );
       nStoredHits++;
     }
   }
@@ -959,7 +972,7 @@ GPUd() void AliHLTTPCCATracker::GetErrors2( Int_t iRow, const AliHLTTPCCATrackPa
   // Use calibrated cluster error from OCDB
   //
 
-  fParam.GetClusterErrors2( iRow, t.GetZ(), t.SinPhi(), t.CosPhi(), t.DzDs(), Err2Y, Err2Z );
+  fParam.GetClusterErrors2( iRow, t.GetZ(), t.SinPhi(), t.GetCosPhi(), t.DzDs(), Err2Y, Err2Z );
 }
 
 
@@ -1017,7 +1030,7 @@ GPUh() void AliHLTTPCCATracker::ReadEvent( std::istream &in )
   for( Int_t ih=0; ih<nHits; ih++ ){
     in>>y[ih]>>z[ih];
   }
-  ReadEvent( rowFirstHit, rowNHits, y, z, nHits );
+  //ReadEvent( rowFirstHit, rowNHits, y, z, nHits );
   if( rowFirstHit ) delete[] rowFirstHit;
   if( rowNHits )delete[] rowNHits;
   if( y )delete[] y;
@@ -1027,7 +1040,7 @@ GPUh() void AliHLTTPCCATracker::ReadEvent( std::istream &in )
 GPUh() void AliHLTTPCCATracker::WriteTracks( std::ostream &out ) 
 {
   //* Write tracks to file 
+   
   out<<fTimers[0]<<std::endl;
   out<<*fNOutTrackHits<<std::endl;
   for( Int_t ih=0; ih<*fNOutTrackHits; ih++ ){
@@ -1046,7 +1059,7 @@ GPUh() void AliHLTTPCCATracker::WriteTracks( std::ostream &out )
     out<< t.OrigTrackID()<<" ";
     out<<std::endl;
     out<< p1.X()<<" ";
-    out<< p1.CosPhi()<<" ";
+    out<< p1.SignCosPhi()<<" ";
     out<< p1.Chi2()<<" ";
     out<< p1.NDF()<<std::endl;
     for( Int_t i=0; i<5; i++ ) out<<p1.Par()[i]<<" ";
@@ -1054,7 +1067,7 @@ GPUh() void AliHLTTPCCATracker::WriteTracks( std::ostream &out )
     for( Int_t i=0; i<15; i++ ) out<<p1.Cov()[i]<<" ";
     out<<std::endl;
     out<< p2.X()<<" ";
-    out<< p2.CosPhi()<<" ";
+    out<< p2.SignCosPhi()<<" ";
     out<< p2.Chi2()<<" ";
     out<< p2.NDF()<<std::endl;
     for( Int_t i=0; i<5; i++ ) out<<p2.Par()[i]<<" ";
@@ -1084,13 +1097,13 @@ GPUh() void AliHLTTPCCATracker::ReadTracks( std::istream &in )
     in>> i; t.SetFirstHitRef( i );
     in>> i; t.SetOrigTrackID( i );
     in>> f; p1.SetX( f );
-    in>> f; p1.SetCosPhi( f );
+    in>> f; p1.SetSignCosPhi( f );
     in>> f; p1.SetChi2( f );
     in>> i; p1.SetNDF( i );
     for( Int_t j=0; j<5; j++ ){ in>>f; p1.SetPar(j,f); }
     for( Int_t j=0; j<15; j++ ){ in>>f; p1.SetCov(j,f); }
     in>> f; p2.SetX( f );
-    in>> f; p2.SetCosPhi( f );
+    in>> f; p2.SetSignCosPhi( f );
     in>> f; p2.SetChi2( f );
     in>> i; p2.SetNDF( i );
     for( Int_t j=0; j<5; j++ ){ in>>f; p2.SetPar(j,f); }
index c686ad638e96b38d9ac70357e3d65046d5107cce..4fdd8aee7795cc63b0078ca0ad754b492cd1d24b 100644 (file)
@@ -51,7 +51,7 @@ class AliHLTTPCCATracker
 
   GPUd() void StartEvent();
 
-  GPUd() void ReadEvent( const Int_t *RowFirstHit, const Int_t *RowNHits, const Float_t *Y, const Float_t *Z, Int_t NHits );
+  GPUd() void ReadEvent( const Int_t *RowFirstHit, const Int_t *RowNHits, const Float_t *X, const Float_t *Y, const Float_t *Z, Int_t NHits );
 
   GPUd() void SetupRowData();
 
index b8b699eb267e45265b0073ce4e815c3ba58f28bd..425680ee10f0d06af50d55723187443d5af8780c 100644 (file)
@@ -536,13 +536,13 @@ Int_t AliHLTTPCCATrackerComponent::DoEvent
       
       if( TMath::Abs(pSP->fZ)>fClusterZCut) continue;
       
-      vHitStoreX[nHits] = pSP->fX;  
+      vHitStoreX[nHits] = pSP->fX;
       vHitStoreY[nHits] = pSP->fY;
       vHitStoreZ[nHits] = pSP->fZ;
       vHitStoreIntID[nHits] = nHits;
       vHitStoreID[nHits] = pSP->fID;
       vHitRowID[nHits] = pSP->fPadRow;
-      nHits++; 
+      nHits++;
       rowNHits[pSP->fPadRow]++;
     }  
 
@@ -552,7 +552,7 @@ Int_t AliHLTTPCCATrackerComponent::DoEvent
       firstRowHit+=rowNHits[ir];
     }
 
-    fTracker->ReadEvent( rowFirstHits, rowNHits, vHitStoreY, vHitStoreZ, nHits );
+    fTracker->ReadEvent( rowFirstHits, rowNHits, vHitStoreX, vHitStoreY, vHitStoreZ, nHits );
   }
 
   if( vOrigClusters ) delete[] vOrigClusters;
@@ -623,7 +623,7 @@ Int_t AliHLTTPCCATrackerComponent::DoEvent
       par.TransportToX( vHitStoreX[iFirstHit], .99 );
       
       AliExternalTrackParam tp;
-      AliHLTTPCCATrackConvertor::GetExtParam( par, tp, 0, fSolenoidBz );
+      AliHLTTPCCATrackConvertor::GetExtParam( par, tp, 0 );
       
       currOutTracklet->fX = tp.GetX();
       currOutTracklet->fY = tp.GetY();
@@ -718,7 +718,7 @@ Int_t AliHLTTPCCATrackerComponent::DoEvent
   // Set log level to "Warning" for on-line system monitoring
   Int_t hz = (Int_t) (fFullTime>1.e-10 ?fNEvents/fFullTime :100000);
   Int_t hz1 = (Int_t) (fRecoTime>1.e-10 ?fNEvents/fRecoTime :100000);
-  HLTInfo( "CATracker slice %d: output %d tracks;  input %d clusters, patches %d..%d, rows %d..%d; reco time %d/%d Hz", 
+  HLTWarning( "CATracker slice %d: output %d tracks;  input %d clusters, patches %d..%d, rows %d..%d; reco time %d/%d Hz", 
            slice, ntracks, nClusters, minPatch, maxPatch, row[0], row[1], hz, hz1 );
 
   return ret;
index b7ccb9c2587f72893c3b4d45b061e83f56a6c939..c62488ea15e42c0a695663641be0b21b3b4ac08b 100644 (file)
@@ -93,8 +93,8 @@ GPUd() void AliHLTTPCCATrackletConstructor::Step1
   CAMath::AtomicMax( &s.fMaxStartRow32[kThread], r.fStartRow);    
   tParam.SetSinPhi(0);
   tParam.SetDzDs(0);
-  tParam.SetKappa(0);
-  tParam.SetCosPhi(1);
+  tParam.SetQPt(0);
+  tParam.SetSignCosPhi(1);
   tParam.SetChi2(0);
   tParam.SetNDF(-3);
   tParam.SetCov( 0,1); 
@@ -111,7 +111,7 @@ GPUd() void AliHLTTPCCATrackletConstructor::Step1
   tParam.SetCov(11,0); 
   tParam.SetCov(12,0); 
   tParam.SetCov(13,0); 
-  tParam.SetCov(14,1);     
+  tParam.SetCov(14,10.);     
 
 }
 
@@ -171,13 +171,8 @@ GPUd() void AliHLTTPCCATrackletConstructor::StoreTracklet
       break;
     }
 
-    if(0){ // kappa => 1/pt
-      const Double_t kCLight = 0.000299792458;  
-      Double_t bz = tracker.Param().Bz();
-      Double_t c = 1.e4;
-      if( CAMath::Abs(bz)>1.e-4 ) c = 1./(bz*kCLight);
-      Double_t pti = tParam.Kappa()*c;
-      if( 1./.5 < CAMath::Abs(pti) ){ //SG!!!
+    if(0){ 
+      if( 1./.5 < CAMath::Abs(tParam.QPt()) ){ //SG!!!
        r.fNHits = 0;
        break;
       }
@@ -236,9 +231,9 @@ GPUd() void AliHLTTPCCATrackletConstructor::UpdateTracklet
   // reconstruction of tracklets, tracklets update step
 
   //std::cout<<"Update tracklet: "<<r.fItr<<" "<<r.fGo<<" "<<r.fStage<<" "<<iRow<<std::endl;
-  Bool_t drawSearch = 0;//r.fItr==356;
-  Bool_t drawFit = 0;//r.fItr==356;
-  Bool_t drawFitted = 0;//drawFit ;//|| 1;//r.fItr==16;
+  Bool_t drawSearch = 0;//r.fItr==2;
+  Bool_t drawFit = 0;//r.fItr==2;
+  Bool_t drawFitted = drawFit ;//|| 1;//r.fItr==16;
 
   if( !r.fGo ) return;
 
@@ -294,9 +289,11 @@ GPUd() void AliHLTTPCCATrackletConstructor::UpdateTracklet
        Float_t ri = 1./CAMath::Sqrt(dx*dx+dy*dy);
        if( iRow==r.fStartRow+1 ){
          tParam.SetSinPhi( dy*ri );
-         tParam.SetCosPhi( dx*ri );
+         tParam.SetSignCosPhi( dx );
          tParam.SetDzDs( dz*ri );
+         std::cout<<"Init. errors... "<<r.fItr<<std::endl;
          tracker.GetErrors2( iRow, tParam, err2Y, err2Z );
+         std::cout<<"Init. errors = "<<err2Y<<" "<<err2Z<<std::endl;
          tParam.SetCov( 0, err2Y );
          tParam.SetCov( 2, err2Z );
        }
@@ -318,15 +315,17 @@ GPUd() void AliHLTTPCCATrackletConstructor::UpdateTracklet
        //#ifdef DRAW
        if( drawFit ) std::cout<<"sinPhi0 = "<<sinPhi<<", cosPhi0 = "<<cosPhi<<std::endl;
        //#endif
-       if( !tParam.TransportToX0( x, sinPhi, cosPhi ) ){ 
+       if( !tParam.TransportToX( x, sinPhi, cosPhi, tracker.Param().Bz(),-1 ) ){ 
          //#ifdef DRAW
          if( drawFit ) std::cout<<" tracklet "<<r.fItr<<", row "<<iRow<<": can not transport!!"<<std::endl;
 //#endif
          if( SAVE() ) tracklet.SetRowHit( iRow, -1 );
          break; 
        }
-               
+       //std::cout<<"mark1 "<<r.fItr<<std::endl;
+       //tParam.Print();
        tracker.GetErrors2( iRow, tParam.GetZ(), sinPhi, cosPhi, tParam.GetDzDs(), err2Y, err2Z );
+       //std::cout<<"mark2"<<std::endl;
        
        if( drawFit ){
          //#ifdef DRAW
@@ -339,7 +338,7 @@ GPUd() void AliHLTTPCCATrackletConstructor::UpdateTracklet
          AliHLTTPCCADisplay::Instance().Ask();
 #endif
        }
-       if( !tParam.Filter200( y, z, err2Y, err2Z ) ) { 
+       if( !tParam.Filter( y, z, err2Y, err2Z, .99 ) ) { 
          //#ifdef DRAW
          if( drawFit ) std::cout<<" tracklet "<<r.fItr<<", row "<<iRow<<": can not filter!!"<<std::endl;
          //#endif
@@ -377,7 +376,7 @@ GPUd() void AliHLTTPCCATrackletConstructor::UpdateTracklet
        //#endif
        r.fNHits=0; r.fGo = 0;
       }else{
-       tParam.SetCosPhi( CAMath::Sqrt(1-tParam.SinPhi()*tParam.SinPhi()) );
+       //tParam.SetCosPhi( CAMath::Sqrt(1-tParam.SinPhi()*tParam.SinPhi()) );
       }
       if( drawFitted ){
        //#ifdef DRAW
@@ -416,7 +415,7 @@ GPUd() void AliHLTTPCCATrackletConstructor::UpdateTracklet
          tParam.Print();
          //#endif
        }
-       if( !tParam.TransportToX0( x, .999 ) ){
+       if( !tParam.TransportToX( x, tParam.SinPhi(), tParam.GetCosPhi(), tracker.Param().Bz(), .99 ) ){
          //#ifdef DRAW
          if( drawSearch ) std::cout<<" tracklet "<<r.fItr<<", row "<<iRow<<": can not transport!!"<<std::endl;
          //#endif
@@ -541,9 +540,12 @@ GPUd() void AliHLTTPCCATrackletConstructor::UpdateTracklet
        }
 
        ushort2 hh = hits[best];
-       
+
+       //std::cout<<"mark 3, "<<r.fItr<<std::endl;
+       //tParam.Print();
        tracker.GetErrors2( iRow, *((AliHLTTPCCATrackParam*)&tParam), err2Y, err2Z );
-       
+       //std::cout<<"mark 4"<<std::endl;
+
        Float_t y = y0 + hh.x*stepY;
        Float_t z = z0 + hh.y*stepZ;
        Float_t dy = y - fY;
@@ -576,7 +578,7 @@ GPUd() void AliHLTTPCCATrackletConstructor::UpdateTracklet
        //AliHLTTPCCADisplay::Instance().DrawTracklet(tParam, hitstore, kBlue);  
        //AliHLTTPCCADisplay::Instance().Ask();
 #endif
-       if( !tParam.Filter2( y, z, err2Y, err2Z, .999 ) ){
+       if( !tParam.Filter( y, z, err2Y, err2Z, .99 ) ){
          if( drawSearch ){
            //#ifdef DRAW
            std::cout<<"tracklet "<<r.fItr<<" at row "<<iRow<<" : can not filter!!!! "<<std::endl;
@@ -643,7 +645,7 @@ GPUd() void AliHLTTPCCATrackletConstructor::Thread
       if( r.fGo ){
        const AliHLTTPCCARow &row = tracker.Row(r.fEndRow);     
        Float_t x = row.X();
-       if( !tParam.TransportToX( x, .999 ) ) r.fGo = 0;
+       if( !tParam.TransportToX( x, tracker.Param().Bz(),.999 ) ) r.fGo = 0;
       }
     }
   
index d002f10d86258c430f01b166aef8cbf329c9a5fe..4cc920dcfcad4a91ab6fa83cc6bd9815bb7da7f3 100644 (file)
@@ -63,14 +63,8 @@ GPUd() void AliHLTTPCCATrackletSelector::Thread
 
        tout.SetNHits( 0 );
        Int_t kind = 0;
-       if(0){ // kappa => 1/pt
-         const AliHLTTPCCATrackParam &tParam = tracklet.Param();
-         const Double_t kCLight = 0.000299792458;  
-         Double_t bz = tracker.Param().Bz();
-         Double_t c = 1.e4;
-         if( CAMath::Abs(bz)>1.e-4 ) c = 1./(bz*kCLight);
-         Double_t pti = tParam.Kappa()*c;
-         if( tNHits>=10 && 1./.5 >= CAMath::Abs(pti) ){ //SG!!!
+       if(0){ 
+         if( tNHits>=10 && 1./.5 >= CAMath::Abs(tracklet.Param().QPt()) ){ //SG!!!
            kind = 1;
          }    
        }
index 9118004b0dd5337bd9e17daff64de2c5de388df5..88a7f981b019c38107765b153ae487c7be0b5d1c 100644 (file)
@@ -50,6 +50,7 @@
 #include "AliESDEvent.h"
 #include "AliTrackReference.h"
 #include "TStopwatch.h"
+#include "AliTPCReconstructor.h"
 
 //#include <fstream.h>
 
@@ -99,8 +100,10 @@ AliTPCtrackerCA::AliTPCtrackerCA(const AliTPCParam *par):
   }
 
   for( Int_t iSlice=0; iSlice<fHLTTracker->NSlices(); iSlice++ ){
-  
-    Float_t bz = AliTracker::GetBz();
+
+    const Double_t kCLight = 0.000299792458;
+
+    Float_t bz = AliTracker::GetBz()*kCLight;
 
     Float_t inRmin = fkParam->GetInnerRadiusLow();
     //Float_t inRmax = fkParam->GetInnerRadiusUp();
@@ -318,6 +321,7 @@ Int_t AliTPCtrackerCA::LoadClusters (TTree * fromTree)
       cluster->SetY(posC[1]);
       cluster->SetZ(posC[2]);
 
+      x = cluster->GetX();
       Float_t y = cluster->GetY();
       Float_t z = cluster->GetZ();        
 
@@ -398,14 +402,12 @@ 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;
       AliTPCseed tTPC;
       AliHLTTPCCAGBTrack &tCA = fHLTTracker->Tracks()[itr];
       AliHLTTPCCATrackParam par = tCA.Param(); 
-      AliHLTTPCCATrackConvertor::GetExtParam( par, tTPC, tCA.Alpha(), bz );
+      AliHLTTPCCATrackConvertor::GetExtParam( par, tTPC, tCA.Alpha() );
       tTPC.SetMass(0.13957);
       tTPC.SetdEdx( tCA.DeDx() );
       if( TMath::Abs(tTPC.GetSigned1Pt())>1./0.02 ) continue;
@@ -426,31 +428,44 @@ Int_t AliTPCtrackerCA::Clusters2Tracks( AliESDEvent *event )
        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, .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()));  
+       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);          
 
+      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 );
@@ -481,7 +496,7 @@ Int_t AliTPCtrackerCA::RefitInward (AliESDEvent *event)
 { 
   //* forward propagation of ESD tracks 
 
-  Float_t bz = fHLTTracker->Slices()[0].Param().Bz();
+  //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.); 
@@ -493,10 +508,10 @@ Int_t AliTPCtrackerCA::RefitInward (AliESDEvent *event)
     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();
-    Float_t dEdX=0;    
+    //Float_t dEdX=0;    
     Int_t hits[1000];
     Int_t nHits = esd->GetTPCclusters(hits);
     
@@ -504,24 +519,24 @@ Int_t AliTPCtrackerCA::RefitInward (AliESDEvent *event)
 
     for( Int_t i=0; i<nHits; i++ ) hits[i] = fHLTTracker->Ext2IntHitID(hits[i]);
    
-    Bool_t ok = fHLTTracker->FitTrack( t, t0, alpha, hits, nHits, dEdX, 0 );
+    Bool_t ok = fHLTTracker->FitTrack( t, t0, alpha, hits, nHits, 0 );
     if( ok &&  nHits>15){
-      if( t.TransportToXWithMaterial( xTPC, bz) ){
+      if( t.TransportToXWithMaterial( xTPC, fHLTTracker->Slices()[0].Param().GetBz(t)) ){
        if (t.GetY() > yMax) {
          if (t.Rotate(dAlpha)){ 
            alpha+=dAlpha;  
-           t.TransportToXWithMaterial( xTPC, bz);
+           t.TransportToXWithMaterial( xTPC, fHLTTracker->Slices()[0].Param().GetBz(t));
          }
        } else if (t.GetY() <-yMax) {
          if (t.Rotate(-dAlpha)){
            alpha+=-dAlpha;
-           t.TransportToXWithMaterial( xTPC, bz);
+           t.TransportToXWithMaterial( xTPC, fHLTTracker->Slices()[0].Param().GetBz(t));
          }
        }    
       }
     
       AliTPCtrack tt(*esd);
-      AliHLTTPCCATrackConvertor::GetExtParam(t,tt,alpha,bz);
+      AliHLTTPCCATrackConvertor::GetExtParam(t,tt,alpha );
       esd->UpdateTrackParams( &tt,AliESDtrack::kTPCrefit); 
     }
   }
@@ -533,7 +548,7 @@ Int_t AliTPCtrackerCA::PropagateBack(AliESDEvent *event)
 
   //* backward propagation of ESD tracks 
 
-  Float_t bz = fHLTTracker->Slices()[0].Param().Bz();
+  //Float_t bz = fHLTTracker->Slices()[0].Param().Bz();
   Int_t nentr=event->GetNumberOfTracks();
      
   for (Int_t itr=0; itr<nentr; itr++) {
@@ -543,10 +558,10 @@ Int_t AliTPCtrackerCA::PropagateBack(AliESDEvent *event)
     if (!(status&AliESDtrack::kTPCin)) continue;
 
     AliHLTTPCCATrackParam t0;
-    AliHLTTPCCATrackConvertor::SetExtParam(t0,*esd, bz );
+    AliHLTTPCCATrackConvertor::SetExtParam(t0,*esd  );
     AliHLTTPCCATrackParam t = t0;
     Float_t alpha = esd->GetAlpha();
-    Float_t dEdX=0;    
+    //Float_t dEdX=0;    
     Int_t hits[1000];
     Int_t nHits = esd->GetTPCclusters(hits);
     
@@ -554,10 +569,10 @@ Int_t AliTPCtrackerCA::PropagateBack(AliESDEvent *event)
 
     for( Int_t i=0; i<nHits; i++ ) hits[i] = fHLTTracker->Ext2IntHitID(hits[i]);
    
-    Bool_t ok = fHLTTracker->FitTrack( t, t0, alpha, hits, nHits, dEdX, 1 );
+    Bool_t ok = fHLTTracker->FitTrack( t, t0, alpha, hits, nHits, 1 );
     if( ok &&  nHits>15){
       AliTPCtrack tt(*esd);
-      AliHLTTPCCATrackConvertor::GetExtParam(t,tt,alpha,bz);
+      AliHLTTPCCATrackConvertor::GetExtParam(t,tt,alpha );
       esd->UpdateTrackParams( &tt,AliESDtrack::kTPCout); 
     }
   }