Logo ROOT   6.14/05
Reference Guide
ratioplot1.py
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 to histograms, name and title for the object, drawing options for the histograms (`hist` and `E` in this case)
7 ## and a drawing option for the output graph.
8 ## Inspired by the tutorial of Paul Gessinger.
9 ##
10 ## \macro_image
11 ## \macro_code
12 ##
13 ## \author Alberto Ferro
14 
15 import ROOT
16 
17 ROOT.gStyle.SetOptStat(0)
18 
19 c1 = ROOT.TCanvas("c1", "A ratio example")
20 h1 = ROOT.TH1D("h1", "h1", 50, 0, 10)
21 h2 = ROOT.TH1D("h2", "h2", 50, 0, 10)
22 f1 = ROOT.TF1("f1", "exp(- x/[0] )")
23 f1.SetParameter(0,3)
24 
25 h1.FillRandom("f1",1900)
26 h2.FillRandom("f1", 2000)
27 h1.Sumw2()
28 h2.Scale(1.9/2.)
29 
30 h1.GetXaxis().SetTitle("x")
31 h1.GetYaxis().SetTitle("y")
32 
33 rp = ROOT.TRatioPlot(h1,h2)
34 
35 c1.SetTicks(0,1)
36 rp.GetLowYaxis().SetNdivisions(505)
37 c1.Update()
38 c1.Draw()
39 rp.Draw()
40