{
"cells": [
{
"cell_type": "markdown",
"id": "6c251746",
"metadata": {},
"source": [
"# rf305_condcorrprod\n",
"Multidimensional models: multi-dimensional pdfs with conditional pdfs in product\n",
"\n",
" `pdf = gauss(x,f(y),sx | y ) * gauss(y,ms,sx)` with `f(y) = a0 + a1*y`\n",
"\n",
"\n",
"\n",
"\n",
"**Author:** Wouter Verkerke \n",
"This notebook tutorial was automatically generated with ROOTBOOK-izer from the macro found in the ROOT repository on Tuesday, May 19, 2026 at 08:30 PM."
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "f80a7927",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:30:43.856960Z",
"iopub.status.busy": "2026-05-19T20:30:43.856850Z",
"iopub.status.idle": "2026-05-19T20:30:43.870269Z",
"shell.execute_reply": "2026-05-19T20:30:43.869800Z"
}
},
"outputs": [],
"source": [
"%%cpp -d\n",
"#include \"RooRealVar.h\"\n",
"#include \"RooDataSet.h\"\n",
"#include \"RooGaussian.h\"\n",
"#include \"RooPolyVar.h\"\n",
"#include \"RooProdPdf.h\"\n",
"#include \"RooPlot.h\"\n",
"#include \"TCanvas.h\"\n",
"#include \"TAxis.h\"\n",
"#include \"TH1.h\"\n",
"using namespace RooFit;"
]
},
{
"cell_type": "markdown",
"id": "c367d677",
"metadata": {},
"source": [
"Create conditional pdf gx(x|y)\n",
"-----------------------------------------------------------"
]
},
{
"cell_type": "markdown",
"id": "58b709ca",
"metadata": {},
"source": [
"Create observables"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "cbc6c5e3",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:30:43.871771Z",
"iopub.status.busy": "2026-05-19T20:30:43.871654Z",
"iopub.status.idle": "2026-05-19T20:30:44.083457Z",
"shell.execute_reply": "2026-05-19T20:30:44.082772Z"
}
},
"outputs": [],
"source": [
"RooRealVar x(\"x\", \"x\", -5, 5);\n",
"RooRealVar y(\"y\", \"y\", -5, 5);"
]
},
{
"cell_type": "markdown",
"id": "7217bd61",
"metadata": {},
"source": [
"Create function f(y) = a0 + a1*y"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "49f7db54",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:30:44.084885Z",
"iopub.status.busy": "2026-05-19T20:30:44.084767Z",
"iopub.status.idle": "2026-05-19T20:30:44.292614Z",
"shell.execute_reply": "2026-05-19T20:30:44.291938Z"
}
},
"outputs": [],
"source": [
"RooRealVar a0(\"a0\", \"a0\", -0.5, -5, 5);\n",
"RooRealVar a1(\"a1\", \"a1\", -0.5, -1, 1);\n",
"RooPolyVar fy(\"fy\", \"fy\", y, RooArgSet(a0, a1));"
]
},
{
"cell_type": "markdown",
"id": "a9cba1ea",
"metadata": {},
"source": [
"Create gaussx(x,f(y),sx)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "12f47dcb",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:30:44.294110Z",
"iopub.status.busy": "2026-05-19T20:30:44.293991Z",
"iopub.status.idle": "2026-05-19T20:30:44.501939Z",
"shell.execute_reply": "2026-05-19T20:30:44.501603Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[#0] WARNING:InputArguments -- The parameter 'sigma' with range [-inf, inf] of the RooGaussian 'gaussx' exceeds the safe range of (0, inf). Advise to limit its range.\n"
]
}
],
"source": [
"RooRealVar sigmax(\"sigma\", \"width of gaussian\", 0.5);\n",
"RooGaussian gaussx(\"gaussx\", \"Gaussian in x with shifting mean in y\", x, fy, sigmax);"
]
},
{
"cell_type": "markdown",
"id": "1824189a",
"metadata": {},
"source": [
"Create pdf gy(y)\n",
"-----------------------------------------------------------"
]
},
{
"cell_type": "markdown",
"id": "56b547c6",
"metadata": {},
"source": [
"Create gaussy(y,0,5)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "8fd60fc6",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:30:44.517997Z",
"iopub.status.busy": "2026-05-19T20:30:44.517855Z",
"iopub.status.idle": "2026-05-19T20:30:44.733234Z",
"shell.execute_reply": "2026-05-19T20:30:44.732508Z"
}
},
"outputs": [],
"source": [
"RooGaussian gaussy(\"gaussy\", \"Gaussian in y\", y, 0.0, 3.0);"
]
},
{
"cell_type": "markdown",
"id": "4622cf94",
"metadata": {},
"source": [
"Create product gx(x|y)*gy(y)\n",
"-------------------------------------------------------"
]
},
{
"cell_type": "markdown",
"id": "a2d6cd48",
"metadata": {},
"source": [
"Create gaussx(x,sx|y) * gaussy(y)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "15c961a3",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:30:44.734946Z",
"iopub.status.busy": "2026-05-19T20:30:44.734826Z",
"iopub.status.idle": "2026-05-19T20:30:44.942619Z",
"shell.execute_reply": "2026-05-19T20:30:44.942003Z"
}
},
"outputs": [],
"source": [
"RooProdPdf model(\"model\", \"gaussx(x|y)*gaussy(y)\", gaussy, Conditional(gaussx, x));"
]
},
{
"cell_type": "markdown",
"id": "ed57b4a9",
"metadata": {},
"source": [
"Sample, fit and plot product pdf\n",
"---------------------------------------------------------------"
]
},
{
"cell_type": "markdown",
"id": "91b552f7",
"metadata": {},
"source": [
"Generate 1000 events in x and y from model"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "fa3fa5a1",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:30:44.944685Z",
"iopub.status.busy": "2026-05-19T20:30:44.944547Z",
"iopub.status.idle": "2026-05-19T20:30:45.165924Z",
"shell.execute_reply": "2026-05-19T20:30:45.165308Z"
}
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"input_line_54:2:2: warning: 'data' shadows a declaration with the same name in the 'std' namespace; use '::data' to reference this declaration\n",
" std::unique_ptr data{model.generate({x, y}, 10000)};\n",
" ^\n"
]
}
],
"source": [
"std::unique_ptr data{model.generate({x, y}, 10000)};"
]
},
{
"cell_type": "markdown",
"id": "188e0fc2",
"metadata": {},
"source": [
"Plot x distribution of data and projection of model on x = Int(dy) model(x,y)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "0a66aa64",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:30:45.167494Z",
"iopub.status.busy": "2026-05-19T20:30:45.167375Z",
"iopub.status.idle": "2026-05-19T20:30:45.376288Z",
"shell.execute_reply": "2026-05-19T20:30:45.375632Z"
}
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"input_line_55:3:1: error: reference to 'data' is ambiguous\n",
"data->plotOn(xframe);\n",
"^\n",
"input_line_54:2:30: note: candidate found by name lookup is 'data'\n",
" std::unique_ptr data{model.generate({x, y}, 10000)};\n",
" ^\n",
"/usr/lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/bits/range_access.h:344:5: note: candidate found by name lookup is 'std::data'\n",
" data(initializer_list<_Tp> __il) noexcept\n",
" ^\n",
"/usr/lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/bits/range_access.h:312:5: note: candidate found by name lookup is 'std::data'\n",
" data(_Container& __cont) noexcept(noexcept(__cont.data()))\n",
" ^\n",
"/usr/lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/bits/range_access.h:323:5: note: candidate found by name lookup is 'std::data'\n",
" data(const _Container& __cont) noexcept(noexcept(__cont.data()))\n",
" ^\n",
"/usr/lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/bits/range_access.h:334:5: note: candidate found by name lookup is 'std::data'\n",
" data(_Tp (&__array)[_Nm]) noexcept\n",
" ^\n"
]
}
],
"source": [
"RooPlot *xframe = x.frame();\n",
"data->plotOn(xframe);\n",
"model.plotOn(xframe);"
]
},