th2polyBoxes.C

Go to the documentation of this file.
00001 //This tutorial illustrates how to create an histogram with polygonal
00002 //bins (TH2Poly). The bins are boxes.
00003 //
00004 //Author: Olivier Couet
00005 
00006 {
00007    TCanvas *ch2p2 = new TCanvas("ch2p2","ch2p2",600,400);
00008    TH2Poly *h2p = new TH2Poly();
00009    h2p->SetName("Boxes");
00010    h2p->SetTitle("Boxes");
00011    gStyle->SetPalette(1);
00012 
00013    Int_t i,j;
00014    Int_t nx = 40;
00015    Int_t ny = 40;
00016    Double_t x1,y1,x2,y2;
00017    Double_t dx=0.2, dy=0.1;
00018    x1 = 0.;
00019    x2 = dx;
00020 
00021    for (i = 0; i<nx; i++) {
00022       y1 = 0.;
00023       y2 = dy;
00024       for (j = 0; j<ny; j++) {
00025          h2p->AddBin(x1, y1, x2, y2);
00026          y1 = y2;
00027          y2 = y2+y2*dy;
00028       }
00029       x1 = x2;
00030       x2 = x2+x2*dx;
00031    }
00032 
00033    TRandom ran;
00034    for (i = 0; i<300000; i++) {
00035       h2p->Fill(50*ran.Gaus(2.,1), ran.Gaus(2.,1));
00036    }
00037 
00038    h2p->Draw("COLZ");
00039    return ch2p2;
00040 }

Generated on Tue Jul 5 15:44:29 2011 for ROOT_528-00b_version by  doxygen 1.5.1