]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - HLT/PHOS/AliHLTPHOSClusterAnalyser.cxx
Preparation to do trackmatching on AOD with tender
[u/mrichter/AliRoot.git] / HLT / PHOS / AliHLTPHOSClusterAnalyser.cxx
index 95e9a11fcf7381af5ded3cd880878d7f3c499107..a0d18a572504195951dd64d095c97a7596192117 100644 (file)
@@ -33,6 +33,7 @@
 #include "AliHLTPHOSRecPointDataStruct.h"
 #include "AliHLTCaloClusterDataStruct.h"
 #include "AliHLTPHOSPhysicsAnalyzer.h"
+#include "AliHLTPHOSDigitReader.h"
 #include "AliPHOSGeoUtils.h"
 #include "AliESDCaloCluster.h"
 #include "TMath.h"
 ClassImp(AliHLTPHOSClusterAnalyser);
 
 AliHLTPHOSClusterAnalyser::AliHLTPHOSClusterAnalyser() :
-  AliHLTPHOSBase(),
-  fLogWeight(0),
+  //  AliHLTPHOSBase(),
+  fLogWeight(4.5),
   fRecPointDataPtr(0),
   fNRecPoints(0),
   fCaloClusterDataPtr(0),
   fCaloClusterHeaderPtr(0),
   fPHOSGeometry(0),
-  fAnalyzerPtr(0),
   fDoClusterFit(false),
   fHaveCPVInfo(false),
   fDoPID(false),
-  fHaveDistanceToBadChannel(false)
+  fHaveDistanceToBadChannel(false),
+  fDigitHeaderPtr(0)
 {
   //See header file for documentation
-  fLogWeight = 4.5;
-
-  fAnalyzerPtr = new AliHLTPHOSPhysicsAnalyzer();
-  //  fPHOSGeometry = AliPHOSGeometry::GetInstance("noCPV");
-  fPHOSGeometry = new AliPHOSGeoUtils("PHOS", "noCPV");
 }
 
 AliHLTPHOSClusterAnalyser::~AliHLTPHOSClusterAnalyser() 
@@ -73,10 +69,12 @@ AliHLTPHOSClusterAnalyser::SetCaloClusterDataPtr(AliHLTCaloClusterDataStruct *ca
   fCaloClusterDataPtr = caloClusterDataPtr; 
 }
 void
-AliHLTPHOSClusterAnalyser::SetRecPointDataPtr(AliHLTPHOSRecPointHeaderStruct *recPointDataPtr)
+AliHLTPHOSClusterAnalyser::SetRecPointDataPtr(AliHLTPHOSRecPointHeaderStruct *recPointDataPtr, AliHLTPHOSDigitHeaderStruct *digitHeaderPtr)
 { 
   fNRecPoints = recPointDataPtr->fNRecPoints;
+
   fRecPointDataPtr = reinterpret_cast<AliHLTPHOSRecPointDataStruct*>(reinterpret_cast<Char_t*>(recPointDataPtr)+sizeof(AliHLTPHOSRecPointHeaderStruct)); 
+  fDigitHeaderPtr = digitHeaderPtr;
 }
 
 Int_t
@@ -93,18 +91,20 @@ AliHLTPHOSClusterAnalyser::CalculateCenterOfGravity()
   //AliPHOSGeometry * phosgeom =  AliPHOSGeometry::GetInstance() ;
 
   AliHLTPHOSRecPointDataStruct *recPoint = fRecPointDataPtr;
-
-  UInt_t iDigit = 0;
-
+  //  UInt_t iDigit = 0;
+  if(!recPoint) return 0;
   for(Int_t iRecPoint=0; iRecPoint < fNRecPoints; iRecPoint++) 
     {
-      digit = &(recPoint->fDigits);
-      for(iDigit = 0; iDigit < recPoint->fMultiplicity; iDigit++)
+      //      cout << "CA: start digit offset: " << recPoint->fStartDigitOffset << endl;
+      digit = reinterpret_cast<AliHLTPHOSDigitDataStruct*>(reinterpret_cast<UChar_t*>(fDigitHeaderPtr) + recPoint->fStartDigitOffset);
+  //      cout << "CA: digit offset: " << digit->fMemOffsetNext << endl;
+      AliHLTPHOSDigitReader reader;
+      reader.SetNextDigit(digit);
+      while(digit)
        {
-         
          xi = digit->fX;
          zi = digit->fZ;
-         //  cout << "COG digits (x:z:E:time): " << xi << " : " << zi << " : " << digit->fEnergy << " : " << digit->fTime << endl;
+         //      cout << "COG digits (x:z:E:time): " << xi << " : " << zi << " : " << digit->fEnergy << " : " << digit->fTime << endl;
          if (recPoint->fAmp > 0 && digit->fEnergy > 0) 
            {
              Float_t w = TMath::Max( 0., fLogWeight + TMath::Log( digit->fEnergy / recPoint->fAmp ) ) ;
@@ -112,20 +112,22 @@ AliHLTPHOSClusterAnalyser::CalculateCenterOfGravity()
              z    += zi * w ;
              wtot += w ;
            }
-         digit++;
+         digit = reader.NextDigit();
        }
-      //cout << endl;
       if (wtot>0) 
        {
          recPoint->fX = x/wtot ;
          recPoint->fZ = z/wtot ;
        }
+
       else
        {
          recPoint->fAmp = 0;
        }
-      recPoint = reinterpret_cast<AliHLTPHOSRecPointDataStruct*>(digit);
-    }
+     recPoint++;
+}
+
+
   return 0;
 }
 
