{ "cells": [ { "cell_type": "markdown", "id": "7a4ddddc", "metadata": {}, "source": [ "# rf803_mcstudy_addons2\n", "Validation and MC studies: RooMCStudy - Using the randomizer and profile likelihood add-on models\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:35 PM." ] }, { "cell_type": "code", "execution_count": 1, "id": "d47c8958", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:35:24.288753Z", "iopub.status.busy": "2026-05-19T20:35:24.288620Z", "iopub.status.idle": "2026-05-19T20:35:24.311740Z", "shell.execute_reply": "2026-05-19T20:35:24.311087Z" } }, "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 \"RooMCStudy.h\"\n", "#include \"RooRandomizeParamMCSModule.h\"\n", "#include \"RooDLLSignificanceMCSModule.h\"\n", "#include \"RooPlot.h\"\n", "#include \"TCanvas.h\"\n", "#include \"TAxis.h\"\n", "#include \"TH1.h\"\n", "#include \"TDirectory.h\"\n", "\n", "using namespace RooFit;" ] }, { "cell_type": "markdown", "id": "601d09cd", "metadata": {}, "source": [ "Create model\n", "-----------------------" ] }, { "cell_type": "markdown", "id": "13fe84f6", "metadata": {}, "source": [ "Simulation of signal and background of top quark decaying into\n", "3 jets with background" ] }, { "cell_type": "markdown", "id": "4b6d16be", "metadata": {}, "source": [ "Observable" ] }, { "cell_type": "code", "execution_count": 2, "id": "4ce56eb7", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:35:24.313532Z", "iopub.status.busy": "2026-05-19T20:35:24.313366Z", "iopub.status.idle": "2026-05-19T20:35:24.637005Z", "shell.execute_reply": "2026-05-19T20:35:24.636346Z" } }, "outputs": [], "source": [ "RooRealVar mjjj(\"mjjj\", \"m(3jet) (GeV)\", 100, 85., 350.);" ] }, { "cell_type": "markdown", "id": "4db9b48e", "metadata": {}, "source": [ "Signal component (Gaussian)" ] }, { "cell_type": "code", "execution_count": 3, "id": "72ef883d", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:35:24.638824Z", "iopub.status.busy": "2026-05-19T20:35:24.638707Z", "iopub.status.idle": "2026-05-19T20:35:24.870993Z", "shell.execute_reply": "2026-05-19T20:35:24.868247Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[#0] WARNING:InputArguments -- The parameter 'wtop' with range [-inf, inf] of the RooGaussian 'sig' exceeds the safe range of (0, inf). Advise to limit its range.\n" ] } ], "source": [ "RooRealVar mtop(\"mtop\", \"m(top)\", 162);\n", "RooRealVar wtop(\"wtop\", \"m(top) resolution\", 15.2);\n", "RooGaussian sig(\"sig\", \"top signal\", mjjj, mtop, wtop);" ] }, { "cell_type": "markdown", "id": "c8ecdec9", "metadata": {}, "source": [ "Background component (Chebychev)" ] }, { "cell_type": "code", "execution_count": 4, "id": "f704284b", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:35:24.872436Z", "iopub.status.busy": "2026-05-19T20:35:24.872313Z", "iopub.status.idle": "2026-05-19T20:35:25.088309Z", "shell.execute_reply": "2026-05-19T20:35:25.087498Z" } }, "outputs": [], "source": [ "RooRealVar c0(\"c0\", \"Chebychev coefficient 0\", -0.846, -1., 1.);\n", "RooRealVar c1(\"c1\", \"Chebychev coefficient 1\", 0.112, -1., 1.);\n", "RooRealVar c2(\"c2\", \"Chebychev coefficient 2\", 0.076, -1., 1.);\n", "RooChebychev bkg(\"bkg\", \"combinatorial background\", mjjj, RooArgList(c0, c1, c2));" ] }, { "cell_type": "markdown", "id": "a682df3d", "metadata": {}, "source": [ "Composite model" ] }, { "cell_type": "code", "execution_count": 5, "id": "851dc9df", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:35:25.096693Z", "iopub.status.busy": "2026-05-19T20:35:25.096494Z", "iopub.status.idle": "2026-05-19T20:35:25.313003Z", "shell.execute_reply": "2026-05-19T20:35:25.312499Z" } }, "outputs": [], "source": [ "RooRealVar nsig(\"nsig\", \"number of signal events\", 53, 0, 1e3);\n", "RooRealVar nbkg(\"nbkg\", \"number of background events\", 103, 0, 5e3);\n", "RooAddPdf model(\"model\", \"model\", RooArgList(sig, bkg), RooArgList(nsig, nbkg));" ] }, { "cell_type": "markdown", "id": "aaff87be", "metadata": {}, "source": [ "Create manager\n", "---------------------------" ] }, { "cell_type": "markdown", "id": "6839e814", "metadata": {}, "source": [ "Configure manager to perform binned extended likelihood fits (Binned(),Extended()) on data generated\n", "with a Poisson fluctuation on Nobs (Extended())" ] }, { "cell_type": "code", "execution_count": 6, "id": "389de8c8", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:35:25.314541Z", "iopub.status.busy": "2026-05-19T20:35:25.314430Z", "iopub.status.idle": "2026-05-19T20:35:25.523163Z", "shell.execute_reply": "2026-05-19T20:35:25.522640Z" } }, "outputs": [], "source": [ "RooMCStudy *mcs = new RooMCStudy(model, mjjj, Binned(), Silence(), Extended(true),\n", " FitOptions(Extended(true), PrintEvalErrors(-1)));" ] }, { "cell_type": "markdown", "id": "efdcb5b1", "metadata": {}, "source": [ "Customize manager\n", "---------------------------------" ] }, { "cell_type": "markdown", "id": "29b695b3", "metadata": {}, "source": [ "Add module that randomizes the summed value of nsig+nbkg\n", "sampling from a uniform distribution between 0 and 1000\n", "\n", "In general one can randomize a single parameter, or a\n", "sum of N parameters, using either a uniform or a Gaussian\n", "distribution. Multiple randomization can be executed\n", "by a single randomizer module" ] }, { "cell_type": "code", "execution_count": 7, "id": "b66e7763", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:35:25.524759Z", "iopub.status.busy": "2026-05-19T20:35:25.524629Z", "iopub.status.idle": "2026-05-19T20:35:25.733417Z", "shell.execute_reply": "2026-05-19T20:35:25.732946Z" } }, "outputs": [], "source": [ "RooRandomizeParamMCSModule randModule;\n", "randModule.sampleSumUniform(RooArgSet(nsig, nbkg), 50, 500);\n", "mcs->addModule(randModule);" ] }, { "cell_type": "markdown", "id": "78f93114", "metadata": {}, "source": [ "Add profile likelihood calculation of significance. Redo each\n", "fit while keeping parameter nsig fixed to zero. For each toy,\n", "the difference in -log(L) of both fits is stored, as well\n", "a simple significance interpretation of the delta(-logL)\n", "using Dnll = 0.5 sigma^2" ] }, { "cell_type": "code", "execution_count": 8, "id": "c93949d2", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:35:25.735254Z", "iopub.status.busy": "2026-05-19T20:35:25.735124Z", "iopub.status.idle": "2026-05-19T20:35:25.943875Z", "shell.execute_reply": "2026-05-19T20:35:25.943378Z" } }, "outputs": [], "source": [ "RooDLLSignificanceMCSModule sigModule(nsig, 0);\n", "mcs->addModule(sigModule);" ] }, { "cell_type": "markdown", "id": "8523e64f", "metadata": {}, "source": [ "Run manager, make plots\n", "---------------------------------------------" ] }, { "cell_type": "markdown", "id": "42b11438", "metadata": {}, "source": [ "Run 1000 experiments. This configuration will generate a fair number\n", "of (harmless) MINUIT warnings due to the instability of the Chebychev polynomial fit\n", "at low statistics." ] }, { "cell_type": "code", "execution_count": 9, "id": "d9b182df", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:35:25.946250Z", "iopub.status.busy": "2026-05-19T20:35:25.946135Z", "iopub.status.idle": "2026-05-19T20:35:26.765688Z", "shell.execute_reply": "2026-05-19T20:35:26.765177Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 495\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 490\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 485\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 480\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 475\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 470\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 465\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 460\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 455\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 450\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 445\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 440\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 435\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 430\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 425\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 420\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 415\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 410\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 405\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 400\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 395\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 390\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 385\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 380\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 375\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 370\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 365\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 360\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 355\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 350\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 345\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 340\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 335\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 330\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 325\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 320\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 315\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 310\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 305\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 300\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 295\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 290\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 285\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 280\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 275\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 270\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 265\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 260\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 255\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 250\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 245\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 240\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 235\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 230\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 225\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 220\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 215\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 210\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 205\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 200\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 195\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 190\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 185\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 180\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 175\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 170\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 165\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 160\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 155\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 150\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 145\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 140\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 135\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 130\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 125\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 120\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 115\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 110\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 105\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 100\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 95\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 90\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 85\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 80\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 75\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 70\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 65\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 60\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 55\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 50\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 45\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 40\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 35\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 30\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 25\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 20\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 15\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 10\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 5\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 0\n", "[#0] WARNING:Generation -- Fit parameter 'mtop' does not have an error. A pull distribution cannot be generated. This might be caused by the parameter being constant or because the fits were not run.\n", "[#0] WARNING:Generation -- Fit parameter 'wtop' does not have an error. A pull distribution cannot be generated. This might be caused by the parameter being constant or because the fits were not run.\n" ] } ], "source": [ "mcs->generateAndFit(500);" ] }, { "cell_type": "markdown", "id": "958a67f6", "metadata": {}, "source": [ "Make some plots" ] }, { "cell_type": "code", "execution_count": 10, "id": "465bd9ce", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:35:26.766913Z", "iopub.status.busy": "2026-05-19T20:35:26.766799Z", "iopub.status.idle": "2026-05-19T20:35:26.978171Z", "shell.execute_reply": "2026-05-19T20:35:26.977301Z" } }, "outputs": [], "source": [ "TH1 *dll_vs_ngen = mcs->fitParDataSet().createHistogram(\"ngen,dll_nullhypo_nsig\", AutoBinning(40), AutoBinning(40));\n", "TH1 *z_vs_ngen = mcs->fitParDataSet().createHistogram(\"ngen,significance_nullhypo_nsig\", AutoBinning(40), AutoBinning(40));\n", "TH1 *errnsig_vs_ngen = mcs->fitParDataSet().createHistogram(\"ngen,nsigerr\", AutoBinning(40), AutoBinning(40));\n", "TH1 *errnsig_vs_nsig = mcs->fitParDataSet().createHistogram(\"nsig,nsigerr\", AutoBinning(40), AutoBinning(40));" ] }, { "cell_type": "markdown", "id": "ba3a373d", "metadata": {}, "source": [ "Draw plots on canvas" ] }, { "cell_type": "code", "execution_count": 11, "id": "e29ceded", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:35:26.979459Z", "iopub.status.busy": "2026-05-19T20:35:26.979336Z", "iopub.status.idle": "2026-05-19T20:35:27.185093Z", "shell.execute_reply": "2026-05-19T20:35:27.184489Z" } }, "outputs": [], "source": [ "TCanvas *c = new TCanvas(\"rf803_mcstudy_addons2\", \"rf802_mcstudy_addons2\", 800, 800);\n", "c->Divide(2, 2);\n", "c->cd(1);\n", "gPad->SetLeftMargin(0.15);\n", "dll_vs_ngen->GetYaxis()->SetTitleOffset(1.6);\n", "dll_vs_ngen->Draw(\"box\");\n", "c->cd(2);\n", "gPad->SetLeftMargin(0.15);\n", "z_vs_ngen->GetYaxis()->SetTitleOffset(1.6);\n", "z_vs_ngen->Draw(\"box\");\n", "c->cd(3);\n", "gPad->SetLeftMargin(0.15);\n", "errnsig_vs_ngen->GetYaxis()->SetTitleOffset(1.6);\n", "errnsig_vs_ngen->Draw(\"box\");\n", "c->cd(4);\n", "gPad->SetLeftMargin(0.15);\n", "errnsig_vs_nsig->GetYaxis()->SetTitleOffset(1.6);\n", "errnsig_vs_nsig->Draw(\"box\");" ] }, { "cell_type": "markdown", "id": "b96c5d8b", "metadata": {}, "source": [ "Make RooMCStudy object available on command line after\n", "macro finishes" ] }, { "cell_type": "code", "execution_count": 12, "id": "2d80eba0", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:35:27.191330Z", "iopub.status.busy": "2026-05-19T20:35:27.191214Z", "iopub.status.idle": "2026-05-19T20:35:27.401043Z", "shell.execute_reply": "2026-05-19T20:35:27.400685Z" } }, "outputs": [], "source": [ "gDirectory->Add(mcs);" ] }, { "cell_type": "markdown", "id": "e42864ab", "metadata": {}, "source": [ "Draw all canvases " ] }, { "cell_type": "code", "execution_count": 13, "id": "d705d9a0", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:35:27.409505Z", "iopub.status.busy": "2026-05-19T20:35:27.409376Z", "iopub.status.idle": "2026-05-19T20:35:27.639567Z", "shell.execute_reply": "2026-05-19T20:35:27.639151Z" } }, "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 }