- added different sorting algorithms for the digits
authorodjuvsla <odjuvsla@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 10 Jun 2010 15:23:09 +0000 (15:23 +0000)
committerodjuvsla <odjuvsla@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 10 Jun 2010 15:23:09 +0000 (15:23 +0000)
- pre-defined compare functions for sorting by energy and by position
- also possible to set the compare function to anything you like

- cleaned up some unnecessary code
- added some comments

HLT/CALO/AliHLTCaloClusterizer.cxx
HLT/CALO/AliHLTCaloClusterizer.h
HLT/CALO/AliHLTCaloClusterizerComponent.cxx

index c07f268c7e7e0d34ca565d2351b816b49949f525..882aa3de19c295290bb4b9e240e3dee718837b70 100644 (file)
@@ -1,7 +1,7 @@
 // $Id$\r
 \r
 /**************************************************************************\r
 // $Id$\r
 \r
 /**************************************************************************\r
- * This file is property of and copyright by the ALICE HLT Project        * \r
+ * This file is property of and copyright by the ALICE HLT Project        *\r
  * All rights reserved.                                                   *\r
  *                                                                        *\r
  * Primary Authors: Oystein Djuvsland                                     *\r
  * All rights reserved.                                                   *\r
  *                                                                        *\r
  * Primary Authors: Oystein Djuvsland                                     *\r
  * without fee, provided that the above copyright notice appears in all   *\r
  * copies and that both the copyright notice and this permission notice   *\r
  * appear in the supporting documentation. The authors make no claims     *\r
  * without fee, provided that the above copyright notice appears in all   *\r
  * copies and that both the copyright notice and this permission notice   *\r
  * appear in the supporting documentation. The authors make no claims     *\r
- * about the suitability of this software for any purpose. It is          * \r
+ * about the suitability of this software for any purpose. It is          *\r
  * provided "as is" without express or implied warranty.                  *\r
  **************************************************************************/\r
 \r
  * provided "as is" without express or implied warranty.                  *\r
  **************************************************************************/\r
 \r
-/** \r
+/**\r
  * @file   AliHLTCaloClusterizer.cxx\r
  * @author Oystein Djuvsland\r
  * @file   AliHLTCaloClusterizer.cxx\r
  * @author Oystein Djuvsland\r
- * @date \r
- * @brief  Clusterizer for PHOS HLT \r
+ * @date\r
+ * @brief  Clusterizer for PHOS HLT\r
  */\r
 \r
 // see header file for class documentation\r
  */\r
 \r
 // see header file for class documentation\r
 ClassImp(AliHLTCaloClusterizer);\r
 \r
 AliHLTCaloClusterizer::AliHLTCaloClusterizer(TString det):\r
 ClassImp(AliHLTCaloClusterizer);\r
 \r
 AliHLTCaloClusterizer::AliHLTCaloClusterizer(TString det):\r
-  AliHLTCaloConstantsHandler(det),\r
-  fRecPointArray(0),\r
-  fRecPointDataPtr(0),\r
-  fFirstRecPointPtr(0),\r
-  fArraySize(0),\r
-  fAvailableSize(0),\r
-  fUsedSize(0),\r
-  fNRecPoints(0),\r
-  fDigitIndexPtr(0),\r
-  fEmcClusteringThreshold(0),\r
-  fEmcMinEnergyThreshold(0),\r
-  fEmcTimeGate(0),\r
-  fDigitsInCluster(0),\r
-  fDigitsPointerArray(0),\r
-  fDigitContainerPtr(0),\r
-  fMaxDigitIndexDiff(0),\r
-  fNDigits(0)\r
+        AliHLTCaloConstantsHandler(det),\r
+        fCompareFunction(CompareDigitsByPosition),\r
+        fRecPointArray(0),\r
+        fRecPointDataPtr(0),\r
+        fFirstRecPointPtr(0),\r
+        fArraySize(0),\r
+        fAvailableSize(0),\r
+        fUsedSize(0),\r
+        fNRecPoints(0),\r
+        fDigitIndexPtr(0),\r
+        fEmcClusteringThreshold(0),\r
+        fEmcMinEnergyThreshold(0),\r
+        fEmcTimeGate(0),\r
+        fDigitsInCluster(0),\r
+        fDigitsPointerArray(0),\r
+        fDigitContainerPtr(0),\r
+        fMaxDigitIndexDiff(0),\r
+        fNDigits(0),\r
+        fSortedByPosition(false),\r
+        fSortedByEnergy(false),\r
+        fSortDigits(false)\r
 {\r
 {\r
-  //See header file for documentation\r
-  //fEmcClusteringThreshold = 0.2;\r
-  //fEmcMinEnergyThreshold = 0.03;\r
-\r
-  fEmcClusteringThreshold = 0.1;\r
-  fEmcMinEnergyThreshold = 0.01;\r
-  fEmcTimeGate = 1.e-6 ;\r
-  \r
-  fMaxDigitIndexDiff = 2*fCaloConstants->GetNZROWSMOD();\r
-  \r
-  \r
-  fArraySize = 10;\r
-  fRecPointArray = new AliHLTCaloRecPointDataStruct*[fArraySize];\r
-  \r
-  fAvailableSize = sizeof(AliHLTCaloRecPointDataStruct) * 20;\r
-  fFirstRecPointPtr = reinterpret_cast<AliHLTCaloRecPointDataStruct*>(new UChar_t[fAvailableSize]);\r
-  fRecPointDataPtr = fFirstRecPointPtr;  \r
+    //See header file for documentation\r
+    //fEmcClusteringThreshold = 0.2;\r
+    //fEmcMinEnergyThreshold = 0.03;\r
+\r
+    fEmcClusteringThreshold = 0.1;\r
+    fEmcMinEnergyThreshold = 0.01;\r
+    fEmcTimeGate = 1.e-6 ;\r
+\r
+    fMaxDigitIndexDiff = 2*fCaloConstants->GetNZROWSMOD();\r
+\r
+\r
+    fArraySize = 10;\r
+    fRecPointArray = new AliHLTCaloRecPointDataStruct*[fArraySize];\r
+\r
+    fAvailableSize = sizeof(AliHLTCaloRecPointDataStruct) * 20;\r
+    fFirstRecPointPtr = reinterpret_cast<AliHLTCaloRecPointDataStruct*>(new UChar_t[fAvailableSize]);\r
+    fRecPointDataPtr = fFirstRecPointPtr;\r
 \r
 }//end\r
 \r
 \r
 }//end\r
 \r
