Logo ROOT   6.16/01
Reference Guide
rf304_uncorrprod.py
Go to the documentation of this file.
1## \file
2## \ingroup tutorial_roofit
3## \notebook
4## 'MULTIDIMENSIONAL MODELS' RooFit tutorial macro #304
5## Simple uncorrelated multi-dimensional p.d.f.s
6##
7## pdf = gauss(x,mx,sx) * gauss(y,my,sy)
8##
9## \macro_code
10##
11## \date February 2018
12## \author Clemens Lange
13## \author Wouter Verkerke (C version)
14
15import ROOT
16
17
18# Create component pdfs in x and y
19# ----------------------------------------------------------------
20
21# Create two p.d.f.s gaussx(x,meanx,sigmax) gaussy(y,meany,sigmay) and its
22# variables
23x = ROOT.RooRealVar("x", "x", -5, 5)
24y = ROOT.RooRealVar("y", "y", -5, 5)
25
26meanx = ROOT.RooRealVar("mean1", "mean of gaussian x", 2)
27meany = ROOT.RooRealVar("mean2", "mean of gaussian y", -2)
28sigmax = ROOT.RooRealVar("sigmax", "width of gaussian x", 1)
29sigmay = ROOT.RooRealVar("sigmay", "width of gaussian y", 5)
30
31gaussx = ROOT.RooGaussian("gaussx", "gaussian PDF", x, meanx, sigmax)
32gaussy = ROOT.RooGaussian("gaussy", "gaussian PDF", y, meany, sigmay)
33
34# Construct uncorrelated product pdf
35# -------------------------------------------------------------------
36
37# Multiply gaussx and gaussy into a two-dimensional p.d.f. gaussxy
38gaussxy = ROOT.RooProdPdf(
39 "gaussxy", "gaussx*gaussy", ROOT.RooArgList(gaussx, gaussy))
40
41# Sample pdf, plot projection on x and y
42# ---------------------------------------------------------------------------
43
44# Generate 10000 events in x and y from gaussxy
45data = gaussxy.generate(ROOT.RooArgSet(x, y), 10000)
46
47# Plot x distribution of data and projection of gaussxy x = Int(dy)
48# gaussxy(x,y)
49xframe = x.frame(ROOT.RooFit.Title("X projection of gauss(x)*gauss(y)"))
50data.plotOn(xframe)
51gaussxy.plotOn(xframe)
52
53# Plot x distribution of data and projection of gaussxy y = Int(dx)
54# gaussxy(x,y)
55yframe = y.frame(ROOT.RooFit.Title("Y projection of gauss(x)*gauss(y)"))
56data.plotOn(yframe)
57gaussxy.plotOn(yframe)
58
59# Make canvas and draw ROOT.RooPlots
60c = ROOT.TCanvas("rf304_uncorrprod", "rf304_uncorrprod", 800, 400)
61c.Divide(2)
62c.cd(1)
63ROOT.gPad.SetLeftMargin(0.15)
64xframe.GetYaxis().SetTitleOffset(1.4)
65xframe.Draw()
66c.cd(2)
67ROOT.gPad.SetLeftMargin(0.15)
68yframe.GetYaxis().SetTitleOffset(1.4)
69yframe.Draw()
70
71c.SaveAs("rf304_uncorrprod.png")