]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
completely re-worked TPC CA tracking code (Sergey/Ivan)
authorrichterm <richterm@f7af4fe6-9843-0410-8265-dc069ae4e863>
Mon, 10 Dec 2007 10:28:55 +0000 (10:28 +0000)
committerrichterm <richterm@f7af4fe6-9843-0410-8265-dc069ae4e863>
Mon, 10 Dec 2007 10:28:55 +0000 (10:28 +0000)
21 files changed:
HLT/TPCLib/tracking-ca/AliHLT3DTrackParam.cxx [new file with mode: 0644]
HLT/TPCLib/tracking-ca/AliHLT3DTrackParam.h [new file with mode: 0644]
HLT/TPCLib/tracking-ca/AliHLTTPCCACell.cxx [new file with mode: 0644]
HLT/TPCLib/tracking-ca/AliHLTTPCCACell.h [new file with mode: 0644]
HLT/TPCLib/tracking-ca/AliHLTTPCCADisplay.cxx [new file with mode: 0644]
HLT/TPCLib/tracking-ca/AliHLTTPCCADisplay.h [new file with mode: 0644]
HLT/TPCLib/tracking-ca/AliHLTTPCCAHit.cxx [new file with mode: 0644]
HLT/TPCLib/tracking-ca/AliHLTTPCCAHit.h [new file with mode: 0644]
HLT/TPCLib/tracking-ca/AliHLTTPCCAOutTrack.cxx [new file with mode: 0644]
HLT/TPCLib/tracking-ca/AliHLTTPCCAOutTrack.h [new file with mode: 0644]
HLT/TPCLib/tracking-ca/AliHLTTPCCAParam.cxx [new file with mode: 0644]
HLT/TPCLib/tracking-ca/AliHLTTPCCAParam.h [new file with mode: 0644]
HLT/TPCLib/tracking-ca/AliHLTTPCCARow.cxx [new file with mode: 0644]
HLT/TPCLib/tracking-ca/AliHLTTPCCARow.h [new file with mode: 0644]
HLT/TPCLib/tracking-ca/AliHLTTPCCATrack.cxx [new file with mode: 0644]
HLT/TPCLib/tracking-ca/AliHLTTPCCATrack.h [new file with mode: 0644]
HLT/TPCLib/tracking-ca/AliHLTTPCCATrackPar.cxx [new file with mode: 0644]
HLT/TPCLib/tracking-ca/AliHLTTPCCATrackPar.h [new file with mode: 0644]
HLT/TPCLib/tracking-ca/AliHLTTPCCATracker.cxx [new file with mode: 0644]
HLT/TPCLib/tracking-ca/AliHLTTPCCATracker.h [new file with mode: 0644]
HLT/libAliHLTTPC.pkg

