{ "cells": [ { "cell_type": "markdown", "id": "ed9ea621", "metadata": {}, "source": [ "# rf506_msgservice\n", "Organisation and simultaneous fits: tuning and customizing the RooFit message logging facility\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 Monday, December 15, 2025 at 04:23 AM." ] }, { "cell_type": "code", "execution_count": 1, "id": "3686bc12", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2025-12-15T03:23:25.357930Z", "iopub.status.busy": "2025-12-15T03:23:25.357764Z", "iopub.status.idle": "2025-12-15T03:23:25.375750Z", "shell.execute_reply": "2025-12-15T03:23:25.375071Z" } }, "outputs": [], "source": [ "%%cpp -d\n", "#include \"RooRealVar.h\"\n", "#include \"RooDataSet.h\"\n", "#include \"RooGaussian.h\"\n", "#include \"RooPolynomial.h\"\n", "#include \"RooAddPdf.h\"\n", "#include \"TCanvas.h\"\n", "#include \"TAxis.h\"\n", "#include \"RooPlot.h\"\n", "#include \"RooMsgService.h\"\n", "\n", "using namespace RooFit;" ] }, { "cell_type": "markdown", "id": "6d20b254", "metadata": {}, "source": [ "Create pdf\n", "--------------------" ] }, { "cell_type": "markdown", "id": "15e7d19c", "metadata": {}, "source": [ "Construct gauss(x,m,s)" ] }, { "cell_type": "code", "execution_count": 2, "id": "6230a138", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2025-12-15T03:23:25.377794Z", "iopub.status.busy": "2025-12-15T03:23:25.377625Z", "iopub.status.idle": "2025-12-15T03:23:25.757019Z", "shell.execute_reply": "2025-12-15T03:23:25.756645Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[#0] WARNING:InputArguments -- The parameter 's' with range [-10, 10] of the RooGaussian 'g' exceeds the safe range of (0, inf). Advise to limit its range.\n" ] } ], "source": [ "RooRealVar x(\"x\", \"x\", -10, 10);\n", "RooRealVar m(\"m\", \"m\", 0, -10, 10);\n", "RooRealVar s(\"s\", \"s\", 1, -10, 10);\n", "RooGaussian gauss(\"g\", \"g\", x, m, s);" ] }, { "cell_type": "markdown", "id": "ba9a017c", "metadata": {}, "source": [ "Construct poly(x,p0)" ] }, { "cell_type": "code", "execution_count": 3, "id": "a5e407c7", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2025-12-15T03:23:25.766150Z", "iopub.status.busy": "2025-12-15T03:23:25.765963Z", "iopub.status.idle": "2025-12-15T03:23:25.975551Z", "shell.execute_reply": "2025-12-15T03:23:25.975087Z" } }, "outputs": [], "source": [ "RooRealVar p0(\"p0\", \"p0\", 0.01, 0., 1.);\n", "RooPolynomial poly(\"p\", \"p\", x, p0);" ] }, { "cell_type": "markdown", "id": "03780883", "metadata": {}, "source": [ "Construct model = f*gauss(x) + (1-f)*poly(x)" ] }, { "cell_type": "code", "execution_count": 4, "id": "51830d3e", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2025-12-15T03:23:25.977945Z", "iopub.status.busy": "2025-12-15T03:23:25.977787Z", "iopub.status.idle": "2025-12-15T03:23:26.188150Z", "shell.execute_reply": "2025-12-15T03:23:26.187577Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "input_line_55:5:1: warning: 'data' shadows a declaration with the same name in the 'std' namespace; use '::data' to reference this declaration\n", "std::unique_ptr data{model.generate(x, 10)};\n", "^\n" ] } ], "source": [ "RooRealVar f(\"f\", \"f\", 0.5, 0., 1.);\n", "RooAddPdf model(\"model\", \"model\", RooArgSet(gauss, poly), f);\n", "\n", "std::unique_ptr data{model.generate(x, 10)};" ] }, { "cell_type": "markdown", "id": "e6711b8d", "metadata": {}, "source": [ "Print configuration of message service\n", "---------------------------------------------------------------------------" ] }, { "cell_type": "markdown", "id": "fa3a3585", "metadata": {}, "source": [ "Print streams configuration" ] }, { "cell_type": "code", "execution_count": 5, "id": "bb8e5c11", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2025-12-15T03:23:26.189977Z", "iopub.status.busy": "2025-12-15T03:23:26.189801Z", "iopub.status.idle": "2025-12-15T03:23:26.401063Z", "shell.execute_reply": "2025-12-15T03:23:26.400503Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Active Message streams\n", "[0] MinLevel = PROGRESS Topic = Generation Minimization Plotting Fitting Integration LinkStateMgmt Eval Caching Optimization ObjectHandling InputArguments Tracing Contents DataHandling NumericIntegration FastEvaluations \n", "[1] MinLevel = INFO Topic = Minimization Plotting Fitting Eval Caching ObjectHandling InputArguments DataHandling NumericIntegration \n", "[2] MinLevel = INFO Topic = HistFactory \n", "\n" ] } ], "source": [ "RooMsgService::instance().Print();\n", "cout << endl;" ] }, { "cell_type": "markdown", "id": "defb8442", "metadata": {}, "source": [ "Adding Integration topic to existing INFO stream\n", "-----------------------------------------------------------------------------------------------" ] }, { "cell_type": "markdown", "id": "8bafbcb4", "metadata": {}, "source": [ "Print streams configuration" ] }, { "cell_type": "code", "execution_count": 6, "id": "ccc75573", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2025-12-15T03:23:26.402948Z", "iopub.status.busy": "2025-12-15T03:23:26.402755Z", "iopub.status.idle": "2025-12-15T03:23:26.618030Z", "shell.execute_reply": "2025-12-15T03:23:26.617643Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Active Message streams\n", "[0] MinLevel = PROGRESS Topic = Generation Minimization Plotting Fitting Integration LinkStateMgmt Eval Caching Optimization ObjectHandling InputArguments Tracing Contents DataHandling NumericIntegration FastEvaluations \n", "[1] MinLevel = INFO Topic = Minimization Plotting Fitting Eval Caching ObjectHandling InputArguments DataHandling NumericIntegration \n", "[2] MinLevel = INFO Topic = HistFactory \n", "\n" ] } ], "source": [ "RooMsgService::instance().Print();\n", "cout << endl;" ] }, { "cell_type": "markdown", "id": "dda144b5", "metadata": {}, "source": [ "Add Integration topic to existing INFO stream" ] }, { "cell_type": "code", "execution_count": 7, "id": "09c7b0ba", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2025-12-15T03:23:26.624758Z", "iopub.status.busy": "2025-12-15T03:23:26.624577Z", "iopub.status.idle": "2025-12-15T03:23:26.833680Z", "shell.execute_reply": "2025-12-15T03:23:26.833186Z" } }, "outputs": [], "source": [ "RooMsgService::instance().getStream(1).addTopic(Integration);" ] }, { "cell_type": "markdown", "id": "91bfca9e", "metadata": {}, "source": [ "Construct integral over gauss to demonstrate new message stream" ] }, { "cell_type": "code", "execution_count": 8, "id": "0ba9dda7", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2025-12-15T03:23:26.853348Z", "iopub.status.busy": "2025-12-15T03:23:26.853135Z", "iopub.status.idle": "2025-12-15T03:23:27.063876Z", "shell.execute_reply": "2025-12-15T03:23:27.063147Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[#1] INFO:Integration -- RooRealIntegral::ctor(g_Int[x]) Constructing integral of function g over observables(x) with normalization () with range identifier \n", "[#1] INFO:Integration -- g: Observable x is suitable for analytical integration (if supported by p.d.f)\n", "[#1] INFO:Integration -- g: Function integrated observables (x) internally with code 1\n", "[#1] INFO:Integration -- g: Observables (x) are analytically integrated with code 1\n", "RooRealIntegral::g_Int[x][ Int gd[Ana](x) ] = 2.50663\n" ] } ], "source": [ "std::unique_ptr igauss{gauss.createIntegral(x)};\n", "igauss->Print();" ] }, { "cell_type": "markdown", "id": "07d891c8", "metadata": {}, "source": [ "Print streams configuration in verbose, which also shows inactive streams" ] }, { "cell_type": "code", "execution_count": 9, "id": "9a376cf4", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2025-12-15T03:23:27.082020Z", "iopub.status.busy": "2025-12-15T03:23:27.081804Z", "iopub.status.idle": "2025-12-15T03:23:27.300388Z", "shell.execute_reply": "2025-12-15T03:23:27.299563Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "Active Message streams\n", "[0] MinLevel = PROGRESS Topic = Generation Minimization Plotting Fitting Integration LinkStateMgmt Eval Caching Optimization ObjectHandling InputArguments Tracing Contents DataHandling NumericIntegration FastEvaluations \n", "[1] MinLevel = INFO Topic = Minimization Plotting Fitting Integration Eval Caching ObjectHandling InputArguments DataHandling NumericIntegration \n", "[2] MinLevel = INFO Topic = HistFactory \n", "\n" ] } ], "source": [ "cout << endl;\n", "RooMsgService::instance().Print();\n", "cout << endl;" ] }, { "cell_type": "markdown", "id": "ce9f1357", "metadata": {}, "source": [ "Remove stream" ] }, { "cell_type": "code", "execution_count": 10, "id": "4994de6e", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2025-12-15T03:23:27.303628Z", "iopub.status.busy": "2025-12-15T03:23:27.303424Z", "iopub.status.idle": "2025-12-15T03:23:27.514072Z", "shell.execute_reply": "2025-12-15T03:23:27.513651Z" } }, "outputs": [], "source": [ "RooMsgService::instance().getStream(1).removeTopic(Integration);" ] }, { "cell_type": "markdown", "id": "3a4cb7bc", "metadata": {}, "source": [ "Examples of pdf value tracing stream\n", "-----------------------------------------------------------------------" ] }, { "cell_type": "markdown", "id": "541c2499", "metadata": {}, "source": [ "Show DEBUG level message on function tracing, trace RooGaussian only" ] }, { "cell_type": "code", "execution_count": 11, "id": "aa036bd2", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2025-12-15T03:23:27.519429Z", "iopub.status.busy": "2025-12-15T03:23:27.519269Z", "iopub.status.idle": "2025-12-15T03:23:27.725074Z", "shell.execute_reply": "2025-12-15T03:23:27.724655Z" } }, "outputs": [], "source": [ "RooMsgService::instance().addStream(DEBUG, Topic(Tracing), ClassName(\"RooGaussian\"));" ] }, { "cell_type": "markdown", "id": "a33770cf", "metadata": {}, "source": [ "Perform a fit to generate some tracing messages" ] }, { "cell_type": "code", "execution_count": 12, "id": "7e4053f2", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2025-12-15T03:23:27.741325Z", "iopub.status.busy": "2025-12-15T03:23:27.741152Z", "iopub.status.idle": "2025-12-15T03:23:27.952137Z", "shell.execute_reply": "2025-12-15T03:23:27.951759Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "input_line_63:2:15: error: reference to 'data' is ambiguous\n", " model.fitTo(*data, Verbose(true));\n", " ^\n", "input_line_55:5:29: note: candidate found by name lookup is 'data'\n", "std::unique_ptr data{model.generate(x, 10)};\n", " ^\n", "/usr/lib/gcc/x86_64-redhat-linux/11/../../../../include/c++/11/bits/range_access.h:319: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/11/../../../../include/c++/11/bits/range_access.h:290: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/11/../../../../include/c++/11/bits/range_access.h:300: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/11/../../../../include/c++/11/bits/range_access.h:310:5: note: candidate found by name lookup is 'std::data'\n", " data(_Tp (&__array)[_Nm]) noexcept\n", " ^\n" ] } ], "source": [ "model.fitTo(*data, Verbose(true));" ] }, { "cell_type": "markdown", "id": "11fba7d4", "metadata": {}, "source": [ "Reset message service to default stream configuration" ] }, { "cell_type": "code", "execution_count": 13, "id": "36c148ae", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2025-12-15T03:23:27.954021Z", "iopub.status.busy": "2025-12-15T03:23:27.953878Z", "iopub.status.idle": "2025-12-15T03:23:28.169938Z", "shell.execute_reply": "2025-12-15T03:23:28.169479Z" } }, "outputs": [], "source": [ "RooMsgService::instance().reset();" ] }, { "cell_type": "markdown", "id": "4d21db0a", "metadata": {}, "source": [ "Show DEBUG level message on function tracing on all objects, redirect output to file" ] }, { "cell_type": "code", "execution_count": 14, "id": "94691ab8", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2025-12-15T03:23:28.173722Z", "iopub.status.busy": "2025-12-15T03:23:28.173518Z", "iopub.status.idle": "2025-12-15T03:23:28.391133Z", "shell.execute_reply": "2025-12-15T03:23:28.387534Z" } }, "outputs": [], "source": [ "RooMsgService::instance().addStream(DEBUG, Topic(Tracing), OutputFile(\"rf506_debug.log\"));" ] }, { "cell_type": "markdown", "id": "6aed618b", "metadata": {}, "source": [ "Perform a fit to generate some tracing messages" ] }, { "cell_type": "code", "execution_count": 15, "id": "5c02c993", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2025-12-15T03:23:28.393910Z", "iopub.status.busy": "2025-12-15T03:23:28.393711Z", "iopub.status.idle": "2025-12-15T03:23:28.605560Z", "shell.execute_reply": "2025-12-15T03:23:28.604964Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "input_line_66:2:15: error: reference to 'data' is ambiguous\n", " model.fitTo(*data, Verbose(true));\n", " ^\n", "input_line_55:5:29: note: candidate found by name lookup is 'data'\n", "std::unique_ptr data{model.generate(x, 10)};\n", " ^\n", "/usr/lib/gcc/x86_64-redhat-linux/11/../../../../include/c++/11/bits/range_access.h:319: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/11/../../../../include/c++/11/bits/range_access.h:290: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/11/../../../../include/c++/11/bits/range_access.h:300: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/11/../../../../include/c++/11/bits/range_access.h:310:5: note: candidate found by name lookup is 'std::data'\n", " data(_Tp (&__array)[_Nm]) noexcept\n", " ^\n" ] } ], "source": [ "model.fitTo(*data, Verbose(true));" ] }, { "cell_type": "markdown", "id": "0104ec36", "metadata": {}, "source": [ "Reset message service to default stream configuration" ] }, { "cell_type": "code", "execution_count": 16, "id": "2a377c5d", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2025-12-15T03:23:28.607686Z", "iopub.status.busy": "2025-12-15T03:23:28.607508Z", "iopub.status.idle": "2025-12-15T03:23:28.817136Z", "shell.execute_reply": "2025-12-15T03:23:28.816651Z" } }, "outputs": [], "source": [ "RooMsgService::instance().reset();" ] }, { "cell_type": "markdown", "id": "b955eb0c", "metadata": {}, "source": [ "Example of another debugging stream\n", "---------------------------------------------------------------------" ] }, { "cell_type": "markdown", "id": "f46961ee", "metadata": {}, "source": [ "Show DEBUG level messages on client/server link state management" ] }, { "cell_type": "code", "execution_count": 17, "id": "fc055716", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2025-12-15T03:23:28.819500Z", "iopub.status.busy": "2025-12-15T03:23:28.819346Z", "iopub.status.idle": "2025-12-15T03:23:29.050810Z", "shell.execute_reply": "2025-12-15T03:23:29.047714Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "All Message streams\n", "[0] MinLevel = PROGRESS Topic = Generation Minimization Plotting Fitting Integration LinkStateMgmt Eval Caching Optimization ObjectHandling InputArguments Tracing Contents DataHandling NumericIntegration FastEvaluations \n", "[1] MinLevel = INFO Topic = Minimization Plotting Fitting Eval Caching ObjectHandling InputArguments DataHandling NumericIntegration \n", "[2] MinLevel = INFO Topic = HistFactory \n", "[3] MinLevel = DEBUG Topic = LinkStateMgmt \n" ] } ], "source": [ "RooMsgService::instance().addStream(DEBUG, Topic(LinkStateMgmt));\n", "RooMsgService::instance().Print(\"v\");" ] }, { "cell_type": "markdown", "id": "6ff9c9a4", "metadata": {}, "source": [ "Clone composite pdf g to trigger some link state management activity" ] }, { "cell_type": "code", "execution_count": 18, "id": "0bc8da9a", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2025-12-15T03:23:29.053184Z", "iopub.status.busy": "2025-12-15T03:23:29.053004Z", "iopub.status.idle": "2025-12-15T03:23:29.270903Z", "shell.execute_reply": "2025-12-15T03:23:29.270408Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[#3] DEBUG:LinkStateMgmt -- RooAbsArg::addServer(0x7f910d9380b0,g): adding server x(0x7f9134014000) for value \n", "[#3] DEBUG:LinkStateMgmt -- RooAbsArg::addServer(0x7f910d9380b0,g): adding server m(0x7f91340143e8) for value \n", "[#3] DEBUG:LinkStateMgmt -- RooAbsArg::addServer(0x7f910d9380b0,g): adding server s(0x7f91340147d0) for value \n", "[#3] DEBUG:LinkStateMgmt -- RooAbsArg::addServer(0x7f910d9380b0,g): adding server x(0x7f9134014000) for value \n", "[#3] DEBUG:LinkStateMgmt -- RooAbsArg::addServer(0x7f910d9380b0,g): adding server m(0x7f91340143e8) for value \n", "[#3] DEBUG:LinkStateMgmt -- RooAbsArg::addServer(0x7f910d9380b0,g): adding server s(0x7f91340147d0) for value \n", "RooGaussian::g[ x=x mean=m sigma=s ] = 1\n" ] } ], "source": [ "RooAbsArg *gprime = gauss.cloneTree();\n", "gprime->Print();" ] }, { "cell_type": "markdown", "id": "46004d2d", "metadata": {}, "source": [ "Reset message service to default stream configuration" ] }, { "cell_type": "code", "execution_count": 19, "id": "95688ba0", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2025-12-15T03:23:29.272613Z", "iopub.status.busy": "2025-12-15T03:23:29.272470Z", "iopub.status.idle": "2025-12-15T03:23:29.481354Z", "shell.execute_reply": "2025-12-15T03:23:29.480868Z" } }, "outputs": [], "source": [ "RooMsgService::instance().reset();" ] } ], "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 }