]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AliAODCaloCells.h
fix saving dEdx on ESD tracks (Markus)
[u/mrichter/AliRoot.git] / STEER / AliAODCaloCells.h
index cb13c328f677d3cbb568f791e0f850862cb8d5ca..53c05e451e4c768cda0595cd3df5746dfa645ff4 100644 (file)
 #ifndef ALIAODCELLS_H
 #define ALIAODCELLS_H
 
-#include <TNamed.h>
+#include <AliVCaloCells.h>
 #include <TMath.h>
 
-class AliAODCaloCells : public TNamed 
+class AliAODCaloCells : public AliVCaloCells
 {
  public:
-  enum AODTwrs_t {kUndef = -1, 
-                 kEMCAL, 
-                 kPHOS};
-
   AliAODCaloCells();
-  AliAODCaloCells(const char* name, const char* title, AODTwrs_t ttype=kUndef);
-  
+  AliAODCaloCells(const char* name, const char* title, VCells_t ttype=kUndef);
+  AliAODCaloCells(const AliAODCaloCells& cells); 
+  AliAODCaloCells& operator=(const AliAODCaloCells& cells);
+  virtual void Copy(TObject &obj) const;
+  virtual AliVCaloCells* CopyCaloCells(Bool_t all) const;
+
   virtual ~AliAODCaloCells();
-  
+  void Clear(const Option_t*);
+
   void CreateContainer(Short_t nCells);
   void DeleteContainer();
   void Sort();
   
-  Bool_t SetCell(Short_t pos, Short_t cellNumber, Double_t amplitude);
+  Bool_t SetCell(Short_t pos, Short_t cellNumber, Double_t amplitude, Double_t time = -1);
   
   Short_t GetNumberOfCells() const { return fNCells; }
-  inline Bool_t   GetCell(Short_t pos, Short_t &cellNumber, Double_t &amplitude) const;
+  void    SetNumberOfCells(Int_t n) { fNCells = n ; }
+  inline Bool_t   GetCell(Short_t pos, Short_t &cellNumber, Double_t &amplitude, Double_t &time) const;
   inline Double_t GetCellAmplitude(Short_t cellNumber);
+  inline Short_t  GetCellPosition(Short_t cellNumber);
   inline Double_t GetAmplitude(Short_t pos) const;
+  Double_t GetCellTime(Short_t /*cellNumber*/) {return -1;}
   inline Short_t  GetCellNumber(Short_t pos) const;
-
+  Double_t GetTime(Short_t /*pos*/) const {return -1;}
+  Bool_t IsEMCAL() const {return (fType == kEMCALCell);}
+  Bool_t IsPHOS() const {return (fType == kPHOSCell);}
   Char_t  GetType() const { return fType;}
-  void    SetType(AODTwrs_t ttype) { fType=ttype; }
+  void    SetType(Char_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);
+  ClassDef(AliAODCaloCells, 2);
 };
 
 
-Bool_t AliAODCaloCells::GetCell(Short_t pos, Short_t &cellNumber, Double_t &amplitude) const 
+Bool_t AliAODCaloCells::GetCell(Short_t pos, Short_t &cellNumber, Double_t &amplitude, Double_t& /*time*/) const 
 { 
   if (pos>=0 && pos<fNCells) {
     cellNumber = fCellNumber[pos];
     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 +81,9 @@ 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);
     return 0.;
   }
 }
@@ -91,7 +94,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 +105,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