]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TPC/AliTPCseed.cxx
Removing obsolete macros which used the AliTPCtracker
[u/mrichter/AliRoot.git] / TPC / AliTPCseed.cxx
index d7c95a07a021eb335f6f0207b5f2fe177366aed1..b5c30f4fe2df1f834e9fa72e725f28a08476422c 100644 (file)
 
 
 //-----------------------------------------------------------------
+//
 //           Implementation of the TPC seed class
 //        This class is used by the AliTPCtrackerMI class
 //      Origin: Marian Ivanov, CERN, Marian.Ivanov@cern.ch
 //-----------------------------------------------------------------
 #include "TClonesArray.h"
+#include "TGraphErrors.h"
 #include "AliTPCseed.h"
 #include "AliTPCReconstructor.h"
 #include "AliTPCClusterParam.h"
@@ -33,7 +35,7 @@
 #include "AliTPCTransform.h"
 #include "AliSplineFit.h"
 #include "AliCDBManager.h"
-
+#include "AliTPCcalibDButil.h"
 
 
 ClassImp(AliTPCseed)
@@ -68,8 +70,7 @@ AliTPCseed::AliTPCseed():
   fSeed2(-1),
   fMAngular(0),
   fCircular(0),
-  fClusterMap(159),
-  fSharedMap(159)
+  fPoolID(-1)
 {
   //
   for (Int_t i=0;i<160;i++) SetClusterIndex2(i,-3);
@@ -80,13 +81,10 @@ AliTPCseed::AliTPCseed():
     fDEDX[i] = 0.;
     fSDEDX[i] = 1e10;
     fNCDEDX[i] = 0;
+    fNCDEDXInclThres[i] = 0;
   }
+  fDEDX[4] = 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, Bool_t clusterOwner):
@@ -116,8 +114,7 @@ AliTPCseed::AliTPCseed(const AliTPCseed &s, Bool_t clusterOwner):
   fSeed2(-1),
   fMAngular(0),
   fCircular(0),
-  fClusterMap(s.fClusterMap),
-  fSharedMap(s.fSharedMap)
+  fPoolID(-1)
 {
   //---------------------
   // dummy copy constructor
@@ -138,7 +135,9 @@ AliTPCseed::AliTPCseed(const AliTPCseed &s, Bool_t clusterOwner):
     fDEDX[i] = s.fDEDX[i];
     fSDEDX[i] = s.fSDEDX[i];
     fNCDEDX[i] = s.fNCDEDX[i];
+    fNCDEDXInclThres[i] = s.fNCDEDXInclThres[i];
   }
+  fDEDX[4] = s.fDEDX[4];
   for (Int_t i=0;i<12;i++) fOverlapLabels[i] = s.fOverlapLabels[i];
 
 }
@@ -171,8 +170,7 @@ AliTPCseed::AliTPCseed(const AliTPCtrack &t):
   fSeed2(-1),
   fMAngular(0),
   fCircular(0),
-  fClusterMap(159),
-  fSharedMap(159)
+  fPoolID(-1)
 {
   //
   // Constructor from AliTPCtrack
@@ -193,14 +191,10 @@ AliTPCseed::AliTPCseed(const AliTPCtrack &t):
     fDEDX[i] = 0.;
     fSDEDX[i] = 1e10;
     fNCDEDX[i] = 0;
+    fNCDEDXInclThres[i] = 0;
   }
