]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - HLT/TPCLib/AliHLTTPCClusterFinder.cxx
bug https://savannah.cern.ch/bugs/?69885
[u/mrichter/AliRoot.git] / HLT / TPCLib / AliHLTTPCClusterFinder.cxx
index dce49a7c7439892b14a98a7669b1c58d536633a0..afc3361f0013d5ab8ed5506b58274bc7f05ed8a7 100644 (file)
 //* provided "as is" without express or implied warranty.                  *
 //**************************************************************************
 
-/** @file   AliHLTTPCClusterFinder.cxx
-    @author Kenneth Aamodt, Kalliopi Kanaki
-    @date   
-    @brief  Cluster Finder for the TPC
-*/
+/ @file   AliHLTTPCClusterFinder.cxx
+//  @author Kenneth Aamodt, Kalliopi Kanaki
+//  @date   
+//  @brief  Cluster Finder for the TPC
+//  @note 
 
 #include "AliHLTTPCDigitReader.h"
 #include "AliHLTTPCRootTypes.h"
 #include "AliHLTTPCLogging.h"
 #include "AliHLTTPCClusterFinder.h"
-#include "AliHLTTPCDigitData.h"
 #include "AliHLTTPCSpacePointData.h"
 #include "AliHLTTPCMemHandler.h"
 #include "AliHLTTPCPad.h"
 #include <sys/time.h>
+#include <algorithm>
+#include <cmath>
+#include "AliTPCcalibDB.h"
+#include "AliTPCTransform.h"
+#include "AliTPCParam.h"
 
 #if __GNUC__ >= 3
 using namespace std;
@@ -69,6 +73,8 @@ AliHLTTPCClusterFinder::AliHLTTPCClusterFinder()
   fUnsorted(0),
   fVectorInitialized(kFALSE),
   fClusters(),
+  fClustersMCInfo(),
+  fMCDigits(),
   fNumberOfPadsInRow(NULL),
   fNumberOfRows(0),
   fRowOfFirstCandidate(0),
@@ -76,13 +82,41 @@ AliHLTTPCClusterFinder::AliHLTTPCClusterFinder()
   fFirstTimeBin(0),
   fLastTimeBin(AliHLTTPCTransform::GetNTimeBins()),
   fTotalChargeOfPreviousClusterCandidate(0),
-  fChargeOfCandidatesFalling(kFALSE)
+  fChargeOfCandidatesFalling(kFALSE),
+  f32BitFormat(kFALSE),
+  fDoMC(kFALSE),
+  fClusterMCVector(),
+  fOfflineTransform(NULL),
+  fOfflineTPCParam( NULL ),
+  fOfflineTPCRecoParam(*AliTPCRecoParam::GetHLTParam()),
+  fTimeMeanDiff(2),
+  fReleaseMemory(0)
 {
   //constructor  
+
+  //uptate the transform class
+
+  fOfflineTransform = AliTPCcalibDB::Instance()->GetTransform(); 
+  if(!fOfflineTransform){
+    HLTError("AliHLTTPCClusterFinder()::UpdateCAlibDB::  Offline transform not in AliTPCcalibDB.");
+  }
+  else{
+    fOfflineTransform->SetCurrentRecoParam(&fOfflineTPCRecoParam);
+  }
+
+  fOfflineTPCParam = AliTPCcalibDB::Instance()->GetParameters();
+  if( !fOfflineTPCParam ){
+    HLTError("AliHLTTPCClusterFinder()::UpdateCAlibDB::  Offline TPC parameters not in AliTPCcalibDB.");
+  } else {
+    fOfflineTPCParam->Update();
+    fOfflineTPCParam->ReadGeoMatrices();
+  }    
+
 }
 
-AliHLTTPCClusterFinder::~AliHLTTPCClusterFinder()
-{
+AliHLTTPCClusterFinder::~AliHLTTPCClusterFinder(){
+  // see header file for class documentation
+  
   //destructor
   if(fVectorInitialized){
     DeInitializePadArray();
@@ -92,16 +126,22 @@ AliHLTTPCClusterFinder::~AliHLTTPCClusterFinder()
     fNumberOfPadsInRow=NULL;
   }
 }
-void AliHLTTPCClusterFinder::InitSlice(Int_t slice,Int_t patch,Int_t firstrow, Int_t lastrow,Int_t nmaxpoints)
-{
+
+void AliHLTTPCClusterFinder::InitSlice(Int_t slice,Int_t patch,Int_t nmaxpoints){
+  // see header file for class documentation
+
   //init slice
   fNClusters = 0;
   fMaxNClusters = nmaxpoints;
   fCurrentSlice = slice;
   fCurrentPatch = patch;
-  fFirstRow = firstrow;
-  fLastRow = lastrow;
+  fFirstRow=AliHLTTPCTransform::GetFirstRow(patch);
+  fLastRow=AliHLTTPCTransform::GetLastRow(patch);
+
+  fClusters.clear();
+  fClustersMCInfo.clear();
+  fMCDigits.clear();
+  fClusterMCVector.clear();   
 }
 
 void AliHLTTPCClusterFinder::InitializePadArray(){
@@ -122,6 +162,8 @@ void AliHLTTPCClusterFinder::InitializePadArray(){
 
   memset( fNumberOfPadsInRow, 0, sizeof(Int_t)*(fNumberOfRows));
 
+  fRowPadVector.clear();
+
   for(UInt_t i=0;i<fNumberOfRows;i++){
     fNumberOfPadsInRow[i]=AliHLTTPCTransform::GetNPads(i+fFirstRow);
     AliHLTTPCPadVector tmpRow;
@@ -135,46 +177,555 @@ void AliHLTTPCClusterFinder::InitializePadArray(){
   fVectorInitialized=kTRUE;
 }
 
-Int_t AliHLTTPCClusterFinder::DeInitializePadArray()
-{
+Int_t AliHLTTPCClusterFinder::DeInitializePadArray(){
   // see header file for class documentation
-  for(UInt_t i=0;i<fNumberOfRows;i++){
-    for(UInt_t j=0;j<=fNumberOfPadsInRow[i];j++){
-      delete fRowPadVector[i][j];
-      fRowPadVector[i][j]=NULL;
+
+  if( fVectorInitialized ){
+    for(UInt_t i=0;i<fNumberOfRows;i++){
+      for(UInt_t j=0;j<=fNumberOfPadsInRow[i];j++){
+       delete fRowPadVector[i][j];
+       fRowPadVector[i][j]=NULL;
+      }
+      fRowPadVector[i].clear();
     }
-    fRowPadVector[i].clear();
+    fRowPadVector.clear();
+    delete[] fNumberOfPadsInRow;
+    fNumberOfPadsInRow = 0;
   }
-  fRowPadVector.clear();
+  fVectorInitialized=kFALSE;
   return 1;
-} 
-
-
-void AliHLTTPCClusterFinder::InitSlice(Int_t slice,Int_t patch,Int_t nmaxpoints)
-{
-  //init slice
-  fNClusters = 0;
-  fMaxNClusters = nmaxpoints;
-  fCurrentSlice = slice;
-  fCurrentPatch = patch;
-  fFirstRow=AliHLTTPCTransform::GetFirstRow(patch);
-  fLastRow=AliHLTTPCTransform::GetLastRow(patch);
 }
 
-void AliHLTTPCClusterFinder::SetOutputArray(AliHLTTPCSpacePointData *pt)
-{
+
+void AliHLTTPCClusterFinder::SetOutputArray(AliHLTTPCSpacePointData *pt){
+  // see header file for class documentation
   //set pointer to output
   fSpacePointData = pt;
 }
 
+
+void AliHLTTPCClusterFinder::ReadDataUnsorted(void* ptr,unsigned long size){
+  // see header file for class documentation
+  //set input pointer
+  fPtr = (UChar_t*)ptr;
+  fSize = size;
+
+  if(!fVectorInitialized){
+    InitializePadArray();
+  }
+
+  if (fDigitReader->InitBlock(fPtr,fSize,fFirstRow,fLastRow,fCurrentPatch,fCurrentSlice)<0) {
+    HLTError("failed setting up digit reader (InitBlock)");
+    return;
+  }
+  
+  while(fDigitReader->NextChannel()){
+    UInt_t row=fDigitReader->GetRow();
+    UInt_t pad=fDigitReader->GetPad();
+
+    if(row>=fRowPadVector.size()){
+      HLTError("Row number is to large: %d, max is %d",row,fRowPadVector.size()-1);
+      continue;
+    }
+    if(pad>=fRowPadVector[row].size()){
+      HLTError("Pad number is to large: %d, max is %d",pad,fRowPadVector[row].size());
+      continue;
+    }
+
+    while(fDigitReader->NextBunch()){
+      if(fDigitReader->GetBunchSize()>1){//to remove single timebin values, this will have to change at some point
+       UInt_t time = fDigitReader->GetTime();
+       if((Int_t)time>=fFirstTimeBin && (Int_t)time+fDigitReader->GetBunchSize()<=fLastTimeBin){
+         // Kenneth: 20-04-09. The following if have been added because of inconsistency in the 40 bit decoder and the 32 bit decoder.
+         // GetSignals() in the 40 bit decoder returns an array of UInt_t while the 32 bit one returns UShort_t
+         // The same is true for the function ReadDataUnsortedDeconvoluteTime() below.
+         // In addition the signals are organized in the opposite direction
+         if(f32BitFormat){
+           const UShort_t *bunchData= fDigitReader->GetSignalsShort();
+           AliHLTTPCClusters candidate;
+           for(Int_t i=fDigitReader->GetBunchSize()-1;i>=0;i--){
+             candidate.fTotalCharge+=bunchData[i];     
+             candidate.fTime += time*bunchData[i];
+             candidate.fTime2 += time*time*bunchData[i];
+             if(bunchData[i]>candidate.fQMax){
+               candidate.fQMax=bunchData[i];
+             }
+             time++;
+           }
+           if(candidate.fTotalCharge>0){
+             candidate.fMean=candidate.fTime/candidate.fTotalCharge;
+             candidate.fPad=candidate.fTotalCharge*pad;
+             candidate.fPad2=candidate.fPad*pad;
+             candidate.fLastMergedPad=pad;
+             candidate.fRowNumber=row+fDigitReader->GetRowOffset();
+           }
+           if(fRowPadVector[row][pad] != NULL){
+             fRowPadVector[row][pad]->AddClusterCandidate(candidate);
+           }
+         }
+         else{
+           const UInt_t *bunchData= fDigitReader->GetSignals();
+           AliHLTTPCClusters candidate;
+           const AliHLTTPCDigitData* digits = NULL;
+           if(fDoMC && (digits = fDigitReader->GetBunchDigits())!=NULL){
+             for(Int_t i=0;i<fDigitReader->GetBunchSize();i++){
+               candidate.fTotalCharge+=bunchData[i];   
+               candidate.fTime += time*bunchData[i];
+               candidate.fTime2 += time*time*bunchData[i];
+               if(bunchData[i]>candidate.fQMax){
+                 candidate.fQMax=bunchData[i];
+               }
+               fMCDigits.push_back(digits[i]);
+               time++;
+             }
+           }
+           else{
+             for(Int_t i=0;i<fDigitReader->GetBunchSize();i++){
+               candidate.fTotalCharge+=bunchData[i];   
+               candidate.fTime += time*bunchData[i];
+               candidate.fTime2 += time*time*bunchData[i];
+               if(bunchData[i]>candidate.fQMax){
+                 candidate.fQMax=bunchData[i];
+               }
+               time++;
+             }
+           }
+           if(candidate.fTotalCharge>0){
+             candidate.fMean=candidate.fTime/candidate.fTotalCharge;
+             candidate.fPad=candidate.fTotalCharge*pad;
+             candidate.fPad2=candidate.fPad*pad;
+             candidate.fLastMergedPad=pad;
+             candidate.fRowNumber=row+fDigitReader->GetRowOffset();
+           }
+           if(fRowPadVector[row][pad] != NULL){
+             fRowPadVector[row][pad]->AddClusterCandidate(candidate);
+             if(fDoMC){
+               fRowPadVector[row][pad]->AddCandidateDigits(fMCDigits);
+               fMCDigits.clear();
+             }
+           }
+         }
+       }
+      }
+    }
+  }
+}
+
+void AliHLTTPCClusterFinder::ReadDataUnsortedDeconvoluteTime(void* ptr,unsigned long size){
+  // see header file for class documentation
+
+  //set input pointer
+  fPtr = (UChar_t*)ptr;
+  fSize = size;
+
+  if(!fVectorInitialized){
+    InitializePadArray();
+  }
+
+  if (fDigitReader->InitBlock(fPtr,fSize,fFirstRow,fLastRow,fCurrentPatch,fCurrentSlice)<0) {
+    HLTError("failed setting up digit reader (InitBlock)");
+    return;
+  }
+  
+  while(fDigitReader->NextChannel()){
+    UInt_t row=fDigitReader->GetRow();
+    UInt_t pad=fDigitReader->GetPad();
+
+    while(fDigitReader->NextBunch()){
+      if(fDigitReader->GetBunchSize()>1){//to remove single timebin values, this will have to change at some point
+       UInt_t time = fDigitReader->GetTime();
+       if((Int_t)time>=fFirstTimeBin && (Int_t)time+fDigitReader->GetBunchSize()<=fLastTimeBin){
+         Int_t indexInBunchData=0;
+         Bool_t moreDataInBunch=kFALSE;
+         UInt_t prevSignal=0;
+         Bool_t signalFalling=kFALSE;
+
+         // Kenneth: 20-04-09. The following if have been added because of inconsistency in the 40 bit decoder and the 32 bit decoder.
+         // GetSignals() in the 40 bit decoder returns an array of UInt_t while the 32 bit one returns UShort_t
+         // The same is true for the function ReadDataUnsorted() above.
+         // In addition the signals are organized in the opposite direction
+         if(f32BitFormat){
+           indexInBunchData = fDigitReader->GetBunchSize();
+           const UShort_t *bunchData= fDigitReader->GetSignalsShort();
+           
+           do{
+             AliHLTTPCClusters candidate;
+             //for(Int_t i=indexInBunchData;i<fDigitReader->GetBunchSize();i++){
+             for(Int_t i=indexInBunchData;i>=0;i--){
+               // Checks if one need to deconvolute the signals
+               if(bunchData[i]>prevSignal && signalFalling==kTRUE){
+                 if(i<fDigitReader->GetBunchSize()-1){ // means there are more than one signal left in the bunch
+                   moreDataInBunch=kTRUE;
+                   prevSignal=0;
+                 }
+                 break;
+               }
+               
+               // Checks if the signal is 0, then quit processing the data.
+               if(bunchData[i]==0 && i<fDigitReader->GetBunchSize()-1){//means we have 0 data fom the rcu, might happen depending on the configuration settings
+                 moreDataInBunch=kTRUE;
+                 prevSignal=0;
+                 break;
+               }
+               
+               if(prevSignal>bunchData[i]){//means the peak of the signal has been reached and deconvolution will happen if the signal rise again.
+                 signalFalling=kTRUE;
+               }
+               candidate.fTotalCharge+=bunchData[i];   
+               candidate.fTime += time*bunchData[i];
+               candidate.fTime2 += time*time*bunchData[i];
+               if(bunchData[i]>candidate.fQMax){
+                 candidate.fQMax=bunchData[i];
+               }
+               
+               prevSignal=bunchData[i];
+               time++;
+               indexInBunchData--;
+             }
+             if(candidate.fTotalCharge>0){
+               candidate.fMean=candidate.fTime/candidate.fTotalCharge;
+               candidate.fPad=candidate.fTotalCharge*pad;
+               candidate.fPad2=candidate.fPad*pad;
+               candidate.fLastMergedPad=pad;
+               candidate.fRowNumber=row+fDigitReader->GetRowOffset();
+             }
+             fRowPadVector[row][pad]->AddClusterCandidate(candidate);
+             fRowPadVector[row][pad]->AddCandidateDigits(fMCDigits);
+             if(indexInBunchData<fDigitReader->GetBunchSize()-1){
+               moreDataInBunch=kFALSE;
+             }
+           }while(moreDataInBunch);
+         }
+         else{
+           const UInt_t *bunchData= fDigitReader->GetSignals();
+           do{
+             AliHLTTPCClusters candidate;
+             for(Int_t i=indexInBunchData;i<fDigitReader->GetBunchSize();i++){
+               // Checks if one need to deconvolute the signals
+               if(bunchData[i]>prevSignal && signalFalling==kTRUE){
+                 if(i<fDigitReader->GetBunchSize()-1){ // means there are more than one signal left in the bunch
+                   moreDataInBunch=kTRUE;
+                   prevSignal=0;
+                 }
+                 break;
+               }
+               
+               // Checks if the signal is 0, then quit processing the data.
+               if(bunchData[i]==0 && i<fDigitReader->GetBunchSize()-1){//means we have 0 data fom the rcu, might happen depending on the configuration settings
+                 moreDataInBunch=kTRUE;
+                 prevSignal=0;
+                 break;
+               }
+               
+               if(prevSignal>bunchData[i]){//means the peak of the signal has been reached and deconvolution will happen if the signal rise again.
+                 signalFalling=kTRUE;
+               }
+
+               candidate.fTotalCharge+=bunchData[i];   
+               candidate.fTime += time*bunchData[i];
+               candidate.fTime2 += time*time*bunchData[i];
+               if(bunchData[i]>candidate.fQMax){
+                 candidate.fQMax=bunchData[i];
+               }
+               
+               prevSignal=bunchData[i];
+               time++;
+               indexInBunchData++;
+             }
+             if(candidate.fTotalCharge>0){
+               candidate.fMean=candidate.fTime/candidate.fTotalCharge;
+               candidate.fPad=candidate.fTotalCharge*pad;
+               candidate.fPad2=candidate.fPad*pad;
+               candidate.fLastMergedPad=pad;
+               candidate.fRowNumber=row+fDigitReader->GetRowOffset();
+             }
+             fRowPadVector[row][pad]->AddClusterCandidate(candidate);
+             if(indexInBunchData<fDigitReader->GetBunchSize()-1){
+               moreDataInBunch=kFALSE;
+             }
+           }while(moreDataInBunch);
+         }
+       }
+      }
+    }
+  }
+}
+
+Bool_t AliHLTTPCClusterFinder::ComparePads(AliHLTTPCPad *nextPad,AliHLTTPCClusters* cluster,Int_t nextPadToRead){
+  // see header file for class documentation
+
+  //Checking if we have a match on the next pad
+  for(UInt_t candidateNumber=0;candidateNumber<nextPad->fClusterCandidates.size();candidateNumber++){
+    if(nextPad->fUsedClusterCandidates[candidateNumber] == 1){
+      continue;
+    }
+    AliHLTTPCClusters *candidate =&nextPad->fClusterCandidates[candidateNumber]; 
+    //    if(cluster->fMean-candidate->fMean==1 || candidate->fMean-cluster->fMean==1 || cluster->fMean-candidate->fMean==0){
+    
+    if( abs((Int_t)(cluster->fMean - candidate->fMean)) <= fTimeMeanDiff ){
+      if(fDeconvPad){
+       if(candidate->fTotalCharge<fTotalChargeOfPreviousClusterCandidate){//peak is reached
+         fChargeOfCandidatesFalling=kTRUE;
+       }
+       if(candidate->fTotalCharge>fTotalChargeOfPreviousClusterCandidate && fChargeOfCandidatesFalling==kTRUE){//we have deconvolution
+         return kFALSE;
+       }
+      }
+      cluster->fMean=candidate->fMean;
+      cluster->fTotalCharge+=candidate->fTotalCharge;
+      cluster->fTime += candidate->fTime;
+      cluster->fTime2 += candidate->fTime2;
+      cluster->fPad+=candidate->fPad;
+      cluster->fPad2+=candidate->fPad2;
+      cluster->fLastMergedPad=candidate->fPad;
+      if(candidate->fQMax>cluster->fQMax){
+       cluster->fQMax=candidate->fQMax;
+      }
+      if(fDoMC){
+       FillMCClusterVector(nextPad->GetCandidateDigits(candidateNumber));
+      }
+
+      if(fDoPadSelection){
+       UInt_t rowNo = nextPad->GetRowNumber();
+       UInt_t padNo = nextPad->GetPadNumber();
+       if(padNo-1>0){
+         fRowPadVector[rowNo][padNo-2]->fSelectedPad=kTRUE;
+         fRowPadVector[rowNo][padNo-2]->fHWAddress=(AliHLTUInt16_t)fDigitReader->GetAltroBlockHWaddr(rowNo,padNo-2);
+       }
+       fRowPadVector[rowNo][padNo-1]->fSelectedPad=kTRUE;// quick solution to set the first pad to selected
+       fRowPadVector[rowNo][padNo-1]->fHWAddress=(AliHLTUInt16_t)fDigitReader->GetAltroBlockHWaddr(rowNo,padNo-1);
+       fRowPadVector[rowNo][padNo]->fSelectedPad=kTRUE;
+       fRowPadVector[rowNo][padNo]->fHWAddress=(AliHLTUInt16_t)fDigitReader->GetAltroBlockHWaddr(rowNo,padNo);
+      }
+
+      //setting the matched pad to used
+      nextPad->fUsedClusterCandidates[candidateNumber]=1;
+      nextPadToRead++;
+      if(nextPadToRead<(Int_t)fNumberOfPadsInRow[fRowOfFirstCandidate]){
+       nextPad=fRowPadVector[fRowOfFirstCandidate][nextPadToRead];
+       ComparePads(nextPad,cluster,nextPadToRead);
+      }
+      else{
+       return kFALSE;
+      }
+    }
+  }
+  return kFALSE;
+}
+
+Int_t AliHLTTPCClusterFinder::FillHWAddressList(AliHLTUInt16_t *hwaddlist, Int_t maxHWadd){
+  // see header file for class documentation
+
+  Int_t counter=0;
+  for(UInt_t row=0;row<fNumberOfRows;row++){
+    for(UInt_t pad=0;pad<fNumberOfPadsInRow[row]-1;pad++){
+      if(fRowPadVector[row][pad]->fSelectedPad){
+       if(counter<maxHWadd){
+        hwaddlist[counter]=(AliHLTUInt16_t)fRowPadVector[row][pad]->fHWAddress;
+        counter++;
+       }
+       else{
+        HLTWarning("To many hardwareaddresses, skip adding");
+       }
+       
+      }
+    }
+  }  
+  return counter;
+}
+
+Int_t AliHLTTPCClusterFinder::FillOutputMCInfo(AliHLTTPCClusterFinder::ClusterMCInfo * outputMCInfo, Int_t maxNumberOfClusterMCInfo){
+  // see header file for class documentation
+  
+  Int_t counter=0;
+  for(UInt_t mc=0;mc<fClustersMCInfo.size();mc++){
+    if(counter<maxNumberOfClusterMCInfo){
+      outputMCInfo[counter] = fClustersMCInfo[mc];
+      counter++;
+    }
+    else{
+      HLTWarning("To much MCInfo has been added (no more space), skip adding");
+    }
+  }
+  return counter;
+}
+
+void AliHLTTPCClusterFinder::FindClusters(){
+  // see header file for function documentation
+
+  AliHLTTPCClusters* tmpCandidate=NULL;
+  for(UInt_t row=0;row<fNumberOfRows;row++){
+    fRowOfFirstCandidate=row;
+    for(UInt_t pad=0;pad<fNumberOfPadsInRow[row];pad++){
+      AliHLTTPCPad *tmpPad=fRowPadVector[row][pad];
+      for(size_t candidate=0;candidate<tmpPad->fClusterCandidates.size();candidate++){
+       if(tmpPad->fUsedClusterCandidates[candidate]){
+         continue;
+       }
+       tmpCandidate=&tmpPad->fClusterCandidates[candidate];
+       UInt_t tmpTotalCharge=tmpCandidate->fTotalCharge;
+
+       if(fDoMC){
+         fClusterMCVector.clear();
+         FillMCClusterVector(tmpPad->GetCandidateDigits(candidate));
+       }
+
+       ComparePads(fRowPadVector[row][pad+1],tmpCandidate,pad+1);
+       if(tmpCandidate->fTotalCharge>tmpTotalCharge){
+         //we have a cluster
+         fClusters.push_back(*tmpCandidate);
+         if(fDoMC){
+           //sort the vector (large->small) according to weight and remove elements above 2 (keep 0 1 and 2) 
+           sort(fClusterMCVector.begin(),fClusterMCVector.end(), MCWeight::CompareWeights );
+           ClusterMCInfo tmpClusterMCInfo;
+
+           MCWeight zeroMC;
+           zeroMC.fMCID=-1;
+           zeroMC.fWeight=0;
+
+           if(fClusterMCVector.size()>0){
+             tmpClusterMCInfo.fClusterID[0]=fClusterMCVector.at(0);
+           }
+           else{
+             tmpClusterMCInfo.fClusterID[0]=zeroMC;
+           }
+
+           if(fClusterMCVector.size()>1){
+           tmpClusterMCInfo.fClusterID[1]=fClusterMCVector.at(1);
+           }
+           else{
+             tmpClusterMCInfo.fClusterID[1]=zeroMC;
+           }
+
+           if(fClusterMCVector.size()>2){
+           tmpClusterMCInfo.fClusterID[2]=fClusterMCVector.at(2);
+           }
+           else{
+             tmpClusterMCInfo.fClusterID[2]=zeroMC;
+           }
+
+           fClustersMCInfo.push_back(tmpClusterMCInfo);
+         }
+         
+       }
+      }
+      tmpPad->ClearCandidates();
+    }
+    fRowPadVector[row][fNumberOfPadsInRow[row]]->ClearCandidates();
+  }
+
+  HLTInfo("Found %d clusters.",fClusters.size());
+
+  //TODO:  Change so it stores AliHLTTPCSpacePointData directly, instead of this copying
+  
+  AliClusterData * clusterlist = new AliClusterData[fClusters.size()]; //Clusterlist
+  for(unsigned int i=0;i<fClusters.size();i++){
+    clusterlist[i].fTotalCharge = fClusters[i].fTotalCharge;
+    clusterlist[i].fPad = fClusters[i].fPad;
+    clusterlist[i].fPad2 = fClusters[i].fPad2;
+    clusterlist[i].fTime = fClusters[i].fTime;
+    clusterlist[i].fTime2 = fClusters[i].fTime2;
+    clusterlist[i].fMean = fClusters[i].fMean;
+    clusterlist[i].fFlags = fClusters[i].fFlags;
+    clusterlist[i].fChargeFalling = fClusters[i].fChargeFalling;
+    clusterlist[i].fLastCharge = fClusters[i].fLastCharge;
+    clusterlist[i].fLastMergedPad = fClusters[i].fLastMergedPad;
+    clusterlist[i].fRow = fClusters[i].fRowNumber;
+    clusterlist[i].fQMax = fClusters[i].fQMax;
+  }
+
+  WriteClusters(fClusters.size(),clusterlist);
+  delete [] clusterlist;
+  fClusters.clear();
+  if( fReleaseMemory ) DeInitializePadArray();// call this when  the -releaseMemory flag is set
+}
+
+
+Bool_t AliHLTTPCClusterFinder::UpdateCalibDB(){
+  
+  //update the db
+  AliTPCcalibDB::Instance()->Update();
+
+  Bool_t ret = 1;
+
+  //uptate the transform class
+
+  fOfflineTransform = AliTPCcalibDB::Instance()->GetTransform(); 
+  if(!fOfflineTransform){
+    HLTError("AliHLTTPCClusterFinder()::UpdateCAlibDB::  Offline transform not in AliTPCcalibDB.");
+    ret = 0;
+  }
+  else{
+    fOfflineTransform->SetCurrentRecoParam(&fOfflineTPCRecoParam);
+  }
+
+  fOfflineTPCParam = AliTPCcalibDB::Instance()->GetParameters();
+  if( !fOfflineTPCParam ){
+    HLTError("AliHLTTPCClusterFinder()::UpdateCAlibDB::  Offline TPC parameters not in AliTPCcalibDB.");
+    ret = 0;
+  } else {
+    fOfflineTPCParam->Update();
+    fOfflineTPCParam->ReadGeoMatrices();
+  }    
+
+  return ret;
+}
+
+//---------------------------------- Under this line the old sorted clusterfinder functions can be found --------------------------------
+
+
+void AliHLTTPCClusterFinder::PrintClusters(){
+  // see header file for class documentation
+
+  for(size_t i=0;i<fClusters.size();i++){
+    HLTInfo("Cluster number: %d",i);
+    HLTInfo("Row: %d \t Pad: %d",fClusters[i].fRowNumber,fClusters[i].fPad/fClusters[i].fTotalCharge);
+    HLTInfo("Total Charge:   %d",fClusters[i].fTotalCharge);
+    HLTInfo("fPad:           %d",fClusters[i].fPad);
+    HLTInfo("PadError:       %d",fClusters[i].fPad2);
+    HLTInfo("TimeMean:       %d",fClusters[i].fTime/fClusters[i].fTotalCharge);
+    HLTInfo("TimeError:      %d",fClusters[i].fTime2);
+    HLTInfo("EndOfCluster:");
+  }
+}
+
+void AliHLTTPCClusterFinder::FillMCClusterVector(vector<AliHLTTPCDigitData> digitData){
+  // see header file for class documentation
+
+  for(UInt_t d=0;d<digitData.size();d++){
+    Int_t nIDsInDigit = (digitData.at(d).fTrackID[0]>=0) + (digitData.at(d).fTrackID[1]>=0) + (digitData.at(d).fTrackID[2]>=0);
+    for(Int_t id=0; id<3; id++){
+      if(digitData.at(d).fTrackID[id]>=0){
+       Bool_t matchFound = kFALSE;
+       MCWeight mc;
+       mc.fMCID = digitData.at(d).fTrackID[id];
+       mc.fWeight = ((Float_t)digitData.at(d).fCharge)/nIDsInDigit;
+       for(UInt_t i=0;i<fClusterMCVector.size();i++){
+         if(mc.fMCID == fClusterMCVector.at(i).fMCID){
+           fClusterMCVector.at(i).fWeight += mc.fWeight;
+           matchFound = kTRUE;
+         }
+       }
+       if(matchFound == kFALSE){
+         fClusterMCVector.push_back(mc);
+       }
+      }
+    }
+  }
+}
+
+
 void AliHLTTPCClusterFinder::Read(void* ptr,unsigned long size){
   //set input pointer
   fPtr = (UChar_t*)ptr;
   fSize = size;
 }
 
-void AliHLTTPCClusterFinder::ProcessDigits()
-{
+void AliHLTTPCClusterFinder::ProcessDigits(){
+  // see header file for class documentation
+
   int iResult=0;
   bool readValue = true;
   Int_t newRow = 0;    
@@ -524,8 +1075,9 @@ void AliHLTTPCClusterFinder::ProcessDigits()
 
 } // ENDEND
 
-void AliHLTTPCClusterFinder::WriteClusters(Int_t nclusters,AliClusterData *list)
-{
+void AliHLTTPCClusterFinder::WriteClusters(Int_t nclusters,AliClusterData *list){
+  // see header file for class documentation
+
   //write cluster to output pointer
   Int_t thisrow=-1,thissector=-1;
   UInt_t counter = fNClusters;
@@ -535,9 +1087,22 @@ void AliHLTTPCClusterFinder::WriteClusters(Int_t nclusters,AliClusterData *list)
 
 
 
-      if(!list[j].fFlags) continue; //discard single pad clusters
-      if(list[j].fTotalCharge < fThreshold) continue; //noise cluster
-
+      if(!list[j].fFlags){
+       if(fDoMC){
+         if(j+(Int_t)fClustersMCInfo.size()-nclusters >=0 && j+fClustersMCInfo.size()-nclusters < fClustersMCInfo.size()){
+           fClustersMCInfo.erase(fClustersMCInfo.begin()+j+fClustersMCInfo.size()-nclusters); // remove the mc info for this cluster since it is not taken into account 
+         }
+       }
+       continue; //discard single pad clusters
+      }
+      if(list[j].fTotalCharge < fThreshold){
+       if(fDoMC){
+         if(j+(Int_t)fClustersMCInfo.size()-nclusters >=0 && j+fClustersMCInfo.size()-nclusters < fClustersMCInfo.size()){
+           fClustersMCInfo.erase(fClustersMCInfo.begin()+j+fClustersMCInfo.size()-nclusters); // remove the mc info for this cluster since it is not taken into account 
+         }
+       }
+       continue; //noise cluster
+      }
       Float_t xyz[3];      
       Float_t fpad =(Float_t)list[j].fPad / list[j].fTotalCharge;
       Float_t fpad2=fXYErr*fXYErr; //fixed given error
@@ -554,7 +1119,8 @@ void AliHLTTPCClusterFinder::WriteClusters(Int_t nclusters,AliClusterData *list)
       if(fCalcerr) { //calc the errors, otherwice take the fixed error 
        Int_t patch = AliHLTTPCTransform::GetPatch(fCurrentRow);
        UInt_t q2=list[j].fTotalCharge*list[j].fTotalCharge;
-       Float_t sy2=list[j].fPad2 * list[j].fTotalCharge - list[j].fPad * list[j].fPad;
+       //      Float_t sy2=list[j].fPad2 * list[j].fTotalCharge - list[j].fPad * list[j].fPad;
+       Float_t sy2=(Float_t)list[j].fPad2 * list[j].fTotalCharge - (Float_t)list[j].fPad * list[j].fPad;
        sy2/=q2;
        if(sy2 < 0) {
            LOG(AliHLTTPCLog::kError,"AliHLTTPCClusterFinder::WriteClusters","Cluster width")
@@ -570,7 +1136,8 @@ void AliHLTTPCClusterFinder::WriteClusters(Int_t nclusters,AliClusterData *list)
            }
          } else fpad2=sy2; //take the width not the error
        }
-       Float_t sz2=list[j].fTime2*list[j].fTotalCharge - list[j].fTime*list[j].fTime;
+       //      Float_t sz2=list[j].fTime2*list[j].fTotalCharge - list[j].fTime*list[j].fTime;
+       Float_t sz2=(Float_t)list[j].fTime2*list[j].fTotalCharge - (Float_t)list[j].fTime*list[j].fTime;
        sz2/=q2;
        if(sz2 < 0){
          LOG(AliHLTTPCLog::kError,"AliHLTTPCClusterFinder::WriteClusters","Cluster width")
@@ -592,28 +1159,47 @@ void AliHLTTPCClusterFinder::WriteClusters(Int_t nclusters,AliClusterData *list)
       
       if(!fRawSP){
        AliHLTTPCTransform::Slice2Sector(fCurrentSlice,fCurrentRow,thissector,thisrow);
-       AliHLTTPCTransform::Raw2Local(xyz,thissector,thisrow,fpad,ftime);
-       
-       if(xyz[0]==0) LOG(AliHLTTPCLog::kError,"AliHLTTPCClustFinder","Cluster Finder")
-         <<AliHLTTPCLog::kDec<<"Zero cluster"<<ENDLOG;
-       if(fNClusters >= fMaxNClusters)
-         {
-           LOG(AliHLTTPCLog::kError,"AliHLTTPCClustFinder::WriteClusters","Cluster Finder")
-             <<AliHLTTPCLog::kDec<<"Too many clusters "<<fNClusters<<ENDLOG;
-           return;
-         }  
+
+       if(fOfflineTransform == NULL){
+         AliHLTTPCTransform::Raw2Local(xyz,thissector,thisrow,fpad,ftime);
+         
+         if(xyz[0]==0) LOG(AliHLTTPCLog::kError,"AliHLTTPCClustFinder","Cluster Finder")
+                         <<AliHLTTPCLog::kDec<<"Zero cluster"<<ENDLOG;
+         if(fNClusters >= fMaxNClusters)
+           {
+             LOG(AliHLTTPCLog::kError,"AliHLTTPCClustFinder::WriteClusters","Cluster Finder")
+               <<AliHLTTPCLog::kDec<<"Too many clusters "<<fNClusters<<ENDLOG;
+             return;
+           }  
        
-       fSpacePointData[counter].fX = xyz[0];
-       //      fSpacePointData[counter].fY = xyz[1];
-       if(fCurrentSlice<18){
-         fSpacePointData[counter].fY = xyz[1];
+         fSpacePointData[counter].fX = xyz[0];
+         //    fSpacePointData[counter].fY = xyz[1];
+         if(fCurrentSlice<18){
+           fSpacePointData[counter].fY = xyz[1];
+         }
+         else{
+           fSpacePointData[counter].fY = -1*xyz[1];
+         }
+         fSpacePointData[counter].fZ = xyz[2];
        }
        else{
-         fSpacePointData[counter].fY = -1*xyz[1];
+         Double_t x[3]={thisrow,fpad+.5,ftime}; 
+         Int_t iSector[1]={thissector};
+         fOfflineTransform->Transform(x,iSector,0,1);
+         double y[3] = {x[0], x[1], x[2] };      
+         
+         if( fOfflineTPCParam && thissector<fOfflineTPCParam->GetNSector() ){
+           TGeoHMatrix  *alignment = fOfflineTPCParam->GetClusterMatrix( thissector );
+           if ( alignment ) alignment->LocalToMaster( x, y);
+         }       
+
+         fSpacePointData[counter].fX = y[0];
+         fSpacePointData[counter].fY = y[1];
+         fSpacePointData[counter].fZ = y[2];
        }
-       fSpacePointData[counter].fZ = xyz[2];
 
-      } else {
+      } 
+      else {
        fSpacePointData[counter].fX = fCurrentRow;
        fSpacePointData[counter].fY = fpad;
        fSpacePointData[counter].fZ = ftime;
@@ -624,7 +1210,7 @@ void AliHLTTPCClusterFinder::WriteClusters(Int_t nclusters,AliClusterData *list)
       fSpacePointData[counter].fSigmaY2 = fpad2;
       fSpacePointData[counter].fSigmaZ2  = ftime2;
 
-      fSpacePointData[counter].fMaxQ = list[j].fQMax;
+      fSpacePointData[counter].fQMax = list[j].fQMax;
 
       fSpacePointData[counter].fUsed = kFALSE;         // only used / set in AliHLTTPCDisplay
       fSpacePointData[counter].fTrackN = -1;           // only used / set in AliHLTTPCDisplay
@@ -652,8 +1238,9 @@ void AliHLTTPCClusterFinder::WriteClusters(Int_t nclusters,AliClusterData *list)
 // STILL TO FIX  ----------------------------------------------------------------------------
 
 #ifdef do_mc
-void AliHLTTPCClusterFinder::GetTrackID(Int_t pad,Int_t time,Int_t *trackID)
-{
+void AliHLTTPCClusterFinder::GetTrackID(Int_t pad,Int_t time,Int_t *trackID) const {
+  // see header file for class documentation
+
   //get mc id
   AliHLTTPCDigitRowData *rowPt = (AliHLTTPCDigitRowData*)fDigitRowData;
   
@@ -681,271 +1268,11 @@ void AliHLTTPCClusterFinder::GetTrackID(Int_t pad,Int_t time,Int_t *trackID)
 }
 #endif
 
-//----------------------------------Methods for the new unsorted way of reading the data --------------------------------
-
-void AliHLTTPCClusterFinder::ReadDataUnsorted(void* ptr,unsigned long size)
-{
-  //set input pointer
-  fPtr = (UChar_t*)ptr;
-  fSize = size;
-
-  if(!fVectorInitialized){
-    InitializePadArray();
-  }
-
-  fDigitReader->InitBlock(fPtr,fSize,fFirstRow,fLastRow,fCurrentPatch,fCurrentSlice);
-  
-  while(fDigitReader->NextChannel()){
-    UInt_t row=fDigitReader->GetRow();
-    UInt_t pad=fDigitReader->GetPad();
-
-    while(fDigitReader->NextBunch()){
-      if(fDigitReader->GetBunchSize()>1){//to remove single timebin values, this will have to change at some point
-       UInt_t time = fDigitReader->GetTime();
-       if((Int_t)time>=fFirstTimeBin && (Int_t)time+fDigitReader->GetBunchSize()<=fLastTimeBin){
-         const UInt_t *bunchData= fDigitReader->GetSignals();
-         AliHLTTPCClusters candidate;
-         for(Int_t i=0;i<fDigitReader->GetBunchSize();i++){
-           candidate.fTotalCharge+=bunchData[i];       
-           candidate.fTime += time*bunchData[i];
-           candidate.fTime2 += time*time*bunchData[i];
-           if(bunchData[i]>candidate.fQMax){
-             candidate.fQMax=bunchData[i];
-           }
-           time++;
-         }
-         if(candidate.fTotalCharge>0){
-           candidate.fMean=candidate.fTime/candidate.fTotalCharge;
-           candidate.fPad=candidate.fTotalCharge*pad;
-           candidate.fPad2=candidate.fPad*pad;
-           candidate.fLastMergedPad=pad;
-           candidate.fRowNumber=row+fDigitReader->GetRowOffset();
-         }
-         fRowPadVector[row][pad]->AddClusterCandidate(candidate);
-       }
-      }
-    }
-  }
-}
-
-void AliHLTTPCClusterFinder::ReadDataUnsortedDeconvoluteTime(void* ptr,unsigned long size)
-{
-  //set input pointer
-  fPtr = (UChar_t*)ptr;
-  fSize = size;
-
-  if(!fVectorInitialized){
-    InitializePadArray();
-  }
-
-  fDigitReader->InitBlock(fPtr,fSize,fFirstRow,fLastRow,fCurrentPatch,fCurrentSlice);
-  
-  while(fDigitReader->NextChannel()){
-    UInt_t row=fDigitReader->GetRow();
-    UInt_t pad=fDigitReader->GetPad();
-
-    while(fDigitReader->NextBunch()){
-      if(fDigitReader->GetBunchSize()>1){//to remove single timebin values, this will have to change at some point
-       UInt_t time = fDigitReader->GetTime();
-       if((Int_t)time>=fFirstTimeBin && (Int_t)time+fDigitReader->GetBunchSize()<=fLastTimeBin){
-         Int_t indexInBunchData=0;
-         Bool_t moreDataInBunch=kFALSE;
-         UInt_t prevSignal=0;
-         Bool_t signalFalling=kFALSE;
-         const UInt_t *bunchData= fDigitReader->GetSignals();
-         do{
-           AliHLTTPCClusters candidate;
-           for(Int_t i=indexInBunchData;i<fDigitReader->GetBunchSize();i++){
-             // Checks if one need to deconvolute the signals
-             if(bunchData[i]>prevSignal && signalFalling==kTRUE){
-               if(i<fDigitReader->GetBunchSize()-1){ // means there are more than one signal left in the bunch
-                 moreDataInBunch=kTRUE;
-                 prevSignal=0;
-               }
-               break;
-             }
-             
-             // Checks if the signal is 0, then quit processing the data.
-             if(bunchData[i]==0 && i<fDigitReader->GetBunchSize()-1){//means we have 0 data fom the rcu, might happen depending on the configuration settings
-               moreDataInBunch=kTRUE;
-               prevSignal=0;
-               break;
-             }
-
-             if(prevSignal>bunchData[i]){//means the peak of the signal has been reached and deconvolution will happen if the signal rise again.
-               signalFalling=kTRUE;
-             }
-             candidate.fTotalCharge+=bunchData[i];     
-             candidate.fTime += time*bunchData[i];
-             candidate.fTime2 += time*time*bunchData[i];
-             if(bunchData[i]>candidate.fQMax){
-               candidate.fQMax=bunchData[i];
-             }
-
-             prevSignal=bunchData[i];
-             time++;
-             indexInBunchData++;
-           }
-           if(candidate.fTotalCharge>0){
-             candidate.fMean=candidate.fTime/candidate.fTotalCharge;
-             candidate.fPad=candidate.fTotalCharge*pad;
-             candidate.fPad2=candidate.fPad*pad;
-             candidate.fLastMergedPad=pad;
-             candidate.fRowNumber=row+fDigitReader->GetRowOffset();
-           }
-           fRowPadVector[row][pad]->AddClusterCandidate(candidate);
-           if(indexInBunchData<fDigitReader->GetBunchSize()-1){
-             moreDataInBunch=kFALSE;
-           }
-         }while(moreDataInBunch);
-       }
-      }
-    }
-  }
-}
-
-Bool_t AliHLTTPCClusterFinder::ComparePads(AliHLTTPCPad *nextPad,AliHLTTPCClusters* cluster,Int_t nextPadToRead){
-  //Checking if we have a match on the next pad
-  for(UInt_t candidateNumber=0;candidateNumber<nextPad->fClusterCandidates.size();candidateNumber++){
-    AliHLTTPCClusters *candidate =&nextPad->fClusterCandidates[candidateNumber]; 
-    if(cluster->fMean-candidate->fMean==1 || candidate->fMean-cluster->fMean==1 || cluster->fMean-candidate->fMean==0){
-      if(fDeconvPad){
-       if(candidate->fTotalCharge<fTotalChargeOfPreviousClusterCandidate){//peak is reached
-         fChargeOfCandidatesFalling=kTRUE;
-       }
-       if(candidate->fTotalCharge>fTotalChargeOfPreviousClusterCandidate && fChargeOfCandidatesFalling==kTRUE){//we have deconvolution
-         return kFALSE;
-       }
-      }
-      cluster->fMean=candidate->fMean;
-      cluster->fTotalCharge+=candidate->fTotalCharge;
-      cluster->fTime += candidate->fTime;
-      cluster->fTime2 += candidate->fTime2;
-      cluster->fPad+=candidate->fPad;
-      cluster->fPad2=candidate->fPad2;
-      cluster->fLastMergedPad=candidate->fPad;
-      if(candidate->fQMax>cluster->fQMax){
-       cluster->fQMax=candidate->fQMax;
-      }
-      
-      if(fDoPadSelection){
-       UInt_t rowNo = nextPad->GetRowNumber();
-       UInt_t padNo = nextPad->GetPadNumber();
-       if(padNo-1>0){
-         fRowPadVector[rowNo][padNo-2]->fSelectedPad=kTRUE;
-         fRowPadVector[rowNo][padNo-2]->fHWAddress=(AliHLTUInt16_t)fDigitReader->GetAltroBlockHWaddr(rowNo,padNo-2);
-       }
-       fRowPadVector[rowNo][padNo-1]->fSelectedPad=kTRUE;// quick solution to set the first pad to selected
-       fRowPadVector[rowNo][padNo-1]->fHWAddress=(AliHLTUInt16_t)fDigitReader->GetAltroBlockHWaddr(rowNo,padNo-1);
-       fRowPadVector[rowNo][padNo]->fSelectedPad=kTRUE;
-       fRowPadVector[rowNo][padNo]->fHWAddress=(AliHLTUInt16_t)fDigitReader->GetAltroBlockHWaddr(rowNo,padNo);
-      }
-
-      //setting the matched pad to used
-      nextPad->fUsedClusterCandidates[candidateNumber]=1;
-      nextPadToRead++;
-      if(nextPadToRead<(Int_t)fNumberOfPadsInRow[fRowOfFirstCandidate]){
-       nextPad=fRowPadVector[fRowOfFirstCandidate][nextPadToRead];
-       ComparePads(nextPad,cluster,nextPadToRead);
-      }
-      else{
-       return kFALSE;
-      }
-    }
-    else{
-      return kFALSE;
-    }
-  }
-  return kFALSE;
-}
-
-Int_t AliHLTTPCClusterFinder::FillHWAddressList(AliHLTUInt16_t *hwaddlist, Int_t maxHWadd){
-  Int_t counter=0;
-  for(UInt_t row=0;row<fNumberOfRows;row++){
-    for(UInt_t pad=0;pad<fNumberOfPadsInRow[row]-1;pad++){
-      if(fRowPadVector[row][pad]->fSelectedPad){
-       if(counter<maxHWadd){
-        hwaddlist[counter]=(AliHLTUInt16_t)fRowPadVector[row][pad]->fHWAddress;
-        counter++;
-       }
-       else{
-        HLTWarning("To many hardwareaddresses, skip adding");
-       }
-       
-      }
-    }
-  }  
-  return counter;
-}
-
-void AliHLTTPCClusterFinder::FindClusters()
-{
-  // see header file for function documentation
-
-  AliHLTTPCClusters* tmpCandidate=NULL;
-  for(UInt_t row=0;row<fNumberOfRows;row++){
-    fRowOfFirstCandidate=row;
-    for(UInt_t pad=0;pad<fNumberOfPadsInRow[row];pad++){
-      AliHLTTPCPad *tmpPad=fRowPadVector[row][pad];
-      for(size_t candidate=0;candidate<tmpPad->fClusterCandidates.size();candidate++){
-       if(tmpPad->fUsedClusterCandidates[candidate]){
-         continue;
-       }
-       tmpCandidate=&tmpPad->fClusterCandidates[candidate];
-       UInt_t tmpTotalCharge=tmpCandidate->fTotalCharge;
-
-       ComparePads(fRowPadVector[row][pad+1],tmpCandidate,pad+1);
-       if(tmpCandidate->fTotalCharge>tmpTotalCharge){
-         //we have a cluster
-         fClusters.push_back(*tmpCandidate);
-       }
-      }
-      tmpPad->ClearCandidates();
-    }
-    fRowPadVector[row][fNumberOfPadsInRow[row]]->ClearCandidates();
-  }
-
-  HLTInfo("Found %d clusters.",fClusters.size());
 
-  //TODO:  Change so it stores AliHLTTPCSpacePointData directly, instead of this copying
-  
-  AliClusterData * clusterlist = new AliClusterData[fClusters.size()]; //Clusterlist
-  for(unsigned int i=0;i<fClusters.size();i++){
-    clusterlist[i].fTotalCharge = fClusters[i].fTotalCharge;
-    clusterlist[i].fPad = fClusters[i].fPad;
-    clusterlist[i].fPad2 = fClusters[i].fPad2;
-    clusterlist[i].fTime = fClusters[i].fTime;
-    clusterlist[i].fTime2 = fClusters[i].fTime2;
-    clusterlist[i].fMean = fClusters[i].fMean;
-    clusterlist[i].fFlags = fClusters[i].fFlags;
-    clusterlist[i].fChargeFalling = fClusters[i].fChargeFalling;
-    clusterlist[i].fLastCharge = fClusters[i].fLastCharge;
-    clusterlist[i].fLastMergedPad = fClusters[i].fLastMergedPad;
-    clusterlist[i].fRow = fClusters[i].fRowNumber;
-  }
-  //  PrintClusters();
-  WriteClusters(fClusters.size(),clusterlist);
-  delete [] clusterlist;
-  fClusters.clear();
-}
 
-void AliHLTTPCClusterFinder::PrintClusters()
-{
+void AliHLTTPCClusterFinder::WriteClusters(Int_t nclusters,AliHLTTPCClusters *list){//This is used when using the AliHLTTPCClusters class for cluster data
   // see header file for class documentation
-  for(size_t i=0;i<fClusters.size();i++){
-    HLTInfo("Cluster number: %d",i);
-    HLTInfo("Row: %d \t Pad: %d",fClusters[i].fRowNumber,fClusters[i].fPad/fClusters[i].fTotalCharge);
-    HLTInfo("Total Charge:   %d",fClusters[i].fTotalCharge);
-    HLTInfo("fPad:           %d",fClusters[i].fPad);
-    HLTInfo("PadError:       %d",fClusters[i].fPad2);
-    HLTInfo("TimeMean:       %d",fClusters[i].fTime/fClusters[i].fTotalCharge);
-    HLTInfo("TimeError:      %d",fClusters[i].fTime2);
-    HLTInfo("EndOfCluster:");
-  }
-}
 
-void AliHLTTPCClusterFinder::WriteClusters(Int_t nclusters,AliHLTTPCClusters *list)//This is used when using the AliHLTTPCClusters class for cluster data
-{
   //write cluster to output pointer
   Int_t thisrow,thissector;
   UInt_t counter = fNClusters;
@@ -1035,7 +1362,7 @@ void AliHLTTPCClusterFinder::WriteClusters(Int_t nclusters,AliHLTTPCClusters *li
       fSpacePointData[counter].fSigmaY2 = fpad2;
       fSpacePointData[counter].fSigmaZ2  = ftime2;
 
-      fSpacePointData[counter].fMaxQ = list[j].fQMax;
+      fSpacePointData[counter].fQMax = list[j].fQMax;
 
       fSpacePointData[counter].fUsed = kFALSE;         // only used / set in AliHLTTPCDisplay
       fSpacePointData[counter].fTrackN = -1;           // only used / set in AliHLTTPCDisplay