Logo ROOT   6.16/01
Reference Guide
rf302_utilfuncs.py
Go to the documentation of this file.
1## \file
2## \ingroup tutorial_roofit
3## \notebook
4## 'MULTIDIMENSIONAL MODELS' RooFit tutorial macro #302
5## Utility functions classes available for use in tailoring
6## of composite (multidimensional) pdfs
7##
8## \macro_code
9##
10## \date February 2018
11## \author Clemens Lange
12## \author Wouter Verkerke (C version)
13
14import ROOT
15
16# Create observables, parameters
17# -----------------------------------------------------------
18
19# Create observables
20x = ROOT.RooRealVar("x", "x", -5, 5)
21y = ROOT.RooRealVar("y", "y", -5, 5)
22
23# Create parameters
24a0 = ROOT.RooRealVar("a0", "a0", -1.5, -5, 5)
25a1 = ROOT.RooRealVar("a1", "a1", -0.5, -1, 1)
26sigma = ROOT.RooRealVar("sigma", "width of gaussian", 0.5)
27
28# Using RooFormulaVar to tailor pdf
29# -----------------------------------------------------------------------
30
31# Create interpreted function f(y) = a0 - a1*sqrt(10*abs(y))
32fy_1 = ROOT.RooFormulaVar(
33 "fy_1", "a0-a1*sqrt(10*abs(y))", ROOT.RooArgList(y, a0, a1))
34
35# Create gauss(x,f(y),s)
36model_1 = ROOT.RooGaussian(
37 "model_1", "Gaussian with shifting mean", x, fy_1, sigma)
38
39# Using RooPolyVar to tailor pdf
40# -----------------------------------------------------------------------
41
42# Create polynomial function f(y) = a0 + a1*y
43fy_2 = ROOT.RooPolyVar("fy_2", "fy_2", y, ROOT.RooArgList(a0, a1))
44
45# Create gauss(x,f(y),s)
46model_2 = ROOT.RooGaussian(
47 "model_2", "Gaussian with shifting mean", x, fy_2, sigma)
48
49# Using RooAddition to tailor pdf
50# -----------------------------------------------------------------------
51
52# Create sum function f(y) = a0 + y
53fy_3 = ROOT.RooAddition("fy_3", "a0+y", ROOT.RooArgList(a0, y))
54
55# Create gauss(x,f(y),s)
56model_3 = ROOT.RooGaussian(
57 "model_3", "Gaussian with shifting mean", x, fy_3, sigma)
58
59# Using RooProduct to tailor pdf
60# -----------------------------------------------------------------------
61
62# Create product function f(y) = a1*y
63fy_4 = ROOT.RooProduct("fy_4", "a1*y", ROOT.RooArgList(a1, y))
64
65# Create gauss(x,f(y),s)
66model_4 = ROOT.RooGaussian(
67 "model_4", "Gaussian with shifting mean", x, fy_4, sigma)
68
69# Plot all pdfs
70# ----------------------------
71
72# Make two-dimensional plots in x vs y
73hh_model_1 = model_1.createHistogram("hh_model_1", x, ROOT.RooFit.Binning(
74 50), ROOT.RooFit.YVar(y, ROOT.RooFit.Binning(50)))
75hh_model_2 = model_2.createHistogram("hh_model_2", x, ROOT.RooFit.Binning(
76 50), ROOT.RooFit.YVar(y, ROOT.RooFit.Binning(50)))
77hh_model_3 = model_3.createHistogram("hh_model_3", x, ROOT.RooFit.Binning(
78 50), ROOT.RooFit.YVar(y, ROOT.RooFit.Binning(50)))
79hh_model_4 = model_4.createHistogram("hh_model_4", x, ROOT.RooFit.Binning(
80 50), ROOT.RooFit.YVar(y, ROOT.RooFit.Binning(50)))
81hh_model_1.SetLineColor(ROOT.kBlue)
82hh_model_2.SetLineColor(ROOT.kBlue)
83hh_model_3.SetLineColor(ROOT.kBlue)
84hh_model_4.SetLineColor(ROOT.kBlue)
85
86# Make canvas and draw ROOT.RooPlots
87c = ROOT.TCanvas("rf302_utilfuncs", "rf302_utilfuncs", 800, 800)
88c.Divide(2, 2)
89c.cd(1)
90ROOT.gPad.SetLeftMargin(0.20)
91hh_model_1.GetZaxis().SetTitleOffset(2.5)
92hh_model_1.Draw("surf")
93c.cd(2)
94ROOT.gPad.SetLeftMargin(0.20)
95hh_model_2.GetZaxis().SetTitleOffset(2.5)
96hh_model_2.Draw("surf")
97c.cd(3)
98ROOT.gPad.SetLeftMargin(0.20)
99hh_model_3.GetZaxis().SetTitleOffset(2.5)
100hh_model_3.Draw("surf")
101c.cd(4)
102ROOT.gPad.SetLeftMargin(0.20)
103hh_model_4.GetZaxis().SetTitleOffset(2.5)
104hh_model_4.Draw("surf")
105
106c.SaveAs("rf302_utilfuncs.png")