+    fDEDX[4] = 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(Double_t xr, Double_t alpha, const Double_t xx[5],
@@ -231,8 +225,7 @@ AliTPCseed::AliTPCseed(Double_t xr, Double_t alpha, const Double_t xx[5],
   fSeed2(-1),
   fMAngular(0),
   fCircular(0),
-  fClusterMap(159),
-  fSharedMap(159)
+  fPoolID(-1)
 {
   //
   // Constructor
@@ -245,7 +238,9 @@ AliTPCseed::AliTPCseed(Double_t xr, Double_t alpha, const Double_t xx[5],
     fDEDX[i] = 0.;
     fSDEDX[i] = 1e10;
     fNCDEDX[i] = 0;
+    fNCDEDXInclThres[i] = 0;
   }
+    fDEDX[4] = 0;
   for (Int_t i=0;i<12;i++) fOverlapLabels[i] = -1;
 }
 
@@ -265,12 +260,17 @@ AliTPCseed & AliTPCseed::operator=(const AliTPCseed &param)
 {
   //
   // assignment operator 
+  // don't touch pool ID
   //
   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;
+    if (!fClusterOwner) for(Int_t i = 0;i<160;++i)fClusterPointer[i] = param.fClusterPointer[i];
+    else                for(Int_t i = 0;i<160;++i) {
+       delete fClusterPointer[i];
+       fClusterPointer[i] = new AliTPCclusterMI(*(param.fClusterPointer[i]));
+      }
     // leave out fPoint, they are also not copied in the copy ctor...
     // but deleted in the dtor... strange...
     fRow            = param.fRow;
@@ -291,7 +291,9 @@ AliTPCseed & AliTPCseed::operator=(const AliTPCseed &param)
       fDEDX[i]   = param.fDEDX[i];
       fSDEDX[i]  = param.fSDEDX[i];
       fNCDEDX[i] = param.fNCDEDX[i];
+      fNCDEDXInclThres[i] = param.fNCDEDXInclThres[i];
     }
+      fDEDX[4]   = param.fDEDX[4];
     for(Int_t i = 0;i<AliPID::kSPECIES;++i)fTPCr[i] = param.fTPCr[i];
     
     fSeedType = param.fSeedType;
@@ -301,8 +303,6 @@ AliTPCseed & AliTPCseed::operator=(const AliTPCseed &param)
     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);
 }
@@ -399,8 +399,9 @@ void AliTPCseed::Reset(Bool_t all)
   */
 
   if (all){   
-    for (Int_t i=0;i<200;i++) SetClusterIndex2(i,-3);
-    for (Int_t i=0;i<160;i++) fClusterPointer[i]=0;
+    for (Int_t i=200;i--;) SetClusterIndex2(i,-3);
+    if (!fClusterOwner) for (Int_t i=160;i--;) fClusterPointer[i]=0;
+    else                for (Int_t i=160;i--;) {delete fClusterPointer[i]; fClusterPointer[i]=0;}
   }
 
 }
@@ -541,15 +542,30 @@ Bool_t AliTPCseed::Update(const AliCluster *c, Double_t chisq, Int_t index)
   Int_t n=GetNumberOfClusters();
   Int_t idx=GetClusterIndex(n);    // save the current cluster index
 
-  AliCluster cl(*c);  cl.SetSigmaY2(fErrorY2); cl.SetSigmaZ2(fErrorZ2);
+  AliTPCclusterMI cl(*(AliTPCclusterMI*)c);  cl.SetSigmaY2(fErrorY2); cl.SetSigmaZ2(fErrorZ2);
+
+  AliTPCClusterParam * parcl = AliTPCcalibDB::Instance()->GetClusterParam();
+  
+  Float_t ty = TMath::Tan(TMath::ASin(GetSnp()));
+  
+  if(  parcl ){
+    Int_t padSize = 0;                          // short pads
+    if (cl.GetDetector() >= 36) {
+      padSize = 1;                              // medium pads 
+      if (cl.GetRow() > 63) padSize = 2; // long pads
+    }
+    Float_t waveCorr = parcl->GetWaveCorrection( padSize, cl.GetZ(), cl.GetMax(),cl.GetPad(), ty );
+    cl.SetY( cl.GetY() - waveCorr ); 
+  }
+
   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);  
-  }
+    cl.SetY(cl.GetY()-dy);  
+    cl.SetZ(cl.GetZ()-dz);  
+  }  
 
   if (!AliTPCtrack::Update(&cl,chisq,index)) return kFALSE;
   
