]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AliAODCaloCells.h
Fix for Savannah bug report 59287
[u/mrichter/AliRoot.git] / STEER / AliAODCaloCells.h
index cb13c328f677d3cbb568f791e0f850862cb8d5ca..18da2b09d80854bb09550db34bd72e777170f941 100644 (file)
 class AliAODCaloCells : public TNamed 
 {
  public:
-  enum AODTwrs_t {kUndef = -1, 
+  enum AODCells_t {kUndef = -1, 
                  kEMCAL, 
                  kPHOS};
 
   AliAODCaloCells();
-  AliAODCaloCells(const char* name, const char* title, AODTwrs_t ttype=kUndef);
+  AliAODCaloCells(const char* name, const char* title, AODCells_t ttype=kUndef);
+  AliAODCaloCells(const AliAODCaloCells& cells); 
+  AliAODCaloCells& operator=(const AliAODCaloCells& cells);
   
   virtual ~AliAODCaloCells();
   
@@ -35,22 +37,20 @@ class AliAODCaloCells : public TNamed
   Short_t GetNumberOfCells() const { return fNCells; }
   inline Bool_t   GetCell(Short_t pos, Short_t &cellNumber, Double_t &amplitude) const;
   inline Double_t GetCellAmplitude(Short_t cellNumber);
+  inline Short_t  GetCellPosition(Short_t cellNumber);
   inline Double_t GetAmplitude(Short_t pos) const;
   inline Short_t  GetCellNumber(Short_t pos) const;
 
   Char_t  GetType() const { return fType;}
-  void    SetType(AODTwrs_t ttype) { fType=ttype; }
+  void    SetType(AODCells_t ttype) { fType=ttype; }
 
  protected:
   Int_t       fNCells;       // Number of cells
   Short_t    *fCellNumber;   //[fNCells] array of cell numbers
-  Double32_t *fAmplitude;    //[fNCells][0.,600.,16] array with cell amplitudes (= energy!)
+  Double32_t *fAmplitude;    //[fNCells][0.,0.,16] array with cell amplitudes (= energy!)
   Bool_t      fIsSorted;     //! true if cell arrays are sorted by index
   Char_t      fType;         // Cell type
   
- private:
-  AliAODCaloCells(const AliAODCaloCells& tow); 
-  AliAODCaloCells& operator=(const AliAODCaloCells& tow);
   
   ClassDef(AliAODCaloCells, 1);
 };
@@ -63,7 +63,7 @@ Bool_t AliAODCaloCells::GetCell(Short_t pos, Short_t &cellNumber, Double_t &ampl
     amplitude = fAmplitude[pos];
     return kTRUE;
   } else {
-    Error("GetCell","Invalid cell array index %d", pos);
+    Warning("GetCell","Invalid cell array index %d", pos);
     return kFALSE;
   }
 }
@@ -77,10 +77,10 @@ Double_t AliAODCaloCells::GetCellAmplitude(Short_t cellNumber)
   }
 
   Short_t pos = TMath::BinarySearch(fNCells, fCellNumber, cellNumber);
-  if (pos>=0 && pos == cellNumber) {
+  if (pos>=0 && fCellNumber[pos] == cellNumber) {
     return fAmplitude[pos];
   } else {
-    Error("GetCellAmplitude","Wrong cell array index %d", pos);
+    Warning("GetCellAmplitude","Wrong cell array index %d", pos);
     return 0.;
   }
 }
@@ -91,7 +91,7 @@ Double_t AliAODCaloCells::GetAmplitude(Short_t pos) const
   if (pos>=0 && pos<fNCells) {
     return fAmplitude[pos];
   } else {
-    Error("GetAmplitude","Invalid cell array index %d", pos);
+    Warning("GetAmplitude","Invalid cell array index %d", pos);
     return 0.;
   }
 }
@@ -102,10 +102,35 @@ Short_t AliAODCaloCells::GetCellNumber(Short_t pos) const
   if (pos>=0 && pos<fNCells) {
     return fCellNumber[pos];
   } else {
-    Error("GetCellNumber","Invalid cell array index %d", pos);
+    Warning("GetCellNumber","Invalid cell array index %d", pos);
     return fNCells;
   }
 }
 
+Short_t AliAODCaloCells::GetCellPosition(Short_t cellNumber)
+{ 
+  if (!fIsSorted) {
+    Sort();
+    fIsSorted=kTRUE;
+  }
+
+   Int_t nabove, nbelow, middle;
+   Short_t pos = -1;
+
+   nabove = fNCells + 1;
+   nbelow = 0;
+   while (nabove - nbelow > 1) {
+      middle = (nabove + nbelow) / 2;
+      if (cellNumber == fCellNumber[middle-1]) {
+         pos =   middle - 1;
+         break;
+      }
+      if (cellNumber  < fCellNumber[middle-1]) nabove = middle;
+      else                                     nbelow = middle;
+   }
+
+  return pos;
+}
+
 
 #endif