]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliAODCaloCells.h
Changes for #82873: Module debugging broken (Christian)
[u/mrichter/AliRoot.git] / STEER / AliAODCaloCells.h
1 /* Copyright(c) 1998-2007, ALICE Experiment at CERN, All rights reserved. *
2  * See cxx source for full Copyright notice                               */
3
4 /* $Id$ */
5
6 //-------------------------------------------------------------------------
7 //     AOD class to store calorimeter cell data
8 //     Author: Markus Oldenburg, CERN
9 //-------------------------------------------------------------------------
10
11 #ifndef ALIAODCELLS_H
12 #define ALIAODCELLS_H
13
14 #include <AliVCaloCells.h>
15 #include <TMath.h>
16
17 class AliAODCaloCells : public AliVCaloCells
18 {
19  public:
20   AliAODCaloCells();
21   AliAODCaloCells(const char* name, const char* title, VCells_t ttype=kUndef);
22   AliAODCaloCells(const AliAODCaloCells& cells); 
23   AliAODCaloCells& operator=(const AliAODCaloCells& cells);
24   virtual void Copy(TObject &obj) const;
25   virtual AliVCaloCells* CopyCaloCells(Bool_t all) const;
26
27   virtual ~AliAODCaloCells();
28   void Clear(const Option_t*);
29
30   void CreateContainer(Short_t nCells);
31   void DeleteContainer();
32   void Sort();
33   
34   Bool_t SetCell(Short_t pos, Short_t cellNumber, Double_t amplitude, Double_t time = -1);
35   
36   Short_t GetNumberOfCells() const { return fNCells; }
37   void    SetNumberOfCells(Int_t n) { fNCells = n ; }
38   inline Bool_t   GetCell(Short_t pos, Short_t &cellNumber, Double_t &amplitude, Double_t &time) const;
39   inline Double_t GetCellAmplitude(Short_t cellNumber);
40   inline Short_t  GetCellPosition(Short_t cellNumber);
41   inline Double_t GetAmplitude(Short_t pos) const;
42   Double_t GetCellTime(Short_t /*cellNumber*/) {return -1;}
43   inline Short_t  GetCellNumber(Short_t pos) const;
44   Double_t GetTime(Short_t /*pos*/) const {return -1;}
45   Bool_t IsEMCAL() const {return (fType == kEMCALCell);}
46   Bool_t IsPHOS() const {return (fType == kPHOSCell);}
47   Char_t  GetType() const { return fType;}
48   void    SetType(Char_t ttype) { fType=ttype; }
49
50
51  protected:
52   Int_t       fNCells;       // Number of cells
53   Short_t    *fCellNumber;   //[fNCells] array of cell numbers
54   Double32_t *fAmplitude;    //[fNCells][0.,0.,16] array with cell amplitudes (= energy!)
55   Bool_t      fIsSorted;     //! true if cell arrays are sorted by index
56   Char_t      fType;         // Cell type
57   
58   
59   ClassDef(AliAODCaloCells, 2);
60 };
61
62
63 Bool_t AliAODCaloCells::GetCell(Short_t pos, Short_t &cellNumber, Double_t &amplitude, Double_t& /*time*/) const 
64
65   if (pos>=0 && pos<fNCells) {
66     cellNumber = fCellNumber[pos];
67     amplitude = fAmplitude[pos];
68     return kTRUE;
69   } else {
70     Warning("GetCell","Invalid cell array index %d", pos);
71     return kFALSE;
72   }
73 }
74
75
76 Double_t AliAODCaloCells::GetCellAmplitude(Short_t cellNumber)
77
78   if (!fIsSorted) {
79     Sort();
80     fIsSorted=kTRUE;
81   }
82
83   Short_t pos = TMath::BinarySearch(fNCells, fCellNumber, cellNumber);
84   if (pos>=0 && fCellNumber[pos] == cellNumber) {
85     return fAmplitude[pos];
86   } else {
87     return 0.;
88   }
89 }
90
91
92 Double_t AliAODCaloCells::GetAmplitude(Short_t pos) const 
93
94   if (pos>=0 && pos<fNCells) {
95     return fAmplitude[pos];
96   } else {
97     Warning("GetAmplitude","Invalid cell array index %d", pos);
98     return 0.;
99   }
100 }
101
102
103 Short_t AliAODCaloCells::GetCellNumber(Short_t pos) const 
104
105   if (pos>=0 && pos<fNCells) {
106     return fCellNumber[pos];
107   } else {
108     Warning("GetCellNumber","Invalid cell array index %d", pos);
109     return fNCells;
110   }
111 }
112
113 Short_t AliAODCaloCells::GetCellPosition(Short_t cellNumber)
114
115   if (!fIsSorted) {
116     Sort();
117     fIsSorted=kTRUE;
118   }
119
120    Int_t nabove, nbelow, middle;
121    Short_t pos = -1;
122
123    nabove = fNCells + 1;
124    nbelow = 0;
125    while (nabove - nbelow > 1) {
126       middle = (nabove + nbelow) / 2;
127       if (cellNumber == fCellNumber[middle-1]) {
128           pos =   middle - 1;
129           break;
130       }
131       if (cellNumber  < fCellNumber[middle-1]) nabove = middle;
132       else                                     nbelow = middle;
133    }
134
135   return pos;
136 }
137
138
139 #endif