Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
hist029_TRatioPlot_simple.C File Reference

Detailed Description

View in nbviewer Open in SWAN
Example creating a simple ratio plot of two histograms using the "pois" division option.

Two histograms are set up and filled with random numbers. The constructor of TRatioPlot takes the two histograms, name and title for the object, drawing options for the histograms (hist and E in this case) and a drawing option for the output graph. The histograms drawing options can be changed with SetH1DrawOpt and SetH2DrawOpt.

void hist029_TRatioPlot_simple()
{
gStyle->SetOptStat(0);
auto C = new TCanvas("C", "A ratio example");
auto h1 = new TH1D("h1", "TRatioPlot Example; x; y", 50, 0, 10);
auto h2 = new TH1D("h2", "h2", 50, 0, 10);
auto f1 = new TF1("f1", "exp(- x/[0] )");
f1->SetParameter(0, 3);
h1->FillRandom("f1", 1900);
h2->FillRandom("f1", 2000);
h1->Sumw2();
h2->Scale(1.9 / 2.);
h2->SetLineColor(kRed);
// Create and draw the ratio plot
auto rp = new TRatioPlot(h1, h2);
C->SetTicks(0, 1);
rp->Draw();
rp->GetLowYaxis()->SetNdivisions(505);
// Add a legend to the ratio plot
rp->GetUpperPad()->cd();
TLegend *legend = new TLegend(0.3, 0.7, 0.7, 0.85);
legend->AddEntry("h1", "First histogram", "l");
legend->AddEntry("h2", "Second histogram", "le");
legend->Draw();
}
@ kRed
Definition Rtypes.h:67
R__EXTERN TStyle * gStyle
Definition TStyle.h:442
The Canvas class.
Definition TCanvas.h:23
1-Dim function class
Definition TF1.h:182
1-D histogram with a double per channel (see TH1 documentation)
Definition TH1.h:926
This class displays a legend box (TPaveText) containing several legend entries.
Definition TLegend.h:23
TLegendEntry * AddEntry(const TObject *obj, const char *label="", Option_t *option="lpf")
Add a new entry to this legend.
Definition TLegend.cxx:319
void Draw(Option_t *option="") override
Draw this legend with its current attributes.
Definition TLegend.cxx:424
Class for displaying ratios, differences and fit residuals.
Definition TRatioPlot.h:44
TH1F * h1
Definition legend1.C:5
TF1 * f1
Definition legend1.C:11
Date
February 2023
Author
Paul Gessinger

Definition in file hist029_TRatioPlot_simple.C.