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