ROOT
master
Reference Guide
Loading...
Searching...
No Matches
rf804_mcstudy_constr.py
Go to the documentation of this file.
1
## \ingroup tutorial_roofit_main
2
## \notebook
3
##
4
## 'VALIDATION AND MC STUDIES' RooFit tutorial macro #804
5
##
6
## Using RooMCStudy on models with constraints
7
##
8
## \macro_image
9
## \macro_code
10
## \macro_output
11
##
12
## \date February 2018
13
## \author Clemens Lange
14
15
16
import
ROOT
17
18
19
# Create model with parameter constraint
20
# ---------------------------------------------------------------------------
21
22
# Observable
23
x =
ROOT.RooRealVar
(
"x"
,
"x"
, -10, 10)
24
25
# Signal component
26
m =
ROOT.RooRealVar
(
"m"
,
"m"
, 0, -10, 10)
27
s =
ROOT.RooRealVar
(
"s"
,
"s"
, 2, 0.1, 10)
28
g =
ROOT.RooGaussian
(
"g"
,
"g"
, x, m, s)
29
30
# Background component
31
p =
ROOT.RooPolynomial
(
"p"
,
"p"
, x)
32
33
# Composite model
34
f =
ROOT.RooRealVar
(
"f"
,
"f"
, 0.4, 0.0, 1.0)
35
sum =
ROOT.RooAddPdf
(
"sum"
,
"sum"
, [g, p], [f])
36
37
# Construct constraint on parameter f
38
fconstraint =
ROOT.RooGaussian
(
"fconstraint"
,
"fconstraint"
, f, 0.7, 0.1)
39
40
# Multiply constraint with p.d.f
41
sumc =
ROOT.RooProdPdf
(
"sumc"
,
"sum with constraint"
, [sum, fconstraint])
42
43
# Setup toy study with model
44
# ---------------------------------------------------
45
46
# Perform toy study with internal constraint on f
47
mcs =
ROOT.RooMCStudy
(sumc, {x}, Constrain={f}, Silence=
True
, Binned=
True
, FitOptions={
"PrintLevel"
: -1})
48
49
# Run 500 toys of 2000 events.
50
# Before each toy is generated, value for the f is sampled from the constraint pdf and
51
# that value is used for the generation of that toy.
52
mcs.generateAndFit
(500, 2000)
53
54
# Make plot of distribution of generated value of f parameter
55
h_f_gen =
mcs.fitParDataSet
().createHistogram(
"f_gen"
, AutoBinning=40)
56
57
# Make plot of distribution of fitted value of f parameter
58
frame1 =
mcs.plotParam
(f, Bins=40)
59
frame1.SetTitle
(
"Distribution of fitted f values"
)
60
61
# Make plot of pull distribution on f
62
frame2 =
mcs.plotPull
(f, Bins=40, FitGauss=
True
)
63
frame1.SetTitle
(
"Distribution of f pull values"
)
64
65
c =
ROOT.TCanvas
(
"rf804_mcstudy_constr"
,
"rf804_mcstudy_constr"
, 1200, 400)
66
c.Divide
(3)
67
c.cd
(1)
68
ROOT.gPad.SetLeftMargin
(0.15)
69
h_f_gen.GetYaxis
().SetTitleOffset(1.4)
70
h_f_gen.Draw
()
71
c.cd
(2)
72
ROOT.gPad.SetLeftMargin
(0.15)
73
frame1.GetYaxis
().SetTitleOffset(1.4)
74
frame1.Draw
()
75
c.cd
(3)
76
ROOT.gPad.SetLeftMargin
(0.15)
77
frame2.GetYaxis
().SetTitleOffset(1.4)
78
frame2.Draw
()
79
80
c.SaveAs
(
"rf804_mcstudy_constr.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
roofit
rf804_mcstudy_constr.py
ROOT master - Reference Guide Generated on Sat Feb 8 2025 04:21:36 (GVA Time) using Doxygen 1.10.0