{
"cells": [
{
"cell_type": "markdown",
"id": "50678ca0",
"metadata": {},
"source": [
"# rf208_convolution\n",
"Addition and convolution: one-dimensional numeric convolution\n",
"\n",
"```\n",
"pdf = landau(t) (x) gauss(t)\n",
"```\n",
"\n",
"This tutorial requires FFT3 to be enabled.\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": "b134a2c1",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:30:06.228536Z",
"iopub.status.busy": "2026-05-19T20:30:06.228408Z",
"iopub.status.idle": "2026-05-19T20:30:06.242122Z",
"shell.execute_reply": "2026-05-19T20:30:06.241554Z"
}
},
"outputs": [],
"source": [
"%%cpp -d\n",
"#include \"RooRealVar.h\"\n",
"#include \"RooDataSet.h\"\n",
"#include \"RooGaussian.h\"\n",
"#include \"RooLandau.h\"\n",
"#include \"RooFFTConvPdf.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": "0f63a2d8",
"metadata": {},
"source": [
"Setup component pdfs\n",
"---------------------------------------"
]
},
{
"cell_type": "markdown",
"id": "89dccf89",
"metadata": {},
"source": [
"Construct observable"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "79f59e84",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:30:06.244136Z",
"iopub.status.busy": "2026-05-19T20:30:06.244012Z",
"iopub.status.idle": "2026-05-19T20:30:06.456369Z",
"shell.execute_reply": "2026-05-19T20:30:06.455767Z"
}
},
"outputs": [],
"source": [
"RooRealVar t(\"t\", \"t\", -10, 30);"
]
},
{
"cell_type": "markdown",
"id": "0068fec8",
"metadata": {},
"source": [
"Construct landau(t,ml,sl) ;"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "e85d6179",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:30:06.458415Z",
"iopub.status.busy": "2026-05-19T20:30:06.458289Z",
"iopub.status.idle": "2026-05-19T20:30:06.666024Z",
"shell.execute_reply": "2026-05-19T20:30:06.665417Z"
}
},
"outputs": [],
"source": [
"RooRealVar ml(\"ml\", \"mean landau\", 5., -20, 20);\n",
"RooRealVar sl(\"sl\", \"sigma landau\", 1, 0.1, 10);\n",
"RooLandau landau(\"lx\", \"lx\", t, ml, sl);"
]
},
{
"cell_type": "markdown",
"id": "a4d111a9",
"metadata": {},
"source": [
"Construct gauss(t,mg,sg)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "c4548bf5",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:30:06.668064Z",
"iopub.status.busy": "2026-05-19T20:30:06.667937Z",
"iopub.status.idle": "2026-05-19T20:30:06.876217Z",
"shell.execute_reply": "2026-05-19T20:30:06.875273Z"
}
},
"outputs": [],
"source": [
"RooRealVar mg(\"mg\", \"mg\", 0);\n",
"RooRealVar sg(\"sg\", \"sg\", 2, 0.1, 10);\n",
"RooGaussian gauss(\"gauss\", \"gauss\", t, mg, sg);"
]
},
{
"cell_type": "markdown",
"id": "8e718955",
"metadata": {},
"source": [
"Construct convolution pdf\n",
"---------------------------------------"
]
},
{
"cell_type": "markdown",
"id": "1e9fb650",
"metadata": {},
"source": [
"Set #bins to be used for FFT sampling to 10000"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "e882b9e2",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:30:06.877770Z",
"iopub.status.busy": "2026-05-19T20:30:06.877642Z",
"iopub.status.idle": "2026-05-19T20:30:07.082758Z",
"shell.execute_reply": "2026-05-19T20:30:07.082212Z"
}
},
"outputs": [],
"source": [
"t.setBins(10000, \"cache\");"
]
},
{
"cell_type": "markdown",
"id": "2113e3d9",
"metadata": {},
"source": [
"Construct landau (x) gauss"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "3750b946",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:30:07.091502Z",
"iopub.status.busy": "2026-05-19T20:30:07.091372Z",
"iopub.status.idle": "2026-05-19T20:30:07.305950Z",
"shell.execute_reply": "2026-05-19T20:30:07.305392Z"
}
},
"outputs": [],
"source": [
"RooFFTConvPdf lxg(\"lxg\", \"landau (X) gauss\", t, landau, gauss);"
]
},
{
"cell_type": "markdown",
"id": "f248de25",
"metadata": {},
"source": [
"Sample, fit and plot convoluted pdf\n",
"----------------------------------------------------------------------"
]
},
{
"cell_type": "markdown",
"id": "ae8989f1",
"metadata": {},
"source": [
"Sample 1000 events in x from gxlx"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "82609c01",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:30:07.308393Z",
"iopub.status.busy": "2026-05-19T20:30:07.308268Z",
"iopub.status.idle": "2026-05-19T20:30:07.517293Z",
"shell.execute_reply": "2026-05-19T20:30:07.516528Z"
}
},
"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{lxg.generate(t, 10000)};\n",
" ^\n"
]
}
],
"source": [
"std::unique_ptr data{lxg.generate(t, 10000)};"
]
},
{
"cell_type": "markdown",
"id": "7300cf4b",
"metadata": {},
"source": [
"Fit gxlx to data"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "c67d0207",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:30:07.518861Z",
"iopub.status.busy": "2026-05-19T20:30:07.518741Z",
"iopub.status.idle": "2026-05-19T20:30:07.727249Z",
"shell.execute_reply": "2026-05-19T20:30:07.726740Z"
}
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"input_line_55:2:13: error: reference to 'data' is ambiguous\n",
" lxg.fitTo(*data, PrintLevel(-1));\n",
" ^\n",
"input_line_54:2:30: note: candidate found by name lookup is 'data'\n",
" std::unique_ptr data{lxg.generate(t, 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": [
"lxg.fitTo(*data, PrintLevel(-1));"
]
},
{
"cell_type": "markdown",
"id": "837496d1",
"metadata": {},
"source": [
"Plot data, landau pdf, landau (X) gauss pdf"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "b374e5b8",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:30:07.728923Z",
"iopub.status.busy": "2026-05-19T20:30:07.728801Z",
"iopub.status.idle": "2026-05-19T20:30:07.937480Z",
"shell.execute_reply": "2026-05-19T20:30:07.936738Z"
}
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"input_line_56:3:1: error: reference to 'data' is ambiguous\n",
"data->plotOn(frame);\n",
"^\n",
"input_line_54:2:30: note: candidate found by name lookup is 'data'\n",
" std::unique_ptr data{lxg.generate(t, 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 *frame = t.frame(Title(\"landau (x) gauss convolution\"));\n",
"data->plotOn(frame);\n",
"lxg.plotOn(frame);\n",
"landau.plotOn(frame, LineStyle(kDashed));"
]
},
{
"cell_type": "markdown",
"id": "f714f7ab",
"metadata": {},
"source": [
"Draw frame on canvas"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "de4d634c",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:30:07.939161Z",
"iopub.status.busy": "2026-05-19T20:30:07.939038Z",
"iopub.status.idle": "2026-05-19T20:30:08.147660Z",
"shell.execute_reply": "2026-05-19T20:30:08.147159Z"
}
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"input_line_58:2:3: error: use of undeclared identifier 'frame'\n",
" (frame->GetYaxis()->SetTitleOffset(1.3999999999999999))\n",
" ^\n",
"Error in : Error evaluating expression (frame->GetYaxis()->SetTitleOffset(1.3999999999999999))\n",
"Execution of your code was aborted.\n"
]
}
],
"source": [
"new TCanvas(\"rf208_convolution\", \"rf208_convolution\", 600, 600);\n",
"gPad->SetLeftMargin(0.15);\n",
"frame->GetYaxis()->SetTitleOffset(1.4);\n",
"frame->Draw();"
]
},
{
"cell_type": "markdown",
"id": "107231e9",
"metadata": {},
"source": [
"Draw all canvases "
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "1716edf7",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:30:08.149350Z",
"iopub.status.busy": "2026-05-19T20:30:08.149230Z",
"iopub.status.idle": "2026-05-19T20:30:08.376873Z",
"shell.execute_reply": "2026-05-19T20:30:08.376312Z"
}
},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"\n",
"
\n",
"\n",
"\n",
"\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"%jsroot on\n",
"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
}