@@ -160,43 +162,34 @@ AliHLTPHOSClusterAnalyser::CreateClusters(UInt_t availableSize, UInt_t& totSize)
   UInt_t maxClusterSize = sizeof(AliHLTCaloClusterDataStruct) + (6 << 7); //Reasonable estimate... (6 = sizeof(Short_t) + sizeof(Float_t)
 
   AliHLTPHOSRecPointDataStruct* recPointPtr = fRecPointDataPtr;
-  AliHLTPHOSDigitDataStruct* digitPtr = &(recPointPtr->fDigits);  
+  AliHLTPHOSDigitDataStruct* digitPtr = 0;
+
+  AliHLTPHOSDigitReader reader;
  
   AliHLTCaloClusterDataStruct* caloClusterPtr = fCaloClusterDataPtr;
-  UShort_t* cellIDPtr = &(caloClusterPtr->fCellsAbsId);
-  Float_t* cellAmpFracPtr = &(caloClusterPtr->fCellsAmpFraction);
   
-  Int_t id = -1;
+  //Int_t id = -1;
   TVector3 globalPos;
 
   for(Int_t i = 0; i < fNRecPoints; i++) //TODO needs fix when we start unfolding (number of clusters not necessarily same as number of recpoints gotten from the clusterizer
     {
-      
+      digitPtr = reinterpret_cast<AliHLTPHOSDigitDataStruct*>(reinterpret_cast<Long_t>(fDigitHeaderPtr) + recPointPtr->fStartDigitOffset);
+      reader.SetNextDigit(digitPtr);
+  
       if(availableSize < (totSize + maxClusterSize)) 
        {
          return -1; //Might get out of buffer, exiting
        }
-      //      cout << "Local Position (x:z:module): " << recPointPtr->fX << " : "<< recPointPtr->fZ << " : " << recPointPtr->fModule << endl;
       fPHOSGeometry->Local2Global(recPointPtr->fModule, recPointPtr->fX, recPointPtr->fZ, globalPos);
-      // cout << "Global Position (x:y:z): " << globalPos[0] << " : "<< globalPos[1] << " : " << globalPos[2] << endl << endl;
 
       caloClusterPtr->fGlobalPos[0] = globalPos[0];
       caloClusterPtr->fGlobalPos[1] = globalPos[1];
       caloClusterPtr->fGlobalPos[2] = globalPos[2];
-
+      cout << "Global position: " << globalPos[0] << ", " << globalPos[1] << ", " << globalPos[2] << endl;
       caloClusterPtr->fNCells = recPointPtr->fMultiplicity;
   
-      cellIDPtr = &(caloClusterPtr->fCellsAbsId);
-      cellAmpFracPtr = &(caloClusterPtr->fCellsAmpFraction);
-     
-      for(UInt_t j = 0; j < caloClusterPtr->fNCells; j++)
+      while(digitPtr)
        {
-         fPHOSGeometry->RelPosToAbsId((Int_t)(recPointPtr->fModule), (double)(digitPtr->fX), (double)(digitPtr->fZ), id);
-         *cellIDPtr = id;
-         *cellAmpFracPtr = digitPtr->fEnergy/recPointPtr->fAmp;
-         digitPtr++;
-         cellIDPtr = reinterpret_cast<UShort_t*>(reinterpret_cast<char*>(cellAmpFracPtr) + sizeof(Float_t)); 
-         cellAmpFracPtr = reinterpret_cast<Float_t*>(reinterpret_cast<char*>(cellIDPtr) + sizeof(Short_t)); 
        }
 
       caloClusterPtr->fEnergy = recPointPtr->fAmp;
@@ -242,16 +235,14 @@ AliHLTPHOSClusterAnalyser::CreateClusters(UInt_t availableSize, UInt_t& totSize)
        }
 
       caloClusterPtr->fClusterType = (AliESDCaloCluster::kPHOSCluster);
-      //      totSize += sizeof(AliHLTCaloClusterDataStruct) + (caloClusterPtr->fNCells)*(sizeof(Short_t) +sizeof(Float_t)-1);   
+      
       totSize += sizeof(AliHLTCaloClusterDataStruct) + (caloClusterPtr->fNCells-1)*(sizeof(Short_t) + sizeof(Float_t));   
 
-      //      caloClusterPtr = reinterpret_cast<AliHLTCaloClusterDataStruct*>(cellAmpFracPtr);
-      caloClusterPtr = reinterpret_cast<AliHLTCaloClusterDataStruct*>(cellIDPtr);
-      recPointPtr = reinterpret_cast<AliHLTPHOSRecPointDataStruct*>(digitPtr);
-      digitPtr = &(recPointPtr->fDigits);  
+      //      recPointPtr = reinterpret_cast<AliHLTPHOSRecPointDataStruct*>(digitPtr);
+      recPointPtr++; 
     }
-  //  cout << "CA: Energy End: " << fCaloClusterDataPtr->fEnergy << endl;
-  //cout << "CA totSize: " << totSize << endl;
+
   return fNRecPoints;
 
 }