Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
rf206_treevistools.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_roofit
3 /// \notebook -nodraw
4 /// Addition and convolution: tools for visualization of RooAbsArg expression trees
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 "RooChebychev.h"
14 #include "RooAddPdf.h"
15 #include "RooExponential.h"
16 #include "TCanvas.h"
17 #include "TAxis.h"
18 #include "RooPlot.h"
19 using namespace RooFit;
20 
21 void rf206_treevistools()
22 {
23  // S e t u p c o m p o s i t e p d f
24  // --------------------------------------
25 
26  // Declare observable x
27  RooRealVar x("x", "x", 0, 10);
28 
29  // Create two Gaussian PDFs g1(x,mean1,sigma) anf g2(x,mean2,sigma) and their parameters
30  RooRealVar mean("mean", "mean of gaussians", 5);
31  RooRealVar sigma1("sigma1", "width of gaussians", 0.5);
32  RooRealVar sigma2("sigma2", "width of gaussians", 1);
33  RooGaussian sig1("sig1", "Signal component 1", x, mean, sigma1);
34  RooGaussian sig2("sig2", "Signal component 2", x, mean, sigma2);
35 
36  // Sum the signal components into a composite signal p.d.f.
37  RooRealVar sig1frac("sig1frac", "fraction of component 1 in signal", 0.8, 0., 1.);
38  RooAddPdf sig("sig", "Signal", RooArgList(sig1, sig2), sig1frac);
39 
40  // Build Chebychev polynomial p.d.f.
41  RooRealVar a0("a0", "a0", 0.5, 0., 1.);
42  RooRealVar a1("a1", "a1", 0.2, 0., 1.);
43  RooChebychev bkg1("bkg1", "Background 1", x, RooArgSet(a0, a1));
44 
45  // Build expontential pdf
46  RooRealVar alpha("alpha", "alpha", -1);
47  RooExponential bkg2("bkg2", "Background 2", x, alpha);
48 
49  // Sum the background components into a composite background p.d.f.
50  RooRealVar bkg1frac("bkg1frac", "fraction of component 1 in background", 0.2, 0., 1.);
51  RooAddPdf bkg("bkg", "Signal", RooArgList(bkg1, bkg2), bkg1frac);
52 
53  // Sum the composite signal and background
54  RooRealVar bkgfrac("bkgfrac", "fraction of background", 0.5, 0., 1.);
55  RooAddPdf model("model", "g1+g2+a", RooArgList(bkg, sig), bkgfrac);
56 
57  // P r i n t c o m p o s i t e t r e e i n A S C I I
58  // -----------------------------------------------------------
59 
60  // Print tree to stdout
61  model.Print("t");
62 
63  // Print tree to file
64  model.printCompactTree("", "rf206_asciitree.txt");
65 
66  // D r a w c o m p o s i t e t r e e g r a p h i c a l l y
67  // -------------------------------------------------------------
68 
69  // Print GraphViz DOT file with representation of tree
70  model.graphVizTree("rf206_model.dot");
71 
72  // Make graphic output file with one of the GraphViz tools
73  // (freely available from www.graphviz.org)
74  //
75  // 'Top-to-bottom graph'
76  // unix> dot -Tgif -o rf207_model_dot.gif rf207_model.dot
77  //
78  // 'Spring-model graph'
79  // unix> fdp -Tgif -o rf207_model_fdp.gif rf207_model.dot
80 }