]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/hough/AliL3Histogram.cxx
Moved to hlt-cern branch, containing fixes since August 03 and upcoming changes for...
[u/mrichter/AliRoot.git] / HLT / hough / AliL3Histogram.cxx
CommitLineData
3e87ef69 1// @(#) $Id$
95a00d93 2
b1886074 3// Author: Anders Vestbo <mailto:vestbo@fi.uib.no>
3e87ef69 4//*-- Copyright &copy ALICE HLT Group
4de874d1 5
e4a2d541 6#include "AliL3StandardIncludes.h"
18758be6 7#include "AliL3Logging.h"
4de874d1 8#include "AliL3Histogram.h"
9
e06900d5 10#if GCCVERSION == 3
11using namespace std;
12#endif
13
b1886074 14//_____________________________________________________________
15// AliL3Histogram
16//
17// 2D histogram class
18758be6 18
4de874d1 19ClassImp(AliL3Histogram)
20
4de874d1 21AliL3Histogram::AliL3Histogram()
22{
18758be6 23 fNxbins = 0;
24 fNybins = 0;
25 fNcells = 0;
26 fXmin = 0;
27 fYmin = 0;
28 fXmax = 0;
29 fYmax = 0;
e06900d5 30 fBinwidthX = 0;
31 fBinwidthY = 0;
4cafa5fc 32 fFirstXbin = 0;
33 fLastXbin = 0;
34 fFirstYbin = 0;
35 fLastYbin = 0;
18758be6 36 fEntries = 0;
37 fContent = 0;
e1842819 38 fThreshold = 0;
6b9816d6 39#ifdef use_root
40 fRootHisto = 0;
41#endif
4de874d1 42}
43
e1842819 44AliL3Histogram::AliL3Histogram(Char_t *name,Char_t *id,
45 Int_t nxbin,Double_t xmin,Double_t xmax,
46 Int_t nybin,Double_t ymin,Double_t ymax)
18758be6 47{
18758be6 48 strcpy(fName,name);
e06900d5 49
18758be6 50 fNxbins = nxbin;
51 fNybins = nybin;
52 fNcells = (nxbin+2)*(nybin+2);
18758be6 53 fXmin = xmin;
54 fYmin = ymin;
55 fXmax = xmax;
56 fYmax = ymax;
e06900d5 57 fBinwidthX = (fXmax - fXmin) / fNxbins;
58 fBinwidthY = (fYmax - fYmin) / fNybins;
59
18758be6 60 fEntries = 0;
4cafa5fc 61 fFirstXbin = 1;
62 fFirstYbin = 1;
63 fLastXbin = nxbin;
64 fLastYbin = nybin;
36d25d02 65#ifdef use_root
4cafa5fc 66 fRootHisto = 0;
36d25d02 67#endif
e1842819 68 fThreshold = 0;
4cafa5fc 69
cfc41e5b 70 fContent = new Int_t[fNcells];
18758be6 71 Reset();
72}
4de874d1 73
74AliL3Histogram::~AliL3Histogram()
75{
76 //Destructor
18758be6 77 if(fContent)
78 delete [] fContent;
36d25d02 79#ifdef use_root
4cafa5fc 80 if(fRootHisto)
81 delete fRootHisto;
36d25d02 82#endif
18758be6 83}
84
18758be6 85void AliL3Histogram::Reset()
86{
e06900d5 87 if(fContent)
88 for(Int_t i=0; i<fNcells; i++) fContent[i] = 0;
89
18758be6 90 fEntries=0;
91}
92
93void AliL3Histogram::Fill(Double_t x,Double_t y,Int_t weight)
94{
95 Int_t bin = FindBin(x,y);
96 AddBinContent(bin,weight);
18758be6 97}
98
99Int_t AliL3Histogram::FindBin(Double_t x,Double_t y)
4cafa5fc 100{
4cafa5fc 101 Int_t xbin = FindXbin(x);
102 Int_t ybin = FindYbin(y);
7a21af2f 103
4cafa5fc 104 return GetBin(xbin,ybin);
105}
106
107Int_t AliL3Histogram::FindXbin(Double_t x)
18758be6 108{
109 if(x < fXmin || x > fXmax)
7a21af2f 110 return 0;
4cafa5fc 111
112 return 1 + (Int_t)(fNxbins*(x-fXmin)/(fXmax-fXmin));
4cafa5fc 113}
114
115Int_t AliL3Histogram::FindYbin(Double_t y)
116{
18758be6 117 if(y < fYmin || y > fYmax)
7a21af2f 118 return 0;
18758be6 119
4cafa5fc 120 return 1 + (Int_t)(fNybins*(y-fYmin)/(fYmax-fYmin));
4cafa5fc 121}
122
123Int_t AliL3Histogram::GetBin(Int_t xbin,Int_t ybin)
124{
0a86fbb7 125 if(xbin < fFirstXbin || xbin > fLastXbin)
126 return 0;
127 if(ybin < fFirstYbin || ybin > fLastYbin)
128 return 0;
4cafa5fc 129
18758be6 130 return xbin + ybin*(fNxbins+2);
4cafa5fc 131}
132
cfc41e5b 133Int_t AliL3Histogram::GetBinContent(Int_t bin)
4cafa5fc 134{
135 if(bin >= fNcells)
136 {
137 LOG(AliL3Log::kError,"AliL3Histogram::GetBinContent","array")<<AliL3Log::kDec<<
138 "bin out of range "<<bin<<ENDLOG;
139 return 0;
140 }
141
e1842819 142 if(fContent[bin] < fThreshold)
143 return 0;
4cafa5fc 144 return fContent[bin];
145}
146
7a21af2f 147void AliL3Histogram::SetBinContent(Int_t xbin,Int_t ybin,Int_t value)
4cafa5fc 148{
149 Int_t bin = GetBin(xbin,ybin);
7a21af2f 150 if(bin == 0)
151 return;
152 SetBinContent(bin,value);
4cafa5fc 153}
154
7a21af2f 155void AliL3Histogram::SetBinContent(Int_t bin,Int_t value)
4cafa5fc 156{
157
158 if(bin >= fNcells)
159 {
160 LOG(AliL3Log::kError,"AliL3Histogram::SetBinContent","array")<<AliL3Log::kDec<<
161 "bin out of range "<<bin<<ENDLOG;
162 return;
163 }
e06900d5 164
7a21af2f 165 if(bin == 0)
166 return;
167 fContent[bin]=value;
18758be6 168}
169
170void AliL3Histogram::AddBinContent(Int_t xbin,Int_t ybin,Int_t weight)
171{
4cafa5fc 172 Int_t bin = GetBin(xbin,ybin);
7a21af2f 173 if(bin == 0)
174 return;
18758be6 175 AddBinContent(bin,weight);
18758be6 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
e7139de1 220 fEntries += h1->GetNEntries();
ad11f553 221}
222
4cafa5fc 223Double_t AliL3Histogram::GetBinCenterX(Int_t xbin)
18758be6 224{
0a86fbb7 225 if(xbin < fFirstXbin || xbin > fLastXbin)
226 {
227 LOG(AliL3Log::kError,"AliL3Histogram::GetBinCenterX","xbin")
228 <<"Bin-value out of range "<<xbin<<ENDLOG;
229 return -1;
230 }
e06900d5 231 // return fXmin + (xbin-1) * fBinwidthX + 0.5*fBinwidthX;
232 return fXmin + (xbin-0.5) * fBinwidthX;
18758be6 233}
234
4cafa5fc 235Double_t AliL3Histogram::GetBinCenterY(Int_t ybin)
18758be6 236{
0a86fbb7 237 if(ybin < fFirstYbin || ybin > fLastYbin)
238 {
239 LOG(AliL3Log::kError,"AliL3Histogram::GetBinCenterY","ybin")
240 <<"Bin-value out of range "<<ybin<<ENDLOG;
241 return -1;
242 }
e06900d5 243 // return fYmin + (ybin-1) * fBinwidthY + 0.5*fBinwidthY;
244 return fYmin + (ybin-0.5) * fBinwidthY;
18758be6 245}
246
4cafa5fc 247void AliL3Histogram::Draw(Char_t *option)
18758be6 248{
237d3f5c 249#ifdef use_root
7b9d6d4e 250 if(!fRootHisto)
251 CreateRootHisto();
3e87ef69 252
253 for(Int_t xbin=GetFirstXbin(); xbin<=GetLastXbin(); xbin++)
18758be6 254 {
3e87ef69 255 for(Int_t ybin=GetFirstYbin(); ybin<=GetLastYbin(); ybin++)
256 {
257 Int_t bin = GetBin(xbin,ybin);
258 fRootHisto->Fill(GetBinCenterX(xbin),GetBinCenterY(ybin),GetBinContent(bin));
259 }
18758be6 260 }
18758be6 261
3e87ef69 262 //fRootHisto->SetStats(kFALSE);
4cafa5fc 263 fRootHisto->Draw(option);
237d3f5c 264 return;
265#endif
266 cerr<<"AliL3Histogram::Draw : You need to compile with ROOT in order to draw histogram"<<endl;
4cafa5fc 267
4de874d1 268}
7b9d6d4e 269
270void AliL3Histogram::CreateRootHisto()
271{
272#ifdef use_root
273 fRootHisto = new TH2F(fName,"",fNxbins,fXmin,fXmax,fNybins,fYmin,fYmax);
274 return;
275#endif
276 cerr<<"AliL3Histogram::CreateRootHisto : You need to compile with ROOT in order to create ROOT histogram"<<endl;
277}