{ "cells": [ { "cell_type": "markdown", "id": "bda075b8", "metadata": {}, "source": [ "# rf206_treevistools\n", "Addition and convolution: tools for visualization of RooAbsArg expression trees\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:29 PM." ] }, { "cell_type": "code", "execution_count": 1, "id": "a5b926e5", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:29:58.191029Z", "iopub.status.busy": "2026-05-19T20:29:58.190921Z", "iopub.status.idle": "2026-05-19T20:29:58.203901Z", "shell.execute_reply": "2026-05-19T20:29:58.203398Z" } }, "outputs": [], "source": [ "%%cpp -d\n", "#include \"RooRealVar.h\"\n", "#include \"RooDataSet.h\"\n", "#include \"RooGaussian.h\"\n", "#include \"RooChebychev.h\"\n", "#include \"RooAddPdf.h\"\n", "#include \"RooExponential.h\"\n", "#include \"TCanvas.h\"\n", "#include \"TAxis.h\"\n", "#include \"RooPlot.h\"\n", "using namespace RooFit;" ] }, { "cell_type": "markdown", "id": "64de7caf", "metadata": {}, "source": [ "Setup composite pdf\n", "--------------------------------------" ] }, { "cell_type": "markdown", "id": "4c6bcc46", "metadata": {}, "source": [ "Declare observable x" ] }, { "cell_type": "code", "execution_count": 2, "id": "e040120e", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:29:58.205347Z", "iopub.status.busy": "2026-05-19T20:29:58.205237Z", "iopub.status.idle": "2026-05-19T20:29:58.415846Z", "shell.execute_reply": "2026-05-19T20:29:58.415147Z" } }, "outputs": [], "source": [ "RooRealVar x(\"x\", \"x\", 0, 10);" ] }, { "cell_type": "markdown", "id": "ad724311", "metadata": {}, "source": [ "Create two Gaussian PDFs g1(x,mean1,sigma) anf g2(x,mean2,sigma) and their parameters" ] }, { "cell_type": "code", "execution_count": 3, "id": "4f48d64f", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:29:58.417544Z", "iopub.status.busy": "2026-05-19T20:29:58.417432Z", "iopub.status.idle": "2026-05-19T20:29:58.625907Z", "shell.execute_reply": "2026-05-19T20:29:58.625291Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[#0] WARNING:InputArguments -- The parameter 'sigma1' with range [-inf, inf] of the RooGaussian 'sig1' exceeds the safe range of (0, inf). Advise to limit its range.\n", "[#0] WARNING:InputArguments -- The parameter 'sigma2' with range [-inf, inf] of the RooGaussian 'sig2' exceeds the safe range of (0, inf). Advise to limit its range.\n" ] } ], "source": [ "RooRealVar mean(\"mean\", \"mean of gaussians\", 5);\n", "RooRealVar sigma1(\"sigma1\", \"width of gaussians\", 0.5);\n", "RooRealVar sigma2(\"sigma2\", \"width of gaussians\", 1);\n", "RooGaussian sig1(\"sig1\", \"Signal component 1\", x, mean, sigma1);\n", "RooGaussian sig2(\"sig2\", \"Signal component 2\", x, mean, sigma2);" ] }, { "cell_type": "markdown", "id": "69b7a1e8", "metadata": {}, "source": [ "Sum the signal components into a composite signal pdf" ] }, { "cell_type": "code", "execution_count": 4, "id": "fb5f0738", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:29:58.627418Z", "iopub.status.busy": "2026-05-19T20:29:58.627307Z", "iopub.status.idle": "2026-05-19T20:29:58.834954Z", "shell.execute_reply": "2026-05-19T20:29:58.834324Z" } }, "outputs": [], "source": [ "RooRealVar sig1frac(\"sig1frac\", \"fraction of component 1 in signal\", 0.8, 0., 1.);\n", "RooAddPdf sig(\"sig\", \"Signal\", RooArgList(sig1, sig2), sig1frac);" ] }, { "cell_type": "markdown", "id": "455b8ee4", "metadata": {}, "source": [ "Build Chebychev polynomial pdf" ] }, { "cell_type": "code", "execution_count": 5, "id": "23d4c8c9", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:29:58.836901Z", "iopub.status.busy": "2026-05-19T20:29:58.836786Z", "iopub.status.idle": "2026-05-19T20:29:59.044376Z", "shell.execute_reply": "2026-05-19T20:29:59.043712Z" } }, "outputs": [], "source": [ "RooRealVar a0(\"a0\", \"a0\", 0.5, 0., 1.);\n", "RooRealVar a1(\"a1\", \"a1\", 0.2, 0., 1.);\n", "RooChebychev bkg1(\"bkg1\", \"Background 1\", x, RooArgSet(a0, a1));" ] }, { "cell_type": "markdown", "id": "c3283adb", "metadata": {}, "source": [ "Build expontential pdf" ] }, { "cell_type": "code", "execution_count": 6, "id": "29cce4ab", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:29:59.046015Z", "iopub.status.busy": "2026-05-19T20:29:59.045898Z", "iopub.status.idle": "2026-05-19T20:29:59.253401Z", "shell.execute_reply": "2026-05-19T20:29:59.252791Z" } }, "outputs": [], "source": [ "RooRealVar alpha(\"alpha\", \"alpha\", -1);\n", "RooExponential bkg2(\"bkg2\", \"Background 2\", x, alpha);" ] }, { "cell_type": "markdown", "id": "8c71b5b2", "metadata": {}, "source": [ "Sum the background components into a composite background pdf" ] }, { "cell_type": "code", "execution_count": 7, "id": "cb62167f", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:29:59.255157Z", "iopub.status.busy": "2026-05-19T20:29:59.255041Z", "iopub.status.idle": "2026-05-19T20:29:59.462557Z", "shell.execute_reply": "2026-05-19T20:29:59.461967Z" } }, "outputs": [], "source": [ "RooRealVar bkg1frac(\"bkg1frac\", \"fraction of component 1 in background\", 0.2, 0., 1.);\n", "RooAddPdf bkg(\"bkg\", \"Signal\", RooArgList(bkg1, bkg2), bkg1frac);" ] }, { "cell_type": "markdown", "id": "815d852d", "metadata": {}, "source": [ "Sum the composite signal and background" ] }, { "cell_type": "code", "execution_count": 8, "id": "ccefd8b6", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:29:59.464695Z", "iopub.status.busy": "2026-05-19T20:29:59.464561Z", "iopub.status.idle": "2026-05-19T20:29:59.672467Z", "shell.execute_reply": "2026-05-19T20:29:59.671773Z" } }, "outputs": [], "source": [ "RooRealVar bkgfrac(\"bkgfrac\", \"fraction of background\", 0.5, 0., 1.);\n", "RooAddPdf model(\"model\", \"g1+g2+a\", RooArgList(bkg, sig), bkgfrac);" ] }, { "cell_type": "markdown", "id": "b43c2d6a", "metadata": {}, "source": [ "Print composite tree in ASCII\n", "-----------------------------------------------------------" ] }, { "cell_type": "markdown", "id": "4f2a4a92", "metadata": {}, "source": [ "Print tree to stdout" ] }, { "cell_type": "code", "execution_count": 9, "id": "122c40ac", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:29:59.674235Z", "iopub.status.busy": "2026-05-19T20:29:59.674120Z", "iopub.status.idle": "2026-05-19T20:29:59.880264Z", "shell.execute_reply": "2026-05-19T20:29:59.879659Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0x7f0cc27e03e8 RooAddPdf::model = 0.582695/1 [Auto,Clean] \n", " 0x7f0cc27e33e8/V- RooAddPdf::bkg = 0.16539/1 [Auto,Clean] \n", " 0x7f0cc27e97d0/V- RooChebychev::bkg1 = 0.8 [Auto,Dirty] \n", " 0x7f0cc28c1000/V- RooRealVar::x = 5\n", " 0x7f0cc27e9000/V- RooRealVar::a0 = 0.5\n", " 0x7f0cc27e93e8/V- RooRealVar::a1 = 0.2\n", " 0x7f0cc27e3000/V- RooRealVar::bkg1frac = 0.2\n", " 0x7f0cc27e63e8/V- RooExponential::bkg2 = 0.00673795 [Auto,Dirty] \n", " 0x7f0cc28c1000/V- RooRealVar::x = 5\n", " 0x7f0cc27e6000/V- RooRealVar::alpha = -1\n", " 0x7f0cc27e0000/V- RooRealVar::bkgfrac = 0.5\n", " 0x7f0cc27f13e8/V- RooAddPdf::sig = 1/1 [Auto,Clean] \n", " 0x7f0cc27f4bb8/V- RooGaussian::sig1 = 1 [Auto,Dirty] \n", " 0x7f0cc28c1000/V- RooRealVar::x = 5\n", " 0x7f0cc27f4000/V- RooRealVar::mean = 5\n", " 0x7f0cc27f43e8/V- RooRealVar::sigma1 = 0.5\n", " 0x7f0cc27f1000/V- RooRealVar::sig1frac = 0.8\n", " 0x7f0cc27f5110/V- RooGaussian::sig2 = 1 [Auto,Dirty] \n", " 0x7f0cc28c1000/V- RooRealVar::x = 5\n", " 0x7f0cc27f4000/V- RooRealVar::mean = 5\n", " 0x7f0cc27f47d0/V- RooRealVar::sigma2 = 1\n" ] } ], "source": [ "model.Print(\"t\");" ] }, { "cell_type": "markdown", "id": "1988122f", "metadata": {}, "source": [ "Print tree to file" ] }, { "cell_type": "code", "execution_count": 10, "id": "8a88831e", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:29:59.881726Z", "iopub.status.busy": "2026-05-19T20:29:59.881591Z", "iopub.status.idle": "2026-05-19T20:30:00.086931Z", "shell.execute_reply": "2026-05-19T20:30:00.086356Z" } }, "outputs": [], "source": [ "model.printCompactTree(\"\", \"rf206_asciitree.txt\");" ] }, { "cell_type": "markdown", "id": "32640d35", "metadata": {}, "source": [ "Draw composite tree graphically\n", "-------------------------------------------------------------" ] }, { "cell_type": "markdown", "id": "1fc8c464", "metadata": {}, "source": [ "Print GraphViz DOT file with representation of tree" ] }, { "cell_type": "code", "execution_count": 11, "id": "a28dff7b", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:30:00.088885Z", "iopub.status.busy": "2026-05-19T20:30:00.088771Z", "iopub.status.idle": "2026-05-19T20:30:00.294151Z", "shell.execute_reply": "2026-05-19T20:30:00.293563Z" } }, "outputs": [], "source": [ "model.graphVizTree(\"rf206_model.dot\");" ] } ], "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 }