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