]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - HLT/PHOS/AliHLTPHOSClusterizerComponent.cxx
Fast online clusterizer now working (Oystein)
[u/mrichter/AliRoot.git] / HLT / PHOS / AliHLTPHOSClusterizerComponent.cxx
index 3d5c55c962e1205756f239f323c9589d22fd9e1e..973ae186a3004f124649d0e45c2765db4289221a 100644 (file)
 #include "AliHLTPHOSRecPointDataStruct.h"
 #include "AliHLTPHOSClusterDataStruct.h"
 #include "AliHLTPHOSRecPointListDataStruct.h"
+#include "AliHLTPHOSDigitContainerDataStruct.h"
 
 using namespace std;
 
 
-const AliHLTComponentDataType AliHLTPHOSClusterizerComponent::fgkInputDataTypes[]={kAliHLTVoidDataType,{0,"",""}};
+const AliHLTComponentDataType AliHLTPHOSClusterizerComponent::fgkInputDataTypes[]=
+  {
+    kAliHLTVoidDataType,{0,"",""}
+  };
 
 AliHLTPHOSClusterizerComponent gAliHLTPHOSClusterizerComponent;
 
-//AliHLTPHOSClusterizerComponent::AliHLTPHOSClusterizerComponent(): AliHLTPHOSBase(), AliHLTProcessor(), fClusterizerPtr(0), fOutPtr(0), 
+//AliHLTPHOSClusterizerComponent::AliHLTPHOSClusterizerComponent(): AliHLTPHOSBase(), AliHLTProcessor(), fClusterizerPtr(0), fOutPtr(0),
 //                                                              fRecPointStructArrayPtr(0), fRecPointListPtr(0)
-AliHLTPHOSClusterizerComponent::AliHLTPHOSClusterizerComponent(): AliHLTPHOSProcessor(), fClusterizerPtr(0), fOutPtr(0), 
-                                                                 fRecPointStructArrayPtr(0), fRecPointListPtr(0)
+AliHLTPHOSClusterizerComponent::AliHLTPHOSClusterizerComponent(): AliHLTPHOSProcessor(), fClusterizerPtr(0), fOutPtr(0),
+    fRecPointStructArrayPtr(0), fRecPointListPtr(0)
 {
   //Constructor
 }
@@ -42,45 +46,45 @@ AliHLTPHOSClusterizerComponent::~AliHLTPHOSClusterizerComponent()
 {
   //Destructor
 
-  if(fClusterizerPtr)
+  if (fClusterizerPtr)
     {
       delete fClusterizerPtr;
       fClusterizerPtr = 0;
     }
-  
-  if(fRecPointListPtr)
+
+  if (fRecPointListPtr)
     {
       delete fRecPointListPtr;
       fRecPointListPtr = 0;
     }
 
-  if(fRecPointStructArrayPtr)
+  if (fRecPointStructArrayPtr)
     {
-      for(int i = 0; i < 1000; i++) 
-       {
-         fRecPointStructArrayPtr[i].Del();
-       }
+      for (int i = 0; i < 1000; i++)
+        {
+          //     fRecPointStructArrayPtr[i].Del();
+        }
       delete fRecPointStructArrayPtr;
       fRecPointStructArrayPtr = 0;
     }
-  
+
 }
 
 /*
-int 
+int
 AliHLTPHOSClusterizerComponent::AliHLTPHOSClusterizerComponent::Deinit()
 {
   ////////// PTH WARNING you should Define a class AliHLTPHOSModuleProcessor
 }
 */
 
-// PTH AliHLTPHOSClusterizerComponent::AliHLTPHOSClusterizerComponent(const AliHLTPHOSClusterizerComponent &):AliHLTProcessor(), 
-//                                                                                                    fClusterizerPtr(0), 
+// PTH AliHLTPHOSClusterizerComponent::AliHLTPHOSClusterizerComponent(const AliHLTPHOSClusterizerComponent &):AliHLTProcessor(),
+//                                                                                                    fClusterizerPtr(0),
 //                                                                                                    fOutPtr(0),
 //                                                                                                    fRecPointStructArrayPtr(0),
 //                                                                                                    fRecPointListPtr(0)
 //{
