ROOT   Reference Guide
Searching...
No Matches
rf407_latextables.py
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 February 2018
10## \authors Clemens Lange, Wouter Verkerke (C++ version)
11
12import ROOT
13
14
15# Setup composite pdf
16# --------------------------------------
17
18# Declare observable x
19x = ROOT.RooRealVar("x", "x", 0, 10)
20
21# Create two Gaussian PDFs g1(x,mean1,sigma) anf g2(x,mean2,sigma) and
22# their parameters
23mean = ROOT.RooRealVar("mean", "mean of gaussians", 5)
24sigma1 = ROOT.RooRealVar("sigma1", "width of gaussians", 0.5)
25sigma2 = ROOT.RooRealVar("sigma2", "width of gaussians", 1)
26sig1 = ROOT.RooGaussian("sig1", "Signal component 1", x, mean, sigma1)
27sig2 = ROOT.RooGaussian("sig2", "Signal component 2", x, mean, sigma2)
28
29# Sum the signal components into a composite signal pdf
30sig1frac = ROOT.RooRealVar("sig1frac", "fraction of component 1 in signal", 0.8, 0.0, 1.0)
31sig = ROOT.RooAddPdf("sig", "Signal", [sig1, sig2], [sig1frac])
32
33# Build Chebychev polynomial pdf
34a0 = ROOT.RooRealVar("a0", "a0", 0.5, 0.0, 1.0)
35a1 = ROOT.RooRealVar("a1", "a1", -0.2, 0.0, 1.0)
36bkg1 = ROOT.RooChebychev("bkg1", "Background 1", x, [a0, a1])
37
38# Build expontential pdf
39alpha = ROOT.RooRealVar("alpha", "alpha", -1)
40bkg2 = ROOT.RooExponential("bkg2", "Background 2", x, alpha)
41
42# Sum the background components into a composite background pdf
43bkg1frac = ROOT.RooRealVar("sig1frac", "fraction of component 1 in background", 0.2, 0.0, 1.0)
44bkg = ROOT.RooAddPdf("bkg", "Signal", [bkg1, bkg2], [sig1frac])
45
46# Sum the composite signal and background
47bkgfrac = ROOT.RooRealVar("bkgfrac", "fraction of background", 0.5, 0.0, 1.0)
48model = ROOT.RooAddPdf("model", "g1+g2+a", [bkg, sig], [bkgfrac])
49
50# Make list of parameters before and after fit
51# ----------------------------------------------------------------------------------------
52
53# Make list of model parameters
54params = model.getParameters({x})
55
56# Save snapshot of prefit parameters
57initParams = params.snapshot()
58
59# Do fit to data, obtain error estimates on parameters
60data = model.generate({x}, 1000)
61model.fitTo(data, PrintLevel=-1)
62
63# Print LateX table of parameters of pdf
64# --------------------------------------------------------------------------
65
66# Print parameter list in LaTeX for (one column with names, column with
67# values)
68params.printLatex()
69
70# Print parameter list in LaTeX for (names values|names values)
71params.printLatex(Columns=2)
72
73# Print two parameter lists side by side (name values initvalues)
74params.printLatex(Sibling=initParams)
75
76# Print two parameter lists side by side (name values initvalues|name
77# values initvalues)
78params.printLatex(Sibling=initParams, Columns=2)
79
80# Write LaTex table to file
81params.printLatex(Sibling=initParams, OutputFile="rf407_latextables.tex")