diff --git a/HLT/TPCLib/tracking-ca/AliHLT3DTrackParam.cxx b/HLT/TPCLib/tracking-ca/AliHLT3DTrackParam.cxx
new file mode 100644 (file)
index 0000000..8809ce6
--- /dev/null
@@ -0,0 +1,380 @@
+// @(#) $Id$
+//***************************************************************************
+// 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 "AliHLT3DTrackParam.h"
+#include "TMath.h"
+
+ClassImp(AliHLT3DTrackParam);
+
+//* Transport utilities
+  
+Double_t AliHLT3DTrackParam::GetDStoPoint( Double_t Bz, const Double_t xyz[3], const Double_t *T0 ) const
+{
+  //* Get DS = Path/Momentum to a certain space point for Bz field
+
+  Double_t q = fSignQ;
+  if( !T0 ) T0 = fParam; 
+  else q = T0[6];
+
+  const Double_t kCLight = 0.000299792458;
+  Double_t bq = Bz*q*kCLight;
+  Double_t pt2 = T0[3]*T0[3] + T0[4]*T0[4];
+  if( pt2<1.e-4 ) return 0;
+  Double_t dx = xyz[0] - T0[0];
+  Double_t dy = xyz[1] - T0[1]; 
+  Double_t a = dx*T0[3]+dy*T0[4];
+  Double_t dS = 0;
+  if( TMath::Abs(bq)<1.e-8 ) dS = a/pt2;
+  else dS = TMath::ATan2( bq*a, pt2 + bq*(dy*T0[3] -dx*T0[4]) )/bq;
+  return dS;
+}
+
+
+void AliHLT3DTrackParam::TransportToDS( Double_t Bz, Double_t DS, Double_t *T0 )
+{
+  //* Transport the particle on DS = Path/Momentum, for Bz field 
+
+  Double_t tmp[7];
+  if( !T0 ){
+    T0 = tmp;
+    T0[0] = fParam[0];
+    T0[1] = fParam[1];
+    T0[2] = fParam[2];
+    T0[3] = fParam[3];
+    T0[4] = fParam[4];
+    T0[5] = fParam[5];
+    T0[6] = fSignQ;
+  }
+  const Double_t kCLight = 0.000299792458;
+  Bz = Bz*T0[6]*kCLight;
+  Double_t bs= Bz*DS;
+  Double_t s = TMath::Sin(bs), c = TMath::Cos(bs);
+  Double_t sB, cB;
+  if( TMath::Abs(bs)>1.e-10){
+    sB= s/Bz;
+    cB= (1-c)/Bz;
+  }else{
+    sB = (1. - bs*bs/6.)*DS;
+    cB = .5*sB*bs;
+  }
+    
+  Double_t px = T0[3];
+  Double_t py = T0[4];
+  Double_t pz = T0[5];
+  
+  Double_t d[6] = { fParam[0]-T0[0], fParam[1]-T0[1], fParam[2]-T0[2], 
+                   fParam[3]-T0[3], fParam[4]-T0[4], fParam[5]-T0[5]  };
+
+  T0[0] = T0[0] + sB*px + cB*py;
+  T0[1] = T0[1] - cB*px + sB*py;
+  T0[2] = T0[2] + DS*pz                       ;
+  T0[3] =          c*px + s*py;
+  T0[4] =         -s*px + c*py;
+  T0[5] = T0[5];
+  Double_t mJ[6][6] = { {1,0,0,   sB, cB,  0, },
+                        {0,1,0,  -cB, sB,  0, },
+                        {0,0,1,    0,  0, DS, },
+                        {0,0,0,    c,  s,  0, },
+                        {0,0,0,   -s,  c,  0, },
+                        {0,0,0,    0,  0,  1, }   };
+
+  for( Int_t i=0; i<6; i++){
+    fParam[i] = T0[i];
+    for( Int_t j=0; j<6; j++) fParam[i] += mJ[i][j]*d[j];
+  }
+
+  Double_t mA[6][6];
+  for( Int_t k=0,i=0; i<6; i++)
+    for( Int_t j=0; j<=i; j++, k++ ) mA[i][j] = mA[j][i] = fCov[k]; 
+
+  Double_t mJC[6][6];
+  for( Int_t i=0; i<6; i++ )
+    for( Int_t j=0; j<6; j++ ){
+      mJC[i][j]=0;
+      for( Int_t k=0; k<6; k++ ) mJC[i][j]+=mJ[i][k]*mA[k][j];
+    }
+  
+  for( Int_t k=0,i=0; i<6; i++)
+    for( Int_t j=0; j<=i; j++, k++ ){
+      fCov[k] = 0;
+      for( Int_t l=0; l<6; l++ ) fCov[k]+=mJC[i][l]*mJ[j][l];
+    }
+}
+
+
+//* Fit utilities 
+
+void AliHLT3DTrackParam::InitializeCovarianceMatrix()
+{
+  //* Initialization of covariance matrix
+
+  for( Int_t i=0; i<21; i++ ) fCov[i] = 0;
+  fSignQ = 0;
+  fCov[0] = fCov[ 2] = fCov[ 5] = 100.;
+  fCov[9] = fCov[14] = fCov[20] = 10000.;
+  fChi2 = 0;
+  fNDF = -5;
+}
+
+void AliHLT3DTrackParam::GetGlueMatrix( const Double_t xyz[3], 
+                                       Double_t G[6], const Double_t *T0  ) const 
+{
+  //* !
+
+  if( !T0 ) T0 = fParam;
+
+  Double_t dx = xyz[0]-T0[0], dy = xyz[1]-T0[1], dz = xyz[2]-T0[2];
+  Double_t px2= T0[3]*T0[3], py2= T0[4]*T0[4], pz2= T0[5]*T0[5];
+  Double_t s2 = (dx*dx + dy*dy + dz*dz);
+  Double_t p2 = px2 + py2 + pz2;
+  if( p2>1.e-4 ) s2/=p2;
+  Double_t x = T0[3]*s2;
+  Double_t xx= px2*s2, xy= x*T0[4], xz= x*T0[5], yy= py2*s2, yz= T0[4]*T0[5]*s2;
+  G[ 0]= xx;
+  G[ 1]= xy;   G[ 2]= yy;
+  G[ 3]= xz;   G[ 4]= yz;   G[ 5]= pz2*s2;  
+}
+
+
+
+void AliHLT3DTrackParam::Filter( const Double_t m[3], const Double_t V[6], const Double_t G[6] )
+{ 
+  //* !
+  
+  Double_t 
+    c00 = fCov[ 0],
+    c10 = fCov[ 1], c11 = fCov[ 2],
+    c20 = fCov[ 3], c21 = fCov[ 4], c22 = fCov[ 5],
+    c30 = fCov[ 6], c31 = fCov[ 7], c32 = fCov[ 8],
+    c40 = fCov[10], c41 = fCov[11], c42 = fCov[12],
+    c50 = fCov[15], c51 = fCov[16], c52 = fCov[17];
+  
+  double
+    z0 = m[0]-fParam[0],
+    z1 = m[1]-fParam[1],
+    z2 = m[2]-fParam[2];
+  
+  Double_t mS[6] = { c00+V[0]+G[0], c10+V[1]+G[1], c11+V[2]+G[2],
+                    c20+V[3]+G[3], c21+V[4]+G[4], c22+V[5]+G[5] };
+  Double_t mSi[6];
+  mSi[0] = mS[4]*mS[4] - mS[2]*mS[5];
+  mSi[1] = mS[1]*mS[5] - mS[3]*mS[4];
+  mSi[3] = mS[2]*mS[3] - mS[1]*mS[4];
+  Double_t det = 1./(mS[0]*mSi[0] + mS[1]*mSi[1] + mS[3]*mSi[3]);
+  mSi[0] *= det;
+  mSi[1] *= det;
+  mSi[3] *= det;
+  mSi[2] = ( mS[3]*mS[3] - mS[0]*mS[5] )*det;
+  mSi[4] = ( mS[0]*mS[4] - mS[1]*mS[3] )*det;
+  mSi[5] = ( mS[1]*mS[1] - mS[0]*mS[2] )*det;
+  
+  fNDF  += 2;
+  fChi2 += ( +(mSi[0]*z0 + mSi[1]*z1 + mSi[3]*z2)*z0
+            +(mSi[1]*z0 + mSi[2]*z1 + mSi[4]*z2)*z1
+            +(mSi[3]*z0 + mSi[4]*z1 + mSi[5]*z2)*z2 );
+        
+  Double_t k0, k1, k2 ; // k = CHtS
+    
+  k0 = c00*mSi[0] + c10*mSi[1] + c20*mSi[3];
+  k1 = c00*mSi[1] + c10*mSi[2] + c20*mSi[4];
+  k2 = c00*mSi[3] + c10*mSi[4] + c20*mSi[5];
+    
+  fParam[ 0]+= k0*z0  + k1*z1  + k2*z2 ;
+  fCov  [ 0]-= k0*c00 + k1*c10 + k2*c20;
+  
+  k0 = c10*mSi[0] + c11*mSi[1] + c21*mSi[3];
+  k1 = c10*mSi[1] + c11*mSi[2] + c21*mSi[4];
+  k2 = c10*mSi[3] + c11*mSi[4] + c21*mSi[5];
+  
+  fParam[ 1]+= k0*z0  + k1*z1  + k2*z2 ;
+  fCov  [ 1]-= k0*c00 + k1*c10 + k2*c20;
+  fCov  [ 2]-= k0*c10 + k1*c11 + k2*c21;
+  
+  k0 = c20*mSi[0] + c21*mSi[1] + c22*mSi[3];
+  k1 = c20*mSi[1] + c21*mSi[2] + c22*mSi[4];
+  k2 = c20*mSi[3] + c21*mSi[4] + c22*mSi[5];
+  
+  fParam[ 2]+= k0*z0  + k1*z1  + k2*z2 ;
+  fCov  [ 3]-= k0*c00 + k1*c10 + k2*c20;
+  fCov  [ 4]-= k0*c10 + k1*c11 + k2*c21;
+  fCov  [ 5]-= k0*c20 + k1*c21 + k2*c22;
+  
+  k0 = c30*mSi[0] + c31*mSi[1] + c32*mSi[3];
+  k1 = c30*mSi[1] + c31*mSi[2] + c32*mSi[4];
+  k2 = c30*mSi[3] + c31*mSi[4] + c32*mSi[5];
+  
+  fParam[ 3]+= k0*z0  + k1*z1  + k2*z2 ;
+  fCov  [ 6]-= k0*c00 + k1*c10 + k2*c20;
+  fCov  [ 7]-= k0*c10 + k1*c11 + k2*c21;
+  fCov  [ 8]-= k0*c20 + k1*c21 + k2*c22;
+  fCov  [ 9]-= k0*c30 + k1*c31 + k2*c32;
+  
+  k0 = c40*mSi[0] + c41*mSi[1] + c42*mSi[3];
+  k1 = c40*mSi[1] + c41*mSi[2] + c42*mSi[4];
+  k2 = c40*mSi[3] + c41*mSi[4] + c42*mSi[5];
+    
+  fParam[ 4]+= k0*z0  + k1*z1  + k2*z2 ;
+  fCov  [10]-= k0*c00 + k1*c10 + k2*c20;
+  fCov  [11]-= k0*c10 + k1*c11 + k2*c21;
+  fCov  [12]-= k0*c20 + k1*c21 + k2*c22;
+  fCov  [13]-= k0*c30 + k1*c31 + k2*c32;
+  fCov  [14]-= k0*c40 + k1*c41 + k2*c42;
+
+  k0 = c50*mSi[0] + c51*mSi[1] + c52*mSi[3];
+  k1 = c50*mSi[1] + c51*mSi[2] + c52*mSi[4];
+  k2 = c50*mSi[3] + c51*mSi[4] + c52*mSi[5];
+  
+  fParam[ 5]+= k0*z0  + k1*z1  + k2*z2 ;
+  fCov  [15]-= k0*c00 + k1*c10 + k2*c20;
+  fCov  [16]-= k0*c10 + k1*c11 + k2*c21;
+  fCov  [17]-= k0*c20 + k1*c21 + k2*c22;
+  fCov  [18]-= k0*c30 + k1*c31 + k2*c32;
+  fCov  [19]-= k0*c40 + k1*c41 + k2*c42;
+  fCov  [20]-= k0*c50 + k1*c51 + k2*c52;
+
+  // fit charge
+
+  Double_t px = fParam[3];
+  Double_t py = fParam[4];
+  Double_t pz = fParam[5];
+  
+  Double_t p = TMath::Sqrt( px*px + py*py + pz*pz );
+  Double_t pi = 1./p;
+  Double_t qp = fSignQ*pi;
+  Double_t qp3 = qp*pi*pi;
+  Double_t 
+    c60 = qp3*(c30+c40+c50),
+    c61 = qp3*(c31+c41+c51),
+    c62 = qp3*(c32+c42+c52);
+
+  k0 = c60*mSi[0] + c61*mSi[1] + c62*mSi[3];
+  k1 = c60*mSi[1] + c61*mSi[2] + c62*mSi[4];
+  k2 = c60*mSi[3] + c61*mSi[4] + c62*mSi[5];
+  
+  qp+= k0*z0  + k1*z1  + k2*z2 ;
+  if( qp>0 ) fSignQ = 1;
+  else if(qp<0 ) fSignQ = -1;
+  else fSignQ = 0;
+}
+
+
+//* Other utilities
+
+void AliHLT3DTrackParam::SetDirection( Double_t Direction[3] )
+{
+  //* Change track direction 
+
+  if( fParam[3]*Direction[0] + fParam[4]*Direction[1] + fParam[5]*Direction[2] >= 0 ) return;
+
+  fParam[3] = -fParam[3];
+  fParam[4] = -fParam[4];
+  fParam[5] = -fParam[5];
+  fSignQ    = -fSignQ;
+
+  fCov[ 6]=-fCov[ 6]; fCov[ 7]=-fCov[ 7]; fCov[ 8]=-fCov[ 8];
+  fCov[10]=-fCov[10]; fCov[11]=-fCov[11]; fCov[12]=-fCov[12];
+  fCov[15]=-fCov[15]; fCov[16]=-fCov[16]; fCov[17]=-fCov[17];
+}
+
+
+void AliHLT3DTrackParam::RotateCoordinateSystem( Double_t alpha )
+{
+  //* !
+
+  Double_t cA = TMath::Cos( alpha );
+  Double_t sA = TMath::Sin( alpha );
+  Double_t x= fParam[0], y= fParam[1], px= fParam[3], py= fParam[4];
+  fParam[0] = x*cA + y*sA;
+  fParam[1] =-x*sA + y*cA;
+  fParam[2] = fParam[2];
+  fParam[3] = px*cA + py*sA;
+  fParam[4] =-px*sA + py*cA;
+  fParam[5] = fParam[5];  
+
+  Double_t mJ[6][6] = { { cA,sA, 0,  0,  0,  0 },
+                        {-sA,cA, 0,  0,  0,  0 },
+                        {  0, 0, 1,  0,  0,  0 },
+                        {  0, 0, 0, cA, sA,  0 },
+                        {  0, 0, 0,-sA, cA,  0 },
+                        {  0, 0, 0,  0,  0,  1 }  };
+                  
+  Double_t mA[6][6];
+  for( Int_t k=0,i=0; i<6; i++)
+    for( Int_t j=0; j<=i; j++, k++ ) mA[i][j] = mA[j][i] = fCov[k]; 
+
+  Double_t mJC[6][6];
+  for( Int_t i=0; i<6; i++ )
+    for( Int_t j=0; j<6; j++ ){
+      mJC[i][j]=0;
+      for( Int_t k=0; k<6; k++ ) mJC[i][j]+=mJ[i][k]*mA[k][j];
+    }
+  
+  for( Int_t k=0,i=0; i<6; i++)
+    for( Int_t j=0; j<=i; j++, k++ ){
+      fCov[k] = 0;
+      for( Int_t l=0; l<6; l++ ) fCov[k]+=mJC[i][l]*mJ[j][l];
+    }
+}
+
+
+void AliHLT3DTrackParam::Get5Parameters( Double_t alpha, Double_t T[6], Double_t C[15] ) const
+{
+  //* !
+
+  AliHLT3DTrackParam t = *this;
+  t.RotateCoordinateSystem(alpha);
+  Double_t 
+    x= t.fParam[0], y= t.fParam[1], z = t.fParam[2], 
+    px= t.fParam[3], py= t.fParam[4], pz = t.fParam[5], q = t.fSignQ;
+
+  Double_t p2 = px*px+py*py+pz*pz;
+  if( p2<1.e-8 ) p2 = 1;
+  Double_t n2 = 1./p2;
+  Double_t n = sqrt(n2);
+
+  T[5] = x;
+  T[0] = y;
+  T[1] = z;
+  T[2] = py/px;
+  T[3] = pz/px;
+  T[4] = q*n;
+
+  Double_t mJ[5][6] = { { -T[2], 1, 0,  0,  0,  0 },
+                        { -T[3], 0, 1,  0,  0,  0 },
+                        { 0, 0, 0,  -T[2]/px,  1./px,  0 },
+                        { 0, 0, 0, -T[3]/px,  0,  1./px },
+                        { 0, 0, 0, -T[4]*n2*px, -T[4]*n2*py, -T[4]*n2*pz} };
+
+  Double_t mA[6][6];
+  for( Int_t k=0,i=0; i<6; i++)
+    for( Int_t j=0; j<=i; j++, k++ ) mA[i][j] = mA[j][i] = t.fCov[k]; 
+
+  Double_t mJC[5][6];
+  for( Int_t i=0; i<5; i++ )
+    for( Int_t j=0; j<6; j++ ){
+      mJC[i][j]=0;
+      for( Int_t k=0; k<6; k++ ) mJC[i][j]+=mJ[i][k]*mA[k][j];
+    }
+  
+  for( Int_t k=0,i=0; i<5; i++)
+    for( Int_t j=0; j<=i; j++, k++ ){
+      C[k] = 0;
+      for( Int_t l=0; l<6; l++ ) C[k]+=mJC[i][l]*mJ[j][l];
+    }
+}
diff --git a/HLT/TPCLib/tracking-ca/AliHLT3DTrackParam.h b/HLT/TPCLib/tracking-ca/AliHLT3DTrackParam.h
new file mode 100644 (file)
index 0000000..7ccabef
--- /dev/null
@@ -0,0 +1,123 @@
+//-*- 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 ALIHLT3DTRACKPARAM_H
+#define ALIHLT3DTRACKPARAM_H
+
+#include "Rtypes.h"
+
+/**
+ * @class AliHLT3DTrackParam
+ */
+class AliHLT3DTrackParam{
+ public:
+
+  //*
+  //*  INITIALIZATION
+  //*
+
+  //* Constructor 
+
+  AliHLT3DTrackParam(): fChi2(0),fNDF(0),fSignQ(0){} 
+
+  //* Destructor (empty)
+
+  virtual ~AliHLT3DTrackParam(){}
+
+  //*
+  //*  ACCESSORS
+  //*
+
+
+  //* Simple accessors 
+
+  Double_t GetX()      const { return fParam[0]; }
+  Double_t GetY()      const { return fParam[1]; }
+  Double_t GetZ()      const { return fParam[2]; }
+  Double_t GetPx()     const { return fParam[3]; }
+  Double_t GetPy()     const { return fParam[4]; }
+  Double_t GetPz()     const { return fParam[5]; }
+  Double_t GetChi2()   const { return fChi2;  }
+  Int_t    GetNDF()    const { return fNDF;   }
+  Int_t    GetCharge() const { return fSignQ; }
+  
+  Double_t GetParameter ( int i ) const ;
+  Double_t GetCovariance( int i ) const ;
+  Double_t GetCovariance( int i, int j ) const ;
+
+  //* Accessors with calculations( &value, &estimated sigma )
+  //* error flag returned (0 means no error during calculations) 
+
+
+  //*
+  //*  MODIFIERS
+  //*
+  
+  Double_t *Param()  { return fParam; }
+  Double_t *Cov()    { return fCov;   }
+  Double_t &X()      { return fParam[0]; }
+  Double_t &Y()      { return fParam[1]; }
+  Double_t &Z()      { return fParam[2]; }
+  Double_t &Px()     { return fParam[3]; }
+  Double_t &Py()     { return fParam[4]; }
+  Double_t &Pz()     { return fParam[5]; }
+  Double_t &Chi2()   { return fChi2;  }
+  Int_t    &NDF()    { return fNDF;   }
+  Int_t    &Charge() { return fSignQ; }
+
+
+  //*
+  //*  UTILITIES
+  //*
+  
+  //* Transport utilities
+  
+  Double_t GetDStoPoint( Double_t Bz, const Double_t xyz[3], const Double_t *T0=0 ) const;
+
+  void TransportToDS( Double_t Bz, Double_t DS, Double_t *T0=0 );
+
+  void TransportToPoint( Double_t Bz, const Double_t xyz[3], Double_t *T0=0 )
+    { 
+      TransportToDS( Bz,GetDStoPoint(Bz, xyz, T0), T0 ) ; 
+    }
+
+  void TransportToPoint( Double_t Bz, Double_t x, Double_t y, Double_t z, Double_t *T0=0 )
+    { 
+      Double_t xyz[3] = {x,y,z};
+      TransportToPoint( Bz, xyz, T0 );
+    }
+
+  //* Fit utilities 
+
+  void InitializeCovarianceMatrix();
+
+  void GetGlueMatrix( const Double_t p[3], Double_t G[6], const Double_t *T0=0  ) const ;
+
+  void Filter( const Double_t m[3], const Double_t V[6], const Double_t G[6] );
+
+  //* Other utilities
+
+  void SetDirection( Double_t Direction[3] );
+
+  void RotateCoordinateSystem( Double_t alpha );
+
+  void Get5Parameters( Double_t alpha, Double_t T[6], Double_t C[15] ) const;
+
+ protected:
+
+  Double_t fParam[6]; // Parameters ( x, y, z, px, py, pz ): 3-position and 3-momentum
+  Double_t fCov[21];  // Covariance matrix
+  Double_t fChi2;     // Chi^2
+  Int_t    fNDF;      // Number of Degrees of Freedom
+  Int_t    fSignQ;    // Charge
+
+  ClassDef(AliHLT3DTrackParam, 0);
+
+};
+
+
+#endif
diff --git a/HLT/TPCLib/tracking-ca/AliHLTTPCCACell.cxx b/HLT/TPCLib/tracking-ca/AliHLTTPCCACell.cxx
new file mode 100644 (file)
index 0000000..41499a4
--- /dev/null
@@ -0,0 +1,22 @@
+// @(#) $Id$
+//*************************************************************************
+// This file is property of and copyright by the ALICE HLT Project        * 
+// ALICE Experiment at CERN, All rights reserved.                         *
+//                                                                        *
+// Primary Authors: Jochen Thaeder <thaeder@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 "AliHLTTPCCACell.h"
+
+
+ClassImp(AliHLTTPCCACell);
diff --git a/HLT/TPCLib/tracking-ca/AliHLTTPCCACell.h b/HLT/TPCLib/tracking-ca/AliHLTTPCCACell.h
new file mode 100644 (file)
index 0000000..c54b8c3
--- /dev/null
@@ -0,0 +1,47 @@
+//-*- 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
+ */
+class AliHLTTPCCACell
+{
+ public:
+
+  AliHLTTPCCACell(): fFirstHitRef(0),fNHits(0),fY(0),fZ(0),fErrY(0),fErrZ(0),fIDown(0),fIUp(0),fIUsed(0){}
+
+  Float_t &Y(){ return fY; }
+  Float_t &Z(){ return fZ; }
+  Float_t &ErrY(){ return fErrY; } 
+  Float_t &ErrZ(){ return fErrZ; }
+  
+  Int_t &FirstHitRef(){ return fFirstHitRef; }
+  Int_t &NHits()      { return fNHits; }
+  Int_t &IDown()      { return fIDown; }
+  Int_t &IUp()        { return fIUp; }
+  Int_t &IUsed()      { return fIUsed; }
+ protected:
+
+  Int_t fFirstHitRef;   // index of the first cell hit in the cell->hit reference array
+  Int_t fNHits;         // number of hits in the cell
+  Float_t fY, fZ;       // Y and Z coordinates
+  Float_t fErrY, fErrZ; // cell errors in Y and Z
+  Int_t fIDown, fIUp;   // indices of 2 neighboring cells in up & down directions
+  Int_t fIUsed;         // if it is used by a reconstructed track
+
+  ClassDef(AliHLTTPCCACell,1);
+};
+
+
+#endif
diff --git a/HLT/TPCLib/tracking-ca/AliHLTTPCCADisplay.cxx b/HLT/TPCLib/tracking-ca/AliHLTTPCCADisplay.cxx
new file mode 100644 (file)
index 0000000..669e708
--- /dev/null
@@ -0,0 +1,440 @@
+// @(#) $Id$
+//*************************************************************************
+// This file is property of and copyright by the ALICE HLT Project        * 
+// ALICE Experiment at CERN, All rights reserved.                         *
+//                                                                        *
+// Primary Authors: Jochen Thaeder <thaeder@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 "AliHLTTPCCADisplay.h"
+
+#include "AliHLTTPCCATracker.h"
+#include "TString.h"
+#include "Riostream.h"
+#include "TMath.h"
+#include "TStyle.h"
+#include "TCanvas.h"
+#include <vector>
+
+ClassImp(AliHLTTPCCADisplay);
+
+AliHLTTPCCADisplay &AliHLTTPCCADisplay::Instance()
+{
+  // reference to static object
+  static AliHLTTPCCADisplay gAliHLTTPCCADisplay;
+  return gAliHLTTPCCADisplay; 
+}
+
+AliHLTTPCCADisplay::AliHLTTPCCADisplay() : fXY(0), fZY(0), fAsk(1), fSectorView(1), fSector(0), 
+                                          fCos(1), fSin(0), fZMin(-250), fZMax(250),
+                                          fRInnerMin(83.65), fRInnerMax(133.3), fROuterMin(133.5), fROuterMax(247.7),
+                                          fTPCZMin(-250.), fTPCZMax(250), fArc(), fLine(), fPLine(), fMarker(), fBox(), fCrown(), fLatex()
+{
+  // constructor
+}
+
+AliHLTTPCCADisplay::AliHLTTPCCADisplay( const AliHLTTPCCADisplay& ) 
+  : fXY(0), fZY(0), fAsk(1), fSectorView(1), fSector(0), 
+    fCos(1), fSin(0), fZMin(-250), fZMax(250),
+    fRInnerMin(83.65), fRInnerMax(133.3), fROuterMin(133.5), fROuterMax(247.7),
+    fTPCZMin(-250.), fTPCZMax(250), fArc(), fLine(), fPLine(), fMarker(), fBox(), fCrown(), fLatex()
+{
+  // dummy
+}
+
+AliHLTTPCCADisplay& AliHLTTPCCADisplay::operator=( const AliHLTTPCCADisplay& )
+{
+  // dummy
+  return *this;
+}
+AliHLTTPCCADisplay::~AliHLTTPCCADisplay()
+{
+  // destructor
+  delete fXY; 
+  delete fZY;
+}
+
+void AliHLTTPCCADisplay::Init()
+{
+  // initialization
+  gStyle->SetCanvasBorderMode(0);
+  gStyle->SetCanvasBorderSize(1);
+  gStyle->SetCanvasColor(0);
+  fXY = new TCanvas ("XY", "XY window", -1, 0, 600, 600);
+  fZY = new TCanvas ("ZY", "ZY window", -610, 0, 590, 600);  
+  fMarker = TMarker(0.0, 0.0, 6);
+}
+
+void AliHLTTPCCADisplay::Update()
+{
+  // update windows
+  if( !fAsk ) return;
+  fXY->Update();
+  fZY->Update();
+}
+
+void AliHLTTPCCADisplay::Clear()
+{
+  // clear windows
+  fXY->Clear();
+  fZY->Clear();
+}
+
+void AliHLTTPCCADisplay::Ask()
+{
+  // whait for the pressed key, when "r" pressed, don't ask anymore
+  char symbol;
+  if (fAsk){
+    Update();
+    cout<<"ask> "<<endl;
+    do{
+      cin.get(symbol);
+      if (symbol == 'r')
+       fAsk = false;
+    } while (symbol != '\n');
+  }
+}
+
+
+void AliHLTTPCCADisplay::SetSectorView()
+{
+  // switch to sector view
+  fSectorView = 1;
+}
+
+void AliHLTTPCCADisplay::SetTPCView()
+{
+  // switch to full TPC view
+  fSectorView = 0;
+  fCos = 1;
+  fSin = 0;
+  fZMin = fTPCZMin;
+  fZMax = fTPCZMax;
+}
+
+void AliHLTTPCCADisplay::SetCurrentSector( AliHLTTPCCATracker *sec )
+{
+  // set reference to the current CA tracker, and read the current sector geometry
+  fSector = sec;
+  if( fSectorView ){
+    fCos = sec->Param().SinAlpha();
+    fSin = - sec->Param().CosAlpha();
+    fZMin = sec->Param().ZMin();
+    fZMax = sec->Param().ZMax();
+    Clear();
+    Double_t r0 = .5*(sec->Param().RMax()+sec->Param().RMin());
+    Double_t dr = .5*(sec->Param().RMax()-sec->Param().RMin());
+    Double_t cx = 0;
+    Double_t cy = r0;
+
+    fXY->Range(cx-dr, cy-dr, cx+dr, cy+dr);
+    Double_t cz = .5*(sec->Param().ZMax()+sec->Param().ZMin());
+    Double_t dz = .5*(sec->Param().ZMax()-sec->Param().ZMin())*1.2;
+    fZY->Range(cz-dz, cy-dr, cz+dz, cy+dr);
+  }
+}
+
+Int_t AliHLTTPCCADisplay::GetColor( Double_t z ) const 
+{
+  // Get color with respect to Z coordinate
+  const Color_t kMyColor[11] = { kGreen, kBlue, kYellow, kMagenta, kCyan, 
+                               kOrange, kSpring, kTeal, kAzure, kViolet, kPink };
+
+  Double_t zz = (z-fZMin)/(fZMax-fZMin);    
+  Int_t iz = (int) (zz*11);
+  if( iz<0 ) iz = 0;
+  if( iz>10 ) iz = 10;
+  return kMyColor[iz]-4;
+}
+
+void AliHLTTPCCADisplay::Global2View( Double_t x, Double_t y, Double_t *xv, Double_t *yv ) const
+{
+  // convert coordinates global->view
+  *xv = x*fCos + y*fSin;
+  *yv = y*fCos - x*fSin;
+}
+
+void AliHLTTPCCADisplay::Sec2View( Double_t x, Double_t y, Double_t *xv, Double_t *yv ) const
+{
+  // convert coordinates sector->view
+  Double_t xg = x*fSector->Param().CosAlpha() - y*fSector->Param().SinAlpha();
+  Double_t yg = y*fSector->Param().CosAlpha() + x*fSector->Param().SinAlpha();
+  *xv = xg*fCos + yg*fSin;
+  *yv = yg*fCos - xg*fSin;
+}
+
+
+void AliHLTTPCCADisplay::DrawTPC()
+{
+  // schematically draw TPC detector
+  fXY->Range(-fROuterMax, -fROuterMax, fROuterMax, fROuterMax);
+  fXY->Clear();
+  {
+    fArc.SetLineColor(kBlack);
+    fArc.SetFillStyle(0);
+    fXY->cd();    
+    for( Int_t iSec=0; iSec<18; iSec++){
+      fCrown.SetLineColor(kBlack);
+      fCrown.SetFillStyle(0);
+      fCrown.DrawCrown(0,0,fRInnerMin, fRInnerMax, 360./18.*iSec, 360./18.*(iSec+1) );
+      fCrown.DrawCrown(0,0,fROuterMin, fROuterMax, 360./18.*iSec, 360./18.*(iSec+1) );
+    }
+  }
+  fZY->cd();
+  fZY->Range( fTPCZMin, -fROuterMax, fTPCZMax, fROuterMax );
+  fZY->Clear();
+}
+
+void AliHLTTPCCADisplay::DrawSector( AliHLTTPCCATracker *sec )
+{     
+  // draw current the TPC sector
+  fXY->cd();
+  Double_t r0 = .5*(sec->Param().RMax()+sec->Param().RMin());
+  Double_t dr = .5*(sec->Param().RMax()-sec->Param().RMin());
+  Double_t cx = r0*sec->Param().CosAlpha();
+  Double_t cy = r0*sec->Param().SinAlpha();
+  Double_t raddeg = 180./3.1415;
+  Double_t a0 = raddeg*.5*(sec->Param().AngleMax() + sec->Param().AngleMin());
+  Double_t da = raddeg*.5*(sec->Param().AngleMax() - sec->Param().AngleMin());
+  if( fSectorView ){
+    cx = 0; cy = r0;
+    a0 = 90.;
+    fLatex.DrawLatex(cx-dr+dr*.05,cy-dr+dr*.05, Form("Sec.%2i",sec->Param().ISec()));
+  }
+  fArc.SetLineColor(kBlack);
+  fArc.SetFillStyle(0);     
+  fCrown.SetLineColor(kBlack);
+  fCrown.SetFillStyle(0);
+    
+  fCrown.DrawCrown(0,0, sec->Param().RMin(),sec->Param().RMax(), a0-da, a0+da );
+
+  fLine.SetLineColor(kBlack);
+  fZY->cd();
+
+  Double_t cz = .5*(sec->Param().ZMax()+sec->Param().ZMin());
+  Double_t dz = .5*(sec->Param().ZMax()-sec->Param().ZMin())*1.2;
+  //fLine.DrawLine(cz+dz, cy-dr, cz+dz, cy+dr ); 
+  if( fSectorView ) fLatex.DrawLatex(cz-dz+dz*.05,cy-dr+dr*.05, Form("Sec.%2i",sec->Param().ISec()));
+}
+
+
+void AliHLTTPCCADisplay::DrawHit( Int_t iRow, Int_t iHit, Int_t color )
+{
+  // draw hit
+  if( !fSector ) return;
+  AliHLTTPCCARow &row = fSector->Rows()[iRow];
+  AliHLTTPCCAHit *h = &(row.Hits()[iHit]);
+  if( color<0 ) color = GetColor( h->Z() );
+
+  Double_t dgy = 3.*TMath::Abs(h->ErrY()*fSector->Param().CosAlpha() - fSector->Param().ErrX()*fSector->Param().SinAlpha() );
+  Double_t dx = fSector->Param().ErrX()*TMath::Sqrt(12.)/2.;
+  Double_t dy = h->ErrY()*3.;
+  Double_t dz = h->ErrZ()*3.;
+  fMarker.SetMarkerColor(color);
+  fArc.SetLineColor(color);
+  fArc.SetFillStyle(0);
+  Double_t vx, vy;
+  Sec2View( row.X(), h->Y(), &vx, &vy );
+  
+  fXY->cd();
+  if( fSectorView ) fArc.DrawEllipse( vx, vy, dx, dy, 0,360, 90);
+  else  fArc.DrawEllipse( vx, vy, dx, dy, 0,360, fSector->Param().Alpha()*180./3.1415);
+  fMarker.DrawMarker(vx, vy);
+  fZY->cd();
+  if( fSectorView ) fArc.DrawEllipse( h->Z(), vy, dz, dx, 0,360, 90 );
+  else fArc.DrawEllipse( h->Z(), vy, dz, dgy, 0,360, fSector->Param().Alpha()*180./3.1415);
+  fMarker.DrawMarker(h->Z(), vy); 
+}
+
+void AliHLTTPCCADisplay::DrawCell( Int_t iRow, AliHLTTPCCACell &cell, Int_t width, Int_t color )
+{
+  // draw cell
+  AliHLTTPCCARow &row = fSector->Rows()[iRow];
+  Double_t vx, vy, vdx, vdy;
+  Sec2View(row.X(), cell.Y(), &vx, &vy);
+  Sec2View(0, cell.ErrY()*3, &vdx, &vdy);
+  if( color<0 ) color = GetColor(cell.Z());
+  fLine.SetLineColor(color);
+  fLine.SetLineWidth(width);
+  fXY->cd();
+  fLine.DrawLine(vx-vdx,vy-vdy, vx+vdx, vy+vdy );
+  fZY->cd();
+  fLine.DrawLine(cell.Z()-3*cell.ErrZ(),vy-vdy, cell.Z()+3*cell.ErrZ(), vy+vdy ); 
+  fLine.SetLineWidth(1);
+}
+
+void  AliHLTTPCCADisplay::DrawCell( Int_t iRow, Int_t iCell, Int_t width, Int_t color )
+{
+  // draw cell
+  AliHLTTPCCARow &row = fSector->Rows()[iRow];
+  DrawCell( iRow, row.Cells()[iCell], width, color );
+}
+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 = fSector->Rows()[iRow1];
+  AliHLTTPCCARow &row2 = fSector->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();
+  Double_t z12 = h12.Z();
+  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();
+  Double_t z22 = h22.Z();
+
+  Double_t vx11, vx12, vy11, vy12, vx21, vx22, vy21, vy22;
+
+  Sec2View(x11,y11, &vx11, &vy11 );
+  Sec2View(x12,y12, &vx12, &vy12 );
+  Sec2View(x21,y21, &vx21, &vy21 );
+  Sec2View(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. );
+  fPLine.SetLineColor(color);    
+  fPLine.SetLineWidth(1);        
+  //fPLine.SetFillColor(color);
+  fPLine.SetFillStyle(-1);
+  fXY->cd();
+  fPLine.DrawPolyLine(5, lx, ly );
+  fZY->cd();
+  fPLine.DrawPolyLine(5, lz, ly );   
+  DrawCell( iRow1, cell1, 1, color );
+  DrawCell( iRow2, cell2, 1, color );
+}
+
+
+Bool_t CompareCellDS( const pair<int,double> &a, const pair<int,double> &b )
+{
+  // function used to sort cells track along trajectory, pair<cell index, track length>
+  return (a.second<b.second);
+}
+
+void AliHLTTPCCADisplay::DrawTrack( AliHLTTPCCATrack &track, Int_t color )
+{
+  // draw track
+  if( track.NCells()<2 ) return;
+
+  Double_t b = -5;    
+
+  std::vector<pair<int,double> > vCells;
+  AliHLTTPCCATrackPar t = track.Param();
+  for( Int_t iCell=0; iCell<track.NCells(); iCell++ ){
+    AliHLTTPCCACell &c = fSector->GetTrackCell(track,iCell);
+    AliHLTTPCCARow &row = fSector->GetTrackCellRow(track,iCell);
+    Double_t xyz[3] = {row.X(), c.Y(), c.Z()};
+    if( iCell==0 ) t.TransportBz(-5, xyz);
+    pair<int,double> tmp(iCell, t.GetDsToPointBz(-5.,xyz));
+    vCells.push_back(tmp);
+  }
+  sort(vCells.begin(), vCells.end(), CompareCellDS );
+  t.Normalize();
+  const Double_t kCLight = 0.000299792458;
+  Double_t bc = b*kCLight;
+  Double_t pt = sqrt(t.Par()[3]*t.Par()[3] +t.Par()[4]*t.Par()[4] );
+  //Double_t p = sqrt(pt*pt +t.Par()[5]*t.Par()[5] );
+  Double_t q = t.Par()[6];
+
+  //for( Int_t iCell=0; iCell<track.fNCells-1; iCell++ )
+  {    
+    AliHLTTPCCACell &c1 = fSector->GetTrackCell(track,vCells[0].first);
+    AliHLTTPCCACell &c2 = fSector->GetTrackCell(track,vCells[track.NCells()-1].first);
+    AliHLTTPCCARow &row1 = fSector->GetTrackCellRow(track,vCells[0].first);
+    AliHLTTPCCARow &row2 = fSector->GetTrackCellRow(track,vCells[track.NCells()-1].first);
+    if( color<0 ) color = GetColor( (c1.Z()+c2.Z())/2. );
+    Double_t vx1, vy1, vx2, vy2;
+    Sec2View(row1.X(), c1.Y(), &vx1, &vy1 );
+    Sec2View(row2.X(), c2.Y(), &vx2, &vy2 );
+    
+    fLine.SetLineColor( color );
+    fLine.SetLineWidth(3);
+    
+    if( fabs(q)>.1 ){
+      Double_t qq = pt/q;
+      
+      Double_t xc = t.Par()[0] + qq*t.Par()[4]/pt/bc;
+      Double_t yc = t.Par()[1] - qq*t.Par()[3]/pt/bc;
+      Double_t r = fabs(qq)/fabs(bc);
+       
+      Double_t vx, vy;
+      Sec2View( xc, yc, &vx, &vy );
+      
+      Double_t a1 = TMath::ATan2(vy1-vy, vx1-vx)/TMath::Pi()*180.;
+      Double_t a2 = TMath::ATan2(vy2-vy, vx2-vx)/TMath::Pi()*180.;
+      Double_t da= a2-a1;      
+      if( da>=180 ) da=360-da;
+      if( da<=-180 ) da=360-da;
+      a1 = a2-da;
+      fArc.SetFillStyle(0);
+      fArc.SetLineColor(color);    
+      fArc.SetLineWidth(3);        
+      
+      fXY->cd();
+      
+      fArc.DrawArc(vx,vy,r, a1,a2,"only");
+    } else {
+      fXY->cd();
+      fLine.DrawLine(vx1,vy1, vx2, vy2 );
+    }
+  }
+
+  for( Int_t iCell=0; iCell<track.NCells()-1; iCell++ ){
+    
+    AliHLTTPCCACell &c1 = fSector->GetTrackCell(track,vCells[iCell].first);
+    AliHLTTPCCACell &c2 = fSector->GetTrackCell(track,vCells[iCell+1].first);
+    AliHLTTPCCARow &row1 = fSector->GetTrackCellRow(track,vCells[iCell].first);
+    AliHLTTPCCARow &row2 = fSector->GetTrackCellRow(track,vCells[iCell+1].first);
+    Double_t x1, y1, z1, x2, y2, z2;
+    {
+      Double_t xyz[3] = {row1.X(), c1.Y(), c1.Z()};
+      t.TransportBz(-5, xyz);
+      x1 = t.Par()[0]; y1 = t.Par()[1]; z1 = t.Par()[2];
+    }
+    {
+      Double_t xyz[3] = {row2.X(), c2.Y(), c2.Z()};
+      t.TransportBz(-5, xyz);
+      x2 = t.Par()[0]; y2 = t.Par()[1]; z2 = t.Par()[2];
+    }
+   
+    Double_t vx1, vy1, vx2, vy2;
+    Sec2View(x1, y1, &vx1, &vy1 );
+    Sec2View(x2, y2, &vx2, &vy2 );
+    
+    fLine.SetLineColor(color);
+    fLine.SetLineWidth(1);
+    
+    fZY->cd();
+    fLine.DrawLine(z1,vy1, z2, vy2 ); 
+  }
+  fLine.SetLineWidth(1);     
+}
+
diff --git a/HLT/TPCLib/tracking-ca/AliHLTTPCCADisplay.h b/HLT/TPCLib/tracking-ca/AliHLTTPCCADisplay.h
new file mode 100644 (file)
index 0000000..554fd9c
--- /dev/null
@@ -0,0 +1,84 @@
+//-*- 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 ALIHLTTPCCADISPLAY_H
+#define ALIHLTTPCCADISPLAY_H
+
+class AliHLTTPCCATracker;
+class AliHLTTPCCACell;
+class AliHLTTPCCATrack;
+
+#include "TCanvas.h"
+#include "TArc.h"
+#include "TLine.h"
+#include "TPolyLine.h"
+#include "TBox.h"
+#include "TCrown.h"
+#include "TMarker.h"
+#include "TLatex.h"
+
+
+/**
+ * @class AliHLTTPCCADisplay
+ */
+class AliHLTTPCCADisplay
+{
+ public:
+
+  static AliHLTTPCCADisplay &Instance();
+  
+  AliHLTTPCCADisplay();
+  AliHLTTPCCADisplay( const AliHLTTPCCADisplay& );
+  AliHLTTPCCADisplay& operator=(const AliHLTTPCCADisplay&);
+
+  virtual ~AliHLTTPCCADisplay();
+
+  void Init();
+  void Update();
+  void Clear();
+  void Ask();
+  void SetSectorView();
+  void SetTPCView();
+  void SetCurrentSector( AliHLTTPCCATracker *sec ); 
+
+  Int_t GetColor( Double_t z ) const ;
+  void Global2View( Double_t x, Double_t y, Double_t *xv, Double_t *yv ) const ;
+  void Sec2View( Double_t x, Double_t y, Double_t *xv, Double_t *yv ) const ;
+
+  void DrawTPC();
+  void DrawSector( AliHLTTPCCATracker *sec ); 
+
+  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 ConnectCells( Int_t iRow1, AliHLTTPCCACell &cell1, Int_t iRow2, AliHLTTPCCACell &cell2, Int_t color=-1 );
+
+  void DrawTrack( AliHLTTPCCATrack &track, Int_t color=-1 );
+
+ protected:
+
+  TCanvas *fXY, *fZY;               // two views
+  Bool_t fAsk;                      // flag to ask for the pressing key
+  Bool_t fSectorView;               // switch between sector/TPC zoomv
+  AliHLTTPCCATracker *fSector;      // current CA tracker, includes sector geometry
+  Double_t fCos, fSin, fZMin, fZMax;// view parameters
+  Double_t fRInnerMin, fRInnerMax, fROuterMin, fROuterMax,fTPCZMin, fTPCZMax; // view parameters
+
+  TArc fArc;       // parameters of drawing objects are copied from this members
+  TLine fLine;     //!
+  TPolyLine fPLine;//!
+  TMarker fMarker; //!
+  TBox fBox;       //!
+  TCrown fCrown;   //!
+  TLatex fLatex;   //!
+
+  ClassDef(AliHLTTPCCADisplay,1);
+
+};
+
+#endif
diff --git a/HLT/TPCLib/tracking-ca/AliHLTTPCCAHit.cxx b/HLT/TPCLib/tracking-ca/AliHLTTPCCAHit.cxx
new file mode 100644 (file)
index 0000000..3324c89
--- /dev/null
@@ -0,0 +1,33 @@
+// @(#) $Id$
+//*************************************************************************
+// This file is property of and copyright by the ALICE HLT Project        * 
+// ALICE Experiment at CERN, All rights reserved.                         *
+//                                                                        *
+// Primary Authors: Jochen Thaeder <thaeder@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 "AliHLTTPCCAHit.h"
+
+
+ClassImp(AliHLTTPCCAHit);
+
+void AliHLTTPCCAHit::Set( Int_t ID, Double_t Y, Double_t Z, 
+                         Double_t ErrY, Double_t ErrZ  )
+{
+  // set parameters
+  fID = ID;
+  fY = Y;
+  fZ = Z;
+  fErrY = ErrY;
+  fErrZ = ErrZ;
+}
diff --git a/HLT/TPCLib/tracking-ca/AliHLTTPCCAHit.h b/HLT/TPCLib/tracking-ca/AliHLTTPCCAHit.h
new file mode 100644 (file)
index 0000000..0101bb4
--- /dev/null
@@ -0,0 +1,44 @@
+//-*- 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 ALIHLTTPCCAHIT_H
+#define ALIHLTTPCCAHIT_H
+
+
+#include "Rtypes.h"
+
+/**
+ * @class AliHLTTPCCAHit
+ */
+class AliHLTTPCCAHit
+{
+ public:
+  AliHLTTPCCAHit(): fY(0),fZ(0),fErrY(0),fErrZ(0),fID(0){;}
+
+  Float_t &Y(){ return fY; }
+  Float_t &Z(){ return fZ; }
+  Float_t &ErrY(){ return fErrY; } 
+  Float_t &ErrZ(){ return fErrZ; }
+  
+  Int_t &ID(){ return fID; }
+  void Set( Int_t ID, Double_t Y, Double_t Z, 
+           Double_t ErrY, Double_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 ID of this hit, 
+                        // used as cluster index in track->hit reference array
+  
+
+  ClassDef(AliHLTTPCCAHit,1);
+};
+
+
+#endif
diff --git a/HLT/TPCLib/tracking-ca/AliHLTTPCCAOutTrack.cxx b/HLT/TPCLib/tracking-ca/AliHLTTPCCAOutTrack.cxx
new file mode 100644 (file)
index 0000000..067aa45
--- /dev/null
@@ -0,0 +1,22 @@
+// @(#) $Id$
+//*************************************************************************
+// This file is property of and copyright by the ALICE HLT Project        * 
+// ALICE Experiment at CERN, All rights reserved.                         *
+//                                                                        *
+// Primary Authors: Jochen Thaeder <thaeder@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 "AliHLTTPCCAOutTrack.h"
+
+
+ClassImp(AliHLTTPCCAOutTrack);
diff --git a/HLT/TPCLib/tracking-ca/AliHLTTPCCAOutTrack.h b/HLT/TPCLib/tracking-ca/AliHLTTPCCAOutTrack.h
new file mode 100644 (file)
index 0000000..af92a93
--- /dev/null
@@ -0,0 +1,37 @@
+//-*- 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 ALIHLTTPCCAOUTTRACK_H
+#define ALIHLTTPCCAOUTTRACK_H
+
+#include "Rtypes.h"
+#include "AliHLTTPCCATrackPar.h"
+
+/**
+ * @class AliHLTTPCCAOutTrack
+ */
+class AliHLTTPCCAOutTrack
+{
+ public:
+
+  AliHLTTPCCAOutTrack():fFirstHitRef(0),fNHits(0),fParam(){}
+  
+  Int_t &NHits()               { return fNHits; }
+  Int_t &FirstHitRef()         { return fFirstHitRef; }
+  AliHLTTPCCATrackPar &Param() { return fParam; }
+
+ protected:
+  
+  Int_t fFirstHitRef;        // index of the first hit reference in track->hit reference array
+  Int_t fNHits;              // number of track hits
+  AliHLTTPCCATrackPar fParam;// fitted track parameters
+
+  ClassDef(AliHLTTPCCAOutTrack,1);
+};
+
+
+#endif
diff --git a/HLT/TPCLib/tracking-ca/AliHLTTPCCAParam.cxx b/HLT/TPCLib/tracking-ca/AliHLTTPCCAParam.cxx
new file mode 100644 (file)
index 0000000..b54c3c5
--- /dev/null
@@ -0,0 +1,90 @@
+// @(#) $Id$
+//*************************************************************************
+// This file is property of and copyright by the ALICE HLT Project        * 
+// ALICE Experiment at CERN, All rights reserved.                         *
+//                                                                        *
+// Primary Authors: Jochen Thaeder <thaeder@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 "AliHLTTPCCAParam.h"
+#include "TMath.h"
+
+
+ClassImp(AliHLTTPCCAParam);
+
+AliHLTTPCCAParam::AliHLTTPCCAParam()
+  : fISec(0),fNRows(63),fRowXFirst(85.225), fRowXStep(0.75),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), fErrZ(0.228808), fErrX(0), fErrY(0),fPadPitch(0.4),fBz(-5.), 
+    fCellConnectionFactor(5), fTrackChiCut(6), fTrackChi2Cut(0), fMaxTrackMatchDRow(3),
+    fYErrorCorrection(0.33), fZErrorCorrection(0.45)
+{
+  Update();
+}
+
+void AliHLTTPCCAParam::Initialize( Int_t iSec, 
+                                  Int_t NRows, 
+                                  Double_t RowXFirst, Double_t RowXStep,
+                                  Double_t Alpha, Double_t DAlpha,
+                                  Double_t RMin, Double_t RMax,
+                                  Double_t ZMin, Double_t ZMax,
+                                  Double_t PadPitch, Double_t ZSigma,
+                                  Double_t Bz
+                                  )
+{
+  // initialization 
+  fISec = iSec;
+  fAlpha = Alpha;
+  fDAlpha = DAlpha;
+  fRMin = RMin;
+  fRMax = RMax;
+  fZMin = ZMin;
+  fZMax = ZMax;
+  fPadPitch = PadPitch;
+  fErrY = 1.; // not in use
+  fErrZ = ZSigma;
+  fBz = Bz;
+  fNRows = NRows;
+  fRowXFirst = RowXFirst;
+  fRowXStep = RowXStep;
+  Update();
+}
+
+void AliHLTTPCCAParam::Update()
+{
+  // update of calculated values
+  fCosAlpha = TMath::Cos(fAlpha);
+  fSinAlpha = TMath::Sin(fAlpha);
+  fAngleMin = fAlpha - fDAlpha/2.;
+  fAngleMax = fAlpha + fDAlpha/2.;
+  fErrX = fPadPitch/TMath::Sqrt(12.);
+  fTrackChi2Cut = fTrackChiCut * fTrackChiCut;
+}
+
+void AliHLTTPCCAParam::Sec2Global(   Double_t x, Double_t y,  Double_t z, 
+                                        Double_t *X, Double_t *Y,  Double_t *Z ) const
+{  
+  // conversion of coorinates sector->global
+  *X = x*fCosAlpha - y*fSinAlpha;
+  *Y = y*fCosAlpha + x*fSinAlpha;
+  *Z = z;
+}
+void AliHLTTPCCAParam::Global2Sec( Double_t X, Double_t Y,  Double_t Z, 
+                                  Double_t *x, Double_t *y,  Double_t *z ) const
+{
+  // conversion of coorinates global->sector
+  *x = X*fCosAlpha + Y*fSinAlpha;
+  *y = Y*fCosAlpha - X*fSinAlpha;
+  *z = Z;
+}
diff --git a/HLT/TPCLib/tracking-ca/AliHLTTPCCAParam.h b/HLT/TPCLib/tracking-ca/AliHLTTPCCAParam.h
new file mode 100644 (file)
index 0000000..bdb6a10
--- /dev/null
@@ -0,0 +1,87 @@
+//-*- 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 ALIHLTTPCCAPARAM_H
+#define ALIHLTTPCCAPARAM_H
+
+#include "Rtypes.h"
+
+/**
+ * @class ALIHLTTPCCAParam
+ * parameters of the CATracker, including geometry information
+ * and some reconstructon constants.
+ */
+class AliHLTTPCCAParam
+{
+ public:
+
+  AliHLTTPCCAParam();
+  virtual ~AliHLTTPCCAParam(){;}
+
+  void Initialize( Int_t iSec, Int_t NRows, Double_t RowXFirst, Double_t RowXStep,
+                  Double_t Alpha, Double_t DAlpha,
+                  Double_t RMin, Double_t RMax, Double_t ZMin, Double_t ZMax,
+                  Double_t PadPitch, Double_t ZSigma, Double_t Bz );
+  void Update();
+
+  void Sec2Global( Double_t x, Double_t y,  Double_t z, 
+                  Double_t *X, Double_t *Y,  Double_t *Z ) const;
+  void Global2Sec( Double_t x, Double_t y,  Double_t z, 
+                  Double_t *X, Double_t *Y,  Double_t *Z ) const;
+  Int_t &ISec(){ return fISec;}
+  Int_t &NRows(){ return fNRows;}
+  Double_t &RowXFirst(){ return fRowXFirst; }
+  Double_t &RowXStep(){ return fRowXStep; }
+  
+  Double_t &Alpha(){ return fAlpha;}
+  Double_t &DAlpha(){ return fDAlpha;}
+  Double_t &CosAlpha(){ return fCosAlpha;}
+  Double_t &SinAlpha(){ return fSinAlpha;}
+  Double_t &AngleMin(){ return fAngleMin;}
+  Double_t &AngleMax(){ return fAngleMax;}
+  Double_t &RMin(){ return fRMin;}
+  Double_t &RMax(){ return fRMax;}
+  Double_t &ZMin(){ return fZMin;}
+  Double_t &ZMax(){ return fZMax;}
+  Double_t &ErrZ(){ return fErrZ;}
+  Double_t &ErrX(){ return fErrX;}
+  Double_t &ErrY(){ return fErrY;}
+  Double_t &Bz(){ return fBz;}
+
+  Double_t &CellConnectionFactor(){ return fCellConnectionFactor; }
+  Double_t &TrackChiCut() { return fTrackChiCut; }
+  Double_t  TrackChi2Cut(){ return fTrackChi2Cut; }
+  Int_t    &MaxTrackMatchDRow(){ return fMaxTrackMatchDRow; }
+  Double_t &YErrorCorrection(){ return fYErrorCorrection; }
+  Double_t &ZErrorCorrection(){ return fZErrorCorrection; }
+
+ protected:
+
+  Int_t fISec; // sector number
+  Int_t fNRows; // number of rows
+  Double_t fRowXFirst, fRowXStep; // X coordinate of the first row and step between rows
+  Double_t fAlpha, fDAlpha; // sector angle and angular size
+  Double_t fCosAlpha, fSinAlpha;// sign and cosine of the sector angle
+  Double_t fAngleMin, fAngleMax; // minimal and maximal angle
+  Double_t fRMin, fRMax;// sector R range
+  Double_t fZMin, fZMax;// sector Z range
+  Double_t fErrZ, fErrX, fErrY;// default cluster errors
+  Double_t fPadPitch; // pad pitch 
+  Double_t fBz;       // magnetic field value (only constant field can be used)
+
+  Double_t fCellConnectionFactor; // allowed distance in Chi^2/3.5 for neighbouring cells
+  Double_t fTrackChiCut; // cut for track Sqrt(Chi2/NDF);
+  Double_t fTrackChi2Cut;// cut for track Chi^2/NDF
+  Int_t    fMaxTrackMatchDRow;// maximal jump in TPC row for connecting track segments
+  Double_t fYErrorCorrection;// correction factor for Y error of input clusters
+  Double_t fZErrorCorrection;// correction factor for Z error of input clusters
+
+  ClassDef(AliHLTTPCCAParam,1);
+};
+
+
+#endif
diff --git a/HLT/TPCLib/tracking-ca/AliHLTTPCCARow.cxx b/HLT/TPCLib/tracking-ca/AliHLTTPCCARow.cxx
new file mode 100644 (file)
index 0000000..a82370b
--- /dev/null
@@ -0,0 +1,56 @@
+// @(#) $Id$
+//*************************************************************************
+// This file is property of and copyright by the ALICE HLT Project        * 
+// ALICE Experiment at CERN, All rights reserved.                         *
+//                                                                        *
+// Primary Authors: Jochen Thaeder <thaeder@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 "AliHLTTPCCARow.h"
+
+
+ClassImp(AliHLTTPCCARow);
+
+AliHLTTPCCARow::AliHLTTPCCARow() :fHits(0),fCells(0),fCellHitPointers(0),fNHits(0),fNCells(0),fX(0)
+{
+  // constructor
+}
+
+AliHLTTPCCARow::AliHLTTPCCARow( const AliHLTTPCCARow &)
+  :fHits(0),fCells(0),fCellHitPointers(0),fNHits(0),fNCells(0),fX(0)
+{
+  // dummy
+}
+
+AliHLTTPCCARow &AliHLTTPCCARow::operator=( const AliHLTTPCCARow &)
+{
+  // dummy
+  fHits = 0;
+  fCells = 0;
+  fCellHitPointers = 0;
+  fNHits = 0;
+  fNCells = 0;
+  return *this;
+}
+
+void AliHLTTPCCARow::Clear()
+{
+  // clear memory
+  delete[] fHits;
+  delete[] fCells;
+  delete[] fCellHitPointers;
+  fHits = 0;
+  fCells = 0;
+  fCellHitPointers = 0;    
+  fNHits = fNCells = 0;
+}
diff --git a/HLT/TPCLib/tracking-ca/AliHLTTPCCARow.h b/HLT/TPCLib/tracking-ca/AliHLTTPCCARow.h
new file mode 100644 (file)
index 0000000..60d1ff7
--- /dev/null
@@ -0,0 +1,57 @@
+//-*- 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 ALIHLTTPCCAROW_H
+#define ALIHLTTPCCAROW_H
+
+
+#include "Rtypes.h"
+
+#include "AliHLTTPCCAHit.h"
+#include "AliHLTTPCCACell.h"
+
+/**
+ * @class ALIHLTTPCCARow
+ * hit and cells container for one TPC row
+ */
+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; }
+  
+  Int_t &NHits()  { return fNHits; }
+  Int_t &NCells() { return fNCells; }
+  Float_t &X() { return fX; }
+
+  AliHLTTPCCAHit  &GetCellHit( AliHLTTPCCACell &c, Int_t i ){ 
+    //* get hit number i of the cell c
+    return fHits[fCellHitPointers[c.FirstHitRef()+i]]; 
+  }
+
+  void Clear();
+
+ private:
+
+  AliHLTTPCCAHit *fHits;   // hit array
+  AliHLTTPCCACell *fCells; // cell array
+  Int_t *fCellHitPointers; // pointers cell->hits
+  Int_t fNHits, fNCells;   // number of hits and cells
+  Float_t fX;              // X coordinate of the row
+
+  ClassDef(AliHLTTPCCARow,1);
+};
+
+#endif
diff --git a/HLT/TPCLib/tracking-ca/AliHLTTPCCATrack.cxx b/HLT/TPCLib/tracking-ca/AliHLTTPCCATrack.cxx
new file mode 100644 (file)
index 0000000..89a8de7
--- /dev/null
@@ -0,0 +1,22 @@
+// @(#) $Id$
+//*************************************************************************
+// This file is property of and copyright by the ALICE HLT Project        * 
+// ALICE Experiment at CERN, All rights reserved.                         *
+//                                                                        *
+// Primary Authors: Jochen Thaeder <thaeder@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 "AliHLTTPCCATrack.h"
+
+
+ClassImp(AliHLTTPCCATrack);
diff --git a/HLT/TPCLib/tracking-ca/AliHLTTPCCATrack.h b/HLT/TPCLib/tracking-ca/AliHLTTPCCATrack.h
new file mode 100644 (file)
index 0000000..c660262
--- /dev/null
@@ -0,0 +1,43 @@
+//-*- 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 ALIHLTTPCCATRACK_H
+#define ALIHLTTPCCATRACK_H
+
+
+#include "Rtypes.h"
+#include "AliHLTTPCCATrackPar.h"
+
+/**
+ * @class ALIHLTTPCCAtrack
+ */
+class AliHLTTPCCATrack
+{
+ public:
+  AliHLTTPCCATrack():fUsed(0),fNCells(0),fIFirstCell(0),fParam(){}
+
+  static bool CompareSize(const AliHLTTPCCATrack &t1, const AliHLTTPCCATrack &t2 ){
+    return t2.fNCells<t1.fNCells;
+  }
+
+  Bool_t &Used()              { return fUsed; }
+  Int_t  &NCells()            { return fNCells; }
+  Int_t &IFirstCell()         { return fIFirstCell; }
+  AliHLTTPCCATrackPar &Param(){ return fParam; }
+
+ private:
+
+  Bool_t fUsed;       // flag for mark tracks used by the track merger
+  Int_t  fNCells;     // number of track cells
+  Int_t  fIFirstCell; // index of first cell reference in track->cell reference array
+  
+  AliHLTTPCCATrackPar fParam; // fitted track parameters
+
+  ClassDef(AliHLTTPCCATrack,1);
+};
+
+#endif
diff --git a/HLT/TPCLib/tracking-ca/AliHLTTPCCATrackPar.cxx b/HLT/TPCLib/tracking-ca/AliHLTTPCCATrackPar.cxx
new file mode 100644 (file)
index 0000000..8f5c621
--- /dev/null
@@ -0,0 +1,407 @@
+// @(#) $Id$
+//*************************************************************************
+// This file is property of and copyright by the ALICE HLT Project        * 
+// ALICE Experiment at CERN, All rights reserved.                         *
+//                                                                        *
+// Primary Authors: Jochen Thaeder <thaeder@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 "AliHLTTPCCATrackPar.h"
+#include "TMath.h"
+
+ClassImp(AliHLTTPCCATrackPar);
+
+void AliHLTTPCCATrackPar::Init()
+{
+  //* Initialization 
+
+  for( Int_t i=0; i<7; i++ ) fP[i] = 0;
+  for( Int_t i=0; i<28; i++ ) fC[i] = 0;
+  fC[0] = fC[2] = fC[5] = 10000;
+  fC[9] = fC[14] = fC[20] = 10000.;
+  fC[27] = 10.;
+  fChi2 = 0;
+  fNDF = -5;
+}
+
+
+void AliHLTTPCCATrackPar::Normalize( Double_t Direction[3] )
+{
+  //* Normalize the track
+
+  Double_t p2 = fP[3]*fP[3] + fP[4]*fP[4] + fP[5]*fP[5];
+  if( p2<1.e-4 ) return;
+  Double_t a2 = 1./p2;
+  Double_t a = sqrt(a2);
+
+  if( Direction && ( fP[3]*Direction[0] + fP[4]*Direction[1] + fP[5]*Direction[2] < 0 ) ) a = -a;
+  
+  Double_t ex = fP[3]*a, ey = fP[4]*a, ez = fP[5]*a, qp = fP[6]*a;
+
+  fP[3] = ex;
+  fP[4] = ey;
+  fP[5] = ez;
+  fP[6] = qp;
+
+  Double_t 
+    h0 = fC[ 6]*ex + fC[10]*ey + fC[15]*ez,
+    h1 = fC[ 7]*ex + fC[11]*ey + fC[16]*ez, 
+    h2 = fC[ 8]*ex + fC[12]*ey + fC[17]*ez,
+    h3 = fC[ 9]*ex + fC[13]*ey + fC[18]*ez, 
+    h4 = fC[13]*ex + fC[14]*ey + fC[19]*ez, 
+    h5 = fC[18]*ex + fC[19]*ey + fC[20]*ez,
+    h6 = fC[24]*ex + fC[25]*ey + fC[26]*ez,
+    d  = h3*ex + h4*ey + h5*ez, 
+    hh = h6 - qp*d ;
+
+  fC[ 6]= a*(fC[ 6] -ex*h0); fC[ 7]= a*(fC[ 7] -ex*h1); fC[ 8]= a*(fC[ 8] -ex*h2); 
+  fC[10]= a*(fC[10] -ey*h0); fC[11]= a*(fC[11] -ey*h1); fC[12]= a*(fC[12] -ey*h2); 
+  fC[15]= a*(fC[15] -ez*h0); fC[16]= a*(fC[16] -ez*h1); fC[17]= a*(fC[17] -ez*h2); 
+  fC[21]= a*(fC[21] -qp*h0); fC[22]= a*(fC[22] -qp*h1); fC[23]= a*(fC[23] -qp*h2);     
+
+  fC[ 9]= a2*( fC[ 9] -h3*ex -h3*ex + d*ex*ex );
+  fC[13]= a2*( fC[13] -h4*ex -h3*ey + d*ey*ex ); 
+  fC[14]= a2*( fC[14] -h4*ey -h4*ey + d*ey*ey );
+
+  fC[18]= a2*( fC[18] -h5*ex -h3*ez + d*ez*ex ); 
+  fC[19]= a2*( fC[19] -h5*ey -h4*ez + d*ez*ey ); 
+  fC[20]= a2*( fC[20] -h5*ez -h5*ez + d*ez*ez );
+
+  fC[24]= a2*( fC[24] -qp*h3 - hh*ex ); 
+  fC[25]= a2*( fC[25] -qp*h4 - hh*ey ); 
+  fC[26]= a2*( fC[26] -qp*h5 - hh*ez );
+  fC[27]= a2*( fC[27] -qp*h6 - hh*qp  ); 
+}
+
+
+Double_t AliHLTTPCCATrackPar::GetDsToPointBz( Double_t Bz, const Double_t xyz[3], const Double_t *T0 ) const
+{
+  //* Get dS to a certain space point for Bz field
+  const Double_t kCLight = 0.000299792458;
+  Double_t bq = Bz*T0[6]*kCLight;
+  Double_t pt2 = T0[3]*T0[3] + T0[4]*T0[4];
+  if( pt2<1.e-4 ) return 0;
+  Double_t dx = xyz[0] - T0[0];
+  Double_t dy = xyz[1] - T0[1]; 
+  Double_t a = dx*T0[3]+dy*T0[4];
+  Double_t dS = 0;
+  if( TMath::Abs(bq)<1.e-8 ) dS = a/pt2;
+  else dS = TMath::ATan2( bq*a, pt2 + bq*(dy*T0[3] -dx*T0[4]) )/bq;
+  return dS;
+}
+
+Double_t AliHLTTPCCATrackPar::GetDsToPointBz( Double_t Bz, const Double_t xyz[3] ) const 
+{
+  return GetDsToPointBz( Bz, xyz, fP );
+}
+
+void AliHLTTPCCATrackPar::TransportBz( Double_t Bz, Double_t S, Double_t *T0 ) 
+{ 
+  //* Transport the particle on dS, for Bz field
+  const Double_t kCLight = 0.000299792458;
+  Bz = Bz*kCLight;
+  Double_t bs= Bz*S;
+  Double_t bqs= bs*T0[6];
+  Double_t s = TMath::Sin(bqs), c = TMath::Cos(bqs);
+  Double_t sB, cB, dsB, dcB;
+  if( TMath::Abs(bqs)>1.e-10){
+    sB= s/Bz/T0[6];
+    cB= (1-c)/Bz/T0[6];
+    dsB = (c*S - sB)/T0[6];
+    dcB = (s*S-cB)/T0[6];
+  }else{
+    sB = (1. - bqs*bqs/6.)*S;
+    cB = .5*sB*bqs;
+    dsB = - T0[6]*bs*bs/3.*S;
+    dcB = .5*(sB*bs - dsB*bqs);
+  }
+  
+  Double_t px = T0[3];
+  Double_t py = T0[4];
+  Double_t pz = T0[5];
+  
+  Double_t d[7] = { fP[0]-T0[0], fP[1]-T0[1], fP[2]-T0[2], 
+                   fP[3]-T0[3], fP[4]-T0[4], fP[5]-T0[5], fP[6]-T0[6] };
+
+  T0[0] = T0[0] + sB*px + cB*py;
+  T0[1] = T0[1] - cB*px + sB*py;
+  T0[2] = T0[2] +  S*pz                       ;
+  T0[3] =          c*px + s*py;
+  T0[4] =         -s*px + c*py;
+  T0[5] = T0[5];
+  T0[6] = T0[6];
+
+  Double_t mJ[7][7] = { {1,0,0,   sB, cB,  0,   dsB*px + dcB*py },
+                        {0,1,0,  -cB, sB,  0, - dcB*px + dsB*py },
+                        {0,0,1,    0,  0,  S,   0               },
+                        {0,0,0,    c,  s,  0,   (-s*px + c*py)*bs },
+                        {0,0,0,   -s,  c,  0,   (-c*px - s*py)*bs },
+                        {0,0,0,    0,  0,  1,   0                 },
+                        {0,0,0,    0,  0,  0,   1                 }  };
+
+  for( Int_t i=0; i<7; i++){
+    fP[i] = T0[i];
+    for( Int_t j=0; j<7; j++) fP[i] += mJ[i][j]*d[j];
+  }
+
+  Double_t mA[7][7];
+  for( Int_t k=0,i=0; i<7; i++)
+    for( Int_t j=0; j<=i; j++, k++ ) mA[i][j] = mA[j][i] = fC[k]; 
+
+  Double_t mJC[7][7];
+  for( Int_t i=0; i<7; i++ )
+    for( Int_t j=0; j<7; j++ ){
+      mJC[i][j]=0;
+      for( Int_t k=0; k<7; k++ ) mJC[i][j]+=mJ[i][k]*mA[k][j];
+    }
+  
+  for( Int_t k=0,i=0; i<7; i++)
+    for( Int_t j=0; j<=i; j++, k++ ){
+      fC[k] = 0;
+      for( Int_t l=0; l<7; l++ ) fC[k]+=mJC[i][l]*mJ[j][l];
+    }
+}
+
+void AliHLTTPCCATrackPar::TransportBz( Double_t Bz, Double_t dS ) 
+{ 
+  //* Transport the particle on dS, for Bz field
+  TransportBz( Bz, dS, fP );
+}
+
+void AliHLTTPCCATrackPar::GetConnectionMatrix( Double_t B, const Double_t p[3], Double_t G[6], const Double_t *T0  ) const 
+{
+  //* Calculate connection matrix between track and point p
+  if( !G ) return;
+  const Double_t kLight = 0.000299792458;
+  B*=kLight;
+  Double_t dx = p[0]-T0[0], dy = p[1]-T0[1], dz = p[2]-T0[2];
+  Double_t px2= T0[3]*T0[3], py2= T0[4]*T0[4], pz2= T0[5]*T0[5];
+  //Double_t B2 = B*B;
+  Double_t s2 = (dx*dx + dy*dy + dz*dz);
+  Double_t p2 = px2 + py2 + pz2;
+  if( p2>1.e-4 ) s2/=p2;
+  Double_t x = T0[3]*s2;
+  Double_t xx= px2*s2, xy= x*T0[4], xz= x*T0[5], yy= py2*s2, yz= T0[4]*T0[5]*s2;
+  //Double_t Bxy= B*xy; 
+  G[ 0]= xx;
+  G[ 1]= xy;   G[ 2]= yy;
+  G[ 3]= xz;   G[ 4]= yz;   G[ 5]= pz2*s2;  
+  /*
+  C[ 0]+= xx;
+  C[ 1]+= xy;   C[ 2]+= yy;
+  C[ 3]+= xz;   C[ 4]+= yz;   C[ 5]+= pz2*s2;  
+  C[ 6]+= Bxy; C[ 7]+= B*yy; C[ 8]+= B*yz;    C[ 9]+=B2*yy;
+  C[10]-= B*xx; C[11]-= Bxy; C[12]-=B*xz;     C[13]-=B2*xy; C[14]+=B2*xx;  
+  */
+}
+
+
+void AliHLTTPCCATrackPar::Filter( const Double_t m[], const Double_t V[], const Double_t V1[6] )
+{
+  //* !
+  Double_t 
+    c00 = fC[ 0],
+    c10 = fC[ 1], c11 = fC[ 2],
+    c20 = fC[ 3], c21 = fC[ 4], c22 = fC[ 5],
+    c30 = fC[ 6], c31 = fC[ 7], c32 = fC[ 8],
+    c40 = fC[10], c41 = fC[11], c42 = fC[12],
+    c50 = fC[15], c51 = fC[16], c52 = fC[17],
+    c60 = fC[21], c61 = fC[22], c62 = fC[23];
+  
+  double
+    z0 = m[0]-fP[0],
+    z1 = m[1]-fP[1],
+    z2 = m[2]-fP[2];
+  
+  Double_t mS[6] = { c00+V[0]+V1[0], c10+V[1]+V1[1], c11+V[2]+V1[2],
+                    c20+V[3]+V1[3], c21+V[4]+V1[4], c22+V[5]+V1[5] };
+  Double_t mSi[6];
+  mSi[0] = mS[4]*mS[4] - mS[2]*mS[5];
+  mSi[1] = mS[1]*mS[5] - mS[3]*mS[4];
+  mSi[3] = mS[2]*mS[3] - mS[1]*mS[4];
+  Double_t det = (mS[0]*mSi[0] + mS[1]*mSi[1] + mS[3]*mSi[3]);
+  if( TMath::Abs(det)<1.e-10 ) return;
+  det = 1./det;
+  mSi[0] *= det;
+  mSi[1] *= det;
+  mSi[3] *= det;
+  mSi[2] = ( mS[3]*mS[3] - mS[0]*mS[5] )*det;
+  mSi[4] = ( mS[0]*mS[4] - mS[1]*mS[3] )*det;
+  mSi[5] = ( mS[1]*mS[1] - mS[0]*mS[2] )*det;
+  
+  fNDF  += 2;
+  fChi2 += ( +(mSi[0]*z0 + mSi[1]*z1 + mSi[3]*z2)*z0
+           +(mSi[1]*z0 + mSi[2]*z1 + mSi[4]*z2)*z1
+           +(mSi[3]*z0 + mSi[4]*z1 + mSi[5]*z2)*z2 );
+        
+  Double_t k0, k1, k2 ; // k = CHtS
+    
+  k0 = c00*mSi[0] + c10*mSi[1] + c20*mSi[3];
+  k1 = c00*mSi[1] + c10*mSi[2] + c20*mSi[4];
+  k2 = c00*mSi[3] + c10*mSi[4] + c20*mSi[5];
+    
+  fP[ 0]+= k0*z0  + k1*z1  + k2*z2 ;
+  fC[ 0]-= k0*c00 + k1*c10 + k2*c20;
+  
+  k0 = c10*mSi[0] + c11*mSi[1] + c21*mSi[3];
+  k1 = c10*mSi[1] + c11*mSi[2] + c21*mSi[4];
+  k2 = c10*mSi[3] + c11*mSi[4] + c21*mSi[5];
+  
+  fP[ 1]+= k0*z0  + k1*z1  + k2*z2 ;
+  fC[ 1]-= k0*c00 + k1*c10 + k2*c20;
+  fC[ 2]-= k0*c10 + k1*c11 + k2*c21;
+  
+  k0 = c20*mSi[0] + c21*mSi[1] + c22*mSi[3];
+  k1 = c20*mSi[1] + c21*mSi[2] + c22*mSi[4];
+  k2 = c20*mSi[3] + c21*mSi[4] + c22*mSi[5];
+  
+  fP[ 2]+= k0*z0  + k1*z1  + k2*z2 ;
+  fC[ 3]-= k0*c00 + k1*c10 + k2*c20;
+  fC[ 4]-= k0*c10 + k1*c11 + k2*c21;
+  fC[ 5]-= k0*c20 + k1*c21 + k2*c22;
+  
+  k0 = c30*mSi[0] + c31*mSi[1] + c32*mSi[3];
+  k1 = c30*mSi[1] + c31*mSi[2] + c32*mSi[4];
+  k2 = c30*mSi[3] + c31*mSi[4] + c32*mSi[5];
+  
+  fP[ 3]+= k0*z0  + k1*z1  + k2*z2 ;
+  fC[ 6]-= k0*c00 + k1*c10 + k2*c20;
+  fC[ 7]-= k0*c10 + k1*c11 + k2*c21;
+  fC[ 8]-= k0*c20 + k1*c21 + k2*c22;
+  fC[ 9]-= k0*c30 + k1*c31 + k2*c32;
+  
+  k0 = c40*mSi[0] + c41*mSi[1] + c42*mSi[3];
+  k1 = c40*mSi[1] + c41*mSi[2] + c42*mSi[4];
+  k2 = c40*mSi[3] + c41*mSi[4] + c42*mSi[5];
+    
+  fP[ 4]+= k0*z0  + k1*z1  + k2*z2 ;
+  fC[10]-= k0*c00 + k1*c10 + k2*c20;
+  fC[11]-= k0*c10 + k1*c11 + k2*c21;
+  fC[12]-= k0*c20 + k1*c21 + k2*c22;
+  fC[13]-= k0*c30 + k1*c31 + k2*c32;
+  fC[14]-= k0*c40 + k1*c41 + k2*c42;
+
+  k0 = c50*mSi[0] + c51*mSi[1] + c52*mSi[3];
+  k1 = c50*mSi[1] + c51*mSi[2] + c52*mSi[4];
+  k2 = c50*mSi[3] + c51*mSi[4] + c52*mSi[5];
+  
+  fP[ 5]+= k0*z0  + k1*z1  + k2*z2 ;
+  fC[15]-= k0*c00 + k1*c10 + k2*c20;
+  fC[16]-= k0*c10 + k1*c11 + k2*c21;
+  fC[17]-= k0*c20 + k1*c21 + k2*c22;
+  fC[18]-= k0*c30 + k1*c31 + k2*c32;
+  fC[19]-= k0*c40 + k1*c41 + k2*c42;
+  fC[20]-= k0*c50 + k1*c51 + k2*c52;
+
+  k0 = c60*mSi[0] + c61*mSi[1] + c62*mSi[3];
+  k1 = c60*mSi[1] + c61*mSi[2] + c62*mSi[4];
+  k2 = c60*mSi[3] + c61*mSi[4] + c62*mSi[5];
+  
+  fP[ 6]+= k0*z0  + k1*z1  + k2*z2 ;
+  fC[21]-= k0*c00 + k1*c10 + k2*c20;
+  fC[22]-= k0*c10 + k1*c11 + k2*c21;
+  fC[23]-= k0*c20 + k1*c21 + k2*c22;
+  fC[24]-= k0*c30 + k1*c31 + k2*c32;
+  fC[25]-= k0*c40 + k1*c41 + k2*c42;
+  fC[26]-= k0*c50 + k1*c51 + k2*c52;
+  fC[27]-= k0*c60 + k1*c61 + k2*c62;
+}
+
+
+void AliHLTTPCCATrackPar::Rotate( Double_t alpha )
+{
+  //* !
+  Double_t cA = TMath::Cos( alpha );
+  Double_t sA = TMath::Sin( alpha );
+  Double_t x= fP[0], y= fP[1], px= fP[3], py= fP[4];
+  fP[0] = x*cA + y*sA;
+  fP[1] =-x*sA + y*cA;
+  fP[2] = fP[2];
+  fP[3] = px*cA + py*sA;
+  fP[4] =-px*sA + py*cA;
+  fP[5] = fP[5];
+  fP[6] = fP[6];
+
+  Double_t mJ[7][7] = { { cA,sA, 0,  0,  0,  0,  0 },
+                        {-sA,cA, 0,  0,  0,  0,  0 },
+                        {  0, 0, 1,  0,  0,  0,  0 },
+                        {  0, 0, 0, cA, sA,  0,  0 },
+                        {  0, 0, 0,-sA, cA,  0,  0 },
+                        {  0, 0, 0,  0,  0,  1,  0 },
+                        {  0, 0, 0,  0,  0,  0,  1 }  };
+
+  Double_t mA[7][7];
+  for( Int_t k=0,i=0; i<7; i++)
+    for( Int_t j=0; j<=i; j++, k++ ) mA[i][j] = mA[j][i] = fC[k]; 
+
+  Double_t mJC[7][7];
+  for( Int_t i=0; i<7; i++ )
+    for( Int_t j=0; j<7; j++ ){
+      mJC[i][j]=0;
+      for( Int_t k=0; k<7; k++ ) mJC[i][j]+=mJ[i][k]*mA[k][j];
+    }
+  
+  for( Int_t k=0,i=0; i<7; i++)
+    for( Int_t j=0; j<=i; j++, k++ ){
+      fC[k] = 0;
+      for( Int_t l=0; l<7; l++ ) fC[k]+=mJC[i][l]*mJ[j][l];
+    }
+}
+
+
+void AliHLTTPCCATrackPar::ConvertTo5( Double_t alpha, Double_t T[], Double_t C[] )
+const {
+  //* !
+  AliHLTTPCCATrackPar t = *this;
+  t.Rotate(alpha);
+  Double_t 
+    x= t.fP[0], y= t.fP[1], z = t.fP[2], 
+    ex= t.fP[3], ey= t.fP[4], ez = t.fP[5], qp = t.fP[6];
+
+  Double_t p2 = ex*ex+ey*ey+ez*ez;
+  if( p2<1.e-4 ) p2 = 1;
+  Double_t n2 = 1./p2;
+  Double_t n = sqrt(n2);
+
+  T[5] = x;
+  T[0] = y;
+  T[1] = z;
+  T[2] = ey/ex;
+  T[3] = ez/ex;
+  T[4] = qp*n;
+
+  Double_t mJ[5][7] = { { -T[2], 1, 0,  0,  0,  0,  0 },
+                        { -T[3], 0, 1,  0,  0,  0,  0 },
+                        { 0, 0, 0,  -T[2]/ex,  1./ex,  0,  0 },
+                        { 0, 0, 0, -T[3]/ex,  0,  1./ex,  0 },
+                        { 0, 0, 0, -T[4]*n2*ex, -T[4]*n2*ey, -T[4]*n2*ez, n }};
+
+  Double_t mA[7][7];
+  for( Int_t k=0,i=0; i<7; i++)
+    for( Int_t j=0; j<=i; j++, k++ ) mA[i][j] = mA[j][i] = t.fC[k]; 
+
+  Double_t mJC[5][7];
+  for( Int_t i=0; i<5; i++ )
+    for( Int_t j=0; j<7; j++ ){
+      mJC[i][j]=0;
+      for( Int_t k=0; k<7; k++ ) mJC[i][j]+=mJ[i][k]*mA[k][j];
+    }
+  
+  for( Int_t k=0,i=0; i<5; i++)
+    for( Int_t j=0; j<=i; j++, k++ ){
+      C[k] = 0;
+      for( Int_t l=0; l<7; l++ ) C[k]+=mJC[i][l]*mJ[j][l];
+    }
+}
diff --git a/HLT/TPCLib/tracking-ca/AliHLTTPCCATrackPar.h b/HLT/TPCLib/tracking-ca/AliHLTTPCCATrackPar.h
new file mode 100644 (file)
index 0000000..b2a2b31
--- /dev/null
@@ -0,0 +1,70 @@
+//-*- 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 ALIHLTTPCCATRACKPAR_H
+#define ALIHLTTPCCATRACKPAR_H
+
+#include "Rtypes.h"
+
+/**
+ * @class AliHLTTPCCATrackPar
+ */
+class AliHLTTPCCATrackPar {
+ public:
+
+  AliHLTTPCCATrackPar(): fChi2(0), fNDF(0){;}
+
+  Double_t *Par(){ return fP; }
+  Double_t *Cov(){ return fC; }
+  Double_t &Chi2(){ return fChi2; }
+  Int_t &NDF(){ return fNDF; }
+
+  void Init();
+  void Normalize( Double_t Direction[3]=0 );
+
+  void TransportBz( Double_t Bz, Double_t S );
+  void TransportBz( Double_t Bz, Double_t S, Double_t *T0 );
+
+  Double_t GetDsToPointBz( Double_t Bz, const Double_t xyz[3] ) const;
+  Double_t GetDsToPointBz( Double_t Bz, const Double_t xyz[3], const Double_t *T0 ) const;
+
+  void TransportBz( Double_t Bz, const Double_t xyz[3] ){ 
+    TransportBz( Bz,GetDsToPointBz(Bz, xyz)) ; 
+  }
+
+  void TransportBz( Double_t Bz, const Double_t xyz[3], Double_t *T0 ){ 
+    TransportBz( Bz,GetDsToPointBz(Bz, xyz, T0), T0) ; 
+  }
+
+  void TransportBz( Double_t Bz, Double_t x, Double_t y, Double_t z ){ 
+    Double_t xyz[3] = {x,y,z};
+    TransportBz(Bz, xyz);
+  }
+
+  void GetConnectionMatrix( Double_t Bz, const Double_t p[3], Double_t G[6], const Double_t *T0  ) const ;
+
+  void GetConnectionMatrix( Double_t Bz, const Double_t p[3], Double_t G[6] ) const {
+    GetConnectionMatrix( Bz, p, G, fP );
+  }
+
+  void Filter( const Double_t m[3], const Double_t V[6], const Double_t V1[6] );
+  void Rotate( Double_t alpha );
+  void ConvertTo5( Double_t alpha, Double_t T[], Double_t C[] ) const;
+
+ private:
+
+  Double_t fP[7];  // parameters:  X, Y, Z, ex, ey, ez, q/P
+  Double_t fC[28]; // Covariance matrix
+  Double_t fChi2;  // Chi^2
+  Int_t fNDF;      // NDF
+
+  ClassDef(AliHLTTPCCATrackPar, 0);
+
+};
+
+
+#endif
diff --git a/HLT/TPCLib/tracking-ca/AliHLTTPCCATracker.cxx b/HLT/TPCLib/tracking-ca/AliHLTTPCCATracker.cxx
new file mode 100644 (file)
index 0000000..c96cb1d
--- /dev/null
@@ -0,0 +1,553 @@
+// @(#) $Id$
+//*************************************************************************
+// This file is property of and copyright by the ALICE HLT Project        * 
+// ALICE Experiment at CERN, All rights reserved.                         *
+//                                                                        *
+// Primary Authors: Jochen Thaeder <thaeder@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 "AliHLTTPCCAHit.h"
+#include "AliHLTTPCCACell.h"
+#include "AliHLTTPCCAOutTrack.h"
+
+#include "TMath.h"
+//#include "Riostream.h"
+#include <vector>
+#include <algo.h>
+
+//#define DRAW
+
+#ifdef DRAW
+#include "AliHLTTPCCADisplay.h"
+#include "TApplication.h"
+#include "TROOT.h"
+#include "TSystem.h"
+#endif //DRAW
+
+ClassImp(AliHLTTPCCATracker);
+
+
+AliHLTTPCCATracker::AliHLTTPCCATracker()
+  :fParam(),fRows(0),fOutTrackHits(0),fNOutTrackHits(0),fOutTracks(0),fNOutTracks(0),fTrackCells(0),fNHitsTotal(0),fTracks(0),fNTracks(0)
+{
+  // constructor
+  fRows = new AliHLTTPCCARow[fParam.NRows()];
+  Initialize( fParam );
+}
+
+AliHLTTPCCATracker::AliHLTTPCCATracker( const AliHLTTPCCATracker& )
+  :fParam(),fRows(0),fOutTrackHits(0),fNOutTrackHits(0),fOutTracks(0),fNOutTracks(0),fTrackCells(0),fNHitsTotal(0),fTracks(0),fNTracks(0)
+{
+  // dummy
+}
+
+AliHLTTPCCATracker &AliHLTTPCCATracker::operator=( const AliHLTTPCCATracker& )
+{
+  // dummy
+}
+
+AliHLTTPCCATracker::~AliHLTTPCCATracker()
+{
+  // destructor
+  StartEvent();
+  delete[] fRows;
+}
+
+// ----------------------------------------------------------------------------------
+void AliHLTTPCCATracker::Initialize( AliHLTTPCCAParam &param )
+{
+  // initialosation
+  StartEvent();
+  delete[] fRows;
+  fRows = 0;
+  fParam = param;
+  fParam.Update();
+  fRows = new AliHLTTPCCARow[fParam.NRows()];
+  for( Int_t irow=0; irow<fParam.NRows(); irow++ ){
+    fRows[irow].X() = fParam.RowXFirst() + irow*fParam.RowXStep();
+  }
+  StartEvent();
+}
+
+void AliHLTTPCCATracker::StartEvent()
+{
+  // start new event and fresh the memory  
+  delete[] fTracks;
+  delete[] fTrackCells;
+  delete[] fOutTrackHits;
+  delete[] fOutTracks;
+  fTracks = 0;
+  fTrackCells = 0;
+  fOutTrackHits = 0;
+  fOutTracks = 0;
+  fNTracks = 0;
+  fNOutTrackHits = 0;
+  fNOutTracks = 0;
+  fNHitsTotal = 0;
+  for( Int_t irow=0; irow<fParam.NRows(); irow++ ){
+    fRows[irow].Clear();
+  }
+}
+
+
+void AliHLTTPCCATracker::ReadHitRow( Int_t iRow, AliHLTTPCCAHit *Row, Int_t NHits )
+{
+  // 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;
+}
+
+void AliHLTTPCCATracker::Reconstruct()
+{
+  // reconstruction of event
+  FindCells();
+  FindTracks();
+}
+
+
+void AliHLTTPCCATracker::FindCells()
+{
+  // cell finder - neighbouring hits are grouped to cells
+
+  for( Int_t irow=0; irow<fParam.NRows(); irow++ ){
+    AliHLTTPCCARow &row=fRows[irow];
+    Int_t nHits = row.NHits();
+    if( nHits<1 ) continue;
+    row.CellHitPointers() = new Int_t[ nHits ];
+    Int_t nPointers = 0;
+    std::vector<AliHLTTPCCACell> vCells; 
+    Bool_t vUsed[10000];
+    for (Int_t ih = 0; ih<nHits; ih++) vUsed[ih] = 0;
+  
+    for (Int_t ih = 0; ih<nHits; ih++){    
+      if( vUsed[ih] ) continue;
+      // cell start
+      AliHLTTPCCACell cell;
+      cell.FirstHitRef() = nPointers;
+      cell.NHits() = 1;
+      cell.IDown() = -1;
+      cell.IUp() = -1;
+      cell.IUsed() = 0;
+      row.CellHitPointers()[nPointers++] = ih;
+      vUsed[ih] = 1;
+      Int_t jLast = ih;
+      while( jLast<nHits-1 ){
+       AliHLTTPCCAHit &h  = row.Hits()[jLast];    
+       Double_t d2min = 1.e10;
+       Int_t jBest = -1;
+       for (Int_t j = jLast+1; j<nHits; j++){    
+         if( vUsed[j] ) continue;
+         AliHLTTPCCAHit &h1  = row.Hits()[j];
+         Double_t dy = TMath::Abs(h.Y() - h1.Y() );
+         if( dy>(h.ErrY()+h1.ErrY())*4. ) break;
+         Double_t dz = TMath::Abs(h.Z() - h1.Z() );
+         if( dz>(h.ErrZ()+h1.ErrZ())*4. ) continue;
+         Double_t d2 = dz*dz+dy*dy;
+         if( d2<d2min ){
+           d2min = d2;
+           jBest = j;
+         }
+       }
+       if( jBest<0 ) break;
+       row.CellHitPointers()[nPointers++] = jBest;
+       cell.NHits()++;
+       vUsed[jBest] = 1;     
+       jLast = jBest;
+      }
+
+      AliHLTTPCCAHit &h = row.GetCellHit(cell,0);
+      AliHLTTPCCAHit &h1= row.GetCellHit(cell,cell.NHits()-1);
+    
+      cell.Y() = .5*(h.Y() + h1.Y());
+      cell.Z() = .5*(h.Z() + h1.Z());
+      cell.ErrY() = .5*(TMath::Abs(h.Y() - h1.Y())/3 + h.ErrY() + h1.ErrY());
+      cell.ErrZ() = .5*(TMath::Abs(h.Z() - h1.Z())/3 + h.ErrZ() + h1.ErrZ());
+      vCells.push_back(cell);
+    }
+    
+    row.Cells() = new AliHLTTPCCACell[vCells.size()];
+    row.NCells() = vCells.size();
+    for( Int_t i=0; i<vCells.size(); i++ ) row.Cells()[i]=vCells[i];  
+  }
+}
+
+
+void AliHLTTPCCATracker::FindTracks()
+{
+  // the Cellular Automaton track finder
+  
+  if( fNHitsTotal < 1 ) return;
+
+#ifdef DRAW
+  if( !gApplication ){
+    TApplication *myapp = new TApplication("myapp",0,0);
+  }
+  AliHLTTPCCADisplay::Instance().SetCurrentSector( this );
+  AliHLTTPCCADisplay::Instance().DrawSector( this );
+  //for (Int_t i = 0; i<fHits.size(); i++) AliHLTTPCCADisplay::Instance().DrawHit( i );
+  //cout<<"hits"<<endl;
+  //AliHLTTPCCADisplay::Instance().Ask();
+  //AliHLTTPCCADisplay::Instance().Clear();
+  //AliHLTTPCCADisplay::Instance().DrawSector( 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<<"cells"<<endl;
+  AliHLTTPCCADisplay::Instance().Ask();
+  Int_t nConnectedCells = 0;
+#endif 
+
+  std::vector<AliHLTTPCCATrack> vTracks; 
+  std::vector<Int_t> vTrackCells; 
+  fTrackCells = new Int_t[2*fNHitsTotal];
+
+  for( Int_t iRow1=0; iRow1<fParam.NRows()-1; iRow1++ ){
+    AliHLTTPCCARow &row1 = fRows[iRow1];
+    Int_t lastRow2 = iRow1+3;
+    if( lastRow2>=fParam.NRows() ) lastRow2 = fParam.NRows()-1;    
+    for( Int_t iRow2=iRow1+1; iRow2<=lastRow2; iRow2++ ){
+      AliHLTTPCCARow &row2 = fRows[iRow2];
+      for (Int_t i1 = 0; i1<row1.NCells(); i1++){
+       AliHLTTPCCACell *c1  = &(row1.Cells()[i1]);
+       if( c1->IUp()>=0 ) continue;
+       Double_t sy1 = c1->ErrY()*c1->ErrY();
+       Double_t sz1 = c1->ErrZ()*c1->ErrZ();
+       for (Int_t i2 = 0; i2<row2.NCells(); i2++){
+         AliHLTTPCCACell *c2  = &(row2.Cells()[i2]);
+         Double_t sy2 = c2->ErrY()*c2->ErrY();
+         Double_t sz2 = c2->ErrZ()*c2->ErrZ();
+         Double_t dist1 = sqrt( (c1->Y()-c2->Y())*(c1->Y()-c2->Y())/(sy1+sy2) );
+         Double_t dist2 = sqrt( (c1->Z()-c2->Z())*(c1->Z()-c2->Z())/(sz1+sz2) );
+         if( dist1>3.5*fParam.CellConnectionFactor() ) continue;
+         if( dist2>3.5*fParam.CellConnectionFactor() ) continue;
+         if( c1->IUp() ==-1 ) c1->IUp() = (i2<<8)+iRow2;
+         else c1->IUp() = -2;
+         if( c2->IDown() ==-1 ) c2->IDown() = (i1<<8)+iRow1;
+         else c2->IDown() = -2;
+       }
+      }
+    }
+  }
+
+  Int_t nOutTrackHits = 0;
+  Int_t nTrackCells = 0;
+  for( Int_t iRow1=0; iRow1<fParam.NRows(); iRow1++ ){
+    AliHLTTPCCARow &row1 = fRows[iRow1];
+    for (Int_t i1 = 0; i1<row1.NCells(); i1++){ 
+      AliHLTTPCCACell *c1  = &(row1.Cells()[i1]);
+      if( c1->IDown()==-2 || c1->IUp()==-2 ) continue;
+      if( c1->IUsed()>0 ) continue;
+      c1->IUsed() = 1;
+      AliHLTTPCCATrack track;
+      track.Used() = 0;
+      track.NCells() = 1;
+      track.IFirstCell() = nTrackCells;
+      fTrackCells[nTrackCells++] = (i1<<8)+iRow1;
+      AliHLTTPCCACell *last = c1;
+      Int_t lastRow = iRow1;
+      while( last->IUp() >=0 ){
+       Int_t iRow2 = last->IUp()%256;
+       AliHLTTPCCARow &row2 = fRows[iRow2];
+       AliHLTTPCCACell *next = &(row2.Cells()[last->IUp()>>8]);
+       if( next->IDown()==-2 || next->IUp()==-2 ) break;
+#ifdef DRAW
+       AliHLTTPCCADisplay::Instance().ConnectCells( lastRow,*last,iRow2,*next );
+       nConnectedCells++;
+#endif 
+       next->IUsed() = 1;      
+       fTrackCells[nTrackCells++] = last->IUp();
+       track.NCells()++;
+       last = next;
+       lastRow = iRow2;
+      } 
+      vTracks.push_back(track);
+    }
+  }
+  
+  Int_t nTracks = vTracks.size();
+  std::sort( vTracks.begin(), vTracks.end(), AliHLTTPCCATrack::CompareSize);
+  
+  fTracks = new AliHLTTPCCATrack[nTracks];
+  fNTracks = 0;
+  vTrackCells.clear();
+  Int_t vMatchedTracks[nTracks];
+  for( Int_t itr=0; itr<nTracks; itr++ ){
+    AliHLTTPCCATrack &iTrack = vTracks[itr];
+    if( iTrack.Used() ) continue;    
+    FitTrack( iTrack );
+    if( iTrack.Param().Chi2() > fParam.TrackChi2Cut()*iTrack.Param().NDF() ) continue;    
+
+    Int_t iFirstRow =  GetTrackCellIRow( iTrack, 0);
+    Int_t iLastRow  =  GetTrackCellIRow( iTrack, iTrack.NCells()-1);
+    AliHLTTPCCACell *iFirstCell = &GetTrackCell( iTrack, 0);
+    AliHLTTPCCACell *iLastCell = &GetTrackCell( iTrack, iTrack.NCells()-1);
+    
+    Bool_t updated = 1;
+    Int_t nMatched = 0;
+    std::vector<Int_t> vMatchedCells;
+    while( updated ){
+      updated = 0;
+      for( Int_t jtr=1; jtr<nTracks; jtr++ ){
+       AliHLTTPCCATrack &jTrack = vTracks[jtr];
+       if( jTrack.Used() ) continue;
+       Int_t jFirstRow =  GetTrackCellIRow( jTrack, 0);
+       Int_t jLastRow =  GetTrackCellIRow( jTrack, jTrack.NCells()-1);
+       AliHLTTPCCACell *jFirstCell = &GetTrackCell( jTrack, 0);
+       AliHLTTPCCACell *jLastCell = &GetTrackCell( jTrack, jTrack.NCells()-1);
+
+       Int_t dFirstRow1 = TMath::Abs(iFirstRow-jLastRow);
+       Int_t dFirstRow2 = TMath::Abs(iFirstRow-jFirstRow);
+       Int_t dLastRow1 = TMath::Abs(iLastRow-jLastRow);
+       Int_t dLastRow2 = TMath::Abs(iLastRow-jFirstRow);
+       if( dFirstRow1 > fParam.MaxTrackMatchDRow() && 
+           dFirstRow2 > fParam.MaxTrackMatchDRow() &&
+           dLastRow1  > fParam.MaxTrackMatchDRow() && 
+           dLastRow2  > fParam.MaxTrackMatchDRow()    ) continue;
+       Int_t iCase=0;
+       AliHLTTPCCACell *iC, *jC;
+       if( dFirstRow1<dFirstRow2 && dFirstRow1<dLastRow1 && dFirstRow1<dLastRow2 ){
+         iCase = 0;
+         iC = iFirstCell;
+         jC = jLastCell;
+       }else if( dFirstRow2<dLastRow1 && dFirstRow2<dLastRow2 ){
+         iCase = 1;
+         iC = iFirstCell;
+         jC = jFirstCell;
+       }else if( dLastRow1<dLastRow2 ){
+         iCase = 2;
+         iC = iLastCell; 
+         jC = jLastCell;
+       }else{
+         iCase = 3;
+         iC = iLastCell; 
+         jC = jFirstCell;
+       }
+       {
+         Double_t dy = TMath::Abs(iC->Y() - jC->Y());
+         Double_t dz = TMath::Abs(iC->Z() - jC->Z());
+         Double_t sy1 = iC->ErrY()*iC->ErrY();
+         Double_t sz1 = iC->ErrZ()*iC->ErrZ();
+         Double_t sy2 = jC->ErrY()*jC->ErrY();
+         Double_t sz2 = jC->ErrZ()*jC->ErrZ();
+         Double_t dist1 = sqrt( (dy)/(sy1+sy2) );
+         Double_t dist2 = sqrt( (dz)/(sz1+sz2) );
+         if( dist1>3.5*5*fParam.CellConnectionFactor() ) continue;
+         if( dist2>3.5*5*fParam.CellConnectionFactor() ) continue;
+       }
+       AliHLTTPCCATrackPar t = iTrack.Param();
+       //t.Chi2() = 0;
+       //t.NDF() = 0;
+       for( Int_t i=0; i<jTrack.NCells() ; i++){
+         AliHLTTPCCACell &c = GetTrackCell(jTrack,i);  
+         AliHLTTPCCARow &row = GetTrackCellRow(jTrack,i);
+         for( Int_t j=0; j<c.NHits(); j++){
+           AliHLTTPCCAHit &h = row.GetCellHit(c,j);
+           Double_t m[3] = {row.X(), h.Y(), h.Z() };
+           Double_t mV[6] = {fParam.ErrX()*fParam.ErrX(), 0, h.ErrY()*h.ErrY(), 0, 0, h.ErrZ()*h.ErrZ() };
+           Double_t mV1[6];
+           t.TransportBz(fParam.Bz(),m);
+           t.GetConnectionMatrix(fParam.Bz(),m, mV1);
+           t.Filter(m, mV, mV1);
+         }
+       }
+       if( t.Chi2() > fParam.TrackChi2Cut()*t.NDF() ) continue;
+       if( iCase==0 ){
+         iFirstRow = jFirstRow;
+         iFirstCell = jFirstCell;
+       }else if( iCase ==1 ){
+         iFirstRow = jLastRow;
+         iFirstCell = jLastCell;
+       }else if( iCase == 2 ){
+         iLastRow = jFirstRow;
+         iLastCell = jFirstCell;
+       }else{
+         iLastRow = jLastRow;
+         iLastCell = jLastCell;
+       }
+       t.Normalize();
+
+       for( Int_t i=0; i<jTrack.NCells(); i++){
+         vMatchedCells.push_back(fTrackCells[jTrack.IFirstCell()+i]);
+       }
+       //t.NDF()+= iTrack.Param().NDF();
+       //t.Chi2()+= iTrack.Param().Chi2();
+       iTrack.Param() = t;
+       vMatchedTracks[nMatched++] = jtr;
+       jTrack.Used()=1;
+       updated = 1;
+       break;
+      }
+    }
+
+    if(0){
+      Double_t t0[7];
+      for( Int_t i=0; i<7; i++ ) t0[i] = iTrack.Param().Par()[i];
+      iTrack.Param().Init();
+      for( Int_t i=0; i<7; i++ ) iTrack.Param().Par()[i] = t0[i];
+      for( Int_t i=0; i<iTrack.NCells() ; i++){
+       AliHLTTPCCACell &c = GetTrackCell( iTrack, i);
+       AliHLTTPCCARow &row = GetTrackCellRow( iTrack, i);
+       for( Int_t j=0; j<c.NHits(); j++){
+         AliHLTTPCCAHit &h = row.GetCellHit(c,j);
+         Double_t m[3] = {row.X(), h.Y(), h.Z() };
+         Double_t mV[6] = {0, 0, h.ErrY()*h.ErrY(), 0, 0, h.ErrZ()*h.ErrZ() };
+         Double_t mV1[6];
+         iTrack.Param().TransportBz(fParam.Bz(), m, t0);
+         iTrack.Param().GetConnectionMatrix(fParam.Bz(), m, mV1, t0);
+         iTrack.Param().Filter(m, mV, mV1);
+       }
+      }
+      iTrack.Param().Normalize();
+    }
+    //FitTrack(iTrack,5);
+    Int_t nHits = 0;
+    for( Int_t iCell=0; iCell<iTrack.NCells(); iCell++){
+      Int_t ind = fTrackCells[iTrack.IFirstCell()+iCell];
+      AliHLTTPCCARow &row = fRows[ind%256];
+      AliHLTTPCCACell &c = row.Cells()[ind>>8];
+      nHits+=c.NHits();
+    }
+    for( UInt_t i=0; i<vMatchedCells.size(); i++){
+      Int_t ind = vMatchedCells[i];
+      AliHLTTPCCARow &row = fRows[ind%256];
+      AliHLTTPCCACell &c = row.Cells()[ind>>8];
+      nHits+=c.NHits();
+    }
+
+    if( nHits<5 ){
+      for( Int_t i=0; i<nMatched; i++ ) vTracks[vMatchedTracks[i]].Used()=0;
+      continue;
+    }
+    iTrack.Used() = 1;
+    Int_t oldNCells = vTrackCells.size();
+    for( Int_t i=0; i<iTrack.NCells() ; i++){
+      vTrackCells.push_back(fTrackCells[iTrack.IFirstCell()+i]);
+    }      
+    iTrack.IFirstCell() = oldNCells;
+    for( UInt_t i=0; i<vMatchedCells.size(); i++){
+      vTrackCells.push_back(vMatchedCells[i]);
+      iTrack.NCells()++;
+    }      
+    fTracks[fNTracks++] = iTrack;  
+    nOutTrackHits+= nHits;  
+  }
+
+
+  //fTrackCells = new Int_t[vTrackCells.size()];
+  for( UInt_t i=0; i<vTrackCells.size(); i++ ) fTrackCells[i] = vTrackCells[i];
+  
+#ifdef DRAW
+  if( nConnectedCells>0 ) AliHLTTPCCADisplay::Instance().Ask();
+#endif 
+
+
+  fOutTrackHits = new Int_t[nOutTrackHits];
+  fNOutTrackHits = 0;
+  fNOutTracks = fNTracks;
+  fOutTracks = new AliHLTTPCCAOutTrack[fNOutTracks];
+  for( Int_t itr=0; itr<fNOutTracks; itr++ ){
+    AliHLTTPCCATrack &t = fTracks[itr];
+#ifdef DRAW
+  AliHLTTPCCADisplay::Instance().DrawTrack( t );
+#endif 
+    AliHLTTPCCAOutTrack &tmp = fOutTracks[itr];
+    tmp.FirstHitRef() = fNOutTrackHits;
+    tmp.NHits() = 0;
+    tmp.Param() = t.Param();
+    for( Int_t iCell=0; iCell<t.NCells(); iCell++){
+      AliHLTTPCCACell &cell = GetTrackCell(t,iCell);
+      AliHLTTPCCARow &row = GetTrackCellRow(t,iCell);
+      for( Int_t iHit=0; iHit<cell.NHits(); iHit++ ){
+       AliHLTTPCCAHit &hit = row.GetCellHit(cell,iHit);
+       fOutTrackHits[fNOutTrackHits] = hit.ID();
+       fNOutTrackHits++;
+       tmp.NHits()++;
+      }
+    }
+  }  
+  
+#ifdef DRAW
+  AliHLTTPCCADisplay::Instance().Ask();
+  //AliHLTTPCCADisplay::Instance().DrawMCTracks(fParam.fISec);
+  //AliHLTTPCCADisplay::Instance().Update();
+  //AliHLTTPCCADisplay::Instance().Ask();
+#endif 
+}
+
+
+
+void AliHLTTPCCATracker::FitTrack( AliHLTTPCCATrack &track, Int_t nIter )
+{    
+  // fit the track with nIter iterations
+
+  AliHLTTPCCATrackPar &t = track.Param();
+  t.Init();
+  
+  AliHLTTPCCACell &c1 = GetTrackCell(track,0);
+  AliHLTTPCCACell &c2 = GetTrackCell(track,track.NCells()-1);
+  AliHLTTPCCARow &row1 = GetTrackCellRow(track,0);
+  AliHLTTPCCARow &row2 = GetTrackCellRow(track,track.NCells()-1);
+  Double_t t0[7];
+  t0[0]=row1.X();
+  t0[1]=c1.Y();
+  t0[2]=c1.Z();
+  t0[3]= row2.X() - row1.X();
+  t0[4]= c2.Y() - c1.Y();
+  t0[5]= c2.Z() - c1.Z();
+  Double_t tt = sqrt(t0[3]*t0[3]+t0[4]*t0[4]+t0[5]*t0[5]);
+  if( fabs(tt)>1.e-4 ){
+    t0[3]/=tt;
+    t0[4]/=tt;
+    t0[5]/=tt;
+  }else{
+    t0[4]=1;
+  }
+  t0[6] = 0;
+
+  for( Int_t iter=0; iter<nIter; iter++ ){
+    t.Init();
+    for( Int_t i=0; i<7; i++) t.Par()[i] = t0[i];
+    {
+      Double_t m[3] = {row1.X(), c1.Y(), c1.Z() };
+      t.TransportBz(fParam.Bz(),m,t0);
+    }
+    t.Init();
+    for( Int_t i=0; i<7; i++ ) t.Par()[i] = t0[i];
+    
+    for( Int_t i=0; i<track.NCells() ; i++){
+      AliHLTTPCCACell &c = GetTrackCell(track,i);
+      AliHLTTPCCARow &row = GetTrackCellRow(track,i);
+      for( Int_t j=0; j<c.NHits(); j++){
+       AliHLTTPCCAHit &h = row.GetCellHit(c,j);
+       Double_t m[3] = {row.X(), h.Y(), h.Z() };
+       Double_t mV[6] = {fParam.ErrX()*fParam.ErrX(), 0, h.ErrY()*h.ErrY(), 0, 0, h.ErrZ()*h.ErrZ() };
+       Double_t mV1[6];
+       t.TransportBz(fParam.Bz(),m, t0);
+       t.GetConnectionMatrix(fParam.Bz(),m, mV1, t0);
+       t.Filter(m, mV, mV1);
+      }
+    }
+    t.Normalize();
+    for( Int_t i=0; i<7; i++ ) t0[i] = t.Par()[i];
+  }
+}
diff --git a/HLT/TPCLib/tracking-ca/AliHLTTPCCATracker.h b/HLT/TPCLib/tracking-ca/AliHLTTPCCATracker.h
new file mode 100644 (file)
index 0000000..fcfd531
--- /dev/null
@@ -0,0 +1,93 @@
+//-*- 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 ALIHLTTPCCATRACKER_H
+#define ALIHLTTPCCATRACKER_H
+
+
+#include "Rtypes.h"
+#include "AliHLTTPCCAParam.h"
+#include "AliHLTTPCCARow.h"
+#include "AliHLTTPCCATrack.h"
+
+class AliHLTTPCCAHit;
+class AliHLTTPCCACell;
+class AliHLTTPCCAOutTrack;
+
+
+/**
+ * @class AliHLTTPCCATracker
+ */
+class AliHLTTPCCATracker
+{
+ public:
+
+  AliHLTTPCCATracker();
+  AliHLTTPCCATracker( const AliHLTTPCCATracker& );
+  AliHLTTPCCATracker &operator=( const AliHLTTPCCATracker& );
+  virtual ~AliHLTTPCCATracker();
+
+  void Initialize( AliHLTTPCCAParam &param );
+
+  void StartEvent();
+  void ReadHit( Int_t iRow, Int_t index, Double_t x, Double_t y, Double_t z, 
+                Double_t ErrY, Double_t ErrZ  ) const {;}
+
+  void ReadHitRow( Int_t iRow, AliHLTTPCCAHit *Row, Int_t NHits );
+
+  void Reconstruct();
+
+  void FindCells();
+  void FindTracks();
+  void FitTrack( AliHLTTPCCATrack &track, Int_t nIter=2 );
+
+  AliHLTTPCCAParam &Param(){ return fParam; }
+  AliHLTTPCCARow *Rows(){ return fRows; }
+
+  Int_t *OutTrackHits(){ return  fOutTrackHits; }
+  Int_t NOutTrackHits() const { return  fNOutTrackHits; }
+  AliHLTTPCCAOutTrack *OutTracks(){ return  fOutTracks; }
+  Int_t NOutTracks() const { return  fNOutTracks; }
+
+  AliHLTTPCCATrack *Tracks(){ return  fTracks; }
+  Int_t NTracks() const { return fNTracks; }
+
+  Int_t *TrackCells(){ return  fTrackCells; }
+
+  AliHLTTPCCACell &GetTrackCell( AliHLTTPCCATrack &t, Int_t i ) const {
+    Int_t ind = fTrackCells[t.IFirstCell()+i];
+    AliHLTTPCCARow &row = fRows[ind%256];
+    return row.Cells()[ind>>8];
+  }
+  AliHLTTPCCARow &GetTrackCellRow( AliHLTTPCCATrack &t, Int_t i ) const {
+    Int_t ind = fTrackCells[t.IFirstCell()+i];
+    return fRows[ind%256];    
+  }
+  Int_t GetTrackCellIRow( AliHLTTPCCATrack &t, Int_t i ) const {
+    Int_t ind = fTrackCells[t.IFirstCell()+i];
+    return ind%256;    
+  }
+ protected:
+  
+  AliHLTTPCCAParam fParam; // parameters
+
+  AliHLTTPCCARow *fRows;// array of hit rows
+
+  Int_t *fOutTrackHits;  // output array of ID's of the reconstructed hits
+  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 *fTrackCells; // indices of cells for reconstructed tracks
+  Int_t fNHitsTotal;// total number of hits in event
+  AliHLTTPCCATrack *fTracks;   // reconstructed tracks
+  Int_t fNTracks;// number of reconstructed tracks
+
+  ClassDef(AliHLTTPCCATracker,1);
+};
+
+#endif
index 6663dc08a3d875eee6d43c8e25dd2408a8adb13a..6d223562a736df52b8f2fee1030470bf8f0c084d 100644 (file)
@@ -42,11 +42,20 @@ CLASS_HDRS:=        AliHLTTPCTransform.h \
                AliHLTTPCSliceTrackerComponent.h \
                AliHLTTPCGlobalMergerComponent.h \
                AliHLTTPCEsdWriterComponent.h \
