{
"cells": [
{
"cell_type": "markdown",
"id": "af4bafb3",
"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 Tuesday, May 19, 2026 at 08:32 PM."
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "971f271b",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:32:21.751163Z",
"iopub.status.busy": "2026-05-19T20:32:21.751053Z",
"iopub.status.idle": "2026-05-19T20:32:21.765590Z",
"shell.execute_reply": "2026-05-19T20:32:21.764938Z"
}
},
"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": "49c83294",
"metadata": {},
"source": [
"Create pdf\n",
"--------------------"
]
},
{
"cell_type": "markdown",
"id": "1545e8ea",
"metadata": {},
"source": [
"Construct gauss(x,m,s)"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "6ca22413",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:32:21.768573Z",
"iopub.status.busy": "2026-05-19T20:32:21.768446Z",
"iopub.status.idle": "2026-05-19T20:32:22.132812Z",
"shell.execute_reply": "2026-05-19T20:32:22.132237Z"
}
},
"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": "1e3a1e26",
"metadata": {},
"source": [
"Construct poly(x,p0)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "8e904753",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:32:22.134045Z",
"iopub.status.busy": "2026-05-19T20:32:22.133932Z",
"iopub.status.idle": "2026-05-19T20:32:22.367785Z",
"shell.execute_reply": "2026-05-19T20:32:22.367077Z"
}
},
"outputs": [],
"source": [
"RooRealVar p0(\"p0\", \"p0\", 0.01, 0., 1.);\n",
"RooPolynomial poly(\"p\", \"p\", x, p0);"
]
},
{
"cell_type": "markdown",
"id": "f31a50fd",
"metadata": {},
"source": [
"Construct model = f*gauss(x) + (1-f)*poly(x)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "9272fefd",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:32:22.369345Z",
"iopub.status.busy": "2026-05-19T20:32:22.369210Z",
"iopub.status.idle": "2026-05-19T20:32:22.578559Z",
"shell.execute_reply": "2026-05-19T20:32:22.577967Z"
}
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"input_line_51: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": "e3561ba6",
"metadata": {},
"source": [
"Print configuration of message service\n",
"---------------------------------------------------------------------------"
]
},
{
"cell_type": "markdown",
"id": "1bcfe006",
"metadata": {},
"source": [
"Print streams configuration"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "94f2850b",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:32:22.583232Z",
"iopub.status.busy": "2026-05-19T20:32:22.583066Z",
"iopub.status.idle": "2026-05-19T20:32:22.792411Z",
"shell.execute_reply": "2026-05-19T20:32:22.792030Z"
}
},
"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": "267e5a4d",
"metadata": {},
"source": [
"Adding Integration topic to existing INFO stream\n",
"-----------------------------------------------------------------------------------------------"
]
},
{
"cell_type": "markdown",
"id": "aaea67d1",
"metadata": {},
"source": [
"Print streams configuration"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "4b702449",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:32:22.793681Z",
"iopub.status.busy": "2026-05-19T20:32:22.793542Z",
"iopub.status.idle": "2026-05-19T20:32:23.002149Z",
"shell.execute_reply": "2026-05-19T20:32:23.001688Z"
}
},
"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": "d2acaf67",
"metadata": {},
"source": [
"Add Integration topic to existing INFO stream"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "993ec30d",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:32:23.003380Z",
"iopub.status.busy": "2026-05-19T20:32:23.003267Z",
"iopub.status.idle": "2026-05-19T20:32:23.211727Z",
"shell.execute_reply": "2026-05-19T20:32:23.211184Z"
}
},
"outputs": [],
"source": [
"RooMsgService::instance().getStream(1).addTopic(Integration);"
]
},
{
"cell_type": "markdown",
"id": "562dcad5",
"metadata": {},
"source": [
"Construct integral over gauss to demonstrate new message stream"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "20951862",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:32:23.213089Z",
"iopub.status.busy": "2026-05-19T20:32:23.212976Z",
"iopub.status.idle": "2026-05-19T20:32:23.421553Z",
"shell.execute_reply": "2026-05-19T20:32:23.421138Z"
}
},
"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": "f3d6b86d",
"metadata": {},
"source": [
"Print streams configuration in verbose, which also shows inactive streams"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "386edf1b",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:32:23.422883Z",
"iopub.status.busy": "2026-05-19T20:32:23.422761Z",
"iopub.status.idle": "2026-05-19T20:32:23.631471Z",
"shell.execute_reply": "2026-05-19T20:32:23.631002Z"
}
},
"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": "296afcab",
"metadata": {},
"source": [
"Remove stream"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "84910599",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:32:23.632690Z",
"iopub.status.busy": "2026-05-19T20:32:23.632550Z",
"iopub.status.idle": "2026-05-19T20:32:23.840954Z",
"shell.execute_reply": "2026-05-19T20:32:23.840408Z"
}
},
"outputs": [],
"source": [
"RooMsgService::instance().getStream(1).removeTopic(Integration);"
]
},
{
"cell_type": "markdown",
"id": "5128890b",
"metadata": {},
"source": [
"Examples of pdf value tracing stream\n",
"-----------------------------------------------------------------------"
]
},
{
"cell_type": "markdown",
"id": "4e9b8291",
"metadata": {},
"source": [
"Show DEBUG level message on function tracing, trace RooGaussian only"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "e9641fad",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:32:23.842320Z",
"iopub.status.busy": "2026-05-19T20:32:23.842209Z",
"iopub.status.idle": "2026-05-19T20:32:24.047532Z",
"shell.execute_reply": "2026-05-19T20:32:24.047022Z"
}
},
"outputs": [],
"source": [
"RooMsgService::instance().addStream(DEBUG, Topic(Tracing), ClassName(\"RooGaussian\"));"
]
},