Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
rf503_wspaceread.py
Go to the documentation of this file.
1## \file
2## \ingroup tutorial_roofit
3## \notebook
4##
5## 'ORGANIZATION AND SIMULTANEOUS FITS' RooFit tutorial macro #503
6##
7## Reading and using a workspace
8##
9## The input file for self macro is generated by rf502_wspaceread.py
10##
11## \macro_image
12## \macro_code
13## \macro_output
14##
15## \date February 2018
16## \authors Clemens Lange, Wouter Verkerke (C version)
17
18import ROOT
19
20
21# Read workspace from file
22# -----------------------------------------------
23
24# Open input file with workspace (generated by rf503_wspacewrite)
25f = ROOT.TFile("rf502_workspace_py.root")
26
27# Retrieve workspace from file
28w = f.Get("w")
29
30# Retrieve pdf, data from workspace
31# -----------------------------------------------------------------
32
33# Retrieve x, and data from workspace
34x = w["x"]
35model = w["model"]
36data = w["modelData"]
37
38# Print structure of composite p.d.f.
39model.Print("t")
40
41# Fit model to data, plot model
42# ---------------------------------------------------------
43
44# Fit model to data
45model.fitTo(data, PrintLevel=-1)
46
47# Plot data and PDF overlaid
48xframe = x.frame(Title="Model and data read from workspace")
49data.plotOn(xframe)
50model.plotOn(xframe)
51
52# Overlay the background component of model with a dashed line
53model.plotOn(xframe, Components="bkg", LineStyle="--")
54
55# Overlay the background+sig2 components of model with a dotted line
56model.plotOn(xframe, Components="bkg,sig2", LineStyle=":")
57
58# Draw the frame on the canvas
59c = ROOT.TCanvas("rf503_wspaceread", "rf503_wspaceread", 600, 600)
60ROOT.gPad.SetLeftMargin(0.15)
61xframe.GetYaxis().SetTitleOffset(1.4)
62xframe.Draw()
63
64c.SaveAs("rf503_wspaceread.png")