]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TPC/AliTPCclustererMI.cxx
Fixes for CAF, etc
[u/mrichter/AliRoot.git] / TPC / AliTPCclustererMI.cxx
index c50b1e82239234b37011565ecefaeed8d5769b45..8b481f7b859fcd6a1b14c4fe3753599f10582d6d 100644 (file)
 //  1. The Input data for reconstruction - Options
 //      1.a Simulated data  - TTree - invoked Digits2Clusters()
 //      1.b Raw data        - Digits2Clusters(AliRawReader* rawReader); 
+//      1.c HLT clusters    - Digits2Clusters and Digits2Clusters(AliRawReader* rawReader)
+//                            invoke ReadHLTClusters()
+//
+//      fUseHLTClusters     - switches between different inputs
+//                            1 -> only TPC raw/sim data
+//                            2 -> if present TPC raw/sim data, otherwise HLT clusters
+//                            3 -> only HLT clusters
+//                            4 -> if present HLT clusters, otherwise TPC raw/sim data
 //
 //  2. The Output data
 //      2.a TTree with clusters - if  SetOutput(TTree * tree) invoked
@@ -48,6 +56,8 @@
 #include <TRandom.h>
 #include <TTree.h>
 #include <TTreeStream.h>
+#include "TSystem.h"
+#include "TClass.h"
 
 #include "AliDigits.h"
 #include "AliLoader.h"
@@ -72,6 +82,8 @@
 #include "AliTPCTransform.h"
 #include "AliTPCclustererMI.h"
 
+using std::cerr;
+using std::endl;
 ClassImp(AliTPCclustererMI)
 
 
@@ -82,7 +94,7 @@ AliTPCclustererMI::AliTPCclustererMI(const AliTPCParam* par, const AliTPCRecoPar
   fNSigBins(0),
   fLoop(0),
   fMaxBin(0),
-  fMaxTime(0),
+  fMaxTime(1006), // 1000>940 so use 1000, add 3 virtual time bins before and 3 after
   fMaxPad(0),
   fSector(-1),
   fRow(-1),
@@ -107,7 +119,12 @@ AliTPCclustererMI::AliTPCclustererMI(const AliTPCParam* par, const AliTPCRecoPar
   fDebugStreamer(0),
   fRecoParam(0),
   fBDumpSignal(kFALSE),
-  fBClonesArray(kFALSE)
+  fBClonesArray(kFALSE),
+  fUseHLTClusters(4),
+  fAllBins(NULL),
+  fAllSigBins(NULL),
+  fAllNSigBins(NULL),
+  fHLTClusterAccess(NULL)
 {
   //
   // COSNTRUCTOR
@@ -129,60 +146,29 @@ AliTPCclustererMI::AliTPCclustererMI(const AliTPCParam* par, const AliTPCRecoPar
   }
 
   //  Int_t nPoints = fRecoParam->GetLastBin()-fRecoParam->GetFirstBin();
-  fRowCl= new AliTPCClustersRow();
-  fRowCl->SetClass("AliTPCclusterMI");
-  fRowCl->SetArray(1);
+  fRowCl= new AliTPCClustersRow("AliTPCclusterMI");
 
-}
-//______________________________________________________________
-AliTPCclustererMI::AliTPCclustererMI(const AliTPCclustererMI &param)
-              :TObject(param),
-  fBins(0),
-  fSigBins(0),
-  fNSigBins(0),
-  fLoop(0),
-  fMaxBin(0),
-  fMaxTime(0),
-  fMaxPad(0),
-  fSector(-1),
-  fRow(-1),
-  fSign(0),
-  fRx(0),
-  fPadWidth(0),
-  fPadLength(0),
-  fZWidth(0),
-  fPedSubtraction(kFALSE),
-  fEventHeader(0),
-  fTimeStamp(0),
-  fEventType(0),
-  fInput(0),
-  fOutput(0),
-  fOutputArray(0),
-  fOutputClonesArray(0),
-  fRowCl(0),
-  fRowDig(0),
-  fParam(0),
-  fNcluster(0),
-  fNclusters(0),
-  fDebugStreamer(0),
-  fRecoParam(0),
-  fBDumpSignal(kFALSE),
-  fBClonesArray(kFALSE)
-{
-  //
-  // dummy
-  //
-  fMaxBin = param.fMaxBin;
-}
-//______________________________________________________________
-AliTPCclustererMI & AliTPCclustererMI::operator =(const AliTPCclustererMI & param)
-{
+  // Non-persistent arrays
   //
-  // assignment operator - dummy
+  //alocate memory for sector - maximal case
   //
-  fMaxBin=param.fMaxBin;
-  return (*this);
+  AliTPCROC * roc = AliTPCROC::Instance();
+  Int_t nRowsMax = roc->GetNRows(roc->GetNSector()-1);
+  Int_t nPadsMax = roc->GetNPads(roc->GetNSector()-1,nRowsMax-1);
+
+  fAllBins = new Float_t*[nRowsMax];
+  fAllSigBins = new Int_t*[nRowsMax];
+  fAllNSigBins = new Int_t[nRowsMax];
+  for (Int_t iRow = 0; iRow < nRowsMax; iRow++) {
+    //
+    Int_t maxBin = fMaxTime*(nPadsMax+6);  // add 3 virtual pads  before and 3 after
+    fAllBins[iRow] = new Float_t[maxBin];
+    memset(fAllBins[iRow],0,sizeof(Float_t)*maxBin);
+    fAllSigBins[iRow] = new Int_t[maxBin];
+    fAllNSigBins[iRow]=0;
+  }
 }
+
 //______________________________________________________________
 AliTPCclustererMI::~AliTPCclustererMI(){
   //
@@ -197,6 +183,22 @@ AliTPCclustererMI::~AliTPCclustererMI(){
     fOutputClonesArray->Delete();
     delete fOutputClonesArray;
   }
+
+  if (fRowCl) {
+    fRowCl->GetArray()->Delete();
+    delete fRowCl;
+  }
+
+  AliTPCROC * roc = AliTPCROC::Instance();
+  Int_t nRowsMax = roc->GetNRows(roc->GetNSector()-1);
+  for (Int_t iRow = 0; iRow < nRowsMax; iRow++) {
+    delete [] fAllBins[iRow];
+    delete [] fAllSigBins[iRow];
+  }
+  delete [] fAllBins;
+  delete [] fAllSigBins;
+  delete [] fAllNSigBins;
+  if (fHLTClusterAccess) delete fHLTClusterAccess;
 }
 
 void AliTPCclustererMI::SetInput(TTree * tree)
@@ -220,10 +222,8 @@ void AliTPCclustererMI::SetOutput(TTree * tree)
   //
   if (!tree) return;
   fOutput= tree;
-  AliTPCClustersRow clrow;
+  AliTPCClustersRow clrow("AliTPCclusterMI");
   AliTPCClustersRow *pclrow=&clrow;  
-  clrow.SetClass("AliTPCclusterMI");
-  clrow.SetArray(1); // to make Clones array
   fOutput->Branch("Segment","AliTPCClustersRow",&pclrow,32000,200);    
 }
 
@@ -271,11 +271,25 @@ void AliTPCclustererMI::MakeCluster(Int_t k,Int_t max,Float_t *bins, UInt_t /*m*
 AliTPCclusterMI &c) 
 {
   //
+  //  Make cluster: characterized by position ( mean-  COG) , shape (RMS) a charge, QMax and Q tot
+  //  Additional correction:
+  //  a) To correct for charge below threshold, in the +1 neghborhood to the max charge charge 
+  //       is extrapolated using gaussian approximation assuming given cluster width.. 
+  //       Additional empirical factor is used to account for the charge fluctuation (kVirtualChargeFactor). 
+  //       Actual value of the  kVirtualChargeFactor should obtained minimimizing residuals between the cluster
+  //       and track interpolation.
+  //  b.) For space points with extended shape (in comparison with expected using parameterization) clusters are 
+  //      unfoded     
+  //  
+  //  NOTE. Actual/Empirical  values for correction are hardwired in the code.
+  //
+  // Input paramters for function:
   //  k    - Make cluster at position k  
   //  bins - 2 D array of signals mapped to 1 dimensional array - 
   //  max  - the number of time bins er one dimension
-  //  c    - refernce to cluster to be filled
+  //  c    - reference to cluster to be filled
   //
+  Double_t kVirtualChargeFactor=0.5;
   Int_t i0=k/max;  //central pad
   Int_t j0=k%max;  //central time bin
 
@@ -301,7 +315,7 @@ AliTPCclusterMI &c)
        Float_t ratio = TMath::Exp(-1.2*TMath::Abs(di)/sigmay2)*TMath::Exp(-1.2*TMath::Abs(dj)/sigmaz2);
        amp = ((matrix[2][0]-2)*(matrix[2][0]-2)/(matrix[-di+2][-dj]+2))*ratio;
        if (amp>2) amp = 2;
-       vmatrix[2+di][2+dj]=amp;
+       vmatrix[2+di][2+dj]= kVirtualChargeFactor*amp;
        vmatrix[2+2*di][2+2*dj]=0;
        if ( (di*dj)!=0){       
          //DIAGONAL ELEMENTS
@@ -596,6 +610,7 @@ void AliTPCclustererMI::AddCluster(AliTPCclusterMI &c, Float_t * /*matrix*/, Int
   AliTPCTransform *transform = AliTPCcalibDB::Instance()->GetTransform() ;
   if (!transform) {
     AliFatal("Tranformations not in calibDB");    
+    return;
   }
   transform->SetCurrentRecoParam((AliTPCRecoParam*)fRecoParam);
   Double_t x[3]={c.GetRow(),c.GetPad(),c.GetTimeBin()};
@@ -610,7 +625,6 @@ void AliTPCclustererMI::AddCluster(AliTPCclusterMI &c, Float_t * /*matrix*/, Int
     c.SetType(-(c.GetType()+3));  //edge clusters
   }
   if (fLoop==2) c.SetType(100);
-  if (!AcceptCluster(&c)) return;
 
   // select output 
   TClonesArray * arr = 0;
@@ -672,7 +686,40 @@ void AliTPCclustererMI::Digits2Clusters()
     fParam->Dump();
     fRecoParam->Dump();
   }
+  fRowDig = NULL;
+
+  //-----------------------------------------------------------------
+  // Use HLT clusters
+  //-----------------------------------------------------------------
+  if (fUseHLTClusters == 3 || fUseHLTClusters == 4) {
+    AliInfo("Using HLT clusters for TPC off-line reconstruction");
+    fZWidth = fParam->GetZWidth();
+    Int_t iResult = ReadHLTClusters();
+
+    // HLT clusters present
+    if (iResult >= 0 && fNclusters > 0)
+      return; 
+
+    // HLT clusters not present
+    if (iResult < 0 || fNclusters == 0) {
+      if (fUseHLTClusters == 3) { 
+       AliError("No HLT clusters present, but requested.");
+       return;
+      }
+      else {
+       AliInfo("Now trying to read from TPC RAW");
+      }
+    }
+    // Some other problem during cluster reading
+    else {
+      AliWarning("Some problem while unpacking of HLT clusters.");
+      return;
+    }
+  } // if (fUseHLTClusters == 3 || fUseHLTClusters == 4) {
 
+  //-----------------------------------------------------------------
+  // Run TPC off-line clusterer
+  //-----------------------------------------------------------------
   AliTPCCalPad * gainTPC = AliTPCcalibDB::Instance()->GetPadGainFactor();
   AliTPCCalPad * noiseTPC = AliTPCcalibDB::Instance()->GetPadNoise();
   AliSimDigits digarr, *dummy=&digarr;
@@ -704,7 +751,7 @@ void AliTPCclustererMI::Digits2Clusters()
     fZWidth = fParam->GetZWidth();
     if (fSector < kNIS) {
       fMaxPad = fParam->GetNPadsLow(row);
-      fSign = (fSector < kNIS/2) ? 1 : -1;
+      fSign =  (fSector < kNIS/2) ? 1 : -1;
       fPadLength = fParam->GetPadPitchLength(fSector,row);
       fPadWidth = fParam->GetPadPitchWidth();
     } else {
@@ -739,7 +786,7 @@ void AliTPCclustererMI::Digits2Clusters()
 
     FindClusters(noiseROC);
     FillRow();
-    fRowCl->GetArray()->Clear();    
+    fRowCl->GetArray()->Clear("C");    
     nclusters+=fNcluster;    
 
     delete[] fBins;
@@ -747,9 +794,16 @@ void AliTPCclustererMI::Digits2Clusters()
   }  
  
   Info("Digits2Clusters", "Number of found clusters : %d", nclusters);
+
+  if (fUseHLTClusters == 2 && nclusters == 0) {
+    AliInfo("No clusters from TPC Raw data, now trying to read HLT clusters.");
+
+    fZWidth = fParam->GetZWidth();
+    ReadHLTClusters();
+  }
 }
 