-  //Copy constructor, not implemented
+//Copy constructor, not implemented
 //}
 
 int
@@ -88,37 +92,33 @@ AliHLTPHOSClusterizerComponent::Deinit()
 {
   //Deinitialization
 
-  if(fClusterizerPtr)
+  if (fClusterizerPtr)
     {
       delete fClusterizerPtr;
       fClusterizerPtr = 0;
     }
-  
-  if(fRecPointListPtr)
+
+  if (fRecPointListPtr)
     {
       delete fRecPointListPtr;
       fRecPointListPtr = 0;
     }
-  
-  for(int i = 0; i < 1000; i++) 
+
+  for (int i = 0; i < 1000; i++)
     {
-      fRecPointStructArrayPtr[i].Del();
+      //    fRecPointStructArrayPtr[i].Del();
     }
-  
-  if(fRecPointStructArrayPtr)
+
+  if (fRecPointStructArrayPtr)
     {
-      for(int i = 0; i < 1000; i++) 
-       {
-         fRecPointStructArrayPtr[i].Del();
-       }
+      for (int i = 0; i < 1000; i++)
+        {
+          //     fRecPointStructArrayPtr[i].Del();
+        }
       delete fRecPointStructArrayPtr;
       fRecPointStructArrayPtr = 0;
     }
 
-
-
-
-
   return 0;
 }
 
@@ -132,7 +132,7 @@ AliHLTPHOSClusterizerComponent::DoDeinit()
 }
 
 
