Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
rf313_paramranges.py
Go to the documentation of this file.
1## \file
2## \ingroup tutorial_roofit
3## \notebook
4## Multidimensional models: working with parameterized ranges to define non-rectangular
5## regions for fitting and integration
6##
7## \macro_code
8##
9## \date February 2018
10## \authors Clemens Lange, Wouter Verkerke (C++ version)
11
12import ROOT
13
14
15# Create 3D pdf
16# -------------------------
17
18# Define observable (x,y,z)
19x = ROOT.RooRealVar("x", "x", 0, 10)
20y = ROOT.RooRealVar("y", "y", 0, 10)
21z = ROOT.RooRealVar("z", "z", 0, 10)
22
23# Define 3 dimensional pdf
24z0 = ROOT.RooRealVar("z0", "z0", -0.1, 1)
25px = ROOT.RooPolynomial("px", "px", x, [0.0])
26py = ROOT.RooPolynomial("py", "py", y, [0.0])
27pz = ROOT.RooPolynomial("pz", "pz", z, [z0])
28pxyz = ROOT.RooProdPdf("pxyz", "pxyz", [px, py, pz])
29
30# Defined non-rectangular region R in (x, y, z)
31# -------------------------------------------------------------------------------------
32
33#
34# R = Z[0 - 0.1*Y^2] * Y[0.1*X - 0.9*X] * X[0 - 10]
35#
36
37# Construct range parameterized in "R" in y [ 0.1*x, 0.9*x ]
38ylo = ROOT.RooFormulaVar("ylo", "0.1*x", [x])
39yhi = ROOT.RooFormulaVar("yhi", "0.9*x", [x])
40y.setRange("R", ylo, yhi)
41
42# Construct parameterized ranged "R" in z [ 0, 0.1*y^2 ]
43zlo = ROOT.RooFormulaVar("zlo", "0.0*y", [y])
44zhi = ROOT.RooFormulaVar("zhi", "0.1*y*y", [y])
45z.setRange("R", zlo, zhi)
46
47# Calculate integral of normalized pdf in R
48# ----------------------------------------------------------------------------------
49
50# Create integral over normalized pdf model over x,y, in "R" region
51intPdf = pxyz.createIntegral({x, y, z}, {x, y, z}, "R")
52
53# Plot value of integral as function of pdf parameter z0
54frame = z0.frame(Title="Integral of pxyz over x,y, in region R")
55intPdf.plotOn(frame)
56
57c = ROOT.TCanvas("rf313_paramranges", "rf313_paramranges", 600, 600)
58ROOT.gPad.SetLeftMargin(0.15)
59frame.GetYaxis().SetTitleOffset(1.6)
60frame.Draw()
61
62c.SaveAs("rf313_paramranges.png")