+               tracking-ca/AliHLTTPCCACell.h \
+               tracking-ca/AliHLTTPCCADisplay.h \
+               tracking-ca/AliHLTTPCCAHit.h \
+               tracking-ca/AliHLTTPCCAOutTrack.h \
+               tracking-ca/AliHLTTPCCAParam.h \
+               tracking-ca/AliHLTTPCCARow.h \
+               tracking-ca/AliHLTTPCCATrackerComponent.h \
+               tracking-ca/AliHLTTPCCATracker.h \
+               tracking-ca/AliHLTTPCCATrack.h \
+               tracking-ca/AliHLTTPCCATrackPar.h \
                AliHLTTPCCalibPedestalComponent.h \
                AliHLTTPCCalibPulserComponent.h
 
 
-
 #              AliHLTTPCDDLDataFileHandler.h
 #              tracking/AliHLTTPCHough.h \
 #              tracking/AliHLTTPCHoughTrack.h \
@@ -88,4 +97,4 @@ PACKCXXFLAGS := ${HLTCXXFLAGS}
 PACKCFLAGS   := ${HLTCLFAGS}
 PACKDCXXFLAGS:= ${HLTDCXXFLAGS}
 
-EINCLUDE := HLT/TPCLib HLT/TPCLib/tracking HLT/BASE HLT/BASE/util TPC RAW STEER
+EINCLUDE := HLT/TPCLib HLT/TPCLib/tracking HLT/TPCLib/tracking-ca HLT/BASE HLT/BASE/util TPC RAW STEER