-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathrf503_wspaceread.py
68 lines (50 loc) · 1.81 KB
/
rf503_wspaceread.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# /
#
# 'ORGANIZATION AND SIMULTANEOUS FITS' ROOT.RooFit tutorial macro #503
#
# Reading and using a workspace
#
# -. ROOT.The input file for self macro is generated by rf502_wspaceread.C
#
#
# 07/2008 - Wouter Verkerke
#
# /
import ROOT
def rf503_wspaceread():
# R e a d w o r k s p a c e f r o m f i l e
# -----------------------------------------------
# Open input file with workspace (generated by rf14_wspacewrite)
f = ROOT.TFile("rf502_workspace.root")
# Retrieve workspace from file
w = f.Get("w")
# R e t r i e v e p d f , a t a f r o m w o r k s p a c e
# -----------------------------------------------------------------
# Retrieve x, and data from workspace
x = w.var("x")
model = w.pdf("model")
data = w.data("modelData")
# Print structure of composite p.d.f.
model.Print("t")
# F i t m o d e l t o d a t a , l o t m o d e l
# ---------------------------------------------------------
# Fit model to data
model.fitTo(data)
# Plot data and PDF overlaid
xframe = x.frame(ROOT.RooFit.Title("Model and data read from workspace"))
data.plotOn(xframe)
model.plotOn(xframe)
# Overlay the background component of model with a dashed line
model.plotOn(xframe, ROOT.RooFit.Components("bkg"),
ROOT.RooFit.LineStyle(ROOT.kDashed))
# Overlay the background+sig2 components of model with a dotted line
model.plotOn(xframe, ROOT.RooFit.Components("bkg,sig2"),
ROOT.RooFit.LineStyle(ROOT.kDotted))
# Draw the frame on the canvas
c = ROOT.TCanvas("rf503_wspaceread", "rf503_wspaceread", 600, 600)
ROOT.gPad.SetLeftMargin(0.15)
xframe.GetYaxis().SetTitleOffset(1.4)
xframe.Draw()
c.SaveAs("rf503_wspaceread.png")
if __name__ == "__main__":
rf503_wspaceread()