ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
th2polyBoxes.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_hist
3 /// This tutorial illustrates how to create an histogram with polygonal
4 /// bins (TH2Poly). The bins are boxes.
5 ///
6 /// \macro_image
7 /// \macro_code
8 ///
9 /// \author Olivier Couet
10 
11 {
12  TCanvas *ch2p2 = new TCanvas("ch2p2","ch2p2",600,400);
13  gStyle->SetPalette(57);
14  TH2Poly *h2p = new TH2Poly();
15  h2p->SetName("Boxes");
16  h2p->SetTitle("Boxes");
17 
18  Int_t i,j;
19  Int_t nx = 40;
20  Int_t ny = 40;
21  Double_t x1,y1,x2,y2;
22  Double_t dx=0.2, dy=0.1;
23  x1 = 0.;
24  x2 = dx;
25 
26  for (i = 0; i<nx; i++) {
27  y1 = 0.;
28  y2 = dy;
29  for (j = 0; j<ny; j++) {
30  h2p->AddBin(x1, y1, x2, y2);
31  y1 = y2;
32  y2 = y2+y2*dy;
33  }
34  x1 = x2;
35  x2 = x2+x2*dx;
36  }
37 
38  TRandom ran;
39  for (i = 0; i<300000; i++) {
40  h2p->Fill(50*ran.Gaus(2.,1), ran.Gaus(2.,1));
41  }
42 
43  h2p->Draw("COLZ");
44  return ch2p2;
45 }
const int nx
Definition: kalman.C:16
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:235
R__EXTERN TStyle * gStyle
Definition: TStyle.h:423
int Int_t
Definition: RtypesCore.h:41
static const double x2[5]
This is the base class for the ROOT Random number generators.
Definition: TRandom.h:29
const int ny
Definition: kalman.C:17
Int_t AddBin(TObject *poly)
Adds a new bin to the histogram.
Definition: TH2Poly.cxx:202
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2878
virtual void SetName(const char *name)
Change the name of this histogram.
Definition: TH1.cxx:8288
The Canvas class.
Definition: TCanvas.h:48
static const double x1[5]
double Double_t
Definition: RtypesCore.h:55
virtual void SetTitle(const char *title)
Change (i.e.
Definition: TH1.cxx:6268
void SetPalette(Int_t ncolors=kBird, Int_t *colors=0, Float_t alpha=1.)
See TColor::SetPalette.
Definition: TStyle.cxx:1445
Int_t Fill(Double_t x, Double_t y)
Increment the bin containing (x,y) by 1.
Definition: TH2Poly.cxx:564
2D Histogram with Polygonal Bins
Definition: TH2Poly.h:70