]>
Commit | Line | Data |
---|---|---|
95a00d93 | 1 | //$Id$ |
2 | ||
b1886074 | 3 | // Author: Anders Vestbo <mailto:vestbo@fi.uib.no> |
4 | //*-- Copyright © ASV | |
4de874d1 | 5 | |
e4a2d541 | 6 | #include "AliL3StandardIncludes.h" |
18758be6 | 7 | #include "AliL3Logging.h" |
4de874d1 | 8 | #include "AliL3Histogram.h" |
9 | ||
e06900d5 | 10 | #if GCCVERSION == 3 |
11 | using namespace std; | |
12 | #endif | |
13 | ||
b1886074 | 14 | //_____________________________________________________________ |
15 | // AliL3Histogram | |
16 | // | |
17 | // 2D histogram class | |
18758be6 | 18 | |
4de874d1 | 19 | ClassImp(AliL3Histogram) |
20 | ||
4de874d1 | 21 | AliL3Histogram::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 | 44 | AliL3Histogram::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 | |
74 | AliL3Histogram::~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 | 85 | void 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 | ||
93 | void 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 | ||
99 | Int_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 | ||
107 | Int_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 | ||
115 | Int_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 | ||
123 | Int_t AliL3Histogram::GetBin(Int_t xbin,Int_t ybin) | |
124 | { | |
125 | if(xbin < 0 || xbin > GetLastXbin()) | |
126 | { | |
127 | LOG(AliL3Log::kError,"AliL3Histogram::GetBin","array")<<AliL3Log::kDec<< | |
128 | "xbin out of range "<<xbin<<ENDLOG; | |
129 | return 0; | |
130 | } | |
e06900d5 | 131 | |
4cafa5fc | 132 | if(ybin < 0 || ybin > GetLastYbin()) |
133 | { | |
6b9816d6 | 134 | LOG(AliL3Log::kError,"AliL3Histogram::Getbin","array")<<AliL3Log::kDec<< |
4cafa5fc | 135 | "ybin out of range "<<xbin<<ENDLOG; |
136 | return 0; | |
137 | } | |
138 | ||
18758be6 | 139 | return xbin + ybin*(fNxbins+2); |
4cafa5fc | 140 | } |
141 | ||
cfc41e5b | 142 | Int_t AliL3Histogram::GetBinContent(Int_t bin) |
4cafa5fc | 143 | { |
144 | if(bin >= fNcells) | |
145 | { | |
146 | LOG(AliL3Log::kError,"AliL3Histogram::GetBinContent","array")<<AliL3Log::kDec<< | |
147 | "bin out of range "<<bin<<ENDLOG; | |
148 | return 0; | |
149 | } | |
150 | ||
e1842819 | 151 | if(fContent[bin] < fThreshold) |
152 | return 0; | |
4cafa5fc | 153 | return fContent[bin]; |
154 | } | |
155 | ||
7a21af2f | 156 | void AliL3Histogram::SetBinContent(Int_t xbin,Int_t ybin,Int_t value) |
4cafa5fc | 157 | { |
158 | Int_t bin = GetBin(xbin,ybin); | |
7a21af2f | 159 | if(bin == 0) |
160 | return; | |
161 | SetBinContent(bin,value); | |
4cafa5fc | 162 | } |
163 | ||
7a21af2f | 164 | void AliL3Histogram::SetBinContent(Int_t bin,Int_t value) |
4cafa5fc | 165 | { |
166 | ||
167 | if(bin >= fNcells) | |
168 | { | |
169 | LOG(AliL3Log::kError,"AliL3Histogram::SetBinContent","array")<<AliL3Log::kDec<< | |
170 | "bin out of range "<<bin<<ENDLOG; | |
171 | return; | |
172 | } | |
e06900d5 | 173 | |
7a21af2f | 174 | if(bin == 0) |
175 | return; | |
176 | fContent[bin]=value; | |
18758be6 | 177 | } |
178 | ||
179 | void AliL3Histogram::AddBinContent(Int_t xbin,Int_t ybin,Int_t weight) | |
180 | { | |
4cafa5fc | 181 | Int_t bin = GetBin(xbin,ybin); |
7a21af2f | 182 | if(bin == 0) |
183 | return; | |
18758be6 | 184 | AddBinContent(bin,weight); |
18758be6 | 185 | } |
186 | ||
187 | void AliL3Histogram::AddBinContent(Int_t bin,Int_t weight) | |
188 | { | |
189 | if(bin < 0 || bin > fNcells) | |
190 | { | |
191 | LOG(AliL3Log::kError,"AliL3Histogram::AddBinContent","array")<<AliL3Log::kDec<< | |
192 | "bin-value out of range "<<bin<<ENDLOG; | |
193 | return; | |
194 | } | |
7a21af2f | 195 | if(bin == 0) |
196 | return; | |
18758be6 | 197 | fEntries++; |
198 | fContent[bin] += weight; | |
199 | } | |
200 | ||
ad11f553 | 201 | void AliL3Histogram::Add(AliL3Histogram *h1,Double_t weight) |
202 | { | |
203 | //Adding two histograms. Should be identical. | |
204 | ||
205 | if(!h1) | |
206 | { | |
207 | LOG(AliL3Log::kError,"AliL3Histogram::Add","Pointer")<< | |
208 | "Attempting to add a non-existing histogram"<<ENDLOG; | |
209 | return; | |
210 | } | |
211 | ||
212 | if(h1->GetNbinsX()!=fNxbins || h1->GetNbinsY()!=fNybins) | |
213 | { | |
214 | LOG(AliL3Log::kError,"AliL3Histogram::Add","array")<< | |
215 | "Mismatch in the number of bins "<<ENDLOG; | |
216 | return; | |
217 | } | |
218 | if(h1->GetFirstXbin()!=fFirstXbin || h1->GetLastXbin()!=fLastXbin || | |
219 | h1->GetFirstYbin()!=fFirstYbin || h1->GetLastYbin()!=fLastYbin) | |
220 | { | |
221 | LOG(AliL3Log::kError,"AliL3Histogram::Add","array")<< | |
222 | "Mismatch in the bin numbering "<<ENDLOG; | |
223 | return; | |
224 | } | |
225 | ||
226 | for(Int_t bin=0; bin<fNcells; bin++) | |
227 | fContent[bin] += h1->GetBinContent(bin); | |
228 | ||
e7139de1 | 229 | fEntries += h1->GetNEntries(); |
ad11f553 | 230 | } |
231 | ||
4cafa5fc | 232 | Double_t AliL3Histogram::GetBinCenterX(Int_t xbin) |
18758be6 | 233 | { |
e06900d5 | 234 | // return fXmin + (xbin-1) * fBinwidthX + 0.5*fBinwidthX; |
235 | return fXmin + (xbin-0.5) * fBinwidthX; | |
18758be6 | 236 | } |
237 | ||
4cafa5fc | 238 | Double_t AliL3Histogram::GetBinCenterY(Int_t ybin) |
18758be6 | 239 | { |
e06900d5 | 240 | // return fYmin + (ybin-1) * fBinwidthY + 0.5*fBinwidthY; |
241 | return fYmin + (ybin-0.5) * fBinwidthY; | |
18758be6 | 242 | } |
243 | ||
4cafa5fc | 244 | void AliL3Histogram::Draw(Char_t *option) |
18758be6 | 245 | { |
237d3f5c | 246 | #ifdef use_root |
7b9d6d4e | 247 | if(!fRootHisto) |
248 | CreateRootHisto(); | |
18758be6 | 249 | for(Int_t bin=0; bin<fNcells; bin++) |
250 | { | |
e1842819 | 251 | fRootHisto->AddBinContent(bin,GetBinContent(bin)); |
18758be6 | 252 | } |
18758be6 | 253 | |
b46b53c1 | 254 | fRootHisto->SetStats(kFALSE); |
4cafa5fc | 255 | fRootHisto->Draw(option); |
237d3f5c | 256 | return; |
257 | #endif | |
258 | cerr<<"AliL3Histogram::Draw : You need to compile with ROOT in order to draw histogram"<<endl; | |
4cafa5fc | 259 | |
4de874d1 | 260 | } |
7b9d6d4e | 261 | |
262 | void AliL3Histogram::CreateRootHisto() | |
263 | { | |
264 | #ifdef use_root | |
265 | fRootHisto = new TH2F(fName,"",fNxbins,fXmin,fXmax,fNybins,fYmin,fYmax); | |
266 | return; | |
267 | #endif | |
268 | cerr<<"AliL3Histogram::CreateRootHisto : You need to compile with ROOT in order to create ROOT histogram"<<endl; | |
269 | } |