AliRunDigitizer: a few bugs fixed to run under
[u/mrichter/AliRoot.git] / HLT / hough / AliL3Histogram.cxx
CommitLineData
18758be6 1//Author: Anders Strand Vestbo
2//Last Modified: 28.6.01
4de874d1 3
18758be6 4#include "AliL3Logging.h"
4de874d1 5#include "AliL3Histogram.h"
6
18758be6 7//2D histogram class.
8
4de874d1 9ClassImp(AliL3Histogram)
10
4de874d1 11AliL3Histogram::AliL3Histogram()
12{
18758be6 13 fNxbins = 0;
14 fNybins = 0;
15 fNcells = 0;
16 fXmin = 0;
17 fYmin = 0;
18 fXmax = 0;
19 fYmax = 0;
4cafa5fc 20 fFirstXbin = 0;
21 fLastXbin = 0;
22 fFirstYbin = 0;
23 fLastYbin = 0;
18758be6 24 fEntries = 0;
25 fContent = 0;
e1842819 26 fThreshold = 0;
4de874d1 27}
28
18758be6 29
e1842819 30AliL3Histogram::AliL3Histogram(Char_t *name,Char_t *id,
31 Int_t nxbin,Double_t xmin,Double_t xmax,
32 Int_t nybin,Double_t ymin,Double_t ymax)
18758be6 33{
34
35 strcpy(fName,name);
36 fNxbins = nxbin;
37 fNybins = nybin;
38 fNcells = (nxbin+2)*(nybin+2);
39
40 fXmin = xmin;
41 fYmin = ymin;
42 fXmax = xmax;
43 fYmax = ymax;
44 fEntries = 0;
4cafa5fc 45 fFirstXbin = 1;
46 fFirstYbin = 1;
47 fLastXbin = nxbin;
48 fLastYbin = nybin;
36d25d02 49#ifdef use_root
4cafa5fc 50 fRootHisto = 0;
36d25d02 51#endif
e1842819 52 fThreshold = 0;
4cafa5fc 53
18758be6 54 fContent = new Double_t[fNcells];
55 Reset();
56}
4de874d1 57
58AliL3Histogram::~AliL3Histogram()
59{
60 //Destructor
18758be6 61 if(fContent)
62 delete [] fContent;
36d25d02 63
64#ifdef use_root
4cafa5fc 65 if(fRootHisto)
66 delete fRootHisto;
36d25d02 67#endif
68
18758be6 69}
70
4de874d1 71
18758be6 72void AliL3Histogram::Reset()
73{
74
75 for(Int_t i=0; i<fNcells; i++)
76 fContent[i] = 0;
77 fEntries=0;
78}
79
80void AliL3Histogram::Fill(Double_t x,Double_t y,Int_t weight)
81{
82 Int_t bin = FindBin(x,y);
83 AddBinContent(bin,weight);
84
85}
86
87Int_t AliL3Histogram::FindBin(Double_t x,Double_t y)
4cafa5fc 88{
89
90 Int_t xbin = FindXbin(x);
91 Int_t ybin = FindYbin(y);
7a21af2f 92
4cafa5fc 93 return GetBin(xbin,ybin);
94}
95
96Int_t AliL3Histogram::FindXbin(Double_t x)
18758be6 97{
98 if(x < fXmin || x > fXmax)
7a21af2f 99 return 0;
4cafa5fc 100
101 return 1 + (Int_t)(fNxbins*(x-fXmin)/(fXmax-fXmin));
102
103}
104
105Int_t AliL3Histogram::FindYbin(Double_t y)
106{
18758be6 107 if(y < fYmin || y > fYmax)
7a21af2f 108 return 0;
18758be6 109
4cafa5fc 110 return 1 + (Int_t)(fNybins*(y-fYmin)/(fYmax-fYmin));
18758be6 111
4cafa5fc 112}
113
114Int_t AliL3Histogram::GetBin(Int_t xbin,Int_t ybin)
115{
116 if(xbin < 0 || xbin > GetLastXbin())
117 {
118 LOG(AliL3Log::kError,"AliL3Histogram::GetBin","array")<<AliL3Log::kDec<<
119 "xbin out of range "<<xbin<<ENDLOG;
120 return 0;
121 }
122 if(ybin < 0 || ybin > GetLastYbin())
123 {
124 LOG(AliL3Log::kError,"AliL3Histogram::FindYbin","array")<<AliL3Log::kDec<<
125 "ybin out of range "<<xbin<<ENDLOG;
126 return 0;
127 }
128
18758be6 129 return xbin + ybin*(fNxbins+2);
4cafa5fc 130}
131
132Double_t AliL3Histogram::GetBinContent(Int_t bin)
133{
134 if(bin >= fNcells)
135 {
136 LOG(AliL3Log::kError,"AliL3Histogram::GetBinContent","array")<<AliL3Log::kDec<<
137 "bin out of range "<<bin<<ENDLOG;
138 return 0;
139 }
140
e1842819 141 if(fContent[bin] < fThreshold)
142 return 0;
4cafa5fc 143 return fContent[bin];
144}
145
7a21af2f 146void AliL3Histogram::SetBinContent(Int_t xbin,Int_t ybin,Int_t value)
4cafa5fc 147{
148 Int_t bin = GetBin(xbin,ybin);
7a21af2f 149 if(bin == 0)
150 return;
151 SetBinContent(bin,value);
4cafa5fc 152}
153
7a21af2f 154void AliL3Histogram::SetBinContent(Int_t bin,Int_t value)
4cafa5fc 155{
156
157 if(bin >= fNcells)
158 {
159 LOG(AliL3Log::kError,"AliL3Histogram::SetBinContent","array")<<AliL3Log::kDec<<
160 "bin out of range "<<bin<<ENDLOG;
161 return;
162 }
7a21af2f 163 if(bin == 0)
164 return;
165 fContent[bin]=value;
18758be6 166
167}
168
169void AliL3Histogram::AddBinContent(Int_t xbin,Int_t ybin,Int_t weight)
170{
4cafa5fc 171 Int_t bin = GetBin(xbin,ybin);
7a21af2f 172 if(bin == 0)
173 return;
18758be6 174 AddBinContent(bin,weight);
175
176}
177
178void AliL3Histogram::AddBinContent(Int_t bin,Int_t weight)
179{
180 if(bin < 0 || bin > fNcells)
181 {
182 LOG(AliL3Log::kError,"AliL3Histogram::AddBinContent","array")<<AliL3Log::kDec<<
183 "bin-value out of range "<<bin<<ENDLOG;
184 return;
185 }
7a21af2f 186 if(bin == 0)
187 return;
18758be6 188 fEntries++;
189 fContent[bin] += weight;
190}
191
ad11f553 192void AliL3Histogram::Add(AliL3Histogram *h1,Double_t weight)
193{
194 //Adding two histograms. Should be identical.
195
196 if(!h1)
197 {
198 LOG(AliL3Log::kError,"AliL3Histogram::Add","Pointer")<<
199 "Attempting to add a non-existing histogram"<<ENDLOG;
200 return;
201 }
202
203 if(h1->GetNbinsX()!=fNxbins || h1->GetNbinsY()!=fNybins)
204 {
205 LOG(AliL3Log::kError,"AliL3Histogram::Add","array")<<
206 "Mismatch in the number of bins "<<ENDLOG;
207 return;
208 }
209 if(h1->GetFirstXbin()!=fFirstXbin || h1->GetLastXbin()!=fLastXbin ||
210 h1->GetFirstYbin()!=fFirstYbin || h1->GetLastYbin()!=fLastYbin)
211 {
212 LOG(AliL3Log::kError,"AliL3Histogram::Add","array")<<
213 "Mismatch in the bin numbering "<<ENDLOG;
214 return;
215 }
216
217 for(Int_t bin=0; bin<fNcells; bin++)
218 fContent[bin] += h1->GetBinContent(bin);
219
220}
221
4cafa5fc 222Double_t AliL3Histogram::GetBinCenterX(Int_t xbin)
18758be6 223{
224
225 Double_t binwidth = (fXmax - fXmin) / fNxbins;
226 return fXmin + (xbin-1) * binwidth + 0.5*binwidth;
227
228}
229
4cafa5fc 230Double_t AliL3Histogram::GetBinCenterY(Int_t ybin)
18758be6 231{
232
233 Double_t binwidth = (fYmax - fYmin) / fNybins;
234 return fYmin + (ybin-1) * binwidth + 0.5*binwidth;
235
236}
237
36d25d02 238#ifdef use_root
4cafa5fc 239void AliL3Histogram::Draw(Char_t *option)
18758be6 240{
4cafa5fc 241 fRootHisto = new TH2F(fName,"",fNxbins,fXmin,fXmax,fNybins,fYmin,fYmax);
18758be6 242 for(Int_t bin=0; bin<fNcells; bin++)
243 {
e1842819 244 fRootHisto->AddBinContent(bin,GetBinContent(bin));
18758be6 245 }
18758be6 246
4cafa5fc 247 fRootHisto->Draw(option);
248
4de874d1 249}
36d25d02 250#endif