# Rf 5 0 6_Msgservice¶

Organisation and simultaneous fits: tuning and customizing the RooFit message logging facility

Author: Wouter Verkerke
This notebook tutorial was automatically generated with ROOTBOOK-izer from the macro found in the ROOT repository on Wednesday, January 19, 2022 at 10:24 AM.

In [1]:
%%cpp -d
#include "RooRealVar.h"
#include "RooDataSet.h"
#include "RooGaussian.h"
#include "RooPolynomial.h"
#include "TCanvas.h"
#include "TAxis.h"
#include "RooPlot.h"
#include "RooMsgService.h"

In [2]:
%%cpp -d
// This is a workaround to make sure the namespace is used inside functions
using namespace RooFit;


## Create pdf¶

Construct gauss(x,m,s)

In [3]:
RooRealVar x("x", "x", -10, 10);
RooRealVar m("m", "m", 0, -10, 10);
RooRealVar s("s", "s", 1, -10, 10);
RooGaussian gauss("g", "g", x, m, s);

RooFit v3.60 -- Developed by Wouter Verkerke and David Kirkby
Copyright (C) 2000-2013 NIKHEF, University of California & Stanford University

[#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.


Construct poly(x,p0)

In [4]:
RooRealVar p0("p0", "p0", 0.01, 0., 1.);
RooPolynomial poly("p", "p", x, p0);


Construct model = fgauss(x) + (1-f)poly(x)

In [5]:
RooRealVar f("f", "f", 0.5, 0., 1.);
RooAddPdf model("model", "model", RooArgSet(gauss, poly), f);

RooDataSet *data = model.generate(x, 10);


Print streams configuration

In [6]:
RooMsgService::instance().Print();
cout << endl;

Active Message streams
[0] MinLevel = PROGRESS Topic = Generation Minimization Plotting Fitting Integration LinkStateMgmt Eval Caching Optimization ObjectHandling InputArguments Tracing Contents DataHandling NumericIntegration FastEvaluations
[1] MinLevel = INFO Topic = Minimization Plotting Fitting Eval Caching ObjectHandling InputArguments DataHandling NumericIntegration
[2] MinLevel = INFO Topic = HistFactory



## Adding integration topic to existing info stream¶

Print streams configuration

In [7]:
RooMsgService::instance().Print();
cout << endl;

Active Message streams
[0] MinLevel = PROGRESS Topic = Generation Minimization Plotting Fitting Integration LinkStateMgmt Eval Caching Optimization ObjectHandling InputArguments Tracing Contents DataHandling NumericIntegration FastEvaluations
[1] MinLevel = INFO Topic = Minimization Plotting Fitting Eval Caching ObjectHandling InputArguments DataHandling NumericIntegration
[2] MinLevel = INFO Topic = HistFactory



Add integration topic to existing info stream

In [8]:
RooMsgService::instance().getStream(1).addTopic(Integration);


Construct integral over gauss to demonstrate new message stream

In [9]:
RooAbsReal *igauss = gauss.createIntegral(x);
igauss->Print();

[#1] INFO:Integration -- RooRealIntegral::ctor(g_Int[x]) Constructing integral of function g over observables(x) with normalization () with range identifier <none>
[#1] INFO:Integration -- g: Observable x is suitable for analytical integration (if supported by p.d.f)
[#1] INFO:Integration -- g: Function integrated observables (x) internally with code 1
[#1] INFO:Integration -- g: Observables (x) are analytically integrated with code 1
RooRealIntegral::g_Int[x][ Int gd[Ana](x) ] = 2.50663


Print streams configuration in verbose, which also shows inactive streams

In [10]:
cout << endl;
RooMsgService::instance().Print();
cout << endl;

Active Message streams
[0] MinLevel = PROGRESS Topic = Generation Minimization Plotting Fitting Integration LinkStateMgmt Eval Caching Optimization ObjectHandling InputArguments Tracing Contents DataHandling NumericIntegration FastEvaluations
[1] MinLevel = INFO Topic = Minimization Plotting Fitting Integration Eval Caching ObjectHandling InputArguments DataHandling NumericIntegration
[2] MinLevel = INFO Topic = HistFactory



Remove stream

In [11]:
RooMsgService::instance().getStream(1).removeTopic(Integration);


## Examples of pdf value tracing stream¶

Show debug level message on function tracing, trace roogaussian only

In [12]:
RooMsgService::instance().addStream(DEBUG, Topic(Tracing), ClassName("RooGaussian"));


Perform a fit to generate some tracing messages

In [13]:
model.fitTo(*data, Verbose(kTRUE));

input_line_63:2:15: error: reference to 'data' is ambiguous
model.fitTo(*data, Verbose(kTRUE));
^
input_line_55:5:13: note: candidate found by name lookup is '__cling_N523::data'
RooDataSet *data = model.generate(x, 10);
^
/usr/include/c++/9/bits/range_access.h:318:5: note: candidate found by name lookup is 'std::data'
data(initializer_list<_Tp> __il) noexcept
^
/usr/include/c++/9/bits/range_access.h:289:5: note: candidate found by name lookup is 'std::data'
data(_Container& __cont) noexcept(noexcept(__cont.data()))
^
/usr/include/c++/9/bits/range_access.h:299:5: note: candidate found by name lookup is 'std::data'
data(const _Container& __cont) noexcept(noexcept(__cont.data()))
^
/usr/include/c++/9/bits/range_access.h:309:5: note: candidate found by name lookup is 'std::data'
data(_Tp (&__array)[_Nm]) noexcept
^


Reset message service to default stream configuration

In [14]:
RooMsgService::instance().reset();


Show debug level message on function tracing on all objects, redirect output to file

In [15]:
RooMsgService::instance().addStream(DEBUG, Topic(Tracing), OutputFile("rf506_debug.log"));


Perform a fit to generate some tracing messages

In [16]:
model.fitTo(*data, Verbose(kTRUE));

input_line_66:2:15: error: reference to 'data' is ambiguous
model.fitTo(*data, Verbose(kTRUE));
^
input_line_55:5:13: note: candidate found by name lookup is '__cling_N523::data'
RooDataSet *data = model.generate(x, 10);
^
/usr/include/c++/9/bits/range_access.h:318:5: note: candidate found by name lookup is 'std::data'
data(initializer_list<_Tp> __il) noexcept
^
/usr/include/c++/9/bits/range_access.h:289:5: note: candidate found by name lookup is 'std::data'
data(_Container& __cont) noexcept(noexcept(__cont.data()))
^
/usr/include/c++/9/bits/range_access.h:299:5: note: candidate found by name lookup is 'std::data'
data(const _Container& __cont) noexcept(noexcept(__cont.data()))
^
/usr/include/c++/9/bits/range_access.h:309:5: note: candidate found by name lookup is 'std::data'
data(_Tp (&__array)[_Nm]) noexcept
^


Reset message service to default stream configuration

In [17]:
RooMsgService::instance().reset();


## Example of another debugging stream¶

Show debug level messages on client/server link state management

In [18]:
RooMsgService::instance().addStream(DEBUG, Topic(LinkStateMgmt));
RooMsgService::instance().Print("v");

All Message streams
[0] MinLevel = PROGRESS Topic = Generation Minimization Plotting Fitting Integration LinkStateMgmt Eval Caching Optimization ObjectHandling InputArguments Tracing Contents DataHandling NumericIntegration FastEvaluations
[1] MinLevel = INFO Topic = Minimization Plotting Fitting Eval Caching ObjectHandling InputArguments DataHandling NumericIntegration
[2] MinLevel = INFO Topic = HistFactory
[3] MinLevel = DEBUG Topic = LinkStateMgmt


Clone composite pdf g to trigger some link state management activity

In [19]:
RooAbsArg *gprime = gauss.cloneTree();
gprime->Print();

[#3] DEBUG:LinkStateMgmt -- RooAbsArg::addServer(0x7f7ae620bf30,g): adding server x(0x7f7af8ba8000) for value

RooMsgService::instance().reset();