-void AliTPCclustererMI::ProcessSectorData(Float_t** allBins, Int_t** allSigBins, Int_t*  allNSigBins){
+void AliTPCclustererMI::ProcessSectorData(){
   //
   // Process the data for the current sector
   //
@@ -779,10 +833,10 @@ void AliTPCclustererMI::ProcessSectorData(Float_t** allBins, Int_t** allSigBins,
     //
     // Line mean - if more than given digits over threshold - make a noise calculation
     // and pedestal substration
-        if (!calcPedestal && allBins[iRow][iPad*fMaxTime+0]<50) continue;
+        if (!calcPedestal && fAllBins[iRow][iPad*fMaxTime+0]<50) continue;
     //
-        if (allBins[iRow][iPad*fMaxTime+0] <1 ) continue;  // no data
-        Float_t *p = &allBins[iRow][iPad*fMaxTime+3];
+        if (fAllBins[iRow][iPad*fMaxTime+0] <1 ) continue;  // no data
+        Float_t *p = &fAllBins[iRow][iPad*fMaxTime+3];
     //Float_t pedestal = TMath::Median(fMaxTime, p);
         Int_t id[3] = {fSector, iRow, iPad-3};
     // calib values
@@ -797,29 +851,29 @@ void AliTPCclustererMI::ProcessSectorData(Float_t** allBins, Int_t** allSigBins,
     //
         for (Int_t iTimeBin = 0; iTimeBin < fMaxTime; iTimeBin++) {
           Int_t bin = iPad*fMaxTime+iTimeBin;
-          allBins[iRow][bin] -= pedestalEvent;
+          fAllBins[iRow][bin] -= pedestalEvent;
           if (iTimeBin < fRecoParam->GetFirstBin())
-            allBins[iRow][bin] = 0;
+            fAllBins[iRow][bin] = 0;
           if (iTimeBin > fRecoParam->GetLastBin())
-            allBins[iRow][bin] = 0;
-          if (allBins[iRow][iPad*fMaxTime+iTimeBin] < zeroSup)
-            allBins[iRow][bin] = 0;
-          if (allBins[iRow][bin] < 3.0*rmsEvent)   // 3 sigma cut on RMS
-            allBins[iRow][bin] = 0;
-          if (allBins[iRow][bin]) allSigBins[iRow][allNSigBins[iRow]++] = bin;
+            fAllBins[iRow][bin] = 0;
+          if (fAllBins[iRow][iPad*fMaxTime+iTimeBin] < zeroSup)
+            fAllBins[iRow][bin] = 0;
+          if (fAllBins[iRow][bin] < 3.0*rmsEvent)   // 3 sigma cut on RMS
+            fAllBins[iRow][bin] = 0;
+          if (fAllBins[iRow][bin]) fAllSigBins[iRow][fAllNSigBins[iRow]++] = bin;
         }
       }
     }
   }
   
-  if (AliTPCReconstructor::StreamLevel()>3) {
+  if (AliTPCReconstructor::StreamLevel()>5) {
     for (Int_t iRow = 0; iRow < nRows; iRow++) {
       Int_t maxPad = fParam->GetNPads(fSector,iRow);
       
       for (Int_t iPad = 3; iPad < maxPad + 3; iPad++) {
         for (Int_t iTimeBin = 0; iTimeBin < fMaxTime; iTimeBin++) {
           Int_t bin = iPad*fMaxTime+iTimeBin;
-          Float_t signal = allBins[iRow][bin];
+          Float_t signal = fAllBins[iRow][bin];
           if (AliTPCReconstructor::StreamLevel()>3 && signal>3) {
             Double_t x[]={iRow,iPad-3,iTimeBin-3};
             Int_t i[]={fSector};
@@ -827,13 +881,13 @@ void AliTPCclustererMI::ProcessSectorData(Float_t** allBins, Int_t** allSigBins,
             trafo.Transform(x,i,0,1);
             Double_t gx[3]={x[0],x[1],x[2]};
             trafo.RotatedGlobal2Global(fSector,gx);
-        //        allSigBins[iRow][allNSigBins[iRow]++]
-            Int_t rowsigBins = allNSigBins[iRow];
-            Int_t first=allSigBins[iRow][0];
+        //        fAllSigBins[iRow][fAllNSigBins[iRow]++]
+            Int_t rowsigBins = fAllNSigBins[iRow];
+            Int_t first=fAllSigBins[iRow][0];
             Int_t last= 0;
-        //        if (rowsigBins>0) allSigBins[iRow][allNSigBins[iRow]-1];
+        //        if (rowsigBins>0) fAllSigBins[iRow][fAllNSigBins[iRow]-1];
             
-            if (AliTPCReconstructor::StreamLevel()>0) {
+            if (AliTPCReconstructor::StreamLevel()>5) {
               (*fDebugStreamer)<<"Digits"<<
                 "sec="<<fSector<<
                 "row="<<iRow<<
@@ -869,14 +923,14 @@ void AliTPCclustererMI::ProcessSectorData(Float_t** allBins, Int_t** allSigBins,
     fMaxPad = fParam->GetNPads(fSector,fRow);
     fMaxBin = fMaxTime*(fMaxPad+6);  // add 3 virtual pads  before and 3 after
     
-    fBins = allBins[fRow];
-    fSigBins = allSigBins[fRow];
-    fNSigBins = allNSigBins[fRow];
+    fBins = fAllBins[fRow];
+    fSigBins = fAllSigBins[fRow];
+    fNSigBins = fAllNSigBins[fRow];
     
     FindClusters(noiseROC);
     
     FillRow();
-    if(fBClonesArray == kFALSE) fRowCl->GetArray()->Clear();
+    if(fBClonesArray == kFALSE) fRowCl->GetArray()->Clear("C");
     fNclusters += fNcluster;
     
   } // End of loop to find clusters
@@ -901,7 +955,39 @@ void AliTPCclustererMI::Digits2Clusters(AliRawReader* rawReader)
     fRecoParam->Dump();
   }
   fRowDig = NULL;
-  AliTPCROC * roc = AliTPCROC::Instance();
+
+  //-----------------------------------------------------------------
+  // Use HLT clusters
+  //-----------------------------------------------------------------
+  if (fUseHLTClusters == 3 || fUseHLTClusters == 4) {
+    AliInfo("Using HLT clusters for TPC off-line reconstruction");
+    fZWidth = fParam->GetZWidth();
+    Int_t iResult = ReadHLTClusters();
+
+    // HLT clusters present
+    if (iResult >= 0 && fNclusters > 0)
+      return;
+
+    // HLT clusters not present
+    if (iResult < 0 || fNclusters == 0) {
+      if (fUseHLTClusters == 3) { 
+       AliError("No HLT clusters present, but requested.");
+       return;
+      }
+      else {
+       AliInfo("Now trying to read TPC RAW");
+      }
+    }
+    // Some other problem during cluster reading
+    else {
+      AliWarning("Some problem while unpacking of HLT clusters.");
+      return;
+    }
+  } // if (fUseHLTClusters == 3 || fUseHLTClusters == 4) {
+   
+  //-----------------------------------------------------------------
+  // Run TPC off-line clusterer
+  //-----------------------------------------------------------------
   AliTPCCalPad * gainTPC = AliTPCcalibDB::Instance()->GetPadGainFactor();
   AliTPCAltroMapping** mapping =AliTPCcalibDB::Instance()->GetMapping();
   //
@@ -927,23 +1013,16 @@ void AliTPCclustererMI::Digits2Clusters(AliRawReader* rawReader)
   fZWidth = fParam->GetZWidth();
   Int_t zeroSup = fParam->GetZeroSup();
   //
-  //alocate memory for sector - maximal case
+  // Clean-up
   //
-  Float_t** allBins = NULL;
-  Int_t** allSigBins = NULL;
-  Int_t*  allNSigBins = NULL;
+  AliTPCROC * roc = AliTPCROC::Instance();
   Int_t nRowsMax = roc->GetNRows(roc->GetNSector()-1);
   Int_t nPadsMax = roc->GetNPads(roc->GetNSector()-1,nRowsMax-1);
-  allBins = new Float_t*[nRowsMax];
-  allSigBins = new Int_t*[nRowsMax];
-  allNSigBins = new Int_t[nRowsMax];
   for (Int_t iRow = 0; iRow < nRowsMax; iRow++) {
     //
     Int_t maxBin = fMaxTime*(nPadsMax+6);  // add 3 virtual pads  before and 3 after
-    allBins[iRow] = new Float_t[maxBin];
-    memset(allBins[iRow],0,sizeof(Float_t)*maxBin);
-    allSigBins[iRow] = new Int_t[maxBin];
-    allNSigBins[iRow]=0;
+    memset(fAllBins[iRow],0,sizeof(Float_t)*maxBin);
+    fAllNSigBins[iRow]=0;
   }
 
   Int_t prevSector=-1;
@@ -1029,15 +1108,15 @@ void AliTPCclustererMI::Digits2Clusters(AliRawReader* rawReader)
           if (!calcPedestal) {
             Int_t bin = iPad*fMaxTime+iTimeBin;
             if (gain>0){
-              allBins[iRow][bin] = signal/gain;
+              fAllBins[iRow][bin] = signal/gain;
             }else{
-              allBins[iRow][bin] =0;
+              fAllBins[iRow][bin] =0;
             }
-            allSigBins[iRow][allNSigBins[iRow]++] = bin;
+            fAllSigBins[iRow][fAllNSigBins[iRow]++] = bin;
           }else{
-            allBins[iRow][iPad*fMaxTime+iTimeBin] = signal;
+            fAllBins[iRow][iPad*fMaxTime+iTimeBin] = signal;
           }
-          allBins[iRow][iPad*fMaxTime+0]+=1.;  // pad with signal
+          fAllBins[iRow][iPad*fMaxTime+0]+=1.;  // pad with signal
           
           // Temporary
           digCounter++;
@@ -1053,39 +1132,36 @@ void AliTPCclustererMI::Digits2Clusters(AliRawReader* rawReader)
   } // End of loop over sectors
   //process last sector
   if ( digCounter>0 ){
-    ProcessSectorData(allBins, allSigBins, allNSigBins);
+    ProcessSectorData();
     for (Int_t iRow = 0; iRow < fParam->GetNRow(fSector); iRow++) {
       Int_t maxPad = fParam->GetNPads(fSector,iRow);
       Int_t maxBin = fMaxTime*(maxPad+6);  // add 3 virtual pads  before and 3 after
-      memset(allBins[iRow],0,sizeof(Float_t)*maxBin);
-      allNSigBins[iRow] = 0;
+      memset(fAllBins[iRow],0,sizeof(Float_t)*maxBin);
+      fAllNSigBins[iRow] = 0;
     }
     prevSector=fSector;
     digCounter=0;
   }
   }
   
-
-  
-  for (Int_t iRow = 0; iRow < nRowsMax; iRow++) {
-    delete [] allBins[iRow];
-    delete [] allSigBins[iRow];
-  }
-  delete [] allBins;
-  delete [] allSigBins;
-  delete [] allNSigBins;
-  
   if (rawReader->GetEventId() && fOutput ){
-    Info("Digits2Clusters", "File  %s Event\t%d\tNumber of found clusters : %d\n", fOutput->GetName(),*(rawReader->GetEventId()), fNclusters);
+    Info("Digits2Clusters", "File  %s Event\t%u\tNumber of found clusters : %d\n", fOutput->GetName(),*(rawReader->GetEventId()), fNclusters);
   }
   
   if(rawReader->GetEventId()) {
-    Info("Digits2Clusters", "Event\t%d\tNumber of found clusters : %d\n",*(rawReader->GetEventId()), fNclusters);
+    Info("Digits2Clusters", "Event\t%u\tNumber of found clusters : %d\n",*(rawReader->GetEventId()), fNclusters);
   }
   
   if(fBClonesArray) {
     //Info("Digits2Clusters", "Number of found clusters : %d\n",fOutputClonesArray->GetEntriesFast());
   }
+
+  if (fUseHLTClusters == 2 && fNclusters == 0) {
+    AliInfo("No clusters from TPC Raw data, now trying to read HLT clusters.");
+
+    fZWidth = fParam->GetZWidth();
+    ReadHLTClusters();
+  }
 }
 
 
@@ -1111,7 +1187,7 @@ void AliTPCclustererMI::Digits2ClustersOld
     fRecoParam->Dump();
   }
   fRowDig = NULL;
-  AliTPCROC * roc = AliTPCROC::Instance();
+
   AliTPCCalPad * gainTPC = AliTPCcalibDB::Instance()->GetPadGainFactor();
   AliTPCAltroMapping** mapping =AliTPCcalibDB::Instance()->GetMapping();
   //
@@ -1134,23 +1210,17 @@ void AliTPCclustererMI::Digits2ClustersOld
   fZWidth = fParam->GetZWidth();
   Int_t zeroSup = fParam->GetZeroSup();
   //
-  //alocate memory for sector - maximal case
+  // Clean-up
   //
-  Float_t** allBins = NULL;
-  Int_t** allSigBins = NULL;
-  Int_t*  allNSigBins = NULL;
+
+  AliTPCROC * roc = AliTPCROC::Instance();
   Int_t nRowsMax = roc->GetNRows(roc->GetNSector()-1);
   Int_t nPadsMax = roc->GetNPads(roc->GetNSector()-1,nRowsMax-1);
-  allBins = new Float_t*[nRowsMax];
-  allSigBins = new Int_t*[nRowsMax];
-  allNSigBins = new Int_t[nRowsMax];
   for (Int_t iRow = 0; iRow < nRowsMax; iRow++) {
     //
     Int_t maxBin = fMaxTime*(nPadsMax+6);  // add 3 virtual pads  before and 3 after
-    allBins[iRow] = new Float_t[maxBin];
-    memset(allBins[iRow],0,sizeof(Float_t)*maxBin);
-    allSigBins[iRow] = new Int_t[maxBin];
-    allNSigBins[iRow]=0;
+    memset(fAllBins[iRow],0,sizeof(Float_t)*maxBin);
+    fAllNSigBins[iRow]=0;
   }
   //
   // Loop over sectors
@@ -1177,7 +1247,7 @@ void AliTPCclustererMI::Digits2ClustersOld
     rawReader->Select("TPC",indexDDL,indexDDL+nDDLs-1);
 
     // select only good sector 
-    input.Next();
+    if (!input.Next()) continue;
     if(input.GetSector() != fSector) continue;
 
     AliTPCCalROC * gainROC    = gainTPC->GetCalROC(fSector);  // pad gains per given sector
@@ -1190,8 +1260,8 @@ void AliTPCclustererMI::Digits2ClustersOld
         maxPad = fParam->GetNPadsUp(iRow);
       
       Int_t maxBin = fMaxTime*(maxPad+6);  // add 3 virtual pads  before and 3 after
-      memset(allBins[iRow],0,sizeof(Float_t)*maxBin);
-      allNSigBins[iRow] = 0;
+      memset(fAllBins[iRow],0,sizeof(Float_t)*maxBin);
+      fAllNSigBins[iRow] = 0;
     }
     
     Int_t digCounter=0;
@@ -1244,15 +1314,15 @@ void AliTPCclustererMI::Digits2ClustersOld
       if (!calcPedestal) {
         Int_t bin = iPad*fMaxTime+iTimeBin;
         if (gain>0){
-          allBins[iRow][bin] = signal/gain;
+          fAllBins[iRow][bin] = signal/gain;
         }else{
-          allBins[iRow][bin] =0;
+          fAllBins[iRow][bin] =0;
         }
-        allSigBins[iRow][allNSigBins[iRow]++] = bin;
+        fAllSigBins[iRow][fAllNSigBins[iRow]++] = bin;
       }else{
-        allBins[iRow][iPad*fMaxTime+iTimeBin] = signal;
+        fAllBins[iRow][iPad*fMaxTime+iTimeBin] = signal;
       }
-      allBins[iRow][iPad*fMaxTime+0]+=1.;  // pad with signal
+      fAllBins[iRow][iPad*fMaxTime+0]+=1.;  // pad with signal
 
       // Temporary
       digCounter++;
@@ -1263,17 +1333,9 @@ void AliTPCclustererMI::Digits2ClustersOld
     //
     // Now loop over rows and perform pedestal subtraction
     if (digCounter==0) continue;
-    ProcessSectorData(allBins, allSigBins, allNSigBins);
+    ProcessSectorData();
   } // End of loop over sectors
 
-  for (Int_t iRow = 0; iRow < nRowsMax; iRow++) {
-    delete [] allBins[iRow];
-    delete [] allSigBins[iRow];
-  }  
-  delete [] allBins;
-  delete [] allSigBins;
-  delete [] allNSigBins;
-  
   if (rawReader->GetEventId() && fOutput ){
     Info("Digits2Clusters", "File  %s Event\t%d\tNumber of found clusters : %d\n", fOutput->GetName(),*(rawReader->GetEventId()), fNclusters);
   }
@@ -1309,6 +1371,7 @@ void AliTPCclustererMI::FindClusters(AliTPCCalROC * noiseROC)
   Float_t minMaxCutSigma       = fRecoParam->GetMinMaxCutSigma();
   Float_t minLeftRightCutSigma = fRecoParam->GetMinLeftRightCutSigma();
   Float_t minUpDownCutSigma    = fRecoParam->GetMinUpDownCutSigma();
+  Int_t   useOnePadCluster     = fRecoParam->GetUseOnePadCluster();
   for (Int_t iSig = 0; iSig < fNSigBins; iSig++) {
     Int_t i = fSigBins[iSig];
     if (i%fMaxTime<=crtime) continue;
@@ -1316,9 +1379,11 @@ void AliTPCclustererMI::FindClusters(AliTPCCalROC * noiseROC)
     //absolute custs
     if (b[0]<minMaxCutAbs) continue;   //threshold for maxima  
     //
-    if (b[-1]+b[1]+b[-fMaxTime]+b[fMaxTime]<=0) continue;  // cut on isolated clusters 
-    if (b[-1]+b[1]<=0) continue;               // cut on isolated clusters
-    if (b[-fMaxTime]+b[fMaxTime]<=0) continue; // cut on isolated clusters
+    if (useOnePadCluster==0){
+      if (b[-1]+b[1]+b[-fMaxTime]+b[fMaxTime]<=0) continue;  // cut on isolated clusters 
+      if (b[-1]+b[1]<=0) continue;               // cut on isolated clusters
+      if (b[-fMaxTime]+b[fMaxTime]<=0) continue; // cut on isolated clusters
+    }
     //
     if ((b[0]+b[-1]+b[1])<minUpDownCutAbs) continue;   //threshold for up down  (TRF) 
     if ((b[0]+b[-fMaxTime]+b[fMaxTime])<minLeftRightCutAbs) continue;   //threshold for left right (PRF)    
@@ -1340,7 +1405,7 @@ void AliTPCclustererMI::FindClusters(AliTPCCalROC * noiseROC)
 }
 
 Bool_t AliTPCclustererMI::AcceptCluster(AliTPCclusterMI *cl){
-  //
+  // -- Depricated --
   // Currently hack to filter digital noise (15.06.2008)
   // To be parameterized in the AliTPCrecoParam
   // More inteligent way  to be used in future
@@ -1485,7 +1550,6 @@ Double_t AliTPCclustererMI::ProcesSignal(Float_t *signal, Int_t nchannels, Int_t
     dsignal[i] = signal[i];
   }
 
-  TGraph * graph=0;
   //
   // Big signals dumping
   //    
@@ -1497,7 +1561,7 @@ Double_t AliTPCclustererMI::ProcesSignal(Float_t *signal, Int_t nchannels, Int_t
       "Sector="<<uid[0]<<
       "Row="<<uid[1]<<
       "Pad="<<uid[2]<<
-      "Graph="<<graph<<
+      //      "Graph="<<graph<<
       "Max="<<max<<
       "MaxPos="<<maxPos<<      
       //
@@ -1509,7 +1573,6 @@ Double_t AliTPCclustererMI::ProcesSignal(Float_t *signal, Int_t nchannels, Int_t
       "Mean09="<<mean09<<
       "RMS09="<<rms09<<
       "\n";
-  delete graph;  
   }
 
   delete [] dsignal;
@@ -1521,7 +1584,111 @@ Double_t AliTPCclustererMI::ProcesSignal(Float_t *signal, Int_t nchannels, Int_t
   return median;
 }
 
+Int_t AliTPCclustererMI::ReadHLTClusters()
+{
+  //
+  // read HLT clusters instead of off line custers, 
+  // used in Digits2Clusters
+  //
+
+  if (!fHLTClusterAccess) {
+  TClass* pCl=NULL;
+  ROOT::NewFunc_t pNewFunc=NULL;
+  do {
+    pCl=TClass::GetClass("AliHLTTPCClusterAccessHLTOUT");
+  } while (!pCl && gSystem->Load("libAliHLTTPC.so")==0);
+  if (!pCl || (pNewFunc=pCl->GetNew())==NULL) {
+    AliError("can not load class description of AliHLTTPCClusterAccessHLTOUT, aborting ...");
+    return -1;
+  }
+  
+  void* p=(*pNewFunc)(NULL);
+  if (!p) {
+    AliError("unable to create instance of AliHLTTPCClusterAccessHLTOUT");
+    return -2;
+  }
+  fHLTClusterAccess=reinterpret_cast<TObject*>(p);
+  }
+
+  TObject* pClusterAccess=fHLTClusterAccess;
+
+  const Int_t kNIS = fParam->GetNInnerSector();
+  const Int_t kNOS = fParam->GetNOuterSector();
+  const Int_t kNS = kNIS + kNOS;
+  fNclusters  = 0;
+  
+  // make sure that all clusters from the previous event are cleared
+  pClusterAccess->Clear("event");
+  for(fSector = 0; fSector < kNS; fSector++) {
+
+    Int_t iResult = 1;
+    TString param("sector="); param+=fSector;
+    // prepare for next sector
+    pClusterAccess->Clear("sector");
+    pClusterAccess->Execute("read", param, &iResult);
+    if (iResult < 0) {
+      return iResult;
+      AliError("HLT Clusters can not be found");
+    }
 
+    TObject* pObj=pClusterAccess->FindObject("clusterarray");
+    if (pObj==NULL) {
+      AliError("HLT clusters requested, but not cluster array not present");
+      return -4;
+    }
 
+    TObjArray* clusterArray=dynamic_cast<TClonesArray*>(pObj);
+    if (!clusterArray) {
+      AliError("HLT cluster array is not of class type TClonesArray");
+      return -5;
+    }
+
+    AliDebug(4,Form("Reading %d clusters from HLT for sector %d", clusterArray->GetEntriesFast(), fSector));
+
+    Int_t nClusterSector=0;
+    Int_t nRows=fParam->GetNRow(fSector);
+
+    for (fRow = 0; fRow < nRows; fRow++) {
+      fRowCl->SetID(fParam->GetIndex(fSector, fRow));
+      if (fOutput) fOutput->GetBranch("Segment")->SetAddress(&fRowCl);
+      fNcluster=0; // reset clusters per row
+      
+      fRx = fParam->GetPadRowRadii(fSector, fRow);
+      fPadLength = fParam->GetPadPitchLength(fSector, fRow);
+      fPadWidth  = fParam->GetPadPitchWidth();
+      fMaxPad = fParam->GetNPads(fSector,fRow);
+      fMaxBin = fMaxTime*(fMaxPad+6);  // add 3 virtual pads  before and 3 after
+      
+      fBins = fAllBins[fRow];
+      fSigBins = fAllSigBins[fRow];
+      fNSigBins = fAllNSigBins[fRow];
+      
+      for (Int_t i=0; i<clusterArray->GetEntriesFast(); i++) {
+       if (!clusterArray->At(i)) 
+         continue;
+       
+       AliTPCclusterMI* cluster=dynamic_cast<AliTPCclusterMI*>(clusterArray->At(i));
+       if (!cluster) continue;
+       if (cluster->GetRow()!=fRow) continue;
+       nClusterSector++;
+       AddCluster(*cluster, NULL, 0);
+      }
+      
+      FillRow();
+      fRowCl->GetArray()->Clear("c");
+      
+    } // for (fRow = 0; fRow < nRows; fRow++) {
+    if (nClusterSector!=clusterArray->GetEntriesFast()) {
+      AliError(Form("Failed to read %d out of %d HLT clusters", 
+                   clusterArray->GetEntriesFast()-nClusterSector, 
+                   clusterArray->GetEntriesFast()));
+    }
+    fNclusters+=nClusterSector;
+  } // for(fSector = 0; fSector < kNS; fSector++) {
 
+  pClusterAccess->Clear("event");
 
+  Info("Digits2Clusters", "Number of converted HLT clusters : %d", fNclusters);
+  
+  return 0;
+}