]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - HLT/TPCLib/AliHLTTPCClusterFinder.cxx
code cleanup, removing unused functionality; fully implemented in the AliHLTTPCDataCo...
[u/mrichter/AliRoot.git] / HLT / TPCLib / AliHLTTPCClusterFinder.cxx
index 934cea9fd0868ef4f5f7b452186a821eb4bbaa5f..d582f80682239d42f93aededa1c92d254dd78066 100644 (file)
@@ -1,5 +1,4 @@
-// @(#) $Id$
-// Original: AliHLTClustFinderNew.cxx,v 1.29 2005/06/14 10:55:21 cvetan Exp 
+// $Id$
 
 //**************************************************************************
 //* This file is property of and copyright by the ALICE HLT Project        * 
 //* 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 "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;
@@ -53,7 +54,7 @@ AliHLTTPCClusterFinder::AliHLTTPCClusterFinder()
   fDeconvPad(kFALSE),
   fStdout(kFALSE),
   fCalcerr(kTRUE),
-  fRawSP(kFALSE),
+  fFillRawClusters(kFALSE),
   fFirstRow(0),
   fLastRow(0),
   fCurrentRow(0),
@@ -71,6 +72,7 @@ AliHLTTPCClusterFinder::AliHLTTPCClusterFinder()
   fClusters(),
   fClustersMCInfo(),
   fMCDigits(),
+  fRawClusters(),
   fNumberOfPadsInRow(NULL),
   fNumberOfRows(0),
   fRowOfFirstCandidate(0),
@@ -81,9 +83,33 @@ AliHLTTPCClusterFinder::AliHLTTPCClusterFinder()
   fChargeOfCandidatesFalling(kFALSE),
   f32BitFormat(kFALSE),
   fDoMC(kFALSE),
