]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - HLT/CALO/AliHLTCaloDigitMaker.cxx
In vmctest:
[u/mrichter/AliRoot.git] / HLT / CALO / AliHLTCaloDigitMaker.cxx
index cd564998030b353818179224a6275e48e11bcb3f..7e28a94e2d4d3e665091a0a7e3a0a41c099a0b36 100644 (file)
@@ -20,9 +20,7 @@
  * @date \r
  * @brief  Digit maker for CALO HLT  \r
  */\r
-  \r
-\r
-    \r
+      \r
 \r
 // see header file for class documentation\r
 // or\r
 #include "AliHLTCaloChannelDataStruct.h"\r
 #include "AliHLTCaloChannelDataHeaderStruct.h"\r
 #include "AliHLTCaloDigitDataStruct.h"\r
+#include "AliHLTCaloCoordinate.h"\r
 #include "AliHLTCaloSharedMemoryInterfacev2.h" // added by PTH\r
 //#include "AliPHOSEMCAGeometry.h"\r
 #include "TH2F.h"\r
 #include "AliHLTCaloConstants.h"\r
+#include "AliHLTLogging.h"\r
 \r
 ClassImp(AliHLTCaloDigitMaker);\r
 \r
@@ -47,6 +47,7 @@ ClassImp(AliHLTCaloDigitMaker);
 \r
 AliHLTCaloDigitMaker::AliHLTCaloDigitMaker(TString det) :\r
   AliHLTCaloConstantsHandler(det),\r
+  AliHLTLogging(),\r
   fShmPtr(0),\r
   fDigitStructPtr(0),\r
   fDigitCount(0),\r
@@ -54,7 +55,10 @@ AliHLTCaloDigitMaker::AliHLTCaloDigitMaker(TString det) :
   fHighGainFactors(0),\r
   fLowGainFactors(0),\r
   fBadChannelMask(0),\r
-  fChannelBook(0)\r
+  fChannelBook(0),\r
+  fMaxEnergy(900),\r
+  fMinTime(0.0),\r
+  fMaxTime(1008.0)\r
 {\r
   // See header file for documentation\r
 \r
@@ -63,7 +67,7 @@ AliHLTCaloDigitMaker::AliHLTCaloDigitMaker(TString det) :
   fHighGainFactors = new Float_t*[fCaloConstants->GetNXCOLUMNSMOD()];\r
   fLowGainFactors = new Float_t*[fCaloConstants->GetNXCOLUMNSMOD()];\r
   \r
-  fBadChannelMask = new Float_t**[fCaloConstants->GetNXCOLUMNSMOD()];\r
+  fBadChannelMask = new Bool_t**[fCaloConstants->GetNXCOLUMNSMOD()];\r
   \r
   fChannelBook= new AliHLTCaloDigitDataStruct**[fCaloConstants->GetNXCOLUMNSMOD()];\r
   \r
@@ -72,33 +76,35 @@ AliHLTCaloDigitMaker::AliHLTCaloDigitMaker(TString det) :
       fHighGainFactors[x] = new Float_t[fCaloConstants->GetNZROWSMOD()];\r
       fLowGainFactors[x] = new Float_t[fCaloConstants->GetNZROWSMOD()];\r
 \r
-      fBadChannelMask[x] = new Float_t*[fCaloConstants->GetNZROWSMOD()];\r
+      fBadChannelMask[x] = new Bool_t*[fCaloConstants->GetNZROWSMOD()];\r
 \r
       fChannelBook[x] = new AliHLTCaloDigitDataStruct*[fCaloConstants->GetNZROWSMOD()];\r
 \r
       for(int z = 0; z < fCaloConstants->GetNZROWSMOD(); z++)\r
        {\r
 \r
-         fHighGainFactors[x][z] = 0.005;\r
-         fLowGainFactors[x][z] = 0.08;\r
+         fHighGainFactors[x][z] = 0.0153;\r
+         fLowGainFactors[x][z] = 0.245;\r
         \r
-         fBadChannelMask[x][z] = new Float_t[fCaloConstants->GetNGAINS()];\r
-         fBadChannelMask[x][z][fCaloConstants->GetHIGHGAIN()] = 1;\r
-         fBadChannelMask[x][z][fCaloConstants->GetLOWGAIN()] = 1\r
+         fBadChannelMask[x][z] = new Bool_t[fCaloConstants->GetNGAINS()];\r
+         fBadChannelMask[x][z][fCaloConstants->GetHIGHGAIN()] = false;\r
+         fBadChannelMask[x][z][fCaloConstants->GetLOWGAIN()] = false\r
          \r
          fChannelBook[x][z] = 0;\r
          \r
        }\r
     }    \r
