Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
rf304_uncorrprod.py
Go to the documentation of this file.
1## \file
2## \ingroup tutorial_roofit
3## \notebook
4## Multidimensional models: simple uncorrelated multi-dimensional pdfs
5##
6## `pdf = gauss(x,mx,sx) * gauss(y,my,sy)`
7##
8## \macro_image
9## \macro_code
10## \macro_output
11##
12## \date February 2018
13## \authors Clemens Lange, Wouter Verkerke (C++ version)
14
15import ROOT
16
17
18# Create component pdfs in x and y
19# ----------------------------------------------------------------
20
21# Create two pdfs 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 pdf gaussxy
38gaussxy = ROOT.RooProdPdf("gaussxy", "gaussx*gaussy", [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({x, y}, 10000)
45
46# Plot x distribution of data and projection of gaussxy x = Int(dy)
47# gaussxy(x,y)
48xframe = x.frame(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(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")