-  fClusterMCVector()
+  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(){
@@ -114,6 +140,7 @@ void AliHLTTPCClusterFinder::InitSlice(Int_t slice,Int_t patch,Int_t nmaxpoints)
   fClustersMCInfo.clear();
   fMCDigits.clear();
   fClusterMCVector.clear();   
+  fRawClusters.clear();
 }
 
 void AliHLTTPCClusterFinder::InitializePadArray(){
@@ -134,6 +161,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;
@@ -150,17 +179,21 @@ void AliHLTTPCClusterFinder::InitializePadArray(){
 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::SetOutputArray(AliHLTTPCSpacePointData *pt){
@@ -311,12 +344,14 @@ void AliHLTTPCClusterFinder::ReadDataUnsortedDeconvoluteTime(void* ptr,unsigned
          // The same is true for the function ReadDataUnsorted() above.
          // In addition the signals are organized in the opposite direction
          if(f32BitFormat){
-           indexInBunchData = fDigitReader->GetBunchSize();
+           indexInBunchData = fDigitReader->GetBunchSize()-1;
            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
@@ -342,7 +377,6 @@ void AliHLTTPCClusterFinder::ReadDataUnsortedDeconvoluteTime(void* ptr,unsigned
                if(bunchData[i]>candidate.fQMax){
                  candidate.fQMax=bunchData[i];
                }
-               
                prevSignal=bunchData[i];
                time++;
                indexInBunchData--;
@@ -354,8 +388,7 @@ void AliHLTTPCClusterFinder::ReadDataUnsortedDeconvoluteTime(void* ptr,unsigned
                candidate.fLastMergedPad=pad;
                candidate.fRowNumber=row+fDigitReader->GetRowOffset();
              }
-             fRowPadVector[row][pad]->AddClusterCandidate(candidate);
-             fRowPadVector[row][pad]->AddCandidateDigits(fMCDigits);
+             fRowPadVector[row][pad]->AddClusterCandidate(candidate);        
              if(indexInBunchData<fDigitReader->GetBunchSize()-1){
                moreDataInBunch=kFALSE;
              }
@@ -365,6 +398,9 @@ void AliHLTTPCClusterFinder::ReadDataUnsortedDeconvoluteTime(void* ptr,unsigned
            const UInt_t *bunchData= fDigitReader->GetSignals();
            do{
              AliHLTTPCClusters candidate;
+             const AliHLTTPCDigitData* digits = fDigitReader->GetBunchDigits();
+             if(fDoMC) fMCDigits.clear();            
+
              for(Int_t i=indexInBunchData;i<fDigitReader->GetBunchSize();i++){
                // Checks if one need to deconvolute the signals
                if(bunchData[i]>prevSignal && signalFalling==kTRUE){
@@ -391,6 +427,7 @@ void AliHLTTPCClusterFinder::ReadDataUnsortedDeconvoluteTime(void* ptr,unsigned
                if(bunchData[i]>candidate.fQMax){
                  candidate.fQMax=bunchData[i];
                }
+               if( fDoMC ) fMCDigits.push_back(digits[i]);
                
                prevSignal=bunchData[i];
                time++;
@@ -404,6 +441,10 @@ void AliHLTTPCClusterFinder::ReadDataUnsortedDeconvoluteTime(void* ptr,unsigned
                candidate.fRowNumber=row+fDigitReader->GetRowOffset();
              }
              fRowPadVector[row][pad]->AddClusterCandidate(candidate);
+             if(fDoMC){
+               fRowPadVector[row][pad]->AddCandidateDigits(fMCDigits);
+               fMCDigits.clear();
+             }
              if(indexInBunchData<fDigitReader->GetBunchSize()-1){
                moreDataInBunch=kFALSE;
              }
@@ -420,8 +461,13 @@ Bool_t AliHLTTPCClusterFinder::ComparePads(AliHLTTPCPad *nextPad,AliHLTTPCCluste
 
   //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(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;
@@ -468,9 +514,6 @@ Bool_t AliHLTTPCClusterFinder::ComparePads(AliHLTTPCPad *nextPad,AliHLTTPCCluste
        return kFALSE;
       }
     }
-    else{
-      return kFALSE;
-    }
   }
   return kFALSE;
 }
@@ -497,7 +540,7 @@ Int_t AliHLTTPCClusterFinder::FillHWAddressList(AliHLTUInt16_t *hwaddlist, Int_t
 }
  
 
-Int_t AliHLTTPCClusterFinder::FillOutputMCInfo(AliHLTTPCClusterFinder::ClusterMCInfo * outputMCInfo, Int_t maxNumberOfClusterMCInfo){
+Int_t AliHLTTPCClusterFinder::FillOutputMCInfo(AliHLTTPCClusterMCLabel * outputMCInfo, Int_t maxNumberOfClusterMCInfo){
   // see header file for class documentation
   
   Int_t counter=0;
@@ -514,6 +557,17 @@ Int_t AliHLTTPCClusterFinder::FillOutputMCInfo(AliHLTTPCClusterFinder::ClusterMC
   return counter;
 }
 
+Int_t AliHLTTPCClusterFinder::FillOutputRaw(AliHLTTPCRawCluster* rawClusters, unsigned sizeInByte) const
+{
+  // fill the raw clusters
+  if (fRawClusters.size()*sizeof(AliHLTTPCRawCluster)>sizeInByte) {
+    HLTError("not enough space to write raw clusters");
+    return 0;
+  }
+  memcpy(rawClusters, &fRawClusters[0], fRawClusters.size()*sizeof(AliHLTTPCRawCluster));
+  return fRawClusters.size();
+}
+
 void AliHLTTPCClusterFinder::FindClusters(){
   // see header file for function documentation
 
@@ -540,10 +594,10 @@ void AliHLTTPCClusterFinder::FindClusters(){
          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;
+           sort(fClusterMCVector.begin(),fClusterMCVector.end(), CompareWeights );
+           AliHLTTPCClusterMCLabel tmpClusterMCInfo;
 
-           MCWeight zeroMC;
+           AliHLTTPCClusterMCWeight zeroMC;
            zeroMC.fMCID=-1;
            zeroMC.fWeight=0;
 
@@ -601,9 +655,40 @@ void AliHLTTPCClusterFinder::FindClusters(){
   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 --------------------------------
 
 
@@ -622,16 +707,17 @@ void AliHLTTPCClusterFinder::PrintClusters(){
   }
 }
 
-void AliHLTTPCClusterFinder::FillMCClusterVector(vector<AliHLTTPCDigitData> digitData){
-
-  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);
+void AliHLTTPCClusterFinder::FillMCClusterVector(vector<AliHLTTPCDigitData> *digitData){
+  // see header file for class documentation
+  if( !digitData ) return;
+  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){
+      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;
+       AliHLTTPCClusterMCWeight 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;
@@ -1012,6 +1098,10 @@ void AliHLTTPCClusterFinder::WriteClusters(Int_t nclusters,AliClusterData *list)
   Int_t thisrow=-1,thissector=-1;
   UInt_t counter = fNClusters;
   
+  if (fFillRawClusters) {
+    fRawClusters.resize(nclusters);
+  }
+
   for(int j=0; j<nclusters; j++)
     {
 
@@ -1019,13 +1109,17 @@ void AliHLTTPCClusterFinder::WriteClusters(Int_t nclusters,AliClusterData *list)
 
       if(!list[j].fFlags){
        if(fDoMC){
-         fClustersMCInfo.erase(fClustersMCInfo.begin()+j); // remove the mc ifo for this cluster since it is not taken into account 
+         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){
-         fClustersMCInfo.erase(fClustersMCInfo.begin()+j); // remove the mc ifo for this cluster since it is not taken into account 
+         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
       }
@@ -1047,20 +1141,25 @@ void AliHLTTPCClusterFinder::WriteClusters(Int_t nclusters,AliClusterData *list)
        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=(Float_t)list[j].fPad2 * list[j].fTotalCharge - (Float_t)list[j].fPad * list[j].fPad;
+       if(q2 == 0) {
+         LOG(AliHLTTPCLog::kError,"AliHLTTPCClusterFinder::WriteClusters","Cluster width")
+           <<"zero charge "<< list[j].fTotalCharge <<" on row "<<fCurrentRow<<" "<<fpad<<" "<<ftime<<ENDLOG;
+         continue;
+       }
        sy2/=q2;
        if(sy2 < 0) {
            LOG(AliHLTTPCLog::kError,"AliHLTTPCClusterFinder::WriteClusters","Cluster width")
              <<"SigmaY2 negative "<<sy2<<" on row "<<fCurrentRow<<" "<<fpad<<" "<<ftime<<ENDLOG;
            continue;
        } else {
-         if(!fRawSP){
+         {
            fpad2 = (sy2 + 1./12)*AliHLTTPCTransform::GetPadPitchWidth(patch)*AliHLTTPCTransform::GetPadPitchWidth(patch);
            if(sy2 != 0){
              fpad2*=0.108; //constants are from offline studies
              if(patch<2)
                fpad2*=2.07;
            }
-         } 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=(Float_t)list[j].fTime2*list[j].fTotalCharge - (Float_t)list[j].fTime*list[j].fTime;
@@ -1070,47 +1169,66 @@ void AliHLTTPCClusterFinder::WriteClusters(Int_t nclusters,AliClusterData *list)
            <<"SigmaZ2 negative "<<sz2<<" on row "<<fCurrentRow<<" "<<fpad<<" "<<ftime<<ENDLOG;
          continue;
        } else {
-         if(!fRawSP){
+         {
            ftime2 = (sz2 + 1./12)*AliHLTTPCTransform::GetZWidth()*AliHLTTPCTransform::GetZWidth();
            if(sz2 != 0) {
              ftime2 *= 0.169; //constants are from offline studies
              if(patch<2)
                ftime2 *= 1.77;
            }
-         } else ftime2=sz2; //take the width, not the error
+         }
        }
       }
       if(fStdout==kTRUE)
        HLTInfo("WriteCluster: padrow %d pad %d +- %d time +- %d charge %d",fCurrentRow, fpad, fpad2, ftime, ftime2, list[j].fTotalCharge);
       
-      if(!fRawSP){
+      if (fFillRawClusters && fRawClusters.size()>(unsigned)counter) {
+       fRawClusters[counter].SetPadRow(fCurrentRow);
+       fRawClusters[counter].SetPad(fpad);  
+       fRawClusters[counter].SetTime(ftime);
+      }
+      {
        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 {
-       fSpacePointData[counter].fX = fCurrentRow;
-       fSpacePointData[counter].fY = fpad;
-       fSpacePointData[counter].fZ = ftime;
-      }
+      } 
       
       fSpacePointData[counter].fCharge = list[j].fTotalCharge;
       fSpacePointData[counter].fPadRow = fCurrentRow;
@@ -1119,13 +1237,19 @@ void AliHLTTPCClusterFinder::WriteClusters(Int_t nclusters,AliClusterData *list)
 
       fSpacePointData[counter].fQMax = list[j].fQMax;
 
-      fSpacePointData[counter].fUsed = kFALSE;         // only used / set in AliHLTTPCDisplay
-      fSpacePointData[counter].fTrackN = -1;           // only used / set in AliHLTTPCDisplay
+      fSpacePointData[counter].SetUsed(kFALSE);         // only used / set in AliHLTTPCDisplay
+      fSpacePointData[counter].SetTrackNumber(-1);      // only used / set in AliHLTTPCDisplay
 
       Int_t patch=fCurrentPatch;
       if(patch==-1) patch=0; //never store negative patch number
-      fSpacePointData[counter].fID = counter
-       +((fCurrentSlice&0x7f)<<25)+((patch&0x7)<<22);//Uli
+      fSpacePointData[counter].SetID( fCurrentSlice, patch, counter );
+
+      if (fFillRawClusters && fRawClusters.size()>(unsigned)counter) {
+       fRawClusters[counter].SetSigmaY2(fSpacePointData[counter].fSigmaY2);
+       fRawClusters[counter].SetSigmaZ2(fSpacePointData[counter].fSigmaZ2);
+       fRawClusters[counter].SetCharge(fSpacePointData[counter].fCharge);
+       fRawClusters[counter].SetQMax(fSpacePointData[counter].fQMax);
+      }
 
 #ifdef do_mc
       Int_t trackID[3];
@@ -1145,7 +1269,7 @@ 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
@@ -1183,6 +1307,10 @@ void AliHLTTPCClusterFinder::WriteClusters(Int_t nclusters,AliHLTTPCClusters *li
   //write cluster to output pointer
   Int_t thisrow,thissector;
   UInt_t counter = fNClusters;
+
+  if (fFillRawClusters) {
+    fRawClusters.resize(nclusters);
+  }
   
   for(int j=0; j<nclusters; j++)
     {
@@ -1206,14 +1334,14 @@ void AliHLTTPCClusterFinder::WriteClusters(Int_t nclusters,AliHLTTPCClusters *li
              <<"SigmaY2 negative "<<sy2<<" on row "<<fCurrentRow<<" "<<fpad<<" "<<ftime<<ENDLOG;
            continue;
        } else {
-         if(!fRawSP){
+         {
            fpad2 = (sy2 + 1./12)*AliHLTTPCTransform::GetPadPitchWidth(patch)*AliHLTTPCTransform::GetPadPitchWidth(patch);
            if(sy2 != 0){
              fpad2*=0.108; //constants are from offline studies
              if(patch<2)
                fpad2*=2.07;
            }
-         } else fpad2=sy2; //take the width not the error
+         }
        }
        Float_t sz2=list[j].fTime2*list[j].fTotalCharge - list[j].fTime*list[j].fTime;
        sz2/=q2;
@@ -1222,20 +1350,25 @@ void AliHLTTPCClusterFinder::WriteClusters(Int_t nclusters,AliHLTTPCClusters *li
            <<"SigmaZ2 negative "<<sz2<<" on row "<<fCurrentRow<<" "<<fpad<<" "<<ftime<<ENDLOG;
          continue;
        } else {
-         if(!fRawSP){
+         {
            ftime2 = (sz2 + 1./12)*AliHLTTPCTransform::GetZWidth()*AliHLTTPCTransform::GetZWidth();
            if(sz2 != 0) {
              ftime2 *= 0.169; //constants are from offline studies
              if(patch<2)
                ftime2 *= 1.77;
            }
-         } else ftime2=sz2; //take the width, not the error
+         }
        }
       }
       if(fStdout==kTRUE)
        HLTInfo("WriteCluster: padrow %d pad %d +- %d time +- %d charge %d",fCurrentRow, fpad, fpad2, ftime, ftime2, list[j].fTotalCharge);
 
-      if(!fRawSP){
+      if (fFillRawClusters && fRawClusters.size()>(unsigned)counter) {
+       fRawClusters[counter].SetPadRow(fCurrentRow);
+       fRawClusters[counter].SetPad(fpad);  
+       fRawClusters[counter].SetTime(ftime);
+      }
+      {
        AliHLTTPCTransform::Slice2Sector(fCurrentSlice,fCurrentRow,thissector,thisrow);
        AliHLTTPCTransform::Raw2Local(xyz,thissector,thisrow,fpad,ftime);
        
@@ -1258,10 +1391,6 @@ void AliHLTTPCClusterFinder::WriteClusters(Int_t nclusters,AliHLTTPCClusters *li
        }
        fSpacePointData[counter].fZ = xyz[2];
        
-      } else {
-       fSpacePointData[counter].fX = fCurrentRow;
-       fSpacePointData[counter].fY = fpad;
-       fSpacePointData[counter].fZ = ftime;
       }
       
       fSpacePointData[counter].fCharge = list[j].fTotalCharge;
@@ -1271,13 +1400,19 @@ void AliHLTTPCClusterFinder::WriteClusters(Int_t nclusters,AliHLTTPCClusters *li
 
       fSpacePointData[counter].fQMax = list[j].fQMax;
 
-      fSpacePointData[counter].fUsed = kFALSE;         // only used / set in AliHLTTPCDisplay
-      fSpacePointData[counter].fTrackN = -1;           // only used / set in AliHLTTPCDisplay
+      fSpacePointData[counter].SetUsed(kFALSE);         // only used / set in AliHLTTPCDisplay
+      fSpacePointData[counter].SetTrackNumber(-1);      // only used / set in AliHLTTPCDisplay
 
       Int_t patch=fCurrentPatch;
       if(patch==-1) patch=0; //never store negative patch number
-      fSpacePointData[counter].fID = counter
-       +((fCurrentSlice&0x7f)<<25)+((patch&0x7)<<22);//Uli
+      fSpacePointData[counter].SetID( fCurrentSlice, patch, counter );
+
+      if (fFillRawClusters && fRawClusters.size()>(unsigned)counter) {
+       fRawClusters[counter].SetSigmaY2(fSpacePointData[counter].fSigmaY2);
+       fRawClusters[counter].SetSigmaZ2(fSpacePointData[counter].fSigmaZ2);
+       fRawClusters[counter].SetCharge(fSpacePointData[counter].fCharge);
+       fRawClusters[counter].SetQMax(fSpacePointData[counter].fQMax);
+      }
 
 #ifdef do_mc
       Int_t trackID[3];