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 
14 import 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
22 x = ROOT.RooRealVar("x", "x", -5, 5)
23 y = ROOT.RooRealVar("y", "y", -5, 5)
24 
25 meanx = ROOT.RooRealVar("mean1", "mean of gaussian x", 2)
26 meany = ROOT.RooRealVar("mean2", "mean of gaussian y", -2)
27 sigmax = ROOT.RooRealVar("sigmax", "width of gaussian x", 1)
28 sigmay = ROOT.RooRealVar("sigmay", "width of gaussian y", 5)
29 
30 gaussx = ROOT.RooGaussian("gaussx", "gaussian PDF", x, meanx, sigmax)
31 gaussy = 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
37 gaussxy = 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
44 data = 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)
48 xframe = x.frame(ROOT.RooFit.Title("X projection of gauss(x)*gauss(y)"))
49 data.plotOn(xframe)
50 gaussxy.plotOn(xframe)
51 
52 # Plot x distribution of data and projection of gaussxy y = Int(dx)
53 # gaussxy(x,y)
54 yframe = y.frame(ROOT.RooFit.Title("Y projection of gauss(x)*gauss(y)"))
55 data.plotOn(yframe)
56 gaussxy.plotOn(yframe)
57 
58 # Make canvas and draw ROOT.RooPlots
59 c = ROOT.TCanvas("rf304_uncorrprod", "rf304_uncorrprod", 800, 400)
60 c.Divide(2)
61 c.cd(1)
62 ROOT.gPad.SetLeftMargin(0.15)
63 xframe.GetYaxis().SetTitleOffset(1.4)
64 xframe.Draw()
65 c.cd(2)
66 ROOT.gPad.SetLeftMargin(0.15)
67 yframe.GetYaxis().SetTitleOffset(1.4)
68 yframe.Draw()
69 
70 c.SaveAs("rf304_uncorrprod.png")