Logo ROOT   6.16/01
Reference Guide
rf305_condcorrprod.py
Go to the documentation of this file.
1## \file
2## \ingroup tutorial_roofit
3## \notebook
4## 'MULTIDIMENSIONAL MODELS' RooFit tutorial macro #305
5## Multi-dimensional p.d.f.s with conditional p.d.fs in product
6##
7## pdf = gauss(x,f(y),sx | y ) * gauss(y,ms,sx) with f(y) = a0 + a1*y
8##
9## \macro_code
10##
11## \date February 2018
12## \author Clemens Lange
13## \author Wouter Verkerke (C version)
14
15import ROOT
16
17# Create conditional pdf gx(x|y)
18# -----------------------------------------------------------
19
20# Create observables
21x = ROOT.RooRealVar("x", "x", -5, 5)
22y = ROOT.RooRealVar("y", "y", -5, 5)
23
24# Create function f(y) = a0 + a1*y
25a0 = ROOT.RooRealVar("a0", "a0", -0.5, -5, 5)
26a1 = ROOT.RooRealVar("a1", "a1", -0.5, -1, 1)
27fy = ROOT.RooPolyVar("fy", "fy", y, ROOT.RooArgList(a0, a1))
28
29# Create gaussx(x,f(y),sx)
30sigmax = ROOT.RooRealVar("sigma", "width of gaussian", 0.5)
31gaussx = ROOT.RooGaussian(
32 "gaussx", "Gaussian in x with shifting mean in y", x, fy, sigmax)
33
34# Create pdf gy(y)
35# -----------------------------------------------------------
36
37# Create gaussy(y,0,5)
38gaussy = ROOT.RooGaussian(
39 "gaussy", "Gaussian in y", y, ROOT.RooFit.RooConst(0), ROOT.RooFit.RooConst(3))
40
41# Create product gx(x|y)*gy(y)
42# -------------------------------------------------------
43
44# Create gaussx(x,sx|y) * gaussy(y)
45model = ROOT.RooProdPdf(
46 "model", "gaussx(x|y)*gaussy(y)", ROOT.RooArgSet(gaussy), ROOT.RooFit.Conditional(ROOT.RooArgSet(gaussx), ROOT.RooArgSet(x)))
47
48# Sample, fit and plot product pdf
49# ---------------------------------------------------------------
50
51# Generate 1000 events in x and y from model
52data = model.generate(ROOT.RooArgSet(x, y), 10000)
53
54# Plot x distribution of data and projection of model x = Int(dy)
55# model(x,y)
56xframe = x.frame()
57data.plotOn(xframe)
58model.plotOn(xframe)
59
60# Plot x distribution of data and projection of model y = Int(dx)
61# model(x,y)
62yframe = y.frame()
63data.plotOn(yframe)
64model.plotOn(yframe)
65
66# Make two-dimensional plot in x vs y
67hh_model = model.createHistogram("hh_model", x, ROOT.RooFit.Binning(
68 50), ROOT.RooFit.YVar(y, ROOT.RooFit.Binning(50)))
69hh_model.SetLineColor(ROOT.kBlue)
70
71# Make canvas and draw ROOT.RooPlots
72c = ROOT.TCanvas("rf305_condcorrprod", "rf05_condcorrprod", 1200, 400)
73c.Divide(3)
74c.cd(1)
75ROOT.gPad.SetLeftMargin(0.15)
76xframe.GetYaxis().SetTitleOffset(1.6)
77xframe.Draw()
78c.cd(2)
79ROOT.gPad.SetLeftMargin(0.15)
80yframe.GetYaxis().SetTitleOffset(1.6)
81yframe.Draw()
82c.cd(3)
83ROOT.gPad.SetLeftMargin(0.20)
84hh_model.GetZaxis().SetTitleOffset(2.5)
85hh_model.Draw("surf")
86
87c.SaveAs("rf305_condcorrprod.png")