{ "cells": [ { "cell_type": "markdown", "id": "908823db", "metadata": {}, "source": [ "# rf302_utilfuncs\n", "Multidimensional models: utility functions classes available for use in tailoring of\n", "composite (multidimensional) pdfs\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": "82cb5cb8", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:30:31.552365Z", "iopub.status.busy": "2026-05-19T20:30:31.552223Z", "iopub.status.idle": "2026-05-19T20:30:31.566164Z", "shell.execute_reply": "2026-05-19T20:30:31.565510Z" } }, "outputs": [], "source": [ "%%cpp -d\n", "#include \"RooRealVar.h\"\n", "#include \"RooDataSet.h\"\n", "#include \"RooGaussian.h\"\n", "#include \"TCanvas.h\"\n", "#include \"TAxis.h\"\n", "#include \"RooPlot.h\"\n", "#include \"RooFormulaVar.h\"\n", "#include \"RooAddition.h\"\n", "#include \"RooProduct.h\"\n", "#include \"RooPolyVar.h\"\n", "#include \"TCanvas.h\"\n", "#include \"TAxis.h\"\n", "#include \"TH1.h\"\n", "\n", "using namespace RooFit;" ] }, { "cell_type": "markdown", "id": "f0c722c3", "metadata": {}, "source": [ "Create observables, parameters\n", "-----------------------------------------------------------" ] }, { "cell_type": "markdown", "id": "a3ce193d", "metadata": {}, "source": [ "Create observables" ] }, { "cell_type": "code", "execution_count": 2, "id": "f404f626", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:30:31.567669Z", "iopub.status.busy": "2026-05-19T20:30:31.567531Z", "iopub.status.idle": "2026-05-19T20:30:31.880357Z", "shell.execute_reply": "2026-05-19T20:30:31.879804Z" } }, "outputs": [], "source": [ "RooRealVar x(\"x\", \"x\", -5, 5);\n", "RooRealVar y(\"y\", \"y\", -5, 5);" ] }, { "cell_type": "markdown", "id": "82ddc031", "metadata": {}, "source": [ "Create parameters" ] }, { "cell_type": "code", "execution_count": 3, "id": "142be45f", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:30:31.882444Z", "iopub.status.busy": "2026-05-19T20:30:31.882329Z", "iopub.status.idle": "2026-05-19T20:30:32.090053Z", "shell.execute_reply": "2026-05-19T20:30:32.089391Z" } }, "outputs": [], "source": [ "RooRealVar a0(\"a0\", \"a0\", -1.5, -5, 5);\n", "RooRealVar a1(\"a1\", \"a1\", -0.5, -1, 1);\n", "RooRealVar sigma(\"sigma\", \"width of gaussian\", 0.5);" ] }, { "cell_type": "markdown", "id": "d4e22235", "metadata": {}, "source": [ "Using RooFormulaVar to tailor pdf\n", "-----------------------------------------------------------------------" ] }, { "cell_type": "markdown", "id": "f229bbbc", "metadata": {}, "source": [ "Create interpreted function f(y) = a0 - a1*sqrt(10*abs(y))" ] }, { "cell_type": "code", "execution_count": 4, "id": "7d23ec0c", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:30:32.092069Z", "iopub.status.busy": "2026-05-19T20:30:32.091954Z", "iopub.status.idle": "2026-05-19T20:30:32.299767Z", "shell.execute_reply": "2026-05-19T20:30:32.299064Z" } }, "outputs": [], "source": [ "RooFormulaVar fy_1(\"fy_1\", \"a0-a1*sqrt(10*abs(y))\", RooArgSet(y, a0, a1));" ] }, { "cell_type": "markdown", "id": "d1602c2b", "metadata": {}, "source": [ "Create gauss(x,f(y),s)" ] }, { "cell_type": "code", "execution_count": 5, "id": "386d8683", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:30:32.301655Z", "iopub.status.busy": "2026-05-19T20:30:32.301520Z", "iopub.status.idle": "2026-05-19T20:30:32.509199Z", "shell.execute_reply": "2026-05-19T20:30:32.508884Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[#0] WARNING:InputArguments -- The parameter 'sigma' with range [-inf, inf] of the RooGaussian 'model_1' exceeds the safe range of (0, inf). Advise to limit its range.\n" ] } ], "source": [ "RooGaussian model_1(\"model_1\", \"Gaussian with shifting mean\", x, fy_1, sigma);" ] }, { "cell_type": "markdown", "id": "e04a570b", "metadata": {}, "source": [ "Using RooPolyVar to tailor pdf\n", "-----------------------------------------------------------------------" ] }, { "cell_type": "markdown", "id": "280b7ec0", "metadata": {}, "source": [ "Create polynomial function f(y) = a0 + a1*y" ] }, { "cell_type": "code", "execution_count": 6, "id": "17e4da13", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:30:32.511158Z", "iopub.status.busy": "2026-05-19T20:30:32.511041Z", "iopub.status.idle": "2026-05-19T20:30:32.718865Z", "shell.execute_reply": "2026-05-19T20:30:32.718164Z" } }, "outputs": [], "source": [ "RooPolyVar fy_2(\"fy_2\", \"fy_2\", y, RooArgSet(a0, a1));" ] }, { "cell_type": "markdown", "id": "850e0872", "metadata": {}, "source": [ "Create gauss(x,f(y),s)" ] }, { "cell_type": "code", "execution_count": 7, "id": "217f4a70", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:30:32.720708Z", "iopub.status.busy": "2026-05-19T20:30:32.720569Z", "iopub.status.idle": "2026-05-19T20:30:32.928569Z", "shell.execute_reply": "2026-05-19T20:30:32.928022Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[#0] WARNING:InputArguments -- The parameter 'sigma' with range [-inf, inf] of the RooGaussian 'model_2' exceeds the safe range of (0, inf). Advise to limit its range.\n" ] } ], "source": [ "RooGaussian model_2(\"model_2\", \"Gaussian with shifting mean\", x, fy_2, sigma);" ] }, { "cell_type": "markdown", "id": "8af135e4", "metadata": {}, "source": [ "Using RooAddition to tailor pdf\n", "-----------------------------------------------------------------------" ] }, { "cell_type": "markdown", "id": "91b21dba", "metadata": {}, "source": [ "Create sum function f(y) = a0 + y" ] }, { "cell_type": "code", "execution_count": 8, "id": "1f3ae99c", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:30:32.930332Z", "iopub.status.busy": "2026-05-19T20:30:32.930215Z", "iopub.status.idle": "2026-05-19T20:30:33.137931Z", "shell.execute_reply": "2026-05-19T20:30:33.137199Z" } }, "outputs": [], "source": [ "RooAddition fy_3(\"fy_3\", \"a0+y\", RooArgSet(a0, y));" ] }, { "cell_type": "markdown", "id": "a417fdd0", "metadata": {}, "source": [ "Create gauss(x,f(y),s)" ] }, { "cell_type": "code", "execution_count": 9, "id": "86158afe", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:30:33.139703Z", "iopub.status.busy": "2026-05-19T20:30:33.139563Z", "iopub.status.idle": "2026-05-19T20:30:33.347551Z", "shell.execute_reply": "2026-05-19T20:30:33.346927Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[#0] WARNING:InputArguments -- The parameter 'sigma' with range [-inf, inf] of the RooGaussian 'model_3' exceeds the safe range of (0, inf). Advise to limit its range.\n" ] } ], "source": [ "RooGaussian model_3(\"model_3\", \"Gaussian with shifting mean\", x, fy_3, sigma);" ] }, { "cell_type": "markdown", "id": "ab777d5c", "metadata": {}, "source": [ "Using RooProduct to tailor pdf\n", "-----------------------------------------------------------------------" ] }, { "cell_type": "markdown", "id": "88931bd5", "metadata": {}, "source": [ "Create product function f(y) = a1*y" ] }, { "cell_type": "code", "execution_count": 10, "id": "f0c153ea", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:30:33.349006Z", "iopub.status.busy": "2026-05-19T20:30:33.348894Z", "iopub.status.idle": "2026-05-19T20:30:33.556573Z", "shell.execute_reply": "2026-05-19T20:30:33.555929Z" } }, "outputs": [], "source": [ "RooProduct fy_4(\"fy_4\", \"a1*y\", RooArgSet(a1, y));" ] }, { "cell_type": "markdown", "id": "553604fd", "metadata": {}, "source": [ "Create gauss(x,f(y),s)" ] }, { "cell_type": "code", "execution_count": 11, "id": "3bc04101", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:30:33.558642Z", "iopub.status.busy": "2026-05-19T20:30:33.558507Z", "iopub.status.idle": "2026-05-19T20:30:33.766121Z", "shell.execute_reply": "2026-05-19T20:30:33.765804Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[#0] WARNING:InputArguments -- The parameter 'sigma' with range [-inf, inf] of the RooGaussian 'model_4' exceeds the safe range of (0, inf). Advise to limit its range.\n" ] } ], "source": [ "RooGaussian model_4(\"model_4\", \"Gaussian with shifting mean\", x, fy_4, sigma);" ] }, { "cell_type": "markdown", "id": "2cec23a5", "metadata": {}, "source": [ "Plot all pdfs\n", "----------------------------" ] }, { "cell_type": "markdown", "id": "f804a7ba", "metadata": {}, "source": [ "Make two-dimensional plots in x vs y" ] }, { "cell_type": "code", "execution_count": 12, "id": "ac6ee0d6", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:30:33.767796Z", "iopub.status.busy": "2026-05-19T20:30:33.767687Z", "iopub.status.idle": "2026-05-19T20:30:33.975682Z", "shell.execute_reply": "2026-05-19T20:30:33.975268Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[#1] INFO:NumericIntegration -- RooRealIntegral::init(model_1_Int[x,y]) using numeric integrator RooIntegrator1D to calculate Int(y)\n", "[#1] INFO:NumericIntegration -- RooRealIntegral::init(model_2_Int[x,y]) using numeric integrator RooIntegrator1D to calculate Int(y)\n", "[#1] INFO:NumericIntegration -- RooRealIntegral::init(model_3_Int[x,y]) using numeric integrator RooIntegrator1D to calculate Int(y)\n", "[#1] INFO:NumericIntegration -- RooRealIntegral::init(model_4_Int[x,y]) using numeric integrator RooIntegrator1D to calculate Int(y)\n" ] } ], "source": [ "TH1 *hh_model_1 = model_1.createHistogram(\"hh_model_1\", x, Binning(50), YVar(y, Binning(50)));\n", "TH1 *hh_model_2 = model_2.createHistogram(\"hh_model_2\", x, Binning(50), YVar(y, Binning(50)));\n", "TH1 *hh_model_3 = model_3.createHistogram(\"hh_model_3\", x, Binning(50), YVar(y, Binning(50)));\n", "TH1 *hh_model_4 = model_4.createHistogram(\"hh_model_4\", x, Binning(50), YVar(y, Binning(50)));\n", "hh_model_1->SetLineColor(kBlue);\n", "hh_model_2->SetLineColor(kBlue);\n", "hh_model_3->SetLineColor(kBlue);\n", "hh_model_4->SetLineColor(kBlue);" ] }, { "cell_type": "markdown", "id": "64b4fce0", "metadata": {}, "source": [ "Make canvas and draw RooPlots" ] }, { "cell_type": "code", "execution_count": 13, "id": "11f73acd", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:30:33.977221Z", "iopub.status.busy": "2026-05-19T20:30:33.977114Z", "iopub.status.idle": "2026-05-19T20:30:34.182089Z", "shell.execute_reply": "2026-05-19T20:30:34.181565Z" } }, "outputs": [], "source": [ "TCanvas *c = new TCanvas(\"rf302_utilfuncs\", \"rf302_utilfuncs\", 800, 800);\n", "c->Divide(2, 2);\n", "c->cd(1);\n", "gPad->SetLeftMargin(0.20);\n", "hh_model_1->GetZaxis()->SetTitleOffset(2.5);\n", "hh_model_1->Draw(\"surf\");\n", "c->cd(2);\n", "gPad->SetLeftMargin(0.20);\n", "hh_model_2->GetZaxis()->SetTitleOffset(2.5);\n", "hh_model_2->Draw(\"surf\");\n", "c->cd(3);\n", "gPad->SetLeftMargin(0.20);\n", "hh_model_3->GetZaxis()->SetTitleOffset(2.5);\n", "hh_model_3->Draw(\"surf\");\n", "c->cd(4);\n", "gPad->SetLeftMargin(0.20);\n", "hh_model_4->GetZaxis()->SetTitleOffset(2.5);\n", "hh_model_4->Draw(\"surf\");" ] }, { "cell_type": "markdown", "id": "5902b95d", "metadata": {}, "source": [ "Draw all canvases " ] }, { "cell_type": "code", "execution_count": 14, "id": "14a79933", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:30:34.183729Z", "iopub.status.busy": "2026-05-19T20:30:34.183613Z", "iopub.status.idle": "2026-05-19T20:30:34.391103Z", "shell.execute_reply": "2026-05-19T20:30:34.390575Z" } }, "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 }