Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
hist037_TH2Poly_boxes.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_hist
3/// \notebook
4/// This tutorial illustrates how to create an histogram with polygonal
5/// bins (TH2Poly). The bins are boxes.
6///
7/// \macro_image
8/// \macro_code
9///
10/// \date August 2016
11/// \author Olivier Couet
12
14{
15 TCanvas *ch2p2 = new TCanvas("ch2p2", "ch2p2", 600, 400);
16 gStyle->SetPalette(57);
17 TH2Poly *h2p = new TH2Poly();
18 h2p->SetName("Boxes");
19 h2p->SetTitle("Boxes");
20
21 Int_t i, j;
22 Int_t nx = 40;
23 Int_t ny = 40;
25 Double_t dx = 0.2, dy = 0.1;
26 xval1 = 0.;
27 xval2 = dx;
28
29 for (i = 0; i < nx; i++) {
30 yval1 = 0.;
31 yval2 = dy;
32 for (j = 0; j < ny; j++) {
33 h2p->AddBin(xval1, yval1, xval2, yval2);
34 yval1 = yval2;
35 yval2 = yval2 + yval2 * dy;
36 }
37 xval1 = xval2;
38 xval2 = xval2 + xval2 * dx;
39 }
40
42 for (i = 0; i < 300000; i++) {
43 h2p->Fill(50 * ran.Gaus(2., 1), ran.Gaus(2., 1));
44 }
45
46 h2p->Draw("COLZ");
47 return ch2p2;
48}
int Int_t
Definition RtypesCore.h:45
double Double_t
Definition RtypesCore.h:59
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
R__EXTERN TStyle * gStyle
Definition TStyle.h:442
The Canvas class.
Definition TCanvas.h:23
2D Histogram with Polygonal Bins
Definition TH2Poly.h:66
This is the base class for the ROOT Random number generators.
Definition TRandom.h:27
void SetPalette(Int_t ncolors=kBird, Int_t *colors=nullptr, Float_t alpha=1.)
See TColor::SetPalette.
Definition TStyle.cxx:1890