Logo ROOT  
Reference Guide
rf304_uncorrprod.py
Go to the documentation of this file.
1## \file
2## \ingroup tutorial_roofit
3## \notebook
4##
5## Multidimensional models: 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## \authors Clemens Lange, Wouter Verkerke (C++ version)
13
14import ROOT
15
16
17# Create component pdfs in x and y
18# ----------------------------------------------------------------
19
20# Create two p.d.f.s gaussx(x,meanx,sigmax) gaussy(y,meany,sigmay) and its
21# variables
22x = ROOT.RooRealVar("x", "x", -5, 5)
23y = ROOT.RooRealVar("y", "y", -5, 5)
24
25meanx = ROOT.RooRealVar("mean1", "mean of gaussian x", 2)
26meany = ROOT.RooRealVar("mean2", "mean of gaussian y", -2)
27sigmax = ROOT.RooRealVar("sigmax", "width of gaussian x", 1)
28sigmay = ROOT.RooRealVar("sigmay", "width of gaussian y", 5)
29
30gaussx = ROOT.RooGaussian("gaussx", "gaussian PDF", x, meanx, sigmax)
31gaussy = ROOT.RooGaussian("gaussy", "gaussian PDF", y, meany, sigmay)
32
33# Construct uncorrelated product pdf
34# -------------------------------------------------------------------
35
36# Multiply gaussx and gaussy into a two-dimensional p.d.f. gaussxy
37gaussxy = ROOT.RooProdPdf(
38 "gaussxy", "gaussx*gaussy", ROOT.RooArgList(gaussx, gaussy))
39
40# Sample pdf, plot projection on x and y
41# ---------------------------------------------------------------------------
42
43# Generate 10000 events in x and y from gaussxy
44data = gaussxy.generate(ROOT.RooArgSet(x, y), 10000)
45
46# Plot x distribution of data and projection of gaussxy x = Int(dy)
47# gaussxy(x,y)
48xframe = x.frame(ROOT.RooFit.Title("X projection of gauss(x)*gauss(y)"))
49data.plotOn(xframe)
50gaussxy.plotOn(xframe)
51
52# Plot x distribution of data and projection of gaussxy y = Int(dx)
53# gaussxy(x,y)
54yframe = y.frame(ROOT.RooFit.Title("Y projection of gauss(x)*gauss(y)"))
55data.plotOn(yframe)
56gaussxy.plotOn(yframe)
57
58# Make canvas and draw ROOT.RooPlots
59c = ROOT.TCanvas("rf304_uncorrprod", "rf304_uncorrprod", 800, 400)
60c.Divide(2)
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()
69
70c.SaveAs("rf304_uncorrprod.png")