from __future__ import print_function
import ROOT
x = ROOT.RooRealVar("x", "x", -10, 10)
sigma = ROOT.RooRealVar("sigma", "sigma", 3, 0.1, 10)
mean = ROOT.RooRealVar("mean", "mean", 0, -10, 10)
gauss = ROOT.RooGaussian("gauss", "gauss", x, mean, sigma)
data = gauss.generate({x}, 10000)
sigma.setVal(3.15)
frame1 = x.frame(Title="Data with distorted Gaussian pdf", Bins=40)
data.plotOn(frame1, DataError="SumW2")
gauss.plotOn(frame1)
print("chi^2 = ", frame1.chiSquare())
hresid = frame1.residHist()
hpull = frame1.pullHist()
frame2 = x.frame(Title="Residual Distribution")
frame2.addPlotable(hresid, "P")
frame3 = x.frame(Title="Pull Distribution")
frame3.addPlotable(hpull, "P")
c = ROOT.TCanvas("rf109_chi2residpull", "rf109_chi2residpull", 900, 300)
c.Divide(3)
c.cd(1)
ROOT.gPad.SetLeftMargin(0.15)
frame1.GetYaxis().SetTitleOffset(1.6)
frame1.Draw()
c.cd(2)
ROOT.gPad.SetLeftMargin(0.15)
frame2.GetYaxis().SetTitleOffset(1.6)
frame2.Draw()
c.cd(3)
ROOT.gPad.SetLeftMargin(0.15)
frame3.GetYaxis().SetTitleOffset(1.6)
frame3.Draw()
c.SaveAs("rf109_chi2residpull.png")