3 // Author: Anders Vestbo <mailto:vestbo@fi.uib.no>
4 //*-- Copyright © ASV
7 #include "AliL3Logging.h"
8 #include "AliL3Histogram.h"
10 //_____________________________________________________________
15 ClassImp(AliL3Histogram)
17 AliL3Histogram::AliL3Histogram()
36 AliL3Histogram::AliL3Histogram(Char_t *name,Char_t *id,
37 Int_t nxbin,Double_t xmin,Double_t xmax,
38 Int_t nybin,Double_t ymin,Double_t ymax)
44 fNcells = (nxbin+2)*(nybin+2);
60 fContent = new Int_t[fNcells];
64 AliL3Histogram::~AliL3Histogram()
78 void AliL3Histogram::Reset()
81 for(Int_t i=0; i<fNcells; i++)
86 void AliL3Histogram::Fill(Double_t x,Double_t y,Int_t weight)
88 Int_t bin = FindBin(x,y);
89 AddBinContent(bin,weight);
93 Int_t AliL3Histogram::FindBin(Double_t x,Double_t y)
96 Int_t xbin = FindXbin(x);
97 Int_t ybin = FindYbin(y);
99 return GetBin(xbin,ybin);
102 Int_t AliL3Histogram::FindXbin(Double_t x)
104 if(x < fXmin || x > fXmax)
107 return 1 + (Int_t)(fNxbins*(x-fXmin)/(fXmax-fXmin));
111 Int_t AliL3Histogram::FindYbin(Double_t y)
113 if(y < fYmin || y > fYmax)
116 return 1 + (Int_t)(fNybins*(y-fYmin)/(fYmax-fYmin));
120 Int_t AliL3Histogram::GetBin(Int_t xbin,Int_t ybin)
122 if(xbin < 0 || xbin > GetLastXbin())
124 LOG(AliL3Log::kError,"AliL3Histogram::GetBin","array")<<AliL3Log::kDec<<
125 "xbin out of range "<<xbin<<ENDLOG;
128 if(ybin < 0 || ybin > GetLastYbin())
130 LOG(AliL3Log::kError,"AliL3Histogram::FindYbin","array")<<AliL3Log::kDec<<
131 "ybin out of range "<<xbin<<ENDLOG;
135 return xbin + ybin*(fNxbins+2);
138 Int_t AliL3Histogram::GetBinContent(Int_t bin)
142 LOG(AliL3Log::kError,"AliL3Histogram::GetBinContent","array")<<AliL3Log::kDec<<
143 "bin out of range "<<bin<<ENDLOG;
147 if(fContent[bin] < fThreshold)
149 return fContent[bin];
152 void AliL3Histogram::SetBinContent(Int_t xbin,Int_t ybin,Int_t value)
154 Int_t bin = GetBin(xbin,ybin);
157 SetBinContent(bin,value);
160 void AliL3Histogram::SetBinContent(Int_t bin,Int_t value)
165 LOG(AliL3Log::kError,"AliL3Histogram::SetBinContent","array")<<AliL3Log::kDec<<
166 "bin out of range "<<bin<<ENDLOG;
175 void AliL3Histogram::AddBinContent(Int_t xbin,Int_t ybin,Int_t weight)
177 Int_t bin = GetBin(xbin,ybin);
180 AddBinContent(bin,weight);
184 void AliL3Histogram::AddBinContent(Int_t bin,Int_t weight)
186 if(bin < 0 || bin > fNcells)
188 LOG(AliL3Log::kError,"AliL3Histogram::AddBinContent","array")<<AliL3Log::kDec<<
189 "bin-value out of range "<<bin<<ENDLOG;
195 fContent[bin] += weight;
198 void AliL3Histogram::Add(AliL3Histogram *h1,Double_t weight)
200 //Adding two histograms. Should be identical.
204 LOG(AliL3Log::kError,"AliL3Histogram::Add","Pointer")<<
205 "Attempting to add a non-existing histogram"<<ENDLOG;
209 if(h1->GetNbinsX()!=fNxbins || h1->GetNbinsY()!=fNybins)
211 LOG(AliL3Log::kError,"AliL3Histogram::Add","array")<<
212 "Mismatch in the number of bins "<<ENDLOG;
215 if(h1->GetFirstXbin()!=fFirstXbin || h1->GetLastXbin()!=fLastXbin ||
216 h1->GetFirstYbin()!=fFirstYbin || h1->GetLastYbin()!=fLastYbin)
218 LOG(AliL3Log::kError,"AliL3Histogram::Add","array")<<
219 "Mismatch in the bin numbering "<<ENDLOG;
223 for(Int_t bin=0; bin<fNcells; bin++)
224 fContent[bin] += h1->GetBinContent(bin);
228 Double_t AliL3Histogram::GetBinCenterX(Int_t xbin)
231 Double_t binwidth = (fXmax - fXmin) / fNxbins;
232 return fXmin + (xbin-1) * binwidth + 0.5*binwidth;
236 Double_t AliL3Histogram::GetBinCenterY(Int_t ybin)
239 Double_t binwidth = (fYmax - fYmin) / fNybins;
240 return fYmin + (ybin-1) * binwidth + 0.5*binwidth;
245 void AliL3Histogram::Draw(Char_t *option)
250 for(Int_t bin=0; bin<fNcells; bin++)
252 fRootHisto->AddBinContent(bin,GetBinContent(bin));
255 fRootHisto->SetStats(kFALSE);
256 fRootHisto->Draw(option);
259 cerr<<"AliL3Histogram::Draw : You need to compile with ROOT in order to draw histogram"<<endl;
263 void AliL3Histogram::CreateRootHisto()
266 fRootHisto = new TH2F(fName,"",fNxbins,fXmin,fXmax,fNybins,fYmin,fYmax);
269 cerr<<"AliL3Histogram::CreateRootHisto : You need to compile with ROOT in order to create ROOT histogram"<<endl;