Logo ROOT   6.16/01
Reference Guide
rf206_treevistools.py
Go to the documentation of this file.
1## \file
2## \ingroup tutorial_roofit
3## \notebook -nodraw
4## 'ADDITION AND CONVOLUTION' RooFit tutorial macro #206
5## Tools for visualization of ROOT.RooAbsArg expression trees
6##
7## \macro_code
8##
9## \date February 2018
10## \author Clemens Lange
11## \author Wouter Verkerke (C version)
12
13import ROOT
14
15# Set up 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 p.d.f.
30sig1frac = ROOT.RooRealVar(
31 "sig1frac", "fraction of component 1 in signal", 0.8, 0., 1.)
32sig = ROOT.RooAddPdf(
33 "sig", "Signal", ROOT.RooArgList(sig1, sig2), ROOT.RooArgList(sig1frac))
34
35# Build Chebychev polynomial p.d.f.
36a0 = ROOT.RooRealVar("a0", "a0", 0.5, 0., 1.)
37a1 = ROOT.RooRealVar("a1", "a1", -0.2, 0., 1.)
38bkg1 = ROOT.RooChebychev("bkg1", "Background 1",
39 x, ROOT.RooArgList(a0, a1))
40
41# Build expontential pdf
42alpha = ROOT.RooRealVar("alpha", "alpha", -1)
43bkg2 = ROOT.RooExponential("bkg2", "Background 2", x, alpha)
44
45# Sum the background components into a composite background p.d.f.
46bkg1frac = ROOT.RooRealVar(
47 "bkg1frac", "fraction of component 1 in background", 0.2, 0., 1.)
48bkg = ROOT.RooAddPdf(
49 "bkg", "Signal", ROOT.RooArgList(bkg1, bkg2), ROOT.RooArgList(bkg1frac))
50
51# Sum the composite signal and background
52bkgfrac = ROOT.RooRealVar("bkgfrac", "fraction of background", 0.5, 0., 1.)
53model = ROOT.RooAddPdf(
54 "model", "g1+g2+a", ROOT.RooArgList(bkg, sig), ROOT.RooArgList(bkgfrac))
55
56# Print composite tree in ASCII
57# -----------------------------------------------------------
58
59# Print tree to stdout
60model.Print("t")
61
62# Print tree to file
63model.printCompactTree("", "rf206_asciitree.txt")
64
65# Draw composite tree graphically
66# -------------------------------------------------------------
67
68# Print GraphViz DOT file with representation of tree
69model.graphVizTree("rf206_model.dot")
70
71# Make graphic output file with one of the GraphViz tools
72# (freely available from www.graphviz.org)
73#
74# 'Top-to-bottom graph'
75# unix> dot -Tgif -o rf207_model_dot.gif rf207_model.dot
76#
77# 'Spring-model graph'
78# unix> fdp -Tgif -o rf207_model_fdp.gif rf207_model.dot