Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
hist029_TRatioPlot_simple.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_hist
3/// \notebook
4/// Example creating a simple ratio plot of two histograms using the `pois` division option.
5/// Two histograms are set up and filled with random numbers. The constructor of `TRatioPlot`
6/// takes the two histograms, name and title for the object, drawing options for the histograms
7/// (`hist` and `E` in this case) and a drawing option for the output graph.
8/// The histograms drawing options can be changed with `SetH1DrawOpt` and `SetH2DrawOpt`.
9///
10/// \macro_image
11/// \macro_code
12///
13/// \date February 2023
14/// \author Paul Gessinger
15
17{
19 auto C = new TCanvas("C", "A ratio example");
20 auto h1 = new TH1D("h1", "TRatioPlot Example; x; y", 50, 0, 10);
21 auto h2 = new TH1D("h2", "h2", 50, 0, 10);
22 auto f1 = new TF1("f1", "exp(- x/[0] )");
23 f1->SetParameter(0, 3);
24 h1->FillRandom("f1", 1900);
25 h2->FillRandom("f1", 2000);
26 h1->Sumw2();
27 h2->Scale(1.9 / 2.);
28 h2->SetLineColor(kRed);
29
30 // Create and draw the ratio plot
31 auto rp = new TRatioPlot(h1, h2);
32 C->SetTicks(0, 1);
33 rp->Draw();
34 rp->GetLowYaxis()->SetNdivisions(505);
35
36 // Add a legend to the ratio plot
37 rp->GetUpperPad()->cd();
38 TLegend *legend = new TLegend(0.3, 0.7, 0.7, 0.85);
39 legend->AddEntry("h1", "First histogram", "l");
40 legend->AddEntry("h2", "Second histogram", "le");
41 legend->Draw();
42}
@ kRed
Definition Rtypes.h:66
R__EXTERN TStyle * gStyle
Definition TStyle.h:442
The Canvas class.
Definition TCanvas.h:23
1-Dim function class
Definition TF1.h:233
virtual void SetParameter(Int_t param, Double_t value)
Definition TF1.h:667
1-D histogram with a double per channel (see TH1 documentation)
Definition TH1.h:693
virtual void FillRandom(TF1 *f1, Int_t ntimes=5000, TRandom *rng=nullptr)
Definition TH1.cxx:3499
virtual void Sumw2(Bool_t flag=kTRUE)
Create structure to store sum of squares of weights.
Definition TH1.cxx:9022
This class displays a legend box (TPaveText) containing several legend entries.
Definition TLegend.h:23
Class for displaying ratios, differences and fit residuals.
Definition TRatioPlot.h:44
void SetOptStat(Int_t stat=1)
The type of information printed in the histogram statistics box can be selected via the parameter mod...
Definition TStyle.cxx:1642
TH1F * h1
Definition legend1.C:5
TF1 * f1
Definition legend1.C:11
constexpr Double_t C()
Velocity of light in .
Definition TMath.h:114