Rf 3 0 4_Uncorrprod

Multidimensional models: simple uncorrelated multi-dimensional pdfs

pdf = gauss(x,mx,sx) * gauss(y,my,sy)

Author: Wouter Verkerke
This notebook tutorial was automatically generated with ROOTBOOK-izer from the macro found in the ROOT repository on Wednesday, January 19, 2022 at 10:17 AM.

In [1]:
%%cpp -d
#include "RooRealVar.h"
#include "RooDataSet.h"
#include "RooGaussian.h"
#include "RooProdPdf.h"
#include "TCanvas.h"
#include "TAxis.h"
#include "RooPlot.h"
In [2]:
%%cpp -d
// This is a workaround to make sure the namespace is used inside functions
using namespace RooFit;

Create component pdfs in x and y

Create two pdfs gaussx(x,meanx,sigmax) gaussy(y,meany,sigmay) and its variables

In [3]:
RooRealVar x("x", "x", -5, 5);
RooRealVar y("y", "y", -5, 5);

RooRealVar meanx("mean1", "mean of gaussian x", 2);
RooRealVar meany("mean2", "mean of gaussian y", -2);
RooRealVar sigmax("sigmax", "width of gaussian x", 1);
RooRealVar sigmay("sigmay", "width of gaussian y", 5);

RooGaussian gaussx("gaussx", "gaussian PDF", x, meanx, sigmax);
RooGaussian gaussy("gaussy", "gaussian PDF", y, meany, sigmay);
RooFit v3.60 -- Developed by Wouter Verkerke and David Kirkby 
                Copyright (C) 2000-2013 NIKHEF, University of California & Stanford University
                All rights reserved, please read http://roofit.sourceforge.net/license.txt

[#0] WARNING:InputArguments -- The parameter 'sigmax' with range [-1e+30, 1e+30] of the RooGaussian 'gaussx' exceeds the safe range of (0, inf). Advise to limit its range.
[#0] WARNING:InputArguments -- The parameter 'sigmay' with range [-1e+30, 1e+30] of the RooGaussian 'gaussy' exceeds the safe range of (0, inf). Advise to limit its range.

Construct uncorrelated product pdf

Multiply gaussx and gaussy into a two-dimensional pdf gaussxy

In [4]:
RooProdPdf gaussxy("gaussxy", "gaussx*gaussy", RooArgList(gaussx, gaussy));

Sample pdf, plot projection on x and y

Generate 10000 events in x and y from gaussxy

In [5]:
RooDataSet *data = gaussxy.generate(RooArgSet(x, y), 10000);

Plot x distribution of data and projection of gaussxy on x = int(dy) gaussxy(x,y)

In [6]:
RooPlot *xframe = x.frame(Title("X projection of gauss(x)*gauss(y)"));
data->plotOn(xframe);
gaussxy.plotOn(xframe);
input_line_56:3:1: error: reference to 'data' is ambiguous
data->plotOn(xframe);
^
input_line_55:2:14: note: candidate found by name lookup is '__cling_N523::data'
 RooDataSet *data = gaussxy.generate(RooArgSet(x, y), 10000);
             ^
/usr/include/c++/9/bits/range_access.h:318:5: note: candidate found by name lookup is 'std::data'
    data(initializer_list<_Tp> __il) noexcept
    ^
/usr/include/c++/9/bits/range_access.h:289:5: note: candidate found by name lookup is 'std::data'
    data(_Container& __cont) noexcept(noexcept(__cont.data()))
    ^
/usr/include/c++/9/bits/range_access.h:299:5: note: candidate found by name lookup is 'std::data'
    data(const _Container& __cont) noexcept(noexcept(__cont.data()))
    ^
/usr/include/c++/9/bits/range_access.h:309:5: note: candidate found by name lookup is 'std::data'
    data(_Tp (&__array)[_Nm]) noexcept
    ^

Plot x distribution of data and projection of gaussxy on y = int(dx) gaussxy(x,y)

In [7]:
RooPlot *yframe = y.frame(Title("Y projection of gauss(x)*gauss(y)"));
data->plotOn(yframe);
gaussxy.plotOn(yframe);
input_line_57:3:1: error: reference to 'data' is ambiguous
data->plotOn(yframe);
^
input_line_55:2:14: note: candidate found by name lookup is '__cling_N523::data'
 RooDataSet *data = gaussxy.generate(RooArgSet(x, y), 10000);
             ^
/usr/include/c++/9/bits/range_access.h:318:5: note: candidate found by name lookup is 'std::data'
    data(initializer_list<_Tp> __il) noexcept
    ^
/usr/include/c++/9/bits/range_access.h:289:5: note: candidate found by name lookup is 'std::data'
    data(_Container& __cont) noexcept(noexcept(__cont.data()))
    ^
/usr/include/c++/9/bits/range_access.h:299:5: note: candidate found by name lookup is 'std::data'
    data(const _Container& __cont) noexcept(noexcept(__cont.data()))
    ^
/usr/include/c++/9/bits/range_access.h:309:5: note: candidate found by name lookup is 'std::data'
    data(_Tp (&__array)[_Nm]) noexcept
    ^

Make canvas and draw rooplots

In [8]:
TCanvas *c = new TCanvas("rf304_uncorrprod", "rf304_uncorrprod", 800, 400);
c->Divide(2);
c->cd(1);
gPad->SetLeftMargin(0.15);
xframe->GetYaxis()->SetTitleOffset(1.4);
xframe->Draw();
c->cd(2);
gPad->SetLeftMargin(0.15);
yframe->GetYaxis()->SetTitleOffset(1.4);
yframe->Draw();
input_line_59:2:3: error: use of undeclared identifier 'xframe'
 (xframe->GetYaxis()->SetTitleOffset(1.3999999999999999))
  ^
Error in <HandleInterpreterException>: Error evaluating expression (xframe->GetYaxis()->SetTitleOffset(1.3999999999999999))
Execution of your code was aborted.

Draw all canvases

In [9]:
%jsroot on
gROOT->GetListOfCanvases()->Draw()