Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
hist018_TH2_cutg.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_hist
3/// \notebook -js
4/// \preview This example demonstrates how to display a 2D histogram and
5/// use TCutG object to select bins for drawing.
6/// Moving TCutG object one can change displayed region of histogram
7///
8/// \macro_image
9/// \macro_code
10///
11/// \date January 2023
12/// \author Sergey Linev
13
14void hist018_TH2_cutg()
15{
16 const int n = 6;
17 Float_t x[6] = {1, 2, 1, -1, -2, -1};
18 Float_t y[6] = {2, 0, -2, -2, 0, 2};
19 TCutG *cut = new TCutG("cut", 6, x, y);
20 TH2F *hist = new TH2F("hist", "Histogram with cut", 40, -10., 10., 40, -10., 10.);
21 for (int i = 0; i < 100000; i++)
22 hist->Fill(gRandom->Gaus(0., 3.), gRandom->Gaus(0., 3.));
23 TCanvas *c1 = new TCanvas("c1", "Histogram draw with TCutG", 600, 900);
24 hist->Draw("col [cut]");
25 cut->Draw("l");
26}
float Float_t
Float 4 bytes (float).
Definition RtypesCore.h:71
externTRandom * gRandom
Definition TRandom.h:62
The Canvas class.
Definition TCanvas.h:23
Graphical cut class.
Definition TCutG.h:20
void Draw(Option_t *chopt="") override
Default Draw method for all objects.
void Draw(Option_t *option="") override
Draw this histogram with options.
Definition TH1.cxx:3097
2-D histogram with a float per channel (see TH1 documentation)
Definition TH2.h:345
Int_t Fill(Double_t) override
Invalid Fill method.
Definition TH2.cxx:363
return c1
Definition legend1.C:41
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
const Int_t n
Definition legend1.C:16