
{
"cell_type": "markdown",
"id": "a7c1845a",
"metadata": {},
"source": [
"Plot x distribution of data and projection of model on y = Int(dx) model(x,y)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "306ea71d",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:30:45.377954Z",
"iopub.status.busy": "2026-05-19T20:30:45.377831Z",
"iopub.status.idle": "2026-05-19T20:30:45.586523Z",
"shell.execute_reply": "2026-05-19T20:30:45.585939Z"
}
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"input_line_56:3:1: error: reference to 'data' is ambiguous\n",
"data->plotOn(yframe);\n",
"^\n",
"input_line_54:2:30: note: candidate found by name lookup is 'data'\n",
" std::unique_ptr data{model.generate({x, y}, 10000)};\n",
" ^\n",
"/usr/lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/bits/range_access.h:344:5: note: candidate found by name lookup is 'std::data'\n",
" data(initializer_list<_Tp> __il) noexcept\n",
" ^\n",
"/usr/lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/bits/range_access.h:312:5: note: candidate found by name lookup is 'std::data'\n",
" data(_Container& __cont) noexcept(noexcept(__cont.data()))\n",
" ^\n",
"/usr/lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/bits/range_access.h:323:5: note: candidate found by name lookup is 'std::data'\n",
" data(const _Container& __cont) noexcept(noexcept(__cont.data()))\n",
" ^\n",
"/usr/lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/bits/range_access.h:334:5: note: candidate found by name lookup is 'std::data'\n",
" data(_Tp (&__array)[_Nm]) noexcept\n",
" ^\n"
]
}
],
"source": [
"RooPlot *yframe = y.frame();\n",
"data->plotOn(yframe);\n",
"model.plotOn(yframe);"
]
},
{
"cell_type": "markdown",
"id": "f20f3e10",
"metadata": {},
"source": [
"Make two-dimensional plot in x vs y"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "65d108f5",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:30:45.588186Z",
"iopub.status.busy": "2026-05-19T20:30:45.588065Z",
"iopub.status.idle": "2026-05-19T20:30:45.795597Z",
"shell.execute_reply": "2026-05-19T20:30:45.795125Z"
}
},
"outputs": [],
"source": [
"TH1 *hh_model = model.createHistogram(\"hh_model\", x, Binning(50), YVar(y, Binning(50)));\n",
"hh_model->SetLineColor(kBlue);"
]
},
{
"cell_type": "markdown",
"id": "2ef09515",
"metadata": {},
"source": [
"Make canvas and draw RooPlots"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "56325b51",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:30:45.819182Z",
"iopub.status.busy": "2026-05-19T20:30:45.819048Z",
"iopub.status.idle": "2026-05-19T20:30:46.024742Z",
"shell.execute_reply": "2026-05-19T20:30:46.024159Z"
}
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"input_line_59:2:3: error: use of undeclared identifier 'xframe'\n",
" (xframe->GetYaxis()->SetTitleOffset(1.6000000000000001))\n",
" ^\n",
"Error in : Error evaluating expression (xframe->GetYaxis()->SetTitleOffset(1.6000000000000001))\n",
"Execution of your code was aborted.\n"
]
}
],
"source": [
"TCanvas *c = new TCanvas(\"rf305_condcorrprod\", \"rf05_condcorrprod\", 1200, 400);\n",
"c->Divide(3);\n",
"c->cd(1);\n",
"gPad->SetLeftMargin(0.15);\n",
"xframe->GetYaxis()->SetTitleOffset(1.6);\n",
"xframe->Draw();\n",
"c->cd(2);\n",
"gPad->SetLeftMargin(0.15);\n",
"yframe->GetYaxis()->SetTitleOffset(1.6);\n",
"yframe->Draw();\n",
"c->cd(3);\n",
"gPad->SetLeftMargin(0.20);\n",
"hh_model->GetZaxis()->SetTitleOffset(2.5);\n",
"hh_model->Draw(\"surf\");"
]
},
{
"cell_type": "markdown",
"id": "703310aa",
"metadata": {},
"source": [
"Draw all canvases "
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "dc96bb18",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:30:46.026401Z",
"iopub.status.busy": "2026-05-19T20:30:46.026277Z",
"iopub.status.idle": "2026-05-19T20:30:46.238875Z",
"shell.execute_reply": "2026-05-19T20:30:46.238523Z"
}
},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"\n",
"
\n",
"\n",
"\n",
"\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"gROOT->GetListOfCanvases()->Draw()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "ROOT C++",
"language": "c++",
"name": "root"
},
"language_info": {
"codemirror_mode": "text/x-c++src",
"file_extension": ".C",
"mimetype": " text/x-c++src",
"name": "c++"
}
},
"nbformat": 4,
"nbformat_minor": 5
}