-  \r
-  //Must be set in child instance\r
-  //fMapperPtr = new AliHLTCaloMapper(det);\r
-\r
 }\r
 \r
 AliHLTCaloDigitMaker::~AliHLTCaloDigitMaker() \r
 {\r
   //See header file for documentation\r
+  delete [] fHighGainFactors;\r
+  delete [] fLowGainFactors;\r
+  delete [] fBadChannelMask;  \r
+  delete [] fChannelBook;\r
+  delete fShmPtr;\r
+\r
 }\r
 \r
 Int_t\r
@@ -107,21 +113,17 @@ AliHLTCaloDigitMaker::MakeDigits(AliHLTCaloChannelDataHeaderStruct* channelDataH
   //See header file for documentation\r
   \r
   Reset();\r
-  \r
-  Int_t j = 0;\r
+\r
   UInt_t totSize = sizeof(AliHLTCaloDigitDataStruct);\r
   \r
 //   Int_t xMod = -1;\r
 //   Int_t zMod = -1;\r
   \r
-  UShort_t coord1[4];\r
-  //  UShort_t coord2[4];\r
-  Float_t locCoord[3];\r
+\r
+  AliHLTCaloCoordinate coord;\r
   \r
   \r
   AliHLTCaloChannelDataStruct* currentchannel = 0;\r
-  //  AliHLTCaloChannelDataStruct* currentchannelLG = 0;  \r
-  AliHLTCaloChannelDataStruct* tmpchannel = 0;\r
   \r
   fShmPtr->SetMemory(channelDataHeader);\r
   currentchannel = fShmPtr->NextChannel();\r
@@ -130,31 +132,31 @@ AliHLTCaloDigitMaker::MakeDigits(AliHLTCaloChannelDataHeaderStruct* channelDataH
     {\r
       if(availableSize < totSize) return -1;\r
 \r
-      fMapperPtr->GetChannelCoord(currentchannel->fChannelID, coord1);\r
+      fMapperPtr->ChannelId2Coordinate(currentchannel->fChannelID, coord);\r
       \r
-      tmpchannel = currentchannel;\r
-         \r
-      fMapperPtr->GetLocalCoord(currentchannel->fChannelID, locCoord);\r
-      if(UseDigit(coord1, currentchannel))\r
+      //      fMapperPtr->GetLocalCoord(currentchannel->fChannelID, locCoord);\r
+      if(UseDigit(coord, currentchannel))\r
       {\r
-        AddDigit(currentchannel, coord1, locCoord);\r
-        j++;         \r
-        totSize += sizeof(AliHLTCaloDigitDataStruct);\r
+       AddDigit(currentchannel, coord);\r
+       //      j++;          \r
+       totSize += sizeof(AliHLTCaloDigitDataStruct);\r
       }\r
-      \r
       currentchannel = fShmPtr->NextChannel(); // Get the next channel\r
-\r
-      fMapperPtr->GetLocalCoord(currentchannel->fChannelID, locCoord);\r
-      if(UseDigit(coord1, currentchannel))\r
-      {\r
-        AddDigit(currentchannel, coord1, locCoord);\r
-        j++;         \r
-        totSize += sizeof(AliHLTCaloDigitDataStruct);\r
-      }\r
-       currentchannel = fShmPtr->NextChannel(); // Get the next channel\r
     }\r
+//       if(currentchannel)\r
+//     {\r
+//       fMapperPtr->GetLocalCoord(currentchannel->fChannelID, locCoord);\r
+//       if(UseDigit(coord1, currentchannel))\r
+//         {\r
+//           AddDigit(currentchannel, coord1, locCoord);\r
+//           j++;            \r
+//           totSize += sizeof(AliHLTCaloDigitDataStruct);\r
+//         }\r
+//       currentchannel = fShmPtr->NextChannel(); // Get the next channel\r
+//     }\r
+//     }\r
    \r
-   fDigitCount += j;\r
+//   fDigitCount += j;\r
    return fDigitCount; \r
 }\r
 \r
@@ -171,6 +173,7 @@ AliHLTCaloDigitMaker::SetGlobalHighGainFactor(Float_t factor)
     }\r
 }\r
 \r
+\r
 void\r
 AliHLTCaloDigitMaker::SetGlobalLowGainFactor(Float_t factor)\r
 {\r
@@ -184,6 +187,7 @@ AliHLTCaloDigitMaker::SetGlobalLowGainFactor(Float_t factor)
     }\r
 }\r
 \r
