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
rf301_composition.py
Go to the documentation of this file.
1## \file
2## \ingroup tutorial_roofit
3## \notebook
4## 'MULTIDIMENSIONAL MODELS' RooFit tutorial macro #301
5## Multi-dimensional p.d.f.s through composition, e.g. substituting a
6## p.d.f parameter with a function that depends on other observables
7##
8## pdf = gauss(x,f(y),s) with f(y) = a0 + a1*y
9##
10## \macro_code
11##
12## \date February 2018
13## \author Clemens Lange
14## \author Wouter Verkerke (C version)
15
16import ROOT
17
18# Setup composed model gauss(x, m(y), s)
19# -----------------------------------------------------------------------
20
21# Create observables
22x = ROOT.RooRealVar("x", "x", -5, 5)
23y = ROOT.RooRealVar("y", "y", -5, 5)
24
25# Create function f(y) = a0 + a1*y
26a0 = ROOT.RooRealVar("a0", "a0", -0.5, -5, 5)
27a1 = ROOT.RooRealVar("a1", "a1", -0.5, -1, 1)
28fy = ROOT.RooPolyVar("fy", "fy", y, ROOT.RooArgList(a0, a1))
29
30# Creat gauss(x,f(y),s)
31sigma = ROOT.RooRealVar("sigma", "width of gaussian", 0.5)
32model = ROOT.RooGaussian(
33 "model", "Gaussian with shifting mean", x, fy, sigma)
34
35# Sample data, plot data and pdf on x and y
36# ---------------------------------------------------------------------------------
37
38# Generate 10000 events in x and y from model
39data = model.generate(ROOT.RooArgSet(x, y), 10000)
40
41# Plot x distribution of data and projection of model x = Int(dy)
42# model(x,y)
43xframe = x.frame()
44data.plotOn(xframe)
45model.plotOn(xframe)
46
47# Plot x distribution of data and projection of model y = Int(dx)
48# model(x,y)
49yframe = y.frame()
50data.plotOn(yframe)
51model.plotOn(yframe)
52
53# Make two-dimensional plot in x vs y
54hh_model = model.createHistogram("hh_model", x, ROOT.RooFit.Binning(
55 50), ROOT.RooFit.YVar(y, ROOT.RooFit.Binning(50)))
56hh_model.SetLineColor(ROOT.kBlue)
57
58# Make canvas and draw ROOT.RooPlots
59c = ROOT.TCanvas("rf301_composition", "rf301_composition", 1200, 400)
60c.Divide(3)
61c.cd(1)
62ROOT.gPad.SetLeftMargin(0.15)
63xframe.GetYaxis().SetTitleOffset(1.4)
64xframe.Draw()
65c.cd(2)
66ROOT.gPad.SetLeftMargin(0.15)
67yframe.GetYaxis().SetTitleOffset(1.4)
68yframe.Draw()
69c.cd(3)
70ROOT.gPad.SetLeftMargin(0.20)
71hh_model.GetZaxis().SetTitleOffset(2.5)
72hh_model.Draw("surf")
73
74c.SaveAs("rf301_composition.png")