@@ -595,17 +611,23 @@ Float_t AliTPCseed::CookdEdx(Double_t low, Double_t up,Int_t i1, Int_t i2, Bool_
   fDEDX[1]      = CookdEdxAnalytical(low,up,useTot ,0   ,row0, 0);
   fDEDX[2]      = CookdEdxAnalytical(low,up,useTot ,row0,row1, 0);
   fDEDX[3]      = CookdEdxAnalytical(low,up,useTot ,row1,row2, 0);
+  fDEDX[4]      = CookdEdxAnalytical(low,up,useTot ,row0,row2, 0); // full OROC truncated mean
   //
   fSDEDX[0]     = CookdEdxAnalytical(low,up,useTot ,i1  ,i2,   1);
   fSDEDX[1]     = CookdEdxAnalytical(low,up,useTot ,0   ,row0, 1);
   fSDEDX[2]     = CookdEdxAnalytical(low,up,useTot ,row0,row1, 1);
   fSDEDX[3]     = CookdEdxAnalytical(low,up,useTot ,row1,row2, 1);
   //
-  fNCDEDX[0]    = TMath::Nint(CookdEdxAnalytical(low,up,useTot ,i1  ,i2,   2));
-  fNCDEDX[1]    = TMath::Nint(CookdEdxAnalytical(low,up,useTot ,0   ,row0, 2));
-  fNCDEDX[2]    = TMath::Nint(CookdEdxAnalytical(low,up,useTot ,row0,row1, 2));
-  fNCDEDX[3]    = TMath::Nint(CookdEdxAnalytical(low,up,useTot ,row1,row2, 2));
-
+  fNCDEDX[0]    = TMath::Nint(GetTPCClustInfo(2, 1, i1  , i2));
+  fNCDEDX[1]    = TMath::Nint(GetTPCClustInfo(2, 1, 0   , row0));
+  fNCDEDX[2]    = TMath::Nint(GetTPCClustInfo(2, 1, row0, row1));
+  fNCDEDX[3]    = TMath::Nint(GetTPCClustInfo(2, 1, row1, row2));
+  //
+  fNCDEDXInclThres[0]    = TMath::Nint(GetTPCClustInfo(2, 2, i1  , i2));
+  fNCDEDXInclThres[1]    = TMath::Nint(GetTPCClustInfo(2, 2, 0   , row0));
+  fNCDEDXInclThres[2]    = TMath::Nint(GetTPCClustInfo(2, 2, row0, row1));
+  fNCDEDXInclThres[3]    = TMath::Nint(GetTPCClustInfo(2, 2, row1, row2));
+  //
   SetdEdx(fDEDX[0]);
   return fDEDX[0];
 
@@ -891,25 +913,6 @@ Double_t AliTPCseed::GetYat(Double_t xk) const {
     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, Bool_t shapeNorm,Int_t posNorm, Int_t padNorm, Int_t returnVal){
@@ -1089,9 +1092,9 @@ Float_t  AliTPCseed::CookdEdxNorm(Double_t low, Double_t up, Int_t type, Int_t i
       AliSplineFit * fitMIP = (AliSplineFit *) timeGainSplines->At(0);
       AliSplineFit * fitFPcosmic = (AliSplineFit *) timeGainSplines->At(1);
       if (fitMIP) {
-       corrTimeGain = fitMIP->Eval(time);
+       corrTimeGain = AliTPCcalibDButil::EvalGraphConst(fitMIP, time);/*fitMIP->Eval(time);*/
       } else {
-       if (fitFPcosmic) corrTimeGain = fitFPcosmic->Eval(time); // This value describes the ratio FP-to-MIP, hardwired for the moment
+       if (fitFPcosmic) corrTimeGain = AliTPCcalibDButil::EvalGraphConst(fitFPcosmic, time);/*fitFPcosmic->Eval(time);*/ 
       }
     }
   }
@@ -1103,7 +1106,7 @@ Float_t  AliTPCseed::CookdEdxNorm(Double_t low, Double_t up, Int_t type, Int_t i
   return mean;
 }
 
-Float_t  AliTPCseed::CookdEdxAnalytical(Double_t low, Double_t up, Int_t type, Int_t i1, Int_t i2, Int_t returnVal){
+Float_t  AliTPCseed::CookdEdxAnalytical(Double_t low, Double_t up, Int_t type, Int_t i1, Int_t i2, Int_t returnVal, Int_t rowThres, Int_t mode){
  
   //
   // calculates dedx using the cluster
@@ -1113,9 +1116,16 @@ Float_t  AliTPCseed::CookdEdxAnalytical(Double_t low, Double_t up, Int_t type, I
   // i1-i2  -  the pad-row range used for calculation
   //           
   // posNorm   - usage of pos normalization 
-  // returnVal - 0 return mean
-  //           - 1 return RMS
-  //           - 2 return number of clusters
+  // returnVal - 0  return mean
+  //           - 1  return RMS
+  //           - 2  return number of clusters
+  //           - 3  ratio
+  //           - 4  mean upper half
+  //           - 5  mean  - lower half
+  //           - 6  third moment
+  // mode      - 0 - linear
+  //           - 1 - logatithmic
+  // rowThres  - number of rows before and after given pad row to check for clusters below threshold
   //           
   // normalization parametrization taken from AliTPCClusterParam
   //
@@ -1129,27 +1139,84 @@ Float_t  AliTPCseed::CookdEdxAnalytical(Double_t low, Double_t up, Int_t type, I
   Float_t amp[160];
   Int_t   indexes[160];
   Int_t   ncl=0;
+  Int_t   nclBelowThr = 0; // counts number of clusters below threshold
   //
   //
   Float_t gainGG      = 1;  // gas gain factor -always enabled
   Float_t gainPad     = 1;  // gain map  - used always
   Float_t corrPos     = 1;  // local position correction - if posNorm enabled
-
   //   
   //
   //
   if (AliTPCcalibDB::Instance()->GetParameters()){
     gainGG= AliTPCcalibDB::Instance()->GetParameters()->GetGasGain()/20000;  //relative gas gain
   }
-
+  //
+  // extract time-dependent correction for pressure and temperature variations
+  //
+  UInt_t runNumber = 1;
+  Float_t corrTimeGain = 1;
+  TObjArray * timeGainSplines = 0x0;
+  TGraphErrors * grPadEqual = 0x0;
+  TGraphErrors*  grChamberGain[3]={0x0,0x0,0x0};
+  //
+  AliTPCTransform * trans = AliTPCcalibDB::Instance()->GetTransform();
+  const AliTPCRecoParam * recoParam = AliTPCcalibDB::Instance()->GetTransform()->GetCurrentRecoParam();
+  //
+  if (recoParam->GetNeighborRowsDedx() == 0) rowThres = 0;
+  //
+  if (trans) {
+      runNumber = trans->GetCurrentRunNumber();
+      //AliTPCcalibDB::Instance()->SetRun(runNumber);
+      timeGainSplines = AliTPCcalibDB::Instance()->GetTimeGainSplinesRun(runNumber);
+      if (timeGainSplines && recoParam->GetUseGainCorrectionTime()>0) {
+       UInt_t time = trans->GetCurrentTimeStamp();
+       AliSplineFit * fitMIP = (AliSplineFit *) timeGainSplines->At(0);
+       AliSplineFit * fitFPcosmic = (AliSplineFit *) timeGainSplines->At(1);
+       if (fitMIP) {
+         corrTimeGain =  AliTPCcalibDButil::EvalGraphConst(fitMIP, time); /*fitMIP->Eval(time);*/
+       } else {
+         if (fitFPcosmic) corrTimeGain = AliTPCcalibDButil::EvalGraphConst(fitFPcosmic, time); /*fitFPcosmic->Eval(time); */
+       }
+       //
+       if (type==1) grPadEqual = (TGraphErrors * ) timeGainSplines->FindObject("TGRAPHERRORS_MEANQMAX_PADREGIONGAIN_BEAM_ALL");
+       if (type==0) grPadEqual = (TGraphErrors * ) timeGainSplines->FindObject("TGRAPHERRORS_MEANQTOT_PADREGIONGAIN_BEAM_ALL");
+        const char* names[3]={"SHORT","MEDIUM","LONG"};
+        for (Int_t iPadRegion=0; iPadRegion<3; ++iPadRegion)
+          grChamberGain[iPadRegion]=(TGraphErrors*)timeGainSplines->FindObject(Form("TGRAPHERRORS_MEAN_CHAMBERGAIN_%s_BEAM_ALL",names[iPadRegion]));
+      }
+  }
+  
+  const Float_t kClusterShapeCut = 1.5; // IMPPRTANT TO DO: move value to AliTPCRecoParam
   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 && irow > 1 && irow < 157) {
+      Bool_t isClBefore = kFALSE;
+      Bool_t isClAfter  = kFALSE;
+      for(Int_t ithres = 1; ithres <= rowThres; ithres++) {
+       AliTPCclusterMI * clusterBefore = GetClusterPointer(irow - ithres);
+       if (clusterBefore) isClBefore = kTRUE;
+       AliTPCclusterMI * clusterAfter  = GetClusterPointer(irow + ithres);
+       if (clusterAfter) isClAfter = kTRUE;
+      }
+      if (isClBefore && isClAfter) nclBelowThr++;
+    }
     if (!cluster) continue;
+    //
+    //
     if (TMath::Abs(cluster->GetY())>cluster->GetX()*ktany-kedgey) continue; // edge cluster
+    //
+    AliTPCTrackerPoint * point = GetTrackPoint(irow);
+    if (point==0) continue;    
+    Float_t rsigmay = TMath::Sqrt(point->GetSigmaY());
+    if (rsigmay > kClusterShapeCut) continue;
+    //
+    if (cluster->IsUsed(11)) continue; // remove shared clusters for PbPb
+    //
     Float_t charge= (type%2)? cluster->GetMax():cluster->GetQ();
     Int_t  ipad= 0;
     if (irow>=row0) ipad=1;
@@ -1169,14 +1236,12 @@ Float_t  AliTPCseed::CookdEdxAnalytical(Double_t low, Double_t up, Int_t type, I
       } else {         // OROC
        factor = roc->GetValue(irow - row0, TMath::Nint(cluster->GetPad()));
       }
-      if (factor>0.5) gainPad=factor;
+      if (factor>0.3) gainPad=factor;
     }
-    
     //
     // Do position normalization - relative distance to 
     // center of pad- time bin
     
-    AliTPCTrackerPoint * point = GetTrackPoint(irow);
     Float_t              ty = TMath::Abs(point->GetAngleY());
     Float_t              tz = TMath::Abs(point->GetAngleZ()*TMath::Sqrt(1+ty*ty));
     Float_t yres0 = parcl->GetRMS0(0,ipad,0,0)/param->GetPadPitchWidth(cluster->GetDetector());
@@ -1208,59 +1273,122 @@ Float_t  AliTPCseed::CookdEdxAnalytical(Double_t low, Double_t up, Int_t type, I
       corrPos*=(1+parcl->GetQnormCorr(ipad, type+2,2)*tz*tz);
       //
     }
-
+    //
+    // pad region equalization outside of cluster param
+    //
+    Float_t gainEqualPadRegion = 1;
+    if (grPadEqual && recoParam->GetUseGainCorrectionTime()>0) gainEqualPadRegion = grPadEqual->Eval(ipad);
+    //
+    // chamber-by-chamber equalization outside gain map
+    //
+    Float_t gainChamber = 1;
+    if (grChamberGain[ipad] && recoParam->GetUseGainCorrectionTime()>0) gainChamber = grChamberGain[ipad]->Eval(cluster->GetDetector());
     //
     amp[ncl]=charge;
     amp[ncl]/=gainGG;
     amp[ncl]/=gainPad;
     amp[ncl]/=corrPos;
+    amp[ncl]/=gainEqualPadRegion;
+    amp[ncl]/=gainChamber;
     //
     ncl++;
   }
 
-  if (type>3) return ncl; 
+  if (type==2) return ncl; 
   TMath::Sort(ncl,amp, indexes, kFALSE);
-
+  //
   if (ncl<10) return 0;
-  
+  //
+  Double_t * ampWithBelow = new Double_t[ncl + nclBelowThr];
+  for(Int_t iCl = 0; iCl < ncl + nclBelowThr; iCl++) {
+    if (iCl < nclBelowThr) {
+      ampWithBelow[iCl] = amp[indexes[0]];
+    } else {
+      ampWithBelow[iCl] = amp[indexes[iCl - nclBelowThr]];
+    }
+  }
+  //printf("DEBUG: %i shit %f", nclBelowThr, amp[indexes[0]]);
+  //
   Float_t suma=0;
   Float_t suma2=0;  
+  Float_t suma3=0;  
+  Float_t sumaS=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]];
-    suma2+=amp[indexes[icl]]*amp[indexes[icl]];
-    sumn++;
-  }
-  Float_t mean =suma/sumn;
-  Float_t rms  =TMath::Sqrt(TMath::Abs(suma2/sumn-mean*mean));
+  // upper,and lower part statistic
+  Float_t sumL=0, sumL2=0, sumLN=0;
+  Float_t sumD=0, sumD2=0, sumDN=0;
+
+  Int_t icl0=TMath::Nint((ncl + nclBelowThr)*low);
+  Int_t icl1=TMath::Nint((ncl + nclBelowThr)*up);
+  Int_t iclm=TMath::Nint((ncl + nclBelowThr)*(low +(up+low)*0.5));
   //
