ROOT logo

From $ROOTSYS/tutorials/hist/th2polyBoxes.C

//This tutorial illustrates how to create an histogram with polygonal
//bins (TH2Poly). The bins are boxes.
//
//Author: Olivier Couet

{
   TCanvas *ch2p2 = new TCanvas("ch2p2","ch2p2",600,400);
   TH2Poly *h2p = new TH2Poly();
   h2p->SetName("Boxes");
   h2p->SetTitle("Boxes");
   gStyle->SetPalette(1);

   Int_t i,j;
   Int_t nx = 40;
   Int_t ny = 40;
   Double_t x1,y1,x2,y2;
   Double_t dx=0.2, dy=0.1;
   x1 = 0.;
   x2 = dx;

   for (i = 0; i<nx; i++) {
      y1 = 0.;
      y2 = dy;
      for (j = 0; j<ny; j++) {
         h2p->AddBin(x1, y1, x2, y2);
         y1 = y2;
         y2 = y2+y2*dy;
      }
      x1 = x2;
      x2 = x2+x2*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;
}
 th2polyBoxes.C:1
 th2polyBoxes.C:2
 th2polyBoxes.C:3
 th2polyBoxes.C:4
 th2polyBoxes.C:5
 th2polyBoxes.C:6
 th2polyBoxes.C:7
 th2polyBoxes.C:8
 th2polyBoxes.C:9
 th2polyBoxes.C:10
 th2polyBoxes.C:11
 th2polyBoxes.C:12
 th2polyBoxes.C:13
 th2polyBoxes.C:14
 th2polyBoxes.C:15
 th2polyBoxes.C:16
 th2polyBoxes.C:17
 th2polyBoxes.C:18
 th2polyBoxes.C:19
 th2polyBoxes.C:20
 th2polyBoxes.C:21
 th2polyBoxes.C:22
 th2polyBoxes.C:23
 th2polyBoxes.C:24
 th2polyBoxes.C:25
 th2polyBoxes.C:26
 th2polyBoxes.C:27
 th2polyBoxes.C:28
 th2polyBoxes.C:29
 th2polyBoxes.C:30
 th2polyBoxes.C:31
 th2polyBoxes.C:32
 th2polyBoxes.C:33
 th2polyBoxes.C:34
 th2polyBoxes.C:35
 th2polyBoxes.C:36
 th2polyBoxes.C:37
 th2polyBoxes.C:38
 th2polyBoxes.C:39
 th2polyBoxes.C:40
 th2polyBoxes.C:41