
{
"cell_type": "markdown",
"id": "a3732170",
"metadata": {},
"source": [
"Perform a fit to generate some tracing messages"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "2690e19e",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:32:24.048944Z",
"iopub.status.busy": "2026-05-19T20:32:24.048827Z",
"iopub.status.idle": "2026-05-19T20:32:24.258011Z",
"shell.execute_reply": "2026-05-19T20:32:24.257590Z"
}
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"input_line_59:2:15: error: reference to 'data' is ambiguous\n",
" model.fitTo(*data, Verbose(true));\n",
" ^\n",
"input_line_51: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/14/../../../../include/c++/14/bits/range_access.h:344: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/14/../../../../include/c++/14/bits/range_access.h:312: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/14/../../../../include/c++/14/bits/range_access.h:323: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/14/../../../../include/c++/14/bits/range_access.h:334: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": "5651afbb",
"metadata": {},
"source": [
"Reset message service to default stream configuration"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "56c2459f",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:32:24.259166Z",
"iopub.status.busy": "2026-05-19T20:32:24.259059Z",
"iopub.status.idle": "2026-05-19T20:32:24.467205Z",
"shell.execute_reply": "2026-05-19T20:32:24.466719Z"
}
},
"outputs": [],
"source": [
"RooMsgService::instance().reset();"
]
},
{
"cell_type": "markdown",
"id": "95e1bcae",
"metadata": {},
"source": [
"Show DEBUG level message on function tracing on all objects, redirect output to file"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "041f66e5",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:32:24.469483Z",
"iopub.status.busy": "2026-05-19T20:32:24.469367Z",
"iopub.status.idle": "2026-05-19T20:32:24.674923Z",
"shell.execute_reply": "2026-05-19T20:32:24.674385Z"
}
},
"outputs": [],
"source": [
"RooMsgService::instance().addStream(DEBUG, Topic(Tracing), OutputFile(\"rf506_debug.log\"));"
]
},
{
"cell_type": "markdown",
"id": "3c0666e8",
"metadata": {},
"source": [
"Perform a fit to generate some tracing messages"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "940e455d",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:32:24.676380Z",
"iopub.status.busy": "2026-05-19T20:32:24.676271Z",
"iopub.status.idle": "2026-05-19T20:32:24.886115Z",
"shell.execute_reply": "2026-05-19T20:32:24.885657Z"
}
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"input_line_62:2:15: error: reference to 'data' is ambiguous\n",
" model.fitTo(*data, Verbose(true));\n",
" ^\n",
"input_line_51: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/14/../../../../include/c++/14/bits/range_access.h:344: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/14/../../../../include/c++/14/bits/range_access.h:312: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/14/../../../../include/c++/14/bits/range_access.h:323: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/14/../../../../include/c++/14/bits/range_access.h:334: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": "b646adf7",
"metadata": {},
"source": [
"Reset message service to default stream configuration"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "04f025b7",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:32:24.892997Z",
"iopub.status.busy": "2026-05-19T20:32:24.892877Z",
"iopub.status.idle": "2026-05-19T20:32:25.101050Z",
"shell.execute_reply": "2026-05-19T20:32:25.100459Z"
}
},
"outputs": [],
"source": [
"RooMsgService::instance().reset();"
]
},
{
"cell_type": "markdown",
"id": "d8b01492",
"metadata": {},
"source": [
"Example of another debugging stream\n",
"---------------------------------------------------------------------"
]
},
{
"cell_type": "markdown",
"id": "ceb540e4",
"metadata": {},
"source": [
"Show DEBUG level messages on client/server link state management"
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "329c1787",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:32:25.103113Z",
"iopub.status.busy": "2026-05-19T20:32:25.103002Z",
"iopub.status.idle": "2026-05-19T20:32:25.308922Z",
"shell.execute_reply": "2026-05-19T20:32:25.308493Z"
}
},
"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": "80bcf7b5",
"metadata": {},
"source": [
"Clone composite pdf g to trigger some link state management activity"
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "ba9da966",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:32:25.310131Z",
"iopub.status.busy": "2026-05-19T20:32:25.310024Z",
"iopub.status.idle": "2026-05-19T20:32:25.518802Z",
"shell.execute_reply": "2026-05-19T20:32:25.518364Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[#3] DEBUG:LinkStateMgmt -- RooAbsArg::addServer(0x7f7dc19dc740,g): adding server x(0x7f7e1176d000) for value \n",
"[#3] DEBUG:LinkStateMgmt -- RooAbsArg::addServer(0x7f7dc19dc740,g): adding server m(0x7f7e1176d3e8) for value \n",
"[#3] DEBUG:LinkStateMgmt -- RooAbsArg::addServer(0x7f7dc19dc740,g): adding server s(0x7f7e1176d7d0) for value \n",
"[#3] DEBUG:LinkStateMgmt -- RooAbsArg::addServer(0x7f7dc19dc740,g): adding server x(0x7f7e1176d000) for value \n",
"[#3] DEBUG:LinkStateMgmt -- RooAbsArg::addServer(0x7f7dc19dc740,g): adding server m(0x7f7e1176d3e8) for value \n",
"[#3] DEBUG:LinkStateMgmt -- RooAbsArg::addServer(0x7f7dc19dc740,g): adding server s(0x7f7e1176d7d0) 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": "3d2e9953",
"metadata": {},
"source": [
"Reset message service to default stream configuration"
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "1ad1f673",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:32:25.519994Z",
"iopub.status.busy": "2026-05-19T20:32:25.519886Z",
"iopub.status.idle": "2026-05-19T20:32:25.728015Z",
"shell.execute_reply": "2026-05-19T20:32:25.727503Z"
}
},
"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
}