ROOT
Version v6.32
master
v6.34
v6.30
v6.28
v6.26
v6.24
v6.22
v6.20
v6.18
v6.16
v6.14
v6.12
v6.10
v6.08
v6.06
Reference Guide
►
ROOT
•
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Modules
Pages
Loading...
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
13
import
ROOT
14
15
16
# Create pdf for sampling
17
# ---------------------------------------------
18
19
x =
ROOT.RooRealVar
(
"x"
,
"x"
, 0, 20)
20
p =
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
26
x.setBins
(20)
27
data1 =
p.generate
({x}, 500)
28
29
# Create a binned dataset with 20 bins and 500 events
30
hist1 =
data1.binnedClone
()
31
32
# Represent data in dh as pdf in x
33
histpdf1 =
ROOT.RooHistPdf
(
"histpdf1"
,
"histpdf1"
, {x}, hist1, 0)
34
35
# Plot unbinned data and histogram pdf overlaid
36
frame1 =
x.frame
(Title=
"Low statistics histogram pdf"
, Bins=100)
37
data1.plotOn
(frame1)
38
histpdf1.plotOn
(frame1)
39
40
# Create high stats histogram
41
# -----------------------------------------------------
42
43
# Sample 100000 events from p
44
x.setBins
(10)
45
data2 =
p.generate
({x}, 100000)
46
47
# Create a binned dataset with 10 bins and 100K events
48
hist2 =
data2.binnedClone
()
49
50
# Represent data in dh as pdf in x, 2nd order interpolation
51
histpdf2 =
ROOT.RooHistPdf
(
"histpdf2"
,
"histpdf2"
, {x}, hist2, 2)
52
53
# Plot unbinned data and histogram pdf overlaid
54
frame2 =
x.frame
(Title=
"High stats histogram pdf with interpolation"
, Bins=100)
55
data2.plotOn
(frame2)
56
histpdf2.plotOn
(frame2)
57
58
c =
ROOT.TCanvas
(
"rf706_histpdf"
,
"rf706_histpdf"
, 800, 400)
59
c.Divide
(2)
60
c.cd
(1)
61
ROOT.gPad.SetLeftMargin
(0.15)
62
frame1.GetYaxis
().SetTitleOffset(1.4)
63
frame1.Draw
()
64
c.cd
(2)
65
ROOT.gPad.SetLeftMargin
(0.15)
66
frame2.GetYaxis
().SetTitleOffset(1.8)
67
frame2.Draw
()
68
69
c.SaveAs
(
"rf706_histpdf.png"
)
TRangeDynCast
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Definition
TCollection.h:358
tutorials
roofit
rf706_histpdf.py
ROOT tags/v6-32-12 - Reference Guide Generated on Tue Apr 8 2025 06:01:06 (GVA Time) using Doxygen 1.10.0