]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TPC/AliTPCseed.cxx
Updated flags for low flux case (A. Dainese)
[u/mrichter/AliRoot.git] / TPC / AliTPCseed.cxx
index 9f72eb15e7bd25ae40a35071590297d33ade6347..324a27f4b4a1b0ce8156f70c7ed9e6efb876e978 100644 (file)
 //-----------------------------------------------------------------
 #include "TClonesArray.h"
 #include "AliTPCseed.h"
+#include "AliTPCReconstructor.h"
+#include "AliTPCClusterParam.h"
+#include "AliTPCCalPad.h"
+#include "AliTPCCalROC.h"
+#include "AliTPCcalibDB.h"
+#include "AliTPCParam.h"
+
+
 
 ClassImp(AliTPCseed)
 
 
 
-AliTPCseed::AliTPCseed():AliTPCtrack(){
+AliTPCseed::AliTPCseed():
+  AliTPCtrack(),
+  fEsd(0x0),
+  fClusterOwner(kFALSE),
+  fRow(0),
+  fSector(-1),
+  fRelativeSector(-1),
+  fCurrentSigmaY2(1e10),
+  fCurrentSigmaZ2(1e10),
+  fCMeanSigmaY2p30(-1.),   //! current mean sigma Y2 - mean30%
+  fCMeanSigmaZ2p30(-1.),   //! current mean sigma Z2 - mean30%
+  fCMeanSigmaY2p30R(-1.),   //! current mean sigma Y2 - mean2%
+  fCMeanSigmaZ2p30R(-1.),   //! current mean sigma Z2 - mean2%
+  //
+  fErrorY2(1e10),
+  fErrorZ2(1e10),
+  fCurrentCluster(0x0),
+  fCurrentClusterIndex1(-1),
+  fInDead(kFALSE),
+  fIsSeeding(kFALSE),
+  fNoCluster(0),
+  fSort(0),
+  fBSigned(kFALSE),
+  fSeedType(0),
+  fSeed1(-1),
+  fSeed2(-1),
+  fMAngular(0),
+  fCircular(0),
+  fClusterMap(159),
+  fSharedMap(159)
+{
   //
-  fRow=0; 
-  fRemoval =0; 
-  for (Int_t i=0;i<200;i++) SetClusterIndex2(i,-3);
+  for (Int_t i=0;i<160;i++) SetClusterIndex2(i,-3);
   for (Int_t i=0;i<160;i++) fClusterPointer[i]=0;
   for (Int_t i=0;i<3;i++)   fKinkIndexes[i]=0;
-  for (Int_t i=0;i<5;i++)   fTPCr[i]=0.2;
-  fPoints = 0;
-  fEPoints = 0;
-  fNFoundable =0;
-  fNShared  =0;
-  fRemoval = 0;
-  fSort =0;
-  fFirstPoint =0;
-  fNoCluster =0;
-  fBSigned = kFALSE;
-  fSeed1 =-1;
-  fSeed2 =-1;
-  fCurrentCluster =0;
-  fCurrentSigmaY2=0;
-  fCurrentSigmaZ2=0;
-  fEsd =0;
-  fCircular = 0;  // not curling track
+  for (Int_t i=0;i<AliPID::kSPECIES;i++)   fTPCr[i]=0.2;
+  for (Int_t i=0;i<4;i++) {
+    fDEDX[i] = 0.;
+    fSDEDX[i] = 1e10;
+    fNCDEDX[i] = 0;
+  }
+  for (Int_t i=0;i<12;i++) fOverlapLabels[i] = -1;
+  //  for (Int_t i=0;i<160;i++) fClusterMap[i]=kFALSE;
+  //for (Int_t i=0;i<160;i++) fSharedMap[i]=kFALSE;
+  fClusterMap.ResetAllBits(kFALSE);
+  fSharedMap.ResetAllBits(kFALSE);
+
 }
-AliTPCseed::AliTPCseed(const AliTPCseed &s):AliTPCtrack(s){
+
+AliTPCseed::AliTPCseed(const AliTPCseed &s, Bool_t clusterOwner):
+  AliTPCtrack(s),
+  fEsd(0x0),
+  fClusterOwner(clusterOwner),
+  fRow(0),
+  fSector(-1),
+  fRelativeSector(-1),
+  fCurrentSigmaY2(-1),
+  fCurrentSigmaZ2(-1),
+  fCMeanSigmaY2p30(-1.),   //! current mean sigma Y2 - mean30%
+  fCMeanSigmaZ2p30(-1.),   //! current mean sigma Z2 - mean30%
+  fCMeanSigmaY2p30R(-1.),   //! current mean sigma Y2 - mean2%
+  fCMeanSigmaZ2p30R(-1.),   //! current mean sigma Z2 - mean2%
+  fErrorY2(1e10),
+  fErrorZ2(1e10),
+  fCurrentCluster(0x0),
+  fCurrentClusterIndex1(-1),
+  fInDead(kFALSE),
+  fIsSeeding(kFALSE),
+  fNoCluster(0),
+  fSort(0),
+  fBSigned(kFALSE),
+  fSeedType(0),
+  fSeed1(-1),
+  fSeed2(-1),
+  fMAngular(0),
+  fCircular(0),
+  fClusterMap(s.fClusterMap),
+  fSharedMap(s.fSharedMap)
+{
   //---------------------
   // dummy copy constructor
   //-------------------------
-  for (Int_t i=0;i<160;i++) fClusterPointer[i] = s.fClusterPointer[i];
+  for (Int_t i=0;i<160;i++) {
+    fClusterPointer[i]=0;
+    if (fClusterOwner){
+      if (s.fClusterPointer[i])
+       fClusterPointer[i] = new AliTPCclusterMI(*(s.fClusterPointer[i]));
+    }else{
+      fClusterPointer[i] = s.fClusterPointer[i];
+    }
+    fTrackPoints[i] = s.fTrackPoints[i];
+  }
   for (Int_t i=0;i<160;i++) fIndex[i] = s.fIndex[i];
+  for (Int_t i=0;i<AliPID::kSPECIES;i++)   fTPCr[i]=s.fTPCr[i];
+  for (Int_t i=0;i<4;i++) {
+    fDEDX[i] = s.fDEDX[i];
+    fSDEDX[i] = s.fSDEDX[i];
+    fNCDEDX[i] = s.fNCDEDX[i];
+  }
+  for (Int_t i=0;i<12;i++) fOverlapLabels[i] = s.fOverlapLabels[i];
 
-  fPoints  = 0;
-  fEPoints = 0;
-  fCircular =0;
-  fEsd =0;
 }
-AliTPCseed::AliTPCseed(const AliTPCtrack &t):AliTPCtrack(t){
-  //
-  //copy constructor
-  fPoints = 0;
-  fEPoints = 0;
-  fNShared  =0; 
-  //  fTrackPoints =0;
-  fRemoval =0;
-  fSort =0;
-  for (Int_t i=0;i<3;i++)   fKinkIndexes[i]=t.GetKinkIndex(i);
+
+
+AliTPCseed::AliTPCseed(const AliTPCtrack &t):
+  AliTPCtrack(t),
+  fEsd(0x0),
+  fClusterOwner(kFALSE),
+  fRow(0),
+  fSector(-1),
+  fRelativeSector(-1),
+  fCurrentSigmaY2(-1),
+  fCurrentSigmaZ2(-1),
+  fCMeanSigmaY2p30(-1.),   //! current mean sigma Y2 - mean30%
+  fCMeanSigmaZ2p30(-1.),   //! current mean sigma Z2 - mean30%
+  fCMeanSigmaY2p30R(-1.),   //! current mean sigma Y2 - mean2%
+  fCMeanSigmaZ2p30R(-1.),   //! current mean sigma Z2 - mean2%
+  fErrorY2(1e10),
+  fErrorZ2(1e10),
+  fCurrentCluster(0x0),
+  fCurrentClusterIndex1(-1),
+  fInDead(kFALSE),
+  fIsSeeding(kFALSE),
+  fNoCluster(0),
+  fSort(0),
+  fBSigned(kFALSE),
+  fSeedType(0),
+  fSeed1(-1),
+  fSeed2(-1),
+  fMAngular(0),
+  fCircular(0),
+  fClusterMap(159),
+  fSharedMap(159)
+{
+  //
+  // Constructor from AliTPCtrack
+  //
+  fFirstPoint =0;
   for (Int_t i=0;i<5;i++)   fTPCr[i]=0.2;
   for (Int_t i=0;i<160;i++) {
     fClusterPointer[i] = 0;
@@ -86,93 +185,133 @@ AliTPCseed::AliTPCseed(const AliTPCtrack &t):AliTPCtrack(t){
       SetClusterIndex2(i,-3); 
     }    
   }
-  fFirstPoint =0;
-  fNoCluster =0;
-  fBSigned = kFALSE;
-  fSeed1 =-1;
-  fSeed2 =-1;
-  fCurrentCluster =0;
-  fCurrentSigmaY2=0;
-  fCurrentSigmaZ2=0;
-  fCircular =0;
-  fEsd =0;
+  for (Int_t i=0;i<4;i++) {
+    fDEDX[i] = 0.;
+    fSDEDX[i] = 1e10;
+    fNCDEDX[i] = 0;
+  }
+  for (Int_t i=0;i<12;i++) fOverlapLabels[i] = -1;
+  
+  //for (Int_t i=0;i<160;i++) fClusterMap[i]=kFALSE;
+  //for (Int_t i=0;i<160;i++) fSharedMap[i]=kFALSE;
+  fClusterMap.ResetAllBits(kFALSE);
+  fSharedMap.ResetAllBits(kFALSE);
+
 }
 
-AliTPCseed::AliTPCseed(UInt_t index,  const Double_t xx[5], const Double_t cc[15], 
-                                        Double_t xr, Double_t alpha):      
-  AliTPCtrack(index, xx, cc, xr, alpha) {
-   //
+AliTPCseed::AliTPCseed(Double_t xr, Double_t alpha, const Double_t xx[5],
+                      const Double_t cc[15], Int_t index):      
+  AliTPCtrack(xr, alpha, xx, cc, index),
+  fEsd(0x0),
+  fClusterOwner(kFALSE),
+  fRow(0),
+  fSector(-1),
+  fRelativeSector(-1),
+  fCurrentSigmaY2(-1),
+  fCurrentSigmaZ2(-1),
+  fCMeanSigmaY2p30(-1.),   //! current mean sigma Y2 - mean30%
+  fCMeanSigmaZ2p30(-1.),   //! current mean sigma Z2 - mean30%
+  fCMeanSigmaY2p30R(-1.),   //! current mean sigma Y2 - mean2%
+  fCMeanSigmaZ2p30R(-1.),   //! current mean sigma Z2 - mean2%
+  fErrorY2(1e10),
+  fErrorZ2(1e10),
+  fCurrentCluster(0x0),
+  fCurrentClusterIndex1(-1),
+  fInDead(kFALSE),
+  fIsSeeding(kFALSE),
+  fNoCluster(0),
+  fSort(0),
+  fBSigned(kFALSE),
+  fSeedType(0),
+  fSeed1(-1),
+  fSeed2(-1),
+  fMAngular(0),
+  fCircular(0),
+  fClusterMap(159),
+  fSharedMap(159)
+{
   //
-  //constructor
-  fRow =0;
-  for (Int_t i=0;i<200;i++) SetClusterIndex2(i,-3);
+  // Constructor
+  //
+  fFirstPoint =0;
+  for (Int_t i=0;i<160;i++) SetClusterIndex2(i,-3);
   for (Int_t i=0;i<160;i++) fClusterPointer[i]=0;
-  for (Int_t i=0;i<3;i++)   fKinkIndexes[i]=0;
   for (Int_t i=0;i<5;i++)   fTPCr[i]=0.2;
-
-  fPoints = 0;
-  fEPoints = 0;
-  fNFoundable =0;
-  fNShared  = 0;
-  //  fTrackPoints =0;
-  fRemoval =0;
-  fSort =0;
-  fFirstPoint =0;
-  //  fHelixIn = new TClonesArray("AliHelix",0);
-  //fHelixOut = new TClonesArray("AliHelix",0);
-  fNoCluster =0;
-  fBSigned = kFALSE;
-  fSeed1 =-1;
-  fSeed2 =-1;
-  fCurrentCluster =0;
-  fCurrentSigmaY2=0;
-  fCurrentSigmaZ2=0;
-  fEsd =0;
+  for (Int_t i=0;i<4;i++) {
+    fDEDX[i] = 0.;
+    fSDEDX[i] = 1e10;
+    fNCDEDX[i] = 0;
+  }
+  for (Int_t i=0;i<12;i++) fOverlapLabels[i] = -1;
 }
 
 AliTPCseed::~AliTPCseed(){
   //
   // destructor
-  if (fPoints) delete fPoints;
-  fPoints =0;
-  if (fEPoints) delete fEPoints;
-  fEPoints = 0;
   fNoCluster =0;
-}
+  if (fClusterOwner){
+    for (Int_t icluster=0; icluster<160; icluster++){
+      delete fClusterPointer[icluster];
+    }
+  }
 
-AliTPCTrackerPoint * AliTPCseed::GetTrackPoint(Int_t i)
-{
-  //
-  // 
-  return &fTrackPoints[i];
 }
-
-void AliTPCseed::RebuildSeed()
+//_________________________________________________
+AliTPCseed & AliTPCseed::operator=(const AliTPCseed &param)
 {
   //
-  // rebuild seed to be ready for storing
-  AliTPCclusterMI cldummy;
-  cldummy.SetQ(0);
-  AliTPCTrackPoint pdummy;
-  pdummy.GetTPoint().fIsShared = 10;
-  for (Int_t i=0;i<160;i++){
-    AliTPCclusterMI * cl0 = fClusterPointer[i];
-    AliTPCTrackPoint *trpoint = (AliTPCTrackPoint*)fPoints->UncheckedAt(i);     
-    if (cl0){
-      trpoint->GetTPoint() = *(GetTrackPoint(i));
-      trpoint->GetCPoint() = *cl0;
-      trpoint->GetCPoint().SetQ(TMath::Abs(cl0->GetQ()));
-    }
-    else{
-      *trpoint = pdummy;
-      trpoint->GetCPoint()= cldummy;
+  // assignment operator 
+  //
+  if(this!=&param){
+    AliTPCtrack::operator=(param);
+    fEsd =param.fEsd; 
+    for(Int_t i = 0;i<160;++i)fClusterPointer[i] = param.fClusterPointer[i]; // this is not allocated by AliTPCSeed
+    fClusterOwner = param.fClusterOwner;
+    // leave out fPoint, they are also not copied in the copy ctor...
+    // but deleted in the dtor... strange...
+    fRow            = param.fRow;
+    fSector         = param.fSector;
+    fRelativeSector = param.fRelativeSector;
+    fCurrentSigmaY2 = param.fCurrentSigmaY2;
+    fCurrentSigmaZ2 = param.fCurrentSigmaZ2;
+    fErrorY2        = param.fErrorY2;
+    fErrorZ2        = param.fErrorZ2;
+    fCurrentCluster = param.fCurrentCluster; // this is not allocated by AliTPCSeed
+    fCurrentClusterIndex1 = param.fCurrentClusterIndex1; 
+    fInDead         = param.fInDead;
+    fIsSeeding      = param.fIsSeeding;
+    fNoCluster      = param.fNoCluster;
+    fSort           = param.fSort;
+    fBSigned        = param.fBSigned;
+    for(Int_t i = 0;i<4;++i){
+      fDEDX[i]   = param.fDEDX[i];
+      fSDEDX[i]  = param.fSDEDX[i];
+      fNCDEDX[i] = param.fNCDEDX[i];
     }
+    for(Int_t i = 0;i<AliPID::kSPECIES;++i)fTPCr[i] = param.fTPCr[i];
     
+    fSeedType = param.fSeedType;
+    fSeed1    = param.fSeed1;
+    fSeed2    = param.fSeed2;
+    for(Int_t i = 0;i<12;++i)fOverlapLabels[i] = param.fOverlapLabels[i];
+    fMAngular = param.fMAngular;
+    fCircular = param.fCircular;
+    for(int i = 0;i<160;++i)fTrackPoints[i] =  param.fTrackPoints[i];
+    fClusterMap = param.fClusterMap;
+    fSharedMap = param.fSharedMap;
   }
-
+  return (*this);
+}
+//____________________________________________________
+AliTPCTrackerPoint * AliTPCseed::GetTrackPoint(Int_t i)
+{
+  //
+  // 
+  return &fTrackPoints[i];
 }
 
 
+
 Double_t AliTPCseed::GetDensityFirst(Int_t n)
 {
   //
@@ -201,6 +340,7 @@ void AliTPCseed::GetClusterStatistic(Int_t first, Int_t last, Int_t &found, Int_
   for (Int_t i=first;i<last; i++){
     Int_t index = GetClusterIndex2(i);
     if (index!=-1) foundable++;
+    if (index&0x8000) continue;
     if (fClusterPointer[i]) {
       found++;
     }
@@ -243,7 +383,7 @@ void AliTPCseed::Reset(Bool_t all)
   SetNumberOfClusters(0);
   fNFoundable = 0;
   SetChi2(0);
-  ResetCovariance();
+  ResetCovariance(10.);
   /*
   if (fTrackPoints){
     for (Int_t i=0;i<8;i++){
@@ -269,14 +409,11 @@ void AliTPCseed::Modify(Double_t factor)
   //This function makes a track forget its history :)  
   //------------------------------------------------------------------
   if (factor<=0) {
-    ResetCovariance();
+    ResetCovariance(10.);
     return;
   }
-  fC00*=factor;
-  fC10*=0;  fC11*=factor;
-  fC20*=0;  fC21*=0;  fC22*=factor;
-  fC30*=0;  fC31*=0;  fC32*=0;  fC33*=factor;
-  fC40*=0;  fC41*=0;  fC42*=0;  fC43*=0;  fC44*=factor;
+  ResetCovariance(factor);
+
   SetNumberOfClusters(0);
   fNFoundable =0;
   SetChi2(0);
@@ -298,25 +435,25 @@ Int_t  AliTPCseed::GetProlongation(Double_t xk, Double_t &y, Double_t & z) const
   // doesn't change internal state of the track
   //-----------------------------------------------------------------
   
-  Double_t x1=fX, x2=x1+(xk-x1), dx=x2-x1;
+  Double_t x1=GetX(), x2=x1+(xk-x1), dx=x2-x1;
 
-  if (TMath::Abs(fP4*xk - fP2) >= 0.999) {   
+  if (TMath::Abs(GetSnp()+GetC()*dx) >= AliTPCReconstructor::GetMaxSnpTrack()) {   
     return 0;
   }
 
   //  Double_t y1=fP0, z1=fP1;
-  Double_t c1=fP4*x1 - fP2, r1=sqrt(1.- c1*c1);
-  Double_t c2=fP4*x2 - fP2, r2=sqrt(1.- c2*c2);
+  Double_t c1=GetSnp(), r1=sqrt(1.- c1*c1);
+  Double_t c2=c1 + GetC()*dx, r2=sqrt(1.- c2*c2);
   
-  y = fP0;
-  z = fP1;
+  y = GetY();
+  z = GetZ();
   //y += dx*(c1+c2)/(r1+r2);
   //z += dx*(c1+c2)/(c1*r2 + c2*r1)*fP3;
   
   Double_t dy = dx*(c1+c2)/(r1+r2);
   Double_t dz = 0;
   //
-  Double_t delta = fP4*dx*(c1+c2)/(c1*r2 + c2*r1);
+  Double_t delta = GetC()*dx*(c1+c2)/(c1*r2 + c2*r1);
   /*
   if (TMath::Abs(delta)>0.0001){
     dz = fP3*TMath::ASin(delta)/fP4;
@@ -325,7 +462,7 @@ Int_t  AliTPCseed::GetProlongation(Double_t xk, Double_t &y, Double_t & z) const
   }
   */
   //  dz =  fP3*AliTPCFastMath::FastAsin(delta)/fP4;
-  dz =  fP3*TMath::ASin(delta)/fP4;
+  dz =  GetTgl()*TMath::ASin(delta)/GetC();
   //
   y+=dy;
   z+=dz;
@@ -341,24 +478,11 @@ Double_t AliTPCseed::GetPredictedChi2(const AliCluster *c) const
   //-----------------------------------------------------------------
   // This function calculates a predicted chi2 increment.
   //-----------------------------------------------------------------
-  //Double_t r00=c->GetSigmaY2(), r01=0., r11=c->GetSigmaZ2();
-  Double_t r00=fErrorY2, r01=0., r11=fErrorZ2;
-  r00+=fC00; r01+=fC10; r11+=fC11;
-
-  Double_t det=r00*r11 - r01*r01;
-  if (TMath::Abs(det) < 1.e-10) {
-    //Int_t n=GetNumberOfClusters();
-    //if (n>4) cerr<<n<<" AliKalmanTrack warning: Singular matrix !\n";
-    return 1e10;
-  }
-  Double_t tmp=r00; r00=r11; r11=tmp; r01=-r01;
-  
-  Double_t dy=c->GetY() - fP0, dz=c->GetZ() - fP1;
-  
-  return (dy*r00*dy + 2*r01*dy*dz + dz*r11*dz)/det;
+  Double_t p[2]={c->GetY(), c->GetZ()};
+  Double_t cov[3]={fErrorY2, 0., fErrorZ2};
+  return AliExternalTrackParam::GetPredictedChi2(p,cov);
 }
 
-
 //_________________________________________________________________________________________
 
 
@@ -379,11 +503,11 @@ Int_t AliTPCseed::Compare(const TObject *o) const {
   }
   else {
     Float_t f2 =1;
-    f2 = 1-20*TMath::Sqrt(t->fC44)/(TMath::Abs(t->GetC())+0.0066);
+    f2 = 1-20*TMath::Sqrt(t->GetSigma1Pt2())/(t->OneOverPt()+0.0066);
     if (t->fBConstrain) f2=1.2;
 
     Float_t f1 =1;
-    f1 = 1-20*TMath::Sqrt(fC44)/(TMath::Abs(GetC())+0.0066);
+    f1 = 1-20*TMath::Sqrt(GetSigma1Pt2())/(OneOverPt()+0.0066);
 
     if (fBConstrain)   f1=1.2;
  
@@ -396,59 +520,43 @@ Int_t AliTPCseed::Compare(const TObject *o) const {
 
 
 //_____________________________________________________________________________
-Int_t AliTPCseed::Update(const AliCluster *c, Double_t chisq, UInt_t /*index*/) {
+Bool_t AliTPCseed::Update(const AliCluster *c, Double_t chisq, Int_t index)
+{
   //-----------------------------------------------------------------
   // This function associates a cluster with this track.
   //-----------------------------------------------------------------
-  Double_t r00=fErrorY2, r01=0., r11=fErrorZ2;
-
-  r00+=fC00; r01+=fC10; r11+=fC11;
-  Double_t det=r00*r11 - r01*r01;
-  Double_t tmp=r00; r00=r11/det; r11=tmp/det; r01=-r01/det;
-
-  Double_t k00=fC00*r00+fC10*r01, k01=fC00*r01+fC10*r11;
-  Double_t k10=fC10*r00+fC11*r01, k11=fC10*r01+fC11*r11;
-  Double_t k20=fC20*r00+fC21*r01, k21=fC20*r01+fC21*r11;
-  Double_t k30=fC30*r00+fC31*r01, k31=fC30*r01+fC31*r11;
-  Double_t k40=fC40*r00+fC41*r01, k41=fC40*r01+fC41*r11;
-
-  Double_t dy=c->GetY() - fP0, dz=c->GetZ() - fP1;
-  Double_t cur=fP4 + k40*dy + k41*dz, eta=fP2 + k20*dy + k21*dz;
-  if (TMath::Abs(cur*fX-eta) >= 0.9) {
-    return 0;
+  Int_t n=GetNumberOfClusters();
+  Int_t idx=GetClusterIndex(n);    // save the current cluster index
+
+  AliCluster cl(*c);  cl.SetSigmaY2(fErrorY2); cl.SetSigmaZ2(fErrorZ2);
+  Float_t dx = ((AliTPCclusterMI*)c)->GetX()-GetX();
+  if (TMath::Abs(dx)>0){
+    Float_t ty = TMath::Tan(TMath::ASin(GetSnp()));
+    Float_t dy = dx*ty;
+    Float_t dz = dx*TMath::Sqrt(1.+ty*ty)*GetTgl();
+    cl.SetY(c->GetY()-dy);  
+    cl.SetZ(c->GetZ()-dz);  
   }
 
-  fP0 += k00*dy + k01*dz;
-  fP1 += k10*dy + k11*dz;
-  fP2  = eta;
-  fP3 += k30*dy + k31*dz;
-  fP4  = cur;
-
-  Double_t c01=fC10, c02=fC20, c03=fC30, c04=fC40;
-  Double_t c12=fC21, c13=fC31, c14=fC41;
-
-  fC00-=k00*fC00+k01*fC10; fC10-=k00*c01+k01*fC11;
-  fC20-=k00*c02+k01*c12;   fC30-=k00*c03+k01*c13;
-  fC40-=k00*c04+k01*c14; 
-
-  fC11-=k10*c01+k11*fC11;
-  fC21-=k10*c02+k11*c12;   fC31-=k10*c03+k11*c13;
-  fC41-=k10*c04+k11*c14; 
-
-  fC22-=k20*c02+k21*c12;   fC32-=k20*c03+k21*c13;
-  fC42-=k20*c04+k21*c14; 
-
-  fC33-=k30*c03+k31*c13;
-  fC43-=k40*c03+k41*c13; 
-
-  fC44-=k40*c04+k41*c14; 
+  if (!AliTPCtrack::Update(&cl,chisq,index)) return kFALSE;
+  
+  if (fCMeanSigmaY2p30<0){
+    fCMeanSigmaY2p30= c->GetSigmaY2();   //! current mean sigma Y2 - mean30%
+    fCMeanSigmaZ2p30= c->GetSigmaZ2();   //! current mean sigma Z2 - mean30%    
+    fCMeanSigmaY2p30R = 1;   //! current mean sigma Y2 - mean5%
+    fCMeanSigmaZ2p30R = 1;   //! current mean sigma Z2 - mean5%
+  }
+  //
+  fCMeanSigmaY2p30= 0.70*fCMeanSigmaY2p30 +0.30*c->GetSigmaY2();   
+  fCMeanSigmaZ2p30= 0.70*fCMeanSigmaZ2p30 +0.30*c->GetSigmaZ2();  
+  if (fCurrentSigmaY2>0){
+    fCMeanSigmaY2p30R = 0.7*fCMeanSigmaY2p30R  +0.3*c->GetSigmaY2()/fCurrentSigmaY2;  
+    fCMeanSigmaZ2p30R = 0.7*fCMeanSigmaZ2p30R  +0.3*c->GetSigmaZ2()/fCurrentSigmaZ2;   
+  }
 
-  Int_t n=GetNumberOfClusters();
-  //  fIndex[n]=index;
-  SetNumberOfClusters(n+1);
-  SetChi2(GetChi2()+chisq);
 
-  return 1;
+  SetClusterIndex(n,idx);          // restore the current cluster index
+  return kTRUE;
 }
 
 
@@ -464,7 +572,6 @@ Float_t AliTPCseed::CookdEdx(Double_t low, Double_t up,Int_t i1, Int_t i2, Bool_
   Float_t weight[200];
   Int_t index[200];
   //Int_t nc = 0;
-  //  TClonesArray & arr = *fPoints; 
   Float_t meanlog = 100.;
   
   Float_t mean[4]  = {0,0,0,0};
@@ -475,11 +582,17 @@ Float_t AliTPCseed::CookdEdx(Double_t low, Double_t up,Int_t i1, Int_t i2, Bool_
   //
   fNShared =0;
 
+  Float_t gainGG = 1;
+  if (AliTPCcalibDB::Instance()->GetParameters()){
+    gainGG= AliTPCcalibDB::Instance()->GetParameters()->GetGasGain()/20000.;  //relative gas gain
+  }
+
+
   for (Int_t of =0; of<4; of++){    
     for (Int_t i=of+i1;i<i2;i+=4)
       {
-       Int_t index = fIndex[i];
-       if (index<0||index&0x8000) continue;
+       Int_t clindex = fIndex[i];
+       if (clindex<0||clindex&0x8000) continue;
 
        //AliTPCTrackPoint * point = (AliTPCTrackPoint *) arr.At(i);
        AliTPCTrackerPoint * point = GetTrackPoint(i);
@@ -594,6 +707,7 @@ Float_t AliTPCseed::CookdEdx(Double_t low, Double_t up,Int_t i1, Int_t i2, Bool_
        }
        if (rsigma>1.5) ampc/=1.3;  // if big backround
        amp[nc[of]]        = ampc;
+       amp[nc[of]]       /=gainGG;
        angular[nc[of]]    = TMath::Sqrt(1.+angley*angley+anglez*anglez);
        weight[nc[of]]     = w;
        nc[of]++;
@@ -681,27 +795,7 @@ Float_t AliTPCseed::CookdEdx(Double_t low, Double_t up,Int_t i1, Int_t i2, Bool_
 
   
   SetdEdx(dedx);
-    
-  //mi deDX
-
-
-
-  //Very rough PID
-  Double_t p=TMath::Sqrt((1.+ GetTgl()*GetTgl())/(Get1Pt()*Get1Pt()));
-
-  if (p<0.6) {
-    if (dedx < 39.+ 12./(p+0.25)/(p+0.25)) { SetMass(0.13957); return dedx;}
-    if (dedx < 39.+ 12./p/p) { SetMass(0.49368); return dedx;}
-    SetMass(0.93827); return dedx;
-  }
-
-  if (p<1.2) {
-    if (dedx < 39.+ 12./(p+0.25)/(p+0.25)) { SetMass(0.13957); return dedx;}
-    SetMass(0.93827); return dedx;
-  }
-
-  SetMass(0.13957); return dedx;
-
+  return dedx;
 }
 Double_t AliTPCseed::Bethe(Double_t bg){
   //
@@ -729,7 +823,7 @@ void AliTPCseed::CookPID()
   Double_t sumr =0;
   for (Int_t j=0; j<ns; j++) {
     Double_t mass=AliPID::ParticleMass(j);
-    Double_t mom=P();
+    Double_t mom=GetP();
     Double_t dedx=fdEdx/fMIP;
     Double_t bethe=Bethe(mom/mass); 
     Double_t sigma=fRes*bethe;
@@ -924,3 +1018,375 @@ void AliTPCseed::CookdEdx2(Double_t low, Double_t up) {
 
 }
 */
+Double_t AliTPCseed::GetYat(Double_t xk) const {
+//-----------------------------------------------------------------
+// This function calculates the Y-coordinate of a track at the plane x=xk.
+//-----------------------------------------------------------------
+  if (TMath::Abs(GetSnp())>AliTPCReconstructor::GetMaxSnpTrack()) return 0.; //patch 01 jan 06
+    Double_t c1=GetSnp(), r1=TMath::Sqrt(1.- c1*c1);
+    Double_t c2=c1+GetC()*(xk-GetX());
+    if (TMath::Abs(c2)>AliTPCReconstructor::GetMaxSnpTrack()) return 0;
+    Double_t r2=TMath::Sqrt(1.- c2*c2);
+    return GetY() + (xk-GetX())*(c1+c2)/(r1+r2);
+}
+
+void AliTPCseed::SetClusterMapBit(int ibit, Bool_t state)
+{
+  fClusterMap[ibit] = state;
+}
+Bool_t AliTPCseed::GetClusterMapBit(int ibit)
+{
+  return fClusterMap[ibit];
+}
+void AliTPCseed::SetSharedMapBit(int ibit, Bool_t state)
+{
+  fSharedMap[ibit] = state;
+}
+Bool_t AliTPCseed::GetSharedMapBit(int ibit)
+{
+  return fSharedMap[ibit];
+}
+
+
+
+
+
+Float_t  AliTPCseed::CookdEdxNorm(Double_t low, Double_t up, Int_t type, Int_t i1, Int_t i2, AliTPCCalPad * gainMap, Bool_t posNorm, Bool_t padNorm){
+  //
+  // calculates dedx using the cluster
+  // low    -  up specify trunc mean range  - default form 0-0.7
+  // type   -  1 - max charge  or 0- total charge in cluster 
+  //           //2- max no corr 3- total+ correction
+  // i1-i2  -  the pad-row range used for calculation
+  //
+  // normalization parametrization taken from AliTPCClusterParam
+  //
+  AliTPCClusterParam * parcl = AliTPCClusterParam::Instance();
+  if (!parcl) parcl = AliTPCcalibDB::Instance()->GetClusterParam();
+  if (!parcl) return 0;
+  Float_t amp[160];
+  Int_t   indexes[160];
+  Int_t   ncl=0;
+  //
+  //
+  Float_t gainGG = 1;
+  if (AliTPCcalibDB::Instance()->GetParameters()){
+    gainGG= 20000./AliTPCcalibDB::Instance()->GetParameters()->GetGasGain();  //relative gas gain
+  }
+
+  const Float_t ktany = TMath::Tan(TMath::DegToRad()*10);
+  const Float_t kedgey =3.;
+  //
+  //
+  for (Int_t irow=i1; irow<i2; irow++){
+    AliTPCclusterMI* cluster = GetClusterPointer(irow);
+    if (!cluster) continue;
+    if (TMath::Abs(cluster->GetY())>cluster->GetX()*ktany-kedgey) continue; // edge cluster
+    Float_t charge= (type%2)? cluster->GetMax():cluster->GetQ();
+    if (!gainMap) gainMap =  AliTPCcalibDB::Instance()->GetDedxGainFactor();
+    if (gainMap) {      
+      Float_t factor = 1;      
+      AliTPCCalROC * roc = gainMap->GetCalROC(cluster->GetDetector());
+      if (irow < 63) { // IROC
+       factor = roc->GetValue(irow, TMath::Nint(cluster->GetPad()))*1.55;
+      } else {         // OROC
+       factor = roc->GetValue(irow - 63, TMath::Nint(cluster->GetPad()));
+      }
+      if (factor>0.5) charge/=factor;
+    }
+    
+    //do normalization
+    Float_t corr=1;
+    Int_t  ipad= 0;
+    if (irow>62) ipad=1;
+    if (irow>127) ipad=2;    
+    if (type<=1){
+      //       
+      AliTPCTrackerPoint * point = GetTrackPoint(irow);
+      Float_t              ty = TMath::Abs(point->GetAngleY());
+      Float_t              tz = TMath::Abs(point->GetAngleZ());
+      
+      Float_t dr    = (250.-TMath::Abs(cluster->GetZ()))/250.;
+      corr  = parcl->Qnorm(ipad,type,dr,ty,tz);
+    }
+    amp[ncl]=charge/corr;
+    amp[ncl]/=gainGG;
+    if (posNorm){
+      //
+      //
+      //
+      corr = parcl->QnormPos(ipad,type, cluster->GetPad(),cluster->GetTimeBin(), cluster->GetZ(),
+                            cluster->GetSigmaY2(),cluster->GetSigmaZ2(),cluster->GetMax(),cluster->GetQ());
+      amp[ncl]/=corr;
+    }
+
+
+    amp[ncl] *= 2.0;     // put mean value to channel 50
+    if (padNorm){
+      corr=1;
+      if (type==0 && parcl->fQpadTnorm) corr = (*parcl->fQpadTnorm)[ipad];
+      if (type==1 && parcl->fQpadTnorm) corr = (*parcl->fQpadMnorm)[ipad];
+      amp[ncl]/=corr;
+    }
+
+    // if (ipad==0) {
+//       amp[ncl] /= 0.65; // this we will take form OCDB
+//     } else
+//       if (ipad==2){
+//     amp[ncl] /=1.57;
+//       }else{
+//       }      
+    ncl++;
+  }
+
+  if (type>3) return ncl; 
+  TMath::Sort(ncl,amp, indexes, kFALSE);
+
+  if (ncl<10) return 0;
+  
+  Float_t suma=0;
+  Float_t sumn=0;
+  Int_t icl0=TMath::Nint(ncl*low);
+  Int_t icl1=TMath::Nint(ncl*up);
+  for (Int_t icl=icl0; icl<icl1;icl++){
+    suma+=amp[indexes[icl]];
+    sumn++;
+  }
+  return suma/sumn;
+
+}
+
+Double_t AliTPCseed::BetheMass(Double_t mass){
+  //
+  // return bethe-bloch
+  //
+  Float_t bg= P()/mass; 
+  const Double_t kp1=0.76176e-1;
+  const Double_t kp2=10.632;
+  const Double_t kp3=0.13279e-4;
+  const Double_t kp4=1.8631;
+  const Double_t kp5=1.9479;
+
+  Double_t dbg = (Double_t) bg;
+
+  Double_t beta = dbg/TMath::Sqrt(1.+dbg*dbg);
+
+  Double_t aa = TMath::Power(beta,kp4);
+  Double_t bb = TMath::Power(1./dbg,kp5);
+
+  bb=TMath::Log(kp3+bb);
+  
+  return ((Float_t)((kp2-aa-bb)*kp1/aa));
+}
+
+
+Float_t  AliTPCseed::CookShape(Int_t type){
+  //
+  //
+  //
+ //-----------------------------------------------------------------
+  // This funtion calculates dE/dX within the "low" and "up" cuts.
+  //-----------------------------------------------------------------
+  Float_t means=0;
+  Float_t meanc=0;
+  for (Int_t i =0; i<160;i++)    {
+    AliTPCTrackerPoint * point = GetTrackPoint(i);
+    if (point==0) continue;
+
+    AliTPCclusterMI * cl = fClusterPointer[i];
+    if (cl==0) continue;       
+    
+    Float_t rsigmay =  TMath::Sqrt(point->GetSigmaY());
+    Float_t rsigmaz =  TMath::Sqrt(point->GetSigmaZ());
+    Float_t rsigma =   (rsigmay+rsigmaz)*0.5;
+    if (type==0) means+=rsigma;
+    if (type==1) means+=rsigmay;
+    if (type==2) means+=rsigmaz;
+    meanc++;
+  }
+  Float_t mean = (meanc>0)? means/meanc:0;
+  return mean;
+}
+
+
+
+Int_t  AliTPCseed::RefitTrack(AliTPCseed *seed, AliExternalTrackParam * parin, AliExternalTrackParam * parout){
+  //
+  // Refit the track
+  // return value - number of used clusters
+  // 
+  //
+  const Int_t kMinNcl =10;
+  AliTPCseed *track=new AliTPCseed(*seed);
+  Int_t sector=-1;
+  // reset covariance
+  //
+  Double_t covar[15];
+  for (Int_t i=0;i<15;i++) covar[i]=0;
+  covar[0]=10.*10.;
+  covar[2]=10.*10.;
+  covar[5]=10.*10./(64.*64.);
+  covar[9]=10.*10./(64.*64.);
+  covar[14]=1*1;
+  //
+
+  Float_t xmin=1000, xmax=-10000;
+  Int_t imin=158, imax=0;
+  for (Int_t i=0;i<160;i++) {
+    AliTPCclusterMI *c=track->GetClusterPointer(i);
+    if (!c) continue;
+    if (sector<0) sector = c->GetDetector();
+    if (c->GetX()<xmin) xmin=c->GetX();
+    if (c->GetX()>xmax) xmax=c->GetX();
+    if (i<imin) imin=i;
+    if (i>imax) imax=i;
+  }
+  if(imax-imin<kMinNcl) {
+    delete track;
+    return 0 ;
+  }
+  // Not succes to rotate
+  if (!track->Rotate(TMath::DegToRad()*(sector%18*20.+10.)-track->GetAlpha())) {
+    delete track;
+    return 0;
+  }
+  //
+  //
+  // fit from inner to outer row
+  //
+  AliExternalTrackParam paramIn;
+  AliExternalTrackParam paramOut;
+  Bool_t isOK=kTRUE;
+  Int_t ncl=0;
+  //
+  //
+  //
+  for (Int_t i=imin; i<=imax; i++){
+    AliTPCclusterMI *c=track->GetClusterPointer(i);
+    if (!c) continue;
+    //    if (RejectCluster(c,track)) continue;
+    sector = (c->GetDetector()%18);
+    if (!track->Rotate(TMath::DegToRad()*(sector%18*20.+10.)-track->GetAlpha())) {
+      //continue;
+    }
+    Double_t r[3]={c->GetX(),c->GetY(),c->GetZ()};
+    Double_t cov[3]={0.01,0.,0.01}; //TODO: correct error parametrisation
+    if (!track->PropagateTo(r[0])) {
+      isOK=kFALSE;
+    }
+    if ( !((static_cast<AliExternalTrackParam*>(track)->Update(&r[1],cov)))) isOK=kFALSE;
+  }
+  if (!isOK) { delete track; return 0;}
+  track->AddCovariance(covar);
+  //
+  //
+  //
+  for (Int_t i=imax; i>=imin; i--){
+    AliTPCclusterMI *c=track->GetClusterPointer(i);
+    if (!c) continue;
+    //if (RejectCluster(c,track)) continue;
+    sector = (c->GetDetector()%18);
+    if (!track->Rotate(TMath::DegToRad()*(sector%18*20.+10.)-track->GetAlpha())) {
+      //continue;
+    }
+    Double_t r[3]={c->GetX(),c->GetY(),c->GetZ()};
+    Double_t cov[3]={0.01,0.,0.01}; //TODO: correct error parametrisation
+    if (!track->PropagateTo(r[0])) {
+      isOK=kFALSE;
+    }
+    if ( !((static_cast<AliExternalTrackParam*>(track)->Update(&r[1],cov)))) isOK=kFALSE;
+  }
+  //if (!isOK) { delete track; return 0;}
+  paramIn = *track;
+  track->AddCovariance(covar);
+  //
+  //
+  for (Int_t i=imin; i<=imax; i++){
+    AliTPCclusterMI *c=track->GetClusterPointer(i);
+    if (!c) continue;
+    sector = (c->GetDetector()%18);
+    if (!track->Rotate(TMath::DegToRad()*(sector%18*20.+10.)-track->GetAlpha())) {
+      //continue;
+    }
+    ncl++;
+    //if (RejectCluster(c,track)) continue;
+    Double_t r[3]={c->GetX(),c->GetY(),c->GetZ()};
+    Double_t cov[3]={0.01,0.,0.01}; //TODO: correct error parametrisation
+    if (!track->PropagateTo(r[0])) {
+      isOK=kFALSE;
+    }
+    if ( !((static_cast<AliExternalTrackParam*>(track)->Update(&r[1],cov)))) isOK=kFALSE;
+  }
+  //if (!isOK) { delete track; return 0;}
+  paramOut=*track;
+  //
+  //
+  //
+  if (parin) (*parin)=paramIn;
+  if (parout) (*parout)=paramOut;
+  return ncl;
+}
+
+
+
+Bool_t AliTPCseed::RefitTrack(AliTPCseed* /*seed*/, Bool_t /*out*/){
+  //
+  //
+  //
+  return kFALSE;
+}
+
+
+
+
+
+
+void  AliTPCseed::GetError(AliTPCclusterMI* cluster, AliExternalTrackParam * param, 
+                                 Double_t& erry, Double_t &errz)
+{
+  //
+  // Get cluster error at given position
+  //
+  AliTPCClusterParam *clusterParam = AliTPCcalibDB::Instance()->GetClusterParam();
+  Double_t tany,tanz;  
+  Double_t snp1=param->GetSnp();
+  tany=snp1/TMath::Sqrt(1.-snp1*snp1);
+  //
+  Double_t tgl1=param->GetTgl();
+  tanz=tgl1/TMath::Sqrt(1.-snp1*snp1);
+  //
+  Int_t padSize = 0;                          // short pads
+  if (cluster->GetDetector() >= 36) {
+    padSize = 1;                              // medium pads 
+    if (cluster->GetRow() > 63) padSize = 2; // long pads
+  }
+
+  erry  = clusterParam->GetError0Par( 0, padSize, (250.0 - TMath::Abs(cluster->GetZ())), TMath::Abs(tany) );
+  errz  = clusterParam->GetError0Par( 1, padSize, (250.0 - TMath::Abs(cluster->GetZ())), TMath::Abs(tanz) );
+}
+
+
+void  AliTPCseed::GetShape(AliTPCclusterMI* cluster, AliExternalTrackParam * param, 
+                                 Double_t& rmsy, Double_t &rmsz)
+{
+  //
+  // Get cluster error at given position
+  //
+  AliTPCClusterParam *clusterParam = AliTPCcalibDB::Instance()->GetClusterParam();
+  Double_t tany,tanz;  
+  Double_t snp1=param->GetSnp();
+  tany=snp1/TMath::Sqrt(1.-snp1*snp1);
+  //
+  Double_t tgl1=param->GetTgl();
+  tanz=tgl1/TMath::Sqrt(1.-snp1*snp1);
+  //
+  Int_t padSize = 0;                          // short pads
+  if (cluster->GetDetector() >= 36) {
+    padSize = 1;                              // medium pads 
+    if (cluster->GetRow() > 63) padSize = 2; // long pads
+  }
+
+  rmsy  = clusterParam->GetRMSQ( 0, padSize, (250.0 - TMath::Abs(cluster->GetZ())), TMath::Abs(tany), TMath::Abs(cluster->GetMax()) );
+  rmsz  = clusterParam->GetRMSQ( 1, padSize, (250.0 - TMath::Abs(cluster->GetZ())), TMath::Abs(tanz) ,TMath::Abs(cluster->GetMax()));
+}