-const Char_t* 
+const Char_t*
 AliHLTPHOSClusterizerComponent::GetComponentID()
 {
   return "AliHltPhosClusterizer";
@@ -143,13 +143,14 @@ AliHLTPHOSClusterizerComponent::GetInputDataTypes( vector<AliHLTComponentDataTyp
 {
   //Get datatypes for input
   const AliHLTComponentDataType* pType=fgkInputDataTypes;
-  while (pType->fID!=0) {
-    list.push_back(*pType);
-    pType++;
-  }
+  while (pType->fID!=0)
+    {
+      list.push_back(*pType);
+      pType++;
+    }
 }
 
-AliHLTComponentDataType 
+AliHLTComponentDataType
 AliHLTPHOSClusterizerComponent::GetOutputDataType()
 {
   //  return AliHLTPHOSPhysicsDefinitions::fgkAliHLTClusterDataType;
@@ -164,77 +165,92 @@ AliHLTPHOSClusterizerComponent::GetOutputDataSize(unsigned long& constBase, doub
   inputMultiplier = 0.2;
 }
 
-int 
+int
 AliHLTPHOSClusterizerComponent::DoEvent(const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
-                                       AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr, AliHLTUInt32_t& size,
-                                       std::vector<AliHLTComponentBlockData>& outputBlocks)
+                                        AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr, AliHLTUInt32_t& size,
+                                        std::vector<AliHLTComponentBlockData>& outputBlocks)
 {
   //Do event
-   
+
   UInt_t tSize            = 0;
-  UInt_t offset           = 0; 
+  UInt_t offset           = 0;
   UInt_t mysize           = 0;
   Int_t nRecPoints        = 0;
+  Int_t nDigits           = 0;
   Int_t index             = 0;
+  Int_t j =0;
 
   AliHLTUInt8_t* outBPtr;
   outBPtr = outputPtr;
-  const AliHLTComponentBlockData* iter = 0; 
-  unsigned long ndx; 
+  const AliHLTComponentBlockData* iter = 0;
+  unsigned long ndx;
 
-  for( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
+  AliHLTPHOSDigitContainerDataStruct *digitContainerPtr = 0;
+  
+  //AliHLTPHOSRecPointContainerStruct *recPointContainerPtr = (AliHLTPHOSRecPointContainerStruct*)outBPtr;
+  fClusterizerPtr->SetRecPointContainer((AliHLTPHOSRecPointContainerStruct*)outBPtr);
+  for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
     {
       iter = blocks+ndx;
-      
-      if(iter->fDataType != AliHLTPHOSDefinitions::fgkCellEnergyDataType)
-       {
-         cout << "Warning: data type is not fgkCellEnergyDataType " << endl;
-         continue;
-       }
-      index = fClusterizerPtr->BuildCellEnergyArray( reinterpret_cast<AliHLTPHOSRcuCellEnergyDataStruct*>(iter->fPtr),
-                                                    fRecPointListPtr);
-      
+      digitContainerPtr = reinterpret_cast<AliHLTPHOSDigitContainerDataStruct*>(iter->fPtr);
+      if (iter->fDataType != AliHLTPHOSDefinitions::fgkAliHLTDigitDataType)
+        {
+          //     cout << "Warning: data type is not fgkAliHLTDigitDataType " << endl;
+          continue;
+        }
+      for (Int_t i = 0; i < digitContainerPtr->fNDigits; i++)
+        {
+         if(fNoCrazyness && digitContainerPtr->fDigitDataStruct[i].fCrazyness)
+           continue;
+           
+          fAllDigitsPtr->fDigitDataStruct[j+nDigits].fX = digitContainerPtr->fDigitDataStruct[i].fX;
+          fAllDigitsPtr->fDigitDataStruct[j+nDigits].fZ = digitContainerPtr->fDigitDataStruct[i].fZ;
+          fAllDigitsPtr->fDigitDataStruct[j+nDigits].fAmplitude = digitContainerPtr->fDigitDataStruct[i].fAmplitude;
+          fAllDigitsPtr->fDigitDataStruct[j+nDigits].fTime = digitContainerPtr->fDigitDataStruct[i].fTime;
+         // fAllDigitsPtr->fDigitDataStruct[i+nDigits].fCrazyness = digitContainerPtr->fDigitDataStruct[i].fCrazyness;
+         j++;
+        }
+      nDigits++;
     }
-  nRecPoints = fClusterizerPtr->CreateRecPointStructArray(fRecPointStructArrayPtr, fRecPointListPtr, index);
-  
-  cout << "Number of clusters found: " << nRecPoints << endl;
-  
-  for(Int_t i = 0; i < nRecPoints; i++)
+
+// nRecPoints = fClusterizerPtr->CreateRecPointStructArray(fRecPointStructArrayPtr, fRecPointListPtr, index);
+
+  fOutPtr =  (AliHLTPHOSRecPointContainerStruct*)outBPtr;
+  nRecPoints = fClusterizerPtr->ClusterizeEvent();
+  //nRecPoints = fClusterizerPtr->CalculateCenterOfGravity(&fRecPointStructArrayPtr[i]);
+  cout << "Number of clusters found: " << nRecPoints << " extracted from " << nDigits << " digits" << endl;
+
+  mysize = 0;
+  offset = tSize;
+
+  //      fClusterizerPtr->CalculateMoments(&fRecPointStructArrayPtr[i], 0);
+  //     fClusterizerPtr->ClusterizeStruct(&fRecPointStructArrayPtr[i], fOutPtr);
+
+  mysize += sizeof(AliHLTPHOSClusterDataStruct);
+
+  AliHLTComponentBlockData bd;
+  FillBlockData( bd );
+  bd.fOffset = offset;
+  bd.fSize = mysize;
+  // PTH      bd.fDataType = AliHLTPHOSPhysicsDefinitions::fgkAliHLTClusterDataType;
+  bd.fDataType = AliHLTPHOSDefinitions::fgkAliHLTClusterDataType;
+  bd.fSpecification = 0xFFFFFFFF;
+  outputBlocks.push_back( bd );
+
+  tSize += mysize;
+  outBPtr += mysize;
+
+  if ( tSize > size )
     {
-      mysize = 0;
-      offset = tSize;
-      
-      fOutPtr =  (AliHLTPHOSClusterDataStruct*)outBPtr;
-      fClusterizerPtr->CalculateCenterOfGravity(&fRecPointStructArrayPtr[i]);
-      //      fClusterizerPtr->CalculateMoments(&fRecPointStructArrayPtr[i], 0);
-      //     fClusterizerPtr->ClusterizeStruct(&fRecPointStructArrayPtr[i], fOutPtr);
-
-      mysize += sizeof(AliHLTPHOSClusterDataStruct);
-      
-      AliHLTComponentBlockData bd;
-      FillBlockData( bd );
-      bd.fOffset = offset;
-      bd.fSize = mysize;
-      // PTH      bd.fDataType = AliHLTPHOSPhysicsDefinitions::fgkAliHLTClusterDataType;
-      bd.fDataType = AliHLTPHOSDefinitions::fgkAliHLTClusterDataType;
-      bd.fSpecification = 0xFFFFFFFF;
-      outputBlocks.push_back( bd );
-       
-      tSize += mysize;
-      outBPtr += mysize;
-      
-      if( tSize > size )
-       {
-         Logging( kHLTLogFatal, "HLT::AliHLTPHOSClusterizerComponent::DoEvent", "Too much data",
-                  "Data written over allowed buffer. Amount written: %lu, allowed amount: %lu."
-                  , tSize, size );
-         return EMSGSIZE;
-       }
+      Logging( kHLTLogFatal, "HLT::AliHLTPHOSClusterizerComponent::DoEvent", "Too much data",
+               "Data written over allowed buffer. Amount written: %lu, allowed amount: %lu."
+               , tSize, size );
+      return EMSGSIZE;
     }
 
+
   size = tSize;
-  fClusterizerPtr->ResetCellEnergyArray();
+// fClusterizerPtr->ResetCellEnergyArray();
 
   return 0;
 
@@ -244,35 +260,40 @@ int
 AliHLTPHOSClusterizerComponent::DoInit(int argc, const char** argv )
 {
   //Do initialization
+  fAllDigitsPtr = new AliHLTPHOSDigitContainerDataStruct();
   fClusterizerPtr = new AliHLTPHOSClusterizer();
-  for(int i = 0; i < argc; i++)
+  //fClusterizerPtr->SetNoCrazyness(true);
+  //
+  for (int i = 0; i < argc; i++)
     {
+      /*
       if(!strcmp("-threshold", argv[i]))
-       fClusterizerPtr->SetThreshold(atof(argv[i+1]));
+      fClusterizerPtr->SetThreshold(atof(argv[i+1]));
       if(!strcmp("-clusterthreshold", argv[i]))
-       fClusterizerPtr->SetClusterThreshold(atof(argv[i+1]));
+      fClusterizerPtr->SetClusterThreshold(atof(argv[i+1]));
       if(!strcmp("-highgain", argv[i]))
-       fClusterizerPtr->SetHighGainFactor(atof(argv[i+1]));
+      fClusterizerPtr->SetHighGainFactor(atof(argv[i+1]));
       if(!strcmp("-lowgain", argv[i]))
-       fClusterizerPtr->SetLowGainFactor(atof(argv[i+1]));
+      fClusterizerPtr->SetLowGainFactor(atof(argv[i+1]));
       if(!strcmp("-arraysize", argv[i]))
-       fClusterizerPtr->SetArraySize(atoi(argv[i+1]));
+      fClusterizerPtr->SetArraySize(atoi(argv[i+1]));*/
     }
-  fClusterizerPtr->ResetCellEnergyArray();
+  //  fClusterizerPtr->ResetCellEnergyArray();
   fRecPointListPtr = new AliHLTPHOSRecPointListDataStruct[N_ZROWS_MOD*N_XCOLUMNS_MOD];
   fRecPointStructArrayPtr = new AliHLTPHOSRecPointDataStruct[1000];
-  for(int i = 0; i < 1000; i++) 
+  for (int i = 0; i < 1000; i++)
     {
       fRecPointStructArrayPtr[i].fMultiplicity = atoi(argv[4])* atoi(argv[4]);
-      fRecPointStructArrayPtr[i].New();
+      // fRecPointStructArrayPtr[i].New();
     }
+  /*
   printf("Clusterizer component started with:\n");
   printf(" Cell threshold:     %f\n", fClusterizerPtr->GetThreshold());
   printf(" Cluster threshold:  %f\n", fClusterizerPtr->GetClusterThreshold());
   printf(" High gain factor:   %f\n", fClusterizerPtr->GetHighGainFactor());
   printf(" Low gain factor:    %f\n", fClusterizerPtr->GetLowGainFactor());
   printf(" Cluster array size: %d\n\n", fClusterizerPtr->GetArraySize());
-
+  */
   return 0;
 }