'ORGANIZATION AND SIMULTANEOUS FITS' RooFit tutorial macro #503

The input file for self macro is generated by rf502_wspaceread.py

Author: Wouter Verkerke (C version)
This notebook tutorial was automatically generated with ROOTBOOK-izer from the macro found in the ROOT repository on Wednesday, January 19, 2022 at 10:23 AM.

In [ ]:
import ROOT


Open input file with workspace (generated by rf503_wspacewrite)

In [ ]:
f = ROOT.TFile("rf502_workspace_py.root")


Retrieve workspace from file

In [ ]:
w = f.Get("w")


## Retrieve pdf, data from workspace¶

Retrieve x, and data from workspace

In [ ]:
x = w["x"]
model = w["model"]
data = w["modelData"]


Print structure of composite p.d.f.

In [ ]:
model.Print("t")


## Fit model to data, plot model¶

Fit model to data

In [ ]:
model.fitTo(data)


Plot data and PDF overlaid

In [ ]:
xframe = x.frame(Title="Model and data read from workspace")
data.plotOn(xframe)
model.plotOn(xframe)


Overlay the background component of model with a dashed line

In [ ]:
model.plotOn(xframe, Components="bkg", LineStyle="--")


Overlay the background+sig2 components of model with a dotted line

In [ ]:
model.plotOn(xframe, Components="bkg,sig2", LineStyle=":")


Draw the frame on the canvas

In [ ]:
c = ROOT.TCanvas("rf503_wspaceread", "rf503_wspaceread", 600, 600)

from ROOT import gROOT