{ "cells": [ { "cell_type": "markdown", "id": "60a121d2", "metadata": {}, "source": [ "# rf313_paramranges\n", "Multidimensional models: working with parametrized ranges to define non-rectangular\n", "regions for fitting and integration\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:31 PM." ] }, { "cell_type": "code", "execution_count": 1, "id": "4958c528", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:31:15.540453Z", "iopub.status.busy": "2026-05-19T20:31:15.540314Z", "iopub.status.idle": "2026-05-19T20:31:15.557364Z", "shell.execute_reply": "2026-05-19T20:31:15.555631Z" } }, "outputs": [], "source": [ "%%cpp -d\n", "#include \"RooRealVar.h\"\n", "#include \"RooDataSet.h\"\n", "#include \"RooGaussian.h\"\n", "#include \"RooPolynomial.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": "bbc28a8a", "metadata": {}, "source": [ "Create 3D pdf\n", "-------------------------" ] }, { "cell_type": "markdown", "id": "d7b536a7", "metadata": {}, "source": [ "Define observable (x,y,z)" ] }, { "cell_type": "code", "execution_count": 2, "id": "e956b430", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:31:15.567183Z", "iopub.status.busy": "2026-05-19T20:31:15.567053Z", "iopub.status.idle": "2026-05-19T20:31:15.884685Z", "shell.execute_reply": "2026-05-19T20:31:15.884042Z" } }, "outputs": [], "source": [ "RooRealVar x(\"x\", \"x\", 0, 10);\n", "RooRealVar y(\"y\", \"y\", 0, 10);\n", "RooRealVar z(\"z\", \"z\", 0, 10);" ] }, { "cell_type": "markdown", "id": "93ce3d93", "metadata": {}, "source": [ "Define 3 dimensional pdf" ] }, { "cell_type": "code", "execution_count": 3, "id": "af68756b", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:31:15.886303Z", "iopub.status.busy": "2026-05-19T20:31:15.886144Z", "iopub.status.idle": "2026-05-19T20:31:16.097644Z", "shell.execute_reply": "2026-05-19T20:31:16.096495Z" } }, "outputs": [], "source": [ "RooRealVar z0(\"z0\", \"z0\", -0.1, 1);\n", "RooPolynomial px(\"px\", \"px\", x, RooConst(0.0));\n", "RooPolynomial py(\"py\", \"py\", y, RooConst(0.0));\n", "RooPolynomial pz(\"pz\", \"pz\", z, z0);\n", "RooProdPdf pxyz(\"pxyz\", \"pxyz\", RooArgSet(px, py, pz));" ] }, { "cell_type": "markdown", "id": "52135efe", "metadata": {}, "source": [ "Defined non-rectangular region R in (x,y,z)\n", "-------------------------------------------------------------------------------------" ] }, { "cell_type": "markdown", "id": "56f497cd", "metadata": {}, "source": [ "R = Z[0 - 0.1*Y^2] * Y[0.1*X - 0.9*X] * X[0 - 10]" ] }, { "cell_type": "markdown", "id": "b3347f51", "metadata": {}, "source": [ "Construct range parametrized in \"R\" in y [ 0.1*x, 0.9*x ]" ] }, { "cell_type": "code", "execution_count": 4, "id": "2114d8c9", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:31:16.099761Z", "iopub.status.busy": "2026-05-19T20:31:16.099564Z", "iopub.status.idle": "2026-05-19T20:31:16.310855Z", "shell.execute_reply": "2026-05-19T20:31:16.309727Z" } }, "outputs": [], "source": [ "RooFormulaVar ylo(\"ylo\", \"0.1*x\", x);\n", "RooFormulaVar yhi(\"yhi\", \"0.9*x\", x);\n", "y.setRange(\"R\", ylo, yhi);" ] }, { "cell_type": "markdown", "id": "7cd84fef", "metadata": {}, "source": [ "Construct parametrized ranged \"R\" in z [ 0, 0.1*y^2 ]" ] }, { "cell_type": "code", "execution_count": 5, "id": "9a3c2639", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:31:16.312425Z", "iopub.status.busy": "2026-05-19T20:31:16.312291Z", "iopub.status.idle": "2026-05-19T20:31:16.523364Z", "shell.execute_reply": "2026-05-19T20:31:16.522168Z" } }, "outputs": [], "source": [ "RooFormulaVar zlo(\"zlo\", \"0.0*y\", y);\n", "RooFormulaVar zhi(\"zhi\", \"0.1*y*y\", y);\n", "z.setRange(\"R\", zlo, zhi);" ] }, { "cell_type": "markdown", "id": "dd786e40", "metadata": {}, "source": [ "Calculate integral of normalized pdf in R\n", "----------------------------------------------------------------------------------" ] }, { "cell_type": "markdown", "id": "2dca04da", "metadata": {}, "source": [ "Create integral over normalized pdf model over x,y,z in \"R\" region" ] }, { "cell_type": "code", "execution_count": 6, "id": "d8a40f6f", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:31:16.525222Z", "iopub.status.busy": "2026-05-19T20:31:16.525064Z", "iopub.status.idle": "2026-05-19T20:31:16.732134Z", "shell.execute_reply": "2026-05-19T20:31:16.731230Z" } }, "outputs": [], "source": [ "std::unique_ptr intPdf{pxyz.createIntegral(RooArgSet(x, y, z), RooArgSet(x, y, z), \"R\")};" ] }, { "cell_type": "markdown", "id": "2a983429", "metadata": {}, "source": [ "Plot value of integral as function of pdf parameter z0" ] }, { "cell_type": "code", "execution_count": 7, "id": "bffa9d1f", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:31:16.733518Z", "iopub.status.busy": "2026-05-19T20:31:16.733404Z", "iopub.status.idle": "2026-05-19T20:31:16.942781Z", "shell.execute_reply": "2026-05-19T20:31:16.941980Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[#1] INFO:NumericIntegration -- RooRealIntegral::init(pxyz_Int[z|R]_Norm[x,y,z]_Int[y|R]_Int[x|R]) using numeric integrator RooIntegrator1D to calculate Int(x)\n", "[#1] INFO:NumericIntegration -- RooRealIntegral::init(pxyz_Int[z|R]_Norm[x,y,z]_Int[y|R]) using numeric integrator RooIntegrator1D to calculate Int(y)\n" ] } ], "source": [ "RooPlot *frame = z0.frame(Title(\"Integral of pxyz over x,y,z in region R\"));\n", "intPdf->plotOn(frame);\n", "\n", "new TCanvas(\"rf313_paramranges\", \"rf313_paramranges\", 600, 600);\n", "gPad->SetLeftMargin(0.15);\n", "frame->GetYaxis()->SetTitleOffset(1.6);\n", "frame->Draw();\n", "\n", "return;" ] }, { "cell_type": "markdown", "id": "7f7f4063", "metadata": {}, "source": [ "Draw all canvases " ] }, { "cell_type": "code", "execution_count": 8, "id": "11758236", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:31:16.955263Z", "iopub.status.busy": "2026-05-19T20:31:16.955127Z", "iopub.status.idle": "2026-05-19T20:31:17.189450Z", "shell.execute_reply": "2026-05-19T20:31:17.188105Z" } }, "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 }