// Author: Anders Vestbo <mailto:vestbo@fi.uib.no>
//*-- Copyright © ALICE HLT Group
-#include <ostream.h>
-
#include "AliL3StandardIncludes.h"
#include "AliL3Logging.h"
#include "AliL3Histogram.h"
-#if GCCVERSION == 3
+#if __GNUC__ >= 3
using namespace std;
#endif
+/** \class AliL3Histogram
+<pre>
//_____________________________________________________________
// AliL3Histogram
//
// 2D histogram class
+//
+</pre>
+*/
+
+//uncomment if you want overflow checks
+//#define _IFON_
ClassImp(AliL3Histogram)
AliL3Histogram::AliL3Histogram()
{
+ // Default constructor
fNxbins = 0;
fNybins = 0;
fNcells = 0;
#endif
}
-AliL3Histogram::AliL3Histogram(Char_t *name,Char_t *id,
+AliL3Histogram::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)
{
+ // Normal constructor
strcpy(fName,name);
fNxbins = nxbin;
void AliL3Histogram::Reset()
{
+ // Reset histogram contents
if(fContent)
for(Int_t i=0; i<fNcells; i++) fContent[i] = 0;
void AliL3Histogram::Fill(Double_t x,Double_t y,Int_t weight)
{
+ // Fill the weight into a bin which correspond to x and y
Int_t bin = FindBin(x,y);
+#ifdef _IFON_
+ if(bin < 0)
+ return;
+#endif
+
+ AddBinContent(bin,weight);
+}
+
+void AliL3Histogram::Fill(Double_t x,Int_t ybin,Int_t weight)
+{
+ // Fill the weight into a bin which correspond to x and ybin
+ Int_t xbin = FindXbin(x);
+ Int_t bin = GetBin(xbin,ybin);
+#ifdef _IFON_
if(bin < 0)
return;
+#endif
+
+ AddBinContent(bin,weight);
+}
+
+void AliL3Histogram::Fill(Int_t xbin,Double_t y,Int_t weight)
+{
+ // Fill the weight into a bin which correspond to xbin and y
+ Int_t ybin = FindYbin(y);
+ Int_t bin = GetBin(xbin,ybin);
+#ifdef _IFON_
+ if(bin < 0)
+ return;
+#endif
+
+ AddBinContent(bin,weight);
+}
+
+void AliL3Histogram::Fill(Int_t xbin,Int_t ybin,Int_t weight)
+{
+ // Fill the weight into a bin which correspond to xbin and ybin
+ Int_t bin = GetBin(xbin,ybin);
+#ifdef _IFON_
+ if(bin < 0)
+ return;
+#endif
AddBinContent(bin,weight);
}
Int_t AliL3Histogram::FindBin(Double_t x,Double_t y) const
{
+ // Finds the bin which correspond to x and y
Int_t xbin = FindXbin(x);
Int_t ybin = FindYbin(y);
+#ifdef _IFON_
if(!xbin || !ybin)
return -1;
+#endif
return GetBin(xbin,ybin);
}
+Int_t AliL3Histogram::FindLabelBin(Double_t x,Double_t y) const
+{
+ // Returns the corresponding bin with the mc labels
+ Int_t xbin = FindXbin(x);
+ Int_t ybin = FindYbin(y);
+#ifdef _IFON_
+ if(!xbin || !ybin)
+ return -1;
+#endif
+
+ return GetLabelBin(xbin,ybin);
+}
+
Int_t AliL3Histogram::FindXbin(Double_t x) const
{
+ // Finds the bin which correspond to x
if(x < fXmin || x > fXmax)
return 0;
Int_t AliL3Histogram::FindYbin(Double_t y) const
{
+ // Finds the bin which correspond to y
if(y < fYmin || y > fYmax)
return 0;
Int_t AliL3Histogram::GetBin(Int_t xbin,Int_t ybin) const
{
+ // Returns the bin which correspond to xbin and ybin
if(xbin < fFirstXbin || xbin > fLastXbin)
return 0;
if(ybin < fFirstYbin || ybin > fLastYbin)
return xbin + ybin*(fNxbins+2);
}
+Int_t AliL3Histogram::GetLabelBin(Int_t xbin,Int_t ybin) const
+{
+ // Returns the corresponding bin with the mc labels
+ if(xbin < fFirstXbin || xbin > fLastXbin)
+ return -1;
+ if(ybin < fFirstYbin || ybin > fLastYbin)
+ return -1;
+
+ return (Int_t)(xbin/2) + ((Int_t)(ybin/2))*((Int_t)((fNxbins+3)/2));
+}
+
Int_t AliL3Histogram::GetBinContent(Int_t bin) const
{
+ // Return the bin content
if(bin >= fNcells)
{
LOG(AliL3Log::kError,"AliL3Histogram::GetBinContent","array")<<AliL3Log::kDec<<
void AliL3Histogram::SetBinContent(Int_t xbin,Int_t ybin,Int_t value)
{
+ // Set bin content
Int_t bin = GetBin(xbin,ybin);
+#ifdef _IFON_
if(bin == 0)
return;
+#endif
+
SetBinContent(bin,value);
}
void AliL3Histogram::SetBinContent(Int_t bin,Int_t value)
{
+ // Set bin content
if(bin >= fNcells)
{
void AliL3Histogram::AddBinContent(Int_t xbin,Int_t ybin,Int_t weight)
{
+ // Adds weight to bin content
Int_t bin = GetBin(xbin,ybin);
+#ifdef _IFON_
if(bin == 0)
return;
+#endif
+
AddBinContent(bin,weight);
}
void AliL3Histogram::AddBinContent(Int_t bin,Int_t weight)
{
+ // Adds weight to bin content
if(bin < 0 || bin > fNcells)
{
LOG(AliL3Log::kError,"AliL3Histogram::AddBinContent","array")<<AliL3Log::kDec<<
fContent[bin] += weight;
}
-void AliL3Histogram::Add(AliL3Histogram *h1,Double_t weight)
+void AliL3Histogram::Add(AliL3Histogram *h1,Double_t /*weight*/)
{
//Adding two histograms. Should be identical.
"Mismatch in the number of bins "<<ENDLOG;
return;
}
+
if(h1->GetFirstXbin()!=fFirstXbin || h1->GetLastXbin()!=fLastXbin ||
h1->GetFirstYbin()!=fFirstYbin || h1->GetLastYbin()!=fLastYbin)
{
Double_t AliL3Histogram::GetBinCenterX(Int_t xbin) const
{
+ // Returns the position of the center of a bin
if(xbin < fFirstXbin || xbin > fLastXbin)
{
LOG(AliL3Log::kError,"AliL3Histogram::GetBinCenterX","xbin")
Double_t AliL3Histogram::GetBinCenterY(Int_t ybin) const
{
+ // Returns the position of the center of a bin
if(ybin < fFirstYbin || ybin > fLastYbin)
{
LOG(AliL3Log::kError,"AliL3Histogram::GetBinCenterY","ybin")
return fYmin + (ybin-0.5) * fBinwidthY;
}
+Double_t AliL3Histogram::GetPreciseBinCenterX(Float_t xbin) const
+{
+ // Returns the position of the center of a bin using precise values inside the bin
+ if(xbin < (fFirstXbin-1.5) || xbin > (fLastXbin+1.5))
+ {
+ LOG(AliL3Log::kError,"AliL3Histogram::GetBinCenterX","xbin")
+ <<"Bin-value out of range "<<xbin<<ENDLOG;
+ return -1;
+ }
+ // return fXmin + (xbin-1) * fBinwidthX + 0.5*fBinwidthX;
+ return fXmin + (xbin-0.5) * fBinwidthX;
+}
+
+Double_t AliL3Histogram::GetPreciseBinCenterY(Float_t ybin) const
+{
+ // Returns the position of the center of a bin using precise values inside the bin
+ if(ybin < (fFirstYbin-1.5) || ybin > (fLastYbin+1.5))
+ {
+ LOG(AliL3Log::kError,"AliL3Histogram::GetBinCenterY","ybin")
+ <<"Bin-value out of range "<<ybin<<ENDLOG;
+ return -1;
+ }
+ // return fYmin + (ybin-1) * fBinwidthY + 0.5*fBinwidthY;
+ return fYmin + (ybin-0.5) * fBinwidthY;
+}
+
void AliL3Histogram::Draw(Char_t *option)
{
+ // Fill the contents of the corresponding ROOT histogram and draws it
#ifdef use_root
if(!fRootHisto)
CreateRootHisto();
//fRootHisto->SetStats(kFALSE);
fRootHisto->Draw(option);
return;
-#endif
+#else
cerr<<"AliL3Histogram::Draw : You need to compile with ROOT in order to draw histogram"<<endl;
-
+#endif
}
void AliL3Histogram::CreateRootHisto()
{
+ // Create ROOT histogram out of AliL3Histogram
#ifdef use_root
fRootHisto = new TH2F(fName,"",fNxbins,fXmin,fXmax,fNybins,fYmin,fYmax);
return;
-#endif
+#else
cerr<<"AliL3Histogram::CreateRootHisto : You need to compile with ROOT in order to create ROOT histogram"<<endl;
+#endif
}
-ostream& operator<<(ostream &o, const AliL3Histogram &h)
+ofstream& operator<<(ofstream &o, const AliL3Histogram &h)
{
for(Int_t xbin=h.GetFirstXbin(); xbin<=h.GetLastXbin(); xbin++)
{