Loading [MathJax]/extensions/tex2jax.js
Logo ROOT   6.16/01
Reference Guide
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
rf504_simwstool.py
Go to the documentation of this file.
1## \file
2## \ingroup tutorial_roofit
3## \notebook -nodraw
4##
5## 'ORGANIZATION AND SIMULTANEOUS FITS' RooFit tutorial macro #504
6##
7## Using RooSimWSTool to construct a simultaneous p.d.f that is built
8## of variations of an input p.d.f
9##
10## \macro_code
11##
12## \date February 2018
13## \author Clemens Lange
14## \author Wouter Verkerke (C version)
15
16import ROOT
17
18
19# Create master pdf
20# ---------------------------------
21
22# Construct gauss(x,m,s)
23x = ROOT.RooRealVar("x", "x", -10, 10)
24m = ROOT.RooRealVar("m", "m", 0, -10, 10)
25s = ROOT.RooRealVar("s", "s", 1, -10, 10)
26gauss = ROOT.RooGaussian("g", "g", x, m, s)
27
28# Construct poly(x,p0)
29p0 = ROOT.RooRealVar("p0", "p0", 0.01, 0., 1.)
30poly = ROOT.RooPolynomial("p", "p", x, ROOT.RooArgList(p0))
31
32# model = f*gauss(x) + (1-f)*poly(x)
33f = ROOT.RooRealVar("f", "f", 0.5, 0., 1.)
34model = ROOT.RooAddPdf("model", "model", ROOT.RooArgList(
35 gauss, poly), ROOT.RooArgList(f))
36
37# Create category observables for splitting
38# ----------------------------------------------------------------------------------
39
40# Define two categories that can be used for splitting
41c = ROOT.RooCategory("c", "c")
42c.defineType("run1")
43c.defineType("run2")
44
45d = ROOT.RooCategory("d", "d")
46d.defineType("foo")
47d.defineType("bar")
48
49# Set up SimWSTool
50# -----------------------------
51
52# Import ingredients in a workspace
53w = ROOT.RooWorkspace("w", "w")
54getattr(w, 'import')(ROOT.RooArgSet(model, c, d))
55
56# Make Sim builder tool
57sct = ROOT.RooSimWSTool(w)
58
59# Build a simultaneous model with one split
60# ---------------------------------------------------------------------------------
61
62# Construct a simultaneous p.d.f with the following form
63#
64# model_run1(x) = f*gauss_run1(x,m_run1,s) + (1-f)*poly
65# model_run2(x) = f*gauss_run2(x,m_run2,s) + (1-f)*poly
66# simpdf(x,c) = model_run1(x) if c=="run1"
67# = model_run2(x) if c=="run2"
68#
69# Returned p.d.f is owned by the workspace
70model_sim = sct.build("model_sim", "model",
71 ROOT.RooFit.SplitParam("m", "c"))
72
73# Print tree structure of model
74model_sim.Print("t")
75
76# Adjust model_sim parameters in workspace
77w.var("m_run1").setVal(-3)
78w.var("m_run2").setVal(+3)
79
80# Print contents of workspace
81w.Print("v")
82
83# Build a simultaneous model with product split
84# -----------------------------------------------------------------------------------------
85
86# Build another simultaneous p.d.f using a composite split in states c X d
87model_sim2 = sct.build("model_sim2", "model",
88 ROOT.RooFit.SplitParam("p0", "c,d"))
89
90# Print tree structure of self model
91model_sim2.Print("t")