-AliHLTCaloClusterizer::~AliHLTCaloClusterizer()  \r
+AliHLTCaloClusterizer::~AliHLTCaloClusterizer()\r
 {\r
 {\r
-  //See header file for documentation\r
+    //See header file for documentation\r
 }\r
 \r
 }\r
 \r
-void \r
+void\r
 AliHLTCaloClusterizer::SetRecPointDataPtr(AliHLTCaloRecPointDataStruct* recPointDataPtr)\r
 {\r
 AliHLTCaloClusterizer::SetRecPointDataPtr(AliHLTCaloRecPointDataStruct* recPointDataPtr)\r
 {\r
-  // See header file for documentation\r
-  fRecPointDataPtr = recPointDataPtr;\r
+    // See header file for documentation\r
+    fRecPointDataPtr = recPointDataPtr;\r
 }\r
 \r
 }\r
 \r
-Int_t \r
+Int_t\r
 AliHLTCaloClusterizer::ClusterizeEvent(Int_t nDigits)\r
 {\r
 AliHLTCaloClusterizer::ClusterizeEvent(Int_t nDigits)\r
 {\r
-  //see header file for documentation\r
-  Int_t nRecPoints = 0;\r
-  fNRecPoints = 0;\r
-  fUsedSize = 0;\r
-  fNDigits = nDigits;\r
-  fRecPointDataPtr = fFirstRecPointPtr;\r
-\r
-  //Clusterization starts\r
-  for(Int_t i = 0; i < nDigits; i++)\r
-    { \r
-      fDigitsInCluster = 0;\r
-\r
-      if(fDigitsPointerArray[i]->fEnergy < fEmcClusteringThreshold)\r
-       {\r
-         continue;\r
-       }\r
-      CheckArray();\r
-      CheckBuffer();\r
-\r
-      // First digit is placed at the fDigits member variable in the recpoint\r
-      fDigitIndexPtr = &(fRecPointDataPtr->fDigits);\r
-      //fUsedSize += sizeof(AliHLTCaloRecPointDataStruct);\r
-      \r
-      fRecPointDataPtr->fAmp = 0;\r
-      fRecPointDataPtr->fModule = fDigitsPointerArray[i]->fModule;\r
-\r
-      // Assigning the digit to this rec point\r
-      fRecPointDataPtr->fDigits = i;\r
-      fUsedSize += sizeof(AliHLTCaloRecPointDataStruct);\r
-      \r
-      // Incrementing the pointer to be ready for new entry\r
-      fDigitIndexPtr++;\r
-\r
-      fRecPointDataPtr->fAmp += fDigitsPointerArray[i]->fEnergy;\r
-      fDigitsPointerArray[i]->fEnergy = 0;\r
-      fDigitsInCluster++;\r
-      nRecPoints++;\r
-\r
-      // Scanning for the neighbours\r
-      if(ScanForNeighbourDigits(i, fRecPointDataPtr) != 0)\r
-      {\r
-        return -1;\r
-      }\r
-\r
-      //fUsedSize += sizeof(AliHLTCaloRecPointDataStruct) + (fDigitsInCluster-1)*sizeof(AliHLTCaloDigitDataStruct);   \r
-      \r
-      fRecPointDataPtr->fMultiplicity = fDigitsInCluster;     \r
-      fRecPointArray[fNRecPoints] = fRecPointDataPtr; \r
-      \r
-      fRecPointDataPtr = reinterpret_cast<AliHLTCaloRecPointDataStruct*>(fDigitIndexPtr);\r
-\r
-      fNRecPoints++;\r
-      \r
+    //see header file for documentation\r
+    Int_t nRecPoints = 0;\r
+    fNRecPoints = 0;\r
+    fUsedSize = 0;\r
+    fNDigits = nDigits;\r
+    fRecPointDataPtr = fFirstRecPointPtr;\r
+\r
+    // Sort our digits\r
+    SortDigits();\r
+\r
+    //Clusterization starts\r
+    for (Int_t i = 0; i < nDigits; i++)\r
+    {\r
+        fDigitsInCluster = 0;\r
+\r
+        if (fDigitsPointerArray[i]->fEnergy < fEmcClusteringThreshold)\r
+        {\r
+            continue;\r
+        }\r
+\r
+        CheckArray();\r
+        CheckBuffer();\r
+\r
+        // First digit is placed at the fDigits member variable in the recpoint\r
+        fDigitIndexPtr = &(fRecPointDataPtr->fDigits);\r
+\r
+        fRecPointDataPtr->fAmp = 0;\r
+        fRecPointDataPtr->fModule = fDigitsPointerArray[i]->fModule;\r
+\r
+        // Assigning the digit to this rec point\r
+        fRecPointDataPtr->fDigits = i;\r
+        fUsedSize += sizeof(AliHLTCaloRecPointDataStruct);\r
+\r
+        // Incrementing the pointer to be ready for new entry\r
+        fDigitIndexPtr++;\r
+\r
+        fRecPointDataPtr->fAmp += fDigitsPointerArray[i]->fEnergy;\r
+        fDigitsPointerArray[i]->fEnergy = 0;\r
+        fDigitsInCluster++;\r
+        nRecPoints++;\r
+\r
+        // Scanning for the neighbours\r
+        if (ScanForNeighbourDigits(i, fRecPointDataPtr) != 0)\r
+        {\r
+            return -1;\r
+        }\r
+\r
+        //fUsedSize += sizeof(AliHLTCaloRecPointDataStruct) + (fDigitsInCluster-1)*sizeof(AliHLTCaloDigitDataStruct);\r
+\r
+        fRecPointDataPtr->fMultiplicity = fDigitsInCluster;\r
+        fRecPointArray[fNRecPoints] = fRecPointDataPtr;\r
+\r
+        fRecPointDataPtr = reinterpret_cast<AliHLTCaloRecPointDataStruct*>(fDigitIndexPtr);\r
+\r
+        fNRecPoints++;\r
+\r
     }//end of clusterization\r
 \r
     return nRecPoints;\r
     }//end of clusterization\r
 \r
     return nRecPoints;\r
@@ -153,206 +160,147 @@ AliHLTCaloClusterizer::ClusterizeEvent(Int_t nDigits)
 Int_t\r
 AliHLTCaloClusterizer::ScanForNeighbourDigits(Int_t index, AliHLTCaloRecPointDataStruct* recPoint)\r
 {\r
 Int_t\r
 AliHLTCaloClusterizer::ScanForNeighbourDigits(Int_t index, AliHLTCaloRecPointDataStruct* recPoint)\r
 {\r
-  //see header file for documentation\r
-  Int_t max = TMath::Min(fNDigits, (Int_t)fMaxDigitIndexDiff+index);\r
-  Int_t min = TMath::Max(0, (Int_t)(index - (Int_t)fMaxDigitIndexDiff));\r
+    //see header file for documentation\r
 \r
 \r
-  max = fNDigits;\r
-  min = 0;\r
-  for(Int_t j = min; j < max; j++)\r
+    // The following cuts can be used if we sort by posisiton. Not tested, but it should be fine...\r
+    Int_t max = TMath::Min(fNDigits, (Int_t)fMaxDigitIndexDiff+index);\r
+    Int_t min = TMath::Max(0, (Int_t)(index - (Int_t)fMaxDigitIndexDiff));\r
+\r
+    // All digits for now\r
+    max = fNDigits;\r
+    min = 0;\r
+\r
+    for (Int_t j = min; j < max; j++)\r
     {\r
     {\r
-      if(fDigitsPointerArray[j]->fEnergy > fEmcMinEnergyThreshold)\r
-       {\r
-         if(j != index)\r
-           {\r
-             if(AreNeighbours(fDigitsPointerArray[index],\r
-                              fDigitsPointerArray[j]))\r
-               {\r
-//               if((fAvailableSize - fUsedSize) < sizeof(Int_t))\r
-//                  {\r
-//                     UChar_t *tmp = new UChar_t[fAvailableSize*2];\r
-//                     memcpy(tmp, fRecPointDataPtr, fAvailableSize);\r
-//                     for(Int_t n = 0; n < fNRecPoints; n++)\r
-//                     {\r
-//                        fRecPointArray[n] = reinterpret_cast<AliHLTCaloRecPointDataStruct*>(reinterpret_cast<UChar_t*>(fRecPointArray[n]) - reinterpret_cast<UChar_t*>(fFirstRecPointPtr) + reinterpret_cast<UChar_t*>(tmp));\r
-//                     }\r
-//                     fRecPointDataPtr = reinterpret_cast<AliHLTCaloRecPointDataStruct*>(tmp);\r
-//                     fFirstRecPointPtr = fRecPointDataPtr;\r
-//                     fUsedSize = 0;\r
-//                  }  \r
-                 CheckBuffer();\r
-                 \r
-                 // Assigning index to digit\r
-                 *fDigitIndexPtr = j;\r
-                 fUsedSize += sizeof(Int_t);\r
-                 \r
-                 // Incrementing digit pointer to be ready for new entry\r
-                 fDigitIndexPtr++;\r
-                 \r
-                 fRecPointDataPtr->fAmp += fDigitsPointerArray[j]->fEnergy;\r
-                 fDigitsPointerArray[j]->fEnergy = 0;        \r
-                 fDigitsInCluster++;\r
-                 ScanForNeighbourDigits(j, recPoint);\r
-               }\r
-           }\r
-       }\r
+        if (fDigitsPointerArray[j]->fEnergy > fEmcMinEnergyThreshold)\r
+        {\r
+            if (j != index)\r
+            {\r
+                if (AreNeighbours(fDigitsPointerArray[index],\r
+                                  fDigitsPointerArray[j]))\r
+                {\r
+                    // Check that the buffer is large enough for adding a digit (can be heavily improved wrt performance)\r
+                    CheckBuffer();\r
+\r
+                    // Assigning index to digit\r
+                    *fDigitIndexPtr = j;\r
+                    fUsedSize += sizeof(Int_t);\r
+\r
+                    // Incrementing digit pointer to be ready for new entry\r
+                    fDigitIndexPtr++;\r
+\r
+                    // Adding the digit energy to the rec point\r
+                    fRecPointDataPtr->fAmp += fDigitsPointerArray[j]->fEnergy;\r
+\r
+                    // Setting the digit energy to 0 (not included in clusterisation anymore)\r
+                    fDigitsPointerArray[j]->fEnergy = 0;\r
+\r
+                    fDigitsInCluster++;\r
+\r
+                    // Scan for neighbours of this digit\r
+                    ScanForNeighbourDigits(j, recPoint);\r
+                }\r
+            }\r
+        }\r
     }\r
     }\r
-  return 0;\r
+    return 0;\r
 }\r
 \r
 }\r
 \r
-Int_t \r
-AliHLTCaloClusterizer::AreNeighbours(AliHLTCaloDigitDataStruct* digit1, \r
-                                           AliHLTCaloDigitDataStruct* digit2)\r
+Int_t\r
+AliHLTCaloClusterizer::AreNeighbours(AliHLTCaloDigitDataStruct* digit1,\r
+                                     AliHLTCaloDigitDataStruct* digit2)\r
 {\r
 {\r
-  //see header file for documentation\r
-  if ( (digit1->fModule == digit2->fModule) /*&& (coord1[1]==coord2[1])*/ ) // inside the same PHOS module\r
-    { \r
-      Int_t rowdiff = TMath::Abs( digit1->fZ - digit2->fZ );  \r
-      Int_t coldiff = TMath::Abs( digit1->fX - digit2->fX ); \r
-      if (( coldiff <= 1   &&  rowdiff == 0 ) || ( coldiff == 0 &&  rowdiff <= 1 ))\r
-       {\r
-//       cout << "Are neighbours: digit (E = "  << digit1->fEnergy << ") with x = " << digit1->fX << " and z = " << digit1->fZ << \r
-//         " is neighbour with digit (E = " << digit2->fEnergy << ") with x = " << digit2->fX << " and z = " << digit2->fZ << endl;\r
-\r
-         if(TMath::Abs(digit1->fTime - digit2->fTime ) < fEmcTimeGate)\r
-           {\r
-             return 1; \r
-           }\r
-       }\r
-\r
-   /*   Float_t rowdiff = TMath::Abs( digit1->fZ - digit2->fZ );  \r
-      Float_t coldiff = TMath::Abs( digit1->fX - digit2->fX ); \r
-      if (( coldiff <= 2.4   &&  rowdiff < 0.4 ) || ( coldiff < 0.4 &&  rowdiff <= 2.4 ))\r
-       {\r
-         //      cout << "Are neighbours: digit (E = "  << digit1->fEnergy << ") with x = " << digit1->fX << " and z = " << digit1->fZ << \r
-         //        " is neighbour with digit (E = " << digit2->fEnergy << ") with x = " << digit2->fX << " and z = " << digit2->fZ << endl;\r
-\r
-         if(TMath::Abs(digit1->fTime - digit2->fTime ) < fEmcTimeGate)\r
-           {\r
-             return 1; \r
-           }\r
-       }\r
-   */\r
-      else\r
-       {\r
-//         cout << "Not neighbours: digit (E = "  << digit1->fEnergy << ") with x = " << digit1->fX << " and z = " << digit1->fZ << \r
-//         " is not neighbour with digit (E = " << digit2->fEnergy << ") with x = " << digit2->fX << " and z = " << digit2->fZ << endl;\r
-       }\r
+    //see header file for documentation\r
+    if ( (digit1->fModule == digit2->fModule) /*&& (coord1[1]==coord2[1])*/ ) // inside the same PHOS module\r
+    {\r
+        Int_t rowdiff = TMath::Abs( digit1->fZ - digit2->fZ );\r
+        Int_t coldiff = TMath::Abs( digit1->fX - digit2->fX );\r
+\r
+        // As in the offline code we define neighbours as cells that share an edge, a corner is not  enough\r
+        if (( coldiff <= 1   &&  rowdiff == 0 ) || ( coldiff == 0 &&  rowdiff <= 1 ))\r
+        {\r
+            // Check also for time\r
+            if (TMath::Abs(digit1->fTime - digit2->fTime ) < fEmcTimeGate)\r
+            {\r
+                return 1;\r
+            }\r
+        }\r
     }\r
     }\r
-  return 0;\r
+    return 0;\r
 }\r
 \r
 \r
 \r
 Int_t AliHLTCaloClusterizer::CheckArray()\r
 {\r
 }\r
 \r
 \r
 \r
 Int_t AliHLTCaloClusterizer::CheckArray()\r
 {\r
-      if(fArraySize == fNRecPoints)\r
-       {\r
-          fArraySize *= 2;\r
-          AliHLTCaloRecPointDataStruct **tmp = new AliHLTCaloRecPointDataStruct*[fArraySize];\r
-          memcpy(tmp, fRecPointArray, fArraySize/2 * sizeof(AliHLTCaloRecPointDataStruct*));\r
-          delete [] fRecPointArray;\r
-          fRecPointArray = tmp;\r
-          //fRecPointArray[fNRecPoints-1] = fRecPointDataPtr;\r
-          //Int_t recPointOffset = reinterpret_cast<UChar_t*>(fRecPointDataPtr) - reinterpret_cast<UChar_t*>(fFirstRecPointPtr);\r
-          //fRecPointDataPtr = reinterpret_cast<AliHLTCaloRecPointDataStruct*>(reinterpret_cast<UChar_t*>(tmp) + recPointOffset);\r
-          \r
-       }\r
-   return 0;\r
+    // See header file for class documentation\r
+    if (fArraySize == fNRecPoints)\r
+    {\r
+        fArraySize *= 2;\r
+        AliHLTCaloRecPointDataStruct **tmp = new AliHLTCaloRecPointDataStruct*[fArraySize];\r
+        memcpy(tmp, fRecPointArray, fArraySize/2 * sizeof(AliHLTCaloRecPointDataStruct*));\r
+        delete [] fRecPointArray;\r
+        fRecPointArray = tmp;\r
+    }\r
+    return 0;\r
 }\r
 \r
 Int_t AliHLTCaloClusterizer::CheckBuffer()\r
 {\r
 }\r
 \r
 Int_t AliHLTCaloClusterizer::CheckBuffer()\r
 {\r
-   // See header file for class documentation \r
-       if((fAvailableSize - fUsedSize) < (Int_t)sizeof(AliHLTCaloRecPointDataStruct))\r
-       {\r
-           Int_t recPointOffset = reinterpret_cast<UChar_t*>(fRecPointDataPtr) - reinterpret_cast<UChar_t*>(fFirstRecPointPtr);\r
-           Int_t digitIndexOffset = reinterpret_cast<UChar_t*>(fDigitIndexPtr) - reinterpret_cast<UChar_t*>(fRecPointDataPtr);\r
-           UChar_t *tmp = new UChar_t[fAvailableSize*2];\r
-\r
-           memcpy(tmp, fFirstRecPointPtr, fUsedSize);\r
-           fAvailableSize *= 2;\r
-           for(Int_t n = 0; n < fNRecPoints; n++)\r
-           {\r
-              fRecPointArray[n] = reinterpret_cast<AliHLTCaloRecPointDataStruct*>(reinterpret_cast<UChar_t*>(fRecPointArray[n]) - reinterpret_cast<UChar_t*>(fFirstRecPointPtr) + reinterpret_cast<UChar_t*>(tmp));\r
-           }\r
-           delete [] fFirstRecPointPtr;\r
-           fFirstRecPointPtr = reinterpret_cast<AliHLTCaloRecPointDataStruct*>(tmp);\r
-           fRecPointDataPtr = reinterpret_cast<AliHLTCaloRecPointDataStruct*>(tmp + recPointOffset);\r
-           fDigitIndexPtr = reinterpret_cast<Int_t*>(reinterpret_cast<UChar_t*>(fRecPointDataPtr) + digitIndexOffset);\r
-           //fUsedSize = 0;\r
-       }\r
-   return 0;\r
+    // See header file for class documentation\r
+    if ((fAvailableSize - fUsedSize) < (Int_t)sizeof(AliHLTCaloRecPointDataStruct))\r
+    {\r
+        Int_t recPointOffset = reinterpret_cast<UChar_t*>(fRecPointDataPtr) - reinterpret_cast<UChar_t*>(fFirstRecPointPtr);\r
+        Int_t digitIndexOffset = reinterpret_cast<UChar_t*>(fDigitIndexPtr) - reinterpret_cast<UChar_t*>(fRecPointDataPtr);\r
+        UChar_t *tmp = new UChar_t[fAvailableSize*2];\r
+\r
+        memcpy(tmp, fFirstRecPointPtr, fUsedSize);\r
+        fAvailableSize *= 2;\r
+        for (Int_t n = 0; n < fNRecPoints; n++)\r
+        {\r
+            fRecPointArray[n] = reinterpret_cast<AliHLTCaloRecPointDataStruct*>(reinterpret_cast<UChar_t*>(fRecPointArray[n]) - reinterpret_cast<UChar_t*>(fFirstRecPointPtr) + reinterpret_cast<UChar_t*>(tmp));\r
+        }\r
+        delete [] fFirstRecPointPtr;\r
+        fFirstRecPointPtr = reinterpret_cast<AliHLTCaloRecPointDataStruct*>(tmp);\r
+        fRecPointDataPtr = reinterpret_cast<AliHLTCaloRecPointDataStruct*>(tmp + recPointOffset);\r
+        fDigitIndexPtr = reinterpret_cast<Int_t*>(reinterpret_cast<UChar_t*>(fRecPointDataPtr) + digitIndexOffset);\r
+        //fUsedSize = 0;\r
+    }\r
+    return 0;\r
 }\r
 \r
 }\r
 \r
-Int_t AliHLTCaloClusterizer::CheckDigits(AliHLTCaloRecPointDataStruct** recArray, AliHLTCaloDigitDataStruct** digitArray, Int_t nRP)\r
+void AliHLTCaloClusterizer::SetSortDigitsByPosition()\r
 {\r
 {\r
-  AliHLTCaloRecPointDataStruct **recpoints = recArray;\r
-  AliHLTCaloDigitDataStruct **digits = digitArray;\r
-  Int_t nRecPoints = nRP;\r
-  \r
-  if(recArray == 0)\r
-  {\r
-     recpoints = fRecPointArray;\r
-  }\r
-  if(digitArray == 0)\r
-  {\r
-     digits = fDigitsPointerArray;\r
-  }\r
-  if(nRP == 0)\r
-  {\r
-     nRecPoints = fNRecPoints;\r
-  }\r
-  for(Int_t i = 0; i < nRecPoints; i++)\r
-  {\r
-          \r
-     AliHLTCaloRecPointDataStruct *recPoint = recpoints[i];\r
-\r
-     //AliHLTCaloRecPointDataStruct *recPoint = fRecPointArray[0];\r
-     Int_t multiplicity = recPoint->fMultiplicity;\r
-     Int_t *digitIndexPtr = &(recPoint->fDigits);\r
-     for(Int_t j = 0; j < multiplicity; j++)\r
-     {\r
-       //AliHLTCaloRecPointDataStruct *recPoint = fRecPointArray[j];\r
-//     AliHLTCaloDigitDataStruct *digit = digits[*digitIndexPtr];\r
-       digitIndexPtr++;\r
-       //recPoint = reinterpret_cast<AliHLTCaloRecPointDataStruct*>(digitIndexPtr);\r
-     }\r
-  }\r
-     \r
-     return 0;\r
+    // Sort the digit pointers by position\r
+    fCompareFunction = &CompareDigitsByPosition;\r
+    fSortDigits = true;\r
+    fSortedByPosition = true;\r
 }\r
 \r
 }\r
 \r
-Int_t AliHLTCaloClusterizer::CheckDigits(AliHLTCaloRecPointDataStruct** recArray, AliHLTCaloDigitDataStruct* digitArray, Int_t nRP)\r
+void AliHLTCaloClusterizer::SetSortDigitsByEnergy()\r
+{\r
+    // See header file for class documentation\r
+    fCompareFunction = &CompareDigitsByEnergy;\r
+    fSortDigits = true;\r
+    fSortedByEnergy = true;\r
+}\r
+\r
+void AliHLTCaloClusterizer::SortDigits()\r
+{\r
+    // See header file for class documentation\r
+    if (fSortDigits) qsort(fDigitsPointerArray, fNDigits, sizeof(AliHLTCaloDigitDataStruct*), fCompareFunction);\r
+}\r
+\r
+Int_t\r
+AliHLTCaloClusterizer::CompareDigitsByPosition(const void *dig0, const void *dig1)\r
+{\r
+    // See header file for documentation\r
+    return (*((AliHLTCaloDigitDataStruct**)(dig0)))->fID - (*((AliHLTCaloDigitDataStruct**)(dig1)))->fID;\r
+}\r
+\r
+Int_t\r
+AliHLTCaloClusterizer::CompareDigitsByEnergy(const void *dig0, const void *dig1)\r
 {\r
 {\r
-  AliHLTCaloRecPointDataStruct **recpoints = recArray;\r
-  AliHLTCaloDigitDataStruct *digits = digitArray;\r
-  Int_t nRecPoints = nRP;\r
-  \r
-  if(recArray == 0)\r
-  {\r
-     recpoints = fRecPointArray;\r
-  }\r
-    if(nRP == 0)\r
-  {\r
-     nRecPoints = fNRecPoints;\r
-  }\r
-  for(Int_t i = 0; i < nRecPoints; i++)\r
-  {\r
-          \r
-     AliHLTCaloRecPointDataStruct *recPoint = recpoints[i];\r
-\r
-     //AliHLTCaloRecPointDataStruct *recPoint = fRecPointArray[0];\r
-     Int_t multiplicity = recPoint->fMultiplicity;\r
-     Int_t *digitIndexPtr = &(recPoint->fDigits);\r
-     for(Int_t j = 0; j < multiplicity; j++)\r
-     {\r
-       //AliHLTCaloRecPointDataStruct *recPoint = fRecPointArray[j];\r
-       AliHLTCaloDigitDataStruct digit = digits[*digitIndexPtr];\r
-       digitIndexPtr++;\r
-       //recPoint = reinterpret_cast<AliHLTCaloRecPointDataStruct*>(digitIndexPtr);\r
-     }\r
-  }\r
-   return 0;\r
-     \r
+    // See header file for documentation\r
+    return (*((AliHLTCaloDigitDataStruct**)(dig1)))->fEnergy - (*((AliHLTCaloDigitDataStruct**)(dig0)))->fEnergy;\r
 }\r
 }\r
index 11c5983f59b4d6e096cfdf75ea4168cc14eb64d7..f2d2bbbcd6ab4175c1276237959ff60a304afaaa 100644 (file)
@@ -122,10 +122,23 @@ public:
   */\r
   AliHLTCaloRecPointDataStruct** GetRecPoints() const { return fRecPointArray; }\r
 \r
   */\r
   AliHLTCaloRecPointDataStruct** GetRecPoints() const { return fRecPointArray; }\r
 \r
-  Int_t CheckDigits(AliHLTCaloRecPointDataStruct **recArray = 0, AliHLTCaloDigitDataStruct **digArray = 0, Int_t nRP = 0);\r
-\r
-  Int_t CheckDigits(AliHLTCaloRecPointDataStruct **recArray, AliHLTCaloDigitDataStruct *digArray, Int_t nRP = 0);\r
-\r
+  /** \r
+  * Sort the digits by energy\r
+  */\r
+  void SetSortDigitsByEnergy();\r
+  \r
+  /** \r
+  * Sort the digits by position\r
+  */\r
+  void SetSortDigitsByPosition();\r
+  \r
+  /** \r
+  * Set the sorting function (as required by stdlib's qsort) if you don't want to use the provided ones \r
+  */\r
+  void SetSortingFunction(Int_t (*compare)(const void*, const void*)) { fCompareFunction = compare; }\r
+  \r
+  \r
+  \r
 protected:\r
 \r
    /** \r
 protected:\r
 \r
    /** \r
@@ -137,7 +150,28 @@ protected:
    * Check the rec point array size and resize the array if necessary\r
    */\r
   virtual Int_t CheckArray(); //COMMENT\r
    * Check the rec point array size and resize the array if necessary\r
    */\r
   virtual Int_t CheckArray(); //COMMENT\r
+  \r
+  /** \r
+  * Sort the digits\r
+  */\r
+  void SortDigits();\r
 \r
 \r
+  /** \r
+  * Compare digits by position\r
+  */\r
+  static Int_t CompareDigitsByPosition(const void *dig0, const void *dig);\r
+  \r
+  /** \r
+  * Compare digits by energy\r
+  */\r
+  static Int_t CompareDigitsByEnergy(const void *dig0, const void *dig);\r
+  \r
+  /** \r
+  * Pointer to the compare function for the sorting of digits\r
+  */\r
+  //Int_t (AliHLTCaloClusterizer::*fCompareFunction)(const void*, const void*);\r
+  Int_t (*fCompareFunction)(const void*, const void*);\r
+  \r
   /** Array of pointers to the rec point output */\r
   AliHLTCaloRecPointDataStruct **fRecPointArray; //COMMENT\r
 \r
   /** Array of pointers to the rec point output */\r
   AliHLTCaloRecPointDataStruct **fRecPointArray; //COMMENT\r
 \r
@@ -185,6 +219,15 @@ protected:
 \r
   /** Number of digits in event */\r
   Int_t fNDigits;                                              //COMMENT\r
 \r
   /** Number of digits in event */\r
   Int_t fNDigits;                                              //COMMENT\r
+  \r
+  /** Are we sorting digits by position? */\r
+  Bool_t fSortedByPosition; //COMMENT\r
+\r
+  /** Are we sorting digits by energy? */\r
+  Bool_t fSortedByEnergy; //COMMENT\r
+\r
+   /** Are we sorting at all? */\r
+   Bool_t fSortDigits; //COMMENT\r
 \r
 private:\r
 \r
 \r
 private:\r
 \r
index 9ff879817df6a79fa57ce6e1b3f4ec31f819c3bc..945a5f14e21f665ac15e06f6d08d4a2e74d71bfe 100644 (file)
@@ -125,7 +125,7 @@ AliHLTCaloClusterizerComponent::DoEvent(const AliHLTComponentEventData& evtData,
       mysize += sizeof(AliHLTCaloClusterHeaderStruct);
       
       // Sort the digit pointers
       mysize += sizeof(AliHLTCaloClusterHeaderStruct);
       
       // Sort the digit pointers
-      qsort(fDigitsPointerArray, digCount, sizeof(AliHLTCaloDigitDataStruct*), CompareDigits);
+//      qsort(fDigitsPointerArray, digCount, sizeof(AliHLTCaloDigitDataStruct*), CompareDigits);
 
       // Copy the digits to the output
       fOutputDigitsArray = reinterpret_cast<AliHLTCaloDigitDataStruct*>(outBPtr);
 
       // Copy the digits to the output
       fOutputDigitsArray = reinterpret_cast<AliHLTCaloDigitDataStruct*>(outBPtr);
@@ -222,6 +222,11 @@ AliHLTCaloClusterizerComponent::ScanConfigurationArgument(int argc, const char *
       fAnalyserPtr->SetCutOnSingleCellClusters(true, argument.Atof());
       return 1;
     }
       fAnalyserPtr->SetCutOnSingleCellClusters(true, argument.Atof());
       return 1;
     }
+  if (argument.CompareTo("-sortbyposition") == 0)
+    {
+      fClusterizerPtr->SetSortDigitsByPosition();
+       return 1;
+    }
     
   return 0;
 }
     
   return 0;
 }
@@ -236,6 +241,8 @@ AliHLTCaloClusterizerComponent::DoInit(int argc, const char** argv )
   fClusterizerPtr = new AliHLTCaloClusterizer(fCaloConstants->GetDETNAME());
 
   fClusterizerPtr->SetDigitArray(fDigitsPointerArray);
   fClusterizerPtr = new AliHLTCaloClusterizer(fCaloConstants->GetDETNAME());
 
   fClusterizerPtr->SetDigitArray(fDigitsPointerArray);
+  
+  fClusterizerPtr->SetSortDigitsByEnergy();
    
   fAnalyserPtr = new AliHLTCaloClusterAnalyser();
   
    
   fAnalyserPtr = new AliHLTCaloClusterAnalyser();