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 Tuesday, March 19, 2024 at 07:15 PM.
%%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 two pdfs gaussx(x,meanx,sigmax) gaussy(y,meany,sigmay) and its variables
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 [-inf, inf] of the RooGaussian 'gaussx' exceeds the safe range of (0, inf). Advise to limit its range. [#0] WARNING:InputArguments -- The parameter 'sigmay' with range [-inf, inf] of the RooGaussian 'gaussy' exceeds the safe range of (0, inf). Advise to limit its range.
Multiply gaussx and gaussy into a two-dimensional pdf gaussxy
RooProdPdf gaussxy("gaussxy", "gaussx*gaussy", RooArgList(gaussx, gaussy));
Generate 10000 events in x and y from gaussxy
std::unique_ptr<RooDataSet> data{gaussxy.generate({x, y}, 10000)};
input_line_50:2:2: warning: 'data' shadows a declaration with the same name in the 'std' namespace; use '::data' to reference this declaration std::unique_ptr<RooDataSet> data{gaussxy.generate({x, y}, 10000)}; ^
Plot x distribution of data and projection of gaussxy on x = Int(dy) gaussxy(x,y)
RooPlot *xframe = x.frame(Title("X projection of gauss(x)*gauss(y)"));
data->plotOn(xframe);
gaussxy.plotOn(xframe);
input_line_51:3:1: error: reference to 'data' is ambiguous data->plotOn(xframe); ^ input_line_50:2:30: note: candidate found by name lookup is 'data' std::unique_ptr<RooDataSet> data{gaussxy.generate({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)
RooPlot *yframe = y.frame(Title("Y projection of gauss(x)*gauss(y)"));
data->plotOn(yframe);
gaussxy.plotOn(yframe);
input_line_52:3:1: error: reference to 'data' is ambiguous data->plotOn(yframe); ^ input_line_50:2:30: note: candidate found by name lookup is 'data' std::unique_ptr<RooDataSet> data{gaussxy.generate({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
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_54: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
%jsroot on
gROOT->GetListOfCanvases()->Draw()