Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
rf407_latextables.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_roofit
3/// \notebook -nodraw
4/// Data and categories: latex printing of lists and sets of RooArgSets
5///
6/// \macro_code
7/// \macro_output
8///
9/// \date July 2008
10/// \author Wouter Verkerke
11
12#include "RooRealVar.h"
13#include "RooDataSet.h"
14#include "RooGaussian.h"
15#include "RooChebychev.h"
16#include "RooAddPdf.h"
17#include "RooExponential.h"
18#include "TCanvas.h"
19#include "TAxis.h"
20#include "RooPlot.h"
21using namespace RooFit;
22
24{
25 // S e t u p c o m p o s i t e p d f
26 // --------------------------------------
27
28 // Declare observable x
29 RooRealVar x("x", "x", 0, 10);
30
31 // Create two Gaussian PDFs g1(x,mean1,sigma) anf g2(x,mean2,sigma) and their parameters
32 RooRealVar mean("mean", "mean of gaussians", 5);
33 RooRealVar sigma1("sigma1", "width of gaussians", 0.5);
34 RooRealVar sigma2("sigma2", "width of gaussians", 1);
35 RooGaussian sig1("sig1", "Signal component 1", x, mean, sigma1);
36 RooGaussian sig2("sig2", "Signal component 2", x, mean, sigma2);
37
38 // Sum the signal components into a composite signal pdf
39 RooRealVar sig1frac("sig1frac", "fraction of component 1 in signal", 0.8, 0., 1.);
40 RooAddPdf sig("sig", "Signal", RooArgList(sig1, sig2), sig1frac);
41
42 // Build Chebychev polynomial pdf
43 RooRealVar a0("a0", "a0", 0.5, 0., 1.);
44 RooRealVar a1("a1", "a1", 0.2, 0., 1.);
45 RooChebychev bkg1("bkg1", "Background 1", x, RooArgSet(a0, a1));
46
47 // Build expontential pdf
48 RooRealVar alpha("alpha", "alpha", -1);
49 RooExponential bkg2("bkg2", "Background 2", x, alpha);
50
51 // Sum the background components into a composite background pdf
52 RooRealVar bkg1frac("sig1frac", "fraction of component 1 in background", 0.2, 0., 1.);
53 RooAddPdf bkg("bkg", "Signal", RooArgList(bkg1, bkg2), sig1frac);
54
55 // Sum the composite signal and background
56 RooRealVar bkgfrac("bkgfrac", "fraction of background", 0.5, 0., 1.);
57 RooAddPdf model("model", "g1+g2+a", RooArgList(bkg, sig), bkgfrac);
58
59 // M a k e l i s t o f p a r a m e t e r s b e f o r e a n d a f t e r f i t
60 // ----------------------------------------------------------------------------------------
61
62 // Make list of model parameters
63 std::unique_ptr<RooArgSet> params{model.getParameters(x)};
64
65 // Save snapshot of prefit parameters
66 std::unique_ptr<RooArgSet> initParams{static_cast<RooArgSet *>(params->snapshot())};
67
68 // Do fit to data, to obtain error estimates on parameters
69 std::unique_ptr<RooDataSet> data{model.generate(x, 1000)};
70 model.fitTo(*data, PrintLevel(-1));
71
72 // P r i n t l a t ex t a b l e o f p a r a m e t e r s o f p d f
73 // --------------------------------------------------------------------------
74
75 // Print parameter list in LaTeX for (one column with names, one column with values)
76 params->printLatex();
77
78 // Print parameter list in LaTeX for (names values|names values)
79 params->printLatex(Columns(2));
80
81 // Print two parameter lists side by side (name values initvalues)
82 params->printLatex(Sibling(*initParams));
83
84 // Print two parameter lists side by side (name values initvalues|name values initvalues)
85 params->printLatex(Sibling(*initParams), Columns(2));
86
87 // Write LaTex table to file
88 params->printLatex(Sibling(*initParams), OutputFile("rf407_latextables.tex"));
89}
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Efficient implementation of a sum of PDFs of the form.
Definition RooAddPdf.h:33
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition RooArgList.h:22
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:24
Chebychev polynomial p.d.f.
Exponential PDF.
Plain Gaussian p.d.f.
Definition RooGaussian.h:24
Variable that can be changed from the outside.
Definition RooRealVar.h:37
RooCmdArg Columns(Int_t ncol)
RooCmdArg Sibling(const RooAbsCollection &sibling)
RooCmdArg OutputFile(const char *fileName)
RooCmdArg PrintLevel(Int_t code)
Double_t x[n]
Definition legend1.C:17
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Definition CodegenImpl.h:64