]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TPC/AliTPCtrackerMI.cxx
TPC HV dip status
[u/mrichter/AliRoot.git] / TPC / AliTPCtrackerMI.cxx
index 8e013e54966c629f415328aac4af7433e7495b08..f194cf48bde8583d0dd6c7f63a8b575c77f141d3 100644 (file)
 #include <TFile.h>
 #include <TObjArray.h>
 #include <TTree.h>
+#include <TGraphErrors.h>
 #include "AliLog.h"
 #include "AliComplexCluster.h"
 #include "AliESDEvent.h"
 #include "AliTrackPointArray.h"
 #include "TRandom.h"
 #include "AliTPCcalibDB.h"
+#include "AliTPCcalibDButil.h"
 #include "AliTPCTransform.h"
 #include "AliTPCClusterParam.h"
-
+#include "AliTPCdEdxInfo.h"
+#include "AliClonesPool.h"
+#include "AliPoolsSet.h"
+#include "AliDCSSensorArray.h"
+#include "AliDCSSensor.h"
+#include "AliDAQ.h"
 //
 
 ClassImp(AliTPCtrackerMI)
@@ -197,11 +204,20 @@ AliTPCtrackerMI::AliTPCtrackerMI()
                 fSeeds(0),
                 fIteration(0),
                 fkParam(0),
-                fDebugStreamer(0)
+                fDebugStreamer(0),
+                fUseHLTClusters(4),
+                fSeedsPool(0),
+                fKinksPool(0)
 {
   //
   // default constructor
   //
+  for (Int_t irow=0; irow<200; irow++){
+    fXRow[irow]=0;
+    fYMax[irow]=0;
+    fPadLength[irow]=0;
+  }
+
 }
 //_____________________________________________________________________
 
@@ -213,8 +229,10 @@ Int_t AliTPCtrackerMI::UpdateTrack(AliTPCseed * track, Int_t accept){
 
 
   AliTPCclusterMI* c =track->GetCurrentCluster();
-  if (accept>0) track->SetCurrentClusterIndex1(track->GetCurrentClusterIndex1() | 0x8000);  //sign not accepted clusters
-
+  if (accept > 0) //sign not accepted clusters
+    track->SetCurrentClusterIndex1(track->GetCurrentClusterIndex1() | 0x8000);  
+  else // unsign accpeted clusters
+    track->SetCurrentClusterIndex1(track->GetCurrentClusterIndex1() & 0xffff7fff);  
   UInt_t i = track->GetCurrentClusterIndex1();
 
   Int_t sec=(i&0xff000000)>>24; 
@@ -362,6 +380,16 @@ Int_t AliTPCtrackerMI::AcceptCluster(AliTPCseed * seed, AliTPCclusterMI * cluste
     seed->SetNFoundable(seed->GetNFoundable()-1);
     return 2;    
   }
+
+  if (fUseHLTClusters == 3 || fUseHLTClusters == 4) {
+    if (fIteration==2){
+      if(!AliTPCReconstructor::GetRecoParam()->GetUseHLTOnePadCluster()) {
+       if (TMath::Abs(cluster->GetSigmaY2()) < kAlmost0)
+         return 2;
+      }
+    }
+  }
+
   return 0;
 }
 
@@ -389,7 +417,10 @@ AliTracker(),
                 fSeeds(0),
                 fIteration(0),
                 fkParam(0),
-                fDebugStreamer(0)
+                 fDebugStreamer(0),
+                 fUseHLTClusters(4),
+                 fSeedsPool(0),
+                 fKinksPool(0)
 {
   //---------------------------------------------------------------------
   // The main TPC tracker constructor
@@ -422,6 +453,12 @@ AliTracker(),
   if (AliTPCReconstructor::StreamLevel()>0) {
     fDebugStreamer = new TTreeSRedirector("TPCdebug.root");
   }
+  //
+  fSeedsPool = new AliClonesPool("AliTPCseed",1000);
+  fSeedsPool->SetName("TPCSeed");
+  fKinksPool = new AliClonesPool("AliKink",1000);
+  fKinksPool->SetName("TPCKink");
+
 }
 //________________________________________________________________________
 AliTPCtrackerMI::AliTPCtrackerMI(const AliTPCtrackerMI &t):
@@ -443,12 +480,21 @@ AliTPCtrackerMI::AliTPCtrackerMI(const AliTPCtrackerMI &t):
                 fSeeds(0),
                 fIteration(0),
                 fkParam(0),
-                fDebugStreamer(0)
+                 fDebugStreamer(0),
+                 fUseHLTClusters(4),
+                 fSeedsPool(0),
+                 fKinksPool(0)
 {
   //------------------------------------
   // dummy copy constructor
   //------------------------------------------------------------------
   fOutput=t.fOutput;
+  for (Int_t irow=0; irow<200; irow++){
+    fXRow[irow]=0;
+    fYMax[irow]=0;
+    fPadLength[irow]=0;
+  }
+
 }
 AliTPCtrackerMI & AliTPCtrackerMI::operator=(const AliTPCtrackerMI& /*r*/)
 {
@@ -465,10 +511,12 @@ AliTPCtrackerMI::~AliTPCtrackerMI() {
   delete[] fInnerSec;
   delete[] fOuterSec;
   if (fSeeds) {
-    fSeeds->Delete(); 
+    fSeeds->Clear(); 
     delete fSeeds;
   }
   if (fDebugStreamer) delete fDebugStreamer;
+  if (fSeedsPool && !fPools) delete fSeedsPool; // RS: owned by reconstruction pools (if exist)
+  if (fKinksPool && !fPools) delete fKinksPool; // RS: owned by reconstruction pools (if exist)
 }
 
 
@@ -477,7 +525,8 @@ void AliTPCtrackerMI::FillESD(const TObjArray* arr)
   //
   //
   //fill esds using updated tracks
-  if (fEvent){
+  if (!fEvent) return;
+  
     // write tracks to the event
     // store index of the track
     Int_t nseed=arr->GetEntriesFast();
@@ -608,9 +657,9 @@ void AliTPCtrackerMI::FillESD(const TObjArray* arr)
        kink->SetIndex(it, knkId<0 ? 0:1); // update track index of the kink: mother at 0, daughter at 1
       }
     }
-    // << account for suppressed tracks in the kink indices (RS)
-  }
-  AliInfo(Form("Number of filled ESDs-\t%d\n",fEvent->GetNumberOfTracks()));
+    // << account for suppressed tracks in the kink indices (RS)  
+    AliInfo(Form("Number of filled ESDs-\t%d\n",fEvent->GetNumberOfTracks()));
+  
 }
 
 
