ROOT   Reference Guide
Searching...
No Matches
rf706_histpdf.py
Go to the documentation of this file.
1## \file
2## \ingroup tutorial_roofit
3## \notebook
4## Special pdf's: histogram based pdfs and functions
5##
6## \macro_image
7## \macro_code
8## \macro_output
9##
10## \date February 2018
11## \authors Clemens Lange, Wouter Verkerke (C++ version)
12
13import ROOT
14
15
16# Create pdf for sampling
17# ---------------------------------------------
18
19x = ROOT.RooRealVar("x", "x", 0, 20)
20p = ROOT.RooPolynomial("p", "p", x, [0.01, -0.01, 0.0004])
21
22# Create low stats histogram
23# ---------------------------------------------------
24
25# Sample 500 events from p
26x.setBins(20)
27data1 = p.generate({x}, 500)
28
29# Create a binned dataset with 20 bins and 500 events
30hist1 = data1.binnedClone()
31
32# Represent data in dh as pdf in x
33histpdf1 = ROOT.RooHistPdf("histpdf1", "histpdf1", {x}, hist1, 0)
34
35# Plot unbinned data and histogram pdf overlaid
36frame1 = x.frame(Title="Low statistics histogram pdf", Bins=100)
37data1.plotOn(frame1)
38histpdf1.plotOn(frame1)
39
40# Create high stats histogram
41# -----------------------------------------------------
42
43# Sample 100000 events from p
44x.setBins(10)
45data2 = p.generate({x}, 100000)
46
47# Create a binned dataset with 10 bins and 100K events
48hist2 = data2.binnedClone()
49
50# Represent data in dh as pdf in x, 2nd order interpolation
51histpdf2 = ROOT.RooHistPdf("histpdf2", "histpdf2", {x}, hist2, 2)
52
53# Plot unbinned data and histogram pdf overlaid
54frame2 = x.frame(Title="High stats histogram pdf with interpolation", Bins=100)
55data2.plotOn(frame2)
56histpdf2.plotOn(frame2)
57
58c = ROOT.TCanvas("rf706_histpdf", "rf706_histpdf", 800, 400)
59c.Divide(2)
60c.cd(1)