]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
New classes for online analysis
authorphille <phille@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 9 May 2007 02:08:25 +0000 (02:08 +0000)
committerphille <phille@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 9 May 2007 02:08:25 +0000 (02:08 +0000)
HLT/PHOS/AliHLTPHOSClusterizer.cxx [new file with mode: 0644]
HLT/PHOS/AliHLTPHOSClusterizer.h [new file with mode: 0644]
HLT/PHOS/AliHLTPHOSClusterizerComponent.cxx [new file with mode: 0644]
HLT/PHOS/AliHLTPHOSClusterizerComponent.h [new file with mode: 0644]

diff --git a/HLT/PHOS/AliHLTPHOSClusterizer.cxx b/HLT/PHOS/AliHLTPHOSClusterizer.cxx
new file mode 100644 (file)
index 0000000..8f2302c
--- /dev/null
@@ -0,0 +1,304 @@
+
+
+
+/**************************************************************************
+ * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                        *
+ * Authors: Øystein Djuvsland <oysteind@ift.uib.no>                       *
+ *                                                                        *
+ * Permission to use, copy, modify and distribute this software and its   *
+ * documentation strictly for non-commercial purposes is hereby granted   *
+ * without fee, provided that the above copyright notice appears in all   *
+ * copies and that both the copyright notice and this permission notice   *
+ * appear in the supporting documentation. The authors make no claims     *
+ * about the suitability of this software for any purpose. It is          *
+ * provided "as is" without express or implied warranty.                  *
+ **************************************************************************/
+
+
+/** @file   AliHLTPHOSClusterizer.cxx
+    @author Øystein Djuvsland
+    @date   
+    @brief  A temporary clusterizer for PHOS
+*/
+
+
+
+#include "AliHLTPHOSPhysicsDefinitions.h"
+#include "AliHLTPHOSClusterizer.h"
+#include "AliHLTPHOSCommonDefs.h"
+#include "TVector3.h"
+#include <iostream>
+#include "TMath.h"
+
+
+ClassImp(AliHLTPHOSClusterizer);
+
+/**
+* Main constructor
+**/
+AliHLTPHOSClusterizer::AliHLTPHOSClusterizer():fStructArray(NULL), fPHOSModule(-1), fThreshold(0),
+                                              fClusterThreshold(0), fHighGainFactor(0.005), fLowGainFactor(0.08),
+                                              fArraySize(3), fMultiplicity(fArraySize*fArraySize)
+{
+  
+}//end
+
+AliHLTPHOSClusterizer::AliHLTPHOSClusterizer(const AliHLTPHOSClusterizer &):fStructArray(NULL), fPHOSModule(-1), fThreshold(0),
+                                                                           fClusterThreshold(0), fHighGainFactor(0.005), fLowGainFactor(0.08),
+                                                                           fArraySize(3), fMultiplicity(fArraySize*fArraySize)
+{
+
+}//end
+
+AliHLTPHOSClusterizer:: ~AliHLTPHOSClusterizer()  
+{
+  
+}
+
+/**
+* Building a 2D array of cell energies of the PHOS detector
+* @param cellData object containing the cell energies from one event
+* @param recPointList list to be filled with coordinates of local maxima in the detector
+**/
+
+Int_t
+AliHLTPHOSClusterizer::BuildCellEnergyArray(AliHLTPHOSRcuCellEnergyDataStruct* cellData, 
+                                           AliHLTPHOSRecPointListDataStruct* recPointList)
+{
+
+  Int_t x = 0;
+  Int_t z = 0;
+  Int_t gain = 0;
+  Int_t xMod = 0;
+  Int_t zMod = 0;
+  Int_t index = 0;
+  Double_t energyCount = 0;
+
+  for(Int_t cell = 0; cell < cellData->fCnt; cell++)
+    {
+     
+      z = (cellData->fValidData[cell]).fZ;
+      x = (cellData->fValidData[cell]).fX;
+      gain = (cellData->fValidData[cell]).fGain;
+
+      zMod = z + (cellData->fRcuZ)*N_ROWS_RCU;
+      xMod = x + (cellData->fRcuX)*N_COLUMNS_RCU;
+      
+      energyCount = (cellData->fValidData[cell]).fEnergy;
+
+      if(gain == 0 && energyCount < 1023) 
+       {
+         fEnergyArray[xMod][zMod] = fHighGainFactor * energyCount;
+        
+         if(fEnergyArray[xMod][zMod] > fClusterThreshold)
+           {         
+             recPointList[index].fZ = zMod;
+             recPointList[index].fX = xMod;
+             
+             for(Int_t j = 0; j < index; j++)
+               {
+                 if(recPointList[j].fZ == zMod && recPointList[j].fX == xMod)
+                   recPointList[j].fZ = -1;
+               }
+             index++;
+           }
+         
+       }
+      else if(gain == 1 && fEnergyArray[xMod][zMod] == 0) 
+       {
+         fEnergyArray[xMod][zMod] = fLowGainFactor * energyCount;
+          if(fEnergyArray[xMod][zMod] > fClusterThreshold)
+           {         
+             recPointList[index].fZ = zMod;
+             recPointList[index].fX = xMod;
+             recPointList[index].fModule = cellData->fModuleID;
+             index++;
+           }
+       }
+
+    }  
+  
+  fPHOSModule = cellData->fModuleID;
+
+  return index;
+}//end BuildCellEnergyArray
+
+
+
+/**
+* Creating an array of rec points
+* @param recPointStructArrayPtr array to store the rec points
+* @param list list of rec points
+* @param nPoints number of points
+**/
+Int_t 
+AliHLTPHOSClusterizer::CreateRecPointStructArray(AliHLTPHOSRecPointDataStruct* recPointStructArrayPtr, 
+                                                AliHLTPHOSRecPointListDataStruct* list, 
+                                                Int_t nPoints) 
+
+{
+  Int_t flag = 0;
+  Int_t edgeFlagRows = 0;
+  Int_t edgeFlagCols = 0;
+  Int_t k = 0;
+  Int_t nRecPoints = 0;
+  Int_t z = 0;
+  Int_t x = 0;
+
+  Float_t* energiesList = NULL;
+  
+  for(Int_t point = 0; point < nPoints; point++)
+    {
+      z = list[point].fZ;
+      x = list[point].fX;
+      if(z == -1) continue;
+
+      if((z-fArraySize/2) < 0/*= - N_ROWS_MOD/2*/ || (z+fArraySize/2) >= N_ROWS_MOD/*/2*/) 
+       {
+         edgeFlagRows = 1;
+         continue;
+       }
+      if((x-fArraySize/2) < 0/*= - N_COLUMNS_MOD/2*/ || (x+fArraySize/2) >= N_COLUMNS_MOD) 
+       {
+         edgeFlagCols = 1;
+         continue;
+       }
+      
+
+      if(!flag) energiesList = new Float_t[fMultiplicity];
+      flag = 0;
+      k = 0;         
+         
+      for(Int_t i = -fArraySize/2; i <= fArraySize/2; i++)
+       {
+         if(flag) break;
+         for(Int_t j = -fArraySize/2; j <= fArraySize/2; j++)
+           {                     
+             
+             if(fEnergyArray[x+i][z+j] > fEnergyArray[x][z] && abs(i) < 2 && abs(j) < 2)
+               {
+                 flag = 1;
+                 break;
+               }
+             energiesList[k] = fEnergyArray[x+i][z+j];
+             k++;
+           }
+       }
+         
+      
+      if(!flag && k)
+       {
+         recPointStructArrayPtr[nRecPoints].fEnergiesListPtr = energiesList;
+         recPointStructArrayPtr[nRecPoints].fCoordinatesPtr[0] = x;
+         recPointStructArrayPtr[nRecPoints].fCoordinatesPtr[1] = z;
+         recPointStructArrayPtr[nRecPoints].fX = x;
+         recPointStructArrayPtr[nRecPoints].fZ = z;
+         recPointStructArrayPtr[nRecPoints].fMultiplicity = fMultiplicity;
+         recPointStructArrayPtr[nRecPoints].fPHOSModule = list[point].fModule;
+         nRecPoints++;
+       }
+    }
+
+
+
+  energiesList = NULL;
+
+  return nRecPoints;
+  
+}//end CreateRecPointStructArray
+
+
+/**
+* Calculating the center of gravity of a rec point
+* Not working well at this point!
+* @param recPointPtr pointer to the rec point
+**/
+Int_t
+AliHLTPHOSClusterizer::CalculateCenterOfGravity(AliHLTPHOSRecPointDataStruct* recPointPtr)
+{
+  Float_t xt = 0;
+  Float_t zt = 0;
+  Float_t xi = 0;
+  Float_t zj = 0;
+  Float_t w = 0;
+  Float_t w0 = 4.5;
+  Float_t wtot = 0;
+
+  Int_t x = recPointPtr->fCoordinatesPtr[0];
+  Int_t z = recPointPtr->fCoordinatesPtr[1];
+  
+  for(Int_t i = -fArraySize/2; i <= fArraySize/2; i++)
+    {
+      for(Int_t j = -fArraySize/2; j <= fArraySize/2; j++)
+       {                         
+         xi = x + i;
+         zj = z + j;
+         w = TMath::Max( 0., w0 + log( fEnergyArray[x+i][z+j] / fEnergyArray[x][z] ) ) ;
+         xt += xi * w ;
+         zt += zj * w ;
+         wtot += w ;
+         
+       }
+    }
+  xt /= wtot ;
+  zt /= wtot ;
+  
+  recPointPtr->fX = xt;
+  recPointPtr->fZ = zt;
+  
+  return 0;
+
+}//end CalculateCenterOfGravity
+  
+
+
+/**
+* Create a simpler data struct for a rec point, containing
+* only coordinates, energy and timing
+* @param recPointPtr pointer to the rec point
+* @clusterStructPtr pointer to the cluster struct
+**/
+Int_t
+AliHLTPHOSClusterizer::ClusterizeStruct(AliHLTPHOSRecPointDataStruct* recPointPtr, AliHLTPHOSClusterDataStruct* clusterStructPtr)
+{
+
+  Float_t clusterEnergy = 0;
+  Float_t* energiesListPtr = recPointPtr->fEnergiesListPtr;
+  
+  for(Int_t i = 0; i < recPointPtr->fMultiplicity; i++)
+    {
+      clusterEnergy += energiesListPtr[i];
+    }
+
+  clusterStructPtr->fLocalPositionPtr[0] = recPointPtr->fX;
+  clusterStructPtr->fLocalPositionPtr[1] = recPointPtr->fZ;
+  clusterStructPtr->fClusterEnergy = clusterEnergy;
+  clusterStructPtr->fPHOSModule = recPointPtr->fPHOSModule;
+
+  return 0;
+
+}//end ClusterizeStruct
+
+
+
+
+/**
+* Resets the cell energy array
+**/ 
+Int_t 
+AliHLTPHOSClusterizer::ResetCellEnergyArray()
+
+{
+  for(Int_t x = 0; x < N_ROWS_MOD; x++)
+    {
+      for(Int_t z = 0; z < N_COLUMNS_MOD; z++)
+       {
+         fEnergyArray[x][z] = 0;
+       }
+    }
+
+  return 0;
+
+}//end ResetCellEnergyArray
+
diff --git a/HLT/PHOS/AliHLTPHOSClusterizer.h b/HLT/PHOS/AliHLTPHOSClusterizer.h
new file mode 100644 (file)
index 0000000..0a7e405
--- /dev/null
@@ -0,0 +1,69 @@
+
+
+#ifndef ALIHLTPHOSCLUSTERIZER
+#define ALIHLTPHOSCLUSTERIZER
+
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+/** @file   AliHLTPHOSClusterizer.h
+    @author Øystein Djuvsland
+    @date   
+    @brief  A temporary clusterizer for PHOS
+*/
+
+
+#include "AliHLTPHOSCommonDefs.h"
+#include "AliHLTPHOSRcuCellEnergyDataStruct.h"
+#include "AliHLTPHOSClusterDataStruct.h"
+#include "AliHLTPHOSRecPointDataStruct.h"
+#include "AliHLTPHOSValidCellDataStruct.h"
+#include "AliHLTPHOSRecPointListDataStruct.h"
+
+class AliHLTPHOSClusterizer
+{
+  
+ public:
+  
+  AliHLTPHOSClusterizer();
+  virtual ~AliHLTPHOSClusterizer();
+  AliHLTPHOSClusterizer(const AliHLTPHOSClusterizer &);
+  AliHLTPHOSClusterizer & operator = (const AliHLTPHOSClusterizer &) {return *this;}
+   
+  void    SetThreshold(Float_t threshold) {fThreshold = threshold;}
+  void    SetClusterThreshold(Float_t clusterThreshold) {fClusterThreshold = clusterThreshold;}
+  
+  void    SetHighGainFactor(Float_t highGain) {fHighGainFactor = highGain;}
+  void    SetLowGainFactor(Float_t lowGain) {fLowGainFactor = lowGain;}
+  void    SetArraySize(Int_t size) 
+  { 
+    fArraySize = size;
+    fMultiplicity = fArraySize * fArraySize;
+  }
+  
+  Float_t GetHighGainFactor() {return fHighGainFactor;}
+  Float_t GetLowGainFactor() {return fLowGainFactor;}
+  Int_t   BuildCellEnergyArray(AliHLTPHOSRcuCellEnergyDataStruct *structPtr, AliHLTPHOSRecPointListDataStruct* recPointList);
+  Int_t   CreateRecPointStructArray(AliHLTPHOSRecPointDataStruct* rectStructsPtr, AliHLTPHOSRecPointListDataStruct* list, Int_t nPoints);
+  Int_t   CalculateCenterOfGravity(AliHLTPHOSRecPointDataStruct* recPointPtr);
+  Int_t   ClusterizeStruct(AliHLTPHOSRecPointDataStruct* recArrayPtr, AliHLTPHOSClusterDataStruct* clusterArrayPtr);
+  Int_t   ResetCellEnergyArray();
+
+  
+ private:
+
+  AliHLTPHOSRcuCellEnergyDataStruct* fStructArray;               /**<Array containing the cell data struct*/
+  AliHLTUInt8_t fPHOSModule;                                     /**<Number of the PHOSModule*/
+  Float_t fEnergyArray[N_COLUMNS_MOD][N_ROWS_MOD];               /**<2D array of cell energies*/
+  Float_t fThreshold;                                            /**<Energy threshold*/
+  Float_t fClusterThreshold;                                     /**<Cluster threshold*/
+  Float_t fHighGainFactor;                                       
+  Float_t fLowGainFactor;
+  Int_t   fArraySize;                                            /**<Size of the array which the energies are summed*/
+  Int_t   fMultiplicity;                                         /**<Number of crystals the energies are summed for*/
+
+  ClassDef(AliHLTPHOSClusterizer, 1);
+};
+
+#endif
diff --git a/HLT/PHOS/AliHLTPHOSClusterizerComponent.cxx b/HLT/PHOS/AliHLTPHOSClusterizerComponent.cxx
new file mode 100644 (file)
index 0000000..845d7fe
--- /dev/null
@@ -0,0 +1,179 @@
+
+#include "AliHLTPHOSClusterizerComponent.h"
+
+#include "AliHLTPHOSClusterizer.h"
+#include "AliHLTPHOSPhysicsDefinitions.h"
+#include "AliHLTPHOSDefinitions.h"
+#include <iostream>
+#include "stdio.h"
+#include <cstdlib>
+
+
+const AliHLTComponentDataType AliHLTPHOSClusterizerComponent::inputDataTypes[]={kAliHLTVoidDataType,{0,"",""}};
+int AliHLTPHOSClusterizerComponent::fEventCount = 0; 
+
+AliHLTPHOSClusterizerComponent gAliHLTPHOSClusterizerComponent;
+
+AliHLTPHOSClusterizerComponent::AliHLTPHOSClusterizerComponent():AliHLTProcessor(), fClusterizerPtr(0), fOutPtr(0), 
+                                                                fRecPointStructArrayPtr(0), fRecPointListPtr(0)
+{
+
+}
+
+AliHLTPHOSClusterizerComponent::~AliHLTPHOSClusterizerComponent()
+{
+}
+
+AliHLTPHOSClusterizerComponent::AliHLTPHOSClusterizerComponent(const AliHLTPHOSClusterizerComponent &):AliHLTProcessor(), 
+                                                                                                      fClusterizerPtr(0), 
+                                                                                                      fOutPtr(0),
+                                                                                                      fRecPointStructArrayPtr(0),
+                                                                                                      fRecPointListPtr(0)
+{
+
+}
+
+Int_t
+AliHLTPHOSClusterizerComponent::Deinit()
+{
+  return 0;
+}
+
+Int_t
+AliHLTPHOSClusterizerComponent::DoDeinit()
+{
+  Logging(kHLTLogInfo, "HLT", "PHOS", ",AliHLTPHOSClusterizerComponent DoDeinit");
+
+  return 0;
+}
+
+
+const Char_t* 
+AliHLTPHOSClusterizerComponent::GetComponentID()
+{
+  return "AliHltPhosClusterizer";
+}
+
+void
+AliHLTPHOSClusterizerComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
+{
+  const AliHLTComponentDataType* pType=inputDataTypes;
+  while (pType->fID!=0) {
+    list.push_back(*pType);
+    pType++;
+  }
+}
+
+AliHLTComponentDataType 
+AliHLTPHOSClusterizerComponent::GetOutputDataType()
+{
+  return AliHLTPHOSPhysicsDefinitions::fgkAliHLTClusterDataType;
+}
+
+void
+AliHLTPHOSClusterizerComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier )
+
+{
+  constBase = 30;
+  inputMultiplier = 1;
+}
+
+Int_t 
+AliHLTPHOSClusterizerComponent::DoEvent(const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
+                                       AliHLTComponentTriggerData& trigData, AliHLTUInt8_t* outputPtr, AliHLTUInt32_t& size,
+                                       std::vector<AliHLTComponentBlockData>& outputBlocks)
+{
+   
+  UInt_t tSize            = 0;
+  UInt_t offset           = 0; 
+  UInt_t mysize           = 0;
+  Int_t nRecPoints        = 0;
+  Int_t index             = 0;
+
+  AliHLTUInt8_t* outBPtr;
+  outBPtr = outputPtr;
+  const AliHLTComponentBlockData* iter = 0; 
+  unsigned long ndx; 
+
+  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);
+      
+    }
+  
+  nRecPoints = fClusterizerPtr->CreateRecPointStructArray(fRecPointStructArrayPtr, fRecPointListPtr, index);
+  
+  for(Int_t i = 0; i < nRecPoints; i++)
+    {
+      mysize = 0;
+      offset = tSize;
+      
+      fOutPtr =  (AliHLTPHOSClusterDataStruct*)outBPtr;
+      fClusterizerPtr->CalculateCenterOfGravity(&fRecPointStructArrayPtr[i]);
+      fClusterizerPtr->ClusterizeStruct(&fRecPointStructArrayPtr[i], fOutPtr);
+
+      mysize += sizeof(AliHLTPHOSClusterDataStruct);
+      
+      AliHLTComponentBlockData bd;
+      FillBlockData( bd );
+      bd.fOffset = offset;
+      bd.fSize = mysize;
+      bd.fDataType = AliHLTPHOSPhysicsDefinitions::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;
+       }
+    }
+
+  fEventCount++; 
+  if(fEventCount%100==0) cout << "Analyzing event: " << fEventCount << endl;
+  size = tSize;
+  fClusterizerPtr->ResetCellEnergyArray();
+
+  return 0;
+
+}
+
+Int_t
+AliHLTPHOSClusterizerComponent::DoInit(Int_t argc, const Char_t** argv )
+{
+  
+  fClusterizerPtr = new AliHLTPHOSClusterizer();
+  fClusterizerPtr->SetThreshold(atof(argv[0]));
+  fClusterizerPtr->SetClusterThreshold(atof(argv[1]));
+  fClusterizerPtr->SetHighGainFactor(atof(argv[2]));
+  fClusterizerPtr->SetLowGainFactor(atof(argv[3]));
+  fClusterizerPtr->SetArraySize(atoi(argv[4]));
+  fClusterizerPtr->ResetCellEnergyArray();
+  fRecPointListPtr = new AliHLTPHOSRecPointListDataStruct[N_ROWS_MOD*N_COLUMNS_MOD];
+  fRecPointStructArrayPtr = new AliHLTPHOSRecPointDataStruct[1000];
+
+  if (argc==0 && argv==NULL) {
+    // this is currently just to get rid of the warning "unused parameter"
+  }
+  
+  return 0;
+}
+
+AliHLTComponent*
+AliHLTPHOSClusterizerComponent::Spawn()
+{
+  return new AliHLTPHOSClusterizerComponent();
+}
diff --git a/HLT/PHOS/AliHLTPHOSClusterizerComponent.h b/HLT/PHOS/AliHLTPHOSClusterizerComponent.h
new file mode 100644 (file)
index 0000000..6736bd3
--- /dev/null
@@ -0,0 +1,53 @@
+#ifndef ALIHLTPHOSCLUSTERIZERCOMPONENT
+#define ALIHLTPHOSCLUSTERIZERCOMPONENT
+
+#include "AliHLTProcessor.h"
+
+#include "AliHLTPHOSClusterizer.h"
+#include "AliHLTPHOSRcuCellEnergyDataStruct.h"
+#include "AliHLTPHOSClusterDataStruct.h"
+#include "AliHLTPHOSRecPointDataStruct.h"
+#include "Rtypes.h"
+
+
+class AliHLTPHOSClusterizerComponent: public AliHLTProcessor
+{
+ public:
+
+  AliHLTPHOSClusterizerComponent();
+  ~AliHLTPHOSClusterizerComponent();
+  AliHLTPHOSClusterizerComponent(const AliHLTPHOSClusterizerComponent &);
+  AliHLTPHOSClusterizerComponent & operator = (const AliHLTPHOSClusterizerComponent &)
+    {
+      return *this;
+    }
+  const char* GetComponentID();
+  void GetInputDataTypes(std::vector<AliHLTComponentDataType, std::allocator<AliHLTComponentDataType> >&);
+
+  AliHLTComponentDataType GetOutputDataType();
+
+  void GetOutputDataSize(unsigned long& constBase, double& inputMultiplier);
+
+  Int_t DoEvent(const AliHLTComponentEventData&, const AliHLTComponentBlockData*,
+               AliHLTComponentTriggerData&, AliHLTUInt8_t*, AliHLTUInt32_t&,
+               std::vector<AliHLTComponentBlockData>&);
+
+  AliHLTComponent* Spawn();
+
+ protected:
+
+  Int_t DoInit(int argc, const char** argv);
+  Int_t Deinit();
+  Int_t DoDeinit();
+
+ private:
+  AliHLTPHOSClusterizer* fClusterizerPtr;
+  AliHLTPHOSClusterDataStruct* fOutPtr;
+  AliHLTPHOSRecPointDataStruct* fRecPointStructArrayPtr;
+  AliHLTPHOSRecPointListDataStruct* fRecPointListPtr;
+  static const AliHLTComponentDataType inputDataTypes[];
+  static int fEventCount;
+
+};
+
+#endif