]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
Completely reworked version of TPC CA tracker (Sergey)
authorrichterm <richterm@f7af4fe6-9843-0410-8265-dc069ae4e863>
Tue, 13 Jan 2009 14:37:57 +0000 (14:37 +0000)
committerrichterm <richterm@f7af4fe6-9843-0410-8265-dc069ae4e863>
Tue, 13 Jan 2009 14:37:57 +0000 (14:37 +0000)
!!! Note: the ca tracking has been disabled for the moment due
to various compilation problems. Will be corrected soon.

59 files changed:
HLT/TPCLib/AliHLTTPCAgent.cxx
HLT/TPCLib/tracking-ca/AliHLTTPCCACell.h [deleted file]
HLT/TPCLib/tracking-ca/AliHLTTPCCADef.h [new file with mode: 0644]
HLT/TPCLib/tracking-ca/AliHLTTPCCADisplay.cxx
HLT/TPCLib/tracking-ca/AliHLTTPCCADisplay.h
HLT/TPCLib/tracking-ca/AliHLTTPCCAEndPoint.h [deleted file]
HLT/TPCLib/tracking-ca/AliHLTTPCCAGBHit.h
HLT/TPCLib/tracking-ca/AliHLTTPCCAGBTrack.h
HLT/TPCLib/tracking-ca/AliHLTTPCCAGBTracker.cxx
HLT/TPCLib/tracking-ca/AliHLTTPCCAGBTracker.h
HLT/TPCLib/tracking-ca/AliHLTTPCCAGrid.cxx
HLT/TPCLib/tracking-ca/AliHLTTPCCAGrid.h
HLT/TPCLib/tracking-ca/AliHLTTPCCAHit.h
HLT/TPCLib/tracking-ca/AliHLTTPCCAHitArea.cxx [new file with mode: 0644]
HLT/TPCLib/tracking-ca/AliHLTTPCCAHitArea.h [new file with mode: 0644]
HLT/TPCLib/tracking-ca/AliHLTTPCCALinksWriter.cxx [moved from HLT/TPCLib/tracking-ca/AliHLTTPCCAEndPoint.cxx with 57% similarity]
HLT/TPCLib/tracking-ca/AliHLTTPCCALinksWriter.h [new file with mode: 0644]
HLT/TPCLib/tracking-ca/AliHLTTPCCAMCPoint.h
HLT/TPCLib/tracking-ca/AliHLTTPCCAMCTrack.cxx
HLT/TPCLib/tracking-ca/AliHLTTPCCAMCTrack.h
HLT/TPCLib/tracking-ca/AliHLTTPCCAMath.h [new file with mode: 0644]
HLT/TPCLib/tracking-ca/AliHLTTPCCANeighboursCleaner.cxx [new file with mode: 0644]
HLT/TPCLib/tracking-ca/AliHLTTPCCANeighboursCleaner.h [new file with mode: 0644]
HLT/TPCLib/tracking-ca/AliHLTTPCCANeighboursFinder.cxx [new file with mode: 0644]
HLT/TPCLib/tracking-ca/AliHLTTPCCANeighboursFinder.h [new file with mode: 0644]
HLT/TPCLib/tracking-ca/AliHLTTPCCANeighboursFinder1.cxx [moved from HLT/TPCLib/tracking-ca/AliHLTTPCCACell.cxx with 64% similarity]
HLT/TPCLib/tracking-ca/AliHLTTPCCANeighboursFinder1.h [new file with mode: 0644]
HLT/TPCLib/tracking-ca/AliHLTTPCCAOutTrack.cxx
HLT/TPCLib/tracking-ca/AliHLTTPCCAOutTrack.h
HLT/TPCLib/tracking-ca/AliHLTTPCCAParam.cxx
HLT/TPCLib/tracking-ca/AliHLTTPCCAParam.h
HLT/TPCLib/tracking-ca/AliHLTTPCCAPerformance.cxx
HLT/TPCLib/tracking-ca/AliHLTTPCCAPerformance.h
HLT/TPCLib/tracking-ca/AliHLTTPCCAProcess.h [new file with mode: 0644]
HLT/TPCLib/tracking-ca/AliHLTTPCCARow.cxx
HLT/TPCLib/tracking-ca/AliHLTTPCCARow.h
HLT/TPCLib/tracking-ca/AliHLTTPCCAStartHitsFinder.cxx [new file with mode: 0644]
HLT/TPCLib/tracking-ca/AliHLTTPCCAStartHitsFinder.h [new file with mode: 0644]
HLT/TPCLib/tracking-ca/AliHLTTPCCATrack.cxx
HLT/TPCLib/tracking-ca/AliHLTTPCCATrack.h
HLT/TPCLib/tracking-ca/AliHLTTPCCATrackConvertor.cxx
HLT/TPCLib/tracking-ca/AliHLTTPCCATrackConvertor.h
HLT/TPCLib/tracking-ca/AliHLTTPCCATrackParam.cxx
HLT/TPCLib/tracking-ca/AliHLTTPCCATrackParam.h
HLT/TPCLib/tracking-ca/AliHLTTPCCATrackParam1.cxx [new file with mode: 0644]
HLT/TPCLib/tracking-ca/AliHLTTPCCATrackParam1.h [new file with mode: 0644]
HLT/TPCLib/tracking-ca/AliHLTTPCCATracker.cxx
HLT/TPCLib/tracking-ca/AliHLTTPCCATracker.h
HLT/TPCLib/tracking-ca/AliHLTTPCCATrackerComponent.cxx
HLT/TPCLib/tracking-ca/AliHLTTPCCATrackerComponent.h
HLT/TPCLib/tracking-ca/AliHLTTPCCATrackletConstructor.cxx [new file with mode: 0644]
HLT/TPCLib/tracking-ca/AliHLTTPCCATrackletConstructor.h [new file with mode: 0644]
HLT/TPCLib/tracking-ca/AliHLTTPCCATrackletSelector.cxx [new file with mode: 0644]
HLT/TPCLib/tracking-ca/AliHLTTPCCATrackletSelector.h [new file with mode: 0644]
HLT/TPCLib/tracking-ca/AliHLTTPCCAUsedHitsInitialiser.cxx [moved from HLT/TPCLib/tracking-ca/AliHLTTPCCAHit.cxx with 63% similarity]
HLT/TPCLib/tracking-ca/AliHLTTPCCAUsedHitsInitialiser.h [new file with mode: 0644]
HLT/TPCLib/tracking-ca/AliTPCtrackerCA.cxx
HLT/TPCLib/tracking-ca/AliTPCtrackerCA.h
HLT/libAliHLTTPC.pkg

index a84d29f4aa18b6c09b19df5ca14e62fc4b5cdaa9..f977f62764911657a65350bba29880d8bcddfa99 100644 (file)
@@ -46,7 +46,7 @@ AliHLTTPCAgent gAliHLTTPCAgent;
 #include "AliHLTTPCCalibCEComponent.h"
 #include "AliHLTTPCCalibPulserComponent.h"
 #include "AliHLTTPCCalibPedestalComponent.h"
-#include "AliHLTTPCCATrackerComponent.h"
+//#include "AliHLTTPCCATrackerComponent.h"
 #include "AliHLTTPCGlobalMergerComponent.h"
 #include "AliHLTTPCSliceTrackerComponent.h"
 #include "AliHLTTPCVertexFinderComponent.h"
@@ -242,7 +242,7 @@ int AliHLTTPCAgent::RegisterComponents(AliHLTComponentHandler* pHandler) const
   pHandler->AddComponent(new AliHLTTPCCompModelDeconverterComponent);
   pHandler->AddComponent(new AliHLTTPCCompModelConverterComponent);
   pHandler->AddComponent(new AliHLTTPCCompDumpComponent);
-  pHandler->AddComponent(new AliHLTTPCCATrackerComponent);
+  //  pHandler->AddComponent(new AliHLTTPCCATrackerComponent);
   pHandler->AddComponent(new AliHLTTPCGlobalMergerComponent);
   pHandler->AddComponent(new AliHLTTPCSliceTrackerComponent);
   pHandler->AddComponent(new AliHLTTPCVertexFinderComponent);
diff --git a/HLT/TPCLib/tracking-ca/AliHLTTPCCACell.h b/HLT/TPCLib/tracking-ca/AliHLTTPCCACell.h
deleted file mode 100644 (file)
index 0f5bfe6..0000000
+++ /dev/null
@@ -1,65 +0,0 @@
-//-*- Mode: C++ -*-
-// @(#) $Id$
-
-//* 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 ALIHLTTPCCACELL_H
-#define ALIHLTTPCCACELL_H
-
-
-#include "Rtypes.h"
-
-/**
- * @class AliHLTTPCCACell
- *
- * The AliHLTTPCCACell class describes the "Cell" object ---
- * the set of neghbouring clusters in the same TPC row.
- * Cells are used as the minimal data units 
- * by the Cellular Automaton tracking algorithm. 
- *
- */
-class AliHLTTPCCACell
-{
- public:
-
-  //AliHLTTPCCACell(): fY(0),fZ(0),fErrY(0),fErrZ(0),fFirstHitRef(0),fNHits(0),fLink(0),fTrackID(0){}
-
-  //virtual ~AliHLTTPCCACell(){}
-
-  Float_t &Y(){ return fY; }
-  Float_t &Z(){ return fZ; }
-  Float_t &ErrY(){ return fErrY; } 
-  Float_t &ErrZ(){ return fErrZ; }
-  Float_t &ZMin(){ return fZMin; }
-  Float_t &ZMax(){ return fZMax; }
-  
-  Int_t &FirstHitRef(){ return fFirstHitRef; }
-  Int_t &NHits()      { return fNHits; }
-
-  Int_t &Link()       { return fLink; }
-  Int_t &Status()     { return fStatus; }
-  Int_t &TrackID()    { return fTrackID; }
- protected:
-
-  Float_t fY, fZ, fZMin,fZMax;       //* Y and Z coordinates
-  Float_t fErrY, fErrZ; //* cell errors in Y and Z
-
-  Int_t fFirstHitRef;   //* index of the first cell hit in the cell->hit reference array
-  Int_t fNHits;         //* number of hits in the cell
-
-  Int_t fLink;          //* link to the next cell on the track
-  Int_t fStatus;        //* status flag
-  Int_t fTrackID;       //* index of track
-
- private:
-
-  void Dummy(); // to make rulechecker happy by having something in .cxx file
-
-  //ClassDef(AliHLTTPCCACell,1);
-};
-
-
-#endif
diff --git a/HLT/TPCLib/tracking-ca/AliHLTTPCCADef.h b/HLT/TPCLib/tracking-ca/AliHLTTPCCADef.h
new file mode 100644 (file)
index 0000000..23010b9
--- /dev/null
@@ -0,0 +1,127 @@
+//-*- Mode: C++ -*-
+
+//* 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 ALIHLTTPCCADEF_H
+#define ALIHLTTPCCADEF_H
+
+/**
+ * Definitions needed for AliHLTTPCCATracker
+ *
+ */  
+//#define HLTCA_STANDALONE // compilation w/o root
+
+#ifdef __CUDACC__
+
+#define HLTCA_GPUCODE
+
+#endif
+
+#if defined(HLTCA_STANDALONE) || defined(HLTCA_GPUCODE)
+
+class TObject{};
+
+#define ClassDef(name,id)
+#define ClassImp(name)
+
+typedef char           Char_t;      //Signed Character 1 byte (char)
+typedef unsigned char  UChar_t;     //Unsigned Character 1 byte (unsigned char)
+typedef short          Short_t;     //Signed Short integer 2 bytes (short)
+typedef unsigned short UShort_t;    //Unsigned Short integer 2 bytes (unsigned short)
+#ifdef R__INT16
+typedef long           Int_t;       //Signed integer 4 bytes
+typedef unsigned long  UInt_t;      //Unsigned integer 4 bytes
+#else
+typedef int            Int_t;       //Signed integer 4 bytes (int)
+typedef unsigned int   UInt_t;      //Unsigned integer 4 bytes (unsigned int)
+#endif
+#ifdef R__B64    // Note: Long_t and ULong_t are currently not portable types
+typedef int            Seek_t;      //File pointer (int)
+typedef long           Long_t;      //Signed long integer 8 bytes (long)
+typedef unsigned long  ULong_t;     //Unsigned long integer 8 bytes (unsigned long)
+#else
+typedef int            Seek_t;      //File pointer (int)
+typedef long           Long_t;      //Signed long integer 4 bytes (long)
+typedef unsigned long  ULong_t;     //Unsigned long integer 4 bytes (unsigned long)
+#endif
+typedef float          Float_t;     //Float 4 bytes (float)
+typedef float          Float16_t;   //Float 4 bytes written with a truncated mantissa
+typedef double         Double_t;    //Double 8 bytes
+typedef double         Double32_t;  //Double 8 bytes in memory, written as a 4 bytes float
+typedef char           Text_t;      //General string (char)
+typedef bool           Bool_t;      //Boolean (0=false, 1=true) (bool)
+typedef unsigned char  Byte_t;      //Byte (8 bits) (unsigned char)
+typedef short          Version_t;   //Class version identifier (short)
+typedef const char     Option_t;    //Option string (const char)
+typedef int            Ssiz_t;      //String size (int)
+typedef float          Real_t;      //TVector and TMatrix element type (float)
+#if defined(R__WIN32) && !defined(__CINT__)
+typedef __int64          Long64_t;  //Portable signed long integer 8 bytes
+typedef unsigned __int64 ULong64_t; //Portable unsigned long integer 8 bytes
+#else
+typedef long long          Long64_t; //Portable signed long integer 8 bytes
+typedef unsigned long long ULong64_t;//Portable unsigned long integer 8 bytes
+#endif
+typedef double         Axis_t;      //Axis values type (double)
+typedef double         Stat_t;      //Statistics type (double)
+typedef short          Font_t;      //Font number (short)
+typedef short          Style_t;     //Style number (short)
+typedef short          Marker_t;    //Marker number (short)
+typedef short          Width_t;     //Line width (short)
+typedef short          Color_t;     //Color number (short)
+typedef short          SCoord_t;    //Screen coordinates (short)
+typedef double         Coord_t;     //Pad world coordinates (double)
+typedef float          Angle_t;     //Graphics angle (float)
+typedef float          Size_t;      //Attribute size (float)
+
+#else 
+
+#include "Rtypes.h"
+#include "TObject.h"
+
+#endif
+
+
+
+#ifdef HLTCA_GPUCODE
+
+#define GPUd() __device__ 
+#define GPUhd() __host__ __device__ 
+#define GPUh() __host__ inline 
+#define GPUg() __global__ 
+
+#define GPUshared() __shared__ 
+#define GPUsync() __syncthreads()
+
+__constant__ float4 cTracker[30000/sizeof(float4)];
+texture<uchar1> texGrid;               
+texture<float2> texHits;       
+
+#else
+
+#define GPUd() 
+#define GPUhd()
+#define GPUg()
+#define GPUh() 
+#define GPUshared() 
+#define GPUsync() 
+
+struct float2{ float x; float y; };
+struct uchar2{ unsigned char x; unsigned char y; };
+struct ushort2{ unsigned short x; unsigned short y; };
+struct uint1{ unsigned int x; };
+struct uint4{ unsigned int x,y,z,w; };
+
+float2 inline make_float2(float x, float y ){
+  float2 ret = {x,y};
+  return ret;
+}
+
+#endif
+
+
+#endif
index 76b1f2110e1a4dc557b6e8c22b0d0732e6042280..f12d509cf3e8928b41b4f3a5e544a92b51951ec1 100644 (file)
 // provided "as is" without express or implied warranty.                    *
 //***************************************************************************
 
-#include "AliHLTTPCCADisplay.h"
 
-#include "AliHLTTPCCATracker.h"
-#include "AliHLTTPCCAEndPoint.h"
-#include "AliHLTTPCCARow.h"
-#include "AliHLTTPCCATrack.h"
+//#include "AliHLTTPCCADisplay.h"
+
+#ifdef XXXX
+
+//#include "AliHLTTPCCATracker.h"
+//#include "AliHLTTPCCARow.h"
+//#include "AliHLTTPCCATrack.h"
 
 //#include "TString.h"
-#include "Riostream.h"
-#include "TMath.h"
-#include "TStyle.h"
-#include "TCanvas.h"
+//#include "Riostream.h"
+//#include "TMath.h"
+//#include "TStyle.h"
+//#include "TCanvas.h"
 
-ClassImp(AliHLTTPCCADisplay)
 
 AliHLTTPCCADisplay &AliHLTTPCCADisplay::Instance()
 {
@@ -147,7 +148,9 @@ void AliHLTTPCCADisplay::SetCurrentSlice( AliHLTTPCCATracker *slice )
     fYX->Range(cx-dr, cy-dr*1.05, cx+dr, cy+dr);
     fZX->Range(cz-dz, cy-dr*1.05, cz+dz, cy+dr);
 
-    //fYX->Range(cx-dr/6, cy-dr, cx+dr/8, cy-dr + dr/8);
+    fYX->Range(cx, cy-dr*0.8, cx+dr/2, cy+dr*0.1);
+    fZX->Range(cz, cy-dr*.8, cz+dz, cy+dr*0.1);
+   //fYX->Range(cx-dr/6, cy-dr, cx+dr/8, cy-dr + dr/8);
     //fZX->Range(cz+dz/2+dz/6, cy-dr , cz+dz-dz/8, cy-dr + dr/8);
 
     //fYX->Range(cx-dr/3, cy-dr/3, cx+dr, cy+dr);
@@ -295,9 +298,10 @@ void AliHLTTPCCADisplay::DrawHit( Int_t iRow, Int_t iHit, Int_t color )
 
   //Double_t dgy = 3.5*TMath::Abs(h->ErrY()*fSlice->Param().CosAlpha() - fSlice->Param().ErrX()*fSlice->Param().SinAlpha() );
   Double_t dx = 0.1;//fSlice->Param().ErrX()*TMath::Sqrt(12.)/2.;
-  Double_t dy = h->ErrY()*3.5;
+  Double_t dy = 0.35;//h->ErrY()*3.5;
   //Double_t dz = h->ErrZ()*3.5;
-  fMarker.SetMarkerSize(.3);
+  fMarker.SetMarkerSize(.5);
+  //fMarker.SetMarkerSize(.3);
   fMarker.SetMarkerColor(color);
   fArc.SetLineColor(color);
   fArc.SetFillStyle(0);
@@ -315,173 +319,108 @@ void AliHLTTPCCADisplay::DrawHit( Int_t iRow, Int_t iHit, Int_t color )
   fMarker.DrawMarker(h->Z(), vy); 
 }
 
-void AliHLTTPCCADisplay::DrawCell( Int_t iRow, AliHLTTPCCACell &cell, Int_t width, Int_t color )
-{
-  // draw cell
-  AliHLTTPCCARow &row = fSlice->Rows()[iRow];
-  Double_t vx, vy, vdx, vdy, vz = cell.Z(), vdz = cell.ErrZ()*3.5;
-  Slice2View(row.X(), cell.Y(), &vx, &vy);
-  Slice2View(0.2, cell.ErrY()*3.5, &vdx, &vdy);
-  if( color<0 ) color = GetColor(cell.Z());
-  fLine.SetLineColor(color);
-  fLine.SetLineWidth(width);
-  fArc.SetLineColor(color);
-  fArc.SetFillStyle(0);
-  fYX->cd();
-  //fLine.DrawLine(vx-vdx,vy-vdy, vx+vdx, vy+vdy );
-  fArc.DrawEllipse(vx, vy, vdx, vdy, 0,360, 0);
-  fZX->cd();
-  //fLine.DrawLine(cell.Z()-3*cell.ErrZ(),vy-vdy, cell.Z()+3*cell.ErrZ(), vy+vdy ); 
-  fArc.DrawEllipse(vz, vy, vdz, vdy, 0,360, 0);
-  fLine.SetLineWidth(1);
-}
 
-void  AliHLTTPCCADisplay::DrawCell( Int_t iRow, Int_t iCell, Int_t width, Int_t color )
-{
-  // draw cell
-  AliHLTTPCCARow &row = fSlice->Rows()[iRow];
-  DrawCell( iRow, row.Cells()[iCell], width, color );
-}
  
 
-void AliHLTTPCCADisplay::DrawEndPoint( Int_t ID, Float_t R, Int_t width, Int_t color)
-{
-  // draw endpoint
-  if( !fSlice ) return;
-  AliHLTTPCCARow &row = fSlice->ID2Row(ID);
-  AliHLTTPCCAEndPoint &p = fSlice->ID2Point(ID);
-  AliHLTTPCCACell &c = fSlice->ID2Cell(p.CellID());
-  if( color<0 ) color = GetColor( c.Z() );
 
-  fArc.SetLineColor(color);
-  fArc.SetFillStyle(0);
-  fArc.SetLineWidth(width);
 
-  Double_t vx, vy;
-  Slice2View( row.X(), c.Y(), &vx, &vy );  
-  fYX->cd();
-  fArc.DrawEllipse( vx, vy, R, R, 0,360, 90);  
-  fZX->cd();
-  fArc.DrawEllipse( c.Z(), vy, R, R, 0,360, 90);  
-  fArc.SetLineWidth(1);
 
-}
-void AliHLTTPCCADisplay::ConnectEndPoints( Int_t iID, Int_t jID, Float_t R, Int_t width, Int_t color )
+
+void AliHLTTPCCADisplay::DrawMergedHit( Int_t iRow, Int_t iHit, Int_t color )
 {
-   // connect endpoints
-  if( !fSlice ) return;
-  AliHLTTPCCARow &irow = fSlice->ID2Row(iID);
-  AliHLTTPCCAEndPoint &ip = fSlice->ID2Point(iID);
-  AliHLTTPCCACell &ic = fSlice->ID2Cell(ip.CellID());
-  AliHLTTPCCARow &jrow = fSlice->ID2Row(jID);
-  AliHLTTPCCAEndPoint &jp = fSlice->ID2Point(jID);
-  AliHLTTPCCACell &jc = fSlice->ID2Cell(jp.CellID());
-  if( color<0 ) color = GetColor( ic.Z() );
+#ifdef XXX
+  // connect two cells on display, kind of row is drawing
   
-  fArc.SetLineColor(color);
-  fArc.SetFillStyle(0);
-  fArc.SetLineWidth(width);
-  fLine.SetLineWidth(width);
-  fLine.SetLineColor(color);
-  Double_t ivx, ivy;
-  Slice2View( irow.X(), ic.Y(), &ivx, &ivy );  
-  Double_t jvx, jvy;
-  Slice2View( jrow.X(), jc.Y(), &jvx, &jvy );  
+  AliHLTTPCCARow &row = fSlice->Rows()[iRow];
+  AliHLTTPCCAHit &h = row.Hits()[iHit];
+  AliHLTTPCCAHit &hyz = row.HitsYZ()[iHit];
+
+  Double_t x = row.X();
+  Double_t y = hyz.Y();
+  Double_t z = hyz.Z();
+  Double_t x1 = x, x2 = x;
+  Double_t y1 = y, y2 = y;
+  Double_t z1 = z, z2 = z;
+  Int_t iRow1 = iRow, iHit1 = iHit;
+  Int_t iRow2 = iRow, iHit2 = iHit;
+
+  if( fSlice->HitLinksDown()[]>=0 ){    
+    iRow1 = iRow - 1;
+    iHit1 = h.LinkDown();
+    AliHLTTPCCARow &row1 = fSlice->Rows()[iRow1];
+    AliHLTTPCCAHitYZ &h1 = row1.HitsYZ()[iHit1];
+    x1 = row1.X();
+    y1 = h1.Y();
+    z1 = h1.Z();
+  }
+  if( h.LinkUp()>=0 ){    
+    iRow2 = iRow+1;
+    iHit2 = h.LinkUp();
+    AliHLTTPCCARow &row2 = fSlice->Rows()[iRow2];
+    AliHLTTPCCAHitYZ &h2 = row2.HitsYZ()[iHit2];
+    x2 = row2.X();
+    y2 = h2.Y();
+    z2 = h2.Z();
+  }
+  if( color<0 ) color = GetColor( (z+z1+z2)/3. );
 
-  fYX->cd();
-  fArc.DrawEllipse( ivx, ivy, R, R, 0,360, 90);  
-  fArc.DrawEllipse( jvx, jvy, R, R, 0,360, 90);  
-  fLine.DrawLine(ivx, ivy,jvx, jvy);
-  fZX->cd();
-  fArc.DrawEllipse( ic.Z(), ivy, R, R, 0,360, 90);  
-  fArc.DrawEllipse( jc.Z(), jvy, R, R, 0,360, 90);  
-  fLine.DrawLine(ic.Z(), ivy, jc.Z(), jvy);
-  fArc.SetLineWidth(1);
-  fLine.SetLineWidth(1);
-}
 
-void AliHLTTPCCADisplay::ConnectCells( Int_t iRow1, AliHLTTPCCACell &cell1, 
-                                      Int_t iRow2, AliHLTTPCCACell &cell2, Int_t color )
-{
-  // connect two cells on display, kind of row is drawing
-  AliHLTTPCCARow &row1 = fSlice->Rows()[iRow1];
-  AliHLTTPCCARow &row2 = fSlice->Rows()[iRow2];
-
-  AliHLTTPCCAHit &h11 = row1.GetCellHit(cell1,0);
-  AliHLTTPCCAHit &h12 = row1.GetCellHit(cell1,cell1.NHits()-1);
-  AliHLTTPCCAHit &h21 = row2.GetCellHit(cell2,0);
-  AliHLTTPCCAHit &h22=  row2.GetCellHit(cell2,cell2.NHits()-1);
-
-  Double_t x11 = row1.X();
-  Double_t x12 = row1.X();
-  Double_t y11 = h11.Y() - h11.ErrY()*3;
-  Double_t y12 = h12.Y() + h12.ErrY()*3;
-  Double_t z11 = h11.Z() - h11.ErrZ()*3;
-  Double_t z12 = h12.Z() + h12.ErrZ()*3;
-  Double_t x21 = row2.X();
-  Double_t x22 = row2.X();
-  Double_t y21 = h21.Y() - h21.ErrY()*3;
-  Double_t y22 = h22.Y() + h22.ErrY()*3;
-  Double_t z21 = h21.Z() - h21.ErrZ()*3;
-  Double_t z22 = h22.Z() + h22.ErrZ()*3;
-
-  Double_t vx11, vx12, vy11, vy12, vx21, vx22, vy21, vy22;
-
-  Slice2View(x11,y11, &vx11, &vy11 );
-  Slice2View(x12,y12, &vx12, &vy12 );
-  Slice2View(x21,y21, &vx21, &vy21 );
-  Slice2View(x22,y22, &vx22, &vy22 );
-
-  Double_t lx[] = { vx11, vx12, vx22, vx21, vx11 };
-  Double_t ly[] = { vy11, vy12, vy22, vy21, vy11 };
-  Double_t lz[] = { z11, z12, z22, z21, z11 };
-
-  if( color<0 ) color = GetColor( (z11+z12+z22+z21)/4. );
+  Slice2View(x,y, &x, &y );
+  Slice2View(x1,y1, &x1, &y1 );
+  Slice2View(x2,y2, &x2, &y2 );
+
+  Double_t lx[] = { x1, x, x2 };
+  Double_t ly[] = { y1, y, y2 };
+  Double_t lz[] = { z1, z, z2 };
+
   fPLine.SetLineColor(color);    
   fPLine.SetLineWidth(1);        
   //fPLine.SetFillColor(color);
   fPLine.SetFillStyle(-1);
  
   fYX->cd();
-  fPLine.DrawPolyLine(5, lx, ly );
+  fPLine.DrawPolyLine(3, lx, ly );
   fZX->cd();
-  fPLine.DrawPolyLine(5, lz, ly );   
-  DrawCell( iRow1, cell1, 1, color );
-  DrawCell( iRow2, cell2, 1, color );
+  fPLine.DrawPolyLine(3, lz, ly );   
+  DrawHit( iRow, iHit, color );
+  DrawHit( iRow1, iHit1, color );
+  DrawHit( iRow2, iHit2, color ); 
+#endif
 }
 
 
-
-
-void AliHLTTPCCADisplay::DrawTrack( AliHLTTPCCATrack &track, Int_t color, Bool_t DrawCells )
+void AliHLTTPCCADisplay::DrawTrack( AliHLTTPCCATrack &track, Int_t color, Bool_t DrawHits )
 {
   // draw track
-
-  if( track.NCells()<2 ) return;
-  int width = 1;
-
-  AliHLTTPCCADisplayTmpCell *vCells = new AliHLTTPCCADisplayTmpCell[track.NCells()];
-  AliHLTTPCCATrackParam &t = fSlice->ID2Point(track.PointID()[0]).Param();
-
-  Int_t iID = track.FirstCellID();
-  {
-    Int_t iCell=0;
-    while( iID>=0 ){
-      AliHLTTPCCACell *c = &(fSlice->ID2Cell( iID )); 
-      AliHLTTPCCARow &row = fSlice->ID2Row(iID);
-      vCells[iCell].ID() = iID;    
-      vCells[iCell].S() = t.GetS( row.X(), c->Y() );
-      vCells[iCell].Z() = c->Z();
-      iCell++;
-      iID = c->Link(); 
+  
+  if( track.NHits()<2 ) return;
+  int width = 2;
+
+  AliHLTTPCCADisplayTmpHit *vHits = new AliHLTTPCCADisplayTmpHit[track.NHits()];
+  AliHLTTPCCATrackParam &t = track.Param();
+
+  Int_t iID = track.FirstHitID();
+  int nhits = 0;
+  { 
+    Int_t iHit = 0;
+    for( int ih=0; ih<track.NHits(); ih++ ){
+      Int_t i = fSlice->TrackHits()[iID];
+      AliHLTTPCCAHit *h = &(fSlice->ID2Hit( i )); 
+      AliHLTTPCCARow &row = fSlice->ID2Row(i);
+      vHits[iHit].ID() = i;    
+      vHits[iHit].S() = t.GetS( row.X(), h->Y() );
+      vHits[iHit].Z() = h->Z();
+      iHit++;
+      nhits++;
+      iID++;
     }
   }
-  sort(vCells, vCells + track.NCells(), AliHLTTPCCADisplayTmpCell::CompareCellZ );
-  
+  sort(vHits, vHits + track.NHits(), AliHLTTPCCADisplayTmpHit::CompareHitZ );
+  cout<<"Draw track, nhits = "<<nhits<<endl;
   {
-    AliHLTTPCCACell &c1 = fSlice->ID2Cell(vCells[0].ID());
-    AliHLTTPCCACell &c2 = fSlice->ID2Cell(vCells[track.NCells()-1].ID());
+    AliHLTTPCCAHit &c1 = fSlice->ID2Hit(vHits[0].ID());
+    AliHLTTPCCAHit &c2 = fSlice->ID2Hit(vHits[track.NHits()-1].ID());
     if( color<0 ) color = GetColor( (c1.Z()+c2.Z())/2. );
   }
   
@@ -489,8 +428,8 @@ void AliHLTTPCCADisplay::DrawTrack( AliHLTTPCCATrack &track, Int_t color, Bool_t
   fMarker.SetMarkerSize(1.);
   /*
   for( Int_t i=0; i<3; i++){    
-    AliHLTTPCCACell &c1 = fSlice->ID2Cell(track.CellID()[i]);    
-    AliHLTTPCCARow &row1 = fSlice->ID2Row(track.CellID()[i]);
+    AliHLTTPCCAHit &c1 = fSlice->ID2Hit(track.HitID()[i]);    
+    AliHLTTPCCARow &row1 = fSlice->ID2Row(track.HitID()[i]);
     Double_t vx1, vy1;
     Slice2View(row1.X(), c1.Y(), &vx1, &vy1 ); 
     fYX->cd();
@@ -499,15 +438,16 @@ void AliHLTTPCCADisplay::DrawTrack( AliHLTTPCCATrack &track, Int_t color, Bool_t
     fMarker.DrawMarker(c1.Z(),vy1);
   }
   */
-  DrawTrackletPoint( fSlice->ID2Point(track.PointID()[0]).Param(), kBlack);//color );
-  DrawTrackletPoint( fSlice->ID2Point(track.PointID()[1]).Param(), kBlack);//color );
-
-  for( Int_t iCell=0; iCell<track.NCells()-1; iCell++ )
+  
+  //DrawTrackletPoint( fSlice->ID2Point(track.PointID()[0]).Param(), kBlack);//color );
+  //DrawTrackletPoint( fSlice->ID2Point(track.PointID()[1]).Param(), kBlack);//color );
+  //cout<<"DrawTrack end points x = "<<fSlice->ID2Point(track.PointID()[0]).Param().GetX()<<" "<<fSlice->ID2Point(track.PointID()[1]).Param().GetX()<<endl;
+  for( Int_t iHit=0; iHit<track.NHits()-1; iHit++ )
   {
-    AliHLTTPCCACell &c1 = fSlice->ID2Cell(vCells[iCell].ID());
-    AliHLTTPCCACell &c2 = fSlice->ID2Cell(vCells[iCell+1].ID());
-    AliHLTTPCCARow &row1 = fSlice->ID2Row(vCells[iCell].ID());
-    AliHLTTPCCARow &row2 = fSlice->ID2Row(vCells[iCell+1].ID());
+    AliHLTTPCCAHit &c1 = fSlice->ID2Hit(vHits[iHit].ID());
+    AliHLTTPCCAHit &c2 = fSlice->ID2Hit(vHits[iHit+1].ID());
+    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 );
@@ -563,14 +503,14 @@ void AliHLTTPCCADisplay::DrawTrack( AliHLTTPCCATrack &track, Int_t color, Bool_t
     }
   }
 
-  for( Int_t iCell=0; iCell<track.NCells()-1; iCell++ ){
-    AliHLTTPCCACell &c1 = fSlice->ID2Cell(vCells[iCell].ID());
-    AliHLTTPCCACell &c2 = fSlice->ID2Cell(vCells[iCell+1].ID());
-    AliHLTTPCCARow &row1 = fSlice->ID2Row(vCells[iCell].ID());
-    AliHLTTPCCARow &row2 = fSlice->ID2Row(vCells[iCell+1].ID());
+  for( Int_t iHit=0; iHit<track.NHits()-1; iHit++ ){
+    AliHLTTPCCAHit &c1 = fSlice->ID2Hit(vHits[iHit].ID());
+    AliHLTTPCCAHit &c2 = fSlice->ID2Hit(vHits[iHit+1].ID());
+    AliHLTTPCCARow &row1 = fSlice->ID2Row(vHits[iHit].ID());
+    AliHLTTPCCARow &row2 = fSlice->ID2Row(vHits[iHit+1].ID());
 
-    if( DrawCells ) ConnectCells( fSlice->ID2IRow(vCells[iCell].ID()),c1,
-                                 fSlice->ID2IRow(vCells[iCell+1].ID()),c2, color );
+    //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 );
@@ -586,7 +526,7 @@ void AliHLTTPCCADisplay::DrawTrack( AliHLTTPCCATrack &track, Int_t color, Bool_t
     fLine.DrawLine(z1,vy1, z2, vy2 ); 
   }
   fLine.SetLineWidth(1);     
-  delete[] vCells;
+  delete[] vHits;  
 }
 
 
@@ -602,7 +542,7 @@ void AliHLTTPCCADisplay::DrawTrackletPoint( AliHLTTPCCATrackParam &t, Int_t colo
   Double_t ex = t.GetCosPhi();
   Double_t ey = sinPhi;
 
-  int width = 3;
+  int width = 1;
 
   if( color<0 ) color = GetColor( t.GetZ() );
     
@@ -629,3 +569,4 @@ void AliHLTTPCCADisplay::DrawTrackletPoint( AliHLTTPCCATrackParam &t, Int_t colo
   fLine.DrawLine(z-3.5*dz,vy-vdy, z+3.5*dz, vy+vdy ); 
   fLine.SetLineWidth(1);
 }
+#endif //XXXX
index 79eb0d41344936fd28d5212283142a84c51864bb..ac1df77d5b8206e1709861c1ff2fb5872067a789 100644 (file)
 #ifndef ALIHLTTPCCADISPLAY_H
 #define ALIHLTTPCCADISPLAY_H
 
+
+#ifdef XXXX
 class AliHLTTPCCATracker;
-class AliHLTTPCCACell;
 class AliHLTTPCCATrack;
 class AliHLTTPCCATrackParam;
 class TCanvas;
-#include "TObject.h"
 #include "TArc.h"
 #include "TLine.h"
 #include "TPolyLine.h"
@@ -26,15 +26,15 @@ class TCanvas;
 #include "TCrown.h"
 #include "TMarker.h"
 #include "TLatex.h"
-
+#endif
 
 /**
  * @class AliHLTTPCCADisplay
  */
-class AliHLTTPCCADisplay:public TObject
+class AliHLTTPCCADisplay
 {
  public:
-
+#ifdef XXXX
   static AliHLTTPCCADisplay &Instance();
   
   AliHLTTPCCADisplay();
@@ -60,13 +60,8 @@ class AliHLTTPCCADisplay:public TObject
   void DrawSlice( AliHLTTPCCATracker *slice ); 
 
   void DrawHit( Int_t iRow,Int_t iHit, Int_t color=-1 );
-  void DrawCell( Int_t iRow, AliHLTTPCCACell &cell, Int_t width=1, Int_t color=-1 );
-  void DrawCell( Int_t iRow, Int_t iCell, Int_t width=1, Int_t color=-1 );
-
-  void DrawEndPoint( Int_t ID, Float_t R, Int_t width=1, Int_t color=-1 );
-  void ConnectEndPoints( Int_t iID, Int_t jID, Float_t R, Int_t width=1, Int_t color=-1 );
 
-  void ConnectCells( Int_t iRow1, AliHLTTPCCACell &cell1, Int_t iRow2, AliHLTTPCCACell &cell2, Int_t color=-1 );
+  void DrawMergedHit( Int_t iRow, Int_t iHit, Int_t color=-1 );
 
   void DrawTrack( AliHLTTPCCATrack &track, Int_t color=-1, Bool_t DrawCells=1 );
   void DrawTrackletPoint( AliHLTTPCCATrackParam &t, Int_t color=-1 );
@@ -94,31 +89,30 @@ class AliHLTTPCCADisplay:public TObject
   TCrown fCrown;   //!
   TLatex fLatex;   //!
 
-  class AliHLTTPCCADisplayTmpCell{  
+  class AliHLTTPCCADisplayTmpHit{  
 
   public:
-    Int_t &ID(){ return fCellID; }
+    Int_t &ID(){ return fHitID; }
     Double_t &S(){ return fS; }
     Double_t &Z(){ return fZ; }
 
-    static Bool_t CompareCellDS( const AliHLTTPCCADisplayTmpCell &a, 
-                                const AliHLTTPCCADisplayTmpCell  &b )
+    static Bool_t CompareHitDS( const AliHLTTPCCADisplayTmpHit &a, 
+                                const AliHLTTPCCADisplayTmpHit  &b )
     {    
       return (a.fS < b.fS);
     }
-    static Bool_t CompareCellZ( const AliHLTTPCCADisplayTmpCell &a, 
-                                const AliHLTTPCCADisplayTmpCell  &b )
+    static Bool_t CompareHitZ( const AliHLTTPCCADisplayTmpHit &a, 
+                                const AliHLTTPCCADisplayTmpHit  &b )
     {    
       return (a.fZ < b.fZ);
     }
   protected:
-    Int_t fCellID; // cell ID
+    Int_t fHitID; // cell ID
     Double_t fS;  // cell position on the XY track curve 
     Double_t fZ;  // cell Z position
   };
 
-
-  ClassDef(AliHLTTPCCADisplay,1);
+#endif // XXXX
 
 };
 
diff --git a/HLT/TPCLib/tracking-ca/AliHLTTPCCAEndPoint.h b/HLT/TPCLib/tracking-ca/AliHLTTPCCAEndPoint.h
deleted file mode 100644 (file)
index 7ed1ac6..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-//-*- Mode: C++ -*-
-// $Id$
-
-//* 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                               *
-
-//*                                                                        *
-//* The AliHLTTPCCAEndPoint class describes the end point of the track     *
-//* it contains the fitted track parameters at this point                  *
-//* The class is used for the matching of tracks withing one TPC slice     *
-//*                                                                        *
-
-#ifndef ALIHLTTPCCAENDPOINT_H
-#define ALIHLTTPCCAENDPOINT_H
-
-
-#include "Rtypes.h"
-#include "AliHLTTPCCATrackParam.h"
-
-/**
- * @class AliHLTTPCCAEndPoint
- */
-class AliHLTTPCCAEndPoint
-{
- public:
-  
-  AliHLTTPCCAEndPoint() :fCellID(0),fTrackID(0),fLink(0),fParam(){}
-  Int_t &CellID()  { return fCellID; }
-  Int_t &TrackID() { return fTrackID; }
-  Int_t &Link()    { return fLink; }
-
-  AliHLTTPCCATrackParam &Param(){ return fParam; };
-
- protected:
-
-  Int_t fCellID;                //* index of the cell
-  Int_t fTrackID;               //* index of the track
-  Int_t fLink;                  //* link to the neighbour (if found)
-  AliHLTTPCCATrackParam fParam; //* track parameters at the end point
-
-private:
-  void Dummy(); //* to make rulechecker happy by having something in .cxx file
-
-};
-
-
-#endif
index aee3f0e0b923876296f61d6ab1d5f2156f02894a..864b03fa668723442127efa768e89aef363937f1 100644 (file)
@@ -8,8 +8,7 @@
 #ifndef ALIHLTTPCCAGBHIT_H
 #define ALIHLTTPCCAGBHIT_H
 
-#include "Rtypes.h"
-#include "AliHLTTPCCAHit.h"
+#include "AliHLTTPCCADef.h"
 
 /**
  * @class AliHLTTPCCAGBHit
@@ -23,7 +22,7 @@ class AliHLTTPCCAGBHit
  public:
   AliHLTTPCCAGBHit()
     :fX(0),fY(0),fZ(0),fErrX(0),fErrY(0),fErrZ(0),fAmp(0),
-    fISlice(0), fIRow(0), fID(0), fIsUsed(0),fSliceHit(){}
+    fISlice(0), fIRow(0), fID(0), fIsUsed(0){}
 
   virtual ~AliHLTTPCCAGBHit(){}
 
@@ -41,8 +40,6 @@ class AliHLTTPCCAGBHit
   Int_t &ID(){ return fID; }
   Bool_t &IsUsed(){ return fIsUsed; };
 
-  AliHLTTPCCAHit &SliceHit(){ return fSliceHit; } 
-
 
   static bool Compare(const AliHLTTPCCAGBHit &a, const AliHLTTPCCAGBHit &b);
 
@@ -69,8 +66,6 @@ class AliHLTTPCCAGBHit
   Int_t fID;     //* external ID (id of AliTPCcluster) 
   Bool_t fIsUsed; //* is used by GBTracks
 
-  AliHLTTPCCAHit fSliceHit; //* corresponding slice hit
-
   //ClassDef(AliHLTTPCCAGBHit,1);
 
 };
index 42eddac2561b161a5f05e5930a0d3d03b9bc9d15..d457f7ad682f7bc8772442f3303a17e026ea236a 100644 (file)
@@ -8,8 +8,8 @@
 #ifndef ALIHLTTPCCAGBTRACK_H
 #define ALIHLTTPCCAGBTRACK_H
 
-#include "Rtypes.h"
 
+#include "AliHLTTPCCADef.h"
 #include "AliHLTTPCCATrackParam.h"
 
 /**
@@ -45,7 +45,7 @@ class AliHLTTPCCAGBTrack
 
   void Dummy(); // to make rulechecker happy by having something in .cxx file
 
-  ClassDef(AliHLTTPCCAGBTrack,1);
+  ClassDef(AliHLTTPCCAGBTrack,1)
 };
 
 
index 84cd47c36ee96a31f244c3ee3681681547e7450e..9e29c09a2531f026ef81ee80c7975c4141aecde9 100644 (file)
 #include "AliHLTTPCCAOutTrack.h"
 #include "AliHLTTPCCATracker.h"
 #include "AliHLTTPCCAGBTrack.h"
+#include "AliHLTTPCCATrackParam.h"
 
-#include "TMath.h"
+#include "AliHLTTPCCAMath.h"
 #include "TStopwatch.h"
-#include "Riostream.h"
+#include <iostream.h>
 
 //#define DRAW
 
 #include "TApplication.h"
 #endif //DRAW
 
-ClassImp(AliHLTTPCCAGBTracker)
 
 AliHLTTPCCAGBTracker::AliHLTTPCCAGBTracker()
-  : TObject(),
+  :
     fSlices(0), 
     fNSlices(0), 
     fHits(0),
@@ -53,7 +53,7 @@ AliHLTTPCCAGBTracker::AliHLTTPCCAGBTracker()
 }
 
 AliHLTTPCCAGBTracker::AliHLTTPCCAGBTracker(const AliHLTTPCCAGBTracker&)
-  : TObject(),
+  : 
     fSlices(0), 
     fNSlices(0), 
     fHits(0),
@@ -148,12 +148,6 @@ void AliHLTTPCCAGBTracker::ReadHit( Float_t x, Float_t y, Float_t z,
   hit.ISlice()=iSlice;
   hit.IRow() = iRow;
   hit.IsUsed() = 0;
-
-  hit.SliceHit().Y() = y;
-  hit.SliceHit().Z() = z;
-  hit.SliceHit().ErrY() = errY;
-  hit.SliceHit().ErrZ() = errZ;
-  hit.SliceHit().ID() = 0;
   fNHits++;
 }
 
@@ -161,8 +155,7 @@ void AliHLTTPCCAGBTracker::FindTracks()
 {
   //* main tracking routine
   fTime = 0;
-  fStatNEvents++;
-
+  fStatNEvents++;  
 #ifdef DRAW
   if( fStatNEvents<=1 ){
     if( !gApplication ){
@@ -173,49 +166,66 @@ void AliHLTTPCCAGBTracker::FindTracks()
   AliHLTTPCCADisplay::Instance().SetSliceView();
   //AliHLTTPCCADisplay::Instance().SetTPCView();
   //AliHLTTPCCADisplay::Instance().DrawTPC();
-#endif //DRAW
+#endif //DRAW  
 
   if( fNHits<=0 ) return;
   
-  sort(fHits,fHits+fNHits, AliHLTTPCCAGBHit::Compare );
+  std::sort(fHits,fHits+fNHits, AliHLTTPCCAGBHit::Compare );  
 
   // Read hits, row by row
 
-  Int_t oldRow = -1;
-  Int_t oldSlice = -1;
-  Int_t nRowHits = 0;
-  Int_t firstRowHit = 0;
   int nHitsTotal = fNHits;
-  AliHLTTPCCAHit *vHits = new AliHLTTPCCAHit[nHitsTotal]; // CA hit array
+  Float_t *hitY = new Float_t [nHitsTotal];
+  Float_t *hitZ = new Float_t [nHitsTotal];
+
+  Int_t sliceNHits[fNSlices];  
+  Int_t rowNHits[fNSlices][200];
   
+  for( Int_t is=0; is<fNSlices; is++ ){
+    sliceNHits[is] = 0;
+    for( Int_t ir=0; ir<200; ir++ ) rowNHits[is][ir] = 0;    
+  }
+
   for( int ih=0; ih<nHitsTotal; ih++){
-    AliHLTTPCCAGBHit &h = fHits[ih];
-    h.SliceHit().ID() = ih;
-    vHits[ih] = h.SliceHit();
-    if( h.IRow() != oldRow || h.ISlice() != oldSlice ){
-      if( oldRow>=0 && oldSlice>=0 ){  
-       fSlices[oldSlice].ReadHitRow( oldRow, vHits+firstRowHit, nRowHits );
+    AliHLTTPCCAGBHit &h = fHits[ih];    
+    sliceNHits[h.ISlice()]++;
+    rowNHits[h.ISlice()][h.IRow()]++;
+  }
+  
+  Int_t firstSliceHit = 0;
+  for( Int_t is=0; is<fNSlices; is++ ){
+    fFirstSliceHit[is] = firstSliceHit;
+    Int_t rowFirstHits[200];
+    Int_t firstRowHit = 0;
+    for( Int_t ir=0; ir<200; ir++ ){
+      rowFirstHits[ir] = firstRowHit;
+      for( Int_t ih=0; ih<rowNHits[is][ir]; ih++){
+       AliHLTTPCCAGBHit &h = fHits[firstSliceHit + firstRowHit + ih];    
+       hitY[firstRowHit + ih] = h.Y();
+       hitZ[firstRowHit + ih] = h.Z(); 
       }
-      oldRow = h.IRow();
-      oldSlice = h.ISlice();
-      firstRowHit = ih;
-      nRowHits = 0;
+      firstRowHit+=rowNHits[is][ir];
     }
-    nRowHits++;    
-  }    
-  if( oldRow>=0 && oldSlice>=0 ){
-    fSlices[oldSlice].ReadHitRow( oldRow, vHits+firstRowHit, nRowHits );
+    //if( is==24 ){//SG!!!
+    fSlices[is].ReadEvent( rowFirstHits, rowNHits[is], hitY, hitZ, sliceNHits[is] );
+    //}
+    firstSliceHit+=sliceNHits[is];
   }
-  delete[] vHits;
-  
-  //cout<<"Start CA reconstruction"<<endl;
 
+
+  delete[] hitY;
+  delete[] hitZ;
+
+  TStopwatch timer1;
+  TStopwatch timer2;
+  //cout<<"Start CA reconstruction"<<endl;
   for( int iSlice=0; iSlice<fNSlices; iSlice++ ){
     TStopwatch timer;
     AliHLTTPCCATracker &slice = fSlices[iSlice];
     slice.Reconstruct();
     timer.Stop();
-    fTime = timer.CpuTime();
+    //fTime+= timer.CpuTime();
+    //blaTime+= timer.CpuTime();
     fStatTime[0] += timer.CpuTime();
     fStatTime[1]+=slice.Timers()[0];
     fStatTime[2]+=slice.Timers()[1];
@@ -226,8 +236,10 @@ void AliHLTTPCCAGBTracker::FindTracks()
     fStatTime[7]+=slice.Timers()[6];
     fStatTime[8]+=slice.Timers()[7];
   }
-  //cout<<"End CA reconstruction"<<endl;
-  
+
+  timer2.Stop();
+  //cout<<"blaTime = "<<timer2.CpuTime()*1.e3<<endl;
+
   for( Int_t iSlice=0; iSlice<fNSlices; iSlice++ ){
     AliHLTTPCCATracker &iS = fSlices[iSlice];
     if( fSliceTrackInfos[iSlice] ) delete[] fSliceTrackInfos[iSlice];
@@ -246,8 +258,10 @@ void AliHLTTPCCAGBTracker::FindTracks()
   Merging();
   timerMerge.Stop();
   fStatTime[9]+=timerMerge.CpuTime();  
-  fTime+=timerMerge.CpuTime();
+  //fTime+=timerMerge.CpuTime();
   //cout<<"End CA merging"<<endl;
+  timer1.Stop();
+  fTime+= timer1.CpuTime();
 
 #ifdef DRAW
   AliHLTTPCCADisplay::Instance().Ask();
@@ -307,15 +321,15 @@ void AliHLTTPCCAGBTracker::Merging()
       AliHLTTPCCATrackParam &iT2 = iTrParams[1][itr];
       iT1 = iS.OutTracks()[itr].StartPoint();
       iT2 = iS.OutTracks()[itr].EndPoint();
-      iOK[0][itr] = iT1.Rotate( dalpha/2 - TMath::Pi()/2 );
-      iOK[1][itr] = iT2.Rotate( dalpha/2 - TMath::Pi()/2 );
+      iOK[0][itr] = iT1.Rotate( dalpha/2 - CAMath::Pi()/2 );
+      iOK[1][itr] = iT2.Rotate( dalpha/2 - CAMath::Pi()/2 );
 
       if( iOK[0][itr] ){
-       iOK[0][itr] = iT1.TransportToX( 0 );
+       iOK[0][itr] = iT1.TransportToX( 0, .99 );
        if( iS.Param().RMin() > iT1.Y() || iS.Param().RMax() < iT1.Y() ) iOK[0][itr]=0;
       }
       if( iOK[1][itr] ){
-       iOK[1][itr] = iT2.TransportToX( 0 );
+       iOK[1][itr] = iT2.TransportToX( 0, .99 );
        if( iS.Param().RMin() > iT2.Y() || iS.Param().RMax() < iT2.Y() ) iOK[1][itr]=0;
       }
     }
@@ -328,14 +342,14 @@ void AliHLTTPCCAGBTracker::Merging()
       AliHLTTPCCATrackParam &jT2 = jTrParams[1][jtr];
       jT1 = jS.OutTracks()[jtr].StartPoint();
       jT2 = jS.OutTracks()[jtr].EndPoint();
-      jOK[0][jtr] = jT1.Rotate( -dalpha/2 - TMath::Pi()/2 );
-      jOK[1][jtr] = jT2.Rotate( -dalpha/2 - TMath::Pi()/2 );
+      jOK[0][jtr] = jT1.Rotate( -dalpha/2 - CAMath::Pi()/2 );
+      jOK[1][jtr] = jT2.Rotate( -dalpha/2 - CAMath::Pi()/2 );
       if( jOK[0][jtr] ){
-       jOK[0][jtr] = jT1.TransportToX( 0 );
+       jOK[0][jtr] = jT1.TransportToX( 0, .99 );
        if( jS.Param().RMin() > jT1.Y() || jS.Param().RMax() < jT1.Y() ) jOK[0][jtr]=0;
       }
       if( jOK[1][jtr] ){
-       jOK[1][jtr] = jT2.TransportToX( 0 );
+       jOK[1][jtr] = jT2.TransportToX( 0, .99 );
        if( jS.Param().RMin() > jT2.Y() || jS.Param().RMax() < jT2.Y() ) jOK[1][jtr]=0;
       }
     }
@@ -420,6 +434,7 @@ void AliHLTTPCCAGBTracker::Merging()
     if( iOK[i] ) delete[] iOK[i];
     if( jOK[i] ) delete[] jOK[i];
   }
+
   timerMerge1.Stop();
   fStatTime[10]+=timerMerge1.CpuTime();
 
@@ -476,7 +491,7 @@ void AliHLTTPCCAGBTracker::Merging()
        AliHLTTPCCATracker &jslice = fSlices[jSlice];
        AliHLTTPCCAOutTrack &jTr = jslice.OutTracks()[jtr];
        for( int jhit=0; jhit<jTr.NHits(); jhit++){
-         int id = jslice.OutTrackHits()[jTr.FirstHitRef()+jhit];         
+         int id = fFirstSliceHit[jSlice] + jslice.OutTrackHits()[jTr.FirstHitRef()+jhit];        
          AliHLTTPCCAGBHit &h = fHits[id];
          FitPoint &p =  fitPoints[h.IRow()];
          if( p.fISlice >=0 ) continue;
@@ -485,8 +500,8 @@ void AliHLTTPCCAGBTracker::Merging()
          p.fX = jslice.Rows()[h.IRow()].X();
          p.fY = h.Y();
          p.fZ = h.Z();
-         p.fErr2Y = h.ErrY()*h.ErrY();
-         p.fErr2Z = h.ErrZ()*h.ErrZ();
+         //p.fErr2Y = h.ErrY()*h.ErrY();
+         //p.fErr2Z = h.ErrZ()*h.ErrZ();
          p.fAmp = h.Amp();
          nHits++;          
        }
@@ -494,8 +509,7 @@ void AliHLTTPCCAGBTracker::Merging()
        jSlice = nextSlice[jSlice];     
       } while( jtr >=0 ); 
 
-      if( nHits < 30 ) continue;     //SG!!!
-
+      if( nHits < 10 ) continue;     //SG!!!
 
       Int_t firstRow = 0, lastRow = maxNRows-1;
       for( firstRow=0; firstRow<maxNRows; firstRow++ ){
@@ -508,7 +522,7 @@ void AliHLTTPCCAGBTracker::Merging()
       Int_t midRow = firstRow;
       for( Int_t i=firstRow+1; i<=lastRow; i++ ){
        if( fitPoints[i].fISlice<0 ) continue;  
-       if( TMath::Abs(i-mmidRow)>=TMath::Abs(midRow-mmidRow) ) continue;
+       if( CAMath::Abs(i-mmidRow)>=CAMath::Abs(midRow-mmidRow) ) continue;
        midRow = i;
       }
       if( midRow==firstRow || midRow==lastRow ) continue;
@@ -526,7 +540,7 @@ void AliHLTTPCCAGBTracker::Merging()
 
       {        
 
-       {         
+       {
          FitPoint &p0 =  fitPoints[firstRow];
          FitPoint &p1 =  fitPoints[midRow];
          FitPoint &p2 =  fitPoints[lastRow];
@@ -535,15 +549,15 @@ void AliHLTTPCCAGBTracker::Merging()
          Float_t x2=p2.fX, y2=p2.fY, z2=p2.fZ;
          if( p1.fISlice!=p0.fISlice ){
            Float_t dAlpha = fSlices[p0.fISlice].Param().Alpha() - fSlices[p1.fISlice].Param().Alpha();
-           Float_t c = TMath::Cos(dAlpha);
-           Float_t s = TMath::Sin(dAlpha);
+           Float_t c = CAMath::Cos(dAlpha);
+           Float_t s = CAMath::Sin(dAlpha);
            x1 = p1.fX*c + p1.fY*s;
            y1 = p1.fY*c - p1.fX*s;
          }
          if( p2.fISlice!=p0.fISlice ){
            Float_t dAlpha = fSlices[p0.fISlice].Param().Alpha() - fSlices[p2.fISlice].Param().Alpha();
-           Float_t c = TMath::Cos(dAlpha);
-           Float_t s = TMath::Sin(dAlpha);
+           Float_t c = CAMath::Cos(dAlpha);
+           Float_t s = CAMath::Sin(dAlpha);
            x2 = p2.fX*c + p2.fY*s;
            y2 = p2.fY*c - p2.fX*s;
          }
@@ -572,7 +586,7 @@ void AliHLTTPCCAGBTracker::Merging()
            }
            //* Transport to the new row
            
-           if( !t0.TransportToX( p.fX ) ) continue;
+           if( !t0.TransportToX( p.fX, .99 ) ) continue;
 
            //* Calculate hit errors
            
@@ -586,7 +600,7 @@ void AliHLTTPCCAGBTracker::Merging()
 
            AliHLTTPCCATracker *cslice = &(fSlices[currslice]);
            AliHLTTPCCARow *row = &(cslice->Rows()[iRow]);
-           if( !t0.TransportToX( row->X() ) ) continue;
+           if( !t0.TransportToX( row->X(), .99 ) ) continue;
 
            if( t0.GetY() > row->MaxY() ){ //next slice
 
@@ -598,8 +612,8 @@ void AliHLTTPCCAGBTracker::Merging()
              currslice = j;
              cslice = &(fSlices[currslice]);
              row = &(cslice->Rows()[iRow]);
-             if( !t0.TransportToX( row->X() ) ) continue;
-             if( TMath::Abs(t0.GetY()) > row->MaxY() ) continue;
+             if( !t0.TransportToX( row->X(), .99 ) ) continue;
+             if( CAMath::Abs(t0.GetY()) > row->MaxY() ) continue;
 
            }else if( t0.GetY() < -row->MaxY() ){ //prev slice
              Int_t j = prevSlice[currslice];
@@ -608,14 +622,14 @@ void AliHLTTPCCAGBTracker::Merging()
              currslice = j;
              cslice = &(fSlices[currslice]);
              row = &(cslice->Rows()[iRow]);
-             if( !t0.TransportToX( row->X() ) ) continue;              
-             if( TMath::Abs(t0.GetY()) > row->MaxY() ) continue;
+             if( !t0.TransportToX( row->X(), .99 ) ) continue;         
+             if( CAMath::Abs(t0.GetY()) > row->MaxY() ) continue;
            }
            
            Int_t bestsh = -1;
            Float_t ds = 1.e10;
            for( Int_t ish=0; ish<row->NHits(); ish++ ){
-             AliHLTTPCCAHit &sh = row->Hits()[ish];
+             AliHLTTPCCAHit &sh = cslice->Hits()[row->FirstHit()+ish];
              Float_t dy = sh.Y() - t0.GetY();
              Float_t dz = sh.Z() - t0.GetZ();
              Float_t dds = dy*dy+dz*dz;
@@ -630,7 +644,7 @@ void AliHLTTPCCAGBTracker::Merging()
            
            GetErrors2( currslice, iRow, t0, p.fErr2Y, p.fErr2Z );
 
-           AliHLTTPCCAHit &sh = row->Hits()[bestsh];
+           AliHLTTPCCAHit &sh = cslice->Hits()[row->FirstHit()+bestsh];
            Float_t dy = sh.Y() - t0.GetY();
            Float_t dz = sh.Z() - t0.GetZ();
            Float_t s2z = /*t0.GetErr2Z() + */ p.fErr2Z;
@@ -639,7 +653,7 @@ void AliHLTTPCCAGBTracker::Merging()
            if( dy*dy>factor2*s2y ) continue;
 
            p.fISlice = currslice;
-           p.fHitID = sh.ID();
+           p.fHitID = fFirstSliceHit[p.fISlice] + cslice->HitsID()[row->FirstHit() + bestsh];
            p.fX = row->X();
            p.fY = sh.Y();
            p.fZ = sh.Z();
@@ -648,17 +662,18 @@ void AliHLTTPCCAGBTracker::Merging()
 
          //* Update the track
          
-         t0.Filter2( p.fY, p.fZ, p.fErr2Y, p.fErr2Z );   
+         t0.Filter2( p.fY, p.fZ, p.fErr2Y, p.fErr2Z, .99 );      
        }
 
        //* final refit, dE/dx calculation
        //cout<<"\n\nstart refit..\n"<<endl;
+
+       AliHLTTPCCATrackParam::AliHLTTPCCATrackFitParam fitPar;
        {
          Double_t sumDeDx = 0;
          Int_t nDeDx = 0;
          t.NHits() = 0;
        
-         AliHLTTPCCATrackFitParam fitPar;
          t0.CalculateFitParameters( fitPar, fSlices[0].Param().Bz() );
 
          t0.Cov()[ 0] = .1;
@@ -701,9 +716,9 @@ void AliHLTTPCCAGBTracker::Merging()
            //cout<<" before transport:"<<endl;
            //t0.Print();
            
-           //if( !t0.TransportToX( p.fX ) ) continue;      
+           //if( !t0.TransportToX( p.fX, .99 ) ) continue;         
            if( !t0.TransportToXWithMaterial( p.fX, fitPar ) ) continue;            
-           //if( !t0.TransportToX( p.fX ) ) continue;      
+           //if( !t0.TransportToX( p.fX, .99 ) ) continue;         
            //cout<<" after transport:"<<endl;
            //t0.Print();
 
@@ -732,13 +747,13 @@ void AliHLTTPCCAGBTracker::Merging()
            //cout<<" before filtration:"<<endl;
            //t0.Print();
 
-           if( !t0.Filter2( p.fY, p.fZ, p.fErr2Y, p.fErr2Z ) ) continue;         
+           if( !t0.Filter2( p.fY, p.fZ, p.fErr2Y, p.fErr2Z, .99 ) ) continue;    
            //cout<<" after filtration:"<<endl;
            //t0.Print();
              first = 0;
            
-           if( TMath::Abs( t0.CosPhi() )>1.e-4 ){
-             Float_t dLdX = TMath::Sqrt(1.+t0.DzDs()*t0.DzDs())/TMath::Abs(t0.CosPhi());
+           if( CAMath::Abs( t0.CosPhi() )>1.e-4 ){
+             Float_t dLdX = CAMath::Sqrt(1.+t0.DzDs()*t0.DzDs())/CAMath::Abs(t0.CosPhi());
              sumDeDx+=p.fAmp/dLdX;
              nDeDx++;
            } 
@@ -753,6 +768,21 @@ void AliHLTTPCCAGBTracker::Merging()
        }
 
        if( t.NHits()<30 ) continue;//SG!!
+       Double_t dAlpha = 0;
+       {
+         Double_t xTPC=83.65;
+         Double_t ddAlpha = 0.00609235;
+         
+         if( t0.TransportToXWithMaterial( xTPC, fitPar ) ){
+           Double_t y=t0.GetY();
+           Double_t ymax=xTPC*CAMath::Tan(dAlpha/2.); 
+           if (y > ymax) {
+             if( t0.Rotate( ddAlpha ) ){ dAlpha=ddAlpha;  t0.TransportToXWithMaterial( xTPC, fitPar ); }
+           } else if (y <-ymax) {
+             if( t0.Rotate( -ddAlpha ) ){  dAlpha=-ddAlpha; t0.TransportToXWithMaterial( xTPC, fitPar );}
+           }       
+         }
+       }
 
        {
          Bool_t ok=1;
@@ -771,15 +801,15 @@ void AliHLTTPCCAGBTracker::Merging()
          }
        }
 
-       if( TMath::Abs(t0.Kappa())<1.e-8 ) t0.Kappa() = 1.e-8;  
+       if( CAMath::Abs(t0.Kappa())<1.e-8 ) t0.Kappa() = 1.e-8; 
        t.Param() = t0;
-       t.Alpha() = fSlices[currslice].Param().Alpha();
+       t.Alpha() = fSlices[currslice].Param().Alpha() + dAlpha;
        nTrackHits+= t.NHits();
        fNTracks++;   
       }
     }
   }
-  cout<<"\n\nRejected: "<<nRejected<<"\n"<<endl;
+  //cout<<"\n\nRejected: "<<nRejected<<"\n"<<endl;
   timerMerge2.Stop();
   fStatTime[11]+=timerMerge2.CpuTime();
 
@@ -797,7 +827,7 @@ void AliHLTTPCCAGBTracker::Merging()
     }
     Int_t nTracks = 0;
     Int_t nHits = 0;
-    sort(vptracks, vptracks+fNTracks, AliHLTTPCCAGBTrack::ComparePNClusters );
+    std::sort(vptracks, vptracks+fNTracks, AliHLTTPCCAGBTrack::ComparePNClusters );
     for( Int_t itr=0; itr<fNTracks; itr++ ){
       AliHLTTPCCAGBTrack &t = *(vptracks[itr]);
       AliHLTTPCCAGBTrack &to = vtracks[nTracks];
@@ -812,7 +842,7 @@ void AliHLTTPCCAGBTracker::Merging()
        to.NHits()++;
        h.IsUsed() = 1;
       }
-      if( to.NHits()<30 ) continue;//SG!!!
+      if( to.NHits()<10 ) continue;//SG!!!
       nHits+=to.NHits();
       nTracks++;
       //cout<<to.Param().GetErr2Y()<<" "<<to.Param().GetErr2Z()<<endl;
@@ -834,9 +864,9 @@ void AliHLTTPCCAGBTracker::GetErrors2( Int_t iSlice, Int_t iRow, AliHLTTPCCATrac
   // Use calibrated cluster error from OCDB
   //
     
-  Float_t z = TMath::Abs((250.-0.275)-TMath::Abs(t.GetZ()));
+  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 = TMath::Abs(t.GetCosPhi())>1.e-2 ?1./t.GetCosPhi() :0;
+  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 ;
 
@@ -856,8 +886,9 @@ void AliHLTTPCCAGBTracker::GetErrors2( AliHLTTPCCAGBHit &h, AliHLTTPCCATrackPara
   GetErrors2( h.ISlice(), h.IRow(), t, Err2Y, Err2Z );
 }
 
-void AliHLTTPCCAGBTracker::WriteSettings( ostream &out )
+void AliHLTTPCCAGBTracker::WriteSettings( ostream &out ) const
 {
+  //* write settings to the file
   out<< NSlices()<<endl;  
   for( int iSlice=0; iSlice<NSlices(); iSlice++ ){    
     fSlices[iSlice].Param().WriteSettings( out );
@@ -866,6 +897,7 @@ void AliHLTTPCCAGBTracker::WriteSettings( ostream &out )
 
 void AliHLTTPCCAGBTracker::ReadSettings( istream &in )
 {
+  //* Read settings from the file
   Int_t nSlices=0;
   in >> nSlices;
   SetNSlices( nSlices );
@@ -876,8 +908,10 @@ void AliHLTTPCCAGBTracker::ReadSettings( istream &in )
   }
 }
 
-void AliHLTTPCCAGBTracker::WriteEvent( ostream &out )
+void AliHLTTPCCAGBTracker::WriteEvent( ostream &out ) const
 {
+  // write event to the file
+
   out<<NHits()<<endl;
   for (Int_t ih=0; ih<NHits(); ih++) {
     AliHLTTPCCAGBHit &h = fHits[ih];
@@ -893,8 +927,10 @@ void AliHLTTPCCAGBTracker::WriteEvent( ostream &out )
   }
 }
 
-void AliHLTTPCCAGBTracker::ReadEvent( istream &in )
+void AliHLTTPCCAGBTracker::ReadEvent( istream &in ) 
 {
+  //* Read event from file 
+
   StartEvent();
   Int_t nHits;
   in >> nHits;
@@ -908,23 +944,24 @@ void AliHLTTPCCAGBTracker::ReadEvent( istream &in )
   }
 }
 
-void AliHLTTPCCAGBTracker::WriteTracks( ostream &out )
+void AliHLTTPCCAGBTracker::WriteTracks( ostream &out ) const 
 {
+  //* Write tracks to file 
+
   out<<fTime<<endl;
   Int_t nTrackHits = 0;
-  for( Int_t itr=0; itr<NTracks(); itr++ ){
-    AliHLTTPCCAGBTrack &t = Tracks()[itr];    
-    nTrackHits+=t.NHits();
+  for( Int_t itr=0; itr<fNTracks; itr++ ){
+    nTrackHits+=fTracks[itr].NHits();
   }
   out<<nTrackHits<<endl;
   for( Int_t ih=0; ih<nTrackHits; ih++ ){
-    out<< TrackHits()[ih]<<" ";
+    out<< fTrackHits[ih]<<" ";
   }
   out<<endl;
   
   out<<NTracks()<<endl;
-  for( Int_t itr=0; itr<NTracks(); itr++ ){
-    AliHLTTPCCAGBTrack &t = Tracks()[itr];    
+  for( Int_t itr=0; itr<fNTracks; itr++ ){
+    AliHLTTPCCAGBTrack &t = fTracks[itr];    
     AliHLTTPCCATrackParam &p = t.Param();      
     out<< t.NHits()<<" ";
     out<< t.FirstHitRef()<<" ";
@@ -943,6 +980,8 @@ void AliHLTTPCCAGBTracker::WriteTracks( ostream &out )
 
 void AliHLTTPCCAGBTracker::ReadTracks( istream &in )
 {
+  //* Read tracks  from file 
+
   in>>fTime;
   fStatTime[0]+=fTime;
   fStatNEvents++;
index 989f4ce03e6bbcbd3fb0993fa823baf6e2ab6d53..bb4e6d80a1c6f39b9956ee08b2c6043c83793984 100644 (file)
@@ -8,7 +8,8 @@
 #ifndef ALIHLTTPCCAGBTRACKER_H
 #define ALIHLTTPCCAGBTRACKER_H
 
-#include "TObject.h"
+#include "AliHLTTPCCADef.h"
+#include <iostream.h>
 
 class AliHLTTPCCATracker;
 class AliHLTTPCCAGBTrack;
@@ -31,7 +32,7 @@ class AliHLTTPCCATrackParam;
  * The class is under construction.
  *
  */
-class AliHLTTPCCAGBTracker:public TObject
+class AliHLTTPCCAGBTracker
 {
 
 public:
@@ -40,7 +41,7 @@ public:
   AliHLTTPCCAGBTracker(const AliHLTTPCCAGBTracker&);
   AliHLTTPCCAGBTracker &operator=(const AliHLTTPCCAGBTracker&);
 
-  virtual ~AliHLTTPCCAGBTracker();
+  ~AliHLTTPCCAGBTracker();
 
   void StartEvent();
   void SetNSlices( Int_t N );
@@ -65,11 +66,11 @@ public:
   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 );
 
-  void WriteSettings( ostream &out );
+  void WriteSettings( ostream &out ) const;
   void ReadSettings( istream &in );
-  void WriteEvent( ostream &out );
+  void WriteEvent( ostream &out ) const;
   void ReadEvent( istream &in );
-  void WriteTracks( ostream &out );
+  void WriteTracks( ostream &out ) const;
   void ReadTracks( istream &in );
 
 protected:
@@ -89,11 +90,11 @@ protected:
   };
 
   AliHLTTPCCAGBSliceTrackInfo **fSliceTrackInfos; //* additional information for slice tracks
-  Double_t fTime;
+  Double_t fTime; //* total time
   Double_t fStatTime[20]; //* timers 
   Int_t fStatNEvents;    //* n events proceed
+  Int_t fFirstSliceHit[100]; // hit array
 
-  ClassDef(AliHLTTPCCAGBTracker,1) //Base class for conformal mapping tracking
 };
 
 #endif
index 571c85dbc5c6ed02be282ed39761944c202e9ca0..aeb886ef33f361dbc5477d0e8da4515ad4efa06f 100644 (file)
 //***************************************************************************
 
 #include "AliHLTTPCCAGrid.h"
-#include "TMath.h"
+#include "AliHLTTPCCAMath.h"
 
-AliHLTTPCCAGrid::AliHLTTPCCAGrid(const AliHLTTPCCAGrid&)
-  :fGrid(0),fNy(0),fNz(0),fN(0),
-   fYMin(0),fYMax(0),fZMin(0),fZMax(0),fStepYInv(0),fStepZInv(0)
+GPUd() void AliHLTTPCCAGrid::Create( Float_t yMin, Float_t yMax, Float_t zMin, Float_t zMax, UInt_t n )
 {
-  //* dummy
+  //* Create the grid
+  
+  fYMin = CAMath::Min(yMin,yMax);
+  fYMax = CAMath::Max(yMin,yMax);
+  fZMin = CAMath::Min(zMin,zMax);
+  fZMax = CAMath::Max(zMin,zMax);
+  fNy = (UInt_t) CAMath::Sqrt( CAMath::Abs( (Float_t) n ) );
+  fNy = CAMath::Max(fNy,1);
+  fNz = fNy;
+  fN = fNy*fNz;
+  fStepYInv = (fYMax - fYMin);
+  fStepZInv = (fZMax - fZMin);
+  Int_t ky = (fNy>1) ?fNy-1 :1;
+  Int_t kz = (fNz>1) ?fNz-1 :1;
+  fStepYInv =  ( fStepYInv>1.e-4 ) ?ky/fStepYInv :1;
+  fStepZInv =  ( fStepZInv>1.e-4 ) ?kz/fStepZInv :1;
 }
 
-AliHLTTPCCAGrid& AliHLTTPCCAGrid::operator=(const AliHLTTPCCAGrid&)
+GPUd() void AliHLTTPCCAGrid::Create( Float_t yMin, Float_t yMax, Float_t zMin, Float_t zMax, float_t sy, Float_t sz )
 {
-  //* dummy
-  return *this;
+  //* Create the grid
+  
+  fYMin = CAMath::Min(yMin,yMax);
+  fYMax = CAMath::Max(yMin,yMax);
+  fZMin = CAMath::Min(zMin,zMax);
+  fZMax = CAMath::Max(zMin,zMax);
+  fStepYInv = 1./sy;
+  fStepZInv = 1./sz;
+
+  fNy = (UInt_t) ( (fYMax - fYMin)*fStepYInv + 1 );
+  fNz = (UInt_t) ( (fZMax - fZMin)*fStepZInv + 1 );
+  fYMax = fYMin + fNy*sy; 
+  fZMax = fZMin + fNz*sz; 
+  fN = fNy*fNz;
 }
 
-void AliHLTTPCCAGrid::Create( Float_t yMin, Float_t yMax, Float_t zMin, Float_t zMax, Int_t n )
+GPUd() UInt_t AliHLTTPCCAGrid::GetBin( Float_t Y, Float_t Z ) const
 {
-  //* Create the grid
+  //* get the bin pointer
   
-  fYMin = TMath::Min(yMin,yMax);
-  fYMax = TMath::Max(yMin,yMax);
-  fZMin = TMath::Min(zMin,zMax);
-  fZMax = TMath::Max(zMin,zMax);
-  fNy = fNz = (Int_t) TMath::Sqrt( (Float_t) n );
-  fNy = TMath::Max(fNy,1);
-  fNz = TMath::Max(fNz,1);
-  fN = fNy*fNz;
-  if( fGrid ) delete[] fGrid;
-  fGrid = new void*[fN];
-  for( Int_t i=0; i<fN; i++ ) fGrid[i] = 0;
-  fStepYInv = (fYMax - fYMin);
-  fStepZInv = (fZMax - fZMin);
-  fStepYInv =  ( fStepYInv>1.e-4 ) ?(fNy-1)/fStepYInv :0;
-  fStepZInv =  ( fStepZInv>1.e-4 ) ?(fNz-1)/fStepZInv :0;
+  Int_t yBin = (Int_t) CAMath::fmul_rz( Y-fYMin, fStepYInv );
+  Int_t zBin = (Int_t) CAMath::fmul_rz( Z-fZMin, fStepZInv );
+  Int_t bin = CAMath::mul24(zBin,fNy) + yBin;    
+  if( bin<0 ) return 0;
+  if( bin>=(Int_t) fN ) return fN - 1;  
+  return (UInt_t) bin;
 }
 
-void **AliHLTTPCCAGrid::Get( Float_t Y, Float_t Z ) const
+GPUd() void AliHLTTPCCAGrid::GetBin( Float_t Y, Float_t Z, UInt_t &bY, UInt_t &bZ ) const
 {
   //* get the bin pointer
 
-  Int_t yBin = (Int_t) ( (Y-fYMin)*fStepYInv );
-  Int_t zBin = (Int_t) ( (Z-fZMin)*fStepZInv );
-  if( yBin<0 ) yBin = 0;
-  else if( yBin>=fNy ) yBin = fNy - 1;
-  if( zBin<0 ) zBin = 0;
-  else if( zBin>=fNz ) zBin = fNz - 1;
-  return fGrid + zBin*fNy + yBin;
+  Int_t bbY = (Int_t) ( (Y-fYMin)*fStepYInv );
+  Int_t bbZ = (Int_t) ( (Z-fZMin)*fStepZInv );  
+  
+  if( bbY<0 ) bbY = 0;
+  else if( bbY>=(Int_t)fNy ) bbY = fNy - 1;  
+  if( bbZ<0 ) bbZ = 0;
+  else if( bbZ>=(Int_t)fNz ) bbZ = fNz - 1;
+  bY = (UInt_t) bbY;
+  bZ = (UInt_t) bbZ;
 }
index 7e3ec8040fb89a867499629c7e513205bdbbd9b4..86e2eb10e02af25f3057b0abfdf01b49c0d8beb8 100644 (file)
@@ -8,7 +8,7 @@
 #ifndef ALIHLTTPCCAGRID_H
 #define ALIHLTTPCCAGRID_H
 
-#include "Rtypes.h"
+#include "AliHLTTPCCADef.h"
 
 /**
  * @class AliHLTTPCCAGrid
 class AliHLTTPCCAGrid
 {
  public:
-  AliHLTTPCCAGrid():fGrid(0),fNy(0),fNz(0),fN(0),
-    fYMin(0),fYMax(0),fZMin(0),fZMax(0),fStepYInv(0),fStepZInv(0){}
-
-  AliHLTTPCCAGrid(const AliHLTTPCCAGrid&);
-  AliHLTTPCCAGrid &operator=(const AliHLTTPCCAGrid&);
-
-  virtual ~AliHLTTPCCAGrid(){ 
-    if( fGrid ) delete[] fGrid; 
+  
+  GPUd() void Create( Float_t yMin, Float_t yMax, Float_t zMin, Float_t zMax, UInt_t n );
+  GPUd() void Create( Float_t yMin, Float_t yMax, Float_t zMin, Float_t zMax, Float_t sy, Float_t sz  );
+  
+  GPUd() UInt_t GetBin( Float_t Y, Float_t Z ) const;
+  GPUd() void GetBin( Float_t Y, Float_t Z, UInt_t &bY, UInt_t &bZ ) const ;
+  
+  GPUd() UInt_t GetBinNoCheck( Float_t Y, Float_t Z ) const {
+    UInt_t bY = (UInt_t) ( (Y-fYMin)*fStepYInv );
+    UInt_t bZ = (UInt_t) ( (Z-fZMin)*fStepZInv );
+    return bZ*fNy + bY;
   }
-
-  void Create( Float_t yMin, Float_t yMax, Float_t zMin, Float_t zMax, Int_t n );
-
-  void **Get( Float_t Y, Float_t Z ) const;
-
-  void **GetNoCheck( Float_t Y, Float_t Z ) const {
-    Int_t yBin = (Int_t) ( (Y-fYMin)*fStepYInv );
-    Int_t zBin = (Int_t) ( (Z-fZMin)*fStepZInv );
-    return fGrid + zBin*fNy + yBin;
+  
+  GPUd() void GetBinNoCheck( Float_t Y, Float_t Z, UInt_t &bY, UInt_t &bZ ) const {
+    bY = (UInt_t) ( (Y-fYMin)*fStepYInv );
+    bZ = (UInt_t) ( (Z-fZMin)*fStepZInv );    
   }
 
-  Int_t N() const { return fN; }
-  Int_t Ny() const { return fNy; }
-  Int_t Nz() const { return fNz; }
-  Float_t YMin() const { return fYMin; }
-  Float_t YMax() const { return fYMax; }
-  Float_t ZMin() const { return fZMin; }
-  Float_t ZMax() const { return fZMax; }
-  Float_t StepYInv() const { return fStepYInv; }
-  Float_t StepZInv() const { return fStepZInv; }
-  void **Grid(){ return fGrid; }
 
- protected:
+  GPUd() UInt_t  N()  const { return fN;  }
+  GPUd() UInt_t  Ny() const { return fNy; }
+  GPUd() UInt_t  Nz() const { return fNz; }
+  GPUd() Float_t YMin() const { return fYMin; }
+  GPUd() Float_t YMax() const { return fYMax; }
+  GPUd() Float_t ZMin() const { return fZMin; }
+  GPUd() Float_t ZMax() const { return fZMax; }
+  GPUd() Float_t StepYInv() const { return fStepYInv; }
+  GPUd() Float_t StepZInv() const { return fStepZInv; }
+  GPUhd() UInt_t &Content2() { return fContent2;}
+  GPUhd() UInt_t &Offset() { return fOffset;}    
+
+  private:
 
-  void **fGrid;      //* the grid as 1-d array
-  Int_t fNy;         //* N bins in Y
-  Int_t fNz;         //* N bins in Z
-  Int_t fN;          //* total N bins
+  UInt_t fNy;        //* N bins in Y
+  UInt_t fNz;        //* N bins in Z
+  UInt_t fN;         //* total N bins
   Float_t fYMin;     //* minimal Y value
   Float_t fYMax;     //* maximal Y value
   Float_t fZMin;     //* minimal Z value
   Float_t fZMax;     //* maximal Z value
   Float_t fStepYInv; //* inverse bin size in Y
   Float_t fStepZInv; //* inverse bin size in Z
-  
-};
 
+  UInt_t fContent2;  //* content of the fN/2 bin [4 bytes ]
+  UInt_t fOffset;    //* offset of this Grid content in the common content array
+};
 
 #endif
index f414bea564bdb1250e1ad111a152d97162d8c5e5..5796d162b37b786bf93cdd6be6f0bac9e67267c2 100644 (file)
@@ -8,7 +8,7 @@
 #ifndef ALIHLTTPCCAHIT_H
 #define ALIHLTTPCCAHIT_H
 
-#include "Rtypes.h"
+#include "AliHLTTPCCADef.h"
 
 /**
  * @class AliHLTTPCCAHit
  */
 class AliHLTTPCCAHit
 {
- public:
-  AliHLTTPCCAHit(): fY(0),fZ(0),fErrY(0),fErrZ(0),fID(0){;}
-  virtual ~AliHLTTPCCAHit(){}
-
-  Float_t &Y()   { return fY;    }
-  Float_t &Z()   { return fZ;    }
-  Float_t &ErrY(){ return fErrY; } 
-  Float_t &ErrZ(){ return fErrZ; }
+public:
+  
+  GPUhd() Float_t &Y()   { return fY;    }
+  GPUhd() Float_t &Z()   { return fZ;    }
+  
+  //protected:
   
-  Int_t &ID(){ return fID; }
-  void Set( Int_t id, Float_t y, Float_t z, 
-           Float_t errY, Float_t errZ  );
-
- protected:
-
   Float_t fY, fZ;       // Y and Z position of the TPC cluster
-  Float_t fErrY, fErrZ; // position errors
-  Int_t fID;            // external unique ID of this hit, 
-                        // used as cluster index in track->hit reference array
- private:
-
-  void Dummy(); // to make rulechecker happy by having something in .cxx file
   
 };
 
 
-
-inline void AliHLTTPCCAHit::Set( Int_t id, Float_t y, Float_t z, 
-                                Float_t errY, Float_t errZ  )
-{
-  //* set parameters
-  fID = id;
-  fY = y;
-  fZ = z;
-  fErrY = errY;
-  fErrZ = errZ;
-}
-
-
 #endif
diff --git a/HLT/TPCLib/tracking-ca/AliHLTTPCCAHitArea.cxx b/HLT/TPCLib/tracking-ca/AliHLTTPCCAHitArea.cxx
new file mode 100644 (file)
index 0000000..21a499f
--- /dev/null
@@ -0,0 +1,111 @@
+//***************************************************************************
+// This file is property of and copyright by the ALICE HLT Project          * 
+// ALICE Experiment at CERN, All rights reserved.                           *
+//                                                                          *
+// Primary Authors: Sergey Gorbunov <sergey.gorbunov@kip.uni-heidelberg.de> *
+//                  Ivan Kisel <kisel@kip.uni-heidelberg.de>                *
+//                  for The ALICE HLT Project.                              *
+//                                                                          *
+// Permission to use, copy, modify and distribute this software and its     *
+// documentation strictly for non-commercial purposes is hereby granted     *
+// without fee, provided that the above copyright notice appears in all     *
+// copies and that both the copyright notice and this permission notice     *
+// appear in the supporting documentation. The authors make no claims       *
+// about the suitability of this software for any purpose. It is            *
+// provided "as is" without express or implied warranty.                    *
+//***************************************************************************
+
+#include "AliHLTTPCCAHitArea.h"
+#include "AliHLTTPCCATracker.h"
+#include "AliHLTTPCCAGrid.h"
+#include "AliHLTTPCCAHit.h"
+
+
+GPUd() void AliHLTTPCCAHitAreaInit( AliHLTTPCCAHitArea &a, AliHLTTPCCATracker &tracker, AliHLTTPCCAGrid &grid, UInt_t hitoffset, Float_t y, Float_t z, Float_t dy, Float_t dz )
+{ 
+  // initialisation
+
+  UInt_t gridOffset = grid.Offset();
+  a.HitOffset() = hitoffset;
+  a.Y() = y;
+  a.Z() = z;
+  a.MinZ() = z-dz; 
+  a.MaxZ() = z+dz;
+  a.MinY() = y-dy;
+  a.MaxY() = y+dy;
+  UInt_t bYmin, bZmin, bYmax;  
+  grid.GetBin(a.MinY(), a.MinZ(), bYmin, bZmin);
+  grid.GetBin(a.MaxY(), a.MaxZ(), bYmax, a.BZmax());  
+  a.BDY() = bYmax - bYmin + 1;
+  a.Ny() = grid.Ny();
+  a.N2() = gridOffset + (grid.N()>>1);
+  a.C2() = grid.Content2();
+  a.IndYmin() = gridOffset + bZmin*a.Ny() + bYmin;
+  a.Iz() = bZmin; 
+  a.HitYfst() = tracker.GetGridContent((UInt_t)( a.IndYmin()));
+  a.HitYlst() = tracker.GetGridContent((UInt_t)( a.IndYmin() + a.BDY()));    
+  if( a.IndYmin()>=a.N2() ) a.HitYfst()+=a.C2();
+  if( a.IndYmin()+ a.BDY() >=a.N2() ) a.HitYlst()+=a.C2();
+  a.Ih() = a.HitYfst(); 
+}
+
+
+GPUd() void AliHLTTPCCAHitArea::Init( AliHLTTPCCATracker &tracker,AliHLTTPCCAGrid &grid, UInt_t hitoffset, Float_t y, Float_t z, Float_t dy, Float_t dz )
+{ 
+  //initialisation
+  AliHLTTPCCAHitAreaInit(*this, tracker, grid, hitoffset, y, z, dy, dz);
+}
+
+GPUd() Int_t AliHLTTPCCAHitArea::GetNext(AliHLTTPCCATracker &tracker, AliHLTTPCCAHit &h)
+{    
+  // get next hit index
+  Int_t ret = -1;
+  do{
+    while( fIh>=fHitYlst ){
+      if( fIz>=fBZmax ) return -1;
+      fIz++;
+      fIndYmin += fNy;
+      fHitYfst = tracker.GetGridContent((UInt_t)( fIndYmin));
+      fHitYlst = tracker.GetGridContent((UInt_t)( fIndYmin + fBDY));      
+      if( fIndYmin>=fn2 ) fHitYfst+=fc2;
+      if( fIndYmin+ fBDY>=fn2 ) fHitYlst+=fc2;
+      fIh = fHitYfst;
+    }
+    
+    h = tracker.GetHit( fHitOffset + fIh );    
+    
+    if( h.fZ>fMaxZ || h.fZ<fMinZ || h.fY<fMinY || h.fY>fMaxY ){
+      fIh++;
+      continue;
+    }
+    ret = fIh;
+    fIh++;
+    break;
+  } while(1);
+  return ret; 
+}
+
+
+
+GPUd() Int_t AliHLTTPCCAHitArea::GetBest(AliHLTTPCCATracker &tracker, AliHLTTPCCAHit &h)
+{
+  // get closest hit in the area
+  Int_t best = -1;
+  Float_t ds = 1.e10;
+  do{
+    AliHLTTPCCAHit hh;
+    Int_t ih=GetNext( tracker, hh ); 
+    if( ih<0 ) break;
+    Float_t dy = hh.fY - fY;
+    Float_t dz = hh.fZ - fZ;
+    Float_t dds = dy*dy+dz*dz;
+    if( dds<ds ){
+      ds = dds;
+      best = ih;
+      h = hh;
+    }
+  }while(1);
+
+  return best;
+}
+
diff --git a/HLT/TPCLib/tracking-ca/AliHLTTPCCAHitArea.h b/HLT/TPCLib/tracking-ca/AliHLTTPCCAHitArea.h
new file mode 100644 (file)
index 0000000..c08a699
--- /dev/null
@@ -0,0 +1,55 @@
+//-*- Mode: C++ -*-
+// @(#) $Id: AliHLTTPCCARow.h 27042 2008-07-02 12:06:02Z richterm $
+
+//* 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 ALIHLTTPCCAHITAREA_H
+#define ALIHLTTPCCAHITAREA_H
+
+
+#include "AliHLTTPCCADef.h"
+
+class AliHLTTPCCAHit;
+class AliHLTTPCCAGrid;
+class AliHLTTPCCATracker;
+
+/**
+ * @class ALIHLTTPCCAHitArea
+ *
+ */
+class AliHLTTPCCAHitArea
+{
+public:
+  
+  GPUd() void Init( AliHLTTPCCATracker &tracker, AliHLTTPCCAGrid &grid, UInt_t hitoffset, Float_t y, Float_t z, Float_t dy, Float_t dz );
+  GPUd() Int_t GetNext(AliHLTTPCCATracker &tracker, AliHLTTPCCAHit &h);
+  GPUd() Int_t GetBest(AliHLTTPCCATracker &tracker, AliHLTTPCCAHit &h );
+
+  GPUhd() Float_t& Y(){ return fY;}
+  GPUhd() Float_t& Z(){ return fZ;}
+  GPUhd() Float_t& MinZ(){ return fMinZ;}
+  GPUhd() Float_t& MaxZ(){ return fMaxZ;}
+  GPUhd() Float_t& MinY(){ return fMinY;}
+  GPUhd() Float_t& MaxY(){ return fMaxY;}
+  GPUhd() UInt_t&  BZmax(){ return fBZmax;}
+  GPUhd() UInt_t&  BDY(){ return fBDY;}
+  GPUhd() UInt_t&  IndYmin(){ return fIndYmin;}
+  GPUhd() UInt_t&  Iz(){ return fIz;}
+  GPUhd() UInt_t&  HitYfst(){ return fHitYfst;}
+  GPUhd() UInt_t&  HitYlst(){ return fHitYlst;}
+  GPUhd() UInt_t&  Ih(){ return fIh;}
+  GPUhd() UInt_t&  Ny(){ return fNy;}
+  GPUhd() UInt_t&  N2(){ return fn2;}
+  GPUhd() UInt_t&  C2(){ return fc2;}
+  GPUhd() UInt_t&  HitOffset(){ return fHitOffset;}
+
+  protected:
+
+  Float_t fY, fZ, fMinZ, fMaxZ, fMinY, fMaxY;    // search coordinates
+  UInt_t fBZmax, fBDY, fIndYmin, fIz, fHitYfst, fHitYlst, fIh, fNy, fn2, fc2; // !
+  UInt_t fHitOffset; // global hit offset
+};
+
+#endif
similarity index 57%
rename from HLT/TPCLib/tracking-ca/AliHLTTPCCAEndPoint.cxx
rename to HLT/TPCLib/tracking-ca/AliHLTTPCCALinksWriter.cxx
index 30532d23dda51f9fa3eb2378893e27e0e627f530..e1a4545834a515946849aaf5a075cfa7d2f0449d 100644 (file)
@@ -1,4 +1,4 @@
-// $Id$
+// @(#) $Id: AliHLTTPCCANeighboursCleaner.cxx 27042 2008-07-02 12:06:02Z richterm $
 //***************************************************************************
 // This file is property of and copyright by the ALICE HLT Project          * 
 // ALICE Experiment at CERN, All rights reserved.                           *
 // provided "as is" without express or implied warranty.                    *
 //***************************************************************************
 
-#include "AliHLTTPCCAEndPoint.h"
+#include "AliHLTTPCCALinksWriter.h"
+#include "AliHLTTPCCATracker.h"
 
-void AliHLTTPCCAEndPoint::Dummy()
+GPUd() void AliHLTTPCCALinksWriter::Thread
+( Int_t nBlocks, Int_t nThreads, Int_t iBlock, Int_t iThread, Int_t iSync,
+  AliHLTTPCCASharedMemory &/*s*/, AliHLTTPCCATracker &tracker )
 {
-  //* do nothing
+  // copy constructed links to the new data scheme (temporary)
+
+  if( iSync==0 )
+    {
+      for( int irow=iBlock; irow<tracker.Param().NRows(); irow+=nBlocks ){
+       AliHLTTPCCARow &row = tracker.Rows()[irow];
+       Short_t *hitLinkUp = tracker.HitLinkUp() + row.FirstHit() ;
+       Short_t *hitLinkDown = tracker.HitLinkDown() + row.FirstHit();
+       Short_t *newUp = ((Short_t*)(tracker.TexHitsFullData() + row.FullOffset())) + row.FullLinkOffset();
+       Short_t *newDown = newUp + row.NHits();
+       
+       for( int ih=iThread; ih<row.NHits(); ih+=nThreads ){
+         newUp[ih] = hitLinkUp[ih];
+         newDown[ih] = hitLinkDown[ih];
+       }
+      }
+    }
 }
diff --git a/HLT/TPCLib/tracking-ca/AliHLTTPCCALinksWriter.h b/HLT/TPCLib/tracking-ca/AliHLTTPCCALinksWriter.h
new file mode 100644 (file)
index 0000000..8dd5d71
--- /dev/null
@@ -0,0 +1,31 @@
+//-*- Mode: C++ -*-
+
+//* 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 ALIHLTTPCCALINKSWRITER_H
+#define ALIHLTTPCCALINKSWRITER_H
+
+
+#include "AliHLTTPCCADef.h"
+
+class AliHLTTPCCATracker;
+
+/**
+ * 
+ */
+class AliHLTTPCCALinksWriter
+{
+ public:
+  class AliHLTTPCCASharedMemory{};
+  
+  GPUd() static Int_t NThreadSyncPoints(){ return 0; }  
+
+  GPUd() static void Thread( Int_t nBlocks, Int_t nThreads, Int_t iBlock, Int_t iThread, Int_t iSync,
+                            AliHLTTPCCASharedMemory &smem, AliHLTTPCCATracker &tracker );
+  
+};
+
+
+#endif
index eb9dff2cd7e8ec8279ec7fe5788860210b34204d..c1ff78d1b1b2a917d6cf40168a21b623c7d0ce10 100644 (file)
@@ -7,7 +7,7 @@
 #ifndef ALIHLTTPCCAMCPOINT_H
 #define ALIHLTTPCCAMCPOINT_H
 
-#include "Rtypes.h"
+#include "AliHLTTPCCADef.h"
 
 
 /**
index 45e099a824f69fe26fb8b1fceaaa14344abb61fa..f9923c14a05715d75b1887290e369a92d1822f0b 100644 (file)
@@ -19,7 +19,7 @@
 #include "AliHLTTPCCAMCTrack.h"
 #include "TParticle.h"
 #include "TDatabasePDG.h"
-#include "TMath.h"
+#include "AliHLTTPCCAMath.h"
 
 
 AliHLTTPCCAMCTrack::AliHLTTPCCAMCTrack()
@@ -54,7 +54,7 @@ AliHLTTPCCAMCTrack::AliHLTTPCCAMCTrack( const TParticle *part )
   fPar[5] = part->Pz()*pi;
   fPar[6] = 0;
   fPDG  = part->GetPdgCode();    
-  if ( TMath::Abs(fPDG) < 100000 ){
+  if ( CAMath::Abs(fPDG) < 100000 ){
     TParticlePDG *pPDG = TDatabasePDG::Instance()->GetParticle(fPDG);
     if( pPDG ) fPar[6] = pPDG->Charge()/3.0*pi;
   }
@@ -70,13 +70,13 @@ void AliHLTTPCCAMCTrack::SetTPCPar( Float_t X, Float_t Y, Float_t Z,
   fTPCPar[0] = X;
   fTPCPar[1] = Y;
   fTPCPar[2] = Z;
-  Double_t p = TMath::Sqrt(Px*Px + Py*Py + Pz*Pz);
+  Double_t p = CAMath::Sqrt(Px*Px + Py*Py + Pz*Pz);
   Double_t pi = ( p >1.e-4 ) ?1./p :0;
   fTPCPar[3] = Px*pi;
   fTPCPar[4] = Py*pi;
   fTPCPar[5] = Pz*pi;
   fTPCPar[6] = 0;
-  if ( TMath::Abs(fPDG) < 100000 ){
+  if ( CAMath::Abs(fPDG) < 100000 ){
     TParticlePDG *pPDG = TDatabasePDG::Instance()->GetParticle(fPDG);
     if( pPDG ) fTPCPar[6] = pPDG->Charge()/3.0*pi;
   }
index cd3d793bd4ea34f1780f09235d3f8e76191e0165..a2d97d50450cc8723599d0a5797151ed3d4248fd 100644 (file)
@@ -8,7 +8,7 @@
 #ifndef ALIHLTTPCCAMCTRACK_H
 #define ALIHLTTPCCAMCTRACK_H
 
-#include "Rtypes.h"
+#include "AliHLTTPCCADef.h"
 
 class TParticle;
 
diff --git a/HLT/TPCLib/tracking-ca/AliHLTTPCCAMath.h b/HLT/TPCLib/tracking-ca/AliHLTTPCCAMath.h
new file mode 100644 (file)
index 0000000..ca6f9f7
--- /dev/null
@@ -0,0 +1,223 @@
+//-*- Mode: C++ -*-
+// @(#) $Id: AliHLTTPCCARow.h 27042 2008-07-02 12:06:02Z richterm $
+
+//* 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 ALIHLTTPCCAMATH_H
+#define ALIHLTTPCCAMATH_H
+
+#include "AliHLTTPCCADef.h"
+
+#if defined(HLTCA_STANDALONE) || defined(HLTCA_GPUCODE)
+#include <math.h>
+#else
+#include "TMath.h"
+#endif
+
+/**
+ * @class ALIHLTTPCCAMath
+ *
+ *
+ */
+class AliHLTTPCCAMath
+{
+public:
+  GPUd() static Float_t Min(Float_t x, Float_t y);
+  GPUd() static Float_t Max(Float_t x, Float_t y);
+  GPUd() static Int_t Min(Int_t x, Int_t y);
+  GPUd() static Int_t Max(Int_t x, Int_t y);
+  GPUd() static Float_t Sqrt(Float_t x );
+  GPUd() static Float_t Abs(Float_t x );
+  GPUd() static Double_t Abs(Double_t x );
+  GPUd() static Int_t Abs(Int_t x );
+  GPUd() static Float_t ASin(Float_t x );
+  GPUd() static Float_t ATan2( Float_t y, Float_t x );
+  GPUd() static Float_t Sin( Float_t x );
+  GPUd() static Float_t Cos( Float_t x );
+  GPUd() static Float_t Tan( Float_t x );
+  GPUd() static Float_t Copysign( Float_t x, Float_t y );  
+  GPUd() static Float_t TwoPi(){ return 6.28319; }
+  GPUd() static Float_t Pi(){ return 3.1415926535897; }
+  GPUd() static Int_t Nint(Float_t x );
+  GPUd() static Bool_t Finite(Float_t x );
+
+  GPUd()  static Int_t atomicExch( Int_t *addr, Int_t val);
+  GPUd()  static Int_t atomicAdd ( Int_t *addr, Int_t val);
+  GPUd()  static Int_t atomicMax ( Int_t *addr, Int_t val);
+  GPUd()  static Int_t atomicMin ( Int_t *addr, Int_t val);
+  GPUd()  static Int_t mul24( Int_t a, Int_t b );
+  GPUd()  static Float_t fmul_rz( Float_t a, Float_t b );
+};
+
+typedef AliHLTTPCCAMath CAMath;
+
+
+#if defined( HLTCA_GPUCODE )
+#define choice(c1,c2,c3) c1
+#elif defined( HLTCA_STANDALONE )
+#define choice(c1,c2,c3) c2
+#else
+#define choice(c1,c2,c3) c3
+#endif
+
+
+GPUd() inline Int_t AliHLTTPCCAMath::Nint(Float_t x)
+{  
+#if defined(HLTCA_STANDALONE) || defined( HLTCA_GPUCODE )
+  int i;
+  if (x >= 0) {
+    i = int(x + 0.5);
+    if (x + 0.5 == Float_t(i) && i & 1) i--;
+  } else {
+    i = int(x - 0.5);
+    if (x - 0.5 == Float_t(i) && i & 1) i++;    
+  }
+  return i;
+#else
+  return TMath::Nint(x);
+#endif
+}
+
+GPUd() inline Bool_t AliHLTTPCCAMath::Finite(Float_t x)
+{  
+  return choice( 1, finite(x), finite(x) );
+}
+
+GPUd() inline Float_t AliHLTTPCCAMath::ATan2(Float_t y, Float_t x)
+{ 
+  return choice(atan2f(y,x), atan2(y,x), TMath::ATan2(y,x) );
+}
+
+
+GPUd() inline Float_t AliHLTTPCCAMath::Copysign(Float_t x, Float_t y)
+{ 
+#if defined( HLTCA_GPUCODE )
+  return copysignf(x,y);
+#else
+  x = CAMath::Abs(x);
+  return (y>=0) ?x : -x;
+#endif
+}
+
+
+GPUd() inline Float_t AliHLTTPCCAMath::Sin(Float_t x)
+{ 
+  return choice( sinf(x), sin(x), TMath::Sin(x) );
+}
+
+GPUd() inline Float_t AliHLTTPCCAMath::Cos(Float_t x)
+{ 
+  return choice( cosf(x), cos(x), TMath::Cos(x) );
+}
+
+GPUd() inline Float_t AliHLTTPCCAMath::Tan(Float_t x)
+{ 
+  return choice( tanf(x), tan(x), TMath::Tan(x) );
+}
+
+GPUd() inline Float_t AliHLTTPCCAMath::Min(Float_t x, Float_t y)
+{ 
+  return choice( fminf(x,y),  (x<y ?x :y), TMath::Min(x,y) );
+}
+
+GPUd() inline Float_t AliHLTTPCCAMath::Max(Float_t x, Float_t y)
+{ 
+  return choice( fmaxf(x,y),  (x>y ?x :y), TMath::Max(x,y) );
+}
+
+GPUd() inline Int_t AliHLTTPCCAMath::Min(Int_t x, Int_t y)
+{ 
+  return choice( min(x,y),  (x<y ?x :y), TMath::Min(x,y) );
+}
+
+GPUd() inline Int_t AliHLTTPCCAMath::Max(Int_t x, Int_t y)
+{ 
+  return choice( max(x,y),  (x>y ?x :y), TMath::Max(x,y) );
+}
+
+GPUd() inline Float_t AliHLTTPCCAMath::Sqrt(Float_t x )
+{ 
+  return choice( sqrtf(x), sqrt(x), TMath::Sqrt(x) );
+}
+
+GPUd() inline Float_t AliHLTTPCCAMath::Abs(Float_t x )
+{ 
+  return choice( fabsf(x), fabs(x), TMath::Abs(x) );
+}
+
+GPUd() inline Double_t AliHLTTPCCAMath::Abs(Double_t x )
+{ 
+  return choice( fabs(x), fabs(x), TMath::Abs(x) );
+}
+
+GPUd() inline Int_t AliHLTTPCCAMath::Abs(Int_t x )
+{ 
+  return choice( abs(x), (x>=0 ?x :-x), TMath::Abs(x) );
+}
+
+GPUd() inline Float_t AliHLTTPCCAMath::ASin(Float_t x )
+{ 
+  return choice( asinf(x), asin(x), TMath::ASin(x) );
+}
+
+
+GPUd() inline Int_t AliHLTTPCCAMath::mul24( Int_t a, Int_t b )
+{
+  return choice( __mul24(a,b), a*b, a*b );
+}
+
+GPUd() inline Float_t AliHLTTPCCAMath::fmul_rz( Float_t a, Float_t b )
+{
+  return choice( __fmul_rz(a,b), a*b, a*b );
+}
+
+
+GPUd()  inline Int_t AliHLTTPCCAMath::atomicExch( Int_t *addr, Int_t val)
+{
+#if defined( HLTCA_GPUCODE )
+  return ::atomicExch(addr, val );
+#else  
+  Int_t old = *addr;
+  *addr = val;
+  return old;
+#endif
+}
+
+GPUd()  inline Int_t AliHLTTPCCAMath::atomicAdd ( Int_t *addr, Int_t val)
+{
+#if defined( HLTCA_GPUCODE )
+  return ::atomicAdd(addr, val );
+#else  
+  Int_t old = *addr;
+  *addr += val;
+  return old;
+#endif
+}
+
+GPUd()  inline Int_t AliHLTTPCCAMath::atomicMax ( Int_t *addr, Int_t val)
+{
+#if defined( HLTCA_GPUCODE )
+  return ::atomicMax(addr, val );
+#else  
+  Int_t old = *addr;
+  if( *addr< val ) *addr = val;
+  return old;
+#endif
+}
+
+GPUd()  inline Int_t AliHLTTPCCAMath::atomicMin ( Int_t *addr, Int_t val)
+{
+#if defined( HLTCA_GPUCODE )
+  return ::atomicMin(addr, val );
+#else  
+  Int_t old = *addr;
+  if( *addr> val ) *addr = val;
+  return old;
+#endif
+}
+
+#undef CHOICE
+
+#endif
diff --git a/HLT/TPCLib/tracking-ca/AliHLTTPCCANeighboursCleaner.cxx b/HLT/TPCLib/tracking-ca/AliHLTTPCCANeighboursCleaner.cxx
new file mode 100644 (file)
index 0000000..ba36388
--- /dev/null
@@ -0,0 +1,70 @@
+// @(#) $Id: AliHLTTPCCANeighboursCleaner.cxx 27042 2008-07-02 12:06:02Z richterm $
+//***************************************************************************
+// This file is property of and copyright by the ALICE HLT Project          * 
+// ALICE Experiment at CERN, All rights reserved.                           *
+//                                                                          *
+// Primary Authors: Sergey Gorbunov <sergey.gorbunov@kip.uni-heidelberg.de> *
+//                  Ivan Kisel <kisel@kip.uni-heidelberg.de>                *
+//                  for The ALICE HLT Project.                              *
+//                                                                          *
+// Permission to use, copy, modify and distribute this software and its     *
+// documentation strictly for non-commercial purposes is hereby granted     *
+// without fee, provided that the above copyright notice appears in all     *
+// copies and that both the copyright notice and this permission notice     *
+// appear in the supporting documentation. The authors make no claims       *
+// about the suitability of this software for any purpose. It is            *
+// provided "as is" without express or implied warranty.                    *
+//***************************************************************************
+
+#include "AliHLTTPCCANeighboursCleaner.h"
+#include "AliHLTTPCCAMath.h"
+#include "AliHLTTPCCATracker.h"
+
+GPUd() void AliHLTTPCCANeighboursCleaner::Thread 
+( Int_t nBlocks, Int_t nThreads, Int_t iBlock, Int_t iThread, Int_t iSync,
+  AliHLTTPCCASharedMemory &s, AliHLTTPCCATracker &tracker )
+{
+  // *
+  // * kill link to the neighbour if the neighbour is not pointed to the hit
+  // *
+
+  if( iSync==0 )
+    {
+      if( iThread==0 ){
+       s.fNRows = tracker.Param().NRows();
+       s.fIRow = iBlock+1;
+       if( s.fIRow <= s.fNRows-2 ){
+         int iRowUp = s.fIRow+1;
+         int iRowDn = s.fIRow-1;  
+         int firstDn = tracker.Rows()[iRowDn].FirstHit();
+         s.fFirstHit = tracker.Rows()[s.fIRow].FirstHit(); 
+         int firstUp = tracker.Rows()[iRowUp].FirstHit();
+         Short_t *hhitLinkUp = tracker.HitLinkUp();
+         Short_t *hhitLinkDown = tracker.HitLinkDown();
+         s.fHitLinkUp = hhitLinkUp + s.fFirstHit;
+         s.fHitLinkDown = hhitLinkDown + s.fFirstHit;    
+         s.fNHits = firstUp - s.fFirstHit;
+         s.fUpHitLinkDown = hhitLinkDown + firstUp;
+         s.fDnHitLinkUp   = hhitLinkUp + firstDn;
+       }
+      }
+    } 
+  else if( iSync==1 )
+    {
+      if( s.fIRow <= s.fNRows-2 ){
+       for( int ih=iThread; ih<s.fNHits; ih+=nThreads ){
+         int up = s.fHitLinkUp[ih];
+         int dn = s.fHitLinkDown[ih];
+         if( (up>=0) && ( s.fUpHitLinkDown[up] != ih) ){
+           s.fHitLinkUp[ih]= -1;      
+           //HLTCA_GPU_SUFFIX(CAMath::atomicExch)( tracker.HitLinkUp() + s.fFirstHit+ih, -1 );      
+         }
+         if( (dn>=0) && ( s.fDnHitLinkUp  [dn] != ih) ){
+           s.fHitLinkDown[ih]=-1;
+           //HLTCA_GPU_SUFFIX(CAMath::atomicExch)( tracker.HitLinkDown() + s.fFirstHit+ih,-1);
+         }
+       }
+      }
+    }
+}
+
diff --git a/HLT/TPCLib/tracking-ca/AliHLTTPCCANeighboursCleaner.h b/HLT/TPCLib/tracking-ca/AliHLTTPCCANeighboursCleaner.h
new file mode 100644 (file)
index 0000000..5167a1a
--- /dev/null
@@ -0,0 +1,51 @@
+//-*- Mode: C++ -*-
+
+//* 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 ALIHLTTPCCANEIGHBOURSCLEANER_H
+#define ALIHLTTPCCANEIGHBOURSCLEANER_H
+
+
+#include "AliHLTTPCCADef.h"
+
+class AliHLTTPCCATracker;
+
+/**
+ * @class AliHLTTPCCANeighboursCleaner
+ * 
+ */
+class AliHLTTPCCANeighboursCleaner
+{
+ public:
+  class AliHLTTPCCASharedMemory
+    {
+     friend class AliHLTTPCCANeighboursCleaner;
+    public:
+#if !defined(HLTCA_GPUCODE)
+      AliHLTTPCCASharedMemory()
+       :fIRow(0),fNRows(0),fNHits(0),fHitLinkDown(0),fHitLinkUp(0),fUpHitLinkDown(0),fDnHitLinkUp(0),fFirstHit(0){}
+      AliHLTTPCCASharedMemory( const AliHLTTPCCASharedMemory& /*dummy*/) 
+       :fIRow(0),fNRows(0),fNHits(0),fHitLinkDown(0),fHitLinkUp(0),fUpHitLinkDown(0),fDnHitLinkUp(0),fFirstHit(0) {}
+      AliHLTTPCCASharedMemory& operator=(const AliHLTTPCCASharedMemory& /*dummy*/){ return *this; }
+#endif
+    protected:
+      Int_t fIRow; // current row index
+      Int_t fNRows; // number of rows
+      Int_t fNHits; // number of hits
+      Short_t *fHitLinkDown; // links to the previous row
+      Short_t *fHitLinkUp; // links to the next row
+      Short_t *fUpHitLinkDown; // links from next row
+      Short_t *fDnHitLinkUp; // links from previous row
+      Int_t fFirstHit; // index of the first row hit in global arrays 
+    };
+
+  GPUd() static Int_t NThreadSyncPoints(){ return 1; }  
+
+  GPUd() static void Thread( Int_t nBlocks, Int_t nThreads, Int_t iBlock, Int_t iThread, Int_t iSync,
+                            AliHLTTPCCASharedMemory &smem, AliHLTTPCCATracker &tracker );
+};
+
+
+#endif
diff --git a/HLT/TPCLib/tracking-ca/AliHLTTPCCANeighboursFinder.cxx b/HLT/TPCLib/tracking-ca/AliHLTTPCCANeighboursFinder.cxx
new file mode 100644 (file)
index 0000000..3991fb1
--- /dev/null
@@ -0,0 +1,150 @@
+// @(#) $Id: AliHLTTPCCANeighboursFinder.cxx 27042 2008-07-02 12:06:02Z richterm $
+//***************************************************************************
+// This file is property of and copyright by the ALICE HLT Project          * 
+// ALICE Experiment at CERN, All rights reserved.                           *
+//                                                                          *
+// Primary Authors: Sergey Gorbunov <sergey.gorbunov@kip.uni-heidelberg.de> *
+//                  Ivan Kisel <kisel@kip.uni-heidelberg.de>                *
+//                  for The ALICE HLT Project.                              *
+//                                                                          *
+// Permission to use, copy, modify and distribute this software and its     *
+// documentation strictly for non-commercial purposes is hereby granted     *
+// without fee, provided that the above copyright notice appears in all     *
+// copies and that both the copyright notice and this permission notice     *
+// appear in the supporting documentation. The authors make no claims       *
+// about the suitability of this software for any purpose. It is            *
+// provided "as is" without express or implied warranty.                    *
+//***************************************************************************
+
+#include "AliHLTTPCCANeighboursFinder.h"
+#include "AliHLTTPCCAMath.h"
+#include "AliHLTTPCCAHitArea.h"
+#include "AliHLTTPCCATracker.h"
+
+GPUd() void AliHLTTPCCANeighboursFinder::Thread
+( Int_t /*nBlocks*/, Int_t nThreads, Int_t iBlock, Int_t iThread, Int_t iSync,
+  AliHLTTPCCASharedMemory &s, AliHLTTPCCATracker &tracker )
+{
+  //* find neighbours
+
+  if( iSync==0 )
+    {
+      if( iThread==0 ){
+       s.fNRows = tracker.Param().NRows();
+       s.fIRow = iBlock;
+       if( s.fIRow < s.fNRows ){
+         s.fFirst = tracker.Rows()[s.fIRow].FirstHit();      
+         s.fHitLinkUp = tracker.HitLinkUp() + s.fFirst;
+         s.fHitLinkDn = tracker.HitLinkDown() + s.fFirst;
+         s.fNHits = tracker.Rows()[s.fIRow].NHits();
+         if( (s.fIRow>0) && (s.fIRow<s.fNRows-1) ){
+           s.fIRowUp = s.fIRow+1;
+           s.fIRowDn = s.fIRow-1; 
+           s.fFirstDn = tracker.Rows()[s.fIRowDn].FirstHit();
+           s.fFirstUp = tracker.Rows()[s.fIRowUp].FirstHit();
+           float xDn = tracker.Rows()[s.fIRowDn].X();
+           float x = tracker.Rows()[s.fIRow].X();
+           float xUp = tracker.Rows()[s.fIRowUp].X();
+           s.fUpNHits = tracker.Rows()[s.fIRowUp].NHits();
+           s.fDnNHits = s.fFirst - s.fFirstDn;
+           s.fUpDx = xUp - x;
+           s.fDnDx = xDn - x;
+           s.fUpTx = xUp/x;
+           s.fDnTx = xDn/x;
+           s.fGridUp = tracker.Rows()[s.fIRowUp].Grid();
+           s.fGridDn = tracker.Rows()[s.fIRowDn].Grid();
+         }
+       }
+      }
+    } 
+  else if( iSync==1 )
+    {
+      if( s.fIRow < s.fNRows ){
+       if( (s.fIRow==0) || (s.fIRow==s.fNRows-1) ){
+         for( int ih=iThread; ih<s.fNHits; ih+=nThreads ){
+           s.fHitLinkUp[ih] = -1;
+           s.fHitLinkDn[ih] = -1;
+         }
+       }else if(0){
+         for( UInt_t ih=iThread; ih<s.fGridUp.N()+1; ih+=nThreads ){
+           s.fGridContentUp[ih] = tracker.GetGridContent(s.fGridUp.Offset()+ih);
+         }
+         for( UInt_t ih=iThread; ih<s.fGridDn.N()+1; ih+=nThreads ){
+           s.fGridContentDn[ih] = tracker.GetGridContent(s.fGridDn.Offset()+ih);
+         }
+       }
+      }
+    }
+  else if( iSync==2 )
+    {
+      if( (s.fIRow<=0) || (s.fIRow >= s.fNRows-1) ) return;
+      
+      const float kAreaSize = 3;     
+      float chi2Cut = 3.*3.*4*(s.fUpDx*s.fUpDx + s.fDnDx*s.fDnDx );
+      const Int_t kMaxN = 5;
+
+      for( int ih=iThread; ih<s.fNHits; ih+=nThreads ){        
+
+       UShort_t *neighUp = s.fB[iThread];
+       float2 *yzUp = s.fA[iThread];
+       
+       int linkUp = -1;
+       int linkDn = -1;
+       
+       if( s.fDnNHits>=1 && s.fUpNHits>=1 ){
+         
+         int nNeighUp = 0;
+         AliHLTTPCCAHit h0 = tracker.GetHit( s.fFirst + ih );    
+         float y = h0.Y(); 
+         float z = h0.Z(); 
+         AliHLTTPCCAHitArea areaDn, areaUp;
+         areaUp.Init( tracker, s.fGridUp,  s.fFirstUp, y*s.fUpTx, z*s.fUpTx, kAreaSize, kAreaSize );
+         areaDn.Init(  tracker, s.fGridDn,  s.fFirstDn, y*s.fDnTx, z*s.fDnTx, kAreaSize, kAreaSize );      
+         do{
+           AliHLTTPCCAHit h;
+           Int_t i = areaUp.GetNext( tracker,h );
+           if( i<0 ) break;
+           neighUp[nNeighUp] = (UShort_t) i;       
+           yzUp[nNeighUp] = make_float2( s.fDnDx*(h.Y()-y), s.fDnDx*(h.Z()-z) );
+           if( ++nNeighUp>=kMaxN ) break;
+         }while(1);
+
+         int nNeighDn=0;
+         if( nNeighUp>0 ){
+
+           int bestDn=-1, bestUp=-1;
+           float bestD=1.e10;
+
+           do{
+             AliHLTTPCCAHit h;
+             Int_t i = areaDn.GetNext( tracker,h );
+             if( i<0 ) break;
+             nNeighDn++;             
+             float2 yzdn = make_float2( s.fUpDx*(h.Y()-y), s.fUpDx*(h.Z()-z) );
+             
+             for( int iUp=0; iUp<nNeighUp; iUp++ ){
+               float2 yzup = yzUp[iUp];
+               float dy = yzdn.x - yzup.x;
+               float dz = yzdn.y - yzup.y;
+               float d = dy*dy + dz*dz;
+               if( d<bestD ){
+                 bestD = d;
+                 bestDn = i;
+                 bestUp = iUp;
+               }               
+             }
+           }while(1);   
+         
+           if( bestD <= chi2Cut ){      
+             linkUp = neighUp[bestUp];
+             linkDn = bestDn;      
+           }
+         }
+       }
+       
+       s.fHitLinkUp[ih] = linkUp;
+       s.fHitLinkDn[ih] = linkDn;
+      }
+    }
+}
+
diff --git a/HLT/TPCLib/tracking-ca/AliHLTTPCCANeighboursFinder.h b/HLT/TPCLib/tracking-ca/AliHLTTPCCANeighboursFinder.h
new file mode 100644 (file)
index 0000000..45a1827
--- /dev/null
@@ -0,0 +1,69 @@
+//-*- Mode: C++ -*-
+
+//* 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 ALIHLTTPCCANEIGHBOURSFINDER_H
+#define ALIHLTTPCCANEIGHBOURSFINDER_H
+
+
+#include "AliHLTTPCCADef.h"
+#include "AliHLTTPCCAGrid.h"
+class AliHLTTPCCATracker;
+
+/**
+ * @class AliHLTTPCCANeighboursFinder
+ * 
+ */
+class AliHLTTPCCANeighboursFinder
+{
+ public:
+  class AliHLTTPCCASharedMemory
+    {
+  friend class AliHLTTPCCANeighboursFinder;
+    public:
+#if !defined(HLTCA_GPUCODE)
+      AliHLTTPCCASharedMemory()
+       : fGridUp(), fGridDn(), fNHits(0), fUpNHits(0), fDnNHits(0), fUpDx(0), fDnDx(0), fUpTx(0), fDnTx(0), fIRow(0), fIRowUp(0), fIRowDn(0), fFirst(0), fFirstDn(0), fFirstUp(0), fNRows(0), fHitLinkUp(0), fHitLinkDn(0)
+      {}
+
+      AliHLTTPCCASharedMemory( const AliHLTTPCCASharedMemory& /*dummy*/) 
+       : fGridUp(), fGridDn(), fNHits(0), fUpNHits(0), fDnNHits(0), fUpDx(0), fDnDx(0), fUpTx(0), fDnTx(0), fIRow(0), fIRowUp(0), fIRowDn(0), fFirst(0), fFirstDn(0), fFirstUp(0), fNRows(0), fHitLinkUp(0), fHitLinkDn(0)
+      {}
+      AliHLTTPCCASharedMemory& operator=(const AliHLTTPCCASharedMemory& /*dummy*/){ return *this; }
+#endif
+    protected:
+      AliHLTTPCCAGrid fGridUp; // grid for the next row
+      AliHLTTPCCAGrid fGridDn; // grid for the previous row
+      Int_t fNHits; // n hits
+      Int_t fUpNHits; // n hits in the next row
+      Int_t fDnNHits; // n hits in the prev row
+      Float_t fUpDx; // x distance to the next row
+      Float_t fDnDx; // x distance to the previous row
+      Float_t fUpTx; // normalized x distance to the next row
+      Float_t fDnTx; // normalized x distance to the previous row
+      Int_t fIRow; // row number
+      Int_t fIRowUp; // next row number 
+      Int_t fIRowDn;// previous row number 
+      Int_t fFirst; // index of the first hit
+      Int_t fFirstDn; // index of the first hit in the next row
+      Int_t fFirstUp;// index of the first hit in the previous row
+      Int_t fNRows; // number of rows
+      Short_t *fHitLinkUp; // links to the next row
+      Short_t *fHitLinkDn; // links to the previous  row
+      float2 fA[256][5]; // temp memory
+      UShort_t fB[256][5]; // temp memory
+      UChar_t fGridContentUp[600]; // grid content for the next row
+      UChar_t fGridContentDn[600];// grid content for the previous row
+    };
+  
+  GPUd() static Int_t NThreadSyncPoints(){ return 2; }  
+
+  GPUd() static void Thread( Int_t nBlocks, Int_t nThreads, Int_t iBlock, Int_t iThread, Int_t iSync,
+                            AliHLTTPCCASharedMemory &smem, AliHLTTPCCATracker &tracker );
+  
+};
+
+
+#endif
similarity index 64%
rename from HLT/TPCLib/tracking-ca/AliHLTTPCCACell.cxx
rename to HLT/TPCLib/tracking-ca/AliHLTTPCCANeighboursFinder1.cxx
index 2beebe37abf802fab791ae2b4074351dfce4f46a..fb6441fc77a0b396f0e4a3f4147e653ffcb4ee43 100644 (file)
@@ -1,4 +1,4 @@
-// @(#) $Id$
+// @(#) $Id: AliHLTTPCCANeighboursFinder.cxx 27042 2008-07-02 12:06:02Z richterm $
 //***************************************************************************
 // This file is property of and copyright by the ALICE HLT Project          * 
 // ALICE Experiment at CERN, All rights reserved.                           *
 // provided "as is" without express or implied warranty.                    *
 //***************************************************************************
 
-#include "AliHLTTPCCACell.h"
+#include "AliHLTTPCCANeighboursFinder1.h"
+#include "AliHLTTPCCATracker.h"
 
-
-  //ClassImp(AliHLTTPCCACell)
-
-void AliHLTTPCCACell::Dummy()
+GPUd() void AliHLTTPCCANeighboursFinder1::Thread
+( Int_t nBlocks, Int_t nThreads, Int_t iBlock, Int_t iThread, Int_t iSync,
+  SharedMemory &s, AliHLTTPCCATracker &tracker )
 {
-  //* do nothing
+  int nRows = 159;
+  int iRow = iBlock;
+  int first = tracker.Rows()[iRow].FirstHit();      
+  Short_t *hitLinkUp = tracker.HitLinkUp() + first;
+  Short_t *hitLinkDn = tracker.HitLinkDown() + first;
+  int NHits = tracker.Rows()[iRow].NHits();
+  for( int ih=iThread; ih<NHits; ih+=nThreads ){       
+    hitLinkUp[ih] = -1;
+    hitLinkDn[ih] = -1;        
+  }
 }
diff --git a/HLT/TPCLib/tracking-ca/AliHLTTPCCANeighboursFinder1.h b/HLT/TPCLib/tracking-ca/AliHLTTPCCANeighboursFinder1.h
new file mode 100644 (file)
index 0000000..891e05c
--- /dev/null
@@ -0,0 +1,34 @@
+//-*- Mode: C++ -*-
+
+//* 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 ALIHLTTPCCANEIGHBOURSFINDER1_H
+#define ALIHLTTPCCANEIGHBOURSFINDER1_H
+
+
+#include "AliHLTTPCCADef.h"
+class AliHLTTPCCATracker;
+
+/**
+ * @class AliHLTTPCCANeighboursFinder
+ * 
+ */
+class AliHLTTPCCANeighboursFinder1
+{
+ public:
+  class SharedMemory
+    {
+    public:
+    };
+  
+  GPUd() static Int_t NThreadSyncPoints(){ return 0; }  
+
+  GPUd() static void Thread( Int_t nBlocks, Int_t nThreads, Int_t iBlock, Int_t iThread, Int_t iSync,
+                            SharedMemory &smem, AliHLTTPCCATracker &tracker );
+  
+};
+
+
+#endif
index e0b3c800dffa477e0af684be078c1e28134c92bb..93905573d6ee534d4eb2dee4838dfff67dfe5398 100644 (file)
@@ -21,7 +21,7 @@
 
 ClassImp(AliHLTTPCCAOutTrack)
 
-void AliHLTTPCCAOutTrack::Dummy()
+GPUh() void AliHLTTPCCAOutTrack::Dummy()
 {
   //* do nothing
 }
index a816cab94197960020231cebe018370018378363..24f7d295296af3771939d43108e82ca87b583472 100644 (file)
@@ -8,7 +8,6 @@
 #ifndef ALIHLTTPCCAOUTTRACK_H
 #define ALIHLTTPCCAOUTTRACK_H
 
-#include "Rtypes.h"
 #include "AliHLTTPCCATrackParam.h"
 
 /**
@@ -27,12 +26,12 @@ class AliHLTTPCCAOutTrack
   AliHLTTPCCAOutTrack():fFirstHitRef(0),fNHits(0),fStartPoint(),fEndPoint(),fOrigTrackID(0){}
   virtual ~AliHLTTPCCAOutTrack(){}
 
-  Int_t &NHits()               { return fNHits; }
-  Int_t &FirstHitRef()         { return fFirstHitRef; }
+  GPUhd() Int_t &NHits()               { return fNHits; }
+  GPUhd() Int_t &FirstHitRef()         { return fFirstHitRef; }
 
-  AliHLTTPCCATrackParam &StartPoint() { return fStartPoint; }
-  AliHLTTPCCATrackParam &EndPoint()   { return fEndPoint; }
-  Int_t &OrigTrackID()                { return fOrigTrackID; }
+  GPUhd() AliHLTTPCCATrackParam &StartPoint() { return fStartPoint; }
+  GPUhd() AliHLTTPCCATrackParam &EndPoint()   { return fEndPoint; }
+  GPUhd() Int_t &OrigTrackID()                { return fOrigTrackID; }
 
  protected:
   
@@ -46,7 +45,7 @@ class AliHLTTPCCAOutTrack
 
   void Dummy(); // to make rulechecker happy by having something in .cxx file
 
-  ClassDef(AliHLTTPCCAOutTrack,1);
+  ClassDef(AliHLTTPCCAOutTrack,1)
 };
 
 
index 39c59ad317c571211712bd15d40a5d472c1ed724..c3d9b4361a6a0764bc97e37a4172d9b512d96ec4 100644 (file)
 //***************************************************************************
 
 #include "AliHLTTPCCAParam.h"
-#include "TMath.h"
+#include "AliHLTTPCCAMath.h"
 
 
-ClassImp(AliHLTTPCCAParam)
-  
-AliHLTTPCCAParam::AliHLTTPCCAParam()
+#if !defined(HLTCA_GPUCODE)  
+
+GPUd() AliHLTTPCCAParam::AliHLTTPCCAParam()
   : fISlice(0),fNRows(63),fAlpha(0.174533), fDAlpha(0.349066),
     fCosAlpha(0), fSinAlpha(0), fAngleMin(0), fAngleMax(0), fRMin(83.65), fRMax(133.3),
     fZMin(0.0529937), fZMax(249.778), fErrX(0), fErrY(0), fErrZ(0.228808),fPadPitch(0.4),fBz(-5.), 
     fYErrorCorrection(0.33), fZErrorCorrection(0.45),
-    fCellConnectionAngleXY(45./180.*TMath::Pi()), 
-    fCellConnectionAngleXZ(45./180.*TMath::Pi()),
+    fCellConnectionAngleXY(45./180.*CAMath::Pi()), 
+    fCellConnectionAngleXZ(45./180.*CAMath::Pi()),
     fMaxTrackMatchDRow(4), fTrackConnectionFactor(3.5), fTrackChiCut(3.5), fTrackChi2Cut(10)
 {
+  // constructor
   fParamS0Par[0][0][0] = 0.00047013;
   fParamS0Par[0][0][1] = 2.00135e-05;
   fParamS0Par[0][0][2] = 0.0106533;
@@ -76,8 +77,9 @@ AliHLTTPCCAParam::AliHLTTPCCAParam()
 
   Update();
 }
+#endif
 
-void AliHLTTPCCAParam::Initialize( Int_t iSlice, 
+GPUd() void AliHLTTPCCAParam::Initialize( Int_t iSlice, 
                                   Int_t nRows, Float_t rowX[],
                                   Float_t alpha, Float_t dAlpha,
                                   Float_t rMin, Float_t rMax,
@@ -106,18 +108,18 @@ void AliHLTTPCCAParam::Initialize( Int_t iSlice,
   Update();
 }
 
-void AliHLTTPCCAParam::Update()
+GPUd() void AliHLTTPCCAParam::Update()
 {
   // update of calculated values
-  fCosAlpha = TMath::Cos(fAlpha);
-  fSinAlpha = TMath::Sin(fAlpha);
+  fCosAlpha = CAMath::Cos(fAlpha);
+  fSinAlpha = CAMath::Sin(fAlpha);
   fAngleMin = fAlpha - fDAlpha/2.;
   fAngleMax = fAlpha + fDAlpha/2.;
-  fErrX = fPadPitch/TMath::Sqrt(12.);
+  fErrX = fPadPitch/CAMath::Sqrt(12.);
   fTrackChi2Cut = fTrackChiCut * fTrackChiCut;
 }
 
-void AliHLTTPCCAParam::Slice2Global( Float_t x, Float_t y,  Float_t z, 
+GPUd() void AliHLTTPCCAParam::Slice2Global( Float_t x, Float_t y,  Float_t z, 
                                     Float_t *X, Float_t *Y,  Float_t *Z ) const
 {  
   // conversion of coorinates sector->global
@@ -126,7 +128,7 @@ void AliHLTTPCCAParam::Slice2Global( Float_t x, Float_t y,  Float_t z,
   *Z = z;
 }
  
-void AliHLTTPCCAParam::Global2Slice( Float_t X, Float_t Y,  Float_t Z, 
+GPUd() void AliHLTTPCCAParam::Global2Slice( Float_t X, Float_t Y,  Float_t Z, 
                                     Float_t *x, Float_t *y,  Float_t *z ) const
 {
   // conversion of coorinates global->sector
@@ -135,17 +137,18 @@ void AliHLTTPCCAParam::Global2Slice( Float_t X, Float_t Y,  Float_t Z,
   *z = Z;
 }
 
-Float_t AliHLTTPCCAParam::GetClusterError2( Int_t yz, Int_t type, Float_t z, Float_t angle )
+GPUd() Float_t AliHLTTPCCAParam::GetClusterError2( Int_t yz, Int_t type, Float_t z, Float_t angle ) const
 {
   //* recalculate the cluster error wih respect to the track slope
   Float_t angle2 = angle*angle;
-  Float_t *c = fParamS0Par[yz][type];
+  const Float_t *c = fParamS0Par[yz][type];
   Float_t v = c[0] + z*(c[1] + c[3]*z) + angle2*(c[2] + angle2*c[4] + c[5]*z );
-  return TMath::Abs(v); 
+  return CAMath::Abs(v); 
 }
 
-void AliHLTTPCCAParam::WriteSettings( ostream &out )
+GPUh() void AliHLTTPCCAParam::WriteSettings( std::ostream &out ) const 
 {
+  // write settings to the file
   out << fISlice<<endl;
   out << fNRows<<endl;
   out << fAlpha<<endl;
@@ -182,8 +185,10 @@ void AliHLTTPCCAParam::WriteSettings( ostream &out )
   out<<endl;
 }
 
-void AliHLTTPCCAParam::ReadSettings( istream &in )
+GPUh() void AliHLTTPCCAParam::ReadSettings( std::istream &in )
 {
+  // Read settings from the file
+
   in >> fISlice;
   in >> fNRows;
   in >> fAlpha;
index a175a5eec98cfbaa5548e26c0f8b536a675cc219..c7311b81c55a10e537d0fcced332d673d8dab127 100644 (file)
@@ -8,8 +8,9 @@
 #ifndef ALIHLTTPCCAPARAM_H
 #define ALIHLTTPCCAPARAM_H
 
-#include "Rtypes.h"
-#include "Riostream.h"
+#include "AliHLTTPCCADef.h"
+#include <iostream.h>
+
 
 /**
  * @class ALIHLTTPCCAParam
@@ -23,54 +24,57 @@ class AliHLTTPCCAParam
 {
  public:
 
-  AliHLTTPCCAParam();
-  virtual ~AliHLTTPCCAParam(){;}
+#if !defined(HLTCA_GPUCODE)  
+  GPUd() AliHLTTPCCAParam();
+#endif
+
+  ~AliHLTTPCCAParam(){;}
 
-  void Initialize( Int_t iSlice, Int_t nRows, Float_t rowX[],
+  GPUd() void Initialize( Int_t iSlice, Int_t nRows, Float_t rowX[],
                   Float_t alpha, Float_t dAlpha,
                   Float_t rMin, Float_t rMax, Float_t zMin, Float_t zMax,
                   Float_t padPitch, Float_t zSigma, Float_t bz );
-  void Update();
+  GPUd() void Update();
   
-  void Slice2Global( Float_t x, Float_t y,  Float_t z, 
+  GPUd() void Slice2Global( Float_t x, Float_t y,  Float_t z, 
                     Float_t *X, Float_t *Y,  Float_t *Z ) const;
-  void Global2Slice( Float_t x, Float_t y,  Float_t z, 
+  GPUd() GPUd() void Global2Slice( Float_t x, Float_t y,  Float_t z, 
                     Float_t *X, Float_t *Y,  Float_t *Z ) const;
-  Int_t &ISlice(){ return fISlice;}
-  Int_t &NRows(){ return fNRows;}
+  GPUhd() Int_t &ISlice(){ return fISlice;}
+  GPUhd() Int_t &NRows(){ return fNRows;}
   
-  Float_t &RowX( Int_t iRow ){ return fRowX[iRow]; }
+  GPUhd() Float_t &RowX( Int_t iRow ){ return fRowX[iRow]; }
   
-  Float_t &Alpha(){ return fAlpha;}
-  Float_t &DAlpha(){ return fDAlpha;}
-  Float_t &CosAlpha(){ return fCosAlpha;}
-  Float_t &SinAlpha(){ return fSinAlpha;}
-  Float_t &AngleMin(){ return fAngleMin;}
-  Float_t &AngleMax(){ return fAngleMax;}
-  Float_t &RMin(){ return fRMin;}
-  Float_t &RMax(){ return fRMax;}
-  Float_t &ZMin(){ return fZMin;}
-  Float_t &ZMax(){ return fZMax;}
-  Float_t &ErrZ(){ return fErrZ;}
-  Float_t &ErrX(){ return fErrX;}
-  Float_t &ErrY(){ return fErrY;}
-  Float_t &Bz(){ return fBz;}
-
-  Float_t &TrackConnectionFactor(){ return fTrackConnectionFactor; }
-  Float_t &TrackChiCut() { return fTrackChiCut; }
-  Float_t &TrackChi2Cut(){ return fTrackChi2Cut; }
-  Int_t   &MaxTrackMatchDRow(){ return fMaxTrackMatchDRow; }
-  Float_t &YErrorCorrection(){ return fYErrorCorrection; }
-  Float_t &ZErrorCorrection(){ return fZErrorCorrection; }
-  Float_t &CellConnectionAngleXY(){ return fCellConnectionAngleXY; }
-  Float_t &CellConnectionAngleXZ(){ return fCellConnectionAngleXZ; }
-
-  Float_t GetClusterError2(Int_t yz, Int_t type, Float_t z, Float_t angle );
-
-  void WriteSettings( ostream &out );
-  void ReadSettings( istream &in );
-
- protected:
+  GPUd() Float_t &Alpha(){ return fAlpha;}
+  GPUd() Float_t &DAlpha(){ return fDAlpha;}
+  GPUd() Float_t &CosAlpha(){ return fCosAlpha;}
+  GPUd() Float_t &SinAlpha(){ return fSinAlpha;}
+  GPUd() Float_t &AngleMin(){ return fAngleMin;}
+  GPUd() Float_t &AngleMax(){ return fAngleMax;}
+  GPUd() Float_t &RMin(){ return fRMin;}
+  GPUd() GPUd() Float_t &RMax(){ return fRMax;}
+  GPUd() GPUd() Float_t &ZMin(){ return fZMin;}
+  GPUd() Float_t &ZMax(){ return fZMax;}
+  GPUd() Float_t &ErrZ(){ return fErrZ;}
+  GPUd() Float_t &ErrX(){ return fErrX;}
+  GPUd() Float_t &ErrY(){ return fErrY;}
+  GPUd() Float_t &Bz(){ return fBz;}
+
+  GPUd() Float_t &TrackConnectionFactor(){ return fTrackConnectionFactor; }
+  GPUd() Float_t &TrackChiCut() { return fTrackChiCut; }
+  GPUd() Float_t &TrackChi2Cut(){ return fTrackChi2Cut; }
+  GPUd() Int_t   &MaxTrackMatchDRow(){ return fMaxTrackMatchDRow; }
+  GPUd() Float_t &YErrorCorrection(){ return fYErrorCorrection; }
+  GPUd() Float_t &ZErrorCorrection(){ return fZErrorCorrection; }
+  GPUd() Float_t &CellConnectionAngleXY(){ return fCellConnectionAngleXY; }
+  GPUd() Float_t &CellConnectionAngleXZ(){ return fCellConnectionAngleXZ; }
+
+  GPUd() Float_t GetClusterError2(Int_t yz, Int_t type, Float_t z, Float_t angle ) const;
+
+  void WriteSettings( std::ostream &out ) const;
+  void ReadSettings( std::istream &in );
+
 protected:
 
   Int_t fISlice; // slice number
   Int_t fNRows; // number of rows
@@ -97,7 +101,6 @@ class AliHLTTPCCAParam
   Float_t fRowX[200];// X-coordinate of rows
   Float_t fParamS0Par[2][3][7];    // cluster error parameterization coeficients
 
-  ClassDef(AliHLTTPCCAParam,1);
 };
 
 
index 1b79e3928fc2bd32e1ba65efbdfed92a767b895b..11dee86679354ac6f853a2b16ca32f83cabf5152 100644 (file)
 #include "TProfile.h"
 
 
-ClassImp(AliHLTTPCCAPerformance)
-
-
-
 AliHLTTPCCAPerformance::AliHLTTPCCAPerformance()
-  : TObject(),
-    fTracker(0),
-    fHitLabels(0), 
-    fNHits(0),
-    fMCTracks(0),
-    fNMCTracks(0),
-    fMCPoints(0),
-    fNMCPoints(0),
-    fDoClusterPulls(1),
-    fStatNEvents(0),
-    fStatNRecTot(0),
-    fStatNRecOut(0),
-    fStatNGhost(0),
-    fStatNMCAll(0),
-    fStatNRecAll(0),
-    fStatNClonesAll(0),
-    fStatNMCRef(0),
-    fStatNRecRef(0),
-    fStatNClonesRef(0),
-    fStatGBNRecTot(0),
-    fStatGBNRecOut(0),
-    fStatGBNGhost(0),
-    fStatGBNMCAll(0),
-    fStatGBNRecAll(0),
-    fStatGBNClonesAll(0),
-    fStatGBNMCRef(0),
-    fStatGBNRecRef(0),
-    fStatGBNClonesRef(0),
-    fHistoDir(0),
-    fhResY(0),
-    fhResZ(0),
-    fhResSinPhi(0),
-    fhResDzDs(0),
-    fhResPt(0),
-    fhPullY(0),
-    fhPullZ(0),
-    fhPullSinPhi(0),
-    fhPullDzDs(0),
-    fhPullQPt(0),
-    fhHitErrY(0),
-    fhHitErrZ(0),
-    fhHitResY(0),
-    fhHitResZ(0),
-    fhHitPullY(0),
-    fhHitPullZ(0),
-    fhHitResY1(0),
-    fhHitResZ1(0),
-    fhHitPullY1(0),
-    fhHitPullZ1(0),
-    fhCellPurity(0),
-    fhCellNHits(0),
-    fhCellPurityVsN(0), 
-    fhCellPurityVsPt(0),
-    fhEffVsP(0),
-    fhGBEffVsP(0)
+  : 
+  fTracker(0),
+  fHitLabels(0),
+  fNHits(0),                   
+  fMCTracks(0),  
+  fNMCTracks(0),               
+  fMCPoints(0),  
+  fNMCPoints(0),               
+  fDoClusterPulls(0),         
+  fStatNEvents(0),
+  fStatNRecTot(0),
+  fStatNRecOut(0),
+  fStatNGhost(0),
+  fStatNMCAll(0),
+  fStatNRecAll(0),
+  fStatNClonesAll(0),
+  fStatNMCRef(0), 
+  fStatNRecRef(0), 
+  fStatNClonesRef(0),  
+  fStatGBNRecTot(0), 
+  fStatGBNRecOut(0), 
+  fStatGBNGhost(0),
+  fStatGBNMCAll(0),
+  fStatGBNRecAll(0),
+  fStatGBNClonesAll(0),
+  fStatGBNMCRef(0), 
+  fStatGBNRecRef(0), 
+  fStatGBNClonesRef(0),  
+  fHistoDir(0), 
+  fhResY(0),       
+  fhResZ(0),       
+  fhResSinPhi(0),  
+  fhResDzDs(0),    
+  fhResPt(0),      
+  fhPullY(0),      
+  fhPullZ(0),      
+  fhPullSinPhi(0), 
+  fhPullDzDs(0),
+  fhPullQPt(0), 
+  fhHitErrY(0), 
+  fhHitErrZ(0),
+  fhHitResY(0),
+  fhHitResZ(0),
+  fhHitPullY(0),
+  fhHitPullZ(0),  
+  fhHitResY1(0),
+  fhHitResZ1(0),
+  fhHitPullY1(0),
+  fhHitPullZ1(0),
+  fhCellPurity(0),
+  fhCellNHits(0),
+  fhCellPurityVsN(0), 
+  fhCellPurityVsPt(0),
+  fhEffVsP(0), 
+  fhGBEffVsP(0),
+  fhNeighQuality(0),
+  fhNeighEff(0),
+  fhNeighQualityVsPt(0),
+  fhNeighEffVsPt(0),
+  fhNeighDy(0),
+  fhNeighDz(0),
+  fhNeighChi(0),
+  fhNeighDyVsPt(0),
+  fhNeighDzVsPt(0),
+  fhNeighChiVsPt(0), 
+  fhNeighNCombVsArea(0)
 {
   //* constructor
 }
 
 
 AliHLTTPCCAPerformance::AliHLTTPCCAPerformance(const AliHLTTPCCAPerformance&)
-  : TObject(),
-    fTracker(0),
-    fHitLabels(0), 
-    fNHits(0),
-    fMCTracks(0),
-    fNMCTracks(0),
-    fMCPoints(0),
-    fNMCPoints(0),
-    fDoClusterPulls(1),
-    fStatNEvents(0),
-    fStatNRecTot(0),
-    fStatNRecOut(0),
-    fStatNGhost(0),
-    fStatNMCAll(0),
-    fStatNRecAll(0),
-    fStatNClonesAll(0),
-    fStatNMCRef(0),
-    fStatNRecRef(0),
-    fStatNClonesRef(0),
-    fStatGBNRecTot(0),
-    fStatGBNRecOut(0),
-    fStatGBNGhost(0),
-    fStatGBNMCAll(0),
-    fStatGBNRecAll(0),
-    fStatGBNClonesAll(0),
-    fStatGBNMCRef(0),
-    fStatGBNRecRef(0),
-    fStatGBNClonesRef(0),
-    fHistoDir(0),
-    fhResY(0),
-    fhResZ(0),
-    fhResSinPhi(0),
-    fhResDzDs(0),
-    fhResPt(0),
-    fhPullY(0),
-    fhPullZ(0),
-    fhPullSinPhi(0),
-    fhPullDzDs(0),
-    fhPullQPt(0),
-    fhHitErrY(0),
-    fhHitErrZ(0),    
-    fhHitResY(0),
-    fhHitResZ(0),
-    fhHitPullY(0),
-    fhHitPullZ(0),
-    fhHitResY1(0),
-    fhHitResZ1(0),
-    fhHitPullY1(0),
-    fhHitPullZ1(0),
-    fhCellPurity(0),
-    fhCellNHits(0),
-    fhCellPurityVsN(0), 
-    fhCellPurityVsPt(0),
-    fhEffVsP(0),
-    fhGBEffVsP(0)
+  :
+  fTracker(0),
+  fHitLabels(0),
+  fNHits(0),                   
+  fMCTracks(0),  
+  fNMCTracks(0),               
+  fMCPoints(0),  
+  fNMCPoints(0),               
+  fDoClusterPulls(0),         
+  fStatNEvents(0),
+  fStatNRecTot(0),
+  fStatNRecOut(0),
+  fStatNGhost(0),
+  fStatNMCAll(0),
+  fStatNRecAll(0),
+  fStatNClonesAll(0),
+  fStatNMCRef(0), 
+  fStatNRecRef(0), 
+  fStatNClonesRef(0),  
+  fStatGBNRecTot(0), 
+  fStatGBNRecOut(0), 
+  fStatGBNGhost(0),
+  fStatGBNMCAll(0),
+  fStatGBNRecAll(0),
+  fStatGBNClonesAll(0),
+  fStatGBNMCRef(0), 
+  fStatGBNRecRef(0), 
+  fStatGBNClonesRef(0),  
+  fHistoDir(0), 
+  fhResY(0),       
+  fhResZ(0),       
+  fhResSinPhi(0),  
+  fhResDzDs(0),    
+  fhResPt(0),      
+  fhPullY(0),      
+  fhPullZ(0),      
+  fhPullSinPhi(0), 
+  fhPullDzDs(0),
+  fhPullQPt(0), 
+  fhHitErrY(0), 
+  fhHitErrZ(0),
+  fhHitResY(0),
+  fhHitResZ(0),
+  fhHitPullY(0),
+  fhHitPullZ(0),  
+  fhHitResY1(0),
+  fhHitResZ1(0),
+  fhHitPullY1(0),
+  fhHitPullZ1(0),
+  fhCellPurity(0),
+  fhCellNHits(0),
+  fhCellPurityVsN(0), 
+  fhCellPurityVsPt(0),
+  fhEffVsP(0), 
+  fhGBEffVsP(0),
+  fhNeighQuality(0),
+  fhNeighEff(0),
+  fhNeighQualityVsPt(0),
+  fhNeighEffVsPt(0),
+  fhNeighDy(0),
+  fhNeighDz(0),
+  fhNeighChi(0),
+  fhNeighDyVsPt(0),
+  fhNeighDzVsPt(0),
+  fhNeighChiVsPt(0), 
+  fhNeighNCombVsArea(0)
 {
   //* dummy
 }
@@ -265,6 +283,26 @@ void AliHLTTPCCAPerformance::CreateHistos()
   TDirectory *curdir = gDirectory;
   fHistoDir = gROOT->mkdir("HLTTPCCATrackerPerformance");
   fHistoDir->cd();
+
+  gDirectory->mkdir("Neighbours");
+  gDirectory->cd("Neighbours");  
+  
+  fhNeighQuality = new TProfile("NeighQuality", "Neighbours Quality vs row", 160, 0., 160.); 
+  fhNeighEff = new TProfile("NeighEff", "Neighbours Efficiency vs row", 160, 0., 160.); 
+  fhNeighQualityVsPt = new TProfile("NeighQualityVsPt", "Neighbours Quality vs Pt", 100, 0., 5.); 
+  fhNeighEffVsPt = new TProfile("NeighEffVsPt", "Neighbours Efficiency vs Pt", 100, 0., 5.); 
+  fhNeighDy = new TH1D("NeighDy","Neighbours dy",100,-10,10);
+  fhNeighDz =  new TH1D("NeighDz","Neighbours dz",100,-10,10);
+  fhNeighChi = new TH1D("NeighChi","Neighbours chi",100,0,20);
+
+  fhNeighDyVsPt = new TH2D("NeighDyVsPt","NeighDyVsPt", 100,0,5, 100, -20,20);
+  fhNeighDzVsPt = new TH2D("NeighDzVsPt","NeighDzVsPt", 100,0,5, 100, -20,20);
+  fhNeighChiVsPt = new TH2D("NeighChiVsPt","NeighChiVsPt", 100,0,5, 100, 0,40);
+  fhNeighNCombVsArea = new TH2D("NeighNCombVsArea","NeighNCombVsArea", 15,0,3, 40, 0,40);
+
+  gDirectory->cd(".."); 
+
+
   gDirectory->mkdir("TrackFit");
   gDirectory->cd("TrackFit");  
   
@@ -359,62 +397,279 @@ void AliHLTTPCCAPerformance::SlicePerformance( Int_t iSlice, Bool_t PrintFlag )
   for( ; endSliceHit<fTracker->NHits(); endSliceHit++){
     if( fTracker->Hits()[endSliceHit].ISlice()!=iSlice ) break;
   }
-
-  { // Cell construction performance
+  
+  { // Efficiency and quality of found neighbours
+#ifdef XXX
+    for( Int_t iRow=1; iRow<slice.Param().NRows()-1; iRow++ ){      
+      AliHLTTPCCARow &row = slice.Rows()[iRow];
+      AliHLTTPCCARow &rowP = slice.Rows()[iRow-1];
+      AliHLTTPCCARow &rowN = slice.Rows()[iRow+1];      
+
+      Int_t nHitsRow[fNMCTracks][3];
+      Bool_t foundRow[fNMCTracks];
+      Bool_t isPrim[fNMCTracks];
+      for (Int_t imc=0; imc<fNMCTracks; imc++){ 
+       for( Int_t i=0; i<3; i++ )nHitsRow[imc][i]=0;
+       foundRow[imc]=0;
+       Float_t y = fMCTracks[imc].Par()[1];
+       Float_t z = fMCTracks[imc].Par()[2];
+       isPrim[imc] = (y*y + z*z < 100. );
+      }
     
-    for( Int_t iRow=0; iRow<slice.Param().NRows(); iRow++ ){
-      AliHLTTPCCARow &row = slice.Rows()[iRow];      
-      for (Int_t ic = 0; ic<row.NCells(); ic++){
-       AliHLTTPCCACell &c  = row.Cells()[ic];
-       Int_t *lb = new Int_t[c.NHits()*3];
-       Int_t nla = 0;  
-       for( Int_t j=0; j<c.NHits(); j++){
-         AliHLTTPCCAHit &h = row.GetCellHit(c,j);
-         //cout<<"hit ID="<<h.ID()<<" of"<<fTracker->NHits()<<endl;
-         //cout<<"gb hit ID="<<fTracker->Hits()[h.ID()].ID()<<endl;
+      for( Int_t i=0; i<3; i++ ){
+       AliHLTTPCCARow &r = slice.Rows()[iRow-1+i];      
+       for (Int_t ih = 0; ih<r.NHits(); ih++){
+         AliHLTTPCCAHit &h = r.Hits()[ih];
          AliHLTTPCCAHitLabel &l = fHitLabels[fTracker->Hits()[h.ID()].ID()];
-         if( l.fLab[0]>=0 ) lb[nla++]= l.fLab[0];
-         if( l.fLab[1]>=0 ) lb[nla++]= l.fLab[1];
-         if( l.fLab[2]>=0 ) lb[nla++]= l.fLab[2];
+         if( l.fLab[0] <0 || l.fLab[1]>=0 ) continue;
+         nHitsRow[l.fLab[0]][i]++;
        }
-       sort( lb, lb+nla );
-       Int_t labmax = -1, labcur=-1, lmax = 0, lcurr=0;        
-       for( Int_t i=0; i<nla; i++ ){
-         if( lb[i]!=labcur ){
-           if( labcur>=0 && lmax<lcurr ){
-             lmax = lcurr;
-             labmax = labcur;
+      }
+
+      for( Int_t it=0; it<row.NTriplets(); it++ ){
+       AliHLTTPCCATriplet &t = row.Triplets()[it];
+       if( !t.Alive() ) continue;
+       AliHLTTPCCAHit &h = row.Hits()[t.HitMid()];
+       AliHLTTPCCAHit &hP = rowP.Hits()[t.HitDown()];
+       AliHLTTPCCAHit &hN = rowN.Hits()[t.HitUp()];
+       AliHLTTPCCAHitLabel &l = fHitLabels[fTracker->Hits()[h.ID()].ID()];
+       AliHLTTPCCAHitLabel &lP = fHitLabels[fTracker->Hits()[hP.ID()].ID()];
+       AliHLTTPCCAHitLabel &lN = fHitLabels[fTracker->Hits()[hN.ID()].ID()];   
+       Bool_t found = ( l.fLab[0]>=0 && lP.fLab[0]==l.fLab[0] && lN.fLab[0]==l.fLab[0] );
+       if( found ) foundRow[l.fLab[0]] = 1;
+       Bool_t isGhost = 1;
+       for( Int_t il=0; il<3; il++ ){
+         if( l.fLab[il]<0 ) continue;
+         Bool_t okP=0, okN=0;
+         for( Int_t jl=0; jl<3; jl++ ){
+           if( lP.fLab[jl]==l.fLab[il] ) okP = 1;
+           if( lN.fLab[jl]==l.fLab[il] ) okN = 1;
+         }
+         if( okP && okN ) isGhost = 0; 
+       }
+       fhNeighQuality->Fill(iRow, !isGhost );
+       if( l.fLab[0]>=0 ) fhNeighQualityVsPt->Fill(fMCTracks[l.fLab[0]].Pt(), !isGhost );
+      }
+    
+      for (Int_t imc=0; imc<fNMCTracks; imc++){ 
+       if( nHitsRow[imc][0]<=0 || nHitsRow[imc][1]<=0 ||nHitsRow[imc][2]<=0 ) continue;
+       if( !isPrim[imc] ) continue;
+       if( fMCTracks[imc].Pt()>0.2 ) fhNeighEff->Fill(iRow, foundRow[imc] );   
+       fhNeighEffVsPt->Fill( fMCTracks[imc].Pt(), foundRow[imc] );     
+      }
+    }
+#endif    
+  } // efficiency and quality of found neighbours
+
+
+
+
+  if(0){ // Local efficiency of found neighbours
+#ifdef XXX    
+    for( Int_t iRow=1; iRow<slice.Param().NRows()-1; iRow++ ){
+      //cout<<"iRow="<<iRow<<endl;
+      AliHLTTPCCARow &row = slice.Rows()[iRow];      
+      AliHLTTPCCARow &rowP = slice.Rows()[iRow-1];      
+      AliHLTTPCCARow &rowN = slice.Rows()[iRow+1];      
+      Float_t xP = rowP.X() - row.X();
+      Float_t xN = rowN.X() - row.X();
+      Float_t tN = rowN.X()/row.X();
+      Float_t tP = rowP.X()/row.X();
+      Float_t chi2Cut = 2*3.*3.*(xN*xN+xP*xP);
+      for (Int_t ih = 0; ih<row.NHits(); ih++){
+       AliHLTTPCCAHit &h = row.Hits()[ih];
+       AliHLTTPCCAHitLabel &l = fHitLabels[fTracker->Hits()[h.ID()].ID()];
+       if( l.fLab[0] <0 || l.fLab[1]>=0 ) continue;
+       Float_t yyP = h.Y()*tP;
+       Float_t zzP = h.Z()*tP;
+       Float_t yyN = h.Y()*tN;
+       Float_t zzN = h.Z()*tN;
+       Float_t mcPt = fMCTracks[l.fLab[0]].Pt();
+       if(0){
+         Int_t jhP=-1;
+         Float_t bestDP = 1.e10;
+         for (Int_t ihP = 0; ihP<rowP.NHits(); ihP++){
+           AliHLTTPCCAHit &hP = rowP.Hits()[ihP];
+           AliHLTTPCCAHitLabel &lP = fHitLabels[fTracker->Hits()[hP.ID()].ID()];
+           Bool_t ok = 0;
+           for( Int_t il=0; il<3; il++ ){
+             if( lP.fLab[il]==l.fLab[0] ) ok = 1;
+           }
+           if( !ok ) continue;
+           Float_t dy = hP.Y()-yyP;
+           Float_t dz = hP.Z()-zzP;
+           Float_t d = dy*dy + dz*dz;
+           if( d<bestDP ){
+             bestDP = d;
+             jhP = ihP;
            }
-           labcur = lb[i];
-           lcurr = 0;
          }
-         lcurr++;
+
+         Int_t jhN=-1;
+         Float_t bestDN = 1.e10;
+         for (Int_t ihN = 0; ihN<rowN.NHits(); ihN++){
+           AliHLTTPCCAHit &hN = rowN.Hits()[ihN];
+           AliHLTTPCCAHitLabel &lN = fHitLabels[fTracker->Hits()[hN.ID()].ID()];
+           Bool_t ok = 0;
+           for( Int_t il=0; il<3; il++ ){
+             if( lN.fLab[il]==l.fLab[0] ) ok = 1;
+           }
+           if( !ok ) continue;
+           Float_t dy = hN.Y()-yyN;
+           Float_t dz = hN.Z()-zzN;
+           Float_t d = dy*dy + dz*dz;
+           if( d<bestDN ){
+             bestDN = d;
+             jhN = ihN;
+           }
+         }
+         if( jhP>=0 && jhN>=0 ){
+           AliHLTTPCCAHit &hP = rowP.Hits()[jhP];
+           AliHLTTPCCAHit &hN = rowN.Hits()[jhN];
+           fhNeighDyVsPt->Fill(mcPt, hP.Y()-yyP);
+           fhNeighDyVsPt->Fill(mcPt, hN.Y()-yyN);
+           fhNeighDzVsPt->Fill(mcPt, hP.Z()-zzP);
+           fhNeighDzVsPt->Fill(mcPt, hN.Z()-zzN);
+           Float_t dy = xP*(hN.Y()-h.Y()) - xN*(hP.Y()-h.Y());
+           Float_t dz = xP*(hN.Z()-h.Z()) - xN*(hP.Z()-h.Z());
+           Float_t chi2 = (dy*dy + dz*dz)/(xN*xN+xP*xP);
+           fhNeighChiVsPt->Fill(mcPt, TMath::Sqrt(chi2/2));        
+         }
+         {
+           Float_t darea = .2;
+           Int_t nAreas = 15;
+           Int_t nComb[nAreas];
+           for( int i=0; i<nAreas; i++ ) nComb[i]=0;
+           for (Int_t ihP = 0; ihP<rowP.NHits(); ihP++){
+             AliHLTTPCCAHit &hP = rowP.Hits()[ihP];
+             Float_t yyy = -xP*h.Y() - xN*(hP.Y()-h.Y());
+             Float_t zzz = -xP*h.Z() - xN*(hP.Z()-h.Z());
+             for (Int_t ihN = 0; ihN<rowN.NHits(); ihN++){
+               AliHLTTPCCAHit &hN = rowN.Hits()[ihN];
+               Float_t dy = xP*hN.Y()+yyy;
+               Float_t dz = xP*hN.Z()+zzz;
+               Float_t chi2 = (dy*dy + dz*dz);
+               if( chi2 >chi2Cut ) continue;
+               Float_t D = TMath::Abs( hP.Y()-yyP );
+               Float_t d = TMath::Abs( hP.Z()-zzP );
+               if( d>D ) D = d;
+               d = TMath::Abs( hN.Y()-yyN );
+               if( d>D ) D = d;
+               d = TMath::Abs( hN.Z()-zzN );
+               if( d>D ) D = d;                
+               int ic = (int) (D/darea);
+               if( ic<nAreas ) nComb[ic]++;
+             }
+           }
+           int j=0;
+           for( int i=0; i<nAreas; i++ ){
+             j+=nComb[i];
+             if(j>0 ) fhNeighNCombVsArea->Fill(i*darea,j);
+           }     
+         }
+       }
+
+       Float_t area = 5;
+       const Int_t maxN = 1000;
+       Int_t neighP[maxN];
+       Int_t neighN[maxN];
+       Float_t zP[maxN];
+       Float_t yP[maxN];
+       Float_t zN[maxN];
+       Float_t yN[maxN];
+       Int_t nNeighP = 0;
+       Int_t nNeighN = 0;     
+       
+       for (Int_t ihP = 0; ihP<rowP.NHits(); ihP++){
+         AliHLTTPCCAHit &hP = rowP.Hits()[ihP];
+         if( TMath::Abs(hP.Y()-yyP)>area || TMath::Abs(hP.Z()-zzP)>area ) continue;
+         AliHLTTPCCAHitLabel &lP = fHitLabels[fTracker->Hits()[hP.ID()].ID()];
+         Bool_t ok = 0;
+         for( Int_t il=0; il<3; il++ ){
+           if( lP.fLab[il]==l.fLab[0] ) ok = 1;
+         }
+         if( !ok ) continue;
+         neighP[nNeighP] = ihP;
+         zP[nNeighP] = xN*(hP.Z()-h.Z());
+         yP[nNeighP] = xN*(hP.Y()-h.Y());
+         nNeighP++;
+         if( nNeighP>=maxN ) break;
        }
-       if( labcur>=0 && lmax<lcurr ){
-         lmax = lcurr;
-         labmax = labcur;
+       for (Int_t ihN = 0; ihN<rowN.NHits(); ihN++){
+         AliHLTTPCCAHit &hN = rowN.Hits()[ihN];
+         if( TMath::Abs(hN.Y()-yyN)>area || TMath::Abs(hN.Z()-zzN)>area ) continue;
+         AliHLTTPCCAHitLabel &lN = fHitLabels[fTracker->Hits()[hN.ID()].ID()];
+         Bool_t ok = 0;
+         for( Int_t il=0; il<3; il++ ){
+           if( lN.fLab[il]==l.fLab[0] ) ok = 1;
+         }
+         if( !ok ) continue;
+         neighN[nNeighN] = ihN;
+         zN[nNeighN] = xP*(hN.Z()-h.Z());
+         yN[nNeighN] = xP*(hN.Y()-h.Y());
+         nNeighN++;
+         if( nNeighN>=maxN ) break;
        }
 
-       Int_t label = labmax;
-       lmax = 0;
-       for( Int_t j=0; j<c.NHits(); j++){
-         AliHLTTPCCAHit &h = row.GetCellHit(c,j);
-         AliHLTTPCCAHitLabel &l = fHitLabels[fTracker->Hits()[h.ID()].ID()];
-         if( l.fLab[0]==label || l.fLab[1]==label || l.fLab[2]==label ) lmax++;
+       if( nNeighN<=0 || nNeighP<=0 ) continue;
+
+       {
+         // neighbours found, look for the straight line connection
+         Int_t bestP=-1, bestN=-1;
+         Float_t bestD=1.e10;
+         for( Int_t iP=0; iP<nNeighP; iP++ ){
+           for( Int_t iN=0; iN<nNeighN; iN++ ){
+             Float_t dy = yP[iP]-yN[iN];
+             Float_t dz = zP[iP]-zN[iN];
+             Float_t d = dy*dy + dz*dz;
+             if( d<bestD){
+               bestD = d;
+               bestP = iP;
+               bestN = iN;
+             }
+           }   
+         }
+         if( bestP>=0 ){
+           AliHLTTPCCAHit &hP = rowP.Hits()[neighP[bestP]];
+           AliHLTTPCCAHit &hN = rowN.Hits()[neighN[bestN]];
+           Float_t yP = hP.Y() - h.Y();
+           Float_t zP = hP.Z() - h.Z();
+           Float_t yN = hN.Y() - h.Y();
+           Float_t zN = hN.Z() - h.Z();
+           Float_t dy = yP+yN;//(xN*yP - xP*yN)/TMath::Sqrt(xN*xN+xP*xP);
+           Float_t dz = zP+zN;//(xN*zP - xP*zN)/TMath::Sqrt(xN*xN+xP*xP);
+           //if( fMCTracks[l.fLab[0]].Pt()>1 ){
+           fhNeighChi->Fill(TMath::Sqrt(bestD/(xN*xN+xP*xP)/4.));
+           fhNeighDy->Fill(dy);
+           fhNeighDz->Fill(dz);          
+           //}
+         }
        }
 
-       nla = c.NHits();
-       if( nla>0 && label>=0 ){
-         double purity = double(lmax)/double(nla);
-         fhCellPurity->Fill(purity);
-         fhCellPurityVsN->Fill(c.NHits(),purity);
-         fhCellPurityVsPt->Fill(fMCTracks[label].Pt(),purity);
+       Bool_t okP=0, okN=0;
+       if( h.FirstTriplet()>=0 ){
+         for( int it=h.FirstTriplet(); it<row.NTriplets(); it++ ){
+           AliHLTTPCCATriplet &t = row.Triplets()[it];
+           if( t.HitMid()!=ih ) break;
+           //if( !t.Alive() ) continue;
+           AliHLTTPCCAHit &hP = rowP.Hits()[t.HitDown()];
+           AliHLTTPCCAHit &hN = rowN.Hits()[t.HitUp()];
+           AliHLTTPCCAHitLabel &lP = fHitLabels[fTracker->Hits()[hP.ID()].ID()];
+           AliHLTTPCCAHitLabel &lN = fHitLabels[fTracker->Hits()[hN.ID()].ID()];
+           for( Int_t jl=0; jl<3; jl++ ){
+             if( lP.fLab[jl]==l.fLab[0] ) okP = 1;
+             if( lN.fLab[jl]==l.fLab[0] ) okN = 1;
+           }
+         }     
        }
-       fhCellNHits->Fill(c.NHits());
-       if(lb) delete[] lb;
+       //fhNeighEff->Fill(iRow, okP&&okN );    
+       //fhNeighEffVsPt->Fill( fMCTracks[l.fLab[0]].Pt(), okP&&okN );  
       }
     }
+#endif
   }
+  
+
 
   // Select reconstructable MC tracks
 
@@ -433,10 +688,10 @@ void AliHLTTPCCAPerformance::SlicePerformance( Int_t iSlice, Bool_t PrintFlag )
       mc.Set() = 0;
       mc.NReconstructed() = 0;
       mc.NTurns() = 1;
-      if( mc.NHits() >=  10 && mc.P()>=.05 ){
+      if( mc.NHits() >=  30 && mc.P()>=.05 ){
        mc.Set() = 1;
        nMCAll++;
-       if( mc.P()>=1. ){
+       if( mc.NHits() >=  30 && mc.P()>=1. ){
          mc.Set() = 2;
          nMCRef++;
        }
@@ -459,7 +714,7 @@ void AliHLTTPCCAPerformance::SlicePerformance( Int_t iSlice, Bool_t PrintFlag )
       Int_t nla=0;
       //cout<<"\nHit labels:"<<endl;
       for( Int_t ihit=0; ihit<nhits; ihit++){
-       Int_t index = slice.OutTrackHits()[tCA.FirstHitRef()+ihit];
+       Int_t index = firstSliceHit + slice.OutTrackHits()[tCA.FirstHitRef()+ihit];
        AliHLTTPCCAHitLabel &l = fHitLabels[fTracker->Hits()[index].ID()];
        //cout<<l.fLab[0]<<" "<<l.fLab[1]<<" "<<l.fLab[2]<<endl;
        if(l.fLab[0]>=0 ) lb[nla++]= l.fLab[0];
@@ -485,7 +740,7 @@ void AliHLTTPCCAPerformance::SlicePerformance( Int_t iSlice, Bool_t PrintFlag )
       }
       lmax = 0;
       for( Int_t ihit=0; ihit<nhits; ihit++){
-       Int_t index = slice.OutTrackHits()[tCA.FirstHitRef()+ihit];
+       Int_t index = firstSliceHit + slice.OutTrackHits()[tCA.FirstHitRef()+ihit];
        AliHLTTPCCAHitLabel &l = fHitLabels[fTracker->Hits()[index].ID()];
        if( l.fLab[0] == labmax || l.fLab[1] == labmax || l.fLab[2] == labmax 
            ) lmax++;
@@ -604,10 +859,12 @@ void AliHLTTPCCAPerformance::Performance()
     fStatNClonesRef=0;
   */
   fStatNEvents++;
+
   for( Int_t islice=0; islice<fTracker->NSlices(); islice++){ 
     SlicePerformance(islice,0);
   }
 
+
   // global tracker performance
   {
       if( !fTracker ) return;
@@ -926,9 +1183,9 @@ void AliHLTTPCCAPerformance::Performance()
        <<fTracker->StatTime(2)/fTracker->StatNEvents()*1.e3<<" "
        <<fTracker->StatTime(3)/fTracker->StatNEvents()*1.e3<<" "
        <<fTracker->StatTime(4)/fTracker->StatNEvents()*1.e3<<" "
-       <<fTracker->StatTime(5)/fTracker->StatNEvents()*1.e3<<"["
-       <<fTracker->StatTime(6)/fTracker->StatNEvents()*1.e3<<"/"
-       <<fTracker->StatTime(7)/fTracker->StatNEvents()*1.e3<<"] "
+       <<fTracker->StatTime(5)/fTracker->StatNEvents()*1.e3<<" "
+       <<fTracker->StatTime(6)/fTracker->StatNEvents()*1.e3<<" "
+       <<fTracker->StatTime(7)/fTracker->StatNEvents()*1.e3<<" "
        <<fTracker->StatTime(8)/fTracker->StatNEvents()*1.e3<<" "
        <<" msec/event "<<endl;
   }
@@ -988,8 +1245,9 @@ void AliHLTTPCCAPerformance::Performance()
   WriteHistos();
 }
 
-void AliHLTTPCCAPerformance::WriteMCEvent( ostream &out )
+void AliHLTTPCCAPerformance::WriteMCEvent( ostream &out ) const
 {
+  // write MC information to the file
   out<<fNMCTracks<<endl;
   for( Int_t it=0; it<fNMCTracks; it++ ){
     AliHLTTPCCAMCTrack &t = fMCTracks[it];
@@ -1016,8 +1274,9 @@ void AliHLTTPCCAPerformance::WriteMCEvent( ostream &out )
   }
 }
 
-void AliHLTTPCCAPerformance::WriteMCPoints( ostream &out )
+void AliHLTTPCCAPerformance::WriteMCPoints( ostream &out ) const
 {  
+  // write Mc points to the file
   out<<fNMCPoints<<endl;
   for( Int_t ip=0; ip<fNMCPoints; ip++ ){
     AliHLTTPCCAMCPoint &p = fMCPoints[ip];
@@ -1035,6 +1294,7 @@ void AliHLTTPCCAPerformance::WriteMCPoints( ostream &out )
 
 void AliHLTTPCCAPerformance::ReadMCEvent( istream &in )
 {
+  // read mc info from the file
   StartEvent();
   if( fMCTracks ) delete[] fMCTracks;
   fMCTracks = 0;
@@ -1075,6 +1335,7 @@ void AliHLTTPCCAPerformance::ReadMCEvent( istream &in )
 
 void AliHLTTPCCAPerformance::ReadMCPoints( istream &in )
 {
+  // read mc points from the file
   if( fMCPoints ) delete[] fMCPoints;
   fMCPoints = 0;
   fNMCPoints = 0;
index 97f53a5fd61cd63d44d1d830da6e71596fafc802..e8aa322e6e7c264b509c20fd13a31784605fb5e1 100644 (file)
@@ -8,9 +8,9 @@
 #ifndef ALIHLTTPCCAPERFORMANCE_H
 #define ALIHLTTPCCAPERFORMANCE_H
 
+#include "AliHLTTPCCADef.h"
 
-#include "TObject.h"
-
+class TObject;
 class TParticle;
 class AliHLTTPCCAMCTrack;
 class AliHLTTPCCAMCPoint;
@@ -28,7 +28,7 @@ class TProfile;
  * and for AliHLTTPCCAGBTracker global tracker
  *
  */
-class AliHLTTPCCAPerformance:public TObject
+class AliHLTTPCCAPerformance
 {
 
  public:
@@ -58,9 +58,9 @@ class AliHLTTPCCAPerformance:public TObject
   void SlicePerformance( Int_t iSlice, Bool_t PrintFlag  );
   void Performance();
 
-  void WriteMCEvent( ostream &out );
+  void WriteMCEvent( ostream &out ) const;
   void ReadMCEvent( istream &in );
-  void WriteMCPoints( ostream &out );
+  void WriteMCPoints( ostream &out ) const;
   void ReadMCPoints( istream &in );
   Bool_t& DoClusterPulls(){ return fDoClusterPulls; }
 
@@ -133,15 +133,27 @@ protected:
     *fhCellNHits//* cell n hits
     ;
 
-    TProfile 
-  *fhCellPurityVsN, //* cell purity vs N hits
-  *fhCellPurityVsPt,//* cell purity vs MC Pt
-      *fhEffVsP, //* reconstruction efficiency vs P plot
-      *fhGBEffVsP; //* global reconstruction efficiency vs P plot
+  TProfile 
+    *fhCellPurityVsN, //* cell purity vs N hits
+    *fhCellPurityVsPt,//* cell purity vs MC Pt
+    *fhEffVsP, //* reconstruction efficiency vs P plot
+    *fhGBEffVsP, //* global reconstruction efficiency vs P plot
+    *fhNeighQuality, // quality for neighbours finder 
+    *fhNeighEff,// efficiency for neighbours finder
+    *fhNeighQualityVsPt,// quality for neighbours finder vs track Pt
+    *fhNeighEffVsPt;// efficiency for neighbours finder vs track Pt
+  TH1D 
+  *fhNeighDy, // dy for neighbours
+    *fhNeighDz,// dz for neighbours
+    *fhNeighChi;// chi2^0.5 for neighbours
+  TH2D
+    *fhNeighDyVsPt, // dy for neighbours vs track Pt
+    *fhNeighDzVsPt,// dz for neighbours vs track Pt
+    *fhNeighChiVsPt, // chi2^0.5 for neighbours vs track Pt
+    *fhNeighNCombVsArea; // N neighbours in the search area
 
   static void WriteDir2Current( TObject *obj );
   
-  ClassDef(AliHLTTPCCAPerformance,1) 
 };
 
 #endif
diff --git a/HLT/TPCLib/tracking-ca/AliHLTTPCCAProcess.h b/HLT/TPCLib/tracking-ca/AliHLTTPCCAProcess.h
new file mode 100644 (file)
index 0000000..64985cb
--- /dev/null
@@ -0,0 +1,104 @@
+//-*- Mode: C++ -*-
+
+//* 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 ALIHLTTPCCAPROCESS_H
+#define ALIHLTTPCCAPROCESS_H
+
+
+/**
+ * Definitions needed for AliHLTTPCCATracker
+ *
+ */
+
+#include "AliHLTTPCCADef.h"
+#include "AliHLTTPCCATrackParam1.h"
+
+class AliHLTTPCCATracker;
+
+#if defined(HLTCA_GPUCODE)
+
+template<class TProcess>
+GPUg() void AliHLTTPCCAProcess()
+{
+  AliHLTTPCCATracker &tracker = *((AliHLTTPCCATracker*) cTracker);
+
+  GPUshared() typename TProcess::AliHLTTPCCASharedMemory smem;
+
+  TProcess::Thread( gridDim.x, blockDim.x, blockIdx.x, threadIdx.x, 0, smem, tracker  );
+
+#define GPUPROCESS(iSync) \
+  if( TProcess::NThreadSyncPoints()>=iSync ){ \
+    GPUsync(); \
+    TProcess::Thread( gridDim.x, blockDim.x, blockIdx.x, threadIdx.x, iSync, smem, tracker  ); \
+  }
+
+  GPUPROCESS(1)
+  GPUPROCESS(2)
+  GPUPROCESS(3)
+    
+    //for( int iSync=0; iSync<=TProcess::NThreadSyncPoints(); iSync++){
+    //__syncthreads();
+    //TProcess::ThreadGPU( gridDim.x, blockDim.x, blockIdx.x, threadIdx.x, iSync, smem, tracker  ); 
+    //}
+    
+#undef GPUPROCESS
+}
+
+#else
+
+template<class TProcess>
+GPUg() void AliHLTTPCCAProcess( Int_t nBlocks, Int_t nThreads, AliHLTTPCCATracker &tracker )
+{
+  for( Int_t iB=0; iB<nBlocks; iB++ ){
+    typename TProcess::AliHLTTPCCASharedMemory smem;
+    for( Int_t iS=0; iS<=TProcess::NThreadSyncPoints(); iS++)
+      for( Int_t iT=0; iT<nThreads; iT++ )
+       TProcess::Thread( nBlocks, nThreads, iB, iT, iS, smem, tracker  );
+  }
+}
+
+#endif
+
+
+
+#if defined(HLTCA_GPUCODE)
+
+template<typename TProcess>
+GPUg() void AliHLTTPCCAProcess1()
+{
+  AliHLTTPCCATracker &tracker = *((AliHLTTPCCATracker*) cTracker);
+  AliHLTTPCCATrackParam1 tParam; 
+  
+  GPUshared() typename TProcess::AliHLTTPCCASharedMemory sMem;  
+  
+  typename TProcess::ThreadMemory rMem;
+
+  for( int iSync=0; iSync<=TProcess::NThreadSyncPoints(); iSync++){
+    GPUsync(); 
+    TProcess::Thread( gridDim.x, blockDim.x, blockIdx.x, threadIdx.x, iSync, 
+                     sMem, rMem, tracker, tParam  ); 
+  }  
+}
+
+#else
+
+template<typename TProcess>
+GPUg() void AliHLTTPCCAProcess1( Int_t nBlocks, Int_t nThreads, AliHLTTPCCATracker &tracker )
+{
+  for( Int_t iB=0; iB<nBlocks; iB++ ){
+    typename TProcess::AliHLTTPCCASharedMemory smem;
+    typename TProcess::AliHLTTPCCAThreadMemory rMem[nThreads];
+    AliHLTTPCCATrackParam1 tParam[nThreads];
+    for( Int_t iS=0; iS<=TProcess::NThreadSyncPoints(); iS++){
+      for( Int_t iT=0; iT<nThreads; iT++ )
+       TProcess::Thread( nBlocks, nThreads, iB, iT, iS, smem, rMem[iT], tracker, tParam[iT]  );
+    }
+  }
+}
+
+#endif
+
+#endif
index 1a0370d7a5a0f9b0f417151b6e78813613451453..479ff00c1e7dbbfe8bd85a50d853c255788d5a19 100644 (file)
 
 #include "AliHLTTPCCARow.h"
 
-ClassImp(AliHLTTPCCARow)
 
-  AliHLTTPCCARow::AliHLTTPCCARow() :fHits(0),fCells(0),fCellHitPointers(0),fEndPoints(0),fNHits(0),fNCells(0),fNEndPoints(0),fX(0),fMaxY(0),fDeltaY(0),fDeltaZ(0)
+#if !defined(HLTCA_GPUCODE)
+AliHLTTPCCARow::AliHLTTPCCARow() 
+  :
+  fFirstHit(0), fNHits(0), fX(0), fMaxY(0), fGrid(),
+  fHy0(0),fHz0(0), fHstepY(0),fHstepZ(0), fHstepYi(0), fHstepZi(0),
+  fFullSize(0), fFullOffset(0), fFullGridOffset(0),fFullLinkOffset(0)
 {
-  //* constructor
+  // dummy constructor
 }
 
-AliHLTTPCCARow::AliHLTTPCCARow( const AliHLTTPCCARow &)
-  :fHits(0),fCells(0),fCellHitPointers(0),fEndPoints(0),fNHits(0),fNCells(0),fNEndPoints(0),fX(0),fMaxY(0),fDeltaY(0),fDeltaZ(0)
-{
-  //* dummy
-}
+#endif
 
-AliHLTTPCCARow &AliHLTTPCCARow::operator=( const AliHLTTPCCARow &)
-{
-  //* dummy
-  fHits = 0;
-  fCells = 0;
-  fCellHitPointers = 0;
-  fEndPoints = 0;
-  fNHits = 0;
-  fNCells = 0;
-  fNEndPoints = 0;
-  return *this;
-}
-
-void AliHLTTPCCARow::Clear()
-{
-  //* clear memory
-  if(fHits) delete[] fHits;
-  fHits = 0;
-  fCells = 0;
-  fCellHitPointers = 0;    
-  fEndPoints = 0;
-  fNHits = fNCells = fNEndPoints = 0;
-}
index 87bd09da17fd0403359b1ae37453b589ffe5b35e..02f5a8e67f8199812833ded76ef1de9b4c5d28a9 100644 (file)
@@ -8,11 +8,8 @@
 #ifndef ALIHLTTPCCAROW_H
 #define ALIHLTTPCCAROW_H
 
-#include "Rtypes.h"
-
-#include "AliHLTTPCCAHit.h"
-#include "AliHLTTPCCACell.h"
-#include "AliHLTTPCCAEndPoint.h"
+#include "AliHLTTPCCADef.h"
+#include "AliHLTTPCCAGrid.h"
 
 /**
  * @class ALIHLTTPCCARow
@@ -25,54 +22,40 @@ class AliHLTTPCCARow
 {
  public: 
 
-  AliHLTTPCCARow();
-  AliHLTTPCCARow ( const AliHLTTPCCARow &);
-  AliHLTTPCCARow &operator=( const AliHLTTPCCARow &);
-
-  virtual ~AliHLTTPCCARow(){ Clear(); }
-
-  AliHLTTPCCAHit  *&Hits() { return fHits; }
-  AliHLTTPCCACell *&Cells(){ return fCells;}
-  Int_t  *&CellHitPointers() { return fCellHitPointers; }
-  AliHLTTPCCAEndPoint *&EndPoints(){ return fEndPoints;}
-  Int_t &NHits()  { return fNHits; }
-  Int_t &NCells() { return fNCells; }
-  Int_t &NEndPoints() { return fNEndPoints; }
-  Float_t &X() { return fX; }
-  Float_t &MaxY() { return fMaxY; }
-  Float_t &DeltaY() { return fDeltaY; }
-  Float_t &DeltaZ() { return fDeltaZ; }
-
-  AliHLTTPCCAHit  &GetCellHit( AliHLTTPCCACell &c, Int_t i ){ 
-    //* get hit number i of the cell c
-    return fHits[fCellHitPointers[c.FirstHitRef()+i]]; 
-  }
-
-  void Clear();
+#if !defined(HLTCA_GPUCODE)
+  AliHLTTPCCARow();  
+#endif
 
-  static Bool_t CompareCellZMax( AliHLTTPCCACell&c, Double_t ZMax )
-  {
-    return (c.ZMax()<ZMax);
-  }
-  static Bool_t CompareEndPointZ( AliHLTTPCCAEndPoint &p, Double_t Z )
-  {
-    return (p.Param().GetZ()<Z);
-  }
+  //AliHLTTPCCARow &operator=( const AliHLTTPCCARow &);
+
+  GPUhd() Int_t   &FirstHit(){ return fFirstHit; }
+  GPUhd() Int_t   &NHits()   { return fNHits; }
+  GPUhd() Float_t &X()       { return fX; }
+  GPUhd() Float_t &MaxY()    { return fMaxY; }
+  GPUhd() AliHLTTPCCAGrid &Grid(){ return fGrid; }  
+
+  GPUhd() float &Hy0() { return fHy0;}
+  GPUhd() float &Hz0() { return fHz0;}
+  GPUhd() float &HstepY() { return fHstepY;}
+  GPUhd() float &HstepZ() { return fHstepZ;}
+  GPUhd() float &HstepYi() { return fHstepYi;}
+  GPUhd() float &HstepZi() { return fHstepZi;}
+  GPUhd() int &FullSize() { return fFullSize;}
+  GPUhd() int &FullOffset() { return fFullOffset;}
+  GPUhd() int &FullGridOffset() { return fFullGridOffset;}
+  GPUhd() int &FullLinkOffset() { return fFullLinkOffset;}
 
 private:
 
-  AliHLTTPCCAHit *fHits;   // hit array
-  AliHLTTPCCACell *fCells; // cell array
-  Int_t *fCellHitPointers; // pointers cell->hits
-  AliHLTTPCCAEndPoint *fEndPoints; // array of track end points
-  Int_t fNHits, fNCells, fNEndPoints;   // number of hits and cells
+  Int_t fFirstHit;         // index of the first hit in the hit array
+  Int_t fNHits;            // number of hits 
   Float_t fX;              // X coordinate of the row
   Float_t fMaxY;           // maximal Y coordinate of the row
-  Float_t fDeltaY;         // allowed Y deviation to the next row
-  Float_t fDeltaZ;         // allowed Z deviation to the next row
+  AliHLTTPCCAGrid fGrid;   // grid of hits
+
+  float fHy0,fHz0, fHstepY,fHstepZ, fHstepYi, fHstepZi; // temporary variables
+  int fFullSize, fFullOffset, fFullGridOffset,fFullLinkOffset; // temporary variables
 
-  ClassDef(AliHLTTPCCARow,1);
 };
 
 #endif
diff --git a/HLT/TPCLib/tracking-ca/AliHLTTPCCAStartHitsFinder.cxx b/HLT/TPCLib/tracking-ca/AliHLTTPCCAStartHitsFinder.cxx
new file mode 100644 (file)
index 0000000..09bcb24
--- /dev/null
@@ -0,0 +1,72 @@
+// @(#) $Id: AliHLTTPCCAStartHitsFinder.cxx 27042 2008-07-02 12:06:02Z richterm $
+//***************************************************************************
+// This file is property of and copyright by the ALICE HLT Project          * 
+// ALICE Experiment at CERN, All rights reserved.                           *
+//                                                                          *
+// Primary Authors: Sergey Gorbunov <sergey.gorbunov@kip.uni-heidelberg.de> *
+//                  Ivan Kisel <kisel@kip.uni-heidelberg.de>                *
+//                  for The ALICE HLT Project.                              *
+//                                                                          *
+// Permission to use, copy, modify and distribute this software and its     *
+// documentation strictly for non-commercial purposes is hereby granted     *
+// without fee, provided that the above copyright notice appears in all     *
+// copies and that both the copyright notice and this permission notice     *
+// appear in the supporting documentation. The authors make no claims       *
+// about the suitability of this software for any purpose. It is            *
+// provided "as is" without express or implied warranty.                    *
+//***************************************************************************
+
+#include "AliHLTTPCCAStartHitsFinder.h"
+#include "AliHLTTPCCATracker.h"
+#include "AliHLTTPCCAMath.h"
+
+GPUd() void AliHLTTPCCAStartHitsFinder::Thread
+( Int_t /*nBlocks*/, Int_t nThreads, Int_t iBlock, Int_t iThread, Int_t iSync,
+  AliHLTTPCCASharedMemory &s, AliHLTTPCCATracker &tracker )
+{
+  // find start hits for tracklets
+
+  if( iSync==0 )
+    {
+      if( iThread==0 ){
+       Int_t *startHits = tracker.StartHits();
+       if( iBlock==0 ){
+         CAMath::atomicExch(startHits,0); 
+       }
+       s.fNRows = tracker.Param().NRows();
+       s.fIRow = iBlock+1;
+       s.fNRowStartHits = 0;
+       if( s.fIRow <= s.fNRows-4 ){
+         int first = tracker.Rows()[s.fIRow].FirstHit();
+         s.fNHits = tracker.Rows()[s.fIRow].NHits(); 
+         if( s.fNHits>=1024 ) s.fNHits = 1023;
+         s.fHitLinkUp = tracker.HitLinkUp() + first;
+         s.fHitLinkDown = tracker.HitLinkDown() + first;
+       } else s.fNHits = -1;
+      }
+    } 
+  else if( iSync==1 )
+    {
+      for( int ih=iThread; ih<s.fNHits; ih+=nThreads ){      
+       if( ( s.fHitLinkDown[ih]<0 ) && ( s.fHitLinkUp[ih]>=0 ) ){
+         int oldNRowStartHits = CAMath::atomicAdd(&s.fNRowStartHits,1);
+         s.fRowStartHits[oldNRowStartHits] = AliHLTTPCCATracker::IRowIHit2ID(s.fIRow, ih);
+       }
+      }
+    }
+  else if( iSync==2 )
+    {
+      if( iThread == 0 ){
+       Int_t *startHits = tracker.StartHits();
+       s.fNOldStartHits = CAMath::atomicAdd(startHits,s.fNRowStartHits);  
+      }
+    }
+  else if( iSync==3 )
+    {
+      Int_t *startHits = tracker.StartHits();
+      for( int ish=iThread; ish<s.fNRowStartHits; ish+=nThreads ){    
+       startHits[1+s.fNOldStartHits+ish] = s.fRowStartHits[ish];
+      }
+    }
+}
+
diff --git a/HLT/TPCLib/tracking-ca/AliHLTTPCCAStartHitsFinder.h b/HLT/TPCLib/tracking-ca/AliHLTTPCCAStartHitsFinder.h
new file mode 100644 (file)
index 0000000..f33f00b
--- /dev/null
@@ -0,0 +1,53 @@
+//-*- Mode: C++ -*-
+
+//* 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 ALIHLTTPCCASTARTHITSFINDER_H
+#define ALIHLTTPCCASTARTHITSFINDER_H
+
+#include "AliHLTTPCCADef.h"
+
+class AliHLTTPCCATracker;
+
+/**
+ * @class AliHLTTPCCAStartHitsFinder
+ * 
+ */
+class AliHLTTPCCAStartHitsFinder
+{
+ public:
+  class AliHLTTPCCASharedMemory
+    {
+     friend class AliHLTTPCCAStartHitsFinder;
+    public:
+ #if !defined(HLTCA_GPUCODE)
+      AliHLTTPCCASharedMemory()
+       : fIRow(0), fNRows(0), fNHits(0), fHitLinkDown(0), fHitLinkUp(0), fNOldStartHits(0), fNRowStartHits(0)
+      {}
+
+      AliHLTTPCCASharedMemory( const AliHLTTPCCASharedMemory& /*dummy*/) 
+       : fIRow(0), fNRows(0), fNHits(0), fHitLinkDown(0), fHitLinkUp(0), fNOldStartHits(0), fNRowStartHits(0)
+      {}
+      AliHLTTPCCASharedMemory& operator=(const AliHLTTPCCASharedMemory& /*dummy*/){ return *this; }
+#endif
+    protected:
+      Int_t fIRow; // row index
+      Int_t fNRows; // n rows
+      Int_t fNHits; // n hits in the row
+      Short_t *fHitLinkDown; // pointer to down link array
+      Short_t *fHitLinkUp; // pointer to the up link array
+      Int_t fRowStartHits[1024]; // temp. array for the start hits
+      Int_t fNOldStartHits; // n start hits from other jobs
+      Int_t fNRowStartHits; // n start hits for this row
+   };
+
+  GPUd() static Int_t NThreadSyncPoints(){ return 3; }  
+
+  GPUd() static void Thread( Int_t nBlocks, Int_t nThreads, Int_t iBlock, Int_t iThread, Int_t iSync,
+                            AliHLTTPCCASharedMemory &smem, AliHLTTPCCATracker &tracker );
+};
+
+
+#endif
index 78ba817d5e83e39cea520b88f650f047c1f115fd..a6b534d55567545b0ed76a53a28230184d1def79 100644 (file)
@@ -18,9 +18,8 @@
 
 #include "AliHLTTPCCATrack.h"
 
-
 //ClassImp(AliHLTTPCCATrack)
 
-void AliHLTTPCCATrack::Dummy()
-{
-}
+//void AliHLTTPCCATrack::Dummy()
+//{
+//}
index 1bfb49cca9d582f6da56a50b6c92cbb93e3cda42..723cb99181d110aacdf13dd3649d41a79759199b 100644 (file)
@@ -8,7 +8,8 @@
 #ifndef ALIHLTTPCCATRACK_H
 #define ALIHLTTPCCATRACK_H
 
-#include "Rtypes.h"
+#include "AliHLTTPCCADef.h"
+#include "AliHLTTPCCATrackParam.h"
 
 /**
  * @class ALIHLTTPCCAtrack
 class AliHLTTPCCATrack
 {
  public:
-  AliHLTTPCCATrack():fAlive(0),fFirstCellID(0),fNCells(0){}
-  virtual ~AliHLTTPCCATrack(){}
-
-  Bool_t &Alive()              { return fAlive; }
-  Int_t  &NCells()            { return fNCells; }
-  Int_t  *CellID()            { return fCellID; }
-  Int_t  &FirstCellID()        { return fFirstCellID; }
-  Int_t  *PointID()            { return fPointID; }
-
- private:
+#if !defined(HLTCA_GPUCODE)
+  AliHLTTPCCATrack() :fAlive(0),fFirstHitID(0),fNHits(0), fParam(){}
+  ~AliHLTTPCCATrack(){}
+#endif
 
+  GPUhd() Bool_t &Alive()               { return fAlive; }
+  GPUhd() Int_t  &NHits()               { return fNHits; }
+  GPUhd() Int_t  &FirstHitID()          { return fFirstHitID; }
+  GPUhd() AliHLTTPCCATrackParam &Param(){ return fParam; };
+  
+private:
+  
   Bool_t fAlive;       // flag for mark tracks used by the track merger
-  Int_t  fFirstCellID; // index of the first track cell in the track->cell pointer array
-  Int_t  fNCells;      // number of track cells
-  Int_t  fCellID[3];   // ID of first,middle,last cell
-  Int_t  fPointID[2];  // ID of the track endpoints
+  Int_t  fFirstHitID; // index of the first track cell in the track->cell pointer array
+  Int_t  fNHits;      // number of track cells
+  AliHLTTPCCATrackParam fParam; // track parameters 
   
- private:
-  void Dummy(); // to make rulechecker happy by having something in .cxx file
+private:
+  //void Dummy(); // to make rulechecker happy by having something in .cxx file
 
-  //ClassDef(AliHLTTPCCATrack,1);
+  //ClassDef(AliHLTTPCCATrack,1)
 };
 
 #endif
index 395eb638dff1712ec53428c976b6e65abfe6850a..0a15d32fa0ebd986ffe3a1139c551bf1ed2ff9bd 100644 (file)
@@ -19,7 +19,7 @@
 #include "AliHLTTPCCATrackConvertor.h"
 #include "AliExternalTrackParam.h"
 #include "AliHLTTPCCATrackParam.h"
-#include "TMath.h"
+#include "AliHLTTPCCAMath.h"
 
 
 void AliHLTTPCCATrackConvertor::GetExtParam( const AliHLTTPCCATrackParam &T1, AliExternalTrackParam &T2, Double_t alpha, Double_t Bz )
@@ -37,7 +37,7 @@ void AliHLTTPCCATrackConvertor::GetExtParam( const AliHLTTPCCATrackParam &T1, Al
   { // kappa => 1/pt
     const Double_t kCLight = 0.000299792458;  
     Double_t c = 1.e4;
-    if( TMath::Abs(Bz)>1.e-4 ) c = 1./(Bz*kCLight);
+    if( CAMath::Abs(Bz)>1.e-4 ) c = 1./(Bz*kCLight);
     par[4] *= c;
     cov[10]*= c;
     cov[11]*= c;
@@ -56,7 +56,7 @@ void AliHLTTPCCATrackConvertor::GetExtParam( const AliHLTTPCCATrackParam &T1, Al
     cov[10] = -cov[10];
     cov[11] = -cov[11];
   }
-  T2.Set((double)T1.GetX(),alpha,par,cov);
+  T2.Set(T1.GetX(),alpha,par,cov);
 }
 
 void AliHLTTPCCATrackConvertor::SetExtParam( AliHLTTPCCATrackParam &T1, const AliExternalTrackParam &T2, Double_t Bz )
@@ -68,7 +68,7 @@ void AliHLTTPCCATrackConvertor::SetExtParam( AliHLTTPCCATrackParam &T1, const Al
   T1.X() = T2.GetX();
   if(T1.SinPhi()>.99 ) T1.SinPhi()=.99;
   if(T1.SinPhi()<-.99 ) T1.SinPhi()=-.99;
-  T1.CosPhi() = TMath::Sqrt(1.-T1.SinPhi()*T1.SinPhi());
+  T1.CosPhi() = CAMath::Sqrt(1.-T1.SinPhi()*T1.SinPhi());
   const Double_t kCLight = 0.000299792458;  
   Double_t c = Bz*kCLight;
   { // 1/pt -> kappa 
index 0d3d8e27b7026debd3763fc9868c527bfaa5a290..5930a24fe8c450f8f8444f19ad19c578813b226d 100644 (file)
@@ -7,7 +7,8 @@
 
 #ifndef ALIHLTTPCCATRACKCONVERTOR_H
 #define ALIHLTTPCCATRACKCONVERTOR_H
-#include "Rtypes.h"
+
+#include "AliHLTTPCCADef.h"
 
 class AliExternalTrackParam;
 class AliHLTTPCCATrackParam;
index 6e5bf236687ae21dc90ce1d17ad3d5b509cc3016..825a9afaaa0919cf57911a04a4708c4e8fd9addc 100644 (file)
 //***************************************************************************
 
 #include "AliHLTTPCCATrackParam.h"
-#include "TMath.h"
-#include "Riostream.h"
+#include "AliHLTTPCCAMath.h"
 
-//ClassImp(AliHLTTPCCATrackParam)
 
 //
 // Circle in XY:
@@ -32,7 +30,7 @@
 
 
 
-void AliHLTTPCCATrackParam::ConstructXY3( const Float_t x[3], const Float_t y[3], 
+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
@@ -49,7 +47,7 @@ void AliHLTTPCCATrackParam::ConstructXY3( const Float_t x[3], const Float_t y[3]
   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 = TMath::Sqrt(lx*lx + ly*ly);
+  Float_t l = CAMath::Sqrt(lx*lx + ly*ly);
  
   Float_t li = 1./l;
   Float_t li2 = li*li;
@@ -129,7 +127,7 @@ void AliHLTTPCCATrackParam::ConstructXY3( const Float_t x[3], const Float_t y[3]
 }
 
 
-Float_t  AliHLTTPCCATrackParam::GetS( Float_t x, Float_t y ) const
+GPUd() Float_t  AliHLTTPCCATrackParam::GetS( Float_t x, Float_t y ) const
 {
   //* Get XY path length to the given point
 
@@ -139,12 +137,12 @@ Float_t  AliHLTTPCCATrackParam::GetS( Float_t x, Float_t y ) const
   x-= GetX();
   y-= GetY();
   Float_t dS = x*ex + y*ey;
-  if( TMath::Abs(k)>1.e-4 ) dS = TMath::ATan2( k*dS, 1+k*(x*ey-y*ex) )/k;
+  if( CAMath::Abs(k)>1.e-4 ) dS = CAMath::ATan2( k*dS, 1+k*(x*ey-y*ex) )/k;
   return dS;
 }
 
-void  AliHLTTPCCATrackParam::GetDCAPoint( Float_t x, Float_t y, Float_t z,
-                                          Float_t &xp, Float_t &yp, Float_t &zp ) const
+GPUd() void  AliHLTTPCCATrackParam::GetDCAPoint( Float_t x, Float_t y, Float_t z,
+                                                Float_t &xp, Float_t &yp, Float_t &zp ) const
 {
   //* Get the track point closest to the (x,y,z)
 
@@ -162,15 +160,15 @@ void  AliHLTTPCCATrackParam::GetDCAPoint( Float_t x, Float_t y, Float_t z,
   yp = y0 + (dy + ex*( (dx*dx+dy*dy)*k - 2*(-dx*ey+dy*ex) )/(a+1) )/a;
   Float_t s = GetS(x,y);
   zp = GetZ() + GetDzDs()*s;
-  if( TMath::Abs(k)>1.e-2 ){
-    Float_t dZ = TMath::Abs( GetDzDs()*TMath::TwoPi()/k );
+  if( CAMath::Abs(k)>1.e-2 ){
+    Float_t dZ = CAMath::Abs( GetDzDs()*CAMath::TwoPi()/k );
     if( dZ>.1 ){
-      zp+= TMath::Nint((z-zp)/dZ)*dZ;    
+      zp+= CAMath::Nint((z-zp)/dZ)*dZ;    
     }
   }
 }
 
-void AliHLTTPCCATrackParam::ConstructXYZ3( const Float_t p0[5], const Float_t p1[5], 
+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[] )
 {      
@@ -187,21 +185,21 @@ void AliHLTTPCCATrackParam::ConstructXYZ3( const Float_t p0[5], const Float_t p1
 
   Float_t pS[3] = { GetS(px[0],py[0]), GetS(px[1],py[1]), GetS(px[2],py[2]) };
   Float_t k = Kappa();
-  if( TMath::Abs(k)>1.e-2 ){    
-    Float_t dS = TMath::Abs( TMath::TwoPi()/k );
-    pS[1]+= TMath::Nint( (pS[0]-pS[1])/dS )*dS; // not more than half turn
-    pS[2]+= TMath::Nint( (pS[1]-pS[2])/dS )*dS;
+  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 = TMath::Abs(t0[3]*dS);
-      if( TMath::Abs(dZ)>1. ){
+      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]+= TMath::Nint( (s0-pS[0])/dS )*dS ;
-       pS[1]+= TMath::Nint( (s1-pS[1])/dS )*dS ;
-       pS[2]+= TMath::Nint( (s2-pS[2])/dS )*dS ;       
+       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 ;      
       }
     }
   }
@@ -224,12 +222,10 @@ void AliHLTTPCCATrackParam::ConstructXYZ3( const Float_t p0[5], const Float_t p1
 }
 
 
-Bool_t  AliHLTTPCCATrackParam::TransportToX( Float_t x )
+GPUd() Int_t  AliHLTTPCCATrackParam::TransportToX( Float_t x, Float_t maxSinPhi )
 {
   //* Transport the track parameters to X=x 
 
-  Bool_t ret = 1;
-
   Float_t x0  = X();
   //Float_t y0  = Y();
   Float_t k   = Kappa();
@@ -239,49 +235,37 @@ Bool_t  AliHLTTPCCATrackParam::TransportToX( Float_t x )
 
   Float_t ey1 = k*dx + ey;
   Float_t ex1;
-  if( TMath::Abs(ey1)>1 ){ // no intersection -> check the border    
-    ey1 = ( ey1>0 ) ?1 :-1;
-    ex1 = 0;
-    dx = ( TMath::Abs(k)>1.e-4) ? ( (ey1-ey)/k ) :0;
-    
-    Float_t ddx = TMath::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;
+  if( CAMath::Abs(ey1)>maxSinPhi ){ // no intersection 
+    return 0;
   }else{
-    ex1 = TMath::Sqrt(1 - ey1*ey1);
+    ex1 = CAMath::Sqrt(1 - ey1*ey1);
     if( ex<0 ) ex1 = -ex1;  
   }
   
   Float_t dx2 = dx*dx;
-  CosPhi() = ex1;
   Float_t ss = ey+ey1;
   Float_t cc = ex+ex1;  
-  Float_t tg = 0;
-  if( TMath::Abs(cc)>1.e-4 ) tg = ss/cc; // tan((phi1+phi)/2)
-  else ret = 0; 
+
+  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*TMath::Sqrt(1+tg*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 = ( TMath::Abs(k)>1.e-4)  ? (2*TMath::ASin(dSin)/k) :dl;  
+  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( TMath::Abs(cc)>1.e-4 ) cci = 1./cc;
-  else ret = 0;
-  if( TMath::Abs(ex)>1.e-4 ) exi = 1./ex;
-  else ret = 0;
-  if( TMath::Abs(ex1)>1.e-4 ) ex1i = 1./ex1;
-  else ret = 0;
-
-  if( !ret ) return ret;
-
+  
+  Float_t cci = 1./cc;
+  Float_t exi = 1./ex;
+  Float_t ex1i = 1./ex1;
+  
+  CosPhi() = ex1;
   X() += dx;
   fP[0]+= dy;
   fP[1]+= dz;
@@ -336,18 +320,19 @@ Bool_t  AliHLTTPCCATrackParam::TransportToX( Float_t x )
   fC[13]= c43;
   fC[14]= c44;
 
-  return ret;
+  return 1;
 }
 
-Bool_t AliHLTTPCCATrackParam::TransportToXWithMaterial( Float_t x, Float_t Bz )
+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(x, par );
+  return TransportToXWithMaterial(Xto, par );
 }
 
 
-Bool_t  AliHLTTPCCATrackParam::TransportToXWithMaterial( Float_t x, AliHLTTPCCATrackFitParam &par )
+GPUd() Bool_t  AliHLTTPCCATrackParam::TransportToXWithMaterial( Float_t x, AliHLTTPCCATrackFitParam &par )
 {
   //* Transport the track parameters to X=x 
 
@@ -364,19 +349,19 @@ Bool_t  AliHLTTPCCATrackParam::TransportToXWithMaterial( Float_t x, AliHLTTPCCAT
 
   Float_t ey1 = k*dx + ey;
   Float_t ex1;
-  if( TMath::Abs(ey1)>.99 ){ // no intersection -> check the border    
+  if( CAMath::Abs(ey1)>.99 ){ // no intersection -> check the border    
     ey1 = ( ey1>0 ) ?1 :-1;
     ex1 = 0;
-    dx = ( TMath::Abs(k)>1.e-4) ? ( (ey1-ey)/k ) :0;
+    dx = ( CAMath::Abs(k)>1.e-4) ? ( (ey1-ey)/k ) :0;
     
-    Float_t ddx = TMath::Abs(x0+dx - x)*k*k;
+    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 = TMath::Sqrt(1 - ey1*ey1);
+    ex1 = CAMath::Sqrt(1 - ey1*ey1);
     if( ex<0 ) ex1 = -ex1;  
   }
   
@@ -385,24 +370,24 @@ Bool_t  AliHLTTPCCATrackParam::TransportToXWithMaterial( Float_t x, AliHLTTPCCAT
   Float_t ss = ey+ey1;
   Float_t cc = ex+ex1;  
   Float_t tg = 0;
-  if( TMath::Abs(cc)>1.e-4 ) tg = ss/cc; // tan((phi1+phi)/2)
+  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*TMath::Sqrt(1+tg*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 = ( TMath::Abs(k)>1.e-4)  ? (2*TMath::ASin(dSin)/k) :dl;
+  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( TMath::Abs(cc)>1.e-4 ) cci = 1./cc;
+  if( CAMath::Abs(cc)>1.e-4 ) cci = 1./cc;
   else ret = 0;
-  if( TMath::Abs(ex)>1.e-4 ) exi = 1./ex;
+  if( CAMath::Abs(ex)>1.e-4 ) exi = 1./ex;
   else ret = 0;
-  if( TMath::Abs(ex1)>1.e-4 ) ex1i = 1./ex1;
+  if( CAMath::Abs(ex1)>1.e-4 ) ex1i = 1./ex1;
   else ret = 0;
 
   if( !ret ) return ret;
@@ -461,7 +446,7 @@ Bool_t  AliHLTTPCCATrackParam::TransportToXWithMaterial( Float_t x, AliHLTTPCCAT
   fC[13]= c43;
   fC[14]= c44;
 
-  Float_t d = TMath::Sqrt(dS*dS + dz*dz );
+  Float_t d = CAMath::Sqrt(dS*dS + dz*dz );
 
   if (oldX > GetX() ) d = -d;
   {
@@ -475,7 +460,7 @@ Bool_t  AliHLTTPCCATrackParam::TransportToXWithMaterial( Float_t x, AliHLTTPCCAT
 
 
 
-Float_t AliHLTTPCCATrackParam::ApproximateBetheBloch( Float_t beta2 ) 
+GPUd() Float_t AliHLTTPCCATrackParam::ApproximateBetheBloch( Float_t beta2 ) 
 {
   //------------------------------------------------------------------
   // This is an approximation of the Bethe-Bloch formula with 
@@ -490,7 +475,7 @@ Float_t AliHLTTPCCATrackParam::ApproximateBetheBloch( Float_t beta2 )
 }
 
 
-void AliHLTTPCCATrackParam::CalculateFitParameters( AliHLTTPCCATrackFitParam &par, Float_t Bz, Float_t mass )
+GPUd() void AliHLTTPCCATrackParam::CalculateFitParameters( AliHLTTPCCATrackFitParam &par, Float_t Bz, Float_t mass )
 {
   //*!
 
@@ -499,11 +484,11 @@ void AliHLTTPCCATrackParam::CalculateFitParameters( AliHLTTPCCATrackFitParam &pa
   Float_t p2 = (1.+ fP[3]*fP[3])*c*c;  
   Float_t k2 = fP[4]*fP[4];
   Float_t beta2= p2 / (p2 + mass*mass*k2);
-  Float_t Bethe = ApproximateBetheBloch(beta2);
+  Float_t bethe = ApproximateBetheBloch(beta2);
 
-  Float_t P2 = (k2>1.e-8) ?p2/k2 :10000; // impuls 2
-  par.fBethe = Bethe;
-  par.fE = TMath::Sqrt( P2 + mass*mass);
+  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;
 
@@ -520,7 +505,7 @@ void AliHLTTPCCATrackParam::CalculateFitParameters( AliHLTTPCCATrackFitParam &pa
 }
 
 
-Bool_t AliHLTTPCCATrackParam::CorrectForMeanMaterial( Float_t xOverX0,  Float_t xTimesRho, AliHLTTPCCATrackFitParam &par )
+GPUd() Bool_t AliHLTTPCCATrackParam::CorrectForMeanMaterial( Float_t xOverX0,  Float_t xTimesRho, AliHLTTPCCATrackFitParam &par )
 {
   //------------------------------------------------------------------
   // This function corrects the track parameters for the crossed material.
@@ -539,7 +524,7 @@ Bool_t AliHLTTPCCATrackParam::CorrectForMeanMaterial( Float_t xOverX0,  Float_t
   //Energy losses************************
   
   Float_t dE = par.fBethe*xTimesRho;
-  if ( TMath::Abs(dE) > 0.3*par.fE ) return 0; //30% energy loss is too much!
+  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;
   fP[4]*= corr;
@@ -548,12 +533,12 @@ Bool_t AliHLTTPCCATrackParam::CorrectForMeanMaterial( Float_t xOverX0,  Float_t
   fC42*= corr;
   fC43*= corr;
   fC44*= corr*corr;
-  fC44+= par.fSigmadE2*TMath::Abs(dE);
+  fC44+= par.fSigmadE2*CAMath::Abs(dE);
   
 
   //Multiple scattering******************
   
-  Float_t theta2 = par.fTheta2*TMath::Abs(xOverX0);
+  Float_t theta2 = par.fTheta2*CAMath::Abs(xOverX0);
   fC22 += theta2*par.fK22*(1.- fP[2]*fP[2]);
   fC33 += theta2*par.fK33;
   fC43 += theta2*par.fK43;
@@ -564,19 +549,17 @@ Bool_t AliHLTTPCCATrackParam::CorrectForMeanMaterial( Float_t xOverX0,  Float_t
 
 
 
-#include "Riostream.h"
-
-Bool_t AliHLTTPCCATrackParam::Rotate( Float_t alpha )
+GPUd() Bool_t AliHLTTPCCATrackParam::Rotate( Float_t alpha )
 {
   //* Rotate the coordinate system in XY on the angle alpha
   
-  Float_t cA = TMath::Cos( alpha );
-  Float_t sA = TMath::Sin( alpha );
+  Float_t cA = CAMath::Cos( alpha );
+  Float_t sA = CAMath::Sin( alpha );
   Float_t x = X(), y= Y(), sP= SinPhi(), cP= CosPhi();
   Float_t cosPhi = cP*cA + sP*sA;
   Float_t sinPhi =-cP*sA + sP*cA;
   
-  if( TMath::Abs(sinPhi)>.99 || TMath::Abs(cosPhi)<1.e-2 || TMath::Abs(cP)<1.e-2  ) return 0;
+  if( CAMath::Abs(sinPhi)>.99 || CAMath::Abs(cosPhi)<1.e-2 || CAMath::Abs(cP)<1.e-2  ) return 0;
   
   Float_t j0 = cP/cosPhi; 
   Float_t j2 = cosPhi/cP;
@@ -610,7 +593,7 @@ Bool_t AliHLTTPCCATrackParam::Rotate( Float_t alpha )
 }
 
 
-Bool_t AliHLTTPCCATrackParam::Filter2( Float_t y, Float_t z, Float_t err2Y, Float_t err2Z )
+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 
 
@@ -649,7 +632,7 @@ Bool_t AliHLTTPCCATrackParam::Filter2( Float_t y, Float_t z, Float_t err2Y, Floa
   k40 = c40*mSi[0] + c41*mSi[1]; k41 = c40*mSi[1] + c41*mSi[2] ;
 
   Float_t sinPhi = fP[2] + k20*z0  + k21*z1  ;
-  if( TMath::Abs(sinPhi)>=0.99 ) return 0;
+  if( CAMath::Abs(sinPhi)>= maxSinPhi ) return 0;
 
   fNDF  += 2;
   fChi2 += ( +(mSi[0]*z0 + mSi[1]*z1 )*z0
@@ -683,14 +666,95 @@ Bool_t AliHLTTPCCATrackParam::Filter2( Float_t y, Float_t z, Float_t err2Y, Floa
   fC[14]-= k40*c40 + k41*c41 ;
     
   if( CosPhi()>=0 ){
-    CosPhi() = TMath::Sqrt(1-SinPhi()*SinPhi());
+    CosPhi() = CAMath::Sqrt(1-SinPhi()*SinPhi());
   }else{
-    CosPhi() = -TMath::Sqrt(1-SinPhi()*SinPhi());
+    CosPhi() = -CAMath::Sqrt(1-SinPhi()*SinPhi());
   }   
   return 1;
 }
 
-void AliHLTTPCCATrackParam::FilterY( Float_t y, Float_t erry )
+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( CosPhi()>=0 ){
+    CosPhi() = CAMath::Sqrt(1-sinPhi*sinPhi);
+  }else{
+    CosPhi() = -CAMath::Sqrt(1-sinPhi*sinPhi);
+  }   
+  return 1;
+}
+
+
+
+
+GPUd() void AliHLTTPCCATrackParam::FilterY( Float_t y, Float_t erry )
 {
   //* Add the y measurement with the Kalman filter 
 
@@ -705,7 +769,7 @@ void AliHLTTPCCATrackParam::FilterY( Float_t y, Float_t erry )
     z0 = y-fP[0];
 
   Float_t s = { c00+erry*erry };
-  if( TMath::Abs(s)<1.e-4 ) return;
+  if( CAMath::Abs(s)<1.e-4 ) return;
 
   Float_t si = 1/s;
 
@@ -723,7 +787,7 @@ void AliHLTTPCCATrackParam::FilterY( Float_t y, Float_t erry )
   k4 = c40*si;
 
   Float_t sinPhi = fP[2] + k2*z0 ;
-  if( TMath::Abs(sinPhi)>=0.99 ) return;
+  if( CAMath::Abs(sinPhi)>=0.99 ) return;
 
   fP[ 0]+= k0*z0 ;
   fP[ 1]+= k1*z0 ;
@@ -752,14 +816,14 @@ void AliHLTTPCCATrackParam::FilterY( Float_t y, Float_t erry )
   fC[14]-= k4*c40;
     
   if( CosPhi()>=0 ){
-    CosPhi() = TMath::Sqrt(1-SinPhi()*SinPhi());
+    CosPhi() = CAMath::Sqrt(1-SinPhi()*SinPhi());
   }else{
-    CosPhi() = -TMath::Sqrt(1-SinPhi()*SinPhi());
+    CosPhi() = -CAMath::Sqrt(1-SinPhi()*SinPhi());
   }   
     
 }
 
-void AliHLTTPCCATrackParam::FilterZ( Float_t z, Float_t errz )
+GPUd() void AliHLTTPCCATrackParam::FilterZ( Float_t z, Float_t errz )
 {
   //* Add the z measurement with the Kalman filter 
 
@@ -774,7 +838,7 @@ void AliHLTTPCCATrackParam::FilterZ( Float_t z, Float_t errz )
     z1 = z-fP[1];
 
   Float_t s = c11 + errz*errz;
-  if( TMath::Abs(s)<1.e-4 ) return;
+  if( CAMath::Abs(s)<1.e-4 ) return;
 
   Float_t si = 1./s;
  
@@ -792,7 +856,7 @@ void AliHLTTPCCATrackParam::FilterZ( Float_t z, Float_t errz )
   k4 = 0;//c41*si;
 
   Float_t sinPhi = fP[2] + k2*z1  ;
-  if( TMath::Abs(sinPhi)>=0.99 ) return;
+  if( CAMath::Abs(sinPhi)>=0.99 ) return;
 
   fP[ 0]+= k0*z1 ;
   fP[ 1]+= k1*z1 ;
@@ -822,15 +886,27 @@ void AliHLTTPCCATrackParam::FilterZ( Float_t z, Float_t errz )
   fC[14]-= k4*c41 ;
     
   if( CosPhi()>=0 ){
-    CosPhi() = TMath::Sqrt(1-SinPhi()*SinPhi());
+    CosPhi() = CAMath::Sqrt(1-SinPhi()*SinPhi());
   }else{
-    CosPhi() = -TMath::Sqrt(1-SinPhi()*SinPhi());
+    CosPhi() = -CAMath::Sqrt(1-SinPhi()*SinPhi());
   }   
     
 }
 
-void AliHLTTPCCATrackParam::Print() const
+#if !defined(HLTCA_GPUCODE)
+#if defined( HLTCA_STANDALONE )
+#include <iostream.h>
+#else
+#include "Riostream.h"
+#endif
+#endif
+
+GPUd() void AliHLTTPCCATrackParam::Print() const
 {
+  //* print parameters
+#if !defined(HLTCA_GPUCODE)
   cout<<"track: "<<GetX()<<" "<<GetY()<<" "<<GetZ()<<" "<<GetSinPhi()<<" "<<GetDzDs()<<" "<<GetKappa()<<endl;
   cout<<"errs2: "<<GetErr2Y()<<" "<<GetErr2Z()<<" "<<GetErr2SinPhi()<<" "<<GetErr2DzDs()<<" "<<GetErr2Kappa()<<endl;
+#endif
 }
index 8222427da940f0724a83332c6c70cd698cbea5bf..8f4ddf6c3de3de960df20513c9822cc3e750dbeb 100644 (file)
@@ -9,13 +9,8 @@
 #ifndef ALIHLTTPCCATRACKPARAM_H
 #define ALIHLTTPCCATRACKPARAM_H
 
-#include "Rtypes.h"
+#include "AliHLTTPCCADef.h"
 
-class AliHLTTPCCATrackFitParam
-{
-public:
-  Float_t fBethe, fE,fTheta2, fEP2, fSigmadE2, fK22,fK33,fK43,fK44;
-};
 
 /**
  * @class AliHLTTPCCATrackParam
@@ -28,18 +23,27 @@ class AliHLTTPCCATrackParam
 {
  public:
 
+  class AliHLTTPCCATrackFitParam
+  {
+  public:
+    Float_t 
+    fBethe, fE,fTheta2, fEP2, fSigmadE2, fK22,fK33,fK43,fK44;// parameters
+  };
+
+#if !defined(HLTCA_GPUCODE)
   AliHLTTPCCATrackParam(): fX(0),fCosPhi(1),fChi2(0), fNDF(0){}
-  //virtual ~AliHLTTPCCATrackParam(){}
-
-  Float_t &X()     { return fX;    }
-  Float_t &Y()     { return fP[0]; }
-  Float_t &Z()     { return fP[1]; }
-  Float_t &SinPhi(){ return fP[2]; }
-  Float_t &DzDs()  { return fP[3]; }
-  Float_t &Kappa() { return fP[4]; }
-  Float_t &CosPhi(){ return fCosPhi; }
-  Float_t &Chi2()  { return fChi2; }
-  Int_t   &NDF()   { return fNDF; }
+  ~AliHLTTPCCATrackParam(){}
+#endif
+
+  GPUd() Float_t &X()     { return fX;    }
+  GPUd() Float_t &Y()     { return fP[0]; }
+  GPUd() Float_t &Z()     { return fP[1]; }
+  GPUd() Float_t &SinPhi(){ return fP[2]; }
+  GPUd() Float_t &DzDs()  { return fP[3]; }
+  GPUd() Float_t &Kappa() { return fP[4]; }
+  GPUd() Float_t &CosPhi(){ return fCosPhi; }
+  GPUd() Float_t &Chi2()  { return fChi2; }
+  GPUd() Int_t   &NDF()   { return fNDF; }
 
   Float_t &Err2Y()      { return fC[0]; }
   Float_t &Err2Z()      { return fC[2]; }
@@ -47,53 +51,54 @@ class AliHLTTPCCATrackParam
   Float_t &Err2DzDs()   { return fC[9]; }
   Float_t &Err2Kappa()  { return fC[14]; }
 
-  Float_t GetX()      const { return fX; }
-  Float_t GetY()      const { return fP[0]; }
-  Float_t GetZ()      const { return fP[1]; }
-  Float_t GetSinPhi() const { return fP[2]; }
-  Float_t GetDzDs()   const { return fP[3]; }
-  Float_t GetKappa()  const { return fP[4]; }
-  Float_t GetCosPhi() const { return fCosPhi; }
-  Float_t GetChi2()   const { return fChi2; }
-  Int_t   GetNDF()    const { return fNDF; }
-
-  Float_t GetErr2Y()      const { return fC[0]; }
-  Float_t GetErr2Z()      const { return fC[2]; }
-  Float_t GetErr2SinPhi() const { return fC[5]; }
-  Float_t GetErr2DzDs()   const { return fC[9]; }
-  Float_t GetErr2Kappa()  const { return fC[14]; }
-
-  Float_t *Par(){ return fP; }
-  Float_t *Cov(){ return fC; }
+  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 GetChi2()   const { return fChi2; }
+  GPUd() Int_t   GetNDF()    const { return fNDF; }
+
+  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]; }
+
+  GPUhd() Float_t *Par(){ return fP; }
+  GPUhd() Float_t *Cov(){ return fC; }
 
   const Float_t *GetPar() const { return fP; }
   const Float_t *GetCov() const { return fC; }
 
-  void ConstructXY3( const Float_t x[3], const Float_t y[3], const Float_t sigmaY2[3], Float_t CosPhi0 );
+  GPUd() void ConstructXY3( const Float_t x[3], const Float_t y[3], const Float_t sigmaY2[3], Float_t CosPhi0 );
 
-  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() void ConstructXYZ3( const Float_t p0[5], const Float_t p1[5], const Float_t p2[5], 
+                             Float_t CosPhi0, Float_t t0[]=0 );
 
-  Float_t GetS( Float_t x, Float_t y ) const;
+  GPUd() Float_t GetS( Float_t x, Float_t y ) const;
 
-  void GetDCAPoint( Float_t x, Float_t y, Float_t z,
-                   Float_t &px, Float_t &py, Float_t &pz ) const;
+  GPUd() void GetDCAPoint( Float_t x, Float_t y, Float_t z,
+                          Float_t &px, Float_t &py, Float_t &pz ) const;
   
-  Bool_t TransportToX( Float_t X );
-  Bool_t TransportToXWithMaterial( Float_t X, AliHLTTPCCATrackFitParam &par );
-  Bool_t TransportToXWithMaterial( Float_t X, Float_t Bz );
-  Bool_t Rotate( Float_t alpha );
+  GPUd() Int_t TransportToX( Float_t X, Float_t maxSinPhi );
+  GPUd() Bool_t TransportToXWithMaterial( Float_t X, AliHLTTPCCATrackFitParam &par );
+  GPUd() Bool_t TransportToXWithMaterial( Float_t X, Float_t Bz );
+  GPUd() Bool_t Rotate( Float_t alpha );
 
-  Bool_t Filter2( Float_t y, Float_t z, Float_t err2Y, Float_t err2Z );
-  void FilterY( Float_t y, Float_t erry );
-  void FilterZ( Float_t z, Float_t errz );
+  GPUd() Bool_t Filter2( Float_t y, Float_t z, Float_t err2Y, Float_t err2Z, Float_t maxSinPhi=.99 );
+  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 );
 
-  static Float_t ApproximateBetheBloch( Float_t beta2 );
-  void CalculateFitParameters( AliHLTTPCCATrackFitParam &par, Float_t Bz, Float_t mass = 0.13957 );
-  Bool_t CorrectForMeanMaterial( Float_t xOverX0,  Float_t xTimesRho, AliHLTTPCCATrackFitParam &par );
-  void Print() const;
+  GPUd() GPUd() static Float_t ApproximateBetheBloch( Float_t beta2 );
+  GPUd() void CalculateFitParameters( AliHLTTPCCATrackFitParam &par, Float_t Bz, Float_t mass = 0.13957 );
+  GPUd() GPUd() Bool_t CorrectForMeanMaterial( Float_t xOverX0,  Float_t xTimesRho, AliHLTTPCCATrackFitParam &par );
+  GPUd() void Print() const;
 
- private:
+private:
 
   Float_t fX;      // x position
   Float_t fCosPhi; // cosPhi
@@ -102,8 +107,6 @@ class AliHLTTPCCATrackParam
   Float_t fChi2;   // the chi^2 value
   Int_t   fNDF;    // the Number of Degrees of Freedom
 
-  //ClassDef(AliHLTTPCCATrackParam, 0);
-
 };
 
 
diff --git a/HLT/TPCLib/tracking-ca/AliHLTTPCCATrackParam1.cxx b/HLT/TPCLib/tracking-ca/AliHLTTPCCATrackParam1.cxx
new file mode 100644 (file)
index 0000000..d334a1c
--- /dev/null
@@ -0,0 +1,949 @@
+// $Id: AliHLTTPCCATrackParam1.cxx 27042 2008-07-02 12:06:02Z richterm $
+//***************************************************************************
+// This file is property of and copyright by the ALICE HLT Project          * 
+// ALICE Experiment at CERN, All rights reserved.                           *
+//                                                                          *
+// Primary Authors: Sergey Gorbunov <sergey.gorbunov@kip.uni-heidelberg.de> *
+//                  Ivan Kisel <kisel@kip.uni-heidelberg.de>                *
+//                  for The ALICE HLT Project.                              *
+//                                                                          *
+// Permission to use, copy, modify and distribute this software and its     *
+// documentation strictly for non-commercial purposes is hereby granted     *
+// without fee, provided that the above copyright notice appears in all     *
+// copies and that both the copyright notice and this permission notice     *
+// appear in the supporting documentation. The authors make no claims       *
+// about the suitability of this software for any purpose. It is            *
+// provided "as is" without express or implied warranty.                    *
+//***************************************************************************
+
+#include "AliHLTTPCCATrackParam1.h"
+#include "AliHLTTPCCAMath.h"
+
+
+//
+// Circle in XY:
+// 
+// R  = 1/TMath::Abs(Kappa);
+// Xc = X - sin(Phi)/Kappa;
+// Yc = Y + cos(Phi)/Kappa;
+//
+
+
+
+GPUd() void AliHLTTPCCATrackParam1::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];
+  }
+  
+  X() = x0;  
+  Y() = y0;
+  SinPhi() = sinPhi;
+  Kappa() = kappa;
+  CosPhi() = 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  AliHLTTPCCATrackParam1::GetS( Float_t x, Float_t y ) const
+{
+  //* Get XY path length to the given point
+
+  Float_t k  = GetKappa();
+  Float_t ex = GetCosPhi();
+  Float_t ey = GetSinPhi();
+  x-= GetX();
+  y-= GetY();
+  Float_t dS = x*ex + y*ey;
+  if( CAMath::Abs(k)>1.e-4 ) dS = CAMath::ATan2( k*dS, 1+k*(x*ey-y*ex) )/k;
+  return dS;
+}
+
+GPUd() void  AliHLTTPCCATrackParam1::GetDCAPoint( Float_t x, Float_t y, Float_t z,
+                                          Float_t &xp, Float_t &yp, Float_t &zp ) 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 ex = GetCosPhi();
+  Float_t ey = GetSinPhi();
+  Float_t dx = x - x0;
+  Float_t dy = y - y0; 
+  Float_t ax = dx*k+ey;
+  Float_t ay = dy*k-ex;
+  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);
+  zp = GetZ() + GetDzDs()*s;
+  if( CAMath::Abs(k)>1.e-2 ){
+    Float_t dZ = CAMath::Abs( GetDzDs()*CAMath::TwoPi()/k );
+    if( dZ>.1 ){
+      zp+= CAMath::Nint((z-zp)/dZ)*dZ;    
+    }
+  }
+}
+
+GPUd() void AliHLTTPCCATrackParam1::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;
+  Z() = (z*ss-sz*s)/a; // z0
+  DzDs() = (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 };
+
+  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  AliHLTTPCCATrackParam1::TransportToX( Float_t x, Float_t maxSinPhi )
+{
+  //* Transport the track parameters to X=x 
+
+  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)>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;
+  
+  CosPhi() = ex1;
+  X() += 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;
+
+ //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 };
+
+  Float_t c00 = fC[0];
+  Float_t c11 = fC[2];
+  Float_t c20 = fC[3];
+  Float_t c22 = fC[5];
+  Float_t c31 = fC[7];
+  Float_t c33 = fC[9];
+  Float_t c40 = fC[10];
+  Float_t c42 = fC[12];
+  Float_t c44 = fC[14];
+
+  float dSc33 = dS*c33;
+  float h2c22 = h2*c22;
+  float h4c42 = h4*c42;
+  float h4c44 = h4*c44;
+  float h2c42 = h2*c42;
+
+  Float_t fC10 = c40 + h2c42 + h4c44;
+  Float_t fC12 = c42 + dx*c44;
+  Float_t fC7 = c31 + dSc33;
+  fC[0]= c00  + h2*h2c22 + h4*h4c44 + 2*( h2*c20 + h4*c40 + h2*h4c42 ) ; 
+  fC[3]= c20 + h2c22 + h4c42 + dx*fC10;
+  fC[10]= fC10;
+  fC[12]= fC12;
+  fC[5]= c22 + dx*( c42 + fC12 );
+
+  fC[7]= fC7;
+  fC[2]= c11 + dS*(c31 + fC7);
+
+  return 1;
+}
+
+GPUd() Int_t  AliHLTTPCCATrackParam1::TransportToX0( Float_t x, Float_t /**/ )
+{
+  //* Transport the track parameters to X=x 
+
+  Float_t ex = fCosPhi;
+  if( CAMath::Abs(ex)<1.e-4 ) return 0;
+
+  Float_t ey = fP[2];
+  Float_t dx = x - fX;  
+  Float_t exi = 1./ex;
+  Float_t dS = dx*exi;
+  Float_t dy = dS*ey;
+  Float_t dz = dS*fP[3];
+  Float_t h2 = dS*exi*exi;
+  Float_t h4 = 0.5*dx*h2;
+  
+  fX = x;
+  fP[0]+= dy + h4*fP[4];
+  fP[1]+= dz;
+  fP[2]+= dx*fP[4];
+
+  //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 };
+
+
+  Float_t c00 = fC[0];
+  Float_t c11 = fC[2];
+  Float_t c20 = fC[3];
+  Float_t c22 = fC[5];
+  Float_t c31 = fC[7];
+  Float_t c33 = fC[9];
+  Float_t c40 = fC[10];
+  Float_t c42 = fC[12];
+  Float_t c44 = fC[14];
+
+  Float_t c40ph4c44 = c40 + h4*c44;
+  Float_t c20ph4c42 = c20 +  h4*c42;
+  Float_t c20ph2c22ph4c42 = h2*c22 + c20ph4c42;
+  Float_t fC10 = c40ph4c44 + h2*c42;
+  Float_t fC12 = c42 + dx*c44;
+  Float_t fC7 = c31 + dS*c33;
+
+  fC[10]= fC10;
+  fC[12]= fC12;
+  fC[7]= fC7;
+  fC[0]= c00  + h2*( c20ph2c22ph4c42 + c20ph4c42) + h4*(c40ph4c44 + c40 ) ; 
+  fC[3]= c20ph2c22ph4c42 + dx*fC10;
+  fC[5]= c22 + dx*( c42 + fC12 );
+  fC[2]= c11 + dS*(c31 + fC7);
+
+  return 1;
+}
+
+/*
+GPUd() Int_t  AliHLTTPCCATrackParam1::TransportToX0( Float_t x, Float_t maxSinPhi )
+{
+// Transport the track parameters to X=x 
+
+  Float_t x0  = X();
+  Float_t ex = CosPhi();
+  Float_t ey = SinPhi();
+  Float_t dx = x - x0;
+
+  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(); 
+  
+  CosPhi() = ex;
+  X() += dx;
+  fP[0]+= dy;
+  fP[1]+= dz;
+  fP[2] = ey;
+  fP[3] = fP[3];
+  fP[4] = fP[4];
+
+  Float_t h2 = dx*exi*exi*exi;
+  Float_t h4 = dx*h2/2;
+
+ //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 };
+
+  Float_t c00 = fC[0];
+  Float_t c11 = fC[2];
+  Float_t c20 = fC[3];
+  Float_t c22 = fC[5];
+  Float_t c31 = fC[7];
+  Float_t c33 = fC[9];
+  Float_t c40 = fC[10];
+  Float_t c42 = fC[12];
+  Float_t c44 = fC[14];
+
+  float dSc33 = dS*c33;
+  float h2c22 = h2*c22;
+  float h4c42 = h4*c42;
+  float h4c44 = h4*c44;
+  float h2c42 = h2*c42;
+
+  Float_t fC10 = c40 + h2c42 + h4c44;
+  Float_t fC12 = c42 + dx*c44;
+  Float_t fC7 = c31 + dSc33;
+  fC[0]= c00  + h2*h2c22 + h4*h4c44 + 2*( h2*c20 + h4*c40 + h2*h4c42 ) ; 
+  fC[3]= c20 + h2c22 + h4c42 + dx*fC10;
+  fC[10]= fC10;
+  fC[12]= fC12;
+  fC[5]= c22 + dx*( c42 + fC12 );
+
+  fC[7]= fC7;
+  fC[2]= c11 + dS*(c31 + fC7);
+
+  return 1;
+}
+*/
+
+GPUd() Int_t  AliHLTTPCCATrackParam1::TransportToXMatrix( Float_t x, 
+                                                          Float_t &OutY, Float_t &OutZ,
+                                                          Float_t &OutErr2Y, Float_t &OutErr2Z,
+                                                          Float_t &H2, Float_t &H4, 
+                                                          Float_t &dS, Float_t &dx,
+                                                          Float_t maxSinPhi ) 
+{
+  //* Transport the track parameters to X=x 
+
+  Float_t x0  = X();
+  //Float_t y0  = Y();
+  Float_t k   = Kappa();
+  Float_t ex = CosPhi();
+  Float_t ey = SinPhi();
+  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;  
+  }
+  
+  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;
+
+  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;
+  
+  Float_t h2 = dx*(1+ ex*ex1 + ey*ey1 )*cci*exi*ex1i;
+  Float_t h4 = dx2*(cc + ss*ey1*ex1i )*cci*cci;
+
+ //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 };
+
+  Float_t c20 = fC[3];
+  Float_t c22 = fC[5];
+  Float_t c31 = fC[7];
+  Float_t c33 = fC[9];
+  Float_t c40 = fC[10];
+  Float_t c42 = fC[12];
+  Float_t c44 = fC[14];
+
+  float dSc33 = dS*c33;
+  float h2c22 = h2*c22;
+  float h4c42 = h4*c42;
+  float h4c44 = h4*c44;  
+
+  OutY = fP[0] + dy;
+  OutZ = fP[1] + dz;
+  OutErr2Y =  fC[0]  + h2*h2c22 + h4*h4c44 + 2*( h2*c20 + h4*c40 + h2*h4c42 ) ; 
+  OutErr2Z = fC[2] + dS*(c31 + c31 + dSc33);
+
+  H2 = h2;
+  H4 = h4;
+
+  return 1;
+}
+
+
+GPUd() Bool_t AliHLTTPCCATrackParam1::TransportToXWithMaterial( Float_t Xto, Float_t Bz )
+{
+  //* Transport the track parameters to X=x 
+  AliHLTTPCCATrackFitParam par;
+  CalculateFitParameters( par, Bz );
+  return TransportToXWithMaterial(Xto, par );
+}
+
+
+GPUd() Bool_t  AliHLTTPCCATrackParam1::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;
+  CosPhi() = 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;
+
+  X() += 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;
+
+  Float_t c00 = fC[0];
+  Float_t c11 = fC[2];
+  Float_t c20 = fC[3];
+  Float_t c22 = fC[5];
+  Float_t c31 = fC[7];
+  Float_t c33 = fC[9];
+  Float_t c40 = fC[10];
+  Float_t c42 = fC[12];
+  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 )  ); 
+
+  fC[2]= c11 + 2*dS*c31 + dS*dS*c33;
+
+  fC[3]= c20 + h2*c22 + h4*c42 + dx*( c40 + h2*c42 + h4*c44);
+  fC[5]= c22 +2*dx*c42 + dx2*c44;
+
+  fC[7]= c31 + dS*c33;
+  fC[9]= c33;
+
+  fC[10]= c40 + h2*c42 + h4*c44;
+  fC[12]= c42 + dx*c44;
+  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;
+}
+
+
+
+GPUd() Float_t AliHLTTPCCATrackParam1::ApproximateBetheBloch( Float_t beta2 ) 
+{
+  //------------------------------------------------------------------
+  // This is an approximation of the Bethe-Bloch formula with 
+  // the density effect taken into account at beta*gamma > 3.5
+  // (the approximation is reasonable only for solid materials) 
+  //------------------------------------------------------------------
+  if (beta2 >= 1) return 0;
+
+  if (beta2/(1-beta2)>3.5*3.5)
+    return 0.153e-3/beta2*( log(3.5*5940)+0.5*log(beta2/(1-beta2)) - beta2);
+  return 0.153e-3/beta2*(log(5940*beta2/(1-beta2)) - beta2);
+}
+
+
+GPUd() void AliHLTTPCCATrackParam1::CalculateFitParameters( AliHLTTPCCATrackFitParam &par, Float_t Bz, 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 k2 = fP[4]*fP[4];
+  Float_t beta2= p2 / (p2 + mass*mass*k2);
+  Float_t bethe = ApproximateBetheBloch(beta2);
+
+  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;
+
+  // Approximate energy loss fluctuation (M.Ivanov)
+  
+  const Float_t knst=0.07; // To be tuned.  
+  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];
+}
+
+
+GPUd() Bool_t AliHLTTPCCATrackParam1::CorrectForMeanMaterial( Float_t xOverX0,  Float_t xTimesRho, AliHLTTPCCATrackFitParam &par )
+{
+  //------------------------------------------------------------------
+  // This function corrects the track parameters for the crossed material.
+  // "xOverX0"   - X/X0, the thickness in units of the radiation length.
+  // "xTimesRho" - is the product length*density (g/cm^2). 
+  //------------------------------------------------------------------
+
+  Float_t &fC22=fC[5];
+  Float_t &fC33=fC[9];
+  Float_t &fC40=fC[10];
+  Float_t &fC42=fC[12];
+  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;
+  fP[4]*= corr;
+  fC40*= corr;  
+  fC42*= corr;  
+  fC44*= corr*corr;
+  fC44+= par.fSigmadE2*CAMath::Abs(dE);
+  
+
+  //Multiple scattering******************
+  
+  Float_t theta2 = par.fTheta2*CAMath::Abs(xOverX0);
+  fC22 += theta2*par.fK22*(1.- fP[2]*fP[2]);
+  fC33 += theta2*par.fK33;
+  fC44 += theta2*par.fK44;
+    
+  return 1;
+}
+
+
+
+//#include "Riostream.h"
+
+GPUd() Bool_t AliHLTTPCCATrackParam1::Rotate( Float_t alpha )
+{
+  //* Rotate the coordinate system in XY on the angle alpha
+  
+  Float_t cA = CAMath::Cos( alpha );
+  Float_t sA = CAMath::Sin( alpha );
+  Float_t x = X(), y= Y(), sP= SinPhi(), cP= CosPhi();
+  Float_t cosPhi = cP*cA + sP*sA;
+  Float_t sinPhi =-cP*sA + sP*cA;
+  
+  if( CAMath::Abs(sinPhi)>.99 || CAMath::Abs(cosPhi)<1.e-2 || CAMath::Abs(cP)<1.e-2  ) return 0;
+  
+  Float_t j0 = cP/cosPhi; 
+  Float_t j2 = cosPhi/cP;
+  
+  X()      =   x*cA +  y*sA;
+  Y()      =  -x*sA +  y*cA;
+  CosPhi() =  cosPhi;
+  SinPhi() =  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
+  //cout<<"alpha="<<alpha<<" "<<x<<" "<<y<<" "<<sP<<" "<<cP<<" "<<j0<<" "<<j2<<endl;
+  //cout<<"      "<<fC[0]<<" "<<fC[1]<<" "<<fC[6]<<" "<<fC[10]<<" "<<fC[4]<<" "<<fC[5]<<" "<<fC[8]<<" "<<fC[12]<<endl;
+  fC[0]*= j0*j0;
+  //fC[3]*= j0;
+  fC[10]*= j0;
+
+  //fC[3]*= j2;
+  fC[5]*= j2*j2; 
+  fC[8]*= j2;
+  fC[12]*= j2;
+  //cout<<"      "<<fC[0]<<" "<<fC[1]<<" "<<fC[6]<<" "<<fC[10]<<" "<<fC[4]<<" "<<fC[5]<<" "<<fC[8]<<" "<<fC[12]<<endl;
+  return 1;
+}
+
+
+GPUd() Bool_t AliHLTTPCCATrackParam1::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],
+    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( 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() void AliHLTTPCCATrackParam1::FilterY( Float_t y, Float_t erry )
+{
+  //* Add the y measurement with the Kalman filter 
+
+  Float_t 
+    c00 = fC[ 0],    
+    c20 = fC[ 3],
+    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, k2, k3, k4;
+    
+  k0 = c00*si;
+  k2 = c20*si;
+  k3 = 0;
+  k4 = c40*si;
+
+  Float_t sinPhi = fP[2] + k2*z0 ;
+  if( CAMath::Abs(sinPhi)>=0.99 ) return;
+
+  fP[ 0]+= k0*z0 ;
+  fP[ 2] = sinPhi;
+  fP[ 3]+= k3*z0 ;
+  fP[ 4]+= k4*z0 ;
+    
+  fC[ 0]-= k0*c00;
+  
+  fC[ 3]-= k2*c00;
+  fC[ 5]-= k2*c20;
+
+  fC[10]-= k4*c00;
+  fC[12]-= k4*c20;
+  fC[14]-= k4*c40;
+    
+  if( CosPhi()>=0 ){
+    CosPhi() = CAMath::Sqrt(1-SinPhi()*SinPhi());
+  }else{
+    CosPhi() = -CAMath::Sqrt(1-SinPhi()*SinPhi());
+  }   
+    
+}
+
+GPUd() void AliHLTTPCCATrackParam1::FilterZ( Float_t z, Float_t errz )
+{
+  //* Add the z measurement with the Kalman filter 
+
+  Float_t 
+    c11 = fC[ 2],
+    c31 = fC[ 7];
+  
+  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 k1 , k3;
+    
+  k1 = c11*si;
+  k3 = c31*si;
+
+  fP[ 1]+= k1*z1 ;
+  fP[ 3]+= k3*z1 ;    
+  
+  fC[ 2]-= k1*c11 ;
+
+  fC[ 7]-= k3*c11 ;
+  fC[ 9]-= k3*c31 ;
+
+}
+
+#if !defined(HLTCA_GPUCODE)
+#if defined( HLTCA_STANDALONE )
+#include <iostream.h>
+#else
+#include "Riostream.h"
+#endif
+#endif
+
+GPUd() void AliHLTTPCCATrackParam1::Print() const
+{
+  //* Print parameters
+
+#if !defined(HLTCA_GPUCODE)
+  cout<<"track: "<<GetX()<<" "<<GetY()<<" "<<GetZ()<<" "<<GetSinPhi()<<" "<<GetDzDs()<<" "<<GetKappa()<<endl;
+  cout<<"errs2: "<<GetErr2Y()<<" "<<GetErr2Z()<<" "<<GetErr2SinPhi()<<" "<<GetErr2DzDs()<<" "<<GetErr2Kappa()<<endl;
+#endif
+}
+
diff --git a/HLT/TPCLib/tracking-ca/AliHLTTPCCATrackParam1.h b/HLT/TPCLib/tracking-ca/AliHLTTPCCATrackParam1.h
new file mode 100644 (file)
index 0000000..5759830
--- /dev/null
@@ -0,0 +1,117 @@
+//-*- Mode: C++ -*-
+// $Id: AliHLTTPCCATrackParam1.h 27042 2008-07-02 12:06:02Z richterm $
+
+//* 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 ALIHLTTPCCATRACKPARAM1_H
+#define ALIHLTTPCCATRACKPARAM1_H
+
+#include "AliHLTTPCCADef.h"
+
+/**
+ * @class AliHLTTPCCATrackParam1
+ *
+ * AliHLTTPCCATrackParam1 class describes the track parametrisation
+ * which is used by the AliHLTTPCCATracker slice tracker.
+ *
+ */
+class AliHLTTPCCATrackParam1
+{
+ public:
+
+  class AliHLTTPCCATrackFitParam
+  {
+  public:
+    Float_t fBethe, fE,fTheta2, fEP2, fSigmadE2, fK22,fK33,fK43,fK44; // fit parameters
+  };
+#if !defined(HLTCA_GPUCODE)
+  AliHLTTPCCATrackParam1(): fX(0),fCosPhi(1),fChi2(0), fNDF(0){}
+  ~AliHLTTPCCATrackParam1(){}
+#endif
+
+  GPUd() Float_t &X()     { return fX;    }
+  GPUd() Float_t &Y()     { return fP[0]; }
+  GPUd() Float_t &Z()     { return fP[1]; }
+  GPUd() Float_t &SinPhi(){ return fP[2]; }
+  GPUd() Float_t &DzDs()  { return fP[3]; }
+  GPUd() Float_t &Kappa() { return fP[4]; }
+  GPUd() Float_t &CosPhi(){ return fCosPhi; }
+  GPUd() Float_t &Chi2()  { return fChi2; }
+  GPUd() Int_t   &NDF()   { return fNDF; }
+
+  Float_t &Err2Y()      { return fC[0]; }
+  Float_t &Err2Z()      { return fC[2]; }
+  Float_t &Err2SinPhi() { return fC[5]; }
+  Float_t &Err2DzDs()   { return fC[9]; }
+  Float_t &Err2Kappa()  { 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 GetChi2()   const { return fChi2; }
+  GPUd() Int_t   GetNDF()    const { return fNDF; }
+
+  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]; }
+
+  GPUhd() Float_t *Par(){ return fP; }
+  GPUhd() Float_t *Cov(){ return fC; }
+
+  GPUd() const Float_t *GetPar() const { return fP; }
+  GPUd() const Float_t *GetCov() const { return fC; }
+
+  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() void GetDCAPoint( Float_t x, Float_t y, Float_t z,
+                   Float_t &px, Float_t &py, Float_t &pz ) const;
+  
+  GPUd() Int_t TransportToX( Float_t X, Float_t maxSinPhi );
+  GPUd() Int_t TransportToX0( Float_t X, Float_t maxSinPhi );
+  GPUd() Int_t TransportToXMatrix( Float_t X, 
+                                   Float_t &Y, Float_t &Z,
+                                   Float_t &Err2Y, Float_t &Err2Z,
+                                   Float_t &H2, Float_t &H4, 
+                                   Float_t &dS, Float_t &dx, Float_t maxSinPhi ) ;
+  GPUd() Bool_t TransportToXWithMaterial( Float_t X, AliHLTTPCCATrackFitParam &par );
+  GPUd() Bool_t TransportToXWithMaterial( Float_t X, Float_t Bz );
+  GPUd() Bool_t Rotate( Float_t alpha );
+
+  GPUd() Bool_t Filter2( 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() Bool_t CorrectForMeanMaterial( Float_t xOverX0,  Float_t xTimesRho, AliHLTTPCCATrackFitParam &par );
+  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 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 efae697070926ebc6314e1a13d730afaef60bc93..c99595aefad0d5810d92df8d6a3033deb1a28966 100644 (file)
 //***************************************************************************
 
 #include "AliHLTTPCCATracker.h"
-
-#include "AliHLTTPCCAHit.h"
-#include "AliHLTTPCCACell.h"
-#include "AliHLTTPCCAEndPoint.h"
 #include "AliHLTTPCCAOutTrack.h"
 #include "AliHLTTPCCAGrid.h"
 #include "AliHLTTPCCARow.h"
 #include "AliHLTTPCCATrack.h"
+#include "AliHLTTPCCAMath.h"
+#include "AliHLTTPCCAHit.h"
 
-#include "TMath.h"
-#include "Riostream.h"
-//#include <algo.h>
 #include "TStopwatch.h"
+#include "AliHLTTPCCAHitArea.h"
+#include "AliHLTTPCCANeighboursFinder.h"
+#include "AliHLTTPCCANeighboursCleaner.h"
+#include "AliHLTTPCCAStartHitsFinder.h"
+#include "AliHLTTPCCATrackletConstructor.h"
+#include "AliHLTTPCCATrackletSelector.h"
+#include "AliHLTTPCCAProcess.h"
+#include "AliHLTTPCCALinksWriter.h"
+#include "AliHLTTPCCAUsedHitsInitialiser.h"
+
+#include "AliHLTTPCCATrackParam.h"
+#include "AliHLTTPCCATrackParam1.h"
+
+#if !defined(HLTCA_GPUCODE)
+#if defined( HLTCA_STANDALONE )
+#include <iostream.h>
+#else
+#include "Riostream.h"
+#endif
+#endif
 
 //#define DRAW
 
 
 ClassImp(AliHLTTPCCATracker)
 
+#if !defined(HLTCA_GPUCODE)  
 
 AliHLTTPCCATracker::AliHLTTPCCATracker()
-  :fParam(),fRows(0),fOutTrackHits(0),fNOutTrackHits(0),fOutTracks(0),fNOutTracks(0),fNHitsTotal(0),fTracks(0),fNTracks(0),fCellHitPointers(0),fCells(0),fEndPoints(0)
+  :
+  fParam(),
+  fNHitsTotal(0),
+  fGridSizeTotal(0),
+  fGrid1SizeTotal(0),
+  fHits(0),
+  fHits1(0),
+  fGridContents(0),
+  fGrid1Contents(0),
+  fHitsID(0),
+  fHitLinkUp(0),
+  fHitLinkDown(0),
+  fHitIsUsed(0),
+  fStartHits(0),  
+  fTracklets(0),
+  fNTracks(0),
+  fTracks(0),
+  fTrackHits(0),
+  fNOutTracks(0),
+  fNOutTrackHits(0),
+  fOutTracks(0),
+  fOutTrackHits(0),
+  fEventMemory(0),
+  fEventMemSize(0),
+  fTexHitsFullData(0),
+  fTexHitsFullSize(0)
 {
   // constructor
   //fRows = new AliHLTTPCCARow[fParam.NRows()];
@@ -50,7 +91,32 @@ AliHLTTPCCATracker::AliHLTTPCCATracker()
 }
 
 AliHLTTPCCATracker::AliHLTTPCCATracker( const AliHLTTPCCATracker& )
-  :fParam(),fRows(0),fOutTrackHits(0),fNOutTrackHits(0),fOutTracks(0),fNOutTracks(0),fNHitsTotal(0),fTracks(0),fNTracks(0),fCellHitPointers(0),fCells(0),fEndPoints(0)
+  :
+  fParam(),
+  fNHitsTotal(0),
+  fGridSizeTotal(0),
+  fGrid1SizeTotal(0),
+  fHits(0),
+  fHits1(0),
+  fGridContents(0),
+  fGrid1Contents(0),
+  fHitsID(0),
+  fHitLinkUp(0),
+  fHitLinkDown(0),
+  fHitIsUsed(0),
+  fStartHits(0),  
+  fTracklets(0),
+  fNTracks(0),
+  fTracks(0),
+  fTrackHits(0),
+  fNOutTracks(0),
+  fNOutTrackHits(0),
+  fOutTracks(0),
+  fOutTrackHits(0),
+  fEventMemory(0),
+  fEventMemSize(0),
+  fTexHitsFullData(0),
+  fTexHitsFullSize(0)
 {
   // dummy
 }
@@ -58,1092 +124,610 @@ AliHLTTPCCATracker::AliHLTTPCCATracker( const AliHLTTPCCATracker& )
 AliHLTTPCCATracker &AliHLTTPCCATracker::operator=( const AliHLTTPCCATracker& )
 {
   // dummy
-  fRows=0;
   fOutTrackHits=0;
   fOutTracks=0;
   fNOutTracks=0;
+  fTrackHits = 0;
+  fEventMemory = 0;
   return *this;
 }
 
-AliHLTTPCCATracker::~AliHLTTPCCATracker()
+GPUd() AliHLTTPCCATracker::~AliHLTTPCCATracker()
 {
   // destructor
   StartEvent();
-  delete[] fRows;
 }
+#endif
+
+
+GPUd() UChar_t AliHLTTPCCATracker::GetGridContent(  UInt_t i ) const
+{
+  //* get grid content
+#if defined(HLTCA_GPUSTEP)
+  return (UChar_t) tex1Dfetch(texGrid,i).x;  
+#else
+  return fGridContents[i];
+#endif
+}
+
+
+GPUd() AliHLTTPCCAHit AliHLTTPCCATracker::GetHit(  UInt_t i ) const
+{
+  //* get hit
+#if defined(HLTCA_USE_GPU)
+  AliHLTTPCCAHit h;
+  float2 f = tex1Dfetch(texHits,i);
+  h.Y() = f.x;
+  h.Z() = f.y;
+  return h;
+#else
+  return fHits[i];
+#endif
+}
+
+
+
 
 // ----------------------------------------------------------------------------------
-void AliHLTTPCCATracker::Initialize( AliHLTTPCCAParam &param )
+GPUd() void AliHLTTPCCATracker::Initialize( AliHLTTPCCAParam &param )
 {
   // initialisation
   StartEvent();
-  delete[] fRows;
-  fRows = 0;
-  fParam = param;  
-  fParam.Update();
-  fRows = new AliHLTTPCCARow[fParam.NRows()];
-  Float_t xStep = 1;
-  Float_t deltaY = TMath::Tan(fParam.CellConnectionAngleXY());
-  Float_t deltaZ = TMath::Tan(fParam.CellConnectionAngleXZ());
+  fParam = param;
+  fParam.Update(); 
   for( Int_t irow=0; irow<fParam.NRows(); irow++ ){
     fRows[irow].X() = fParam.RowX(irow);        
-    if( irow < fParam.NRows()-1 ) xStep = fParam.RowX(irow+1) - fParam.RowX(irow);
-    fRows[irow].DeltaY() = xStep*deltaY;
-    fRows[irow].DeltaZ() = xStep*deltaZ;
-    fRows[irow].MaxY() = TMath::Tan( fParam.DAlpha()/2.)*fRows[irow].X();
+    fRows[irow].MaxY() = CAMath::Tan( fParam.DAlpha()/2.)*fRows[irow].X();    
   }
   StartEvent();
 }
 
-void AliHLTTPCCATracker::StartEvent()
+GPUd() void AliHLTTPCCATracker::StartEvent()
 {
   // start new event and fresh the memory  
 
-  if( fTracks ) delete[] fTracks;
-  if( fOutTrackHits ) delete[] fOutTrackHits;
+  if( fEventMemory ) delete[] fEventMemory;
   if( fOutTracks ) delete[] fOutTracks;
-  if( fCellHitPointers ) delete[] fCellHitPointers;
-  if( fCells ) delete[] fCells;
-  if( fEndPoints ) delete[] fEndPoints;
+  if( fOutTrackHits ) delete[] fOutTrackHits;
+  fEventMemory = 0;
+  fHits = 0;
+  fHits1 = 0;
+  fHitsID = 0;
+  fTrackHits = 0;
   fTracks = 0;
   fOutTrackHits = 0;
   fOutTracks = 0;
-  fCellHitPointers = 0;
-  fCells = 0;
-  fEndPoints = 0;
   fNTracks = 0;
   fNOutTrackHits = 0;
   fNOutTracks = 0;
   fNHitsTotal = 0;
-  if( fRows ) {
-    for( Int_t irow=0; irow<fParam.NRows(); irow++ )  fRows[irow].Clear();
-  }
 }
 
-
-void AliHLTTPCCATracker::ReadHitRow( Int_t iRow, AliHLTTPCCAHit *Row, Int_t NHits )
+GPUhd() void  AliHLTTPCCATracker::SetPointers()
 {
-  // read row of hits
-  AliHLTTPCCARow &row = fRows[iRow];
-  row.Hits() = new AliHLTTPCCAHit[NHits];
-  for( Int_t i=0; i<NHits; i++ ){ 
-    row.Hits()[i]=Row[i];
-    row.Hits()[i].ErrY()*= fParam.YErrorCorrection();
-    row.Hits()[i].ErrZ()*= fParam.ZErrorCorrection();
-  }
-  row.NHits() = NHits;
-  fNHitsTotal += NHits;
+  // set all pointers to the event memory
+
+  fEventMemSize = 0;
+  UInt_t &size = fEventMemSize;
+  fHits = (AliHLTTPCCAHit*) (fEventMemory+ size);
+  size+= sizeof(AliHLTTPCCAHit)*fNHitsTotal;
+  fHits1 = (ushort2*) (fEventMemory+ size);
+  size+= sizeof(ushort2)*fNHitsTotal;
+  fGridContents = (UChar_t *) (fEventMemory + size);
+  size+= sizeof(Int_t)*fGridSizeTotal;
+  fGrid1Contents = (UInt_t *) (fEventMemory + size);
+  size+= sizeof(UInt_t)*fGrid1SizeTotal;
+  fHitsID = (Int_t *) (fEventMemory + size);
+  size+= sizeof(Int_t) * fNHitsTotal;
+  fHitLinkUp = (Short_t *) (fEventMemory + size);
+  size+= sizeof(Int_t) * fNHitsTotal;
+  fHitLinkDown = (Short_t *) (fEventMemory + size);
+  size+= sizeof(Int_t) * fNHitsTotal;
+  fHitIsUsed = (Int_t *) (fEventMemory + size);
+  size+= sizeof(Int_t) * fNHitsTotal;
+  fStartHits = (Int_t *) (fEventMemory + size);
+  size+= sizeof(Int_t) * (fNHitsTotal+1);
+  size = (size/16+1)*16;
+  fTexHitsFullData = (uint4*)(fEventMemory+ size);
+  size+= ((sizeof(UShort_t)*6*fNHitsTotal + sizeof(UShort_t)*2*fGrid1SizeTotal )/16+1)*16;
+
+  fTracklets = (Int_t *) (fEventMemory + size);
+  size+= sizeof(Int_t) * (1 + fNHitsTotal*(5+ sizeof(AliHLTTPCCATrackParam)/4 + 160 ));
+  fNTracks = (Int_t *) (fEventMemory + size);
+  size+= sizeof(Int_t);
+  fTracks = (AliHLTTPCCATrack* )(fEventMemory + size);
+  size+= sizeof(AliHLTTPCCATrack) * (fNHitsTotal+1);
+  fTrackHits = ( Int_t *)(fEventMemory + size);
+  size+= sizeof(Int_t) * (10*fNHitsTotal+1);
+
+  fOutTrackHits = 0;
+  fOutTracks = 0;
 }
 
-void AliHLTTPCCATracker::Reconstruct()
+GPUd() void AliHLTTPCCATracker::ReadEvent( Int_t *RowFirstHit, Int_t *RowNHits, Float_t *Y, Float_t *Z, Int_t NHits )
 {
-  //* reconstruction of event
+  //* Read event
 
-#ifdef DRAW
-  if( !gApplication ){
-    TApplication *myapp = new TApplication("myapp",0,0);
+  fNHitsTotal = NHits;
+  fGridSizeTotal = 0;
+  fGrid1SizeTotal = 0;
+  fTexHitsFullSize = 0;
+
+  //cout<<"event mem = "<<fEventMemory<<endl;
+  for( Int_t iRow=0; iRow<fParam.NRows(); iRow++ ){
+    //cout<<"row, nhits="<<iRow<<" "<<RowNHits[iRow]<<endl;
+    //cout<<"row, firsthit="<<iRow<<" "<<RowFirstHit[iRow]<<endl;
+    AliHLTTPCCARow &row = fRows[iRow];
+    row.FirstHit() = RowFirstHit[iRow];
+    row.NHits() = RowNHits[iRow];
+    Float_t yMin=1.e3, yMax=-1.e3, zMin=1.e3, zMax=-1.e3;
+    Int_t nGrid =  row.NHits();   
+    for( Int_t i=0; i<row.NHits(); i++ ){       
+      Int_t j = RowFirstHit[iRow]+i;
+      if( yMax < Y[j] ) yMax = Y[j];
+      if( yMin > Y[j] ) yMin = Y[j];
+      if( zMax < Z[j] ) zMax = Z[j];
+      if( zMin > Z[j] ) zMin = Z[j];
+    }
+    if( nGrid == 0 ){
+      yMin = yMax = zMin = zMax = 0;
+      nGrid = 1;
+    }
+
+    row.Grid().Create( yMin, yMax, zMin, zMax, nGrid );
+
+    float sy = ( CAMath::Abs( row.Grid().StepYInv() ) >1.e-4 ) ?1./row.Grid().StepYInv() :1;
+    float sz = ( CAMath::Abs( row.Grid().StepZInv() ) >1.e-4 ) ?1./row.Grid().StepZInv() :1;
+
+    //cout<<"grid n = "<<row.Grid().N()<<" "<<sy<<" "<<sz<<" "<<yMin<<" "<<yMax<<" "<<zMin<<" "<<zMax<<endl;
+    
+    bool recreate=0;
+    if( sy < 2. ) { recreate = 1; sy = 2; }
+    if( sz < 2. ) { recreate = 1; sz = 2; }
+    if( recreate ) row.Grid().Create( yMin, yMax, zMin, zMax, sy, sz );
+
+    fGridSizeTotal+=row.Grid().N()+3+10;    
+    //cout<<"grid n = "<<row.Grid().N()<<endl;
   }
-  //AliHLTTPCCADisplay::Instance().Init();
   
-  AliHLTTPCCADisplay::Instance().SetCurrentSlice( this );
-  AliHLTTPCCADisplay::Instance().SetSliceView();
-  AliHLTTPCCADisplay::Instance().DrawSlice( this );  
-  //for( Int_t iRow=0; iRow<fParam.NRows(); iRow++ )
-  //for (Int_t i = 0; i<fRows[iRow].NHits(); i++) 
-  //AliHLTTPCCADisplay::Instance().DrawHit( iRow, i );
-  //AliHLTTPCCADisplay::Instance().Ask();
-#endif
+  fGrid1SizeTotal = fGridSizeTotal+10;
 
-  fTimers[0] = 0;
-  fTimers[1] = 0;
-  fTimers[2] = 0;
-  fTimers[3] = 0;
-  fTimers[4] = 0;
-  fTimers[5] = 0;
-  fTimers[6] = 0;
-  fTimers[7] = 0;
-  if( fNHitsTotal < 1 ) return;
+  SetPointers();  
 
-  //cout<<"Find Cells..."<<endl;
-  FindCells();
-  //cout<<"Merge Cells..."<<endl;
-  MergeCells();
-  //cout<<"Find Tracks..."<<endl;
-  FindTracks();
-  //cout<<"Find Tracks OK"<<endl;
- }
+  fEventMemory = (char*) ( new uint4 [ fEventMemSize/sizeof(uint4) + 100]);
+  SetPointers();
 
+  fGridSizeTotal = 0;
+  fGrid1SizeTotal = 0;
 
-void AliHLTTPCCATracker::FindCells()
-{
-  //* cell finder - neighbouring hits are grouped to cells
+  for( Int_t iRow=0; iRow<fParam.NRows(); iRow++ ){
+    AliHLTTPCCARow &row = fRows[iRow];
+    AliHLTTPCCAGrid &grid = row.Grid();
 
-  TStopwatch timer;
+    Int_t c[grid.N()+3+10];
+    Int_t bins[row.NHits()];
+    Int_t filled[ row.Grid().N() +3+10 ];
 
-  fCellHitPointers = new Int_t [fNHitsTotal];
-  fCells = new AliHLTTPCCACell[fNHitsTotal]; 
-  fEndPoints = new AliHLTTPCCAEndPoint[fNHitsTotal]; 
-  struct THitCont{
-    Float_t Ymin, Ymax, Zmin, Zmax;
-    Int_t binYmin, binYmax, binZmin, binZmax;
-    Bool_t used;
-    AliHLTTPCCAHit *h;
-    THitCont *next;
-  };
-  THitCont *hitCont = new THitCont[fNHitsTotal];    
-
-  Int_t lastCellHitPointer = 0;
-  Int_t lastCell = 0;
+    for( UInt_t bin=0; bin<row.Grid().N()+3; bin++ ) filled[bin] = 0;  
 
-  for( Int_t irow=0; irow<fParam.NRows(); irow++ ){
-    AliHLTTPCCARow &row=fRows[irow];
-    Int_t nHits = row.NHits();
-    //cout<<"row = "<<irow<<", x="<<row.X()<<endl;
-    if( nHits<1 ) continue;
-    //cout<<nHits*sizeof(AliHLTTPCCAHit)/1024.<<endl;
-
-    Float_t deltaY = row.DeltaY();
-    Float_t deltaZ = row.DeltaZ();
-
-    Float_t yMin = 1.e20, zMin = 1.e20, yMax = -1.e20, zMax = -1.e20;
-    for (Int_t ih = 0; ih<nHits; ih++){    
-      AliHLTTPCCAHit &h  = row.Hits()[ih];    
-      if( yMin> h.Y() ) yMin = h.Y();
-      if( yMax< h.Y() ) yMax = h.Y();
-      if( zMin> h.Z() ) zMin = h.Z();
-      if( zMax< h.Z() ) zMax = h.Z();
+    for( Int_t i=0; i<row.NHits(); i++ ){
+      Int_t j = RowFirstHit[iRow]+i;
+      Int_t bin = row.Grid().GetBin( Y[j], Z[j] );
+      bins[i] = bin;
+      filled[bin]++;
     }
-    AliHLTTPCCAGrid grid;
-    grid.Create( yMin, yMax, zMin, zMax, nHits );
-    //cout<<"row "<<irow<<", delta = "<<delta<<" :\n"<<endl;
-    for (Int_t ih = 0; ih<nHits; ih++){    
-      AliHLTTPCCAHit &h  = row.Hits()[ih];
-      THitCont &cont = hitCont[ih];
-      THitCont *&bin = * ((THitCont **) grid.GetNoCheck(h.Y(),h.Z()));
-      cont.h = &h;
-      cont.used = 0;
-      Float_t y = h.Y();
-      //cout<<"ih = "<<ih<<", y= "<<y<<endl;
-      Float_t dY = 3.5*h.ErrY() + deltaY;
-      cont.Ymin = y-dY;
-      cont.Ymax = y+dY;
-      Float_t z = h.Z();
-      Float_t dZ = 3.5*h.ErrZ() + deltaZ;
-      cont.Zmin = z-dZ;
-      cont.Zmax = z+dZ;
-      cont.binYmin = (Int_t ) ( (cont.Ymin-dY-grid.YMin())*grid.StepYInv() );
-      cont.binYmax = (Int_t ) ( (cont.Ymax+dY-grid.YMin())*grid.StepYInv() );
-      cont.binZmin = (Int_t ) ( (cont.Zmin-dZ-grid.ZMin())*grid.StepZInv() );
-      cont.binZmax = (Int_t ) ( (cont.Zmax+dZ-grid.ZMin())*grid.StepZInv() );
-      if( cont.binYmin<0 ) cont.binYmin = 0;
-      if( cont.binYmin>=grid.Ny() ) cont.binYmin = grid.Ny()-1;
-      if( cont.binYmax<0 ) cont.binYmax = 0;
-      if( cont.binYmax>=grid.Ny() ) cont.binYmax = grid.Ny()-1;
-      if( cont.binZmin<0 ) cont.binZmin = 0;
-      if( cont.binZmin>=grid.Nz() ) cont.binZmin = grid.Nz()-1;
-      if( cont.binZmax<0 ) cont.binZmax = 0;
-      if( cont.binZmax>=grid.Nz() ) cont.binZmax = grid.Nz()-1;
-      cont.next = bin;
-      bin = &cont;
-    }        
-
-    row.CellHitPointers() = fCellHitPointers + lastCellHitPointer;
-    row.Cells() = fCells + lastCell;
-    Int_t nPointers = 0;
-    Int_t nCells = 0;
-
-    //Int_t statMaxBins = 0;
-    //Int_t statMaxHits = 0;
-    for (Int_t ih = 0; ih<nHits; ih++){    
-      THitCont &cont = hitCont[ih];
-      if( cont.used ) continue;
-      // cell start
-      AliHLTTPCCACell &cell = row.Cells()[nCells++];
-      cell.FirstHitRef() = nPointers;
-      cell.NHits() = 1;
-      cell.Link() = -1;
-      cell.Status() = 0;
-      cell.TrackID() = -1;
-      row.CellHitPointers()[nPointers++] = ih;
-      cont.used = 1;      
 
-#ifdef DRAW
-      //AliHLTTPCCADisplay::Instance().DrawHit( irow, ih, kRed );
-#endif
-  // cell finder - neighbouring hits are grouped to cells
+    {
+      Int_t n=0;
+      for( UInt_t bin=0; bin<row.Grid().N()+3; bin++ ){
+       c[bin] = n;
+       n+=filled[bin];
+      }
+    }
+    for( Int_t i=0; i<row.NHits(); i++ ){ 
+      Int_t bin = bins[i];
+      Int_t ind = c[bin] + filled[bin]-1;
+      AliHLTTPCCAHit &h = fHits[RowFirstHit[iRow]+ind];
+      fHitsID[RowFirstHit[iRow]+ind] = RowFirstHit[iRow]+i;
+      h.Y() = Y[row.FirstHit()+i];
+      h.Z() = Z[row.FirstHit()+i];
+      filled[bin]--;
+    }
 
-      
-      Float_t ymin = cont.Ymin;
-      Float_t ymax = cont.Ymax;
-      Float_t zmin = cont.Zmin;
-      Float_t zmax = cont.Zmax;
-      Int_t binYmin = cont.binYmin;
-      Int_t binYmax = cont.binYmax;
-      Int_t binZmin = cont.binZmin;
-      Int_t binZmax = cont.binZmax;
-
-      Bool_t repeat = 1;
-      while( repeat ){
-       repeat = 0;
-       THitCont ** startY = (THitCont **) grid.Grid() + binZmin*grid.Ny();
-       //Float_t Ymax1 = Ymax;
-       //Float_t Ymin1 = Ymin;
-       //Float_t Zmax1 = Zmax;
-       //Float_t Zmin1 = Zmin;
-       Int_t binYmax1 = binYmax;
-       Int_t binYmin1 = binYmin;
-       Int_t binZmax1 = binZmax;
-       Int_t binZmin1 = binZmin;
-#ifdef DRAW
-       //cell.Y() = .5*(Ymin+Ymax);
-       //cell.Z() = .5*(Zmin+Zmax);
-       //cell.ErrY() = .5*( Ymax - Ymin )/3.5;
-       //cell.ErrZ() = .5*( Zmax - Zmin )/3.5;
-       //cell.YMin() = Ymin;
-       //cell.YMax() = Ymax;
-       //AliHLTTPCCADisplay::Instance().DrawCell( irow, nCells-1, 1,kRed );
-       //AliHLTTPCCADisplay::Instance().Ask();
-#endif
-       for( Int_t iGridZ=binZmin1; iGridZ<=binZmax1; iGridZ++, startY += grid.Ny() ){
-         for( Int_t iGridY=binYmin1; iGridY<=binYmax1; iGridY++ ){
-           for( THitCont *bin = *(startY + iGridY); bin; bin=bin->next ){
-             Int_t jh = bin->h-row.Hits();
-             THitCont &cont1 = hitCont[jh];
-             if( cont1.used ) continue;              
-             //cout<<"["<<Ymin<<","<<Ymax<<"]: ["<<cont1.Ymin<<","<<cont1.Ymax<<"]"<<endl;
-             if( cont1.Ymax < ymin ) continue; 
-             if( cont1.Ymin > ymax ) continue;
-             if( cont1.Zmax < zmin ) break;// in the grid cell hit Y is decreasing
-             if( cont1.Zmin > zmax ) continue;
-               
-             if( cont1.Ymin < ymin ){ ymin = cont1.Ymin; repeat = 1; }
-             if( cont1.Ymax > ymax ){ ymax = cont1.Ymax; repeat = 1; }
-             if( cont1.Zmin < zmin ){ zmin = cont1.Zmin; repeat = 1; }
-             if( cont1.Zmax > zmax ){ zmax = cont1.Zmax; repeat = 1; }
-             if( cont1.binYmin < binYmin ){ binYmin = cont1.binYmin; repeat = 1; }
-             if( cont1.binYmax > binYmax ){ binYmax = cont1.binYmax; repeat = 1; }
-             if( cont1.binZmin < binZmin ){ binZmin = cont1.binZmin; repeat = 1; }
-             if( cont1.binZmax > binZmax ){ binZmax = cont1.binZmax; repeat = 1; }
-               
-             row.CellHitPointers()[nPointers++] = jh;
-             cell.NHits()++;
-             cont1.used = 1;       
-#ifdef DRAW
-             //AliHLTTPCCADisplay::Instance().DrawHit( irow, jh, kRed );
-             //AliHLTTPCCADisplay::Instance().Ask();  
-#endif
-           }
-         }
-       }
+    grid.Offset() = fGridSizeTotal;
+    Int_t off= grid.N()+3+10;
+    fGridSizeTotal+=off;
+    Int_t n2 = grid.N()/2;
+    grid.Content2() = c[n2];
+    UChar_t *cnew = fGridContents + grid.Offset();
+
+    for( Int_t i=0; i<n2; i++ ){
+      Int_t v = c[i];
+      if( v>=256 ){
+       cout<<" ERROR!!! "<<v<<endl;
+       v = 255;
+      }else if( v<0 ){
+       cout<<" ERROR!!! "<<v<<endl;
+       v = 0;
+      }              
+      cnew[i] = (UChar_t ) v;
+    }
+    for( UInt_t i=n2; i<grid.N()+3; i++ ){
+      Int_t v = c[i] - grid.Content2();
+      if( v>=256 ){
+       cout<<" ERROR 1 !!! "<<v<<endl;
+       v = 255;
+      }else if( v<0 ){
+       cout<<" ERROR 1 !!! "<<v<<endl;
+       v = 0;
       }
-      
-      cell.Y() = .5*(ymin+ymax);
-      cell.Z() = .5*(zmin+zmax);
-      cell.ErrY() = .5*( ymax - ymin - 2*deltaY)/3.5;
-      cell.ErrZ() = .5*( zmax - zmin -2*deltaZ)/3.5;
-      cell.ZMin() = zmin;
-      cell.ZMax() = zmax;
-#ifdef DRAW
-      //AliHLTTPCCADisplay::Instance().DrawCell( irow, nCells-1 );
-      //AliHLTTPCCADisplay::Instance().Ask();  
-#endif
+      cnew[i] = (UChar_t) v;     
     }
-    //cout<<statMaxBins<<"/"<<grid.N()<<" "<<statMaxHits<<"/"<<nHits<<endl;
 
     
-    row.NCells() = nCells;
-    lastCellHitPointer += nPointers;
-    lastCell += nCells;
-  }
-  delete[] hitCont;
-  timer.Stop();
-  fTimers[0] = timer.CpuTime();
-}
-
-
-void AliHLTTPCCATracker::MergeCells()
-{
-  // First step: 
-  //  for each Cell find one neighbour in the next row (irow+1)
-  //  when there are no neighbours, look to the rows (irow+2),(irow+3)
-  //
-  // Initial state: 
-  //  cell.Link  =-1
-  //  cell.Link1  =-1
-  //  cell.Track      =-1
-  //
-  // Intermediate state: same as final
-  //
-  // Final state:
-  //  cell.Link = Neighbour ID, if there is a neighbour 
-  //             = -1, if no neighbours found
-  //             = -2, if there was more than one neighbour
-  //  cell.Link1 = ID of the cell which has this Cell as a forward neighbour
-  //             = -1 there are no backward neighbours
-  //             = -2 there are more than one neighbour
-  //  cell.Track = -1
-  //
-
-  TStopwatch timer;
+    UInt_t *cnew1 = fGrid1Contents + grid.Offset();
+
+    for( UInt_t i=0; i<grid.N()+1; i++ ){
+      UInt_t g0n = 0;
+      UInt_t g1n = 0;
+      UInt_t g1 = 0;
+      UInt_t g0 = c[i];// max [gN]
+      UInt_t g0e = c[i+2]; //max[gN+2]
+      g0n = g0e - g0;
+      if( i+grid.Ny()< grid.N()+1 ){// max [gN-gNy]
+       g1 = c[i+grid.Ny()]; // max [gN]
+       UInt_t g1e = c[i+grid.Ny()+2];//max [gN+2]
+       g1n = g1e - g1;  
+      }
 
-  Int_t nStartCells = 0;
-  for( Int_t iRow1=0; iRow1<fParam.NRows(); iRow1++ ){
-    AliHLTTPCCARow &row1 = fRows[iRow1];
+      if( g0n > 63 ) g0n = 63;
+      if( g1n > 63 ) g1n = 63;
+      cnew1[i] = (g1n<<26) + (g1<<16) + (g0n<<10) + g0;
+    }
+    {
+      float y0 = row.Grid().YMin();
+      float stepY = (row.Grid().YMax() - y0)*(1./65535.);
+      float z0 = row.Grid().ZMin();
+      float stepZ = (row.Grid().ZMax() - z0)*(1./65535.);
+      float stepYi = 1./stepY;
+      float stepZi = 1./stepZ;
       
-    Float_t deltaY = row1.DeltaY();
-    Float_t deltaZ = row1.DeltaZ();
-    Float_t xStep = 1;
-    if( iRow1 < fParam.NRows()-1 ) xStep = fParam.RowX(iRow1+1) - fParam.RowX(iRow1);
-    Float_t tx = xStep/row1.X();
-    Int_t lastRow2 = iRow1+3;
-    if( lastRow2>=fParam.NRows() ) lastRow2 = fParam.NRows()-1;
-
-    for (Int_t i1 = 0; i1<row1.NCells(); i1++){
-      AliHLTTPCCACell &c1  = row1.Cells()[i1];
-      //cout<<"row, cell= "<<iRow1<<" "<<i1<<" "<<c1.Y()<<" "<<c1.ErrY()<<" "<<c1.Z()<<" "<<c1.ErrZ()<<endl;
-      //Float_t sy1 = c1.ErrY()*c1.ErrY();      
-      Float_t yy = c1.Y() +tx*c1.Y();
-      Float_t zz = c1.Z() +tx*c1.Z();
+      row.Hy0() = y0;
+      row.Hz0() = z0;
+      row.HstepY() = stepY;
+      row.HstepZ() = stepZ;
+      row.HstepYi() = stepYi;
+      row.HstepZi() = stepZi;
       
-      Float_t yMin = yy - 3.5*c1.ErrY() - deltaY;
-      Float_t yMax = yy + 3.5*c1.ErrY() + deltaY;
-      Float_t zMin = zz - 3.5*c1.ErrZ() - deltaZ;
-      Float_t zMax = zz + 3.5*c1.ErrZ() + deltaZ;
-      //Float_t sz1 = c1.ErrZ()*c1.ErrZ();
-      if( c1.Status()<=0 ) nStartCells++;
-
-      // looking for neighbour for the Cell c1
-      Bool_t found = 0;
-      for( Int_t iRow2=iRow1+1; iRow2<=lastRow2&&(!found); iRow2++ ){
-       AliHLTTPCCARow &row2 = fRows[iRow2];
-       AliHLTTPCCACell *cc2 = lower_bound(row2.Cells(),row2.Cells()+row2.NCells(),zMin,AliHLTTPCCARow::CompareCellZMax);
-       for (Int_t i2 = (cc2 - row2.Cells()); i2<row2.NCells(); i2++){
-         //cout<<"   candidat = "<<iRow2<<" "<<i2<<endl;
-         
-         AliHLTTPCCACell &c2  = row2.Cells()[i2];
-         Float_t y2Min = c2.Y() - 3.5*c2.ErrY();
-         Float_t y2Max = c2.Y() + 3.5*c2.ErrY();
-         Float_t z2Min = c2.Z() - 3.5*c2.ErrZ();
-         Float_t z2Max = c2.Z() + 3.5*c2.ErrZ();
-
-         if( y2Min > yMax ) continue;
-         if( y2Max < yMin ) continue;
-         if( z2Min > zMax ) break;
-         if( z2Max < zMin ) continue;
-
-         // c1 & c2 are neighbours
-
-         found = 1;
-         
-         if( c1.Link() ==-1 && c2.Status()==0 ){ 
-           // one-to-one connection - OK
-           c1.Link() = IRowICell2ID(iRow2,i2);
-           c2.Status() = 1;
-         }else{
-           // multi-connection - break all links
-           if( c1.Link()>=0 ) ID2Cell(c1.Link()).Status() = -1;            
-           c1.Link()  = -2;
-           c2.Status() = -1;
-         }
+      for( Int_t ih=0; ih<row.NHits(); ih++ ){
+       Int_t ihTot = RowFirstHit[iRow]+ih;
+       AliHLTTPCCAHit &hh = fHits[ihTot];
+       ushort2  &h = fHits1[ihTot];
+       float xx = ((hh.Y() - y0)*stepYi); //SG!!!
+       float yy = ((hh.Z() - z0)*stepZi);
+       if( xx<0 || yy<0 || xx>=65536 || yy>= 65536 ){
+         cout<<"!!!! hit packing error!!! "<<xx<<" "<<yy<<" "<<endl;
        }
-      }//row2
-    }
-  }//row1
-
-  timer.Stop();
-  fTimers[1] = timer.CpuTime();
-  
-  // Second step: create tracks 
-  //  for each sequence of neighbouring Cells create Track object
-  //
-  // Final state:
-  //  cell.Track     = TrackNumber for first and last track cell
-  //                 = -1 for other cells
-  //  cell.Link     = Neighbour ID, if there is a neighbour 
-  //                 = -1, if no neighbour (last cell on the track )
-  //  cell.Link1     = backward neighbour ID, if there is a neighbour 
-  //                 = -1 for first and last track cells
-  
-  TStopwatch timer2;
-  
-  fTracks = new AliHLTTPCCATrack[nStartCells];
-  fNTracks = 0;
-
-  for( Int_t iRow=0; iRow<fParam.NRows(); iRow++ ){
-    AliHLTTPCCARow &row = fRows[iRow];
-    for( Int_t iCell = 0; iCell<row.NCells(); iCell++){ 
-      AliHLTTPCCACell &c  = row.Cells()[iCell];
-      if( c.Status()>0 ) continue; // not a starting cell
-
-      Int_t firstID = IRowICell2ID( iRow, iCell );
-      Int_t midID = firstID;
-      Int_t lastID = firstID;
-
-      AliHLTTPCCATrack &track = fTracks[fNTracks];
-      track.Alive() = 1;
-      track.NCells() = 1;
-      AliHLTTPCCACell *last = &c;
-      while( last->Link() >=0 ){
-       Int_t nextID = last->Link();
-       AliHLTTPCCACell *next = & ID2Cell(nextID);
-       if(next->Status()!=1 ){
-         last->Link() = -1;
-         break;
-       }       
-       track.NCells()++;
-       last = next;
-       lastID = nextID;
+       h.x = (UShort_t) xx;//((hh.Y() - y0)*stepYi);
+       h.y = (UShort_t) yy;//((hh.Z() - z0)*stepZi);
       }
-      Int_t nCells05 = (track.NCells()-1)/2;
-      for( Int_t i=0; i<nCells05; i++ ) midID = ID2Cell(midID).Link();
-      //cout<<fNTracks<<", NCells="<<track.NCells()<<" "<<nCells05<<"id="<<firstID<<" "<<midID<<" "<<lastID<<endl;
-      c.TrackID() = fNTracks;
-      last->TrackID() = fNTracks;
-      track.FirstCellID() = firstID;
-      track.CellID()[0] = firstID;
-      track.CellID()[1] = midID;
-      track.CellID()[2] = lastID;
-      track.PointID()[0] = -1;
-      track.PointID()[1] = -1;
-      //cout<<"Track N "<<fNTracks<<", NCells="<<track.NCells()<<endl;
-
-      fNTracks++;
     }
-  }
-  if( fNTracks != nStartCells ){
-    //cout<<"fNTracks="<<fNTracks<<", NStrartCells="<<nStartCells<<endl;
-    //exit(0);
-    return;
-  }
 
-  // create endpoints 
-
-  Int_t nEndPointsTotal = 0;
-  for( Int_t iRow=0; iRow<fParam.NRows(); iRow++ ){
-    AliHLTTPCCARow &row = fRows[iRow];
-    row.EndPoints()= fEndPoints + nEndPointsTotal;
-    row.NEndPoints()=0;
-    for( Int_t iCell = 0; iCell<row.NCells(); iCell++){ 
-      AliHLTTPCCACell &c  = row.Cells()[iCell];
-      if( c.TrackID()< 0 ) continue; // not an endpoint
-      AliHLTTPCCAEndPoint &p = row.EndPoints()[row.NEndPoints()];
-      p.CellID() = IRowICell2ID(iRow,iCell);
-      p.TrackID() = c.TrackID();
-      p.Link() = -1;
-      AliHLTTPCCATrack &track = fTracks[c.TrackID()];
-      if( c.Link()>=0 ){
-       track.PointID()[0] = IRowICell2ID(iRow,row.NEndPoints());
-      }else{
-       track.PointID()[1] = IRowICell2ID(iRow,row.NEndPoints());
-       if( track.PointID()[0]<0 )track.PointID()[0] = track.PointID()[1];
+    if(1){       
+      row.FullOffset() = fTexHitsFullSize;
+      ushort2 *p= (ushort2*)(fTexHitsFullData+row.FullOffset());      
+      for( Int_t ih=0; ih<row.NHits(); ih++ ){
+       Int_t ihTot = RowFirstHit[iRow]+ih;
+       p[ih] = fHits1[ihTot];
       }
-      row.NEndPoints()++;
+      Int_t size = row.NHits()*sizeof(ushort2);
+
+      row.FullGridOffset() = row.NHits()*2;      
+      UShort_t *p1 = ((UShort_t *)p) + row.FullGridOffset();
+
+      Int_t n = grid.N();
+      for( Int_t i=0; i<n; i++ ){
+       p1[i] = c[i];
+      }     
+      UShort_t a = c[n-1];
+      Int_t nn = n+grid.Ny()+2;
+      for( Int_t i=n; i<nn; i++ ) p1[i] = a;
+
+      size+= (nn)*sizeof(UShort_t);
+      row.FullLinkOffset() = row.NHits()*2 + nn;
+      size+= row.NHits()*2*sizeof(Short_t);
+      if( size%16 ) size = size/16+1;
+      else size = size/16;
+      row.FullSize()=size;
+      //cout<<iRow<<", "<<row.fNHits<<"= "<<size*16<<"b: "<<row.fFullOffset<<" "<<row.fFullSize<<" "<<row.fFullGridOffset<<" "<<row.fFullLinkOffset<<endl;
+
+      fTexHitsFullSize+=size;
     }
-    nEndPointsTotal += row.NEndPoints();
   }
-  timer2.Stop();
-  fTimers[2] = timer2.CpuTime();
+  fGrid1SizeTotal = fGridSizeTotal+10;
 }
 
-void AliHLTTPCCATracker::FindTracks()
-{
-  // the Cellular Automaton track finder  
-  TStopwatch timer3;
-  //cout<<"combine & fit tracks"<<endl;
-  for( Int_t itr=0; itr<fNTracks; itr++ ){
-    AliHLTTPCCATrack &iTrack = fTracks[itr];
-    //if( iTrack.NCells()<3 ) continue;
-    //cout<<" fit track "<<itr<<", NCells="<<iTrack.NCells()<<endl;    
-    ID2Point(iTrack.PointID()[0]).Param().CosPhi() = -1;
-    ID2Point(iTrack.PointID()[1]).Param().CosPhi() = 1;
-    FitTrack( iTrack );
-    //if( iTrack.Param().Chi2() > fParam.TrackChi2Cut()*iTrack.Param().NDF() ){
-      //iTrack.Alive() = 0;
-    //}
-  }
-  timer3.Stop();
-  fTimers[3] = timer3.CpuTime();
 
+GPUh() void AliHLTTPCCATracker::Reconstruct()
+{
+  //* reconstruction of event
+  
 #ifdef DRAW
   if( !gApplication ){
     TApplication *myapp = new TApplication("myapp",0,0);
-  }    
+  }
   //AliHLTTPCCADisplay::Instance().Init();
   
   AliHLTTPCCADisplay::Instance().SetCurrentSlice( this );
-  AliHLTTPCCADisplay::Instance().DrawSlice( this );
-  cout<<"draw hits..."<<endl;
-  for( Int_t iRow=0; iRow<fParam.NRows(); iRow++ )
-    for (Int_t i = 0; i<fRows[iRow].NHits(); i++) 
-      AliHLTTPCCADisplay::Instance().DrawHit( iRow, i );
-  AliHLTTPCCADisplay::Instance().Ask();
-  AliHLTTPCCADisplay::Instance().ClearView();
-  AliHLTTPCCADisplay::Instance().DrawSlice( this );
-  cout<<"draw cells..."<<endl;
-  for( Int_t iRow=0; iRow<fParam.NRows(); iRow++ )
-    for (Int_t i = 0; i<fRows[iRow].NCells(); i++) 
-      AliHLTTPCCADisplay::Instance().DrawCell( iRow, i );
-  AliHLTTPCCADisplay::Instance().Ask();  
-
-  Int_t nConnectedCells = 0;
-
-  cout<<"draw merged cells..."<<endl;
-
-  for( Int_t iRow=0; iRow<fParam.NRows(); iRow++ )
-    for (Int_t i = 0; i<fRows[iRow].NCells(); i++) 
-      {
-       AliHLTTPCCACell &c = fRows[iRow].Cells()[i];
-       Int_t id = c.Link();
-       if( id<0 ) continue;    
-       AliHLTTPCCADisplay::Instance().ConnectCells( iRow,c,ID2IRow(id),ID2Cell(id) );
-       nConnectedCells++;
-      }
-  if( nConnectedCells>0 ){
-    AliHLTTPCCADisplay::Instance().Ask();  
-  }
+  AliHLTTPCCADisplay::Instance().SetSliceView();
+  AliHLTTPCCADisplay::Instance().DrawSlice( this );  
+  //for( Int_t iRow=0; iRow<fParam.NRows(); iRow++ )
+  //for (Int_t i = 0; i<fRows[iRow].NHits(); i++) 
+  //AliHLTTPCCADisplay::Instance().DrawHit( iRow, i );
+  //AliHLTTPCCADisplay::Instance().Ask();
+#endif
 
-  
-  AliHLTTPCCADisplay::Instance().ClearView();
-  AliHLTTPCCADisplay::Instance().DrawSlice( this );
-  for( Int_t iRow=0; iRow<fParam.NRows(); iRow++ )
-    for (Int_t i = 0; i<fRows[iRow].NCells(); i++) 
-      AliHLTTPCCADisplay::Instance().DrawCell( iRow, i );  
-  
-  cout<<"draw initial tracks"<<endl;
-  
-  for( Int_t itr=0; itr<fNTracks; itr++ ){
-    AliHLTTPCCATrack &iTrack = fTracks[itr];
-    if( iTrack.NCells()<3 ) continue;
-    if( !iTrack.Alive() ) continue;
-    AliHLTTPCCADisplay::Instance().DrawTrack( iTrack );
-  }
-  //if( fNTracks>0 ) 
-  AliHLTTPCCADisplay::Instance().Ask();
-#endif 
+  fTimers[0] = 0; // find neighbours
+  fTimers[1] = 0; // construct tracklets
+  fTimers[2] = 0; // fit tracklets
+  fTimers[3] = 0; // prolongation of tracklets
+  fTimers[4] = 0; // selection
+  fTimers[5] = 0; // write output
+  fTimers[6] = 0;
+  fTimers[7] = 0;
+
+  if( fNHitsTotal < 1 ) return;
+  //if( fParam.ISlice()!=3 ) return;
+  TStopwatch timer0;
+  *fNTracks = 0;
+#if !defined(HLTCA_GPUCODE)  
 
-  TStopwatch timer4;
+  AliHLTTPCCAProcess<AliHLTTPCCANeighboursFinder>( Param().NRows(), 1, *this );
+  AliHLTTPCCAProcess<AliHLTTPCCANeighboursCleaner>( Param().NRows()-2, 1, *this );
+  AliHLTTPCCAProcess<AliHLTTPCCAStartHitsFinder>( Param().NRows()-4, 1, *this );
 
-  Bool_t doMerging=1;//SG!!!
+  Int_t nStartHits = *fStartHits;      
   
-  Float_t factor2 = fParam.TrackConnectionFactor()*fParam.TrackConnectionFactor();
-  Int_t *refEndPoints = new Int_t[fNHitsTotal];
-  Int_t nRefEndPoints = 0;
-  for( Int_t iRow=0; iRow<fParam.NRows(); iRow++ ){
-    AliHLTTPCCARow &irow = fRows[iRow];
-    for (Int_t iPoint = 0; iPoint<irow.NEndPoints(); iPoint++){ 
-      refEndPoints[nRefEndPoints++] = IRowICell2ID(iRow,iPoint);
-    }
+  Int_t nThreads = 128;
+  Int_t nBlocks = fNHitsTotal/nThreads + 1;
+  if( nBlocks<12 ){
+    nBlocks = 12; 
+    nThreads = fNHitsTotal/12+1;
+    if( nThreads%32 ) nThreads = (nThreads/32+1)*32;
   }
-  bool first = 1;
-  while( doMerging ){
-
-    //cout<<"do merging"<<endl;
-    
-    doMerging = 0;
-
-    // find nejghbouring tracks
-    TStopwatch timer5;
-    //cout<<"nRefEndPoints = "<<nRefEndPoints<<endl;
-
-    for( Int_t iRef=0; iRef<nRefEndPoints; iRef++ ){
-      Int_t iRow = ID2IRow(refEndPoints[iRef]);
-      AliHLTTPCCARow &irow = fRows[iRow];
-      Int_t iPoint = ID2ICell(refEndPoints[iRef]);      
-      AliHLTTPCCAEndPoint &ip  = irow.EndPoints()[iPoint];
-      if( ip.TrackID()<0 ) continue; // not active endpoint
-
-      AliHLTTPCCATrack &iTrack = fTracks[ip.TrackID()];
-      if( iTrack.NCells()<3 ) continue;
-      
-      Int_t jRowMin = iRow - fParam.MaxTrackMatchDRow();
-      Int_t jRowMax = iRow + fParam.MaxTrackMatchDRow();
-      if( jRowMin<0 ) jRowMin = 0;
-      if( jRowMax>=fParam.NRows() ) jRowMax = fParam.NRows()-1;
-
-      if( ip.Param().CosPhi()>=0 ){ //TMath::Abs([2])<TMath::Pi()/2. ){
-       jRowMin = iRow;
-      }else{
-       jRowMax = iRow;
-      }
-
-      Int_t bestNeighbourN = -1;
-      Float_t bestDist2 = 1.e20;
-      Int_t bestLink = -1;
-      if( ip.Link()>=0 ){ 
-       bestNeighbourN = fTracks[ID2Point(ip.Link()).TrackID()].NCells();
-      }
-      
-      Float_t y0 = ip.Param().GetY();
-      Float_t z0 = ip.Param().GetZ();
-
- #ifdef DRAW      
-      //AliHLTTPCCADisplay::Instance().DrawTrackletPoint(ip.Param(),kBlue);
-      //AliHLTTPCCADisplay::Instance().Ask();
-#endif
-     
-      for( Int_t jRow = jRowMin; jRow<=jRowMax; jRow++){
-       AliHLTTPCCARow &jrow = fRows[jRow];
-       Float_t dx2 = (irow.X()-jrow.X())*(irow.X()-jrow.X());
-
-       // extrapolate the track to row jRow
-
-       //for( int ii=0; ii<10; ii++){
-       //AliHLTTPCCATrackParam iPar = ip.Param();
-       //iPar.TransportToX( jrow.X());
-       //}
-       AliHLTTPCCATrackParam iPar = ip.Param();
-       Bool_t ok = iPar.TransportToX( jrow.X());
-       if( !ok ) continue;
-#ifdef DRAW
-       //AliHLTTPCCADisplay::Instance().DrawTrackletPoint(iPar, kBlack);
-       //AliHLTTPCCADisplay::Instance().Ask();
-#endif
-       Float_t zMin = iPar.GetZ() - 3.5*TMath::Sqrt(iPar.GetErr2Z()) - .2*3.5;
-       AliHLTTPCCAEndPoint *jjp = lower_bound(jrow.EndPoints(),jrow.EndPoints()+jrow.NEndPoints(),zMin,AliHLTTPCCARow::CompareEndPointZ);
-       
-       for (Int_t jPoint = jjp-jrow.EndPoints(); jPoint<jrow.NEndPoints(); jPoint++){ 
-
-         AliHLTTPCCAEndPoint &jp  = jrow.EndPoints()[jPoint];
-         
-         if( jp.TrackID()<0 ) continue; // endpoint not active
-         if( jp.TrackID()==ip.TrackID() ) continue; // same track
-         
-         AliHLTTPCCATrack &jTrack = fTracks[jp.TrackID()];
-         
-         if( bestNeighbourN > jTrack.NCells() ){
-           continue; // there is already better neighbour found
-         }
-         if( jp.Link()>=0 &&
-             fTracks[ID2Point(jp.Link()).TrackID()].NCells()>=iTrack.NCells() ){
-           continue; // jTrack is already linked to a better track or to iTrack
-         }
-
-         Float_t dy2, dz2;
-         AliHLTTPCCATrackParam &jPar = jp.Param();
-
-         // check direction
-         {
-           if( jPar.GetCosPhi()*iPar.GetCosPhi()>=0 ) continue;
-         }       
-         // check for neighbouring
-         {
-           float d = jPar.GetY() - iPar.GetY();
-           float s2 = jPar.GetErr2Y() + iPar.GetErr2Y();
-           if( d*d>factor2*s2 ){
-             continue;
-           }
-           //cout<<"\ndy="<<TMath::Sqrt(d*d)<<", err="<<TMath::Sqrt(factor2*s2)<<endl;
-           d = jPar.GetZ() - iPar.GetZ();
-           s2 = jPar.GetErr2Z() + iPar.GetErr2Z();
-           if( d*d>factor2*s2 ){
-             if( d>0 ) break;
-             continue;
-           }
-           //cout<<"dz="<<TMath::Sqrt(d*d)<<", err="<<TMath::Sqrt(factor2*s2)<<endl;
-           if( iTrack.NCells()>=3 && jTrack.NCells()>=3 ){
-             d = jPar.GetSinPhi() + iPar.GetSinPhi(); //! phi sign is different
-             s2 = jPar.GetErr2SinPhi() + iPar.GetErr2SinPhi();
-             if( d*d>factor2*s2 ) continue;
-             //cout<<"dphi="<<TMath::Sqrt(d*d)<<", err="<<TMath::Sqrt(factor2*s2)<<endl;
-             d = jPar.GetKappa() + iPar.GetKappa(); // ! kappa sign iz different
-             s2 = jPar.GetErr2Kappa() + iPar.GetErr2Kappa();
-             if( d*d>factor2*s2 ) continue;
-             //cout<<"dk="<<TMath::Sqrt(d*d)<<", err="<<TMath::Sqrt(factor2*s2)<<endl;
-             d = jPar.GetDzDs() + iPar.GetDzDs(); // ! DzDs sign iz different
-             s2 = jPar.GetErr2DzDs() + iPar.GetErr2DzDs();
-             if( d*d>factor2*s2 ) continue;
-             //cout<<"dlam="<<TMath::Sqrt(d*d)<<", err="<<TMath::Sqrt(factor2*s2)<<endl;
-           }
-         }
-         
-         Float_t dy = jPar.GetY() - y0;
-         dy2 = dy*dy;
-         Float_t dz = jPar.GetZ() - z0;
-         dz2 = dz*dz;
-         Float_t dist2 = dx2+dy2+dz2;
-
-         if( ( bestNeighbourN == jTrack.NCells() ) && dist2>bestDist2 ) continue;
-         
-         // tracks can be matched
-         
-         bestLink = IRowICell2ID( jRow, jPoint );
-         bestNeighbourN = jTrack.NCells();
-         bestDist2 = dist2;
-       }
-      }
-               
-      if( bestLink < 0 ) continue; // no neighbours found
-
-      AliHLTTPCCAEndPoint &jp = ID2Point(bestLink);
       
-      if( ip.Link()>=0 ){ // break existing link of iTrack
-       ID2Point(ip.Link()).Link() = -1;
-      }
-      if( jp.Link()>=0 ){ // break existing link of jTrack
-       ID2Point(jp.Link()).Link() = -1;
-      }
-      ip.Link() = bestLink;
-      jp.Link()= IRowICell2ID( iRow, iPoint );
-      
-      //cout<<"create link ("<<jp.Link()<<","<<ip.TrackID()<<")->("<<ip.Link()<<","<<jp.TrackID()<<")"<<endl;
-      
-    }
+  nThreads = fNHitsTotal;
+  nBlocks = 1;
 
-    timer5.Stop();
-    if(first) fTimers[5] += timer5.CpuTime();
+  AliHLTTPCCAProcess<AliHLTTPCCAUsedHitsInitialiser>(nBlocks, nThreads,*this);
 
-    //cout<<"merge neighbours"<<endl;
-    // merge neighbours
+  nThreads = 256;
+  nBlocks = 30;
 
-    TStopwatch timer6;
+  nThreads = 1;
+  nBlocks = 1;
+  
+  AliHLTTPCCAProcess<AliHLTTPCCALinksWriter>(nBlocks, nThreads,*this);
+
+  Int_t nMemThreads = 128;
+  nThreads = 256;//96;
+  nBlocks = nStartHits/nThreads + 1;
+  if( nBlocks<30 ){
+    nBlocks = 30;
+    nThreads = (nStartHits)/30+1;
+    if( nThreads%32 ) nThreads = (nThreads/32+1)*32;
+  }
 
-    Int_t nRefEndPointsNew = 0;
-    for( Int_t iRef=0; iRef<nRefEndPoints; iRef++ ){
+  nThreads = nStartHits;
+  nBlocks = 1;
 
-      Int_t iRow = ID2IRow(refEndPoints[iRef]);
-      Int_t iPoint = ID2ICell(refEndPoints[iRef]);
-      AliHLTTPCCARow &irow = fRows[iRow];
-      AliHLTTPCCAEndPoint &ip  = irow.EndPoints()[iPoint];
-      if( ip.TrackID()<0 ) continue; // not active endpoint 
-      if( ip.Link()<0 ) continue; // no neighbours found
+  AliHLTTPCCAProcess1<AliHLTTPCCATrackletConstructor>(nBlocks, nMemThreads+nThreads,*this);
 
-      Int_t ipID = IRowICell2ID(iRow,iPoint);
-      Int_t jpID = ip.Link();
-      AliHLTTPCCAEndPoint &jp  = ID2Point(jpID);
-      
-      if( jp.Link()!=ipID ){
-       //cout<<"broken link: jp.Link()!=iID"<<endl;
-       //exit(0);
-       return;
-      }
-      if( jp.TrackID()<0 ){ 
-       //cout<<"broken link: jp.TrackID()<=0"<<endl;
-       //exit(0);
-       return;
-      }
-      if( jp.TrackID()==ip.TrackID() ){
-       //cout<<"broken link: jp.TrackID()==ip.TrackID()"<<endl;
-       //exit(0);        
-       return;
-      }
-     
-      //cout<<"Merge neighbours ("<<ipID<<","<<ip.TrackID()<<")->("<<jpID<<","<<jp.TrackID()<<")"<<endl;
+  { 
+    nThreads = 128;
+    nBlocks = nStartHits/nThreads + 1;
+    if( nBlocks<12 ){
+      nBlocks = 12;  
+      nThreads = nStartHits/12+1;
+      nThreads = (nThreads/32+1)*32;
+    }
+    *fStartHits = 0;
+    *fTrackHits = 0;
 
-      AliHLTTPCCATrack &iTrack = fTracks[ip.TrackID()];
-      AliHLTTPCCATrack &jTrack = fTracks[jp.TrackID()];
+    nThreads = nStartHits;
+    nBlocks = 1;
 
-      // rotate cell link direction for jTrack if necessary
-      
-      Int_t icID = ip.CellID();
-      Int_t jcID = jp.CellID();
-      AliHLTTPCCACell &ic  = ID2Cell(icID);
-      AliHLTTPCCACell &jc  = ID2Cell(jcID);
-      
-      if( ( ic.Link()<0 && jc.Link()<0 ) || ( ic.Link()>=0 && jc.Link()>=0 ) ){
-
-       Int_t currID =  jTrack.CellID()[0];
-       jTrack.CellID()[0] = jTrack.CellID()[2];
-       jTrack.CellID()[2] = currID;
-
-       Int_t pID =  jTrack.PointID()[0];
-       jTrack.PointID()[0] = jTrack.PointID()[1];
-       jTrack.PointID()[1] = pID;
-
-       currID = jTrack.FirstCellID();
-       Int_t lastID = -1;
-       while( currID>=0 ){
-         AliHLTTPCCACell &c = ID2Cell( currID );
-         Int_t nextID = c.Link();
-         c.Link() = lastID;
-         lastID = currID;
-         currID = nextID;
-       }
-       jTrack.FirstCellID() = lastID;  
-      }
-      //cout<<"track i "<<ip.TrackID()<<", points="<<ipID<<", "<<iTrack.PointID()[0]<<", "<<iTrack.PointID()[1]<<endl;
-      //cout<<"track j "<<jp.TrackID()<<", points="<<jpID<<", "<<jTrack.PointID()[0]<<", "<<jTrack.PointID()[1]<<endl;
-      Int_t itr = ip.TrackID();
-      ip.TrackID() = -1;
-      jp.TrackID() = -1;
-      ip.Link()  = -1;
-      jp.Link()  = -1;
-      jTrack.Alive() = 0;
-      
-      //cout<<"iTrack ID: "<<iTrack.CellID()[0]<<" "<<iTrack.CellID()[1]<<" "<<iTrack.CellID()[2]<<endl;
-      //cout<<"jTrack ID: "<<jTrack.CellID()[0]<<" "<<jTrack.CellID()[1]<<" "<<jTrack.CellID()[2]<<endl;
-      if( ic.Link()<0 ){ //match iTrack->jTrack
-       ic.Link() = jcID;
-       iTrack.PointID()[1] = jTrack.PointID()[1];
-       ID2Point(iTrack.PointID()[1]).TrackID() = itr;
-       if( jTrack.NCells()<3 ){
-         refEndPoints[nRefEndPointsNew++] = iTrack.PointID()[1];
-         doMerging = 1;
-         ID2Point(iTrack.PointID()[1]).Param() = ip.Param();// just to set phi direction
-       }
-       if( iTrack.NCells()<3 ){
-         refEndPoints[nRefEndPointsNew++] = iTrack.PointID()[0];
-         doMerging = 1;
-         ID2Point(iTrack.PointID()[0]).Param() = jp.Param();// just to set phi direction
-       }
-
-       if( TMath::Abs(ID2Cell(jTrack.CellID()[2]).Z()-ID2Cell(iTrack.CellID()[0]).Z())>
-           TMath::Abs(ID2Cell(iTrack.CellID()[2]).Z()-ID2Cell(iTrack.CellID()[0]).Z())  ){
-         iTrack.CellID()[2] = jTrack.CellID()[2];
-       }
-      }else{ //match jTrack->iTrack
-       jc.Link() = icID;
-       iTrack.FirstCellID()=jTrack.FirstCellID();
-       iTrack.PointID()[0] = jTrack.PointID()[0];
-       ID2Point(iTrack.PointID()[0]).TrackID() = itr;
-       if( jTrack.NCells()<3 ){
-         refEndPoints[nRefEndPointsNew++] = iTrack.PointID()[0];
-         doMerging = 1;
-         ID2Point(iTrack.PointID()[0]).Param() = ip.Param(); // just to set phi direction
-       }
-       if( iTrack.NCells()<3 ){
-         refEndPoints[nRefEndPointsNew++] = iTrack.PointID()[1];
-         doMerging = 1;
-         ID2Point(iTrack.PointID()[1]).Param() = jp.Param();// just to set phi direction
-       }
-       if( TMath::Abs(ID2Cell(jTrack.CellID()[0]).Z()-ID2Cell(iTrack.CellID()[2]).Z())>
-           TMath::Abs(ID2Cell(iTrack.CellID()[0]).Z()-ID2Cell(iTrack.CellID()[2]).Z())  ){
-         iTrack.CellID()[0] = jTrack.CellID()[0];
-       }
-      }
 
-      //cout<<"merged ID: "<<iTrack.CellID()[0]<<" "<<iTrack.CellID()[1]<<" "<<iTrack.CellID()[2]<<endl;
+    AliHLTTPCCAProcess<AliHLTTPCCATrackletSelector>(nBlocks, nThreads,*this);
 
-      if( jTrack.NCells()>iTrack.NCells() ){
-       iTrack.CellID()[1] = jTrack.CellID()[1];
-      }
-      
-      AliHLTTPCCAEndPoint &p0 = ID2Point(iTrack.PointID()[0]);
-      AliHLTTPCCAEndPoint &p1 = ID2Point(iTrack.PointID()[1]);
-      
-      if( p0.Link() == iTrack.PointID()[1] ){
-       p0.Link() = -1;
-       p1.Link() = -1;
-      }
-      //cout<<" NCells itr/jtr= "<<iTrack.NCells()<<" "<<jTrack.NCells()<<endl;
-      //cout<<" fit merged track "<<itr<<", NCells="<<iTrack.NCells()<<endl;
-      Float_t *t0 = ( jTrack.NCells()>iTrack.NCells() ) ?jp.Param().Par() :ip.Param().Par();            
-      iTrack.NCells()+=jTrack.NCells();      
-      FitTrack(iTrack,t0);
+    //cudaMemcpy(cpuTrackerCopy.fNTracks, gpuTrackerCopy.fNTracks, sizeof(int), cudaMemcpyDeviceToHost);
+    //cudaMemcpy(cpuTrackerCopy.fTrackHits, gpuTrackerCopy.fTrackHits, sizeof(int), cudaMemcpyDeviceToHost);
+         
+    //Int_t size = sizeof(AliHLTTPCCATrack)*( *cpuTrackerCopy.fNTracks );
+    //cudaMemcpy(cpuTrackerCopy.fTracks, gpuTrackerCopy.fTracks, size, cudaMemcpyDeviceToHost);
+    //cout<<"Tracks size = "<<size<<endl;      
+    
+    //size = sizeof(Int_t)*( *cpuTrackerCopy.fTrackHits );
+    //cudaMemcpy(cpuTrackerCopy.fTrackHits+1, gpuTrackerCopy.fTrackHits+1, size, cudaMemcpyDeviceToHost);
+    //cout<<"Track hits size = "<<size<<endl;
+    //cpuTrackerCopy.WriteOutput();
+    nStartHits = *fStartHits;
+    //cout<<"N tracklets constructed = "<<nStartHits<<endl;
+       
+    //cout<<"Selected NTracks = "<<*fNTracks<<endl;
+    WriteOutput();      
+  }
 
-#ifdef DRAW
-      cout<<"merged points..."<<ipID<<"/"<<jpID<<endl;
-      //AliHLTTPCCADisplay::Instance().ConnectCells( iRow,ic,ID2IRow(jcID),jc,kRed );
-      AliHLTTPCCADisplay::Instance().ConnectEndPoints( ipID,jpID,1.,2,kRed );
-      AliHLTTPCCADisplay::Instance().DrawEndPoint( ipID,1.,2,kRed );
-      AliHLTTPCCADisplay::Instance().DrawEndPoint( jpID,1.,2,kRed );
-      AliHLTTPCCADisplay::Instance().Ask();
-      cout<<"merged track"<<endl;
-      AliHLTTPCCADisplay::Instance().DrawTrack(iTrack);
-      AliHLTTPCCADisplay::Instance().Ask();
 #endif
-      /*
-      static int ntr=0;
-      if( ntr++==1 ){
-       doMerging = 0;
-       break;
-      }
-      */
-      //doMerging = 1;    
-    }
-
-    timer6.Stop();  
-    if(first)fTimers[6] += timer6.CpuTime();
 
-    nRefEndPoints = nRefEndPointsNew;
-
-    //cout<<"merging ok"<<endl;
-    //first = 0;
-  }// do merging
-  delete[] refEndPoints;
-  timer4.Stop();  
-  fTimers[4] = timer4.CpuTime();
-
-#ifdef DRAW
-  //if( fNTracks>0 ) AliHLTTPCCADisplay::Instance().Ask();
-#endif 
+  timer0.Stop();
+  fTimers[0] = timer0.CpuTime();
 
+ }
 
 
 
-#ifdef DRAWXX
-  AliHLTTPCCADisplay::Instance().ClearView();
-  AliHLTTPCCADisplay::Instance().DrawSlice( this );
-  for( Int_t iRow=0; iRow<fParam.NRows(); iRow++ )
-    for (Int_t i = 0; i<fRows[iRow].NCells(); i++) 
-      AliHLTTPCCADisplay::Instance().DrawCell( iRow, i );  
-  
-  cout<<"draw final tracks"<<endl;
-  
-  for( Int_t itr=0; itr<fNTracks; itr++ ){
-    AliHLTTPCCATrack &iTrack = fTracks[itr];
-    if( iTrack.NCells()<3 ) continue;
-    if( !iTrack.Alive() ) continue;
-    AliHLTTPCCADisplay::Instance().DrawTrack( iTrack );
-    cout<<"final track "<<itr<<", ncells="<<iTrack.NCells()<<endl;
-    AliHLTTPCCADisplay::Instance().Ask();
-  }
-  AliHLTTPCCADisplay::Instance().Ask();
-#endif
 
+GPUh() void AliHLTTPCCATracker::WriteOutput()
+{
   // write output
-  TStopwatch timer7;
 
-  //cout<<"write output"<<endl;
-#ifdef DRAW
-  AliHLTTPCCADisplay::Instance().ClearView();
-  AliHLTTPCCADisplay::Instance().DrawSlice( this );
-  for( Int_t iRow=0; iRow<fParam.NRows(); iRow++ )
-    for (Int_t i = 0; i<fRows[iRow].NCells(); i++) 
-      AliHLTTPCCADisplay::Instance().DrawCell( iRow, i );  
-  
-  cout<<"draw out tracks"<<endl;
-#endif
-
-  fOutTrackHits = new Int_t[fNHitsTotal];
-  fOutTracks = new AliHLTTPCCAOutTrack[fNTracks];
+  TStopwatch timer;
+  fOutTrackHits = new Int_t[fNHitsTotal*10];
+  fOutTracks = new AliHLTTPCCAOutTrack[*fNTracks];
   fNOutTrackHits = 0;
   fNOutTracks = 0;
-
-  for( Int_t iTr=0; iTr<fNTracks; iTr++){
+  //cout<<"NTracks = "<<*fNTracks<<endl;
+  //cout<<"NHits = "<<fNHitsTotal<<endl;
+  for( Int_t iTr=0; iTr<*fNTracks; iTr++){
+    //cout<<"iTr = "<<iTr<<endl;
     AliHLTTPCCATrack &iTrack = fTracks[iTr];
     if( !iTrack.Alive() ) continue;
-    if( iTrack.NCells()<3 ) continue;      
+    if( iTrack.NHits()<3 ) continue;      
+    //cout<<10<<endl;
     AliHLTTPCCAOutTrack &out = fOutTracks[fNOutTracks];
     out.FirstHitRef() = fNOutTrackHits;
     out.NHits() = 0;
     out.OrigTrackID() = iTr;
     {
-      AliHLTTPCCAEndPoint &p0 = ID2Point(iTrack.PointID()[0]); 
-      AliHLTTPCCAEndPoint &p2 = ID2Point(iTrack.PointID()[1]); 
-      out.StartPoint() = p0.Param();
-      out.EndPoint() = p2.Param();
+      out.StartPoint() = iTrack.Param();
+      out.EndPoint() = iTrack.Param();
     }
-    AliHLTTPCCATrackParam &t = out.StartPoint();//SG!!!
-    AliHLTTPCCATrackParam t0 = t;
+    //cout<<11<<endl;
 
-    t.Chi2() = 0;
-    t.NDF() = -5;      
-    first = 1; // removed  bool in front  -> JT
-
-    Int_t iID = iTrack.FirstCellID();
+    Int_t iID = iTrack.FirstHitID();
     Int_t fNOutTrackHitsOld = fNOutTrackHits;
-    for( AliHLTTPCCACell *ic = &ID2Cell(iID); ic->Link()>=0; iID = ic->Link(), ic = &ID2Cell(iID) ){
-      //cout<<"itr="<<iTr<<", cell ="<<ID2IRow(iID)<<" "<<ID2ICell(iID)<<endl;
-      AliHLTTPCCARow &row = ID2Row(iID);
-      if( !t0.TransportToX( row.X() ) ) continue;
-      Int_t jHit = -1;
-      Float_t dy, dz, d = 1.e10;
-      for( Int_t iHit=0; iHit<ic->NHits(); iHit++ ){
-       AliHLTTPCCAHit &h = row.GetCellHit(*ic,iHit);
-
-       // check for wrong hits 
-       {
-         Float_t ddy = t0.GetY() - h.Y();
-         Float_t ddz = t0.GetZ() - h.Z();
-         Float_t dd = ddy*ddy+ddz*ddz;
-         if( dd<d ){
-           d = dd;
-           dy = ddy;
-           dz = ddz;
-           jHit = iHit;
-         }
-       }
-      }
-      if( jHit<0 ) continue;
-      AliHLTTPCCAHit &h = row.GetCellHit(*ic,jHit);
-      //if( dy*dy > 3.5*3.5*(/*t0.GetErr2Y() + */h.ErrY()*h.ErrY() ) ) continue;//SG!!!
-      //if( dz*dz > 3.5*3.5*(/*t0.GetErr2Z() + */h.ErrZ()*h.ErrZ() ) ) continue;
-      //if( !t0.Filter2( h.Y(), h.Z(), h.ErrY()*h.ErrY(), h.ErrZ()*h.ErrZ() ) ) continue;
-      
-      if( !t.TransportToX( row.X() ) ) continue;           
-
-      //* Update the track
-           
-         if( first ){
-           t.Cov()[ 0] = .5*.5;
-           t.Cov()[ 1] = 0;
-           t.Cov()[ 2] = .5*.5;
-           t.Cov()[ 3] = 0;
-           t.Cov()[ 4] = 0;
-           t.Cov()[ 5] = .2*.2;
-           t.Cov()[ 6] = 0;
-           t.Cov()[ 7] = 0;
-           t.Cov()[ 8] = 0;
-           t.Cov()[ 9] = .2*.2;
-           t.Cov()[10] = 0;
-           t.Cov()[11] = 0;
-           t.Cov()[12] = 0;
-           t.Cov()[13] = 0;
-           t.Cov()[14] = .2*.2;
-           t.Chi2() = 0;
-           t.NDF() = -5;
-         }
-
-      if( t.Filter2( h.Y(), h.Z(), h.ErrY()*h.ErrY(), h.ErrZ()*h.ErrZ() ) ) first = 0;
-      else continue;
-
-      fOutTrackHits[fNOutTrackHits] = h.ID();
+    //cout<<12<<" "<<iID<<" "<<iTrack.NHits()<<endl;
+    for( Int_t ith=0; ith<iTrack.NHits(); ith++ ){
+      //cout<<ith<<":"<<endl;
+      Int_t ic = (fTrackHits[iID+ith]);
+      //cout<<ic<<endl;
+      AliHLTTPCCARow &row = ID2Row(ic);
+      Int_t ih = ID2IHit(ic);
+      //cout<<"write row,hit="<<ID2IRow(ic)<<" "<<ih<<endl;
+      fOutTrackHits[fNOutTrackHits] = fHitsID[row.FirstHit()+ih];
       fNOutTrackHits++;
-      if( fNOutTrackHits>fNHitsTotal ){
+      //cout<<"ok"<<endl;
+      if( fNOutTrackHits>fNHitsTotal*10 ){
        cout<<"fNOutTrackHits>fNHitsTotal"<<endl;
        exit(0);//SG!!!
        return;
       }
-      out.NHits()++;
+      out.NHits()++;      
     }
+    //cout<<13<<endl;
     //cout<<fNOutTracks<<": itr = "<<iTr<<", n outhits = "<<out.NHits()<<endl;
-    if( out.NHits() > 3 ){
+    if( out.NHits() >= 2 ){
       fNOutTracks++;
-#ifdef DRAW
-      AliHLTTPCCADisplay::Instance().DrawTrack( iTrack );
-      cout<<"out track "<<(fNOutTracks-1)<<", orig = "<<iTr<<", nhits="<<out.NHits()<<endl;
-      AliHLTTPCCADisplay::Instance().Ask();    
-#endif
-      
     }else {
       fNOutTrackHits = fNOutTrackHitsOld;
     }
   }
-  //cout<<"end writing"<<endl;
-  timer7.Stop();  
-  fTimers[7] = timer7.CpuTime();
-
-#ifdef DRAW
-  AliHLTTPCCADisplay::Instance().Ask();
-  //AliHLTTPCCADisplay::Instance().DrawMCTracks(fParam.fISec);
-  //AliHLTTPCCADisplay::Instance().Update();
-  //AliHLTTPCCADisplay::Instance().Ask();
-#endif 
+  timer.Stop();
+  fTimers[5]+=timer.CpuTime();
 }
 
+GPUh() void AliHLTTPCCATracker::FitTrackFull( AliHLTTPCCATrack &/**/, Float_t * /**/ ) const 
+{  
+  // fit track with material
+#ifdef XXX    
+  //* Fit the track   
+  FitTrack( iTrack, tt0 );
+  if( iTrack.NHits()<=3 ) return;
+    
+  AliHLTTPCCATrackParam &t = iTrack.Param();
+  AliHLTTPCCATrackParam t0 = t;
+
+  t.Chi2() = 0;
+  t.NDF() = -5;        
+  Bool_t first = 1;
+
+  Int_t iID = iTrack.FirstHitID();
+  for( Int_t ih=0; ih<iTrack.NHits(); ih++, iID++ ){
+    Int_t *ic = &(fTrackHits[iID]);
+    Int_t iRow = ID2IRow(*ic);
+    AliHLTTPCCARow &row = fRows[iRow];      
+    if( !t0.TransportToX( row.X() ) ) continue;      
+    Float_t dy, dz;
+    AliHLTTPCCAHit &h = ID2Hit(*ic);
+
+    // check for wrong hits    
+    if(0){
+      dy = t0.GetY() - h.Y();
+      dz = t0.GetZ() - h.Z();
+      
+      //if( dy*dy > 3.5*3.5*(/*t0.GetErr2Y() + */h.ErrY()*h.ErrY() ) ) continue;//SG!!!
+      //if( dz*dz > 3.5*3.5*(/*t0.GetErr2Z() + */h.ErrZ()*h.ErrZ() ) ) continue;      
+    }
 
-void AliHLTTPCCATracker::FitTrack( AliHLTTPCCATrack &track, Float_t t0[] ) const 
-{      
-  //* Fit the track 
-
-  AliHLTTPCCAEndPoint &p0 = ID2Point(track.PointID()[0]);      
-  AliHLTTPCCAEndPoint &p2 = ID2Point(track.PointID()[1]);      
-  AliHLTTPCCACell &c0 = ID2Cell(p0.CellID());  
-  AliHLTTPCCACell &c1 = ID2Cell(track.CellID()[1]);    
-  AliHLTTPCCACell &c2 = ID2Cell(p2.CellID());  
-  AliHLTTPCCARow &row0 = ID2Row(p0.CellID());
-  AliHLTTPCCARow &row1 = ID2Row(track.CellID()[1]);
-  AliHLTTPCCARow &row2 = ID2Row(p2.CellID());
+    if( !t.TransportToX( row.X() ) ) continue;  
 
+    //* Update the track
+           
+    if( first ){
+      t.Cov()[ 0] = .5*.5;
+      t.Cov()[ 1] = 0;
+      t.Cov()[ 2] = .5*.5;
+      t.Cov()[ 3] = 0;
+      t.Cov()[ 4] = 0;
+      t.Cov()[ 5] = .2*.2;
+      t.Cov()[ 6] = 0;
+      t.Cov()[ 7] = 0;
+      t.Cov()[ 8] = 0;
+      t.Cov()[ 9] = .2*.2;
+      t.Cov()[10] = 0;
+      t.Cov()[11] = 0;
+      t.Cov()[12] = 0;
+      t.Cov()[13] = 0;
+      t.Cov()[14] = .2*.2;
+      t.Chi2() = 0;
+      t.NDF() = -5;
+    }
+    Float_t err2Y, err2Z;
+    GetErrors2( iRow, t, err2Y, err2Z );
+
+    if( !t.Filter2( h.Y(), h.Z(), err2Y, err2Z ) ) continue;
+
+    first = 0;      
+  }  
+  /*
+  Float_t cosPhi = iTrack.Param().GetCosPhi();
+  p0.Param().TransportToX(ID2Row( iTrack.PointID()[0] ).X());
+  p2.Param().TransportToX(ID2Row( iTrack.PointID()[1] ).X());  
+  if( p0.Param().GetCosPhi()*cosPhi<0 ){ // change direction
+  Float_t *par = p0.Param().Par();
+  Float_t *cov = p0.Param().Cov();
+  par[2] = -par[2]; // sin phi
+  par[3] = -par[3]; // DzDs
+    par[4] = -par[4]; // kappa
+    cov[3] = -cov[3];
+    cov[4] = -cov[4];
+    cov[6] = -cov[6];
+    cov[7] = -cov[7];
+    cov[10] = -cov[10];
+    cov[11] = -cov[11];
+    p0.Param().CosPhi() = -p0.Param().GetCosPhi();
+  }
+  */
+#endif
+}
 
+GPUh() void AliHLTTPCCATracker::FitTrack( AliHLTTPCCATrack &/*track*/, Float_t */*t0[]*/ ) const 
+{      
+  //* Fit the track   
+#ifdef XXX
+  AliHLTTPCCAEndPoint &p2 = ID2Point(track.PointID()[1]);
+  AliHLTTPCCAHit &c0 = ID2Hit(fTrackHits[p0.TrackHitID()].HitID());    
+  AliHLTTPCCAHit &c1 = ID2Hit(fTrackHits[track.HitID()[1]].HitID());   
+  AliHLTTPCCAHit &c2 = ID2Hit(fTrackHits[p2.TrackHitID()].HitID());    
+  AliHLTTPCCARow &row0 = ID2Row(fTrackHits[p0.TrackHitID()].HitID());
+  AliHLTTPCCARow &row1 = ID2Row(fTrackHits[track.HitID()[1]].HitID());
+  AliHLTTPCCARow &row2 = ID2Row(fTrackHits[p2.TrackHitID()].HitID());
   Float_t sp0[5] = {row0.X(), c0.Y(), c0.Z(), c0.ErrY(), c0.ErrZ() };
   Float_t sp1[5] = {row1.X(), c1.Y(), c1.Z(), c1.ErrY(), c1.ErrZ() };
   Float_t sp2[5] = {row2.X(), c2.Y(), c2.Z(), c2.ErrY(), c2.ErrZ() };
-  if( track.NCells()>=3 ){
+  //cout<<"Fit track, points ="<<sp0[0]<<" "<<sp0[1]<<" / "<<sp1[0]<<" "<<sp1[1]<<" / "<<sp2[0]<<" "<<sp2[1]<<endl;
+  if( track.NHits()>=3 ){    
     p0.Param().ConstructXYZ3(sp0,sp1,sp2,p0.Param().CosPhi(), t0);
     p2.Param().ConstructXYZ3(sp2,sp1,sp0,p2.Param().CosPhi(), t0);
     //p2.Param() = p0.Param();
@@ -1162,4 +746,39 @@ void AliHLTTPCCATracker::FitTrack( AliHLTTPCCATrack &track, Float_t t0[] ) const
     p2.Param().Err2Y() = c2.ErrY()*c2.ErrY();
     p2.Param().Err2Z() = c2.ErrZ()*c2.ErrZ();
   }
+#endif
+}
+
+
+
+GPUd() void AliHLTTPCCATracker::GetErrors2( Int_t iRow, const AliHLTTPCCATrackParam &t, Float_t &Err2Y, Float_t &Err2Z ) const
+{
+  //
+  // 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 ;
+
+  Err2Y = fParam.GetClusterError2(0,type, z,angleY);  
+  Err2Z = fParam.GetClusterError2(1,type, z,angleZ);
+}
+
+GPUd() void AliHLTTPCCATracker::GetErrors2( Int_t iRow, const AliHLTTPCCATrackParam1 &t, Float_t &Err2Y, Float_t &Err2Z ) const
+{
+  //
+  // 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 ;
+
+  Err2Y = fParam.GetClusterError2(0,type, z,angleY);  
+  Err2Z = fParam.GetClusterError2(1,type, z,angleZ);
 }
index f9d5035426114871fb393363f87ec5545aeb5d74..549c88ad3da11484d0d2052f76d9c74867be9ce3 100644 (file)
@@ -9,16 +9,17 @@
 #define ALIHLTTPCCATRACKER_H
 
 
-#include "Rtypes.h"
+#include "AliHLTTPCCADef.h"
 #include "AliHLTTPCCAParam.h"
 #include "AliHLTTPCCARow.h"
+#include "AliHLTTPCCAHit.h"
 
 class AliHLTTPCCATrack;
-class AliHLTTPCCAHit;
-class AliHLTTPCCACell;
 class AliHLTTPCCAOutTrack;
 class AliHLTTPCCATrackParam;
-class AliHLTTPCCAEndPoint;
+class AliHLTTPCCATrackParam1;
+
+
 
 /**
  * @class AliHLTTPCCATracker
@@ -36,79 +37,122 @@ class AliHLTTPCCATracker
 {
  public:
 
+#if !defined(HLTCA_GPUCODE)  
   AliHLTTPCCATracker();
   AliHLTTPCCATracker( const AliHLTTPCCATracker& );
   AliHLTTPCCATracker &operator=( const AliHLTTPCCATracker& );
 
-  virtual ~AliHLTTPCCATracker();
+  GPUd() ~AliHLTTPCCATracker();
+#endif
 
-  void Initialize( AliHLTTPCCAParam &param );
+  GPUd() void Initialize( AliHLTTPCCAParam &param );
 
-  void StartEvent();
+  GPUd() void StartEvent();
 
-  void ReadHitRow( Int_t iRow, AliHLTTPCCAHit *Row, Int_t NHits );
+  GPUd() void ReadEvent( Int_t *RowFirstHit, Int_t *RowNHits, Float_t *Y, Float_t *Z, Int_t NHits );
 
   void Reconstruct();
 
-  void FindCells();
-  void MergeCells();
-  void FindTracks();
+  void WriteOutput();
+
+  GPUd() void GetErrors2( Int_t iRow,  const AliHLTTPCCATrackParam &t, Float_t &Err2Y, Float_t &Err2Z ) const;
+  GPUd() void GetErrors2( Int_t iRow,  const AliHLTTPCCATrackParam1 &t, Float_t &Err2Y, Float_t &Err2Z ) const;
 
-  AliHLTTPCCAParam &Param(){ return fParam; }
-  AliHLTTPCCARow *Rows(){ return fRows; }
+  GPUhd() AliHLTTPCCAParam &Param(){ return fParam; }
+  GPUhd() AliHLTTPCCARow *Rows(){ return fRows; }
+
+  Int_t * HitsID(){ return fHitsID; }
 
   Int_t *OutTrackHits(){ return  fOutTrackHits; }
   Int_t NOutTrackHits() const { return  fNOutTrackHits; }
-  AliHLTTPCCAOutTrack *OutTracks(){ return  fOutTracks; }
-  Int_t NOutTracks() const { return  fNOutTracks; }
+  GPUd() AliHLTTPCCAOutTrack *OutTracks(){ return  fOutTracks; }
+  GPUd() Int_t NOutTracks() const { return  fNOutTracks; }
+  GPUhd() Int_t *TrackHits(){ return fTrackHits; }
 
-  AliHLTTPCCATrack *Tracks(){ return  fTracks; }
-  Int_t NTracks() const { return fNTracks; }
+  GPUhd() AliHLTTPCCATrack *Tracks(){ return  fTracks; }
+  GPUhd() Int_t &NTracks()  { return *fNTracks; }
 
   Double_t *Timers(){ return fTimers; }
 
-  static Int_t IRowICell2ID( Int_t iRow, Int_t iCell ){ 
-    return (iCell<<8)+iRow; 
+  GPUhd() static Int_t IRowIHit2ID( Int_t iRow, Int_t iHit ){ 
+    return (iHit<<8)+iRow; 
   }
-  static Int_t ID2IRow( Int_t CellID ){ 
-    return ( CellID%256 ); 
+  GPUhd() static Int_t ID2IRow( Int_t HitID ){ 
+    return ( HitID%256 ); 
   }
-  static Int_t ID2ICell( Int_t CellID ){ 
-    return ( CellID>>8 ); 
+  GPUhd() static Int_t ID2IHit( Int_t HitID ){ 
+    return ( HitID>>8 ); 
   }  
-  AliHLTTPCCACell &ID2Cell( Int_t CellID ) const{
-    return fRows[CellID%256].Cells()[CellID>>8];
+
+  GPUhd() AliHLTTPCCAHit &ID2Hit( Int_t HitID ) {
+    return fHits[fRows[HitID%256].FirstHit() + (HitID>>8)];
   }
-  AliHLTTPCCARow &ID2Row( Int_t CellID ) const{
-    return fRows[CellID%256];
+  GPUhd() AliHLTTPCCARow &ID2Row( Int_t HitID ) {
+    return fRows[HitID%256];
   }
   
-  AliHLTTPCCAEndPoint &ID2Point( Int_t PointID ) const{
-    return fRows[PointID%256].EndPoints()[PointID>>8];
-  }
-
   void FitTrack( AliHLTTPCCATrack &track, Float_t *t0 = 0 ) const;
+  void FitTrackFull( AliHLTTPCCATrack &track, Float_t *t0 = 0 ) const;
+  GPUhd() void SetPointers();
+
+  GPUhd() Short_t *HitLinkUp(){ return fHitLinkUp;}
+  GPUhd() Short_t *HitLinkDown(){ return fHitLinkDown;}
+  GPUhd() Int_t  *StartHits(){ return fStartHits;}
+  GPUhd() Int_t  *Tracklets(){ return fTracklets;}
+  GPUhd() Int_t  *HitIsUsed(){ return fHitIsUsed;}
+  GPUhd() AliHLTTPCCAHit *Hits(){ return fHits;}
+  GPUhd() Int_t &NHitsTotal(){ return fNHitsTotal;}
+  GPUhd() uint4 *&TexHitsFullData(){ return fTexHitsFullData;}
+  GPUhd() Int_t &TexHitsFullSize(){ return fTexHitsFullSize;}
+
+  GPUd() UChar_t GetGridContent( UInt_t i ) const; 
+  GPUd() AliHLTTPCCAHit GetHit( UInt_t i ) const;
+
+  private:
+  //  
 
- protected:
-  
   AliHLTTPCCAParam fParam; // parameters
+  AliHLTTPCCARow fRows[200];// array of hit rows
+  Double_t fTimers[10]; // running CPU time for different parts of the algorithm
+  
+  // event
+  Int_t fNHitsTotal;// total number of hits in event
+  Int_t fGridSizeTotal; // total grid size
+  Int_t fGrid1SizeTotal;// total grid1 size
 
-  AliHLTTPCCARow *fRows;// array of hit rows
+  AliHLTTPCCAHit *fHits; // hits
+  ushort2 *fHits1; // hits1
+  
+  UChar_t *fGridContents; // grid content
+  UInt_t *fGrid1Contents; // grid1 content
+  Int_t *fHitsID; // hit ID's
+  // temporary information
+  
+  Short_t *fHitLinkUp; // array of up links
+  Short_t *fHitLinkDown;// array of down links
+  Int_t *fHitIsUsed; // array of used flags
+  Int_t  *fStartHits;   // array of start hits
+  Int_t *fTracklets; // array of tracklets
 
-  Int_t *fOutTrackHits;  // output array of ID's of the reconstructed hits
+  Int_t *fNTracks;// number of reconstructed tracks
+  AliHLTTPCCATrack *fTracks;   // reconstructed tracks
+  Int_t *fTrackHits; // array of track hit numbers
+
+  // output
+
+  Int_t fNOutTracks; // number of tracks in fOutTracks array
   Int_t fNOutTrackHits;  // number of hits in fOutTrackHits array
   AliHLTTPCCAOutTrack *fOutTracks; // output array of the reconstructed tracks
-  Int_t fNOutTracks; // number of tracks in fOutTracks array
+  Int_t *fOutTrackHits;  // output array of ID's of the reconstructed hits
 
-  Int_t fNHitsTotal;// total number of hits in event
-  AliHLTTPCCATrack *fTracks;   // reconstructed tracks
-  Int_t fNTracks;// number of reconstructed tracks
-  Int_t *fCellHitPointers;// global array of cell->hit pointers
-  AliHLTTPCCACell *fCells;// global array of cells
-  AliHLTTPCCAEndPoint *fEndPoints;// global array of endpoints
-  Double_t fTimers[10]; // running CPU time for different parts of the algorithm
+  char *fEventMemory; // common event memory
+  UInt_t fEventMemSize; // size of the event memory
 
-  ClassDef(AliHLTTPCCATracker,1);
+  uint4 *fTexHitsFullData; // CUDA texture for hits
+  Int_t fTexHitsFullSize; // size of the CUDA texture
 };
 
+
 #endif
index 214d49bdbefd8051e8c74057ab8d27811c5fa39b..ba25d8e100cdf1c347b496ebc99b1d6cb2510f87 100644 (file)
 using namespace std;
 #endif
 
-#include <climits>
+//#include <climits>
 #include "AliHLTTPCCATrackerComponent.h"
 #include "AliHLTTPCTransform.h"
 #include "AliHLTTPCCATracker.h"
-#include "AliHLTTPCCAHit.h"
 #include "AliHLTTPCCAOutTrack.h"
 #include "AliHLTTPCCAParam.h"
 #include "AliHLTTPCCATrackConvertor.h"
@@ -46,6 +45,13 @@ using namespace std;
 #include "TStopwatch.h"
 #include "TMath.h"
 
+/** global object for registration 
+ * Matthias 2009-01-13 temporarily using the global object approach again.
+ * CA cade had to be disabled because of various compilation problems, so
+ * the global object approach fits better for the moment.
+ */
+AliHLTTPCCATrackerComponent gAliHLTTPCCATrackerComponent;
+
 /** ROOT macro for the implementation of ROOT specific class methods */
 ClassImp(AliHLTTPCCATrackerComponent)
 
@@ -148,10 +154,10 @@ int AliHLTTPCCATrackerComponent::DoInit( int argc, const char** argv )
 
   fFullTime = 0;
   fRecoTime = 0;
-  fNEvents = 0; 
+  fNEvents = 0;
 
   fTracker = new AliHLTTPCCATracker();
-
+  
   // read command line
 
   int i = 0;
@@ -287,8 +293,8 @@ int AliHLTTPCCATrackerComponent::DoEvent
  AliHLTUInt32_t& size, 
  vector<AliHLTComponentBlockData>& outputBlocks )
 {
-
-  AliHLTUInt32_t MaxBufferSize = size;
+ //* process event
+  AliHLTUInt32_t maxBufferSize = size;
   size = 0; // output size
 
   if(GetFirstInputBlock( kAliHLTDataTypeSOR ) || GetFirstInputBlock( kAliHLTDataTypeEOR )){    
@@ -375,7 +381,6 @@ int AliHLTTPCCATrackerComponent::DoEvent
 
   // Initialize the tracker
 
-  Float_t Bz = fSolenoidBz;
   
   {
     if( !fTracker ) fTracker = new AliHLTTPCCATracker;
@@ -397,19 +402,19 @@ int AliHLTTPCCATrackerComponent::DoEvent
     //TPCZmin = -249.645, ZMax = 249.778    
     //    Float_t rMin =  inRmin;
     //    Float_t rMax =  outRmax;
-    Int_t NRows = AliHLTTPCTransform::GetNRows();
+    Int_t nRows = AliHLTTPCTransform::GetNRows();
         
     Float_t padPitch = 0.4;
     Float_t sigmaZ = 0.228808;
     
-    Float_t *rowX = new Float_t [NRows];
-    for( Int_t irow=0; irow<NRows; irow++){
+    Float_t *rowX = new Float_t [nRows];
+    for( Int_t irow=0; irow<nRows; irow++){
       rowX[irow] = AliHLTTPCTransform::Row2X( irow );
     }     
      
     AliHLTTPCCAParam param;
-    param.Initialize( iSec, NRows, rowX, alpha, dalpha,
-                     inRmin, outRmax, zMin, zMax, padPitch, sigmaZ, Bz );
+    param.Initialize( iSec, nRows, rowX, alpha, dalpha,
+                     inRmin, outRmax, zMin, zMax, padPitch, sigmaZ, fSolenoidBz );
     param.YErrorCorrection() = 1;
     param.ZErrorCorrection() = 2;
     param.CellConnectionAngleXY() = fCellConnectionAngleXY/180.*TMath::Pi();
@@ -487,58 +492,46 @@ int AliHLTTPCCATrackerComponent::DoEvent
 
   sort( vOrigClusters, vOrigClusters+nClusters, CompareClusters );
 
-  AliHLTTPCCAHit *vHits = new AliHLTTPCCAHit [nHitsTotal]; // CA hit array
   Float_t *vHitStoreX = new Float_t [nHitsTotal];       // hit X coordinates
   Float_t *vHitStoreY = new Float_t [nHitsTotal];       // hit Y coordinates
   Float_t *vHitStoreZ = new Float_t [nHitsTotal];       // hit Z coordinates
+  Int_t *vHitStoreIntID = new Int_t [nHitsTotal];            // hit ID's
   Int_t *vHitStoreID = new Int_t [nHitsTotal];            // hit ID's
   Int_t *vHitRowID = new Int_t [nHitsTotal];            // hit ID's
 
   Int_t nHits = 0;
+
   {
+    Int_t rowNHits[200];
+    Int_t rowFirstHits[200];
+    for( Int_t ir=0; ir<200; ir++ ) rowNHits[ir] = 0;
     Int_t oldRow = -1;
-    Int_t nRowHits = 0;
-    Int_t firstRowHit = 0;
-
     for (Int_t i=0; i<nClusters; i++ ){
       AliHLTTPCSpacePointData* pSP = vOrigClusters[i];
-      if( pSP->fPadRow != oldRow ){
-       if( oldRow>=0 ){
-         if( fTracker->Rows()[oldRow].NHits()!=0 ) HLTError("CA: clusters from row %d are readed twice",oldRow);
-         fTracker->ReadHitRow( oldRow, vHits+firstRowHit, nRowHits );
-       }
-       oldRow = pSP->fPadRow;
-       firstRowHit = nHits;
-       nRowHits = 0;
-      }
-      AliHLTTPCCAHit &h = vHits[nHits];
-      //if( TMath::Abs(pSP->fX- fTracker->Rows()[pSP->fPadRow].X() )>1.e-4 ) cout<<"row "<<(Int_t)pSP->fPadRow<<" "<<fTracker->Rows()[pSP->fPadRow].X()-pSP->fX <<endl;
-      if( TMath::Abs(pSP->fX- fTracker->Rows()[pSP->fPadRow].X() )>1.e-4 ) HLTError( "row %d, %f",(Int_t)pSP->fPadRow, fTracker->Rows()[pSP->fPadRow].X()-pSP->fX );
-
-      h.Y() = pSP->fY;
-      h.Z() = pSP->fZ;
-      if( TMath::Abs(h.Z())>fClusterZCut) continue;
-      h.ErrY() = TMath::Sqrt(TMath::Abs(pSP->fSigmaY2));
-      h.ErrZ() = TMath::Sqrt(TMath::Abs(pSP->fSigmaZ2));  
-      if( h.ErrY()<.1 ) h.ErrY() = .1;
-      if( h.ErrZ()<.1 ) h.ErrZ() = .1;
-      if( h.ErrY()>1. ) h.ErrY() = 1.;
-      if( h.ErrZ()>1. ) h.ErrZ() = 1.;
-      h.ID() = nHits;
+      if( oldRow>=0 && pSP->fPadRow < oldRow )
+       HLTError("CA: clusters from row %d are readed twice",oldRow);      
+      
+      if( TMath::Abs(pSP->fZ)>fClusterZCut) continue;
+      
       vHitStoreX[nHits] = pSP->fX;  
-      vHitStoreY[nHits] = h.Y();
-      vHitStoreZ[nHits] = h.Z();
+      vHitStoreY[nHits] = pSP->fY;
+      vHitStoreZ[nHits] = pSP->fZ;
+      vHitStoreIntID[nHits] = nHits;
       vHitStoreID[nHits] = pSP->fID;
       vHitRowID[nHits] = pSP->fPadRow;
       nHits++; 
-      nRowHits++;
+      rowNHits[pSP->fPadRow]++;
     }  
-    if( oldRow>=0 ){
-      if( fTracker->Rows()[oldRow].NHits()!=0 ) HLTError("CA: clusters from row %d are readed twice",oldRow);
-      fTracker->ReadHitRow( oldRow, vHits+firstRowHit, nRowHits );
+
+    Int_t firstRowHit = 0;
+    for( Int_t ir=0; ir<200; ir++ ){
+      rowFirstHits[ir] = firstRowHit;
+      firstRowHit+=rowNHits[ir];
     }
+
+    fTracker->ReadEvent( rowFirstHits, rowNHits, vHitStoreY, vHitStoreZ, nHits );
   }
+
   if( vOrigClusters ) delete[] vOrigClusters;
 
   // reconstruct the event  
@@ -578,8 +571,8 @@ int AliHLTTPCCATrackerComponent::DoEvent
 
     UInt_t dSize = sizeof(AliHLTTPCTrackSegmentData) + t.NHits()*sizeof(UInt_t);
     
-    if( mySize + dSize > MaxBufferSize ){
-      Logging( kHLTLogWarning, "HLT::TPCCATracker::DoEvent", "Wrtite output","Output buffer size exceed (buffer size %d, current size %d), %d tracks are not stored", MaxBufferSize, mySize, ntracks-itr+1);
+    if( mySize + dSize > maxBufferSize ){
+      Logging( kHLTLogWarning, "HLT::TPCCATracker::DoEvent", "Wrtite output","Output buffer size exceed (buffer size %d, current size %d), %d tracks are not stored", maxBufferSize, mySize, ntracks-itr+1);
       ret = -ENOSPC;
       break;
     }
@@ -599,7 +592,7 @@ int AliHLTTPCCATrackerComponent::DoEvent
 
     AliHLTTPCCATrackParam par = t.StartPoint();
 
-    par.TransportToX( vHitStoreX[iFirstHit] );
+    par.TransportToX( vHitStoreX[iFirstHit], .99 );
 
     AliExternalTrackParam tp;
     AliHLTTPCCATrackConvertor::GetExtParam( par, tp, 0, fSolenoidBz );
@@ -607,7 +600,7 @@ int AliHLTTPCCATrackerComponent::DoEvent
     currOutTracklet->fX = tp.GetX();
     currOutTracklet->fY = tp.GetY();
     currOutTracklet->fZ = tp.GetZ();
-    currOutTracklet->fCharge = -(Int_t ) tp.GetSign();
+    currOutTracklet->fCharge = (Int_t ) tp.GetSign();
     currOutTracklet->fPt = TMath::Abs(tp.GetSignedPt());
     Float_t snp =  tp.GetSnp() ;
     if( snp>.999 ) snp=.999;
@@ -623,7 +616,7 @@ int AliHLTTPCCATrackerComponent::DoEvent
     currOutTracklet->fPsierr = h*h*tp.GetSigmaSnp2();
     currOutTracklet->fTglerr = tp.GetSigmaTgl2();
     
-    if( par.TransportToX( vHitStoreX[iLastHit] ) ){     
+    if( par.TransportToX( vHitStoreX[iLastHit],.99 ) ){     
       currOutTracklet->fLastX = par.GetX();
       currOutTracklet->fLastY = par.GetY();
       currOutTracklet->fLastZ = par.GetZ();
@@ -658,10 +651,10 @@ int AliHLTTPCCATrackerComponent::DoEvent
     outPtr->fTrackletCnt++; 
   }
 
-  if( vHits ) delete[] vHits;
   if( vHitStoreX ) delete[] vHitStoreX;
   if( vHitStoreY ) delete[] vHitStoreY;
   if( vHitStoreZ ) delete[] vHitStoreZ;
+  if( vHitStoreIntID ) delete[] vHitStoreIntID;
   if( vHitStoreID ) delete[] vHitStoreID;
   if( vHitRowID ) delete[] vHitRowID;
   
@@ -688,7 +681,6 @@ int AliHLTTPCCATrackerComponent::DoEvent
           slice, ntracks, nClusters, minPatch, maxPatch, row[0], row[1], hz, hz1 );
 
   return ret;
-
 }
 
        
index d65b9234ed77ba914996fdf2e400290018e05842..eeb1d7294057e10c90b81deeedacd06d8fdedf86 100644 (file)
@@ -35,19 +35,19 @@ public:
   // Public functions to implement AliHLTComponent's interface.
   // These functions are required for the registration process
   
-  /** @see component interface AliHLTComponent::GetComponentID */
+  /** @see component interface @ref AliHLTComponent::GetComponentID */
   const char* GetComponentID() ;
   
-  /** @see component interface AliHLTComponent::GetInputDataTypes */
+  /** @see component interface @ref AliHLTComponent::GetInputDataTypes */
   void GetInputDataTypes( vector<AliHLTComponentDataType>& list)  ;
   
-  /** @see component interface AliHLTComponent::GetOutputDataType */
+  /** @see component interface @ref AliHLTComponent::GetOutputDataType */
   AliHLTComponentDataType GetOutputDataType() ;
 
-  /** @see component interface AliHLTComponent::GetOutputDataSize */
+  /** @see component interface @ref AliHLTComponent::GetOutputDataSize */
   virtual void GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) ;
 
-  /** @see component interface AliHLTComponent::Spawn */
+  /** @see component interface @ref AliHLTComponent::Spawn */
   AliHLTComponent* Spawn() ;
 
 protected:
@@ -56,10 +56,10 @@ protected:
   // These functions provide initialization as well as the actual processing
   // capabilities of the component. 
   
-  /** @see component interface AliHLTComponent::DoInit */
+  /** @see component interface @ref AliHLTComponent::DoInit */
   int DoInit( int argc, const char** argv );
   
-  /** @see component interface AliHLTComponent::DoDeinit */
+  /** @see component interface @ref AliHLTComponent::DoDeinit */
   int DoDeinit();
   
   /** @see component interface @ref AliHLTProcessor::DoEvent */
diff --git a/HLT/TPCLib/tracking-ca/AliHLTTPCCATrackletConstructor.cxx b/HLT/TPCLib/tracking-ca/AliHLTTPCCATrackletConstructor.cxx
new file mode 100644 (file)
index 0000000..06a7f68
--- /dev/null
@@ -0,0 +1,472 @@
+// @(#) $Id: AliHLTTPCCATrackletConstructor.cxx 27042 2008-07-02 12:06:02Z richterm $
+//***************************************************************************
+// This file is property of and copyright by the ALICE HLT Project          * 
+// ALICE Experiment at CERN, All rights reserved.                           *
+//                                                                          *
+// Primary Authors: Sergey Gorbunov <sergey.gorbunov@kip.uni-heidelberg.de> *
+//                  Ivan Kisel <kisel@kip.uni-heidelberg.de>                *
+//                  for The ALICE HLT Project.                              *
+//                                                                          *
+// Permission to use, copy, modify and distribute this software and its     *
+// documentation strictly for non-commercial purposes is hereby granted     *
+// without fee, provided that the above copyright notice appears in all     *
+// copies and that both the copyright notice and this permission notice     *
+// appear in the supporting documentation. The authors make no claims       *
+// about the suitability of this software for any purpose. It is            *
+// provided "as is" without express or implied warranty.                    *
+//***************************************************************************
+
+#include "AliHLTTPCCATracker.h"
+#include "AliHLTTPCCATrackParam.h"
+#include "AliHLTTPCCATrackParam1.h"
+#include "AliHLTTPCCAGrid.h"
+#include "AliHLTTPCCAHitArea.h"
+#include "AliHLTTPCCAMath.h"
+#include "AliHLTTPCCADef.h"
+#include "AliHLTTPCCATrackletConstructor.h"
+
+//GPUd() void myprintf1(int i, int j){
+  //printf("fwd: iS=%d, iRow=%d\n",i,j);
+//}
+//GPUd() void myprintf2(int i, int j){
+  //printf("bck: iS=%d, iRow=%d\n",i,j);
+//}
+
+
+GPUd() void AliHLTTPCCATrackletConstructor::Step0 
+( Int_t nBlocks, Int_t /*nThreads*/, Int_t iBlock, Int_t iThread, Int_t /*iSync*/,
+  AliHLTTPCCASharedMemory &s, AliHLTTPCCAThreadMemory &r, AliHLTTPCCATracker &tracker, AliHLTTPCCATrackParam1 &/*tParam*/ )
+{
+  // reconstruction of tracklets, step 0
+  
+  const Int_t kNMemThreads = 128;
+  
+  r.fIsMemThread = ( iThread<kNMemThreads );
+  if( iThread==0 ){    
+    int nTracks = tracker.StartHits()[0];
+    if(iBlock==0) *tracker.Tracklets() = nTracks;
+    int nTrPerBlock = nTracks/nBlocks+1;
+    s.fNRows = tracker.Param().NRows();
+    s.fItr0 = nTrPerBlock*iBlock;
+    s.fItr1 = s.fItr0 + nTrPerBlock;
+    if( s.fItr1> nTracks ) s.fItr1 = nTracks;
+    s.fUsedHits = tracker.HitIsUsed();
+    s.fMinStartRow = 158;
+    s.fMaxStartRow = 0;
+  }
+  if( iThread<32 ){
+    s.fMinStartRow32[iThread] = 158;    
+    s.fMaxStartRow32[iThread] = 0;
+  }
+}
+
+
+GPUd() void AliHLTTPCCATrackletConstructor::Step1 
+( Int_t /*nBlocks*/, Int_t /*nThreads*/, Int_t /*iBlock*/, Int_t iThread, Int_t /*iSync*/,
+  AliHLTTPCCASharedMemory &s, AliHLTTPCCAThreadMemory &r, AliHLTTPCCATracker &tracker, AliHLTTPCCATrackParam1 &tParam )
+{
+  // reconstruction of tracklets, step 1
+
+  const Int_t kNMemThreads = 128;
+
+  r.fItr= s.fItr0 + ( iThread - kNMemThreads ); 
+  r.fGo = (!r.fIsMemThread) && ( r.fItr<s.fItr1 );
+  r.fSave = r.fGo;
+  r.fNHits=0;
+  
+  if( !r.fGo ) return;
+  
+  r.fStage = 0;
+  
+  r.fTrackStoreOffset = 1 + r.fItr*(5+ sizeof(AliHLTTPCCATrackParam)/4 + 160 );
+  r.fHitStoreOffset = r.fTrackStoreOffset + 5+ sizeof(AliHLTTPCCATrackParam)/4 ;
+  
+  int *hitstore = tracker.Tracklets() +r.fHitStoreOffset;
+  
+  UInt_t kThread = iThread %32;//& 00000020;
+  if( SAVE() ) for( int i=0; i<160; i++ ) hitstore[i] = -1;
+  
+  int id = tracker.StartHits()[1 + r.fItr];
+  r.fFirstRow = AliHLTTPCCATracker::ID2IRow(id);
+  r.fCurrIH =  AliHLTTPCCATracker::ID2IHit(id);
+  CAMath::atomicMin( &s.fMinStartRow32[kThread], r.fFirstRow);    
+  CAMath::atomicMax( &s.fMaxStartRow32[kThread], r.fFirstRow);    
+  tParam.SinPhi() = 0;
+  tParam.DzDs() = 0; 
+  tParam.Kappa() = 0;
+  tParam.CosPhi() = 1;
+  tParam.Chi2() = 0;
+  tParam.NDF() = -3;      
+  
+  tParam.Cov()[1] = 0;
+  tParam.Cov()[4] = 0;
+  tParam.Cov()[8] = 0;
+  tParam.Cov()[13] = 0;
+  
+  tParam.Cov()[3] = 0;
+  tParam.Cov()[5] = 1.;
+  tParam.Cov()[7] = 0;
+  tParam.Cov()[9] = 1.;
+  tParam.Cov()[10] = 0;
+  tParam.Cov()[12] = 0;
+  tParam.Cov()[14] = 1.;
+  r.fLastRow = r.fFirstRow;
+}
+
+GPUd() void AliHLTTPCCATrackletConstructor::Step2 
+( Int_t /*nBlocks*/, Int_t /*nThreads*/, Int_t /*iBlock*/, Int_t iThread, Int_t /*iSync*/,
+  AliHLTTPCCASharedMemory &s, AliHLTTPCCAThreadMemory &/*r*/, AliHLTTPCCATracker &/*tracker*/, AliHLTTPCCATrackParam1 &/*tParam*/ )
+{  
+  // reconstruction of tracklets, step 2
+  if( iThread==0 ){
+    //CAMath::atomicMinGPU(&s.fMinRow, s.fMinRow32[iThread]);
+    int minStartRow = 158;
+    int maxStartRow = 0;
+    for( int i=0; i<32; i++ ){      
+      if( s.fMinStartRow32[i]<minStartRow ) minStartRow = s.fMinStartRow32[i];
+      if( s.fMaxStartRow32[i]>maxStartRow ) maxStartRow = s.fMaxStartRow32[i];
+    }   
+    s.fMinStartRow = minStartRow;
+    s.fMaxStartRow = maxStartRow;
+  }
+}
+
+GPUd() void AliHLTTPCCATrackletConstructor::ReadData 
+( Int_t iThread, AliHLTTPCCASharedMemory &s, AliHLTTPCCAThreadMemory &r, AliHLTTPCCATracker &tracker, Int_t iRow )
+{  
+
+  // reconstruction of tracklets, read data step
+  const Int_t kNMemThreads = 128;
+  if( r.fIsMemThread ){
+    AliHLTTPCCARow &row = tracker.Rows()[iRow];
+    bool jr = !r.fCurrentData;
+    Int_t n = row.FullSize();
+    uint4* gMem = tracker.TexHitsFullData() + row.FullOffset();
+    uint4 *sMem = s.fData[jr];
+    for( int i=iThread; i<n; i+=kNMemThreads ) sMem[i] = gMem[i];
+  }
+}
+
+
+GPUd() void AliHLTTPCCATrackletConstructor::UnpackGrid 
+( Int_t /*nBlocks*/, Int_t nThreads, Int_t /*iBlock*/, Int_t iThread, Int_t /*iSync*/,
+  AliHLTTPCCASharedMemory &s, AliHLTTPCCAThreadMemory &r, AliHLTTPCCATracker &tracker, AliHLTTPCCATrackParam1 &/*tParam*/,Int_t iRow )
+{
+  // reconstruction of tracklets, grid unpacking step
+
+  AliHLTTPCCARow &row = tracker.Rows()[iRow];
+  int n = row.Grid().N()+1;
+  int nY = row.Grid().Ny();
+  uint4 *tmpint4 = s.fData[r.fCurrentData];
+  UShort_t *sGridP = (reinterpret_cast<UShort_t*>(tmpint4)) + row.FullGridOffset();
+  
+  UInt_t *sGrid = s.fGridContent1;      
+
+  for( int i=iThread; i<n; i+=nThreads ){
+    UInt_t s0 = sGridP[i];
+    UInt_t e0 = sGridP[i+2];
+    UInt_t s1 = sGridP[i+nY];
+    UInt_t e1 = sGridP[i+nY+2];
+    UInt_t nh0 = e0-s0;
+    UInt_t nh1 = e1-s1;
+    sGrid[i] = (nh1<<26)+(s1<<16)+( nh0<<10 ) + s0;
+  }
+}
+
+
+GPUd() void AliHLTTPCCATrackletConstructor::StoreTracklet 
+( Int_t /*nBlocks*/, Int_t /*nThreads*/, Int_t /*iBlock*/, Int_t /*iThread*/, Int_t /*iSync*/,
+  AliHLTTPCCASharedMemory &/*s*/, AliHLTTPCCAThreadMemory &r, AliHLTTPCCATracker &tracker, AliHLTTPCCATrackParam1 &tParam )
+{    
+  // reconstruction of tracklets, tracklet store step
+
+  if( !r.fSave ) return;
+
+  do{ 
+    if( r.fNHits<10 ){ 
+      r.fNHits = 0;
+      break;
+    }
+    
+    {  
+      Bool_t ok=1;
+      Float_t *c = tParam.Cov();
+      for( int i=0; i<15; i++ ) ok = ok && CAMath::Finite(c[i]);
+      for( int i=0; i<5; i++ ) ok = ok && CAMath::Finite(tParam.Par()[i]);
+      ok = ok && (tParam.X()>50);
+      
+      if( c[0]<=0 || c[2]<=0 || c[5]<=0 || c[9]<=0 || c[14]<=0 ) ok = 0;      
+      
+      if(!ok){
+       r.fNHits = 0;
+       break; 
+      }
+    }   
+  }while(0);
+  if( !SAVE() ) return;
+    
+  int *store = tracker.Tracklets() + r.fTrackStoreOffset;
+  int *hitstore = tracker.Tracklets() +r.fHitStoreOffset;
+  store[0] = r.fNHits;
+  
+  if( r.fNHits>0 ){
+    store[3] = r.fFirstRow;
+    store[4] = r.fLastRow;   
+    if( CAMath::Abs(tParam.Par()[4])<1.e-8 ) tParam.Par()[4] = 1.e-8;
+    *((AliHLTTPCCATrackParam1*)(store+5)) = tParam;
+    int w = (r.fNHits<<16)+r.fItr;
+    for( int iRow=0; iRow<160; iRow++ ){
+      Int_t ih = hitstore[iRow];
+      if( ih>=0 ){
+       int ihTot = tracker.Rows()[iRow].FirstHit() + ih;
+       CAMath::atomicMax( tracker.HitIsUsed() + ihTot, w );
+      }
+    }
+  }  
+}
+
+GPUd() void AliHLTTPCCATrackletConstructor::UpdateTracklet
+( Int_t /*nBlocks*/, Int_t /*nThreads*/, Int_t /*iBlock*/, Int_t /*iThread*/, Int_t /*iSync*/,
+    AliHLTTPCCASharedMemory &s, AliHLTTPCCAThreadMemory &r, AliHLTTPCCATracker &tracker, AliHLTTPCCATrackParam1 &tParam,Int_t iRow )
+{
+  // reconstruction of tracklets, tracklets update step
+
+  if( !r.fGo ) return;
+         
+  const Int_t kMaxRowGap = 5;  
+  
+  int *hitstore = tracker.Tracklets() +r.fHitStoreOffset;
+  
+  AliHLTTPCCARow &row = tracker.Rows()[iRow];
+  
+  float y0 = row.Grid().YMin();
+  float stepY = row.HstepY();
+  float z0 = row.Grid().ZMin();
+  float stepZ = row.HstepZ();
+  float stepYi = row.HstepYi();
+  float stepZi = row.HstepZi();          
+  
+  if( r.fStage == 0 ){ // fitting part     
+    do{
+      
+      if( iRow<r.fFirstRow || r.fCurrIH<0  ) break;
+
+      uint4 *tmpint4 = s.fData[r.fCurrentData];   
+      ushort2 hh = reinterpret_cast<ushort2*>(tmpint4)[r.fCurrIH];
+      
+      Int_t oldIH = r.fCurrIH;
+      r.fCurrIH = reinterpret_cast<Short_t*>(tmpint4)[row.FullLinkOffset() + r.fCurrIH];         
+      
+      float x = row.X();
+      float y = y0 + hh.x*stepY;
+      float z = z0 + hh.y*stepZ;
+     
+      if( iRow==r.fFirstRow ){
+       tParam.X() = x;
+       tParam.Y() = y;
+       tParam.Z() = z;
+       float err2Y, err2Z;       
+       tracker.GetErrors2( iRow, tParam, err2Y, err2Z );
+       tParam.Cov()[0] = err2Y;
+       tParam.Cov()[2] = err2Z;
+      }else{       
+       if( !tParam.TransportToX0( x, .95 ) ){ 
+         if( SAVE() ) hitstore[iRow] = -1; 
+         break; 
+       }
+       float err2Y, err2Z;
+       tracker.GetErrors2( iRow, *((AliHLTTPCCATrackParam*)&tParam), err2Y, err2Z );
+       if( !tParam.Filter2( y, z, err2Y, err2Z, .95 ) ) { 
+         if( SAVE() ) hitstore[iRow] = -1; 
+         break; 
+       }          
+      }
+      if( SAVE() ) hitstore[iRow] = oldIH; 
+      r.fNHits++;
+      r.fLastRow = iRow;
+      if( r.fCurrIH<0 ){
+       r.fStage = 1;    
+       if( r.fNHits<3 ){ r.fNHits=0; r.fGo = 0;}
+      } 
+      break;
+    } while(0);
+  }
+  else // forward/backward searching part
+    {          
+      do{ 
+       if( r.fStage == 2 && iRow>=r.fFirstRow ) break; 
+       if( r.fNMissed>kMaxRowGap  ){ 
+         r.fGo = 0; 
+         break;
+       }
+       
+       r.fNMissed++;   
+       
+       float x = row.X();
+       float err2Y, err2Z;
+       if( !tParam.TransportToX0( x, .95 ) ) break;
+       uint4 *tmpint4 = s.fData[r.fCurrentData];   
+
+       ushort2 *hits = reinterpret_cast<ushort2*>(tmpint4);
+       UInt_t *gridContent1 = ((UInt_t*)(s.fGridContent1));
+       
+       float fY = tParam.GetY();
+       float fZ = tParam.GetZ();
+       Int_t best = -1;                
+       
+       { // search for the closest hit
+         
+         Int_t ds;
+         Int_t fY0 = (Int_t) ((fY - y0)*stepYi);
+         Int_t fZ0 = (Int_t) ((fZ - z0)*stepZi);
+         Int_t ds0 = ( ((int)1)<<30);
+         ds = ds0;
+         
+         UInt_t fIndYmin;
+         UInt_t fHitYfst=1, fHitYlst=0, fHitYfst1=1, fHitYlst1=0;
+         
+         fIndYmin = row.Grid().GetBin( (float)(fY-1.), (float)(fZ-1.) );
+         UInt_t c = gridContent1[fIndYmin];
+         fHitYfst = c & 0x000003FF;
+         fHitYlst = fHitYfst + ((c & 0x0000FC00)>>10);
+         fHitYfst1 = ( c & 0x03FF0000 )>>16;
+         fHitYlst1 = fHitYfst1 + ((c & 0xFC000000)>>26);         
+        
+         for( UInt_t fIh = fHitYfst; fIh<fHitYlst; fIh++ ){
+           ushort2 hh = hits[fIh];       
+           Int_t ddy = (Int_t)(hh.x) - fY0;
+           Int_t ddz = (Int_t)(hh.y) - fZ0;
+           Int_t dds = CAMath::mul24(ddy,ddy) + CAMath::mul24(ddz,ddz);
+           if( dds<ds ){
+             ds = dds;
+             best = fIh;
+           }                 
+         }
+                 
+         for( UInt_t fIh = fHitYfst1; fIh<fHitYlst1; fIh++ ){
+           ushort2 hh = hits[fIh];
+           Int_t ddy = (Int_t)(hh.x) - fY0;
+           Int_t ddz = (Int_t)(hh.y) - fZ0;
+           Int_t dds = CAMath::mul24(ddy,ddy) + CAMath::mul24(ddz,ddz);
+           if( dds<ds ){
+             ds = dds;
+             best = fIh;
+           }                         
+         }
+       }// end of search for the closest hit
+       
+       if( best<0 ) break;     
+       
+       ushort2 hh = hits[best];
+       
+       tracker.GetErrors2( iRow, *((AliHLTTPCCATrackParam*)&tParam), err2Y, err2Z );
+       
+       float y = y0 + hh.x*stepY;
+       float z = z0 + hh.y*stepZ;
+       float dy = y - fY;
+       float dz = z - fZ;        
+       
+       const Float_t kFactor = 3.5*3.5;
+       Float_t sy2 = kFactor*( tParam.GetErr2Y() +  err2Y );
+       Float_t sz2 = kFactor*( tParam.GetErr2Z() +  err2Z );
+       if( sy2 > 1. ) sy2 = 1.;
+       if( sz2 > 1. ) sz2 = 1.;
+       if( iRow==63 || iRow==64 || iRow==65 ){
+         if( sy2 < 4. ) sy2 = 4.;
+         if( sz2 < 4. ) sz2 = 4.;
+       }
+       
+       
+       if( CAMath::fmul_rz(dy,dy)>sy2 || CAMath::fmul_rz(dz,dz)>sz2  ) break;
+       
+       if( !tParam.Filter2( y, z, err2Y, err2Z, .95 ) ) break;
+
+       if( SAVE() ) hitstore[ iRow ] = best;
+       r.fNHits++;          
+       r.fNMissed=0;           
+      }while(0);
+    }
+}
+
+
+
+GPUd() void AliHLTTPCCATrackletConstructor::Thread
+( Int_t nBlocks, Int_t nThreads, Int_t iBlock, Int_t iThread, Int_t iSync,
+  AliHLTTPCCASharedMemory &s, AliHLTTPCCAThreadMemory &r, AliHLTTPCCATracker &tracker, AliHLTTPCCATrackParam1 &tParam )
+{    
+
+  // reconstruction of tracklets
+  if( iSync==0 )
+    {  
+      Step0( nBlocks, nThreads, iBlock, iThread, iSync, s, r, tracker, tParam );
+    }
+  else if( iSync==1 )
+    { 
+      Step1( nBlocks, nThreads, iBlock, iThread, iSync, s, r, tracker, tParam );
+    }
+  else if( iSync==2 )
+    {
+      Step2( nBlocks, nThreads, iBlock, iThread, iSync, s, r, tracker, tParam );
+    }
+  
+  else if( iSync==3 )
+    
+    {
+      r.fCurrentData = 1;
+      ReadData( iThread, s, r, tracker, s.fMinStartRow );
+      r.fCurrentData = 0;
+      r.fNMissed = 0;           
+    }
+  else if( iSync==3+159*2+1 )//322
+    
+    {
+      r.fCurrentData = 1;
+      Int_t nextRow = s.fMaxStartRow-1;
+      if( nextRow<0 ) nextRow = 0;
+      ReadData( iThread, s, r, tracker, nextRow );
+      r.fCurrentData = 0;
+      r.fNMissed = 0;           
+      r.fStage = 2;
+    }
+  
+  else if( iSync<=3+159*2+1+159*2 )
+    
+    {      
+      int iRow, nextRow;
+      if(  iSync<=3+159*2 ){
+       iRow = (iSync -4)/2;
+       //if( iBlock==0 && iThread==0 ) myprintf1(iSync,iRow);      
+       if( iRow < s.fMinStartRow ) return;
+       nextRow = iRow+1;
+       if( nextRow>158 ) nextRow = 158;
+      }else{
+       iRow = 158 - (iSync - 4-159*2-1)/2;
+       //if( iBlock==0 && iThread==0 ) myprintf2(iSync,iRow);      
+       if( iRow >= s.fMaxStartRow ) return;
+       nextRow = iRow-1;
+       if( nextRow<0 ) nextRow = 0;
+      }
+      
+      if( iSync%2==0 ){
+       UnpackGrid( nBlocks, nThreads, iBlock, iThread, iSync,
+                   s, r, tracker, tParam, iRow );    
+      }else{   
+       if( r.fIsMemThread ){
+         ReadData( iThread, s, r, tracker, nextRow );  
+       }else{
+         UpdateTracklet( nBlocks, nThreads, iBlock, iThread, iSync,
+                         s, r, tracker, tParam, iRow );
+       }
+       r.fCurrentData = !r.fCurrentData;
+      }      
+    }    
+  
+  else if( iSync== 4+159*4 +1+1 ) // 642
+    
+    {
+      StoreTracklet( nBlocks, nThreads, iBlock, iThread, iSync, //SG!!!
+                    s, r, tracker, tParam );
+    }
+}
+
diff --git a/HLT/TPCLib/tracking-ca/AliHLTTPCCATrackletConstructor.h b/HLT/TPCLib/tracking-ca/AliHLTTPCCATrackletConstructor.h
new file mode 100644 (file)
index 0000000..a2195d5
--- /dev/null
@@ -0,0 +1,113 @@
+//-*- Mode: C++ -*-
+
+//* 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 ALIHLTTPCCATRACKLETCONSTRUCTOR_H
+#define ALIHLTTPCCATRACKLETCONSTRUCTOR_H
+
+
+#include "AliHLTTPCCADef.h"
+
+/**
+ * @class AliHLTTPCCATrackletConstructor
+ * 
+ */
+class AliHLTTPCCATrackletConstructor
+{
+ public:
+
+  class   AliHLTTPCCASharedMemory
+    {
+      friend class AliHLTTPCCATrackletConstructor;
+    public:
+#if !defined(HLTCA_GPUCODE)
+      AliHLTTPCCASharedMemory()
+       : fItr0(0), fItr1(0), fNRows(0), fUsedHits(0), fMinStartRow(0), fMaxStartRow(0)
+      {}
+
+      AliHLTTPCCASharedMemory( const AliHLTTPCCASharedMemory& /*dummy*/) 
+       : fItr0(0), fItr1(0), fNRows(0), fUsedHits(0), fMinStartRow(0), fMaxStartRow(0)
+      {}
+      AliHLTTPCCASharedMemory& operator=(const AliHLTTPCCASharedMemory& /*dummy*/){ return *this; }
+#endif
+    protected:
+      uint4 fData[2][(500+500+500)/4]; // temp memory
+      UInt_t fGridContent1[600]; // grid1 content
+      int fItr0; // start track index
+      int fItr1; // end track index
+      int fNRows; // n rows
+      Int_t *fUsedHits;   // array of used hits
+      int fMinStartRow; // min start row
+      int fMinStartRow32[32]; // min start row for each thread in warp
+      int fMaxStartRow; // max start row
+      int fMaxStartRow32[32];// max start row for each thread in warp
+    };
+
+  class  AliHLTTPCCAThreadMemory
+    {
+      friend class AliHLTTPCCATrackletConstructor;
+     public:
+#if !defined(HLTCA_GPUCODE)
+      AliHLTTPCCAThreadMemory()
+       : fItr(0), fFirstRow(0), fLastRow(0), fCurrIH(0), fIsMemThread(0), fGo(0), fSave(0), fCurrentData(0), fStage(0), fNHits(0), fNMissed(0), fTrackStoreOffset(0), fHitStoreOffset(0) 
+      {}
+
+      AliHLTTPCCAThreadMemory( const AliHLTTPCCAThreadMemory& /*dummy*/) 
+       : fItr(0), fFirstRow(0), fLastRow(0), fCurrIH(0), fIsMemThread(0), fGo(0), fSave(0), fCurrentData(0), fStage(0), fNHits(0), fNMissed(0), fTrackStoreOffset(0), fHitStoreOffset(0) 
+      {}
+      AliHLTTPCCAThreadMemory& operator=(const AliHLTTPCCAThreadMemory& /*dummy*/){ return *this; }
+#endif
+    protected:
+      Int_t fItr; // track index
+      Int_t fFirstRow;  // first row index
+      Int_t fLastRow; // last row index
+      Int_t fCurrIH; // indef of the current hit
+      Bool_t fIsMemThread; // is the thread used for memory taken
+      Bool_t fGo; // do fit/searching flag
+      Bool_t fSave; // save flag
+      Bool_t fCurrentData; // index of the current memory array
+      Int_t fStage; // reco stage
+      Int_t fNHits; // n track hits
+      Int_t fNMissed; // n missed hits during search
+      Int_t fTrackStoreOffset; // offset in the global array
+      Int_t fHitStoreOffset;   // offset in the global array
+    };
+
+  GPUd() static Int_t NThreadSyncPoints(){ return 4+159*4 +1+1; }  
+
+  GPUd() static void Thread( Int_t nBlocks, Int_t nThreads, Int_t iBlock, Int_t iThread, 
+                            Int_t iSync, AliHLTTPCCASharedMemory &s, AliHLTTPCCAThreadMemory &r, 
+                            AliHLTTPCCATracker &tracker, AliHLTTPCCATrackParam1 &tParam );
+  
+  GPUd() static void Step0
+    ( Int_t nBlocks, Int_t nThreads, Int_t iBlock, Int_t iThread, Int_t iSync,
+      AliHLTTPCCASharedMemory &s, AliHLTTPCCAThreadMemory &r, AliHLTTPCCATracker &tracker, AliHLTTPCCATrackParam1 &tParam );
+  GPUd() static void Step1
+    ( Int_t nBlocks, Int_t nThreads, Int_t iBlock, Int_t iThread, Int_t iSync,
+      AliHLTTPCCASharedMemory &s, AliHLTTPCCAThreadMemory &r, AliHLTTPCCATracker &tracker, AliHLTTPCCATrackParam1 &tParam );
+  GPUd() static void Step2
+    ( Int_t nBlocks, Int_t nThreads, Int_t iBlock, Int_t iThread, Int_t iSync,
+      AliHLTTPCCASharedMemory &s, AliHLTTPCCAThreadMemory &r, AliHLTTPCCATracker &tracker, AliHLTTPCCATrackParam1 &tParam );
+
+  GPUd() static void ReadData( Int_t iThread, AliHLTTPCCASharedMemory &s, AliHLTTPCCAThreadMemory &r, AliHLTTPCCATracker &tracker, Int_t iRow );
+
+  GPUd() static void UpdateTracklet
+    ( Int_t nBlocks, Int_t nThreads, Int_t iBlock, Int_t iThread, Int_t iSync,
+      AliHLTTPCCASharedMemory &s, AliHLTTPCCAThreadMemory &r, AliHLTTPCCATracker &tracker, AliHLTTPCCATrackParam1 &tParam, Int_t iRow );
+
+  GPUd() static void UnpackGrid
+    ( Int_t nBlocks, Int_t nThreads, Int_t iBlock, Int_t iThread, Int_t iSync,
+      AliHLTTPCCASharedMemory &s, AliHLTTPCCAThreadMemory &r, AliHLTTPCCATracker &tracker, AliHLTTPCCATrackParam1 &tParam, Int_t iRow );
+
+  GPUd() static void StoreTracklet
+    ( Int_t nBlocks, Int_t nThreads, Int_t iBlock, Int_t iThread, Int_t iSync,
+      AliHLTTPCCASharedMemory &s, AliHLTTPCCAThreadMemory &r, AliHLTTPCCATracker &tracker, AliHLTTPCCATrackParam1 &tParam);
+
+  static Bool_t SAVE(){ return 1; }
+
+};
+
+
+#endif
diff --git a/HLT/TPCLib/tracking-ca/AliHLTTPCCATrackletSelector.cxx b/HLT/TPCLib/tracking-ca/AliHLTTPCCATrackletSelector.cxx
new file mode 100644 (file)
index 0000000..2794486
--- /dev/null
@@ -0,0 +1,80 @@
+// @(#) $Id: AliHLTTPCCATrackletSelector.cxx 27042 2008-07-02 12:06:02Z richterm $
+//***************************************************************************
+// This file is property of and copyright by the ALICE HLT Project          * 
+// ALICE Experiment at CERN, All rights reserved.                           *
+//                                                                          *
+// Primary Authors: Sergey Gorbunov <sergey.gorbunov@kip.uni-heidelberg.de> *
+//                  Ivan Kisel <kisel@kip.uni-heidelberg.de>                *
+//                  for The ALICE HLT Project.                              *
+//                                                                          *
+// Permission to use, copy, modify and distribute this software and its     *
+// documentation strictly for non-commercial purposes is hereby granted     *
+// without fee, provided that the above copyright notice appears in all     *
+// copies and that both the copyright notice and this permission notice     *
+// appear in the supporting documentation. The authors make no claims       *
+// about the suitability of this software for any purpose. It is            *
+// provided "as is" without express or implied warranty.                    *
+//***************************************************************************
+
+#include "AliHLTTPCCATrackletSelector.h"
+#include "AliHLTTPCCATrack.h"
+#include "AliHLTTPCCATracker.h"
+#include "AliHLTTPCCATrackParam.h"
+#include "AliHLTTPCCAMath.h"
+
+GPUd() void AliHLTTPCCATrackletSelector::Thread
+( Int_t nBlocks, Int_t nThreads, Int_t iBlock, Int_t iThread, Int_t iSync,
+  AliHLTTPCCASharedMemory &s, AliHLTTPCCATracker &tracker )
+{
+  // select best tracklets and kill clones
+
+  if( iSync==0 )
+    {
+      if( iThread==0 ){
+       if(iBlock==0){
+         CAMath::atomicExch(&(tracker.NTracks()),0);
+         CAMath::atomicExch(tracker.TrackHits(),0);
+       }
+       s.fNTracklets = tracker.Tracklets()[0];
+       s.fNThreadsTotal = nThreads*nBlocks;
+       s.fItr0 = nThreads*iBlock;
+       //if( iBlock==0 ) tracker.StartHits()[0] = 0;//SG!!!
+      }
+    }
+  else if( iSync==1 )
+    {
+      AliHLTTPCCATrack tout;
+      Int_t trackHits[160];
+       
+      for( Int_t itr= s.fItr0 + iThread; itr<s.fNTracklets; itr+=s.fNThreadsTotal ){                   
+       Int_t *t = tracker.Tracklets() + 1 + itr*(5+ sizeof(AliHLTTPCCATrackParam)/4 + 160 );   
+       Int_t tNHits = *t;
+       if( tNHits<=0 ) continue;
+       
+       CAMath::atomicAdd( tracker.StartHits(), 1);//SG!!!
+       tout.NHits() = 0;
+       Int_t *hitstore = t + 5+ sizeof(AliHLTTPCCATrackParam)/4 ;    
+       Int_t w = (tNHits<<16)+itr;     
+       Int_t nRows = tracker.Param().NRows();
+       for( Int_t irow=0; irow<nRows; irow++ ){
+         Int_t ih = hitstore[irow];
+         if( ih<0 ) continue;
+         AliHLTTPCCARow &row = tracker.Rows()[irow];
+         Int_t ihTot = row.FirstHit()+ih;      
+         if( tracker.HitIsUsed()[ihTot] > w ) continue;
+         Int_t th = AliHLTTPCCATracker::IRowIHit2ID(irow,ih);
+         trackHits[tout.NHits()] = th;
+         tout.NHits()++;
+       }       
+       if( tout.NHits()<10 ) continue;//SG!!!
+       Int_t itrout = CAMath::atomicAdd(&(tracker.NTracks()),1);
+       tout.FirstHitID() = CAMath::atomicAdd( tracker.TrackHits(), tout.NHits() ) + 1;
+       tout.Param() = *( (AliHLTTPCCATrackParam*)( t+5) );
+       tout.Alive() = 1;
+       tracker.Tracks()[itrout] = tout;
+       for( Int_t ih=0; ih<tout.NHits(); ih++ ){//SG
+         tracker.TrackHits()[tout.FirstHitID() + ih] = trackHits[ih];
+       }
+      }
+    }
+}
diff --git a/HLT/TPCLib/tracking-ca/AliHLTTPCCATrackletSelector.h b/HLT/TPCLib/tracking-ca/AliHLTTPCCATrackletSelector.h
new file mode 100644 (file)
index 0000000..7444162
--- /dev/null
@@ -0,0 +1,38 @@
+//-*- Mode: C++ -*-
+
+//* 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 ALIHLTTPCCATRACKLETSELECTOR_H
+#define ALIHLTTPCCATRACKLETSELECTOR_H
+
+
+#include "AliHLTTPCCADef.h"
+class AliHLTTPCCATracker;
+
+/**
+ * @class AliHLTTPCCATrackletSelector
+ * 
+ */
+class AliHLTTPCCATrackletSelector
+{
+ public:
+  class AliHLTTPCCASharedMemory
+    {
+      friend class AliHLTTPCCATrackletSelector;
+    protected:
+      Int_t fItr0; // index of the first track in the block
+      Int_t fNThreadsTotal; // total n threads
+      Int_t fNTracklets; // n of tracklets
+    };
+
+  GPUd() static Int_t NThreadSyncPoints(){ return 1; }  
+  
+  GPUd() static void Thread( Int_t nBlocks, Int_t nThreads, Int_t iBlock, Int_t iThread, Int_t iSync,
+                            AliHLTTPCCASharedMemory &smem, AliHLTTPCCATracker &tracker );
+  
+};
+
+
+#endif
similarity index 63%
rename from HLT/TPCLib/tracking-ca/AliHLTTPCCAHit.cxx
rename to HLT/TPCLib/tracking-ca/AliHLTTPCCAUsedHitsInitialiser.cxx
index 3ca286c23cb384f902979e190cd0a190043eeb7b..9ced5a5e91b94b0f286933c0d482790866b49871 100644 (file)
@@ -1,4 +1,4 @@
-// @(#) $Id$
+// @(#) $Id: AliHLTTPCCAUsedHitsInitialiser.cxx 27042 2008-07-02 12:06:02Z richterm $
 //***************************************************************************
 // This file is property of and copyright by the ALICE HLT Project          * 
 // ALICE Experiment at CERN, All rights reserved.                           *
 // provided "as is" without express or implied warranty.                    *
 //***************************************************************************
 
-#include "AliHLTTPCCAHit.h"
+#include "AliHLTTPCCAUsedHitsInitialiser.h"
+#include "AliHLTTPCCATracker.h"
 
 
-void AliHLTTPCCAHit::Dummy()
+void AliHLTTPCCAUsedHitsInitialiser::Thread
+( Int_t nBlocks, Int_t nThreads, Int_t iBlock, Int_t iThread, Int_t iSync,
+  AliHLTTPCCASharedMemory &s, AliHLTTPCCATracker &tracker )
 {
-  //* do nothing
+  // initialise used hit flags with 0
+
+  if( iSync==0 )
+    {
+      if( iThread==0 ){
+       s.fNHits = tracker.NHitsTotal();
+       s.fUsedHits = tracker.HitIsUsed();
+       s.fNThreadsTotal = nThreads*nBlocks;
+       s.fIh0 = nThreads*iBlock;
+      }
+    } 
+  else if( iSync==1 )
+    {
+      for( int ih=s.fIh0 + iThread; ih<s.fNHits; ih+=s.fNThreadsTotal ) s.fUsedHits[ih] = 0;         
+    }
 }
+
diff --git a/HLT/TPCLib/tracking-ca/AliHLTTPCCAUsedHitsInitialiser.h b/HLT/TPCLib/tracking-ca/AliHLTTPCCAUsedHitsInitialiser.h
new file mode 100644 (file)
index 0000000..6de3721
--- /dev/null
@@ -0,0 +1,51 @@
+//-*- Mode: C++ -*-
+
+//* 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 ALIHLTTPCCAUSEDHITSINITIALISER_H
+#define ALIHLTTPCCAUSEDHITSINITIALISER_H
+
+
+#include "AliHLTTPCCADef.h"
+
+class AliHLTTPCCATracker;
+
+/**
+ * @class AliHLTTPCCAUsedHitsInitialiser
+ * 
+ */
+class AliHLTTPCCAUsedHitsInitialiser
+{
+ public:
+  class AliHLTTPCCASharedMemory
+    {
+      friend class AliHLTTPCCAUsedHitsInitialiser;
+     public:
+#if !defined(HLTCA_GPUCODE)
+      AliHLTTPCCASharedMemory()
+       : fNHits(0), fUsedHits(0), fNThreadsTotal(0), fIh0(0)
+      {}
+
+      AliHLTTPCCASharedMemory( const AliHLTTPCCASharedMemory& /*dummy*/) 
+       : fNHits(0), fUsedHits(0), fNThreadsTotal(0), fIh0(0)
+      {}
+      AliHLTTPCCASharedMemory& operator=(const AliHLTTPCCASharedMemory& /*dummy*/){ return *this; }
+#endif
+    protected:
+      Int_t fNHits; // n hits
+      Int_t *fUsedHits; // pointer to the used hits array
+      Int_t fNThreadsTotal; // total n threads
+      Int_t fIh0; // start hit index for the thread
+     };
+
+  GPUd() static Int_t NThreadSyncPoints(){ return 3; }  
+
+  GPUd() static void Thread( Int_t nBlocks, Int_t nThreads, Int_t iBlock, Int_t iThread, Int_t iSync,
+                            AliHLTTPCCASharedMemory &smem, AliHLTTPCCATracker &tracker );  
+
+};
+
+
+#endif
index fafdf6fc6cbf992346dbcfb4821ba3281aca9eb9..294ae6a521125e83c994a7d6eefb6ef6861e50a3 100644 (file)
 
 #include "AliTPCtrackerCA.h"
 
-#include <TTree.h>
-#include <Riostream.h>
-#include "AliCluster.h"
+#include "TTree.h"
+#include "Riostream.h"
+//#include "AliCluster.h"
 #include "AliTPCClustersRow.h"
 #include "AliTPCParam.h"
 #include "AliRun.h"
 #include "AliRunLoader.h"
 #include "AliStack.h"
 
-#include "AliHLTTPCCATracker.h"
-#include "AliHLTTPCCAGBHit.h"
 #include "AliHLTTPCCAGBTracker.h"
+#include "AliHLTTPCCAGBHit.h"
 #include "AliHLTTPCCAGBTrack.h"
-#include "AliHLTTPCCAMCTrack.h"
-#include "AliHLTTPCCAOutTrack.h"
 #include "AliHLTTPCCAPerformance.h"
 #include "AliHLTTPCCAParam.h"
 #include "AliHLTTPCCATrackConvertor.h"
+#include "AliHLTTPCCATracker.h"
 
 #include "TMath.h"
 #include "AliTPCLoader.h"
 #include "AliTPCclusterMI.h"
 #include "AliTPCTransform.h"
 #include "AliTPCcalibDB.h"
-#include "AliTPCReconstructor.h"
 #include "AliTPCtrack.h"
 #include "AliESDtrack.h"
 #include "AliESDEvent.h"
 #include "AliTrackReference.h"
+#include "TStopwatch.h"
 
 //#include <fstream.h>
 
@@ -84,9 +82,9 @@ AliTPCtrackerCA::AliTPCtrackerCA(const AliTPCParam *par):
   AliTracker(),fParam(par), fClusters(0), fNClusters(0), fHLTTracker(0), fHLTPerformance(0),fDoHLTPerformance(0),fDoHLTPerformanceClusters(0),fStatNEvents(0)
 {
   //* constructor
-
   DoHLTPerformance() = 1;
-  DoHLTPerformanceClusters() = 1;
+  DoHLTPerformanceClusters() = 0;
 
   fHLTTracker = new AliHLTTPCCAGBTracker;
   fHLTTracker->SetNSlices( fParam->GetNSector()/2 );
@@ -121,19 +119,18 @@ AliTPCtrackerCA::AliTPCtrackerCA(const AliTPCParam *par):
     Float_t padPitch = 0.4;
     Float_t sigmaZ = 0.228808;
 
-    Int_t NRows = fParam->GetNRowLow()+fParam->GetNRowUp();
-
+    Int_t nRows = fParam->GetNRowLow()+fParam->GetNRowUp();
     Float_t rowX[200];
     for( Int_t irow=0; irow<fParam->GetNRowLow(); irow++){
       rowX[irow] = fParam->GetPadRowRadiiLow(irow);
     }     
     for( Int_t irow=0; irow<fParam->GetNRowUp(); irow++){
       rowX[fParam->GetNRowLow()+irow] = fParam->GetPadRowRadiiUp(irow);
-    }      
+    }
     AliHLTTPCCAParam param;
-    param.Initialize( iSlice, NRows, rowX, alpha, dalpha,
+    param.Initialize( iSlice, nRows, rowX, alpha, dalpha,
                      inRmin, outRmax, zMin, zMax, padPitch, sigmaZ, bz );
-    param.YErrorCorrection() = 1.;//.33;
+    param.YErrorCorrection() = 1.;// .33;
     param.ZErrorCorrection() = 1.;//.33;
     param.MaxTrackMatchDRow() = 5;
     param.TrackConnectionFactor() = 3.5;
@@ -143,8 +140,9 @@ AliTPCtrackerCA::AliTPCtrackerCA(const AliTPCParam *par):
 
 
 
-Int_t AliTPCtrackerCA::LoadClusters (TTree * tree)
+Int_t AliTPCtrackerCA::LoadClusters (TTree * fromTree)
 { 
+  // load clusters to the local arrays
   fNClusters = 0;
   if( fClusters ) delete[] fClusters;
 
@@ -156,7 +154,7 @@ Int_t AliTPCtrackerCA::LoadClusters (TTree * tree)
   // load mc tracks
   while( fDoHLTPerformance ){
     if( !gAlice ) break;
-    AliRunLoader *rl = AliRunLoader::GetRunLoader(); 
+    AliRunLoader *rl = gAlice->GetRunLoader(); 
     if( !rl ) break;
     rl->LoadKinematics();
     AliStack *stack = rl->Stack();
@@ -174,15 +172,15 @@ Int_t AliTPCtrackerCA::LoadClusters (TTree * tree)
       isTPC = new Bool_t [stack->GetNtrack()];
       for( Int_t i=0; i<stack->GetNtrack(); i++ ) isTPC[i] = 0;
       rl->LoadTrackRefs();
-      TTree *TR = rl->TreeTR();
-      if( !TR ) break;
-      TBranch *branch=TR->GetBranch("TrackReferences");
+      TTree *mcTree = rl->TreeTR();
+      if( !mcTree ) break;
+      TBranch *branch=mcTree->GetBranch("TrackReferences");
       if (!branch ) break;     
       TClonesArray tpcdummy("AliTrackReference",1000), *tpcRefs=&tpcdummy;
       branch->SetAddress(&tpcRefs);
-      Int_t nr=(Int_t)TR->GetEntries();
+      Int_t nr=(Int_t)mcTree->GetEntries();
       for (Int_t r=0; r<nr; r++) {
-       TR->GetEvent(r);
+       mcTree->GetEvent(r);
        Int_t nref = tpcRefs->GetEntriesFast();
        if (!nref) continue;
        AliTrackReference *tpcRef= 0x0;  
@@ -236,7 +234,7 @@ Int_t AliTPCtrackerCA::LoadClusters (TTree * tree)
     break;
   }
   
-  TBranch * br = tree->GetBranch("Segment");
+  TBranch * br = fromTree->GetBranch("Segment");
   if( !br ) return 1;
 
   AliTPCClustersRow *clrow = new AliTPCClustersRow;
@@ -247,10 +245,10 @@ Int_t AliTPCtrackerCA::LoadClusters (TTree * tree)
   br->SetAddress(&clrow);
   
   //
-  Int_t NEnt=Int_t(tree->GetEntries());
+  Int_t nEnt=Int_t(fromTree->GetEntries());
 
   fNClusters = 0;
-  for (Int_t i=0; i<NEnt; i++) {
+  for (Int_t i=0; i<nEnt; i++) {
     br->GetEntry(i);
     Int_t sec,row;
     fParam->AdjustSectorRow(clrow->GetID(),sec,row);
@@ -261,13 +259,13 @@ Int_t AliTPCtrackerCA::LoadClusters (TTree * tree)
   fHLTTracker->SetNHits( fNClusters );
   if( fDoHLTPerformance ) fHLTPerformance->SetNHits( fNClusters );
   int ind=0;
-  for (Int_t i=0; i<NEnt; i++) {
+  for (Int_t i=0; i<nEnt; i++) {
     br->GetEntry(i);
     Int_t sec,row;
     fParam->AdjustSectorRow(clrow->GetID(),sec,row);
-    int NClu = clrow->GetArray()->GetEntriesFast();
+    int nClu = clrow->GetArray()->GetEntriesFast();
     Float_t x = fParam->GetPadRowRadii(sec,row);
-    for (Int_t icl=0; icl<NClu; icl++){
+    for (Int_t icl=0; icl<nClu; icl++){
       Int_t lab0 = -1;
       Int_t lab1 = -1;
       Int_t lab2 = -1;
@@ -285,9 +283,9 @@ Int_t AliTPCtrackerCA::LoadClusters (TTree * tree)
       Int_t id[1]={cluster->GetDetector()};
       transform->Transform(xx,id,0,1);  
       //if (!AliTPCReconstructor::GetRecoParam()->GetBYMirror()){
-      if (cluster->GetDetector()%36>17){
-       xx[1]*=-1;
-      }
+      //if (cluster->GetDetector()%36>17){
+      //xx[1]*=-1;
+      //}
       //}
 
       cluster->SetX(xx[0]);
@@ -332,9 +330,12 @@ AliCluster * AliTPCtrackerCA::GetCluster(Int_t index) const
 
 Int_t AliTPCtrackerCA::Clusters2Tracks( AliESDEvent *event )
 {
-  //cout<<"Start of AliTPCtrackerCA"<<endl;
+  // reconstruction
+  cout<<"Start of AliTPCtrackerCA"<<endl;
+  TStopwatch timer;
 
   fHLTTracker->FindTracks();
+  cout<<"Do performance.."<<endl;
   if( fDoHLTPerformance ) fHLTPerformance->Performance();
 
   if( 0 ) {// Write Event    
@@ -347,18 +348,18 @@ Int_t AliTPCtrackerCA::Clusters2Tracks( AliESDEvent *event )
       geo.close();
     }
 
-    fstream eventStream;
+    fstream hits;
     char name[255];
     sprintf( name,"CAEvents/%i.event.dat",fStatNEvents ); 
-    eventStream.open(name, ios::out);
-    if( eventStream.is_open() ){
-      fHLTTracker->WriteEvent(eventStream);    
+    hits.open(name, ios::out);
+    if( hits.is_open() ){
+      fHLTTracker->WriteEvent(hits);   
       fstream tracks;
       sprintf( name,"CAEvents/%i.tracks.dat",fStatNEvents ); 
       tracks.open(name, ios::out);
       fHLTTracker->WriteTracks(tracks);        
     }
-    eventStream.close();   
+    hits.close();   
     if( fDoHLTPerformance ){
       fstream mcevent, mcpoints;
       char mcname[255];
@@ -367,7 +368,7 @@ Int_t AliTPCtrackerCA::Clusters2Tracks( AliESDEvent *event )
       if( mcevent.is_open() ){      
        fHLTPerformance->WriteMCEvent(mcevent);
       }
-      if(fDoHLTPerformanceClusters ){
+      if(1 && fDoHLTPerformanceClusters ){
        sprintf( mcname,"CAEvents/%i.mcpoints.dat",fStatNEvents ); 
        mcpoints.open(mcname, ios::out);
        if( mcpoints.is_open() ){      
@@ -391,17 +392,17 @@ Int_t AliTPCtrackerCA::Clusters2Tracks( AliESDEvent *event )
       AliHLTTPCCATrackConvertor::GetExtParam( par, tTPC, tCA.Alpha(), bz );
       tTPC.SetMass(0.13957);
       tTPC.SetdEdx( tCA.DeDx() );
-      if( TMath::Abs(tTPC.GetSigned1Pt())>1./0.1 ) continue;
+      if( TMath::Abs(tTPC.GetSigned1Pt())>1./0.02 ) continue;
       int nhits = tCA.NHits();
       if( nhits>kMaxRow ) nhits = kMaxRow;
       tTPC.SetNumberOfClusters(nhits);      
       for( Int_t ih=0; ih<nhits; ih++ ){
        Int_t index = fHLTTracker->TrackHits()[tCA.FirstHitRef()+ih];
-       Int_t ext_index = fHLTTracker->Hits()[index].ID();
-       tTPC.SetClusterIndex(ih, ext_index);
+       Int_t extIndex = fHLTTracker->Hits()[index].ID();
+       tTPC.SetClusterIndex(ih, extIndex);
       }
       CookLabel(&tTPC,0.1);          
-      {
+      if(0){
        Double_t xTPC=fParam->GetInnerRadiusLow();
        Double_t dAlpha = fParam->GetInnerAngle()/180.*TMath::Pi();
        if (tTPC.AliExternalTrackParam::PropagateTo(xTPC,bz)) {   
@@ -423,6 +424,13 @@ Int_t AliTPCtrackerCA::Clusters2Tracks( AliESDEvent *event )
       event->AddTrack(&tESD);
     }
   }
+  timer.Stop();
+  static double time=0, time1 = 0;
+  static int ncalls = 0;
+  time+=timer.CpuTime();
+  time1+=timer.RealTime();
+  ncalls++;
+  cout<<"\n\nCA tracker speed: cpu = "<<time/ncalls*1.e3<<" [ms/ev], real = "<<time1/ncalls*1.e3<<" [ms/ev], n calls = "<<ncalls<<endl<<endl;
 
   //cout<<"End of AliTPCtrackerCA"<<endl;
   return 0;
@@ -442,7 +450,7 @@ Int_t AliTPCtrackerCA::RefitInward (AliESDEvent *event)
      
   for (Int_t i=0; i<nentr; i++) {
     AliESDtrack *esd=event->GetTrack(i);
-    ULong_t status=esd->GetStatus();
+    ULong_t status=esd->GetStatus(); 
     if (!(status&AliESDtrack::kTPCin)) continue;
     AliHLTTPCCATrackParam t0;
     AliHLTTPCCATrackConvertor::SetExtParam(t0,*esd, bz );
index 79886cb40797a64395f9d0c19cee0f203385ab4b..d84866fba4d3d3377233fe0900d4fdd6fcd5f648 100644 (file)
@@ -34,8 +34,8 @@ public:
   AliTPCtrackerCA & operator=(const AliTPCtrackerCA& );
   virtual ~AliTPCtrackerCA();
   //
-  Int_t RefitInward (AliESDEvent *);
-  Int_t PropagateBack(AliESDEvent *);
+  Int_t RefitInward (AliESDEvent *event);
+  Int_t PropagateBack(AliESDEvent *event);
   //
   Int_t Clusters2Tracks (AliESDEvent *esd);
 
index b5a4b3050e4c6e61c59ca652e1740a44da1183bd..04a4e9256e7048ea606003c2cea9717fca972cbf 100644 (file)
@@ -1,6 +1,34 @@
 #-*- Mode: Makefile -*-
 # $Id$
 
+TRACKING_CA:=  
+# TRACKING_CA:=        tracking-ca/AliHLTTPCCATrack.h \
+#              tracking-ca/AliHLTTPCCADisplay.h  \
+#              tracking-ca/AliHLTTPCCATracker.h \
+#              tracking-ca/AliHLTTPCCAOutTrack.h  \
+#              tracking-ca/AliHLTTPCCATrackParam.h \
+#              tracking-ca/AliHLTTPCCATrackParam1.h \
+#              tracking-ca/AliHLTTPCCATrackConvertor.h \
+#              tracking-ca/AliHLTTPCCAParam.h     \
+#              tracking-ca/AliHLTTPCCARow.h \
+#              tracking-ca/AliHLTTPCCAGrid.h \
+#              tracking-ca/AliHLTTPCCAHitArea.h \
+#              tracking-ca/AliHLTTPCCAGBHit.h  \
+#              tracking-ca/AliHLTTPCCAMCTrack.h  \
+#              tracking-ca/AliHLTTPCCAMCPoint.h  \
+#              tracking-ca/AliHLTTPCCAGBTrack.h  \
+#              tracking-ca/AliHLTTPCCAGBTracker.h \
+#              tracking-ca/AliHLTTPCCAPerformance.h \
+#              tracking-ca/AliTPCtrackerCA.h \
+#              tracking-ca/AliHLTTPCCATrackerComponent.h \
+#              tracking-ca/AliHLTTPCCANeighboursFinder.h \
+#              tracking-ca/AliHLTTPCCANeighboursCleaner.h \
+#              tracking-ca/AliHLTTPCCAStartHitsFinder.h \
+#              tracking-ca/AliHLTTPCCAUsedHitsInitialiser.h \
+#              tracking-ca/AliHLTTPCCATrackletConstructor.h \
+#              tracking-ca/AliHLTTPCCATrackletSelector.h \
+#              tracking-ca/AliHLTTPCCALinksWriter.h
+
 CLASS_HDRS:=   AliHLTTPCTransform.h \
                AliHLTTPCAgent.h \
                AliHLTTPCMemHandler.h \
@@ -48,27 +76,7 @@ CLASS_HDRS:=         AliHLTTPCTransform.h \
                AliHLTTPCEsdWriterComponent.h \
                AliHLTTPCHistogramHandlerComponent.h \
                AliHLTTPCClusterConverterComponent.h \
-               tracking-ca/AliHLT3DTrackParam.h \
-               tracking-ca/AliHLTTPCCATrack.h \
-               tracking-ca/AliHLTTPCCACell.h     \
-               tracking-ca/AliHLTTPCCAEndPoint.h     \
-               tracking-ca/AliHLTTPCCADisplay.h  \
-               tracking-ca/AliHLTTPCCATracker.h \
-               tracking-ca/AliHLTTPCCAHit.h      \
-               tracking-ca/AliHLTTPCCAOutTrack.h  \
-               tracking-ca/AliHLTTPCCATrackParam.h \
-               tracking-ca/AliHLTTPCCATrackConvertor.h \
-               tracking-ca/AliHLTTPCCAParam.h     \
-               tracking-ca/AliHLTTPCCARow.h \
-               tracking-ca/AliHLTTPCCAGrid.h \
-               tracking-ca/AliHLTTPCCAGBHit.h  \
-               tracking-ca/AliHLTTPCCAMCTrack.h  \
-               tracking-ca/AliHLTTPCCAMCPoint.h  \
-               tracking-ca/AliHLTTPCCAGBTrack.h  \
-               tracking-ca/AliHLTTPCCAGBTracker.h \
-               tracking-ca/AliHLTTPCCAPerformance.h \
-               tracking-ca/AliTPCtrackerCA.h \
-               tracking-ca/AliHLTTPCCATrackerComponent.h \
+               $(TRACKING_CA) \
                comp/AliHLTTPCCompDataCompressorHelper.h \
                comp/AliHLTTPCCompDumpComponent.h \
                comp/AliHLTTPCCompModelAnalysis.h \