@@ -1116,7 +1165,7 @@ Bool_t   AliTPCtrackerMI::GetProlongation(Double_t x1, Double_t x2, Double_t x[5
 
 Int_t  AliTPCtrackerMI::LoadClusters (TTree *const tree)
 {
-  //
+  // load clusters
   //
   fInput = tree;
   return LoadClusters();
@@ -1157,15 +1206,13 @@ Int_t  AliTPCtrackerMI::LoadClusters(const TObjArray *arr)
     }
     if (left ==0){
       tpcrow->SetN1(clrow->GetArray()->GetEntriesFast());
-      tpcrow->SetClusters1(new AliTPCclusterMI[tpcrow->GetN1()]);
       for (Int_t j=0;j<tpcrow->GetN1();++j) 
        tpcrow->SetCluster1(j, *(AliTPCclusterMI*)(clrow->GetArray()->At(j)));
     }
     if (left ==1){
       tpcrow->SetN2(clrow->GetArray()->GetEntriesFast());
-      tpcrow->SetClusters2(new AliTPCclusterMI[tpcrow->GetN2()]);
       for (Int_t j=0;j<tpcrow->GetN2();++j) 
-       tpcrow->SetCluster2(j,*(AliTPCclusterMI*)(clrow->GetArray()->At(j)));
+       tpcrow->SetCluster2(j, *(AliTPCclusterMI*)(clrow->GetArray()->At(j)));
     }
     clrow->GetArray()->Clear("C");
   }
@@ -1238,14 +1285,17 @@ Int_t  AliTPCtrackerMI::LoadClusters()
 {
   //
   // load clusters to the memory
-  AliTPCClustersRow *clrow= new AliTPCClustersRow("AliTPCclusterMI");
+  static AliTPCClustersRow *clrow= new AliTPCClustersRow("AliTPCclusterMI");
   //
   //  TTree * tree = fClustersArray.GetTree();
 
   TTree * tree = fInput;
   TBranch * br = tree->GetBranch("Segment");
   br->SetAddress(&clrow);
-  //
+
+  // Conversion of pad, row coordinates in local tracking coords.
+  // Could be skipped here; is already done in clusterfinder
+
   Int_t j=Int_t(tree->GetEntries());
   for (Int_t i=0; i<j; i++) {
     br->GetEntry(i);
@@ -1268,19 +1318,17 @@ Int_t  AliTPCtrackerMI::LoadClusters()
     }
     if (left ==0){
       tpcrow->SetN1(clrow->GetArray()->GetEntriesFast());
-      tpcrow->SetClusters1(new AliTPCclusterMI[tpcrow->GetN1()]);
       for (Int_t k=0;k<tpcrow->GetN1();++k) 
        tpcrow->SetCluster1(k, *(AliTPCclusterMI*)(clrow->GetArray()->At(k)));
     }
     if (left ==1){
       tpcrow->SetN2(clrow->GetArray()->GetEntriesFast());
-      tpcrow->SetClusters2(new AliTPCclusterMI[tpcrow->GetN2()]);
       for (Int_t k=0;k<tpcrow->GetN2();++k) 
-       tpcrow->SetCluster2(k,*(AliTPCclusterMI*)(clrow->GetArray()->At(k)));
+       tpcrow->SetCluster2(k, *(AliTPCclusterMI*)(clrow->GetArray()->At(k)));
     }
   }
   //
-  delete clrow;
+  clrow->Clear("C");
   LoadOuterSectors();
   LoadInnerSectors();
   return 0;
@@ -1345,11 +1393,13 @@ void AliTPCtrackerMI::FillClusterArray(TObjArray* array) const{
 
 void   AliTPCtrackerMI::Transform(AliTPCclusterMI * cluster){
   //
+  // transformation
   //
-  //
-  AliTPCTransform *transform = AliTPCcalibDB::Instance()->GetTransform() ;
+  AliTPCcalibDB * calibDB = AliTPCcalibDB::Instance();
+  AliTPCTransform *transform = calibDB->GetTransform() ;
   if (!transform) {
     AliFatal("Tranformations not in calibDB");
+    return;
   }
   transform->SetCurrentRecoParam((AliTPCRecoParam*)AliTPCReconstructor::GetRecoParam());
   Double_t x[3]={cluster->GetRow(),cluster->GetPad(),cluster->GetTimeBin()};
@@ -1382,22 +1432,23 @@ void   AliTPCtrackerMI::Transform(AliTPCclusterMI * cluster){
   cluster->SetY(x[1]);
   cluster->SetZ(x[2]);
   // The old stuff:
-
   //
   // 
   //
   //if (!fkParam->IsGeoRead()) fkParam->ReadGeoMatrices();
-  TGeoHMatrix  *mat = fkParam->GetClusterMatrix(cluster->GetDetector());
-  //TGeoHMatrix  mat;
-  Double_t pos[3]= {cluster->GetX(),cluster->GetY(),cluster->GetZ()};
-  Double_t posC[3]={cluster->GetX(),cluster->GetY(),cluster->GetZ()};
-  if (mat) mat->LocalToMaster(pos,posC);
-  else{
-    // chack Loading of Geo matrices from GeoManager - TEMPORARY FIX
-  }
-  cluster->SetX(posC[0]);
-  cluster->SetY(posC[1]);
-  cluster->SetZ(posC[2]);
+  if (AliTPCReconstructor::GetRecoParam()->GetUseSectorAlignment() && (!calibDB->HasAlignmentOCDB())){
+    TGeoHMatrix  *mat = fkParam->GetClusterMatrix(cluster->GetDetector());
+    //TGeoHMatrix  mat;
+    Double_t pos[3]= {cluster->GetX(),cluster->GetY(),cluster->GetZ()};
+    Double_t posC[3]={cluster->GetX(),cluster->GetY(),cluster->GetZ()};
+    if (mat) mat->LocalToMaster(pos,posC);
+    else{
+      // chack Loading of Geo matrices from GeoManager - TEMPORARY FIX
+    }
+    cluster->SetX(posC[0]);
+    cluster->SetY(posC[1]);
+    cluster->SetZ(posC[2]);
+  }
 }
 
 //_____________________________________________________________________________
@@ -1510,7 +1561,7 @@ AliTPCclusterMI *AliTPCtrackerMI::GetClusterMI(Int_t index) const {
   Int_t ncl=(index&0x00007fff)>>00;
 
   const AliTPCtrackerRow * tpcrow=0;
-  AliTPCclusterMI * clrow =0;
+  TClonesArray * clrow =0;
 
   if (sec<0 || sec>=fkNIS*4) {
     AliWarning(Form("Wrong sector %d",sec));
@@ -1548,7 +1599,7 @@ AliTPCclusterMI *AliTPCtrackerMI::GetClusterMI(Int_t index) const {
     }
   }
 
-  return &(clrow[ncl]);      
+  return (AliTPCclusterMI*)clrow->At(ncl);
   
 }
 
@@ -1573,9 +1624,10 @@ Int_t AliTPCtrackerMI::FollowToNext(AliTPCseed& t, Int_t nr) {
   if (fIteration>0 && tpcindex>=-1){  //if we have already clusters 
     //        
     if (tpcindex==-1) return 0; //track in dead zone
-    if (tpcindex>0){     //
+    if (tpcindex >= 0){     //
       cl = t.GetClusterPointer(nr);
-      if ( (cl==0) ) cl = GetClusterMI(tpcindex);
+      //if (cl==0) cl = GetClusterMI(tpcindex);
+      if (!cl) cl = GetClusterMI(tpcindex);
       t.SetCurrentClusterIndex1(tpcindex); 
     }
     if (cl){      
@@ -1607,7 +1659,11 @@ Int_t AliTPCtrackerMI::FollowToNext(AliTPCseed& t, Int_t nr) {
        t.SetNFoundable(t.GetNFoundable()+1);
        UpdateTrack(&t,accept);
        return 1;
-      }    
+      }
+      else { // Remove old cluster from track
+       t.SetClusterIndex(nr, -3);
+       t.SetClusterPointer(nr, 0);
+      }
     }
   }
   if (TMath::Abs(t.GetSnp())>AliTPCReconstructor::GetMaxSnpTracker()) return 0;  // cut on angle
@@ -1619,7 +1675,11 @@ Int_t AliTPCtrackerMI::FollowToNext(AliTPCseed& t, Int_t nr) {
   //
   UInt_t index=0;
   //  if (TMath::Abs(t.GetSnp())>0.95 || TMath::Abs(x*t.GetC()-t.GetEta())>0.95) return 0;// patch 28 fev 06
-  Double_t  y=t.GetYat(x);
+  if (!t.PropagateTo(x)) {
+    if (fIteration==0) t.SetRemoval(10);
+    return 0;
+  }
+  Double_t y = t.GetY(); 
   if (TMath::Abs(y)>ymax){
     if (y > ymax) {
       t.SetRelativeSector((t.GetRelativeSector()+1) % fN);
@@ -1630,14 +1690,13 @@ Int_t AliTPCtrackerMI::FollowToNext(AliTPCseed& t, Int_t nr) {
       if (!t.Rotate(-fSectors->GetAlpha())) 
        return 0;
     }
-    //return 1;
+    if (!t.PropagateTo(x)) {
+      if (fIteration==0) t.SetRemoval(10);
+      return 0;
+    }
+    y = t.GetY();
   }
   //
-  if (!t.PropagateTo(x)) {
-    if (fIteration==0) t.SetRemoval(10);
-    return 0;
-  }
-  y=t.GetY(); 
   Double_t z=t.GetZ();
   //
 
@@ -1762,7 +1821,7 @@ Int_t AliTPCtrackerMI::UpdateClusters(AliTPCseed& t,  Int_t nr) {
   // This function tries to find a track prolongation to next pad row
   //-----------------------------------------------------------------
   t.SetCurrentCluster(0);
-  t.SetCurrentClusterIndex1(0);   
+  t.SetCurrentClusterIndex1(-3);   
    
   Double_t xt=t.GetX();
   Int_t     row = GetRowNumber(xt)-1; 
@@ -1847,9 +1906,9 @@ Int_t AliTPCtrackerMI::UpdateClusters(AliTPCseed& t,  Int_t nr) {
 
   if (!cl){
     index = t.GetClusterIndex2(nr);    
-    if ( (index>0) && (index&0x8000)==0){
+    if ( (index >= 0) && (index&0x8000)==0){
       cl = t.GetClusterPointer(nr);
-      if ( (cl==0) && (index>0)) cl = GetClusterMI(index);
+      if ( (cl==0) && (index >= 0)) cl = GetClusterMI(index);
       t.SetCurrentClusterIndex1(index);
       if (cl) {
        t.SetCurrentCluster(cl);
@@ -1900,8 +1959,8 @@ Int_t AliTPCtrackerMI::FollowToNextCluster(AliTPCseed & t, Int_t nr) {
  
   } else {
     if (fIteration==0){
-      if ( ( (t.GetSigmaY2()+t.GetSigmaZ2())>0.16)&& t.GetNumberOfClusters()>18) t.SetRemoval(10);      
-      if (  t.GetChi2()/t.GetNumberOfClusters()>6 &&t.GetNumberOfClusters()>18) t.SetRemoval(10);      
+      if ( t.GetNumberOfClusters()>18 && ( (t.GetSigmaY2()+t.GetSigmaZ2())>0.16)) t.SetRemoval(10);      
+      if ( t.GetNumberOfClusters()>18 && t.GetChi2()/t.GetNumberOfClusters()>6 ) t.SetRemoval(10);      
 
       if (( (t.GetNFoundable()*0.5 > t.GetNumberOfClusters()) || t.GetNoCluster()>15)) t.SetRemoval(10);
     }
@@ -1912,19 +1971,23 @@ Int_t AliTPCtrackerMI::FollowToNextCluster(AliTPCseed & t, Int_t nr) {
 
 
 //_____________________________________________________________________________
-Int_t AliTPCtrackerMI::FollowProlongation(AliTPCseed& t, Int_t rf, Int_t step) {
+Int_t AliTPCtrackerMI::FollowProlongation(AliTPCseed& t, Int_t rf, Int_t step, Bool_t fromSeeds) {
   //-----------------------------------------------------------------
   // This function tries to find a track prolongation.
   //-----------------------------------------------------------------
   Double_t xt=t.GetX();
   //
-  Double_t alpha=t.GetAlpha() - fSectors->GetAlphaShift();
+  Double_t alpha=t.GetAlpha();
   if (alpha > 2.*TMath::Pi()) alpha -= 2.*TMath::Pi();  
   if (alpha < 0.            ) alpha += 2.*TMath::Pi();  
   //
   t.SetRelativeSector(Int_t(alpha/fSectors->GetAlpha()+0.0001)%fN);
     
-  Int_t first = GetRowNumber(xt)-1;
+  Int_t first = GetRowNumber(xt);
+  if (!fromSeeds)
+    first -= step;
+  if (first < 0)
+    first = 0;
   for (Int_t nr= first; nr>=rf; nr-=step) {
     // update kink info
     if (t.GetKinkIndexes()[0]>0){
@@ -1967,19 +2030,23 @@ Int_t AliTPCtrackerMI::FollowProlongation(AliTPCseed& t, Int_t rf, Int_t step) {
 
 
 
-Int_t AliTPCtrackerMI::FollowBackProlongation(AliTPCseed& t, Int_t rf) {
+Int_t AliTPCtrackerMI::FollowBackProlongation(AliTPCseed& t, Int_t rf, Bool_t fromSeeds) {
   //-----------------------------------------------------------------
   // This function tries to find a track prolongation.
   //-----------------------------------------------------------------
   //
   Double_t xt=t.GetX();  
-  Double_t alpha=t.GetAlpha() - fSectors->GetAlphaShift();
+  Double_t alpha=t.GetAlpha();
   if (alpha > 2.*TMath::Pi()) alpha -= 2.*TMath::Pi();  
   if (alpha < 0.            ) alpha += 2.*TMath::Pi();  
   t.SetRelativeSector(Int_t(alpha/fSectors->GetAlpha()+0.0001)%fN);
     
   Int_t first = t.GetFirstPoint();
-  if (first<GetRowNumber(xt)+1) first = GetRowNumber(xt)+1;
+  Int_t ri = GetRowNumber(xt); 
+  if (!fromSeeds)
+    ri += 1;
+
+  if (first<ri) first = ri;
   //
   if (first<0) first=0;
   for (Int_t nr=first; nr<=rf; nr++) {
@@ -2022,7 +2089,7 @@ Int_t AliTPCtrackerMI::FollowBackProlongation(AliTPCseed& t, Int_t rf) {
    
 Float_t AliTPCtrackerMI::OverlapFactor(AliTPCseed * s1, AliTPCseed * s2, Int_t &sum1, Int_t & sum2)
 {
-  //
+  // overlapping factor
   //
   sum1=0;
   sum2=0;
@@ -2065,7 +2132,7 @@ Float_t AliTPCtrackerMI::OverlapFactor(AliTPCseed * s1, AliTPCseed * s2, Int_t &
 
 void  AliTPCtrackerMI::SignShared(AliTPCseed * s1, AliTPCseed * s2)
 {
-  //
+  // shared clusters
   //
   Float_t thetaCut = 0.2;//+10.*TMath::Sqrt(s1->GetSigmaTglZ()+ s2->GetSigmaTglZ());
   if (TMath::Abs(s1->GetTgl()-s2->GetTgl())>thetaCut) return;
@@ -2086,11 +2153,7 @@ void  AliTPCtrackerMI::SignShared(AliTPCseed * s1, AliTPCseed * s2)
     //    if ( (s1->GetClusterIndex2(i)&0xFFFF8FFF)==(s2->GetClusterIndex2(i)&0xFFFF8FFF) && s1->GetClusterIndex2(i)>0) {
     if ( (s1->GetClusterIndex2(i))==(s2->GetClusterIndex2(i)) && s1->GetClusterIndex2(i)>0) {
       sumshared++;
-      s1->SetSharedMapBit(i, kTRUE);
-      s2->SetSharedMapBit(i, kTRUE);
     }
-    if (s1->GetClusterIndex2(i)>0)
-      s1->SetClusterMapBit(i, kTRUE);
   }
   if (sumshared>cutN0){
     // sign clusters
@@ -2148,7 +2211,7 @@ void  AliTPCtrackerMI::SignShared(TObjArray * arr)
   for (Int_t i=0; i<nseed; i++) {
     AliTPCseed *pt=(AliTPCseed*)arr->UncheckedAt(i);    
     if (!pt) continue;
-    for (Int_t j=0;j<=12;j++){
+    for (Int_t j=0;j<12;j++){
       pt->SetOverlapLabel(j,0);
     }
   }
@@ -2239,12 +2302,7 @@ void AliTPCtrackerMI::RemoveUsed2(TObjArray * arr, Float_t factor1,  Float_t fac
     if (!pt) continue;
     //
     if (quality[trackindex]<0){
-      if (pt) {
-       delete arr->RemoveAt(trackindex);
-      }
-      else{
-       arr->RemoveAt(trackindex);
-      }
+      fSeedsPool->MarkSlotFree( arr->RemoveAt(trackindex) );
       continue;
     }
     //
@@ -2272,7 +2330,7 @@ void AliTPCtrackerMI::RemoveUsed2(TObjArray * arr, Float_t factor1,  Float_t fac
            "pt.="<<pt<<
            "\n";
        }
-       delete arr->RemoveAt(trackindex);
+       fSeedsPool->MarkSlotFree( arr->RemoveAt(trackindex) );
        continue;
       }      
       if (pt->GetNumberOfClusters()<50&&(found-0.5*shared)<minimal){  //remove short tracks
@@ -2284,7 +2342,7 @@ void AliTPCtrackerMI::RemoveUsed2(TObjArray * arr, Float_t factor1,  Float_t fac
            "pt.="<<pt<<
            "\n";
        }
-       delete arr->RemoveAt(trackindex);
+       fSeedsPool->MarkSlotFree( arr->RemoveAt(trackindex) );
        continue;
       }
     }
@@ -2341,23 +2399,25 @@ void AliTPCtrackerMI::DumpClusters(Int_t iter, TObjArray *trackArray)
 
   for (Int_t sec=0;sec<fkNIS;sec++){
     for (Int_t row=0;row<fInnerSec->GetNRows();row++){
-      AliTPCclusterMI *cl = fInnerSec[sec][row].GetClusters1();
+      TClonesArray *cla = fInnerSec[sec][row].GetClusters1();
       for (Int_t icl =0;icl< fInnerSec[sec][row].GetN1();icl++){    
-       Float_t gx[3];  cl[icl].GetGlobalXYZ(gx);
+       AliTPCclusterMI* cl = (AliTPCclusterMI*)cla->At(icl);
+       Float_t gx[3];  cl->GetGlobalXYZ(gx);
        (*fDebugStreamer)<<"clDump"<< 
          "iter="<<iter<<
-         "cl.="<<&cl[icl]<<      
+         "cl.="<<cl<<      
          "gx0="<<gx[0]<<
          "gx1="<<gx[1]<<
          "gx2="<<gx[2]<<
          "\n";
       }
-      cl = fInnerSec[sec][row].GetClusters2();
+      cla = fInnerSec[sec][row].GetClusters2();
       for (Int_t icl =0;icl< fInnerSec[sec][row].GetN2();icl++){
-       Float_t gx[3];  cl[icl].GetGlobalXYZ(gx);
+       AliTPCclusterMI* cl = (AliTPCclusterMI*)cla->At(icl);
+       Float_t gx[3];  cl->GetGlobalXYZ(gx);
        (*fDebugStreamer)<<"clDump"<< 
          "iter="<<iter<<
-         "cl.="<<&cl[icl]<<
+         "cl.="<<cl<<
          "gx0="<<gx[0]<<
          "gx1="<<gx[1]<<
          "gx2="<<gx[2]<<
@@ -2368,23 +2428,27 @@ void AliTPCtrackerMI::DumpClusters(Int_t iter, TObjArray *trackArray)
   
   for (Int_t sec=0;sec<fkNOS;sec++){
     for (Int_t row=0;row<fOuterSec->GetNRows();row++){
-      AliTPCclusterMI *cl = fOuterSec[sec][row].GetClusters1();
+      TClonesArray *cla = fOuterSec[sec][row].GetClusters1();
       for (Int_t icl =0;icl< fOuterSec[sec][row].GetN1();icl++){
-       Float_t gx[3];  cl[icl].GetGlobalXYZ(gx);
+       Float_t gx[3];  
+       AliTPCclusterMI* cl = (AliTPCclusterMI*) cla->At(icl);
+       cl->GetGlobalXYZ(gx);
        (*fDebugStreamer)<<"clDump"<< 
          "iter="<<iter<<
-         "cl.="<<&cl[icl]<<
+         "cl.="<<cl<<
          "gx0="<<gx[0]<<
          "gx1="<<gx[1]<<
          "gx2="<<gx[2]<<
          "\n";      
       }
-      cl = fOuterSec[sec][row].GetClusters2();
+      cla = fOuterSec[sec][row].GetClusters2();
       for (Int_t icl =0;icl< fOuterSec[sec][row].GetN2();icl++){
-       Float_t gx[3];  cl[icl].GetGlobalXYZ(gx);
+       Float_t gx[3];  
+       AliTPCclusterMI* cl = (AliTPCclusterMI*) cla->At(icl);
+       cl->GetGlobalXYZ(gx);
        (*fDebugStreamer)<<"clDump"<< 
          "iter="<<iter<<
-         "cl.="<<&cl[icl]<<
+         "cl.="<<cl<<
          "gx0="<<gx[0]<<
          "gx1="<<gx[1]<<
          "gx2="<<gx[2]<<
@@ -2402,27 +2466,27 @@ void AliTPCtrackerMI::UnsignClusters()
   
   for (Int_t sec=0;sec<fkNIS;sec++){
     for (Int_t row=0;row<fInnerSec->GetNRows();row++){
-      AliTPCclusterMI *cl = fInnerSec[sec][row].GetClusters1();
+      TClonesArray *cla = fInnerSec[sec][row].GetClusters1();
       for (Int_t icl =0;icl< fInnerSec[sec][row].GetN1();icl++)
        //      if (cl[icl].IsUsed(10))         
-       cl[icl].Use(-1);
-      cl = fInnerSec[sec][row].GetClusters2();
+       ((AliTPCclusterMI*) cla->At(icl))->Use(-1);
+      cla = fInnerSec[sec][row].GetClusters2();
       for (Int_t icl =0;icl< fInnerSec[sec][row].GetN2();icl++)
        //if (cl[icl].IsUsed(10))       
-         cl[icl].Use(-1);      
+       ((AliTPCclusterMI*) cla->At(icl))->Use(-1);
     }
   }
   
   for (Int_t sec=0;sec<fkNOS;sec++){
     for (Int_t row=0;row<fOuterSec->GetNRows();row++){
-      AliTPCclusterMI *cl = fOuterSec[sec][row].GetClusters1();
+      TClonesArray *cla = fOuterSec[sec][row].GetClusters1();
       for (Int_t icl =0;icl< fOuterSec[sec][row].GetN1();icl++)
        //if (cl[icl].IsUsed(10))       
-         cl[icl].Use(-1);
-      cl = fOuterSec[sec][row].GetClusters2();
+       ((AliTPCclusterMI*) cla->At(icl))->Use(-1);
+      cla = fOuterSec[sec][row].GetClusters2();
       for (Int_t icl =0;icl< fOuterSec[sec][row].GetN2();icl++)
        //if (cl[icl].IsUsed(10))       
-       cl[icl].Use(-1);      
+       ((AliTPCclusterMI*) cla->At(icl))->Use(-1);
     }
   }
   
@@ -2519,7 +2583,7 @@ void AliTPCtrackerMI::SignClusters(const TObjArray * arr, Float_t fnumber, Float
     pt->GetClusterStatistic(0,160,found, foundable,shared);
     if (shared/float(found)>0.3) {
       if (shared/float(found)>0.9 ){
-       //delete arr->RemoveAt(i);
+       //fSeedsPool->MarkSlotFree( arr->RemoveAt(i) );
       }
       continue;
     }
@@ -2596,59 +2660,6 @@ void AliTPCtrackerMI::SignClusters(const TObjArray * arr, Float_t fnumber, Float
 }
 
 
-void  AliTPCtrackerMI::StopNotActive(const TObjArray * arr, Int_t row0, Float_t th0, Float_t th1, Float_t th2) const
-{
-  // stop not active tracks
-  // take th1 as threshold for number of founded to number of foundable on last 10 active rows
-  // take th2 as threshold for number of founded to number of foundable on last 20 active rows 
-  Int_t nseed = arr->GetEntriesFast();  
-  //
-  for (Int_t i=0; i<nseed; i++) {
-    AliTPCseed *pt=(AliTPCseed*)arr->UncheckedAt(i);    
-    if (!pt) {
-      continue;
-    }
-    if (!(pt->IsActive())) continue;
-    StopNotActive(pt,row0,th0, th1,th2);
-  }
-}
-
-
-
-void  AliTPCtrackerMI::StopNotActive(AliTPCseed * seed, Int_t row0, Float_t th0, Float_t th1,
- Float_t th2) const
-{
-  // stop not active tracks
-  // take th1 as threshold for number of founded to number of foundable on last 10 active rows
-  // take th2 as threshold for number of founded to number of foundable on last 20 active rows 
-  Int_t sumgood1  = 0;
-  Int_t sumgood2  = 0;
-  Int_t foundable = 0;
-  Int_t maxindex = seed->GetLastPoint();  //last foundable row
-  if (seed->GetNFoundable()*th0 > seed->GetNumberOfClusters()) {
-    seed->Desactivate(10) ;
-    return;
-  }
-
-  for (Int_t i=row0; i<maxindex; i++){
-    Int_t index = seed->GetClusterIndex2(i);
-    if (index!=-1) foundable++;
-    //if (!c) continue;
-    if (foundable<=30) sumgood1++;
-    if (foundable<=50) {
-      sumgood2++;
-    }
-    else{ 
-      break;
-    }        
-  }
-  if (foundable>=30.){ 
-     if (sumgood1<(th1*30.)) seed->Desactivate(10);
-  }
-  if (foundable>=50)
-    if (sumgood2<(th2*50.)) seed->Desactivate(10);
-}
-
 
 Int_t AliTPCtrackerMI::RefitInward(AliESDEvent *event)
 {
@@ -2656,8 +2667,29 @@ Int_t AliTPCtrackerMI::RefitInward(AliESDEvent *event)
   // back propagation of ESD tracks
   //
   //return 0;
+  if (!event) return 0;
   const Int_t kMaxFriendTracks=2000;
   fEvent = event;
+  // extract correction object for multiplicity dependence of dEdx
+  TObjArray * gainCalibArray = AliTPCcalibDB::Instance()->GetTimeGainSplinesRun(event->GetRunNumber());
+
+  AliTPCTransform *transform = AliTPCcalibDB::Instance()->GetTransform() ;
+  if (!transform) {
+    AliFatal("Tranformations not in RefitInward");
+    return 0;
+  }
+  transform->SetCurrentRecoParam((AliTPCRecoParam*)AliTPCReconstructor::GetRecoParam());
+  const AliTPCRecoParam * recoParam = AliTPCcalibDB::Instance()->GetTransform()->GetCurrentRecoParam();
+  Int_t nContribut = event->GetNumberOfTracks();
+  TGraphErrors * graphMultDependenceDeDx = 0x0;
+  if (recoParam && recoParam->GetUseMultiplicityCorrectionDedx() && gainCalibArray) {
+    if (recoParam->GetUseTotCharge()) {
+      graphMultDependenceDeDx = (TGraphErrors *) gainCalibArray->FindObject("TGRAPHERRORS_MEANQTOT_MULTIPLICITYDEPENDENCE_BEAM_ALL");
+    } else {
+      graphMultDependenceDeDx = (TGraphErrors *) gainCalibArray->FindObject("TGRAPHERRORS_MEANQMAX_MULTIPLICITYDEPENDENCE_BEAM_ALL");
+    }
+  }
+  //
   ReadSeeds(event,2);
   fIteration=2;
   //PrepareForProlongation(fSeeds,1);
@@ -2703,13 +2735,11 @@ Int_t AliTPCtrackerMI::RefitInward(AliESDEvent *event)
     seed->PropagateTo(fkParam->GetInnerRadiusLow());
     seed->UpdatePoints();
     AddCovariance(seed);
-    MakeBitmaps(seed);
+    MakeESDBitmaps(seed, esd);
     seed->CookdEdx(0.02,0.6);
     CookLabel(seed,0.1); //For comparison only
-    esd->SetTPCClusterMap(seed->GetClusterMap());
-    esd->SetTPCSharedMap(seed->GetSharedMap());
     //
-    if (AliTPCReconstructor::StreamLevel()>1 && seed!=0&&esd!=0) {
+    if (AliTPCReconstructor::StreamLevel()>1 && seed!=0) {
       TTreeSRedirector &cstream = *fDebugStreamer;
       cstream<<"Crefit"<<
        "Esd.="<<esd<<
@@ -2724,13 +2754,42 @@ Int_t AliTPCtrackerMI::RefitInward(AliESDEvent *event)
       Int_t   ndedx = seed->GetNCDEDX(0);
       Float_t sdedx = seed->GetSDEDX(0);
       Float_t dedx  = seed->GetdEdx();
+      // apply mutliplicity dependent dEdx correction if available
+      if (graphMultDependenceDeDx) {
+       Double_t corrGain =  AliTPCcalibDButil::EvalGraphConst(graphMultDependenceDeDx, nContribut);
+       dedx += (1 - corrGain)*50.; // MIP is normalized to 50
+      }
       esd->SetTPCsignal(dedx, sdedx, ndedx);
       //
+      // fill new dEdx information
+      //
+      Double32_t signal[4]; 
+      Char_t ncl[3]; 
+      Char_t nrows[3];
+      //
+      for(Int_t iarr=0;iarr<3;iarr++) {
+       signal[iarr] = seed->GetDEDXregion(iarr+1);
+       ncl[iarr] = seed->GetNCDEDX(iarr+1);
+       nrows[iarr] = seed->GetNCDEDXInclThres(iarr+1);
+      }
+      signal[3] = seed->GetDEDXregion(4);
+      //
+      AliClonesPool* pooldEdx = fPools ? fPools->GetPoolTPCdEdx() : 0;
+      AliTPCdEdxInfo * infoTpcPid = 0;
+      if (pooldEdx) {
+       infoTpcPid = new(pooldEdx->NextFreeSlot()) AliTPCdEdxInfo(); 
+       pooldEdx->RegisterClone(pooldEdx);
+      }
+      else infoTpcPid = new AliTPCdEdxInfo();
+      infoTpcPid->SetTPCSignalRegionInfo(signal, ncl, nrows);
+      esd->SetTPCdEdxInfo(infoTpcPid);
+      //
       // add seed to the esd track in Calib level
       //
       Bool_t storeFriend = gRandom->Rndm()<(kMaxFriendTracks)/Float_t(nseed);
-      if (AliTPCReconstructor::StreamLevel()>0 &&storeFriend){
-       AliTPCseed * seedCopy = new AliTPCseed(*seed, kTRUE); 
+      if (AliTPCReconstructor::StreamLevel()>0 &&storeFriend){ 
+       AliTPCseed * seedCopy = new( fSeedsPool->NextFreeSlot() ) AliTPCseed(*seed, kTRUE); 
+       fSeedsPool->RegisterClone(seedCopy);
        esd->AddCalibObject(seedCopy);
       }
       ntracks++;
@@ -2751,7 +2810,7 @@ Int_t AliTPCtrackerMI::PropagateBack(AliESDEvent *event)
   //
   // back propagation of ESD tracks
   //
-
+  if (!event) return 0;
   fEvent = event;
   fIteration = 1;
   ReadSeeds(event,1);
@@ -2771,6 +2830,7 @@ Int_t AliTPCtrackerMI::PropagateBack(AliESDEvent *event)
     seed->UpdatePoints();
     AddCovariance(seed);
     AliESDtrack *esd=event->GetTrack(i);
+    if (!esd) continue; //never happen
     if (seed->GetNumberOfClusters()<60 && seed->GetNumberOfClusters()<(esd->GetTPCclusters(0) -5)*0.8){
       AliExternalTrackParam paramIn;
       AliExternalTrackParam paramOut;
@@ -2820,22 +2880,39 @@ Int_t AliTPCtrackerMI::PropagateBack(AliESDEvent *event)
 }
 
 
-void AliTPCtrackerMI::DeleteSeeds()
+Int_t AliTPCtrackerMI::PostProcess(AliESDEvent *event)
 {
   //
-  //delete Seeds
+  // Post process events 
+  //
+  if (!event) return 0;
 
-  Int_t nseed = fSeeds->GetEntriesFast();
-  for (Int_t i=0;i<nseed;i++){
-    AliTPCseed * seed = (AliTPCseed*)fSeeds->At(i);
-    if (seed) delete fSeeds->RemoveAt(i);
+  //
+  // Set TPC event status
+  // 
+
+  // event affected by HV dip
+  // reset TPC status
+  if(IsTPCHVDipEvent(event)) { 
+    event->ResetDetectorStatus(AliDAQ::kTPC);
   }
-  delete fSeeds;
+  //printf("Status %d \n", event->IsDetectorOn(AliDAQ::kTPC));
 
+  return 0;
+}
+
+
+void AliTPCtrackerMI::DeleteSeeds()
+{
+  //
+  fSeeds->Clear();
+  fSeedsPool->Clear("C"); // nominally allocate memory
+  delete fSeeds;
   fSeeds =0;
 }
 
-void AliTPCtrackerMI::ReadSeeds(AliESDEvent *const event, Int_t direction)
+void AliTPCtrackerMI::ReadSeeds(const AliESDEvent *const event, Int_t direction)
 {
   //
   //read seeds from the event
@@ -2858,7 +2935,8 @@ void AliTPCtrackerMI::ReadSeeds(AliESDEvent *const event, Int_t direction)
     AliTPCtrack t(*esd);
     t.SetNumberOfClusters(0);
     //    AliTPCseed *seed = new AliTPCseed(t,t.GetAlpha());
-    AliTPCseed *seed = new AliTPCseed(t/*,t.GetAlpha()*/);
+    AliTPCseed *seed = new( fSeedsPool->NextFreeSlot() ) AliTPCseed(t/*,t.GetAlpha()*/);
+    fSeedsPool->RegisterClone(seed);
     seed->SetUniqueID(esd->GetID());
     AddCovariance(seed);   //add systematic ucertainty
     for (Int_t ikink=0;ikink<3;ikink++) {
@@ -2881,7 +2959,7 @@ void AliTPCtrackerMI::ReadSeeds(AliESDEvent *const event, Int_t direction)
     if ( direction ==2 &&(status & AliESDtrack::kTRDrefit) == 0 ) seed->ResetCovariance(10.);
     //if ( direction ==2 && ((status & AliESDtrack::kTPCout) == 0) ) {
     //  fSeeds->AddAt(0,i);
-    //  delete seed;
+    //  fSeedsPool->MarkSlotFree( seed );
     //  continue;    
     //}
     if ( direction ==2 &&(status & AliESDtrack::kTRDrefit) > 0 )  {
@@ -2902,24 +2980,27 @@ void AliTPCtrackerMI::ReadSeeds(AliESDEvent *const event, Int_t direction)
     // rotate to the local coordinate system
     //   
     fSectors=fInnerSec; fN=fkNIS;    
-    Double_t alpha=seed->GetAlpha() - fSectors->GetAlphaShift();
+    Double_t alpha=seed->GetAlpha();
     if (alpha > 2.*TMath::Pi()) alpha -= 2.*TMath::Pi();
     if (alpha < 0.            ) alpha += 2.*TMath::Pi();
-    Int_t ns=Int_t(alpha/fSectors->GetAlpha())%fN;
+    Int_t ns=Int_t(alpha/fSectors->GetAlpha()+0.0001)%fN;
     alpha =ns*fSectors->GetAlpha() + fSectors->GetAlphaShift();
+    alpha-=seed->GetAlpha();  
     if (alpha<-TMath::Pi()) alpha += 2*TMath::Pi();
     if (alpha>=TMath::Pi()) alpha -= 2*TMath::Pi();
-    alpha-=seed->GetAlpha();  
-    if (!seed->Rotate(alpha)) {
-      delete seed;
-      continue;
+    if (TMath::Abs(alpha) > 0.001) { // This should not happen normally
+      AliWarning(Form("Rotating track over %f",alpha));
+      if (!seed->Rotate(alpha)) {
+       fSeedsPool->MarkSlotFree( seed );
+       continue;
+      }
     }
     seed->SetESD(esd);
     // sign clusters
     if (esd->GetKinkIndex(0)<=0){
       for (Int_t irow=0;irow<160;irow++){
        Int_t index = seed->GetClusterIndex2(irow);    
-       if (index>0){ 
+       if (index >= 0){ 
          //
          AliTPCclusterMI * cl = GetClusterMI(index);
          seed->SetClusterPointer(irow,cl);
@@ -2962,7 +3043,8 @@ void AliTPCtrackerMI::MakeSeeds3(TObjArray * arr, Int_t sec, Int_t i1, Int_t i2,
   Double_t x[5], c[15];
   //  Int_t di = i1-i2;
   //
-  AliTPCseed * seed = new AliTPCseed();
+  AliTPCseed * seed = new( fSeedsPool->NextFreeSlot() ) AliTPCseed();
+  fSeedsPool->RegisterClone(seed);
   Double_t alpha=fSectors->GetAlpha(), shift=fSectors->GetAlphaShift();
   Double_t cs=cos(alpha), sn=sin(alpha);
   //
@@ -3172,9 +3254,9 @@ void AliTPCtrackerMI::MakeSeeds3(TObjArray * arr, Int_t sec, Int_t i1, Int_t i2,
        //      if (!BuildSeed(kr1[is],kcl,0,x1,x2,x3,x,c)) continue;
        
         UInt_t index=kr1.GetIndex(is);
-       seed->~AliTPCseed(); // this does not set the pointer to 0...
-       AliTPCseed *track=new(seed) AliTPCseed(x1, ns*alpha+shift, x, c, index);
-       
+       if (seed) {fSeedsPool->MarkSlotFree(seed); seed = 0;}
+       AliTPCseed *track = seed = new( fSeedsPool->NextFreeSlot() ) AliTPCseed(x1, ns*alpha+shift, x, c, index);
+       fSeedsPool->RegisterClone(seed);
        track->SetIsSeeding(kTRUE);
        track->SetSeed1(i1);
        track->SetSeed2(i2);
@@ -3186,8 +3268,7 @@ void AliTPCtrackerMI::MakeSeeds3(TObjArray * arr, Int_t sec, Int_t i1, Int_t i2,
          Int_t foundable,found,shared;
          track->GetClusterStatistic((i1+i2)/2,i1, found, foundable, shared, kTRUE);
          if ((found<0.55*foundable)  || shared>0.5*found || (track->GetSigmaY2()+track->GetSigmaZ2())>0.5){
-           seed->Reset();
-           seed->~AliTPCseed();
+           fSeedsPool->MarkSlotFree(seed); seed = 0;
            continue;
          }
          //}
@@ -3205,8 +3286,7 @@ void AliTPCtrackerMI::MakeSeeds3(TObjArray * arr, Int_t sec, Int_t i1, Int_t i2,
        if (track->GetNumberOfClusters()<(i1-i2)*0.5 || 
            track->GetNumberOfClusters() < track->GetNFoundable()*0.6 || 
            track->GetNShared()>0.4*track->GetNumberOfClusters() ) {
-         seed->Reset();
-         seed->~AliTPCseed();
+         fSeedsPool->MarkSlotFree(seed); seed = 0;
          continue;
        }
        nout1++;
@@ -3226,13 +3306,11 @@ void AliTPCtrackerMI::MakeSeeds3(TObjArray * arr, Int_t sec, Int_t i1, Int_t i2,
              track2->SetBConstrain(kFALSE);
              track2->SetSeedType(1);
              arr->AddLast(track2); 
-             seed->Reset();
-             seed->~AliTPCseed();
+             fSeedsPool->MarkSlotFree( seed ); seed = 0;
              continue;         
            }
            else{
-             seed->Reset();
-             seed->~AliTPCseed();
+             fSeedsPool->MarkSlotFree( seed ); seed = 0;
              continue;
            
            }
@@ -3240,8 +3318,9 @@ void AliTPCtrackerMI::MakeSeeds3(TObjArray * arr, Int_t sec, Int_t i1, Int_t i2,
        }
       
        track->SetSeedType(0);
-       arr->AddLast(track); 
-       seed = new AliTPCseed;  
+       arr->AddLast(track); // note, track is seed, don't free the seed
+       seed = new( fSeedsPool->NextFreeSlot() ) AliTPCseed;    
+       fSeedsPool->RegisterClone(seed);
        nout2++;
        // don't consider other combinations
        if (track->GetNumberOfClusters() > track->GetNFoundable()*0.8)
@@ -3252,7 +3331,7 @@ void AliTPCtrackerMI::MakeSeeds3(TObjArray * arr, Int_t sec, Int_t i1, Int_t i2,
   if (fDebug>3){
     Info("MakeSeeds3","\nSeeding statistic:\t%d\t%d\t%d\t%d\t%d\t%d",nin0,nin1,nin2,nin,nout1,nout2);
   }
-  delete seed;
+  if (seed) fSeedsPool->MarkSlotFree( seed );
 }
 
 
@@ -3280,7 +3359,8 @@ void AliTPCtrackerMI::MakeSeeds5(TObjArray * arr, Int_t sec, Int_t i1, Int_t i2,
   Double_t x[5], c[15];
   //
   // make temporary seed
-  AliTPCseed * seed = new AliTPCseed;
+  AliTPCseed * seed = new( fSeedsPool->NextFreeSlot() ) AliTPCseed;
+  fSeedsPool->RegisterClone(seed);
   Double_t alpha=fOuterSec->GetAlpha(), shift=fOuterSec->GetAlphaShift();
   //  Double_t cs=cos(alpha), sn=sin(alpha);
   //
@@ -3343,7 +3423,7 @@ void AliTPCtrackerMI::MakeSeeds5(TObjArray * arr, Int_t sec, Int_t i1, Int_t i2,
       y3 = kcl->GetY(); 
       // apply angular cuts
       if (TMath::Abs(y1-y3)>dymax) continue;
-      x3 = x3; 
+      //x3 = x3; 
       z3 = kcl->GetZ();        
       if (TMath::Abs(z1-z3)>dzmax) continue;
       //
@@ -3461,8 +3541,9 @@ void AliTPCtrackerMI::MakeSeeds5(TObjArray * arr, Int_t sec, Int_t i1, Int_t i2,
       //       if (!BuildSeed(kr1[is],kcl,0,x1,x2,x3,x,c)) continue;
       
       index=kr1.GetIndex(is);
-      seed->~AliTPCseed();
-      AliTPCseed *track=new(seed) AliTPCseed(x1, sec*alpha+shift, x, c, index);
+      if (seed) {fSeedsPool->MarkSlotFree( seed ); seed = 0;}
+      AliTPCseed *track = seed = new( fSeedsPool->NextFreeSlot() ) AliTPCseed(x1, sec*alpha+shift, x, c, index);
+      fSeedsPool->RegisterClone(seed);
       
       track->SetIsSeeding(kTRUE);
 
@@ -3470,8 +3551,7 @@ void AliTPCtrackerMI::MakeSeeds5(TObjArray * arr, Int_t sec, Int_t i1, Int_t i2,
       FollowProlongation(*track, i1-7,1);
       if (track->GetNumberOfClusters() < track->GetNFoundable()*0.75 || 
          track->GetNShared()>0.6*track->GetNumberOfClusters() || ( track->GetSigmaY2()+ track->GetSigmaZ2())>0.6){
-       seed->Reset();
-       seed->~AliTPCseed();
+       fSeedsPool->MarkSlotFree( seed ); seed = 0;
        continue;
       }
       nout1++;
@@ -3485,8 +3565,7 @@ void AliTPCtrackerMI::MakeSeeds5(TObjArray * arr, Int_t sec, Int_t i1, Int_t i2,
       if (track->GetNumberOfClusters()<(i1-i2)*0.5 || 
          track->GetNumberOfClusters()<track->GetNFoundable()*0.7 || 
          track->GetNShared()>2. || track->GetChi2()/track->GetNumberOfClusters()>6 || ( track->GetSigmaY2()+ track->GetSigmaZ2())>0.5 ) {
-       seed->Reset();
-       seed->~AliTPCseed();
+       fSeedsPool->MarkSlotFree( seed ); seed = 0;
        continue;
       }
    
@@ -3496,9 +3575,8 @@ void AliTPCtrackerMI::MakeSeeds5(TObjArray * arr, Int_t sec, Int_t i1, Int_t i2,
        FollowProlongation(*track2, i2,1);
        track2->SetBConstrain(kFALSE);
        track2->SetSeedType(4);
-       arr->AddLast(track2); 
-       seed->Reset();
-       seed->~AliTPCseed();
+       arr->AddLast(track2);
+       fSeedsPool->MarkSlotFree( seed ); seed = 0;
       }
       
    
@@ -3511,7 +3589,7 @@ void AliTPCtrackerMI::MakeSeeds5(TObjArray * arr, Int_t sec, Int_t i1, Int_t i2,
   if (fDebug>3){
     Info("MakeSeeds5","\nSeeding statiistic:\t%d\t%d\t%d\t%d\t%d\t%d\t%d",nin0,nin1,nin2,nin,nout1,nout2,nout3);
   }
-  delete seed;
+  if (seed) fSeedsPool->MarkSlotFree(seed);
 }
 
 
@@ -3543,7 +3621,8 @@ void AliTPCtrackerMI::MakeSeeds2(TObjArray * arr, Int_t sec, Int_t i1, Int_t i2,
 
   AliTPCpolyTrack polytrack;
   Int_t nclusters=fSectors[sec][row0];
-  AliTPCseed * seed = new AliTPCseed;
+  AliTPCseed * seed = new( fSeedsPool->NextFreeSlot() ) AliTPCseed;
+  fSeedsPool->RegisterClone(seed);
 
   Int_t sumused=0;
   Int_t cused=0;
@@ -3741,8 +3820,9 @@ void AliTPCtrackerMI::MakeSeeds2(TObjArray * arr, Int_t sec, Int_t i1, Int_t i2,
 
        UInt_t index=0;
        //kr0.GetIndex(is);
-       seed->~AliTPCseed();
-       AliTPCseed *track=new(seed) AliTPCseed(x1,sec*alpha+shift,x,c,index);
+       if (seed) {fSeedsPool->MarkSlotFree( seed ); seed = 0;}
+       AliTPCseed *track = seed = new( fSeedsPool->NextFreeSlot() ) AliTPCseed(x1,sec*alpha+shift,x,c,index);
+       fSeedsPool->RegisterClone(seed);
        track->SetIsSeeding(kTRUE);
        Int_t rc=FollowProlongation(*track, i2);        
        if (constrain) track->SetBConstrain(1);
@@ -3754,13 +3834,12 @@ void AliTPCtrackerMI::MakeSeeds2(TObjArray * arr, Int_t sec, Int_t i1, Int_t i2,
        if (rc==0 || track->GetNumberOfClusters()<(i1-i2)*0.5 || 
            track->GetNumberOfClusters() < track->GetNFoundable()*0.6 || 
            track->GetNShared()>0.4*track->GetNumberOfClusters()) {
-         //delete track;
-         seed->Reset();
-         seed->~AliTPCseed();
+         fSeedsPool->MarkSlotFree( seed ); seed = 0;
        }
        else {
-         arr->AddLast(track);
-         seed = new AliTPCseed;
+         arr->AddLast(track); // track IS seed, don't free seed
+         seed = new( fSeedsPool->NextFreeSlot() ) AliTPCseed;
+         fSeedsPool->RegisterClone(seed);
        }
        nin3++;
       }
@@ -3769,7 +3848,7 @@ void AliTPCtrackerMI::MakeSeeds2(TObjArray * arr, Int_t sec, Int_t i1, Int_t i2,
   if (fDebug>3){
     Info("MakeSeeds2","\nSeeding statiistic:\t%d\t%d\t%d\t%d",nin0,nin1,nin2,nin3);
   }
-  delete seed;
+  if (seed) fSeedsPool->MarkSlotFree( seed );
 }
 
 
@@ -3800,7 +3879,7 @@ AliTPCseed *AliTPCtrackerMI::MakeSeed(AliTPCseed *const track, Float_t r0, Float
       if ( (index<p0) || x0[0]<0 ){
        if (trpoint->GetX()>1){
          clindex = track->GetClusterIndex2(i);
-         if (clindex>0){       
+         if (clindex >= 0){    
            x0[0] = trpoint->GetX();
            x0[1] = trpoint->GetY();
            x0[2] = trpoint->GetZ();
@@ -3811,7 +3890,7 @@ AliTPCseed *AliTPCtrackerMI::MakeSeed(AliTPCseed *const track, Float_t r0, Float
 
       if ( (index<p1) &&(trpoint->GetX()>1)){
        clindex = track->GetClusterIndex2(i);
-       if (clindex>0){
+       if (clindex >= 0){
          x1[0] = trpoint->GetX();
          x1[1] = trpoint->GetY();
          x1[2] = trpoint->GetZ();
@@ -3820,7 +3899,7 @@ AliTPCseed *AliTPCtrackerMI::MakeSeed(AliTPCseed *const track, Float_t r0, Float
       }
       if ( (index<p2) &&(trpoint->GetX()>1)){
        clindex = track->GetClusterIndex2(i);
-       if (clindex>0){
+       if (clindex >= 0){
          x2[0] = trpoint->GetX();
          x2[1] = trpoint->GetY();
          x2[2] = trpoint->GetZ(); 
@@ -3891,7 +3970,8 @@ AliTPCseed *AliTPCtrackerMI::MakeSeed(AliTPCseed *const track, Float_t r0, Float
   c[14]=f40*sy1*f40+f42*sy2*f42+f43*sy3*f43;
   
   //  Int_t row1 = fSectors->GetRowNumber(x2[0]);
-  AliTPCseed *seed=new  AliTPCseed(x2[0], sec2*fSectors->GetAlpha()+fSectors->GetAlphaShift(), x, c, 0);
+  AliTPCseed *seed = new( fSeedsPool->NextFreeSlot() )  AliTPCseed(x2[0], sec2*fSectors->GetAlpha()+fSectors->GetAlphaShift(), x, c, 0);
+  fSeedsPool->RegisterClone(seed);
   //  Double_t y0,z0,y1,z1, y2,z2;
   //seed->GetProlongation(x0[0],y0,z0);
   // seed->GetProlongation(x1[0],y1,z1);
@@ -3923,8 +4003,8 @@ AliTPCseed *AliTPCtrackerMI::ReSeed(const AliTPCseed *track, Float_t r0, Float_t
   ipos[2] = TMath::Min(int(r2*nclusters),nclusters-1);   // last point
   //
   //
-  Double_t  xyz[3][3];
-  Int_t     row[3],sec[3]={0,0,0};
+  Double_t  xyz[3][3]={{0}};
+  Int_t     row[3]={0},sec[3]={0,0,0};
   //
   // find track row position at given ratio of the length
   Int_t index=-1;
@@ -4011,7 +4091,8 @@ AliTPCseed *AliTPCtrackerMI::ReSeed(const AliTPCseed *track, Float_t r0, Float_t
   c[14]=f40*sy1*f40+f42*sy2*f42+f43*sy3*f43;
   
   //  Int_t row1 = fSectors->GetRowNumber(xyz[2][0]);
-  AliTPCseed *seed=new  AliTPCseed(xyz[2][0], sec[2]*fSectors->GetAlpha()+fSectors->GetAlphaShift(), x, c, 0);
+  AliTPCseed *seed=new( fSeedsPool->NextFreeSlot() ) AliTPCseed(xyz[2][0], sec[2]*fSectors->GetAlpha()+fSectors->GetAlphaShift(), x, c, 0);
+  fSeedsPool->RegisterClone(seed);
   seed->SetLastPoint(row[2]);
   seed->SetFirstPoint(row[2]);  
   return seed;
@@ -4160,7 +4241,8 @@ AliTPCseed *AliTPCtrackerMI::ReSeed(AliTPCseed *track,Int_t r0, Bool_t forward)
   c[14]=f40*sy1*f40+f42*sy2*f42+f43*sy3*f43;
   
   //  Int_t row1 = fSectors->GetRowNumber(xyz[2][0]);
-  AliTPCseed *seed=new  AliTPCseed(xyz[2][0], sec[2]*fSectors->GetAlpha()+fSectors->GetAlphaShift(), x, c, 0);
+  AliTPCseed *seed=new( fSeedsPool->NextFreeSlot() )  AliTPCseed(xyz[2][0], sec[2]*fSectors->GetAlpha()+fSectors->GetAlphaShift(), x, c, 0);
+  fSeedsPool->RegisterClone(seed);
   seed->SetLastPoint(row[2]);
   seed->SetFirstPoint(row[2]);  
   for (Int_t i=row[0];i<row[2];i++){
@@ -4343,6 +4425,8 @@ void  AliTPCtrackerMI::FindMultiMC(const TObjArray * array, AliESDEvent */*esd*/
   }    
   delete [] helixes;
   delete [] xm;
+  delete [] dz0;
+  delete [] dz1;
   if (AliTPCReconstructor::StreamLevel()>1) {
     AliInfo("Time for curling tracks removal DEBUGGING MC");
     timer.Print();
@@ -4489,7 +4573,7 @@ void  AliTPCtrackerMI::FindSplitted(TObjArray * array, AliESDEvent */*esd*/, Int
        //
        //
        //
-       delete array->RemoveAt(index1);
+       fSeedsPool->MarkSlotFree( array->RemoveAt(index1) );
       }
     }
   }
@@ -4565,7 +4649,8 @@ void  AliTPCtrackerMI::FindCurling(const TObjArray * array, AliESDEvent */*esd*/
   //
   TStopwatch timer;
   timer.Start();
-  Double_t phase[2][2],radius[2];
+  Double_t phase[2][2]={{0,0},{0,0}},radius[2]={0,0};
+
   //
   // Find tracks
   //
@@ -4707,36 +4792,32 @@ void  AliTPCtrackerMI::FindCurling(const TObjArray * array, AliESDEvent */*esd*/
 }
 
 
-
-
-
 void  AliTPCtrackerMI::FindKinks(TObjArray * array, AliESDEvent *esd)
 {
   //
   //  find kinks
   //
   //
-
-  TObjArray *kinks= new TObjArray(10000);
+  // RS something is wrong in this routine: not all seeds are assigned to daughters and mothers array, but they all are queried
+  // to check later
+  if (fPools && !fPools->GetPool(AliPoolsSet::kPoolTPCKink)) fPools->SetPool(fKinksPool,AliPoolsSet::kPoolTPCKink);  
+  fKinksPool->Clear();
   //  TObjArray *v0s= new TObjArray(10000);
   Int_t nentries = array->GetEntriesFast();
-  AliHelix *helixes      = new AliHelix[nentries];
-  Int_t    *sign         = new Int_t[nentries];
-  Int_t    *nclusters    = new Int_t[nentries];
-  Float_t  *alpha        = new Float_t[nentries];
-  AliKink  *kink         = new AliKink();
-  Int_t      * usage     = new Int_t[nentries];
-  Float_t  *zm           = new Float_t[nentries];
-  Float_t  *z0           = new Float_t[nentries]; 
-  Float_t  *fim          = new Float_t[nentries];
-  Float_t  *shared       = new Float_t[nentries];
-  Bool_t   *circular     = new Bool_t[nentries];
-  Float_t *dca          = new Float_t[nentries];
+  AliHelix *helixes = new AliHelix[nentries];
+  Int_t    sign[nentries];
+  Int_t    nclusters[nentries];
+  Float_t  alpha[nentries];
+  Int_t    usage[nentries];
+  Float_t  zm[nentries];
+  Float_t  z0[nentries]; 
+  Float_t  fim[nentries];
+  Float_t  shared[nentries];
+  Bool_t   circular[nentries];
+  Float_t  dca[nentries];
   //const AliESDVertex * primvertex = esd->GetVertex();
   //
   //  nentries = array->GetEntriesFast();
-  //
-  
   //
   //
   for (Int_t i=0;i<nentries;i++){
@@ -4777,7 +4858,7 @@ void  AliTPCtrackerMI::FindKinks(TObjArray * array, AliESDEvent *esd)
   Int_t ncandidates =0;
   Int_t nall =0;
   Int_t ntracks=0; 
-  Double_t phase[2][2],radius[2];
+  Double_t phase[2][2]={{0,0},{0,0}},radius[2]={0,0};
 
   //
   // Find circling track
@@ -4896,8 +4977,9 @@ void  AliTPCtrackerMI::FindKinks(TObjArray * array, AliESDEvent *esd)
     }
   }
   //
-  //  Finf kinks loop
+  //  Find kinks loop
   // 
+  AliKink* kink = new( fKinksPool->NextFreeSlot() ) AliKink(); fKinksPool->RegisterClone(kink);
   //
   for (Int_t i =0;i<nentries;i++){
     if (sign[i]==0) continue;
@@ -5122,24 +5204,29 @@ void  AliTPCtrackerMI::FindKinks(TObjArray * array, AliESDEvent *esd)
        continue;
       }
       //
-      kinks->AddLast(kink);
-      kink = new AliKink;
+      kink = new( fKinksPool->NextFreeSlot() ) AliKink(); fKinksPool->RegisterClone(kink);
       ncandidates++;
     }
   }
-  //
+  // eliminate last dummy kink
+  fKinksPool->MarkSlotFree(kink); 
+  kink = 0;
+  if (ncandidates!=fKinksPool->GetEntriesFast() ) { 
+    AliError(Form("Mismatch in number of kinks: %d %d",ncandidates,fKinksPool->GetEntriesFast()));
+  }
   // sort the kinks according quality - and refit them towards vertex
   //
-  Int_t       nkinks    = kinks->GetEntriesFast();
-  Float_t    *quality   = new Float_t[nkinks];
-  Int_t      *indexes   = new Int_t[nkinks];
-  AliTPCseed *mothers   = new AliTPCseed[nkinks];
-  AliTPCseed *daughters = new AliTPCseed[nkinks];
+  Int_t       nkinks    = fKinksPool->GetEntriesFast();
+  Float_t     quality[nkinks];
+  Int_t       indexes[nkinks];
+  AliTPCseed*  mothers[nkinks];;
+  AliTPCseed*  daughters[nkinks];
   //
   //
   for (Int_t i=0;i<nkinks;i++){
     quality[i] =100000;
-    AliKink *kinkl = (AliKink*)kinks->At(i);
+    mothers[i] = daughters[i] = 0;
+    AliKink *kinkl = (AliKink*)fKinksPool->At(i);
     //
     // refit kinks towards vertex
     // 
@@ -5169,29 +5256,27 @@ void  AliTPCtrackerMI::FindKinks(TObjArray * array, AliESDEvent *esd)
       if (first>ktrack1->GetLastPoint()-25) first = TMath::Max(ktrack1->GetLastPoint()-25,30);
       AliTPCseed* seed1 = ReSeed(ktrack1,first,kTRUE);
       //
-      if (seed0 && seed1){
+      if (seed0 && seed1) {
        kinkl->SetStatus(1,8);
        if (RefitKink(*seed0,*seed1,*kinkl)) kinkl->SetStatus(1,9);
        row0 = GetRowNumber(kinkl->GetR());
        sumn = seed0->GetNumberOfClusters()+seed1->GetNumberOfClusters();
-       mothers[i] = *seed0;
-       daughters[i] = *seed1;
+       mothers[i] = seed0;
+       daughters[i] = seed1;
       }
-      else{
-       delete kinks->RemoveAt(i);
-       if (seed0) delete seed0;
-       if (seed1) delete seed1;
+      else {
+       fKinksPool->MarkSlotFree(kinkl);
+       if (seed0) fSeedsPool->MarkSlotFree( seed0 );
+       if (seed1) fSeedsPool->MarkSlotFree( seed1 );
        continue;
       }
       if (kinkl->GetDistance()>0.5 || kinkl->GetR()<110 || kinkl->GetR()>240) {
-       delete kinks->RemoveAt(i);
-       if (seed0) delete seed0;
-       if (seed1) delete seed1;
+       fKinksPool->MarkSlotFree(kinkl);
+       if (seed0) fSeedsPool->MarkSlotFree( seed0 );
+       if (seed1) fSeedsPool->MarkSlotFree( seed1 );
+       mothers[i] = daughters[i] = 0;
        continue;
       }
-      //
-      delete seed0;
-      delete seed1;            
     }
     //
     if (kinkl) quality[i] = 160*((0.1+kinkl->GetDistance())*(2.-kinkl->GetTPCDensityFactor()))/(sumn+40.);  //the longest -clossest will win
@@ -5201,22 +5286,23 @@ void  AliTPCtrackerMI::FindKinks(TObjArray * array, AliESDEvent *esd)
   //remove double find kinks
   //
   for (Int_t ikink0=1;ikink0<nkinks;ikink0++){
-    AliKink * kink0 = (AliKink*) kinks->At(indexes[ikink0]);
+    AliKink * kink0 = (AliKink*) fKinksPool->At(indexes[ikink0]);
     if (!kink0) continue;
+    AliTPCseed *mother0   = mothers[indexes[ikink0]];
+    AliTPCseed *daughter0 = daughters[indexes[ikink0]];
+    if (!mother0 || !daughter0) continue;
     //
-    for (Int_t ikink1=0;ikink1<ikink0;ikink1++){
-      if (!kink0) continue;
-      AliKink * kink1 = (AliKink*) kinks->At(indexes[ikink1]);
+    for (Int_t ikink1=0;ikink1<ikink0;ikink1++){ 
+      AliKink * kink1 = (AliKink*) fKinksPool->At(indexes[ikink1]);
       if (!kink1) continue;
+      AliTPCseed *mother1   = mothers[indexes[ikink1]];
+      AliTPCseed *daughter1 = daughters[indexes[ikink1]];
+      if (!mother1 || !daughter1) continue;
       // if not close kink continue
       if (TMath::Abs(kink1->GetPosition()[2]-kink0->GetPosition()[2])>10) continue;
       if (TMath::Abs(kink1->GetPosition()[1]-kink0->GetPosition()[1])>10) continue;
       if (TMath::Abs(kink1->GetPosition()[0]-kink0->GetPosition()[0])>10) continue;
       //
-      AliTPCseed &mother0   = mothers[indexes[ikink0]];
-      AliTPCseed &daughter0 = daughters[indexes[ikink0]];
-      AliTPCseed &mother1   = mothers[indexes[ikink1]];
-      AliTPCseed &daughter1 = daughters[indexes[ikink1]];
       Int_t row0 = (kink0->GetTPCRow0()+kink1->GetTPCRow0())/2;
       //
       Int_t same  = 0;
@@ -5227,10 +5313,10 @@ void  AliTPCtrackerMI::FindKinks(TObjArray * array, AliESDEvent *esd)
       Int_t bothd = 0;
       //
       for (Int_t i=0;i<row0;i++){
-       if (mother0.GetClusterIndex(i)>0 && mother1.GetClusterIndex(i)>0){
+       if (mother0->GetClusterIndex(i)>0 && mother1->GetClusterIndex(i)>0){
          both++;
          bothm++;
-         if (mother0.GetClusterIndex(i)==mother1.GetClusterIndex(i)){
+         if (mother0->GetClusterIndex(i)==mother1->GetClusterIndex(i)){
            same++;
            samem++;
          }
@@ -5238,10 +5324,11 @@ void  AliTPCtrackerMI::FindKinks(TObjArray * array, AliESDEvent *esd)
       }
 
       for (Int_t i=row0;i<158;i++){
-       if (daughter0.GetClusterIndex(i)>0 && daughter0.GetClusterIndex(i)>0){
+       //if (daughter0.GetClusterIndex(i)>0 && daughter0.GetClusterIndex(i)>0){ // RS: Bug? 
+       if (daughter0->GetClusterIndex(i)>0 && daughter1->GetClusterIndex(i)>0){
          both++;
          bothd++;
-         if (mother0.GetClusterIndex(i)==mother1.GetClusterIndex(i)){
+         if (daughter0->GetClusterIndex(i)==daughter1->GetClusterIndex(i)){
            same++;
            samed++;
          }
@@ -5251,18 +5338,21 @@ void  AliTPCtrackerMI::FindKinks(TObjArray * array, AliESDEvent *esd)
       Float_t ratiom = Float_t(samem+1)/Float_t(bothm+1);
       Float_t ratiod = Float_t(samed+1)/Float_t(bothd+1);
       if (ratio>0.3 && ratiom>0.5 &&ratiod>0.5) {
-       Int_t sum0 = mother0.GetNumberOfClusters()+daughter0.GetNumberOfClusters();
-       Int_t sum1 = mother1.GetNumberOfClusters()+daughter1.GetNumberOfClusters();
+       Int_t sum0 = mother0->GetNumberOfClusters()+daughter0->GetNumberOfClusters();
+       Int_t sum1 = mother1->GetNumberOfClusters()+daughter1->GetNumberOfClusters();
        if (sum1>sum0){
          shared[kink0->GetIndex(0)]= kTRUE;
          shared[kink0->GetIndex(1)]= kTRUE;      
-         delete kinks->RemoveAt(indexes[ikink0]);
+         fKinksPool->MarkSlotFree(kink0); 
+         kink0 = 0;
          break;
        }
        else{
          shared[kink1->GetIndex(0)]= kTRUE;
          shared[kink1->GetIndex(1)]= kTRUE;      
-         delete kinks->RemoveAt(indexes[ikink1]);
+         fKinksPool->MarkSlotFree(kink1);
+         fKinksPool->MarkSlotFree(kink1); 
+         kink1 = 0;
        }
       }
     }
@@ -5270,7 +5360,7 @@ void  AliTPCtrackerMI::FindKinks(TObjArray * array, AliESDEvent *esd)
 
 
   for (Int_t i=0;i<nkinks;i++){
-    AliKink * kinkl = (AliKink*) kinks->At(indexes[i]);
+    AliKink * kinkl = (AliKink*) fKinksPool->At(indexes[i]);
     if (!kinkl) continue;
     kinkl->SetTPCRow0(GetRowNumber(kinkl->GetR()));
     Int_t index0 = kinkl->GetIndex(0);
@@ -5290,9 +5380,12 @@ void  AliTPCtrackerMI::FindKinks(TObjArray * array, AliESDEvent *esd)
     //
     //
     if ( ktrack0->GetKinkIndex(0)==0 && ktrack1->GetKinkIndex(0)==0) {  //best kink
-      if (mothers[indexes[i]].GetNumberOfClusters()>20 && daughters[indexes[i]].GetNumberOfClusters()>20 && (mothers[indexes[i]].GetNumberOfClusters()+daughters[indexes[i]].GetNumberOfClusters())>100){
-       *ktrack0 = mothers[indexes[i]];
-       *ktrack1 = daughters[indexes[i]];
+      if (mothers[indexes[i]] && daughters[indexes[i]]) {
+       if (mothers[indexes[i]]->GetNumberOfClusters()>20 && daughters[indexes[i]]->GetNumberOfClusters()>20 && 
+           (mothers[indexes[i]]->GetNumberOfClusters()+daughters[indexes[i]]->GetNumberOfClusters())>100) {
+       *ktrack0 = *mothers[indexes[i]];
+       *ktrack1 = *daughters[indexes[i]];
+       }
       }
     }
     //
@@ -5308,9 +5401,8 @@ void  AliTPCtrackerMI::FindKinks(TObjArray * array, AliESDEvent *esd)
     AliTPCseed * track0 = (AliTPCseed*)array->At(i);
     if (!track0) continue;
     if (track0->GetKinkIndex(0)!=0) continue;
-    if (shared[i]) delete array->RemoveAt(i);
+    if (shared[i]) fSeedsPool->MarkSlotFree( array->RemoveAt(i) );
   }
-
   //
   //
   RemoveUsed2(array,0.5,0.4,30);
@@ -5336,38 +5428,38 @@ void  AliTPCtrackerMI::FindKinks(TObjArray * array, AliESDEvent *esd)
       }
     }
     if (Float_t(ishared+1)/Float_t(all+1)>0.5) {  
-      delete array->RemoveAt(i);
+      fSeedsPool->MarkSlotFree( array->RemoveAt(i) );
       continue;
     }
     //
     if (track0->GetKinkIndex(0)!=0) continue;
     if (track0->GetNumberOfClusters()<80) continue;
 
-    AliTPCseed *pmother = new AliTPCseed();
-    AliTPCseed *pdaughter = new AliTPCseed();
-    AliKink *pkink = new AliKink;
-
+    AliTPCseed *pmother   = new( fSeedsPool->NextFreeSlot() ) AliTPCseed(); fSeedsPool->RegisterClone(pmother);
+    AliTPCseed *pdaughter = new( fSeedsPool->NextFreeSlot() ) AliTPCseed(); fSeedsPool->RegisterClone(pdaughter);
+    AliKink    *pkink     = new( fKinksPool->NextFreeSlot() ) AliKink(); fKinksPool->RegisterClone(pkink);
+    //
     AliTPCseed & mother = *pmother;
     AliTPCseed & daughter = *pdaughter;
     AliKink & kinkl = *pkink;
     if (CheckKinkPoint(track0,mother,daughter, kinkl)){
       if (mother.GetNumberOfClusters()<30||daughter.GetNumberOfClusters()<20) {
-       delete pmother;
-       delete pdaughter;
-       delete pkink;
+       fSeedsPool->MarkSlotFree(pmother);
+       fSeedsPool->MarkSlotFree(pdaughter);
+       fKinksPool->MarkSlotFree(pkink);
        continue;  //too short tracks
       }
       if (mother.Pt()<1.4) {
-       delete pmother;
-       delete pdaughter;
-       delete pkink;
+       fSeedsPool->MarkSlotFree(pmother);
+       fSeedsPool->MarkSlotFree(pdaughter);
+       fKinksPool->MarkSlotFree(pkink);
        continue;
       }
       Int_t row0= kinkl.GetTPCRow0();
       if (kinkl.GetDistance()>0.5 || kinkl.GetR()<110. || kinkl.GetR()>240.) {
-       delete pmother;
-       delete pdaughter;
-       delete pkink;
+       fSeedsPool->MarkSlotFree(pmother);
+       fSeedsPool->MarkSlotFree(pdaughter);
+       fKinksPool->MarkSlotFree(pkink);
        continue;
       }
       //
@@ -5375,13 +5467,19 @@ void  AliTPCtrackerMI::FindKinks(TObjArray * array, AliESDEvent *esd)
       mother.SetKinkIndex(0,-(index+1));
       daughter.SetKinkIndex(0,index+1);
       if (mother.GetNumberOfClusters()>50) {
-       delete array->RemoveAt(i);
-       array->AddAt(new AliTPCseed(mother),i);
+       fSeedsPool->MarkSlotFree( array->RemoveAt(i) );
+       AliTPCseed* mtc = new( fSeedsPool->NextFreeSlot() ) AliTPCseed(mother);
+       fSeedsPool->RegisterClone(mtc);
+       array->AddAt(mtc,i);
       }
       else{
-       array->AddLast(new AliTPCseed(mother));
+       AliTPCseed* mtc = new( fSeedsPool->NextFreeSlot() ) AliTPCseed(mother);
+       fSeedsPool->RegisterClone(mtc);
+       array->AddLast(mtc);
       }
-      array->AddLast(new AliTPCseed(daughter));      
+      AliTPCseed* dtc = new( fSeedsPool->NextFreeSlot() ) AliTPCseed(daughter);
+      fSeedsPool->RegisterClone(dtc);
+      array->AddLast(dtc);      
       for (Int_t icl=0;icl<row0;icl++) {
        if (mother.GetClusterPointer(icl)) mother.GetClusterPointer(icl)->Use(20);
       }
@@ -5391,394 +5489,22 @@ void  AliTPCtrackerMI::FindKinks(TObjArray * array, AliESDEvent *esd)
       }
       //
     }
-    delete pmother;
-    delete pdaughter;
-    delete pkink;
+    fSeedsPool->MarkSlotFree(pmother);
+    fSeedsPool->MarkSlotFree(pdaughter);
+    fKinksPool->MarkSlotFree(pkink);
   }
-
-  delete [] daughters;
-  delete [] mothers;
-  //
   //
-  delete [] dca;
-  delete []circular;
-  delete []shared;
-  delete []quality;
-  delete []indexes;
+  for (int i=nkinks;i--;) {
+    if (daughters[i]) fSeedsPool->MarkSlotFree(daughters[i]);
+    if (mothers[i])   fSeedsPool->MarkSlotFree(mothers[i]);
+  }
+  fKinksPool->Clear();
   //
-  delete kink;
-  delete[]fim;
-  delete[] zm;
-  delete[] z0;
-  delete [] usage;
-  delete[] alpha;
-  delete[] nclusters;
-  delete[] sign;
   delete[] helixes;
-  kinks->Delete();
-  delete kinks;
-
   AliInfo(Form("Ncandidates=\t%d\t%d\t%d\t%d\n",esd->GetNumberOfKinks(),ncandidates,ntracks,nall));
   timer.Print();
 }
 
-void  AliTPCtrackerMI::FindV0s(const TObjArray * array, AliESDEvent *const esd)
-{
-  //
-  //  find V0s
-  //
-  //
-  TObjArray *tpcv0s      = new TObjArray(100000);
-  Int_t     nentries     = array->GetEntriesFast();
-  AliHelix *helixes      = new AliHelix[nentries];
-  Int_t    *sign         = new Int_t[nentries];
-  Float_t  *alpha        = new Float_t[nentries];
-  Float_t  *z0           = new Float_t[nentries]; 
-  Float_t  *dca          = new Float_t[nentries];
-  Float_t  *sdcar        = new Float_t[nentries];
-  Float_t  *cdcar        = new Float_t[nentries];
-  Float_t  *pulldcar     = new Float_t[nentries];
-  Float_t  *pulldcaz     = new Float_t[nentries];
-  Float_t  *pulldca      = new Float_t[nentries];
-  Bool_t   *isPrim       = new Bool_t[nentries];  
-  const AliESDVertex * primvertex = esd->GetVertex();
-  Double_t             zvertex = primvertex->GetZv(); 
-  //
-  //  nentries = array->GetEntriesFast();
-  //
-  for (Int_t i=0;i<nentries;i++){
-    sign[i]=0;
-    isPrim[i]=0;
-    AliTPCseed* track = (AliTPCseed*)array->At(i);    
-    if (!track) continue;
-    track->GetV0Indexes()[0] = 0;  //rest v0 indexes
-    track->GetV0Indexes()[1] = 0;  //rest v0 indexes
-    track->GetV0Indexes()[2] = 0;  //rest v0 indexes
-    //
-    alpha[i] = track->GetAlpha();
-    new (&helixes[i]) AliHelix(*track);
-    Double_t xyz[3];
-    helixes[i].Evaluate(0,xyz);
-    sign[i] = (track->GetC()>0) ? -1:1;
-    Double_t x,y,z;
-    x=160;
-    z0[i]=1000;
-    if (track->GetProlongation(0,y,z))  z0[i] = z;
-    dca[i] = track->GetD(0,0);
-    // 
-    // dca error parrameterezation + pulls
-    //
-    sdcar[i]      = TMath::Sqrt(0.150*0.150+(100*track->GetC())*(100*track->GetC()));
-    if (TMath::Abs(track->GetTgl())>1) sdcar[i]*=2.5;
-    cdcar[i]      = TMath::Exp((TMath::Abs(track->GetC())-0.0106)*525.3);
-    pulldcar[i]   = (dca[i]-cdcar[i])/sdcar[i];
-    pulldcaz[i]   = (z0[i]-zvertex)/sdcar[i];
-    pulldca[i]    = TMath::Sqrt(pulldcar[i]*pulldcar[i]+pulldcaz[i]*pulldcaz[i]);
-    if (track->TPCrPID(1)+track->TPCrPID(2)+track->TPCrPID(3)>0.5) {
-      if (pulldca[i]<3.) isPrim[i]=kTRUE;  //pion, muon and Kaon  3 sigma cut
-    }
-    if (track->TPCrPID(4)>0.5) {
-      if (pulldca[i]<0.5) isPrim[i]=kTRUE;  //proton 0.5 sigma cut
-    }
-    if (track->TPCrPID(0)>0.4) {
-      isPrim[i]=kFALSE;  //electron no  sigma cut
-    }
-  }
-  //
-  //
-  TStopwatch timer;
-  timer.Start();
-  Int_t ncandidates =0;
-  Int_t nall =0;
-  Int_t ntracks=0; 
-  Double_t phase[2][2],radius[2];
-  //
-  //  Finf V0s loop
-  // 
-  //
-  // //  
-  Float_t fprimvertex[3]={GetX(),GetY(),GetZ()};
-  AliV0 vertex; 
-  Double_t cradius0 = 10*10;
-  Double_t cradius1 = 200*200;
-  Double_t cdist1=3.;
-  Double_t cdist2=4.;
-  Double_t cpointAngle = 0.95;
-  //
-  Double_t delta[2]={10000,10000};
-  for (Int_t i =0;i<nentries;i++){
-    if (sign[i]==0) continue;
-    AliTPCseed * track0 = (AliTPCseed*)array->At(i);
-    if (!track0) continue;
-    if (AliTPCReconstructor::StreamLevel()>1){
-      TTreeSRedirector &cstream = *fDebugStreamer;
-      cstream<<"Tracks"<<
-       "Tr0.="<<track0<<
-       "dca="<<dca[i]<<
-       "z0="<<z0[i]<<
-       "zvertex="<<zvertex<<
-       "sdcar0="<<sdcar[i]<<
-       "cdcar0="<<cdcar[i]<<
-       "pulldcar0="<<pulldcar[i]<<
-       "pulldcaz0="<<pulldcaz[i]<<
-       "pulldca0="<<pulldca[i]<<
-       "isPrim="<<isPrim[i]<<
-       "\n";
-    }
-    //
-    if (track0->GetSigned1Pt()<0) continue;
-    if (track0->GetKinkIndex(0)>0||isPrim[i]) continue;   //daughter kink
-    //
-    if (TMath::Abs(helixes[i].GetHelix(4))<0.000000001) continue;
-    ntracks++;
-    // debug output
-    
-    
-    for (Int_t j =0;j<nentries;j++){
-      AliTPCseed * track1 = (AliTPCseed*)array->At(j);
-      if (!track1) continue;
-      if (track1->GetKinkIndex(0)>0 || isPrim[j]) continue; //daughter kink
-      if (sign[j]*sign[i]>0) continue; 
-      if (TMath::Abs(helixes[j].GetHelix(4))<0.000001) continue;
-      if (track0->GetCircular()+track1->GetCircular()>1) continue;    //circling -returning track
-      nall++;
-      //
-      // DCA to prim vertex cut
-      //
-      //
-      delta[0]=10000;
-      delta[1]=10000;
-
-      Int_t npoints = helixes[i].GetRPHIintersections(helixes[j], phase, radius,cdist2);
-      if (npoints<1) continue;
-      Int_t iclosest=0;
-      // cuts on radius      
-      if (npoints==1){
-       if (radius[0]<cradius0||radius[0]>cradius1) continue;
-       helixes[i].LinearDCA(helixes[j],phase[0][0],phase[0][1],radius[0],delta[0]);
-       if (delta[0]>cdist1) continue;
-      }
-      else{
-       if (TMath::Max(radius[0],radius[1])<cradius0|| TMath::Min(radius[0],radius[1])>cradius1) continue;      
-       helixes[i].LinearDCA(helixes[j],phase[0][0],phase[0][1],radius[0],delta[0]);    
-       helixes[i].LinearDCA(helixes[j],phase[1][0],phase[1][1],radius[1],delta[1]);
-       if (delta[1]<delta[0]) iclosest=1;
-       if (delta[iclosest]>cdist1) continue;
-      }
-      helixes[i].ParabolicDCA(helixes[j],phase[iclosest][0],phase[iclosest][1],radius[iclosest],delta[iclosest]);
-      if (radius[iclosest]<cradius0 || radius[iclosest]>cradius1 || delta[iclosest]>cdist1) continue;
-      //
-      Double_t pointAngle = helixes[i].GetPointAngle(helixes[j],phase[iclosest],fprimvertex);
-      if (pointAngle<cpointAngle) continue;
-      //
-      Bool_t isGamma = kFALSE;
-      vertex.SetParamP(*track0); //track0 - plus
-      vertex.SetParamN(*track1); //track1 - minus
-      vertex.Update(fprimvertex);
-      if (track0->TPCrPID(0)>0.3&&track1->TPCrPID(0)>0.3&&vertex.GetAnglep()[2]<0.15) isGamma=kTRUE;              // gamma conversion candidate
-      Double_t pointAngle2 = vertex.GetV0CosineOfPointingAngle();
-      //continue;
-      if (vertex.GetV0CosineOfPointingAngle()<cpointAngle && (!isGamma)) continue;// point angle cut
-      //Bo:      if (vertex.GetDist2()>2&&(!isGamma)) continue;      // point angle cut
-      if (vertex.GetDcaV0Daughters()>2&&(!isGamma)) continue;//Bo:   // point angle cut
-      Float_t sigmae     = 0.15*0.15;
-      if (vertex.GetRr()<80) 
-       sigmae += (sdcar[i]*sdcar[i]+sdcar[j]*sdcar[j])*(1.-vertex.GetRr()/80.)*(1.-vertex.GetRr()/80.);
-      sigmae+= TMath::Sqrt(sigmae);
-      //Bo:      if (vertex.GetDist2()/sigmae>3.&&(!isGamma)) continue; 
-      if (vertex.GetDcaV0Daughters()/sigmae>3.&&(!isGamma)) continue; 
-      Float_t densb0=0,densb1=0,densa0=0,densa1=0;
-      Int_t row0 = GetRowNumber(vertex.GetRr());
-      if (row0>15){
-       //Bo:   if (vertex.GetDist2()>0.2) continue;             
-       if (vertex.GetDcaV0Daughters()>0.2) continue;             
-       densb0     = track0->Density2(0,row0-5);          
-       densb1     = track1->Density2(0,row0-5);         
-       if (densb0>0.3|| densb1>0.3) continue;            //clusters before vertex
-       densa0     = track0->Density2(row0+5,row0+40);    
-       densa1     = track1->Density2(row0+5,row0+40);    
-       if ((densa0<0.4|| densa1<0.4)&&(!isGamma)) continue;            //missing clusters after vertex
-      }
-      else{
-       densa0     = track0->Density2(0,40);  //cluster density
-       densa1     = track1->Density2(0,40);  //cluster density
-       if ((vertex.GetRr()<80&&densa0+densa1<1.)&&(!isGamma)) continue;
-      }
-//Bo:        vertex.SetLab(0,track0->GetLabel());
-//Bo:        vertex.SetLab(1,track1->GetLabel());
-      vertex.SetChi2After((densa0+densa1)*0.5);
-      vertex.SetChi2Before((densb0+densb1)*0.5);
-      vertex.SetIndex(0,i);
-      vertex.SetIndex(1,j);
-//Bo:      vertex.SetStatus(1); // TPC v0 candidate
-      vertex.SetOnFlyStatus(2);//Bo: // TPC v0 candidate
-//Bo:        vertex.SetRp(track0->TPCrPIDs());
-//Bo:        vertex.SetRm(track1->TPCrPIDs());
-      tpcv0s->AddLast(new AliESDv0(vertex));      
-      ncandidates++;
-      {
-       Int_t eventNr = esd->GetEventNumberInFile(); // This is most likely NOT the event number you'd like to use. It has nothing to do with the 'real' event number
-       Double_t radiusm= (delta[0]<delta[1])? TMath::Sqrt(radius[0]):TMath::Sqrt(radius[1]);  
-       Double_t deltam= (delta[0]<delta[1])? TMath::Sqrt(delta[0]):TMath::Sqrt(delta[1]);  
-       if (AliTPCReconstructor::StreamLevel()>1) {
-         Int_t lab0=track0->GetLabel();
-         Int_t lab1=track1->GetLabel();
-         Char_t c0=track0->GetCircular();
-         Char_t c1=track1->GetCircular();
-          TTreeSRedirector &cstream = *fDebugStreamer;
-         cstream<<"V0"<<
-         "Event="<<eventNr<<
-         "vertex.="<<&vertex<<
-         "Tr0.="<<track0<<
-         "lab0="<<lab0<<
-         "Helix0.="<<&helixes[i]<<     
-         "Tr1.="<<track1<<
-         "lab1="<<lab1<<
-         "Helix1.="<<&helixes[j]<<
-         "pointAngle="<<pointAngle<<
-         "pointAngle2="<<pointAngle2<<
-         "dca0="<<dca[i]<<
-         "dca1="<<dca[j]<<
-         "z0="<<z0[i]<<
-         "z1="<<z0[j]<<
-         "zvertex="<<zvertex<<
-         "circular0="<<c0<<
-         "circular1="<<c1<<
-         "npoints="<<npoints<<
-         "radius0="<<radius[0]<<
-         "delta0="<<delta[0]<<
-         "radius1="<<radius[1]<<
-         "delta1="<<delta[1]<<
-         "radiusm="<<radiusm<<
-         "deltam="<<deltam<<
-         "sdcar0="<<sdcar[i]<<
-         "sdcar1="<<sdcar[j]<<
-         "cdcar0="<<cdcar[i]<<
-         "cdcar1="<<cdcar[j]<<
-         "pulldcar0="<<pulldcar[i]<<
-         "pulldcar1="<<pulldcar[j]<<
-         "pulldcaz0="<<pulldcaz[i]<<
-         "pulldcaz1="<<pulldcaz[j]<<
-         "pulldca0="<<pulldca[i]<<
-         "pulldca1="<<pulldca[j]<<
-         "densb0="<<densb0<<
-         "densb1="<<densb1<<
-         "densa0="<<densa0<<
-         "densa1="<<densa1<<
-         "sigmae="<<sigmae<<
-           "\n";}
-      }
-    }
-  }    
-  Float_t *quality = new Float_t[ncandidates];
-  Int_t *indexes = new Int_t[ncandidates];
-  Int_t naccepted =0;
-  for (Int_t i=0;i<ncandidates;i++){
-    quality[i]     = 0; 
-    AliESDv0 *v0 = (AliESDv0*)tpcv0s->At(i);
-    quality[i]     = 1./(1.00001-v0->GetV0CosineOfPointingAngle());   //base point angle
-    // quality[i]    /= (0.5+v0->GetDist2());  
-    // quality[i]    *= v0->GetChi2After();               //density factor
-
-    Int_t index0 = v0->GetIndex(0);
-    Int_t index1 = v0->GetIndex(1);
-    //Bo:    Double_t minpulldca = TMath::Min(2.+pulldca[v0->GetIndex(0)],(2.+pulldca[v0->GetIndex(1)]) );     //pull
-    Double_t minpulldca = TMath::Min(2.+pulldca[index0],(2.+pulldca[index1]) );//Bo:
-
-
-
-    AliTPCseed * track0 = (AliTPCseed*)array->At(index0);
-    AliTPCseed * track1 = (AliTPCseed*)array->At(index1);
-    if (track0->TPCrPID(0)>0.3&&track1->TPCrPID(0)>0.3&&v0->GetAnglep()[2]<0.15) quality[i]+=1000000;              // gamma conversion candidate
-    if (track0->TPCrPID(4)>0.9||(track1->TPCrPID(4)>0.9&&minpulldca>4)) quality[i]*=10;    // lambda candidate candidate
-  }
-
-  TMath::Sort(ncandidates,quality,indexes,kTRUE);
-  //
-  //
-  for (Int_t i=0;i<ncandidates;i++){
-    AliESDv0 * v0 = (AliESDv0*)tpcv0s->At(indexes[i]);
-    if (!v0) continue;
-    Int_t index0 = v0->GetIndex(0);
-    Int_t index1 = v0->GetIndex(1);
-    AliTPCseed * track0 = (AliTPCseed*)array->At(index0);
-    AliTPCseed * track1 = (AliTPCseed*)array->At(index1);
-    if (!track0||!track1) {
-      printf("Bug\n");
-      continue;
-    }
-    Bool_t accept =kTRUE;  //default accept
-    Int_t *v0indexes0 = track0->GetV0Indexes();
-    Int_t *v0indexes1 = track1->GetV0Indexes();
-    //
-    Int_t order0 = (v0indexes0[0]!=0) ? 1:0;
-    Int_t order1 = (v0indexes1[0]!=0) ? 1:0;    
-    if (v0indexes0[1]!=0) order0 =2;
-    if (v0indexes1[1]!=0) order1 =2;      
-    //
-    if (v0indexes0[2]!=0) {order0=3; accept=kFALSE;}
-    if (v0indexes0[2]!=0) {order1=3; accept=kFALSE;}
-    //
-    AliESDv0 * v02 = v0;
-    if (accept){
-      //Bo:      v0->SetOrder(0,order0);
-      //Bo:      v0->SetOrder(1,order1);
-      //Bo:      v0->SetOrder(1,order0+order1);     
-      v0->SetOnFlyStatus(kTRUE);
-      Int_t index = esd->AddV0(v0);
-      v02 = esd->GetV0(index);
-      v0indexes0[order0]=index;
-      v0indexes1[order1]=index;
-      naccepted++;
-    }
-    {
-      Int_t eventNr = esd->GetEventNumberInFile(); // This is most likely NOT the event number you'd like to use. It has nothing to do with the 'real' event number
-      if (AliTPCReconstructor::StreamLevel()>1) {
-       Int_t lab0=track0->GetLabel();
-       Int_t lab1=track1->GetLabel();
-        TTreeSRedirector &cstream = *fDebugStreamer;
-       cstream<<"V02"<<
-       "Event="<<eventNr<<
-       "vertex.="<<v0<<        
-       "vertex2.="<<v02<<
-       "Tr0.="<<track0<<
-       "lab0="<<lab0<<
-       "Tr1.="<<track1<<
-       "lab1="<<lab1<<
-       "dca0="<<dca[index0]<<
-       "dca1="<<dca[index1]<<
-       "order0="<<order0<<
-       "order1="<<order1<<
-       "accept="<<accept<<
-       "quality="<<quality[i]<<
-       "pulldca0="<<pulldca[index0]<<
-       "pulldca1="<<pulldca[index1]<<
-       "index="<<i<<
-         "\n";}
-    }
-  }    
-
-
-  //
-  //
-  delete []quality;
-  delete []indexes;
-//
-  delete [] isPrim;
-  delete [] pulldca;
-  delete [] pulldcaz;
-  delete [] pulldcar;
-  delete [] cdcar;
-  delete [] sdcar;
-  delete [] dca;
-  //
-  delete[] z0;
-  delete[] alpha;
-  delete[] sign;
-  delete[] helixes;
-  printf("TPC V0 finder : naccepted\t%d\tncandidates\t%d\tntracks\t%d\tnall\t%d\n",naccepted,ncandidates,ntracks,nall);
-  timer.Print();
-}
 
 Int_t AliTPCtrackerMI::RefitKink(AliTPCseed &mother, AliTPCseed &daughter, const AliESDkink &knk)
 {
@@ -5946,7 +5672,8 @@ Int_t  AliTPCtrackerMI::CheckKinkPoint(AliTPCseed*seed,AliTPCseed &mother, AliTP
   seed1->Reset(kTRUE);  
   last = seed1->GetLastPoint();
   //
-  AliTPCseed *seed0 = new AliTPCseed(*seed);
+  AliTPCseed *seed0 = new( fSeedsPool->NextFreeSlot() ) AliTPCseed(*seed);
+  fSeedsPool->RegisterClone(seed0);
   seed0->Reset(kFALSE);
   seed0->Reset();
   //
@@ -5986,13 +5713,15 @@ Int_t  AliTPCtrackerMI::CheckKinkPoint(AliTPCseed*seed,AliTPCseed &mother, AliTP
       //
     }
   }
-  delete seed0;
-  delete seed1;
+  fSeedsPool->MarkSlotFree( seed0 );
+  fSeedsPool->MarkSlotFree( seed1 );
   if (index<0) return 0;
   //
   Int_t row0    = GetRowNumber(kinks[index].GetR());   //row 0 estimate
-  seed0 = new AliTPCseed(param0[index]);
-  seed1 = new AliTPCseed(param1[index]);
+  seed0 = new( fSeedsPool->NextFreeSlot() ) AliTPCseed(param0[index]);
+  fSeedsPool->RegisterClone(seed0);
+  seed1 = new( fSeedsPool->NextFreeSlot() ) AliTPCseed(param1[index]);
+  fSeedsPool->RegisterClone(seed1);
   seed0->Reset(kFALSE);
   seed1->Reset(kFALSE);
   seed0->ResetCovariance(10.);
@@ -6045,8 +5774,8 @@ Int_t  AliTPCtrackerMI::CheckKinkPoint(AliTPCseed*seed,AliTPCseed &mother, AliTP
   //
   //
   if (index==-1 || param0[index].GetNumberOfClusters()+param1[index].GetNumberOfClusters()<100){
-    delete seed0;
-    delete seed1;
+    fSeedsPool->MarkSlotFree( seed0 );
+    fSeedsPool->MarkSlotFree( seed1 );
     return 0;
   }
 
@@ -6073,8 +5802,8 @@ Int_t  AliTPCtrackerMI::CheckKinkPoint(AliTPCseed*seed,AliTPCseed &mother, AliTP
       "\n";
   }
   if ( chi2P2+chi2P3<AliTPCReconstructor::GetRecoParam()->GetKinkAngleCutChi2(0)){
-    delete seed0;
-    delete seed1;
+    fSeedsPool->MarkSlotFree( seed0 );
+    fSeedsPool->MarkSlotFree( seed1 );
     return 0; 
   }
 
@@ -6099,8 +5828,8 @@ Int_t  AliTPCtrackerMI::CheckKinkPoint(AliTPCseed*seed,AliTPCseed &mother, AliTP
   if ( chi2P2+chi2P3<AliTPCReconstructor::GetRecoParam()->GetKinkAngleCutChi2(1)){
     mother=*seed;
   }
-  delete seed0;
-  delete seed1;
+  fSeedsPool->MarkSlotFree( seed0 );
+  fSeedsPool->MarkSlotFree( seed1 );
   //
   return 1;
 }
@@ -6164,10 +5893,12 @@ Int_t AliTPCtrackerMI::ReadSeeds(const TFile *inp) {
   Int_t n=(Int_t)seedTree->GetEntries();
   for (Int_t i=0; i<n; i++) {
      seedTree->GetEvent(i);
-     fSeeds->AddLast(new AliTPCseed(*seed/*,seed->GetAlpha()*/));
+     AliTPCseed* sdc = new( fSeedsPool->NextFreeSlot() ) AliTPCseed(*seed/*,seed->GetAlpha()*/);
+     fSeedsPool->RegisterClone(sdc);
+     fSeeds->AddLast(sdc);
   }
   
-  delete seed;
+  delete seed; // RS: this seed is not from the pool, delete it !!!
   delete seedTree; 
   savedir->cd();
   return 0;
@@ -6176,8 +5907,16 @@ Int_t AliTPCtrackerMI::ReadSeeds(const TFile *inp) {
 Int_t AliTPCtrackerMI::Clusters2Tracks (AliESDEvent *const esd)
 {
   //
+  // clusters to tracks
+  if (fPools && !fPools->GetPoolTPCSeed()) fPools->SetPool(fSeedsPool,AliPoolsSet::kPoolTPCSeed);
   if (fSeeds) DeleteSeeds();
-  fEvent = esd;
+  else fSeedsPool->Clear("C");
+  fEvent = esd; 
+
+  AliTPCTransform *transform = AliTPCcalibDB::Instance()->GetTransform() ;  
+  transform->SetCurrentTimeStamp( esd->GetTimeStamp());
+  transform->SetCurrentRun(esd->GetRunNumber());
+
   Clusters2Tracks();
   if (!fSeeds) return 1;
   FillESD(fSeeds);
@@ -6207,16 +5946,16 @@ Int_t AliTPCtrackerMI::Clusters2Tracks() {
     if (!pt) continue;    
     Int_t nc=t.GetNumberOfClusters();
     if (nc<20) {
-      delete fSeeds->RemoveAt(i);
+      fSeedsPool->MarkSlotFree( fSeeds->RemoveAt(i) );
       continue;
     } 
     CookLabel(pt,0.1); 
     if (pt->GetRemoval()==10) {
       if (pt->GetDensityFirst(20)>0.8 || pt->GetDensityFirst(30)>0.8 || pt->GetDensityFirst(40)>0.7)
-       pt->Desactivate(10);  // make track again active
+       pt->Desactivate(10);  // make track again active  // MvL: should be 0 ?
       else{
        pt->Desactivate(20);    
-       delete fSeeds->RemoveAt(i);
+       fSeedsPool->MarkSlotFree( fSeeds->RemoveAt(i) );
       }
     } 
   }
@@ -6240,7 +5979,7 @@ Int_t AliTPCtrackerMI::Clusters2Tracks() {
     if (!pt) continue;    
     Int_t nc=t.GetNumberOfClusters();
     if (nc<15) {
-      delete fSeeds->RemoveAt(i);
+      fSeedsPool->MarkSlotFree( fSeeds->RemoveAt(i) );
       continue;
     }
     CookLabel(pt,0.1); //For comparison only
@@ -6251,7 +5990,7 @@ Int_t AliTPCtrackerMI::Clusters2Tracks() {
       pt->SetLab2(i);
     }
     else
-      delete fSeeds->RemoveAt(i);
+      fSeedsPool->MarkSlotFree( fSeeds->RemoveAt(i) );
   }
 
   
@@ -6266,7 +6005,7 @@ Int_t AliTPCtrackerMI::Clusters2Tracks() {
     if (!pt) continue;    
     Int_t nc=t.GetNumberOfClusters();
     if (nc<15) {
-      delete fSeeds->RemoveAt(i);
+      fSeedsPool->MarkSlotFree( fSeeds->RemoveAt(i) );
       continue;
     }
     t.SetUniqueID(i);
@@ -6281,7 +6020,7 @@ Int_t AliTPCtrackerMI::Clusters2Tracks() {
       pt->SetLab2(i);
     }
     else
-      delete fSeeds->RemoveAt(i);
+      fSeedsPool->MarkSlotFree( fSeeds->RemoveAt(i) );
     //AliTPCseed * seed1 = ReSeed(pt,0.05,0.5,1);
     //if (seed1){
     //  FollowProlongation(*seed1,0);
@@ -6305,7 +6044,7 @@ Int_t AliTPCtrackerMI::Clusters2Tracks() {
   fIteration = 2;
   
   PrepareForProlongation(fSeeds,5.);
-  PropagateForward2(fSeeds);
+  PropagateForard2(fSeeds);
    
   printf("Time for FORWARD propagation: \t");timer.Print();timer.Start();
   // RemoveUsed(fSeeds,0.7,0.7,6);
@@ -6318,7 +6057,7 @@ Int_t AliTPCtrackerMI::Clusters2Tracks() {
     if (!pt) continue;    
     Int_t nc=t.GetNumberOfClusters();
     if (nc<15) {
-      delete fSeeds->RemoveAt(i);
+      fSeedsPool->MarkSlotFree( fSeeds->RemoveAt(i) );
       continue;
     }
     t.CookdEdx(0.02,0.6);
@@ -6328,7 +6067,7 @@ Int_t AliTPCtrackerMI::Clusters2Tracks() {
       cerr<<found++<<'\r';      
     }
     else
-      delete fSeeds->RemoveAt(i);
+      fSeedsPool->MarkSlotFree( fSeeds->RemoveAt(i) );
     pt->fLab2 = i;
   }
   */
@@ -6363,7 +6102,8 @@ TObjArray * AliTPCtrackerMI::Tracking(Int_t seedtype, Int_t i1, Int_t i2, Float_
   //
   //
   //tracking routine
-  TObjArray * arr = new TObjArray;
+  static TObjArray arrTracks;
+  TObjArray * arr = &arrTracks;
   // 
   fSectors = fOuterSec;
   TStopwatch timer;
@@ -6388,7 +6128,7 @@ TObjArray * AliTPCtrackerMI::Tracking(Int_t seedtype, Int_t i1, Int_t i2, Float_
 
 TObjArray * AliTPCtrackerMI::Tracking()
 {
-  //
+  // tracking
   //
   if (AliTPCReconstructor::GetRecoParam()->GetSpecialSeeding()) return TrackingSpecial();
   TStopwatch timer;
@@ -6601,11 +6341,12 @@ TObjArray * AliTPCtrackerMI::TrackingSpecial()
 }
 
 
-void AliTPCtrackerMI::SumTracks(TObjArray *arr1,TObjArray *&arr2) const
+void AliTPCtrackerMI::SumTracks(TObjArray *arr1,TObjArray *&arr2)
 {
   //
   //sum tracks to common container
   //remove suspicious tracks
+  // RS: Attention: supplied tracks come in the static array, don't delete them
   Int_t nseed = arr2->GetEntriesFast();
   for (Int_t i=0;i<nseed;i++){
     AliTPCseed *pt=(AliTPCseed*)arr2->UncheckedAt(i);    
@@ -6614,12 +6355,12 @@ void AliTPCtrackerMI::SumTracks(TObjArray *arr1,TObjArray *&arr2) const
       // remove tracks with too big curvature
       //
       if (TMath::Abs(pt->GetC())>AliTPCReconstructor::GetRecoParam()->GetMaxC()){
-       delete arr2->RemoveAt(i);
+       fSeedsPool->MarkSlotFree( arr2->RemoveAt(i) );
        continue;
       }
        // REMOVE VERY SHORT  TRACKS
       if (pt->GetNumberOfClusters()<20){ 
-       delete arr2->RemoveAt(i);
+       fSeedsPool->MarkSlotFree( arr2->RemoveAt(i) );
        continue;
       }// patch 28 fev06
       // NORMAL ACTIVE TRACK
@@ -6629,7 +6370,7 @@ void AliTPCtrackerMI::SumTracks(TObjArray *arr1,TObjArray *&arr2) const
       }
       //remove not usable tracks
       if (pt->GetRemoval()!=10){
-       delete arr2->RemoveAt(i);
+       fSeedsPool->MarkSlotFree( arr2->RemoveAt(i) );
        continue;
       }
      
@@ -6637,11 +6378,11 @@ void AliTPCtrackerMI::SumTracks(TObjArray *arr1,TObjArray *&arr2) const
       if (pt->GetDensityFirst(20)>0.8 || pt->GetDensityFirst(30)>0.8 || pt->GetDensityFirst(40)>0.7)
        arr1->AddLast(arr2->RemoveAt(i));
       else{      
-       delete arr2->RemoveAt(i);
+       fSeedsPool->MarkSlotFree( arr2->RemoveAt(i) );
       }
     }
   }
-  delete arr2;  arr2 = 0;
+  // delete arr2;  arr2 = 0; // RS: this is static array, don't delete it
 }
 
 
@@ -6697,7 +6438,7 @@ void  AliTPCtrackerMI::ParallelTracking(TObjArray *const arr, Int_t rfirst, Int_
   }    
 }
 
-void AliTPCtrackerMI::PrepareForBackProlongation(TObjArray *const arr,Float_t fac) const
+void AliTPCtrackerMI::PrepareForBackProlongation(const TObjArray *const arr,Float_t fac) const
 {
   //
   //
@@ -6719,7 +6460,7 @@ void AliTPCtrackerMI::PrepareForBackProlongation(TObjArray *const arr,Float_t fa
       Float_t angle2 = pt->GetAlpha();
       
       if (TMath::Abs(angle1-angle2)>0.001){
-       pt->Rotate(angle1-angle2);
+       if (!pt->Rotate(angle1-angle2)) return;
        //angle2 = pt->GetAlpha();
        //pt->fRelativeSector = pt->GetAlpha()/fInnerSec->GetAlpha();
        //if (pt->GetAlpha()<0) 
@@ -6752,7 +6493,7 @@ void AliTPCtrackerMI::PrepareForProlongation(TObjArray *const arr, Float_t fac)
 
 }
 
-Int_t AliTPCtrackerMI::PropagateBack(TObjArray *const arr)
+Int_t AliTPCtrackerMI::PropagateBack(const TObjArray *const arr)
 {
   //
   // make back propagation
@@ -6765,7 +6506,7 @@ Int_t AliTPCtrackerMI::PropagateBack(TObjArray *const arr)
       fSectors = fInnerSec;
       //FollowBackProlongation(*pt,fInnerSec->GetNRows()-1);
       //fSectors = fOuterSec;
-      FollowBackProlongation(*pt,fInnerSec->GetNRows()+fOuterSec->GetNRows()-1);     
+      FollowBackProlongation(*pt,fInnerSec->GetNRows()+fOuterSec->GetNRows()-1,1);     
       //if (pt->GetNumberOfClusters()<(pt->fEsd->GetTPCclusters(0)) ){
       //       Error("PropagateBack","Not prolonged track %d",pt->GetLabel());
       //       FollowBackProlongation(*pt2,fInnerSec->GetNRows()+fOuterSec->GetNRows()-1);
@@ -6775,7 +6516,7 @@ Int_t AliTPCtrackerMI::PropagateBack(TObjArray *const arr)
       AliESDkink * kink = fEvent->GetKink(pt->GetKinkIndex(0)-1);
       pt->SetFirstPoint(kink->GetTPCRow0());
       fSectors = fInnerSec;
-      FollowBackProlongation(*pt,fInnerSec->GetNRows()+fOuterSec->GetNRows()-1);  
+      FollowBackProlongation(*pt,fInnerSec->GetNRows()+fOuterSec->GetNRows()-1,1);  
     }
     CookLabel(pt,0.3);
   }
@@ -6783,7 +6524,7 @@ Int_t AliTPCtrackerMI::PropagateBack(TObjArray *const arr)
 }
 
 
-Int_t AliTPCtrackerMI::PropagateForward2(TObjArray *const arr)
+Int_t AliTPCtrackerMI::PropagateForward2(const TObjArray *const arr)
 {
   //
   // make forward propagation
@@ -6793,12 +6534,12 @@ Int_t AliTPCtrackerMI::PropagateForward2(TObjArray *const arr)
   for (Int_t i=0;i<nseed;i++){
     AliTPCseed *pt = (AliTPCseed*)arr->UncheckedAt(i);
     if (pt) { 
-      FollowProlongation(*pt,0);
+      FollowProlongation(*pt,0,1,1);
       CookLabel(pt,0.3);
     }
     
   }
 return 0;
+ return 0;
 }
 
 
@@ -6865,7 +6606,7 @@ Int_t AliTPCtrackerMI::PropagateBack(AliTPCseed *const pt, Int_t row0, Int_t row
 
 void  AliTPCtrackerMI::GetShape(AliTPCseed * seed, Int_t row)
 {
-  //
+  // gets cluster shape
   // 
   AliTPCClusterParam * clparam = AliTPCcalibDB::Instance()->GetClusterParam();
   Float_t zdrift = TMath::Abs((fkParam->GetZLength(0)-TMath::Abs(seed->GetZ())));
@@ -6974,7 +6715,7 @@ void AliTPCtrackerMI::CookLabel(AliKalmanTrack *tk, Float_t wrong) const {
      Int_t tail=Int_t(0.10*noc);
      max=0;
      Int_t ind=0;
-     for (i=1; i<=160&&ind<tail; i++) {
+     for (i=1; i<160&&ind<tail; i++) {
        //       AliTPCclusterMI *c=clusters[noc-i];
        AliTPCclusterMI *c=clusters[i];
        if (!c) continue;
@@ -7030,7 +6771,7 @@ Int_t AliTPCtrackerMI::CookLabel(AliTPCseed *const t, Float_t wrong,Int_t first,
      }
   }
   noc = current;
-  if (noc<5) return -1;
+  //if (noc<5) return -1;
   Int_t lab=123456789;
   for (i=0; i<noc; i++) {
     AliTPCclusterMI *c=clusters[i];
@@ -7058,7 +6799,7 @@ Int_t AliTPCtrackerMI::CookLabel(AliTPCseed *const t, Float_t wrong,Int_t first,
      Int_t tail=Int_t(0.10*noc);
      max=0;
      Int_t ind=0;
-     for (i=1; i<=160&&ind<tail; i++) {
+     for (i=1; i<160&&ind<tail; i++) {
        //       AliTPCclusterMI *c=clusters[noc-i];
        AliTPCclusterMI *c=clusters[i];
        if (!c) continue;
@@ -7092,7 +6833,7 @@ Int_t  AliTPCtrackerMI::GetRowNumber(Double_t x[3]) const
 
 
 
-void AliTPCtrackerMI::MakeBitmaps(AliTPCseed *t)
+void AliTPCtrackerMI::MakeESDBitmaps(AliTPCseed *t, AliESDtrack *esd)
 {
   //-----------------------------------------------------------------------
   // Fill the cluster and sharing bitmaps of the track
@@ -7103,22 +6844,30 @@ void AliTPCtrackerMI::MakeBitmaps(AliTPCseed *t)
   AliTPCTrackerPoint *point;
   AliTPCclusterMI    *cluster;
   
+  Int_t nclsf = 0;
+  TBits clusterMap(159);
+  TBits sharedMap(159);
+  TBits fitMap(159);
   for (int iter=firstpoint; iter<lastpoint; iter++) {
     // Change to cluster pointers to see if we have a cluster at given padrow
+
     cluster = t->GetClusterPointer(iter);
     if (cluster) {
-      t->SetClusterMapBit(iter, kTRUE);
+      clusterMap.SetBitNumber(iter, kTRUE);
       point = t->GetTrackPoint(iter);
       if (point->IsShared())
-       t->SetSharedMapBit(iter,kTRUE);
-      else
-       t->SetSharedMapBit(iter, kFALSE);
+       sharedMap.SetBitNumber(iter,kTRUE);
     }
-    else {
-      t->SetClusterMapBit(iter, kFALSE);
-      t->SetSharedMapBit(iter, kFALSE);
+    if (t->GetClusterIndex(iter) >= 0 && (t->GetClusterIndex(iter) & 0x8000) == 0) {
+      fitMap.SetBitNumber(iter, kTRUE);
+      nclsf++;
     }
   }
+  esd->SetTPCClusterMap(clusterMap);
+  esd->SetTPCSharedMap(sharedMap);
+  esd->SetTPCFitMap(fitMap);
+  if (nclsf != t->GetNumberOfClusters())
+    AliWarning(Form("Inconsistency between ncls %d and indices %d (found %d)",t->GetNumberOfClusters(),nclsf,esd->GetTPCClusterMap().CountBits()));
 }
 
 Bool_t AliTPCtrackerMI::IsFindable(AliTPCseed & track){
@@ -7138,9 +6887,40 @@ Bool_t AliTPCtrackerMI::IsFindable(AliTPCseed & track){
 
 void AliTPCtrackerMI::AddCovariance(AliTPCseed * seed){
   //
-  // Adding systematic error
+  // Adding systematic error estimate to the covariance matrix
   // !!!! the systematic error for element 4 is in 1/cm not in pt 
+  //
+  const Double_t *param = AliTPCReconstructor::GetRecoParam()->GetSystematicError();
+  //
+  // use only the diagonal part if not specified otherwise
+  if (!AliTPCReconstructor::GetRecoParam()->GetUseSystematicCorrelation()) return AddCovarianceAdd(seed);
+  //
+  Double_t *covarS= (Double_t*)seed->GetCovariance();
+  Double_t factor[5]={1,1,1,1,1};
+  Double_t facC =  AliTracker::GetBz()*kB2C;
+  factor[0]= TMath::Sqrt(TMath::Abs((covarS[0] + param[0]*param[0])/covarS[0]));
+  factor[1]= TMath::Sqrt(TMath::Abs((covarS[2] + param[1]*param[1])/covarS[2]));
+  factor[2]= TMath::Sqrt(TMath::Abs((covarS[5] + param[2]*param[2])/covarS[5]));
+  factor[3]= TMath::Sqrt(TMath::Abs((covarS[9] + param[3]*param[3])/covarS[9]));
+  factor[4]= TMath::Sqrt(TMath::Abs((covarS[14] + facC*facC*param[4]*param[4])/covarS[14]));
+  // 0
+  // 1    2
+  // 3    4    5
+  // 6    7    8    9 
+  // 10   11   12   13   14
+  for (Int_t i=0; i<5; i++){
+    for (Int_t j=i; j<5; j++){
+      Int_t index=seed->GetIndex(i,j);
+      covarS[index]*=factor[i]*factor[j];
+    }
+  }
+}
 
+
+void AliTPCtrackerMI::AddCovarianceAdd(AliTPCseed * seed){
+  //
+  // Adding systematic error - as additive factor without correlation
+  //
   const Double_t *param = AliTPCReconstructor::GetRecoParam()->GetSystematicError();
   Double_t *covarIn= (Double_t*)seed->GetCovariance();
   Double_t covar[15];
@@ -7173,3 +6953,51 @@ void AliTPCtrackerMI::AddCovariance(AliTPCseed * seed){
   //
   seed->AddCovariance(covar);
 }
+
+//_____________________________________________________________________________
+Bool_t  AliTPCtrackerMI::IsTPCHVDipEvent(AliESDEvent const *esdEvent) {
+//
+// check events affected by TPC HV dip
+//
+if(!esdEvent) return kFALSE;
+
+// Init TPC OCDB
+if(!AliTPCcalibDB::Instance()) return kFALSE;
+AliTPCcalibDB::Instance()->SetRun(esdEvent->GetRunNumber());
+
+// Get HV TPC chamber sensors and calculate the median
+AliDCSSensorArray *voltageArray= AliTPCcalibDB::Instance()->GetVoltageSensors(esdEvent->GetRunNumber());
+if(!voltageArray) return kFALSE;
+
+TString sensorName="";
+Double_t kTPCHVdip = 2.0; // allow for 2V dip as compared to median from given sensor
+
+
+  for(Int_t sector=0; sector<72; sector++)
+  {
+    Char_t sideName='A';
+    if ((sector/18)%2==1) sideName='C';
+    if (sector<36){
+      //IROC
+      sensorName=Form("TPC_ANODE_I_%c%02d_VMEAS",sideName,sector%18);
+    } else {
+      //OROC
+      sensorName=Form("TPC_ANODE_O_%c%02d_0_VMEAS",sideName,sector%18);
+    }
+    
+    AliDCSSensor* sensor = voltageArray->GetSensor(sensorName.Data());
+    if(!sensor) continue;
+    TGraph *graph = sensor->GetGraph();
+    if(!graph) continue;
+    Double_t median = TMath::Median(graph->GetN(), graph->GetY());
+    if(median == 0) continue;
+
+    //printf("chamber %d, sensor %s, HV %f, median %f\n", sector, sensorName.Data(), sensor->GetValue(esdEvent->GetTimeStamp()), median);
+    
+    if(TMath::Abs(sensor->GetValue(esdEvent->GetTimeStamp())-median)>kTPCHVdip) {
+      return kTRUE; 
+    }
+  } 
+  return kFALSE; 
+}