{ "cells": [ { "cell_type": "markdown", "id": "8d3d8745", "metadata": {}, "source": [ "# rf304_uncorrprod\n", "Multidimensional models: simple uncorrelated multi-dimensional pdfs\n", "\n", "`pdf = gauss(x,mx,sx) * gauss(y,my,sy)`\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": "57966912", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:30:39.815290Z", "iopub.status.busy": "2026-05-19T20:30:39.815156Z", "iopub.status.idle": "2026-05-19T20:30:39.828295Z", "shell.execute_reply": "2026-05-19T20:30:39.827994Z" } }, "outputs": [], "source": [ "%%cpp -d\n", "#include \"RooRealVar.h\"\n", "#include \"RooDataSet.h\"\n", "#include \"RooGaussian.h\"\n", "#include \"RooProdPdf.h\"\n", "#include \"TCanvas.h\"\n", "#include \"TAxis.h\"\n", "#include \"RooPlot.h\"\n", "using namespace RooFit;" ] }, { "cell_type": "markdown", "id": "87d282f9", "metadata": {}, "source": [ "Create component pdfs in x and y\n", "----------------------------------------------------------------" ] }, { "cell_type": "markdown", "id": "810c939f", "metadata": {}, "source": [ "Create two pdfs gaussx(x,meanx,sigmax) gaussy(y,meany,sigmay) and its variables" ] }, { "cell_type": "code", "execution_count": 2, "id": "a9010184", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:30:39.837763Z", "iopub.status.busy": "2026-05-19T20:30:39.837587Z", "iopub.status.idle": "2026-05-19T20:30:40.202678Z", "shell.execute_reply": "2026-05-19T20:30:40.202350Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[#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.\n", "[#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.\n" ] } ], "source": [ "RooRealVar x(\"x\", \"x\", -5, 5);\n", "RooRealVar y(\"y\", \"y\", -5, 5);\n", "\n", "RooRealVar meanx(\"mean1\", \"mean of gaussian x\", 2);\n", "RooRealVar meany(\"mean2\", \"mean of gaussian y\", -2);\n", "RooRealVar sigmax(\"sigmax\", \"width of gaussian x\", 1);\n", "RooRealVar sigmay(\"sigmay\", \"width of gaussian y\", 5);\n", "\n", "RooGaussian gaussx(\"gaussx\", \"gaussian PDF\", x, meanx, sigmax);\n", "RooGaussian gaussy(\"gaussy\", \"gaussian PDF\", y, meany, sigmay);" ] }, { "cell_type": "markdown", "id": "5a4247b5", "metadata": {}, "source": [ "Construct uncorrelated product pdf\n", "-------------------------------------------------------------------" ] }, { "cell_type": "markdown", "id": "014080bd", "metadata": {}, "source": [ "Multiply gaussx and gaussy into a two-dimensional pdf gaussxy" ] }, { "cell_type": "code", "execution_count": 3, "id": "dd84afa8", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:30:40.215023Z", "iopub.status.busy": "2026-05-19T20:30:40.214887Z", "iopub.status.idle": "2026-05-19T20:30:40.434895Z", "shell.execute_reply": "2026-05-19T20:30:40.433715Z" } }, "outputs": [], "source": [ "RooProdPdf gaussxy(\"gaussxy\", \"gaussx*gaussy\", RooArgList(gaussx, gaussy));" ] }, { "cell_type": "markdown", "id": "c17926a9", "metadata": {}, "source": [ "Sample pdf, plot projection on x and y\n", "---------------------------------------------------------------------------" ] }, { "cell_type": "markdown", "id": "f719c14b", "metadata": {}, "source": [ "Generate 10000 events in x and y from gaussxy" ] }, { "cell_type": "code", "execution_count": 4, "id": "4759ba18", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:30:40.436723Z", "iopub.status.busy": "2026-05-19T20:30:40.436552Z", "iopub.status.idle": "2026-05-19T20:30:40.645490Z", "shell.execute_reply": "2026-05-19T20:30:40.644786Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "input_line_51: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{gaussxy.generate({x, y}, 10000)};\n", " ^\n" ] } ], "source": [ "std::unique_ptr data{gaussxy.generate({x, y}, 10000)};" ] }, { "cell_type": "markdown", "id": "9be1877b", "metadata": {}, "source": [ "Plot x distribution of data and projection of gaussxy on x = Int(dy) gaussxy(x,y)" ] }, { "cell_type": "code", "execution_count": 5, "id": "48cb77af", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:30:40.647428Z", "iopub.status.busy": "2026-05-19T20:30:40.647293Z", "iopub.status.idle": "2026-05-19T20:30:40.856490Z", "shell.execute_reply": "2026-05-19T20:30:40.856110Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "input_line_52:3:1: error: reference to 'data' is ambiguous\n", "data->plotOn(xframe);\n", "^\n", "input_line_51:2:30: note: candidate found by name lookup is 'data'\n", " std::unique_ptr data{gaussxy.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(Title(\"X projection of gauss(x)*gauss(y)\"));\n", "data->plotOn(xframe);\n", "gaussxy.plotOn(xframe);" ] }, { "cell_type": "markdown", "id": "6a8684b4", "metadata": {}, "source": [ "Plot x distribution of data and projection of gaussxy on y = Int(dx) gaussxy(x,y)" ] }, { "cell_type": "code", "execution_count": 6, "id": "6b37f8df", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:30:40.864068Z", "iopub.status.busy": "2026-05-19T20:30:40.863937Z", "iopub.status.idle": "2026-05-19T20:30:41.074048Z", "shell.execute_reply": "2026-05-19T20:30:41.072997Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "input_line_53:3:1: error: reference to 'data' is ambiguous\n", "data->plotOn(yframe);\n", "^\n", "input_line_51:2:30: note: candidate found by name lookup is 'data'\n", " std::unique_ptr data{gaussxy.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(Title(\"Y projection of gauss(x)*gauss(y)\"));\n", "data->plotOn(yframe);\n", "gaussxy.plotOn(yframe);" ] }, { "cell_type": "markdown", "id": "c92e95b8", "metadata": {}, "source": [ "Make canvas and draw RooPlots" ] }, { "cell_type": "code", "execution_count": 7, "id": "47485dca", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:30:41.075865Z", "iopub.status.busy": "2026-05-19T20:30:41.075712Z", "iopub.status.idle": "2026-05-19T20:30:41.294984Z", "shell.execute_reply": "2026-05-19T20:30:41.293570Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "input_line_55:2:3: error: use of undeclared identifier 'xframe'\n", " (xframe->GetYaxis()->SetTitleOffset(1.3999999999999999))\n", " ^\n", "Error in : Error evaluating expression (xframe->GetYaxis()->SetTitleOffset(1.3999999999999999))\n", "Execution of your code was aborted.\n" ] } ], "source": [ "TCanvas *c = new TCanvas(\"rf304_uncorrprod\", \"rf304_uncorrprod\", 800, 400);\n", "c->Divide(2);\n", "c->cd(1);\n", "gPad->SetLeftMargin(0.15);\n", "xframe->GetYaxis()->SetTitleOffset(1.4);\n", "xframe->Draw();\n", "c->cd(2);\n", "gPad->SetLeftMargin(0.15);\n", "yframe->GetYaxis()->SetTitleOffset(1.4);\n", "yframe->Draw();" ] }, { "cell_type": "markdown", "id": "24edf32f", "metadata": {}, "source": [ "Draw all canvases " ] }, { "cell_type": "code", "execution_count": 8, "id": "069c7ada", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:30:41.296674Z", "iopub.status.busy": "2026-05-19T20:30:41.296521Z", "iopub.status.idle": "2026-05-19T20:30:41.526194Z", "shell.execute_reply": "2026-05-19T20:30:41.525686Z" } }, "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 }