Rf 7 0 6_Histpdf¶

Special pdf's: histogram based pdfs and functions

Author: Clemens Lange, Wouter Verkerke (C++ version)
This notebook tutorial was automatically generated with ROOTBOOK-izer from the macro found in the ROOT repository on Monday, January 17, 2022 at 10:16 AM.

In [ ]:
import ROOT

Create pdf for sampling¶

In [ ]:
x = ROOT.RooRealVar("x", "x", 0, 20)
p = ROOT.RooPolynomial("p", "p", x, [0.01, -0.01, 0.0004])

Create low stats histogram¶

Sample 500 events from p

In [ ]:
x.setBins(20)
data1 = p.generate({x}, 500)

Create a binned dataset with 20 bins and 500 events

In [ ]:
hist1 = data1.binnedClone()

Represent data in dh as pdf in x

In [ ]:
histpdf1 = ROOT.RooHistPdf("histpdf1", "histpdf1", {x}, hist1, 0)

Plot unbinned data and histogram pdf overlaid

In [ ]:
frame1 = x.frame(Title="Low statistics histogram pdf", Bins=100)
data1.plotOn(frame1)
histpdf1.plotOn(frame1)

Create high stats histogram¶

Sample 100000 events from p

In [ ]:
x.setBins(10)
data2 = p.generate({x}, 100000)

Create a binned dataset with 10 bins and 100K events

In [ ]:
hist2 = data2.binnedClone()

Represent data in dh as pdf in x, 2nd order interpolation

In [ ]:
histpdf2 = ROOT.RooHistPdf("histpdf2", "histpdf2", {x}, hist2, 2)

Plot unbinned data and histogram pdf overlaid

In [ ]:
frame2 = x.frame(Title="High stats histogram pdf with interpolation", Bins=100)
data2.plotOn(frame2)
histpdf2.plotOn(frame2)

c = ROOT.TCanvas("rf706_histpdf", "rf706_histpdf", 800, 400)
c.Divide(2)
c.cd(1)
frame1.GetYaxis().SetTitleOffset(1.4)
frame1.Draw()
c.cd(2)