Multidimensional models: multi-dimensional pdfs through composition e.g. substituting a pdf parameter with a function that depends on other observables
pdf = gauss(x,f(y),s)
with f(y) = a0 + a1*y
Author: Wouter Verkerke
This notebook tutorial was automatically generated with ROOTBOOK-izer from the macro found in the ROOT repository on Friday, March 31, 2023 at 10:13 AM.
%%cpp -d
#include "RooRealVar.h"
#include "RooDataSet.h"
#include "RooGaussian.h"
#include "RooPolyVar.h"
#include "RooPlot.h"
#include "TCanvas.h"
#include "TAxis.h"
#include "TH1.h"
using namespace RooFit;
Create observables
RooRealVar x("x", "x", -5, 5);
RooRealVar y("y", "y", -5, 5);
Create function f(y) = a0 + a1*y
RooRealVar a0("a0", "a0", -0.5, -5, 5);
RooRealVar a1("a1", "a1", -0.5, -1, 1);
RooPolyVar fy("fy", "fy", y, RooArgSet(a0, a1));
Create gauss(x,f(y),s)
RooRealVar sigma("sigma", "width of gaussian", 0.5);
RooGaussian model("model", "Gaussian with shifting mean", x, fy, sigma);
[#0] WARNING:InputArguments -- The parameter 'sigma' with range [-inf, inf] of the RooGaussian 'model' exceeds the safe range of (0, inf). Advise to limit its range.
Generate 10000 events in x and y from model
RooDataSet *data = model.generate(RooArgSet(x, y), 10000);
[#1] INFO:NumericIntegration -- RooRealIntegral::init(model_Int[x,y]) using numeric integrator RooIntegrator1D to calculate Int(y) [#1] INFO:NumericIntegration -- RooRealIntegral::init(model_Int[x,y]) using numeric integrator RooIntegrator1D to calculate Int(y) [#1] INFO:NumericIntegration -- RooRealIntegral::init(model_Int[x,y]) using numeric integrator RooIntegrator1D to calculate Int(y)
input_line_51:2:2: warning: 'data' shadows a declaration with the same name in the 'std' namespace; use '::data' to reference this declaration RooDataSet *data = model.generate(RooArgSet(x, y), 10000); ^
Plot x distribution of data and projection of model on x = Int(dy) model(x,y)
RooPlot *xframe = x.frame();
data->plotOn(xframe);
model.plotOn(xframe);
input_line_52:3:1: error: reference to 'data' is ambiguous data->plotOn(xframe); ^ input_line_51:2:14: note: candidate found by name lookup is 'data' RooDataSet *data = model.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 model on y = Int(dx) model(x,y)
RooPlot *yframe = y.frame();
data->plotOn(yframe);
model.plotOn(yframe);
input_line_53:3:1: error: reference to 'data' is ambiguous data->plotOn(yframe); ^ input_line_51:2:14: note: candidate found by name lookup is 'data' RooDataSet *data = model.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 two-dimensional plot in x vs y
TH1 *hh_model = model.createHistogram("hh_model", x, Binning(50), YVar(y, Binning(50)));
hh_model->SetLineColor(kBlue);
[#1] INFO:NumericIntegration -- RooRealIntegral::init(model_Int[x,y]) using numeric integrator RooIntegrator1D to calculate Int(y)
Make canvas and draw RooPlots
TCanvas *c = new TCanvas("rf301_composition", "rf301_composition", 1200, 400);
c->Divide(3);
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();
c->cd(3);
gPad->SetLeftMargin(0.20);
hh_model->GetZaxis()->SetTitleOffset(2.5);
hh_model->Draw("surf");
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
gROOT->GetListOfCanvases()->Draw()