rf304_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 Sunday, November 27, 2022 at 11:07 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"
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 [2]:
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);
[#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 [3]:
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 [4]:
RooDataSet *data = gaussxy.generate(RooArgSet(x, y), 10000);
input_line_52:2:2: warning: 'data' shadows a declaration with the same name in the 'std' namespace; use '::data' to reference this declaration
 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 [5]:
RooPlot *xframe = x.frame(Title("X projection of gauss(x)*gauss(y)"));
data->plotOn(xframe);
gaussxy.plotOn(xframe);
input_line_53:3:1: error: reference to 'data' is ambiguous
data->plotOn(xframe);
^
input_line_52: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 [6]:
RooPlot *yframe = y.frame(Title("Y projection of gauss(x)*gauss(y)"));
data->plotOn(yframe);
gaussxy.plotOn(yframe);
input_line_54:3:1: error: reference to 'data' is ambiguous
data->plotOn(yframe);
^
input_line_52: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 [7]:
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_56: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 [8]:
%jsroot on
gROOT->GetListOfCanvases()->Draw()