+\r
 void\r
 AliHLTCaloDigitMaker::SetBadChannelMask(TH2F* badChannelHGHist, TH2F* badChannelLGHist, Float_t qCut)\r
 {\r
@@ -193,19 +197,19 @@ AliHLTCaloDigitMaker::SetBadChannelMask(TH2F* badChannelHGHist, TH2F* badChannel
        {\r
          if(badChannelHGHist->GetBinContent(x, z) < qCut && badChannelHGHist->GetBinContent(x, z) > 0)\r
            {\r
-             fBadChannelMask[x][z][fCaloConstants->GetHIGHGAIN()] = 1;\r
+             fBadChannelMask[x][z][fCaloConstants->GetHIGHGAIN()] = true;\r
            }\r
          else\r
            {\r
-             fBadChannelMask[x][z][fCaloConstants->GetHIGHGAIN()] = 0;\r
+             fBadChannelMask[x][z][fCaloConstants->GetHIGHGAIN()] = false;\r
            }\r
          if(badChannelLGHist->GetBinContent(x, z) < qCut && badChannelLGHist->GetBinContent(x, z) > 0)\r
            {\r
-             fBadChannelMask[x][z][fCaloConstants->GetLOWGAIN()] = 0;\r
+             fBadChannelMask[x][z][fCaloConstants->GetLOWGAIN()] = false;\r
            }\r
          else\r
            {\r
-             fBadChannelMask[x][z][fCaloConstants->GetLOWGAIN()] = 0;\r
+             fBadChannelMask[x][z][fCaloConstants->GetLOWGAIN()] = false;\r
            }\r
        }\r
     }\r
@@ -226,58 +230,86 @@ AliHLTCaloDigitMaker::Reset()
 }\r
 \r
 \r
-void AliHLTCaloDigitMaker::AddDigit(AliHLTCaloChannelDataStruct* channelData, UShort_t* channelCoordinates, Float_t* localCoordinates)\r
+void AliHLTCaloDigitMaker::AddDigit(AliHLTCaloChannelDataStruct* channelData, AliHLTCaloCoordinate &coord)\r
 {\r
 \r
-  fChannelBook[channelCoordinates[0]][channelCoordinates[0]] = fDigitStructPtr;\r
-\r
-  fDigitStructPtr->fX = channelCoordinates[0];\r
-  fDigitStructPtr->fZ = channelCoordinates[1];\r
+  // Some book keeping of the pointers\r
+  AliHLTCaloDigitDataStruct *tmpDigit = fDigitStructPtr + 1;\r
 \r
-  fDigitStructPtr->fLocX = localCoordinates[0];\r
-  fDigitStructPtr->fLocZ = localCoordinates[1];\r
-\r
-  if(channelCoordinates[2] == fCaloConstants->GetHIGHGAIN() )\r
+  // Check if we already have a digit in this position, and correct the book keeping correspondently\r
+  if(fChannelBook[coord.fX][coord.fZ]) \r
+    {\r
+      tmpDigit = fDigitStructPtr;\r
+      fDigitStructPtr = fChannelBook[coord.fX][coord.fZ];\r
+      fDigitCount--;\r
+      //      printf("Going to overwrite digit: x = %d, z = %d, gain = %d, energy = %f\n", fDigitStructPtr->fX, fDigitStructPtr->fZ, fDigitStructPtr->fGain, fDigitStructPtr->fEnergy);\r
+    }\r
+  \r
+  fChannelBook[coord.fX][coord.fZ] = fDigitStructPtr;\r
\r
+  fDigitStructPtr->fX = coord.fX;\r
+  fDigitStructPtr->fZ = coord.fZ;\r
+  fDigitStructPtr->fGain = coord.fGain;\r
+  fDigitStructPtr->fOverflow = false;\r
+  fDigitStructPtr->fAssociatedCluster = -1;\r
+  \r
+  fDigitStructPtr->fID = fDigitStructPtr->fZ * fCaloConstants->GetNXCOLUMNSMOD() + fDigitStructPtr->fX;\r
+  \r
+  if(coord.fGain == fCaloConstants->GetHIGHGAIN() )\r
     {\r
-      fDigitStructPtr->fEnergy = channelData->fEnergy*fHighGainFactors[channelCoordinates[0]][channelCoordinates[1]];\r
-      if(channelData->fEnergy >= 1023)\r
+      fDigitStructPtr->fEnergy = channelData->fEnergy*fHighGainFactors[coord.fX][coord.fZ];\r
+      fDigitStructPtr->fHgPresent = true;\r
+      if(channelData->fEnergy >= fMaxEnergy)\r
        {\r
          fDigitStructPtr->fOverflow = true;\r
        }\r
-      //       printf("HG channel (x = %d, z = %d) with amplitude: %f --> Digit with energy: %f \n", channelCoordinates[0], channelCoordinates[1], channelData->fEnergy, fDigitStructPtr->fEnergy);\r
+      \r
+      HLTDebug("HG channel (x = %d, z = %d) with amplitude: %f --> Digit with energy: %f \n", \r
+              coord.fX, coord.fZ, channelData->fEnergy, fDigitStructPtr->fEnergy);\r
     }\r
   else\r
     {\r
-      fDigitStructPtr->fEnergy = channelData->fEnergy*fLowGainFactors[channelCoordinates[0]][channelCoordinates[1]];\r
-      if(channelData->fEnergy >= 1023)\r
+      fDigitStructPtr->fEnergy = channelData->fEnergy*fLowGainFactors[coord.fX][coord.fZ];\r
+      if(channelData->fEnergy >= fMaxEnergy)\r
        {\r
          fDigitStructPtr->fOverflow = true;\r
        }\r
-      //       printf("LG channel (x = %d, z = %d) with amplitude: %f --> Digit with energy: %f\n", channelCoordinates[0], channelCoordinates[1], channelData->fEnergy, fDigitStructPtr->fEnergy); \r
+      HLTDebug("LG channel (x = %d, z = %d) with amplitude: %f --> Digit with energy: %f\n", coord.fX, coord.fZ, channelData->fEnergy, fDigitStructPtr->fEnergy); \r
     }\r
   fDigitStructPtr->fTime = channelData->fTime * 0.0000001; //TODO\r
   fDigitStructPtr->fCrazyness = channelData->fCrazyness;\r
-  fDigitStructPtr->fModule = channelCoordinates[3];\r
-  fDigitStructPtr++;\r
+  fDigitStructPtr->fModule = coord.fModuleId;\r
+  fDigitStructPtr = tmpDigit;\r
+  //  fDigitStructPtr++;\r
+  fDigitCount++;\r
 }\r
 \r
