Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
rf506_msgservice.py
Go to the documentation of this file.
1## \file
2## \ingroup tutorial_roofit
3## \notebook -nodraw
4## Organization and simultaneous fits: tuning and customizing the ROOT.RooFit message logging facility
5##
6## \macro_code
7##
8## \date February 2018
9## \authors Clemens Lange, Wouter Verkerke (C++ version)
10
11import ROOT
12
13# Create pdf
14# --------------------
15
16# Construct gauss(x,m,s)
17x = ROOT.RooRealVar("x", "x", -10, 10)
18m = ROOT.RooRealVar("m", "m", 0, -10, 10)
19s = ROOT.RooRealVar("s", "s", 1, -10, 10)
20gauss = ROOT.RooGaussian("g", "g", x, m, s)
21
22# Construct poly(x,p0)
23p0 = ROOT.RooRealVar("p0", "p0", 0.01, 0.0, 1.0)
24poly = ROOT.RooPolynomial("p", "p", x, [p0])
25
26# model = f*gauss(x) + (1-f)*poly(x)
27f = ROOT.RooRealVar("f", "f", 0.5, 0.0, 1.0)
28model = ROOT.RooAddPdf("model", "model", [gauss, poly], [f])
29
30data = model.generate({x}, 10)
31
32# Print configuration of message service
33# ------------------------------------------
34
35# Print streams configuration
36ROOT.RooMsgService.instance().Print()
37
38# Adding integration topic to existing INFO stream
39# ---------------------------------------------------
40
41# Print streams configuration
42ROOT.RooMsgService.instance().Print()
43
44# Add Integration topic to existing INFO stream
45ROOT.RooMsgService.instance().getStream(1).addTopic(ROOT.RooFit.Integration)
46
47# Construct integral over gauss to demonstrate message stream
48igauss = gauss.createIntegral({x})
49igauss.Print()
50
51# Print streams configuration in verbose, also shows inactive streams
52ROOT.RooMsgService.instance().Print()
53
54# Remove stream
55ROOT.RooMsgService.instance().getStream(1).removeTopic(ROOT.RooFit.Integration)
56
57# Examples of pdf value tracing
58# -----------------------------------------------------------------------
59
60# Show DEBUG level message on function tracing, ROOT.RooGaussian only
61ROOT.RooMsgService.instance().addStream(ROOT.RooFit.DEBUG, Topic=ROOT.RooFit.Tracing, ClassName="RooGaussian")
62
63# Perform a fit to generate some tracing messages
64model.fitTo(data, Verbose=True)
65
66# Reset message service to default stream configuration
67ROOT.RooMsgService.instance().reset()
68
69# Show DEBUG level message on function tracing on all objects, output to
70# file
71ROOT.RooMsgService.instance().addStream(ROOT.RooFit.DEBUG, Topic=ROOT.RooFit.Tracing, OutputFile="rf506_debug.log")
72
73# Perform a fit to generate some tracing messages
74model.fitTo(data, Verbose=True)
75
76# Reset message service to default stream configuration
77ROOT.RooMsgService.instance().reset()
78
79# Example of another debugging stream
80# ---------------------------------------------------------------------
81
82# Show DEBUG level messages on client/server link state management
83ROOT.RooMsgService.instance().addStream(ROOT.RooFit.DEBUG, Topic=ROOT.RooFit.LinkStateMgmt)
84ROOT.RooMsgService.instance().Print("v")
85
86# Clone composite pdf g to trigger some link state management activity
87gprime = gauss.cloneTree()
88gprime.Print()
89
90# Reset message service to default stream configuration
91ROOT.RooMsgService.instance().reset()