-  // do time-dependent correction for pressure and temperature variations
-  UInt_t runNumber = 1;
-  Float_t corrTimeGain = 1;
-  AliTPCTransform * trans = AliTPCcalibDB::Instance()->GetTransform();
-  const AliTPCRecoParam * recoParam = AliTPCcalibDB::Instance()->GetTransform()->GetCurrentRecoParam();
-  if (trans && recoParam->GetUseGainCorrectionTime()>0) {
-    runNumber = trans->GetCurrentRunNumber();
-    //AliTPCcalibDB::Instance()->SetRun(runNumber);
-    TObjArray * timeGainSplines = AliTPCcalibDB::Instance()->GetTimeGainSplinesRun(runNumber);
-    if (timeGainSplines) {
-      UInt_t time = trans->GetCurrentTimeStamp();
-      AliSplineFit * fitMIP = (AliSplineFit *) timeGainSplines->At(0);
-      AliSplineFit * fitFPcosmic = (AliSplineFit *) timeGainSplines->At(1);
-      if (fitMIP) {
-       corrTimeGain = fitMIP->Eval(time);
-      } else {
-       if (fitFPcosmic) corrTimeGain = fitFPcosmic->Eval(time); // This value describes the ratio FP-to-MIP, hardwired for the moment
+  for (Int_t icl=icl0; icl<icl1;icl++){
+    if (ampWithBelow[icl]<0.1) continue;
+    Double_t camp=ampWithBelow[icl]/corrTimeGain;
+    if (mode==1) camp= TMath::Log(camp);
+    if (icl<icl1){
+      suma+=camp;
+      suma2+=camp*camp;
+      suma3+=camp*camp*camp;
+      sumaS+=TMath::Power(TMath::Abs(camp),1./3.);
+      sumn++;
+    }
+    if (icl>iclm){
+      sumL+=camp;
+      sumL2+=camp*camp;
+      sumLN++;
       }
+    if (icl<=iclm){
+      sumD+=camp;
+      sumD2+=camp*camp;
+      sumDN++;
     }
   }
-  mean /= corrTimeGain;
-  rms /= corrTimeGain;
+  //
+  Float_t mean = 0;
+  Float_t meanL = 0;  
+  Float_t meanD = 0;           // lower half mean
+  if (sumn > 1e-30)   mean =suma/sumn;
+  if (sumLN > 1e-30)  meanL =sumL/sumLN;
+  if (sumDN > 1e-30)  meanD =(sumD/sumDN);
+  /*
+  Float_t mean =suma/sumn;
+  Float_t meanL = sumL/sumLN;  
+  Float_t meanD =(sumD/sumDN);           // lower half mean
+  */
+
+  Float_t rms = 0;
+  Float_t mean2=0;
+  Float_t mean3=0;
+  Float_t meanS=0;
+
+  if(sumn>0){
+    rms = TMath::Sqrt(TMath::Abs(suma2/sumn-mean*mean));
+    mean2=suma2/sumn;
+    mean3=suma3/sumn;
+    meanS=sumaS/sumn;
+  }
+
+  if (mean2>0) mean2=TMath::Power(TMath::Abs(mean2),1./2.);
+  if (mean3>0) mean3=TMath::Power(TMath::Abs(mean3),1./3.);
+  if (meanS>0) meanS=TMath::Power(TMath::Abs(meanS),3.);
+  //
+  if (mode==1) mean=TMath::Exp(mean);
+  if (mode==1) meanL=TMath::Exp(meanL);  // upper truncation
+  if (mode==1) meanD=TMath::Exp(meanD);  // lower truncation
+  //
+  delete [] ampWithBelow;
+  
+
   //
   if (returnVal==1) return rms;
   if (returnVal==2) return ncl;
+  if (returnVal==3) return Double_t(nclBelowThr)/Double_t(nclBelowThr+ncl);
+  if (returnVal==4) return meanL;
+  if (returnVal==5) return meanD;
+  if (returnVal==6) return mean2;
+  if (returnVal==7) return mean3;
+  if (returnVal==8) return meanS;
   return mean;
 }
 
@@ -1321,7 +1449,7 @@ Int_t  AliTPCseed::RefitTrack(AliTPCseed *seed, AliExternalTrackParam * parin, A
   Int_t imin=158, imax=0;
   for (Int_t i=0;i<160;i++) {
     AliTPCclusterMI *c=track->GetClusterPointer(i);
-    if (!c) continue;
+    if (!c || (track->GetClusterIndex(i) & 0x8000)) continue; 
     if (sector<0) sector = c->GetDetector();
     if (c->GetX()<xmin) xmin=c->GetX();
     if (c->GetX()>xmax) xmax=c->GetX();
@@ -1350,7 +1478,7 @@ Int_t  AliTPCseed::RefitTrack(AliTPCseed *seed, AliExternalTrackParam * parin, A
   //
   for (Int_t i=imin; i<=imax; i++){
     AliTPCclusterMI *c=track->GetClusterPointer(i);
-    if (!c) continue;
+    if (!c || (track->GetClusterIndex(i) & 0x8000)) continue; 
     //    if (RejectCluster(c,track)) continue;
     sector = (c->GetDetector()%18);
     if (!track->Rotate(TMath::DegToRad()*(sector%18*20.+10.)-track->GetAlpha())) {
@@ -1370,7 +1498,7 @@ Int_t  AliTPCseed::RefitTrack(AliTPCseed *seed, AliExternalTrackParam * parin, A
   //
   for (Int_t i=imax; i>=imin; i--){
     AliTPCclusterMI *c=track->GetClusterPointer(i);
-    if (!c) continue;
+    if (!c || (track->GetClusterIndex(i) & 0x8000)) continue;
     //if (RejectCluster(c,track)) continue;
     sector = (c->GetDetector()%18);
     if (!track->Rotate(TMath::DegToRad()*(sector%18*20.+10.)-track->GetAlpha())) {
@@ -1390,7 +1518,7 @@ Int_t  AliTPCseed::RefitTrack(AliTPCseed *seed, AliExternalTrackParam * parin, A
   //
   for (Int_t i=imin; i<=imax; i++){
     AliTPCclusterMI *c=track->GetClusterPointer(i);
-    if (!c) continue;
+    if (!c || (track->GetClusterIndex(i) & 0x8000)) continue; 
     sector = (c->GetDetector()%18);
     if (!track->Rotate(TMath::DegToRad()*(sector%18*20.+10.)-track->GetAlpha())) {
       //continue;
@@ -1536,3 +1664,82 @@ Double_t AliTPCseed::GetQCorrShape(Int_t ipad, Int_t type,Float_t z, Float_t ty,
 
 }
 
+
+//_______________________________________________________________________
+Float_t AliTPCseed::GetTPCClustInfo(Int_t nNeighbours, Int_t type, Int_t row0, Int_t row1)
+{
+  //
+  // TPC cluster information
+  // type 0: get fraction of found/findable clusters with neighbourhood definition
+  //      1: found clusters
+  //      2: findable (number of clusters above and below threshold)
+  //
+  // definition of findable clusters:
+  //            a cluster is defined as findable if there is another cluster
+  //           within +- nNeighbours pad rows. The idea is to overcome threshold
+  //           effects with a very simple algorithm.
+  //
+
+  const Float_t kClusterShapeCut = 1.5; // IMPPRTANT TO DO: move value to AliTPCRecoParam
+  const Float_t ktany = TMath::Tan(TMath::DegToRad()*10);
+  const Float_t kedgey =3.;
+  
+  Float_t ncl = 0;
+  Float_t nclBelowThr = 0; // counts number of clusters below threshold
+
+  for (Int_t irow=row0; irow<row1; irow++){
+    AliTPCclusterMI* cluster = GetClusterPointer(irow);
+
+    if (!cluster && irow > 1 && irow < 157) {
+      Bool_t isClBefore = kFALSE;
+      Bool_t isClAfter  = kFALSE;
+      for(Int_t ithres = 1; ithres <= nNeighbours; ithres++) {
+       AliTPCclusterMI * clusterBefore = GetClusterPointer(irow - ithres);
+       if (clusterBefore) isClBefore = kTRUE;
+       AliTPCclusterMI * clusterAfter  = GetClusterPointer(irow + ithres);
+       if (clusterAfter) isClAfter = kTRUE;
+      }
+      if (isClBefore && isClAfter) nclBelowThr++;
+    }
+    if (!cluster) continue;
+    //
+    //
+    if (TMath::Abs(cluster->GetY())>cluster->GetX()*ktany-kedgey) continue; // edge cluster
+    //
+    AliTPCTrackerPoint * point = GetTrackPoint(irow);
+    if (point==0) continue;    
+    Float_t rsigmay = TMath::Sqrt(point->GetSigmaY());
+    if (rsigmay > kClusterShapeCut) continue;
+    //
+    if (cluster->IsUsed(11)) continue; // remove shared clusters for PbPb
+    ncl++;
+  }
+
+  if(ncl<10)
+    return 0;
+  if(type==0) 
+    if(nclBelowThr+ncl>0)
+      return ncl/(nclBelowThr+ncl);
+  if(type==1)
+    return ncl;
+  if(type==2)
+    return ncl+nclBelowThr;
+  return 0;
+}
+//_______________________________________________________________________
+Int_t AliTPCseed::GetNumberOfClustersIndices() {
+  Int_t ncls = 0;
+  for (int i=0; i < 160; i++) {
+    if ((fIndex[i] & 0x8000) == 0)
+      ncls++;
+  }
+  return ncls;
+}
+
+//_______________________________________________________________________
+void AliTPCseed::Clear(Option_t*)
+{
+  // formally seed may allocate memory for clusters (althought this should not happen for 
+  // the seeds in the pool). Hence we need this method for fwd. compatibility
+  if (fClusterOwner) for (int i=160;i--;) {delete fClusterPointer[i]; fClusterPointer[i] = 0;}
+}