-bool AliHLTCaloDigitMaker::UseDigit(UShort_t *channelCoordinates, AliHLTCaloChannelDataStruct *channel) \r
+bool AliHLTCaloDigitMaker::UseDigit(AliHLTCaloCoordinate &channelCoordinates, AliHLTCaloChannelDataStruct *channel) \r
 {\r
-  AliHLTCaloDigitDataStruct *tmpDigit = fChannelBook[channelCoordinates[0]][channelCoordinates[1]];\r
+   \r
+   if(fBadChannelMask[channelCoordinates.fX][channelCoordinates.fZ][0] == true) return false;\r
+   if(channel->fTime < fMinTime || channel->fTime > fMaxTime) return false;\r
+   \r
+  AliHLTCaloDigitDataStruct *tmpDigit = fChannelBook[channelCoordinates.fX][channelCoordinates.fZ];\r
+  //printf("UseDigit: Got digit, x: %d, z: %d, gain: %d, amp: %f\n", channelCoordinates.fX, channelCoordinates.fZ, channelCoordinates.fGain, channel->fEnergy);\r
   if(tmpDigit)\r
     {\r
-      if(channelCoordinates[2] == fCaloConstants->GetLOWGAIN())\r
+      if(channelCoordinates.fGain == fCaloConstants->GetLOWGAIN())\r
        {\r
+                 //printf("UseDigit: Already have digit with, x: %d, z: %d, with high gain \n", channelCoordinates.fX, channelCoordinates.fZ);\r
          if(tmpDigit->fOverflow)\r
            {\r
+                    // printf("But it was in overflow! Let's use this low gain!\n");\r
              return true;\r
            }\r
          return false;\r
        }\r
       else\r
        {\r
-         if(channel->fEnergy >= fCaloConstants->GetMAXBINVALUE() )\r
+                 //printf("UseDigit: Already have digit with, x: %d, z: %d, with low gain: %d\n", channelCoordinates.fX, channelCoordinates.fZ);\r
+         if(channel->fEnergy > fMaxEnergy )\r
            {\r
+             tmpDigit->fHgPresent = true;\r
              return false;\r
            }\r
          return true;\r
@@ -285,3 +317,19 @@ bool AliHLTCaloDigitMaker::UseDigit(UShort_t *channelCoordinates, AliHLTCaloChan
     }\r
   return true;\r
 }\r
+\r
+void AliHLTCaloDigitMaker::SetBadChannel(Int_t x, Int_t z, Bool_t bad)\r
+{\r
+   // See header file for class documentation\r
+   fBadChannelMask[x][z][0] = bad;\r
+   fBadChannelMask[x][z][1] = bad;\r
+}\r
+\r
+void AliHLTCaloDigitMaker::SetGain(Int_t x, Int_t z, Float_t ratio, Float_t gain)\r
+{\r
+   // See header file for class documentation\r
+   HLTDebug("Applying gain: %f for channel x: %d, z: %d", gain, x, z); \r
+   fHighGainFactors[x][z] = gain;\r
+   fLowGainFactors[x][z] = gain * ratio;\r
+   \r
+}\r