]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/hough/AliL3Histogram.cxx
Major changes
[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;
4de874d1 26}
27
18758be6 28
4cafa5fc 29AliL3Histogram::AliL3Histogram(Char_t *name,Char_t *id,Int_t nxbin,Double_t xmin,Double_t xmax,Int_t nybin,Double_t ymin,Double_t ymax)
18758be6 30{
31
32 strcpy(fName,name);
33 fNxbins = nxbin;
34 fNybins = nybin;
35 fNcells = (nxbin+2)*(nybin+2);
36
37 fXmin = xmin;
38 fYmin = ymin;
39 fXmax = xmax;
40 fYmax = ymax;
41 fEntries = 0;
4cafa5fc 42 fFirstXbin = 1;
43 fFirstYbin = 1;
44 fLastXbin = nxbin;
45 fLastYbin = nybin;
46 fRootHisto = 0;
47
18758be6 48 fContent = new Double_t[fNcells];
49 Reset();
50}
4de874d1 51
52AliL3Histogram::~AliL3Histogram()
53{
54 //Destructor
18758be6 55 if(fContent)
56 delete [] fContent;
4cafa5fc 57 if(fRootHisto)
58 delete fRootHisto;
18758be6 59}
60
4de874d1 61
18758be6 62void AliL3Histogram::Reset()
63{
64
65 for(Int_t i=0; i<fNcells; i++)
66 fContent[i] = 0;
67 fEntries=0;
68}
69
70void AliL3Histogram::Fill(Double_t x,Double_t y,Int_t weight)
71{
72 Int_t bin = FindBin(x,y);
73 AddBinContent(bin,weight);
74
75}
76
77Int_t AliL3Histogram::FindBin(Double_t x,Double_t y)
4cafa5fc 78{
79
80 Int_t xbin = FindXbin(x);
81 Int_t ybin = FindYbin(y);
82
83 return GetBin(xbin,ybin);
84}
85
86Int_t AliL3Histogram::FindXbin(Double_t x)
18758be6 87{
88 if(x < fXmin || x > fXmax)
89 {
4cafa5fc 90 LOG(AliL3Log::kError,"AliL3Histogram::FindXbin","array")<<AliL3Log::kDec<<
18758be6 91 "x-value out of range "<<x<<ENDLOG;
92 return 0;
93 }
4cafa5fc 94
95 return 1 + (Int_t)(fNxbins*(x-fXmin)/(fXmax-fXmin));
96
97}
98
99Int_t AliL3Histogram::FindYbin(Double_t y)
100{
18758be6 101 if(y < fYmin || y > fYmax)
102 {
4cafa5fc 103 LOG(AliL3Log::kError,"AliL3Histogram::FindYbin","array")<<AliL3Log::kDec<<
18758be6 104 "y-value out of range "<<y<<ENDLOG;
105 return 0;
106 }
107
4cafa5fc 108 return 1 + (Int_t)(fNybins*(y-fYmin)/(fYmax-fYmin));
18758be6 109
4cafa5fc 110}
111
112Int_t AliL3Histogram::GetBin(Int_t xbin,Int_t ybin)
113{
114 if(xbin < 0 || xbin > GetLastXbin())
115 {
116 LOG(AliL3Log::kError,"AliL3Histogram::GetBin","array")<<AliL3Log::kDec<<
117 "xbin out of range "<<xbin<<ENDLOG;
118 return 0;
119 }
120 if(ybin < 0 || ybin > GetLastYbin())
121 {
122 LOG(AliL3Log::kError,"AliL3Histogram::FindYbin","array")<<AliL3Log::kDec<<
123 "ybin out of range "<<xbin<<ENDLOG;
124 return 0;
125 }
126
18758be6 127 return xbin + ybin*(fNxbins+2);
4cafa5fc 128}
129
130Double_t AliL3Histogram::GetBinContent(Int_t bin)
131{
132 if(bin >= fNcells)
133 {
134 LOG(AliL3Log::kError,"AliL3Histogram::GetBinContent","array")<<AliL3Log::kDec<<
135 "bin out of range "<<bin<<ENDLOG;
136 return 0;
137 }
138
139 return fContent[bin];
140}
141
142void AliL3Histogram::SetBinContent(Int_t xbin,Int_t ybin)
143{
144 Int_t bin = GetBin(xbin,ybin);
145 SetBinContent(bin);
146}
147
148void AliL3Histogram::SetBinContent(Int_t bin)
149{
150
151 if(bin >= fNcells)
152 {
153 LOG(AliL3Log::kError,"AliL3Histogram::SetBinContent","array")<<AliL3Log::kDec<<
154 "bin out of range "<<bin<<ENDLOG;
155 return;
156 }
157 fContent[bin]=0;
18758be6 158
159}
160
161void AliL3Histogram::AddBinContent(Int_t xbin,Int_t ybin,Int_t weight)
162{
4cafa5fc 163 Int_t bin = GetBin(xbin,ybin);
18758be6 164 AddBinContent(bin,weight);
165
166}
167
168void AliL3Histogram::AddBinContent(Int_t bin,Int_t weight)
169{
170 if(bin < 0 || bin > fNcells)
171 {
172 LOG(AliL3Log::kError,"AliL3Histogram::AddBinContent","array")<<AliL3Log::kDec<<
173 "bin-value out of range "<<bin<<ENDLOG;
174 return;
175 }
176 fEntries++;
177 fContent[bin] += weight;
178}
179
4cafa5fc 180Double_t AliL3Histogram::GetBinCenterX(Int_t xbin)
18758be6 181{
182
183 Double_t binwidth = (fXmax - fXmin) / fNxbins;
184 return fXmin + (xbin-1) * binwidth + 0.5*binwidth;
185
186}
187
4cafa5fc 188Double_t AliL3Histogram::GetBinCenterY(Int_t ybin)
18758be6 189{
190
191 Double_t binwidth = (fYmax - fYmin) / fNybins;
192 return fYmin + (ybin-1) * binwidth + 0.5*binwidth;
193
194}
195
196
4cafa5fc 197void AliL3Histogram::Draw(Char_t *option)
18758be6 198{
4cafa5fc 199 fRootHisto = new TH2F(fName,"",fNxbins,fXmin,fXmax,fNybins,fYmin,fYmax);
18758be6 200 for(Int_t bin=0; bin<fNcells; bin++)
201 {
4cafa5fc 202 fRootHisto->AddBinContent(bin,fContent[bin]);
18758be6 203 }
204 //printf("ncells %d %d\n",(hist->GetNbinsX()+2)*(hist->GetNbinsY()+2),fNcells);
18758be6 205
4cafa5fc 206 fRootHisto->Draw(option);
207
4de874d1 208}