diff --git a/tutorials/hist/ratioplot2.py b/tutorials/hist/ratioplot2.py new file mode 100644 index 0000000000000000000000000000000000000000..4121950728ee5199ec6f7a98ecb33f1d4c378055 --- /dev/null +++ b/tutorials/hist/ratioplot2.py @@ -0,0 +1,34 @@ +## \file +## \ingroup tutorial_hist +## \notebook +## Example of a fit residual plot. +## +## Creates a histogram filled with random numbers from a gaussian distribution +## and fits it with a standard gaussian function. The result is passed to the `TRatioPlot` +## constructor. Additionally, after calling `TRatioPlot::Draw` the upper and lower y axis +## titles are modified. +## Confidence interval bands are automatically drawn on the bottom (but can be disabled by draw option `nobands`. +## nspired by the tutorial of Paul Gessinger. +## \macro_image +## \macro_code +## +## \author Alberto Ferro + +import ROOT + +ROOT.gStyle.SetOptStat(0) + +c1 = ROOT.TCanvas("c1", "fit residual simple") +h1 = ROOT.TH1D("h1", "h1", 50, -5, 5) + +h1.FillRandom("gaus", 2000) +h1.Fit("gaus") +h1.GetXaxis().SetTitle("x") + +rp1 = ROOT.TRatioPlot(h1) +rp1.Draw() +rp1.GetLowerRefYaxis().SetTitle("ratio") +rp1.GetUpperRefYaxis().SetTitle("entries") + +c1.Update() + diff --git a/tutorials/hist/ratioplot3.py b/tutorials/hist/ratioplot3.py new file mode 100644 index 0000000000000000000000000000000000000000..7fce56ed3bad442ea8195d1dcee2f00a077019dc --- /dev/null +++ b/tutorials/hist/ratioplot3.py @@ -0,0 +1,33 @@ +## \file +## \ingroup tutorial_hist +## \notebook +## Example which shows how you can get the graph of the lower plot and set the y axis range for it. +## +## Since the lower plot is not created until `TRatioPlot::Draw` is called, you can only use the method +## afterwards. +## Inspired by the tutorial of Paul Gessinger. +## +## \macro_image +## \macro_code +## +## \author Alberto Ferro + +import ROOT + +ROOT.gStyle.SetOptStat(0) +c1 = ROOT.TCanvas("c1", "fit residual simple") +c1.SetLogy() + +h1 = ROOT.TH1D("h1", "h1", 50, -5, 5) +h1.FillRandom("gaus", 2000) +h1.Fit("gaus") +h1.SetMinimum(0.001) +h1.GetXaxis().SetTitle("x") +h1.GetYaxis().SetTitle("y") + +rp1 = ROOT.TRatioPlot(h1) +rp1.Draw() +rp1.GetLowerRefGraph().SetMinimum(-2) +rp1.GetLowerRefGraph().SetMaximum(2) + +c1.Update() diff --git a/tutorials/hist/ratioplot4.py b/tutorials/hist/ratioplot4.py new file mode 100644 index 0000000000000000000000000000000000000000..1a5ffb790212dfcf1dada9a2f32757df1c2e52a1 --- /dev/null +++ b/tutorials/hist/ratioplot4.py @@ -0,0 +1,36 @@ +## \file +## \ingroup tutorial_hist +## \notebook +## Example that shows custom dashed lines on the lower plot, specified by a vector of floats. +## +## By default, dashed lines are drawn at certain points. You can either disable them, or specify +## where you want them to appear. +## Inspired by the tutorial of Paul Gessinger. +## +## \macro_image +## \macro_code +## +## \author Alberto Ferro + +import ROOT + +ROOT.gStyle.SetOptStat(0) + +c1 = ROOT.TCanvas("c1", "fit residual simple") +h1 = ROOT.TH1D("h1", "h1", 50, -5, 5) +h1.FillRandom("gaus", 2000) +h1.Fit("gaus") +h1.GetXaxis().SetTitle("x") +h1.GetYaxis().SetTitle("y") + +rp1 = ROOT.TRatioPlot(h1) + +lines = ROOT.std.vector('double')() +for i in range(-3,4):lines.push_back(i) +rp1.SetGridlines(lines) + +rp1.Draw() +rp1.GetLowerRefGraph().SetMinimum(-4) +rp1.GetLowerRefGraph().SetMaximum(4) + +c1.Update() diff --git a/tutorials/hist/ratioplot5.py b/tutorials/hist/ratioplot5.py new file mode 100644 index 0000000000000000000000000000000000000000..be1661d2b91ff5418c35e589deeff3f4e666b984 --- /dev/null +++ b/tutorials/hist/ratioplot5.py @@ -0,0 +1,27 @@ +## \file +## \ingroup tutorial_hist +## \notebook +## Example that shows how you can set the colors of the confidence interval bands by using +## the method `TRatioPlot::SetConfidenceIntervalColors`. +## Inspired by the tutorial of Paul Gessinger. +## +## \macro_image +## \macro_code +## +## \author Alberto Ferro + +import ROOT + +ROOT.gStyle.SetOptStat(0) + +c1 = ROOT.TCanvas("c1", "fit residual simple") +h1 = ROOT.TH1D("h1", "h1", 50, -5, 5) +h1.FillRandom("gaus", 2000) +h1.Fit("gaus") +h1.GetXaxis().SetTitle("x") +h1.GetYaxis().SetTitle("y") + +rp1 = ROOT.TRatioPlot(h1) +rp1.SetConfidenceIntervalColors(ROOT.kBlue, ROOT.kRed) +rp1.Draw() +c1.Update() diff --git a/tutorials/hist/ratioplot6.py b/tutorials/hist/ratioplot6.py new file mode 100644 index 0000000000000000000000000000000000000000..acfa4da88414c11586a115ebbbe863afef8c4244 --- /dev/null +++ b/tutorials/hist/ratioplot6.py @@ -0,0 +1,35 @@ +## \file +## \ingroup tutorial_hist +## \notebook +## Example showing a fit residual plot, where the separation margin has been set to 0. +## The last label of the lower plot's y axis is hidden automatically. +## Inspired by the tutorial of Paul Gessinger. +## +## \macro_image +## \macro_code +## +## \author Alberto Ferro + +import ROOT + +ROOT.gStyle.SetOptStat(0) + +c1 = ROOT.TCanvas("c1", "fit residual simple") +ROOT.gPad.SetFrameFillStyle(0) + +h1 = ROOT.TH1D("h1", "h1", 50, -5, 5) +h1.FillRandom("gaus", 5000) +h1.Fit("gaus", "S") + +h1.Sumw2() +h1.GetXaxis().SetTitle("x") +h1.GetYaxis().SetTitle("y") + +rp1 = ROOT.TRatioPlot(h1, "errfunc") +rp1.SetGraphDrawOpt("L") +rp1.SetSeparationMargin(0.0) +rp1.Draw() +rp1.GetLowerRefGraph().SetMinimum(-2) +rp1.GetLowerRefGraph().SetMaximum(2) + +c1.Update()