]> git.uio.no Git - u/mrichter/AliRoot.git/blame_incremental - STEER/AliAODCaloCells.h
New version (Mihaela)
[u/mrichter/AliRoot.git] / STEER / AliAODCaloCells.h
... / ...
CommitLineData
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
17class 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
29 void CreateContainer(Short_t nCells);
30 void DeleteContainer();
31 void Sort();
32
33 Bool_t SetCell(Short_t pos, Short_t cellNumber, Double_t amplitude, Double_t time = -1);
34
35 Short_t GetNumberOfCells() const { return fNCells; }
36 void SetNumberOfCells(Int_t n) { fNCells = n ; }
37 inline Bool_t GetCell(Short_t pos, Short_t &cellNumber, Double_t &amplitude, Double_t &time) const;
38 inline Double_t GetCellAmplitude(Short_t cellNumber);
39 inline Short_t GetCellPosition(Short_t cellNumber);
40 inline Double_t GetAmplitude(Short_t pos) const;
41 Double_t GetCellTime(Short_t /*cellNumber*/) {return -1;}
42 inline Short_t GetCellNumber(Short_t pos) const;
43 Double_t GetTime(Short_t /*pos*/) const {return -1;}
44 Bool_t IsEMCAL() const {return (fType == kEMCALCell);}
45 Bool_t IsPHOS() const {return (fType == kPHOSCell);}
46 Char_t GetType() const { return fType;}
47 void SetType(Char_t ttype) { fType=ttype; }
48
49
50 protected:
51 Int_t fNCells; // Number of cells
52 Short_t *fCellNumber; //[fNCells] array of cell numbers
53 Double32_t *fAmplitude; //[fNCells][0.,0.,16] array with cell amplitudes (= energy!)
54 Bool_t fIsSorted; //! true if cell arrays are sorted by index
55 Char_t fType; // Cell type
56
57
58 ClassDef(AliAODCaloCells, 2);
59};
60
61
62Bool_t AliAODCaloCells::GetCell(Short_t pos, Short_t &cellNumber, Double_t &amplitude, Double_t& /*time*/) const
63{
64 if (pos>=0 && pos<fNCells) {
65 cellNumber = fCellNumber[pos];
66 amplitude = fAmplitude[pos];
67 return kTRUE;
68 } else {
69 Warning("GetCell","Invalid cell array index %d", pos);
70 return kFALSE;
71 }
72}
73
74
75Double_t AliAODCaloCells::GetCellAmplitude(Short_t cellNumber)
76{
77 if (!fIsSorted) {
78 Sort();
79 fIsSorted=kTRUE;
80 }
81
82 Short_t pos = TMath::BinarySearch(fNCells, fCellNumber, cellNumber);
83 if (pos>=0 && fCellNumber[pos] == cellNumber) {
84 return fAmplitude[pos];
85 } else {
86 return 0.;
87 }
88}
89
90
91Double_t AliAODCaloCells::GetAmplitude(Short_t pos) const
92{
93 if (pos>=0 && pos<fNCells) {
94 return fAmplitude[pos];
95 } else {
96 Warning("GetAmplitude","Invalid cell array index %d", pos);
97 return 0.;
98 }
99}
100
101
102Short_t AliAODCaloCells::GetCellNumber(Short_t pos) const
103{
104 if (pos>=0 && pos<fNCells) {
105 return fCellNumber[pos];
106 } else {
107 Warning("GetCellNumber","Invalid cell array index %d", pos);
108 return fNCells;
109 }
110}
111
112Short_t AliAODCaloCells::GetCellPosition(Short_t cellNumber)
113{
114 if (!fIsSorted) {
115 Sort();
116 fIsSorted=kTRUE;
117 }
118
119 Int_t nabove, nbelow, middle;
120 Short_t pos = -1;
121
122 nabove = fNCells + 1;
123 nbelow = 0;
124 while (nabove - nbelow > 1) {
125 middle = (nabove + nbelow) / 2;
126 if (cellNumber == fCellNumber[middle-1]) {
127 pos = middle - 1;
128 break;
129 }
130 if (cellNumber < fCellNumber[middle-1]) nabove = middle;
131 else nbelow = middle;
132 }
133
134 return pos;
135}
136
137
138#endif