Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
rf506_msgservice.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_roofit
3 /// \notebook -nodraw
4 /// Organisation and simultaneous fits: tuning and customizing the RooFit message logging facility
5 ///
6 /// \macro_output
7 /// \macro_code
8 /// \author 07/2008 - Wouter Verkerke
9 
10 #include "RooRealVar.h"
11 #include "RooDataSet.h"
12 #include "RooGaussian.h"
13 #include "RooConstVar.h"
14 #include "RooPolynomial.h"
15 #include "RooAddPdf.h"
16 #include "TCanvas.h"
17 #include "TAxis.h"
18 #include "RooPlot.h"
19 #include "RooMsgService.h"
20 
21 using namespace RooFit;
22 
23 void rf506_msgservice()
24 {
25  // C r e a t e p d f
26  // --------------------
27 
28  // Construct gauss(x,m,s)
29  RooRealVar x("x", "x", -10, 10);
30  RooRealVar m("m", "m", 0, -10, 10);
31  RooRealVar s("s", "s", 1, -10, 10);
32  RooGaussian gauss("g", "g", x, m, s);
33 
34  // Construct poly(x,p0)
35  RooRealVar p0("p0", "p0", 0.01, 0., 1.);
36  RooPolynomial poly("p", "p", x, p0);
37 
38  // Construct model = f*gauss(x) + (1-f)*poly(x)
39  RooRealVar f("f", "f", 0.5, 0., 1.);
40  RooAddPdf model("model", "model", RooArgSet(gauss, poly), f);
41 
42  RooDataSet *data = model.generate(x, 10);
43 
44  // P r i n t c o n f i g u r a t i o n o f m e s s a g e s e r v i c e
45  // ---------------------------------------------------------------------------
46 
47  // Print streams configuration
48  RooMsgService::instance().Print();
49  cout << endl;
50 
51  // A d d i n g I n t e g r a t i o n t o p i c t o e x i s t i n g I N F O s t r e a m
52  // -----------------------------------------------------------------------------------------------
53 
54  // Print streams configuration
55  RooMsgService::instance().Print();
56  cout << endl;
57 
58  // Add Integration topic to existing INFO stream
59  RooMsgService::instance().getStream(1).addTopic(Integration);
60 
61  // Construct integral over gauss to demonstrate new message stream
62  RooAbsReal *igauss = gauss.createIntegral(x);
63  igauss->Print();
64 
65  // Print streams configuration in verbose, which also shows inactive streams
66  cout << endl;
67  RooMsgService::instance().Print();
68  cout << endl;
69 
70  // Remove stream
71  RooMsgService::instance().getStream(1).removeTopic(Integration);
72 
73  // E x a m p l e s o f p d f v a l u e t r a c i n g s t r e a m
74  // -----------------------------------------------------------------------
75 
76  // Show DEBUG level message on function tracing, trace RooGaussian only
77  RooMsgService::instance().addStream(DEBUG, Topic(Tracing), ClassName("RooGaussian"));
78 
79  // Perform a fit to generate some tracing messages
80  model.fitTo(*data, Verbose(kTRUE));
81 
82  // Reset message service to default stream configuration
83  RooMsgService::instance().reset();
84 
85  // Show DEBUG level message on function tracing on all objects, redirect output to file
86  RooMsgService::instance().addStream(DEBUG, Topic(Tracing), OutputFile("rf506_debug.log"));
87 
88  // Perform a fit to generate some tracing messages
89  model.fitTo(*data, Verbose(kTRUE));
90 
91  // Reset message service to default stream configuration
92  RooMsgService::instance().reset();
93 
94  // E x a m p l e o f a n o t h e r d e b u g g i n g s t r e a m
95  // ---------------------------------------------------------------------
96 
97  // Show DEBUG level messages on client/server link state management
98  RooMsgService::instance().addStream(DEBUG, Topic(LinkStateMgmt));
99  RooMsgService::instance().Print("v");
100 
101  // Clone composite pdf g to trigger some link state management activity
102  RooAbsArg *gprime = gauss.cloneTree();
103  gprime->Print();
104 
105  // Reset message service to default stream configuration
106  RooMsgService::instance().reset();
107 }