Logo ROOT  
Reference Guide
th2polyBoxes.C File Reference

Detailed Description

View in nbviewer Open in SWAN This tutorial illustrates how to create an histogram with polygonal bins (TH2Poly).

The bins are boxes.

TCanvas *th2polyBoxes() {
TCanvas *ch2p2 = new TCanvas("ch2p2","ch2p2",600,400);
TH2Poly *h2p = new TH2Poly();
h2p->SetName("Boxes");
h2p->SetTitle("Boxes");
Int_t i,j;
Int_t nx = 40;
Int_t ny = 40;
Double_t xval1,yval1,xval2,yval2;
Double_t dx=0.2, dy=0.1;
xval1 = 0.;
xval2 = dx;
for (i = 0; i<nx; i++) {
yval1 = 0.;
yval2 = dy;
for (j = 0; j<ny; j++) {
h2p->AddBin(xval1, yval1, xval2, yval2);
yval1 = yval2;
yval2 = yval2+yval2*dy;
}
xval1 = xval2;
xval2 = xval2+xval2*dx;
}
TRandom ran;
for (i = 0; i<300000; i++) {
h2p->Fill(50*ran.Gaus(2.,1), ran.Gaus(2.,1));
}
h2p->Draw("COLZ");
return ch2p2;
}
Author
Olivier Couet

Definition in file th2polyBoxes.C.

TRandom::Gaus
virtual Double_t Gaus(Double_t mean=0, Double_t sigma=1)
Samples a random number from the standard Normal (Gaussian) Distribution with the given mean and sigm...
Definition: TRandom.cxx:274
TH2Poly::AddBin
virtual Int_t AddBin(TObject *poly)
Adds a new bin to the histogram.
Definition: TH2Poly.cxx:222
Int_t
int Int_t
Definition: RtypesCore.h:45
TH1::SetName
virtual void SetName(const char *name)
Change the name of this histogram.
Definition: TH1.cxx:8726
TH1::SetTitle
virtual void SetTitle(const char *title)
See GetStatOverflows for more information.
Definition: TH1.cxx:6655
TRandom
This is the base class for the ROOT Random number generators.
Definition: TRandom.h:27
gStyle
R__EXTERN TStyle * gStyle
Definition: TStyle.h:412
Double_t
double Double_t
Definition: RtypesCore.h:59
TStyle::SetPalette
void SetPalette(Int_t ncolors=kBird, Int_t *colors=0, Float_t alpha=1.)
See TColor::SetPalette.
Definition: TStyle.cxx:1782
TCanvas
The Canvas class.
Definition: TCanvas.h:23
TH2Poly::Fill
virtual Int_t Fill(Double_t x, Double_t y)
Increment the bin containing (x,y) by 1.
Definition: TH2Poly.cxx:589
TH2Poly
2D Histogram with Polygonal Bins
Definition: TH2Poly.h:66
TH1::Draw
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:3050