-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathrf110_normintegration.py
77 lines (59 loc) · 2.52 KB
/
rf110_normintegration.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
69
70
71
72
73
74
75
76
77
# /
#
# 'BASIC FUNCTIONALITY' ROOT.RooFit tutorial macro #110
#
# Examples on normalization of p.d.f.s,
# integration of p.d.fs, construction
# of cumulative distribution functions from p.d.f.s
# in one dimension
#
# 07/2008 - Wouter Verkerke
#
# /
import ROOT
def rf110_normintegration():
# S e t u p m o d e l
# ---------------------
# Create observables x,y
x = ROOT.RooRealVar("x", "x", -10, 10)
# Create p.d.f. gaussx(x,-2,3)
gx = ROOT.RooGaussian(
"gx", "gx", x, ROOT.RooFit.RooConst(-2), ROOT.RooFit.RooConst(3))
# R e t r i e v e r a w & n o r m a l i z e d v a l u e s o f R o o F i t p . d . f . s
# --------------------------------------------------------------------------------------------------
# Return 'raw' unnormalized value of gx
print "gx = ", gx.getVal()
# Return value of gx normalized over x in range [-10,10]
nset = ROOT.RooArgSet(x)
print "gx_Norm[x] = ", gx.getVal(nset)
# Create object representing integral over gx
# which is used to calculate gx_Norm[x] == gx / gx_Int[x]
igx = gx.createIntegral(ROOT.RooArgSet(x))
print "gx_Int[x] = ", igx.getVal()
# I n t e g r a t e n o r m a l i z e d p d f o v e r s u b r a n g e
# ----------------------------------------------------------------------------
# Define a range named "signal" in x from -5,5
x.setRange("signal", -5, 5)
# Create an integral of gx_Norm[x] over x in range "signal"
# ROOT.This is the fraction of of p.d.f. gx_Norm[x] which is in the
# range named "signal"
igx_sig = gx.createIntegral(ROOT.RooArgSet(x), ROOT.RooFit.NormSet(
ROOT.RooArgSet(x)), ROOT.RooFit.Range("signal"))
print "gx_Int[x|signal]_Norm[x] = ", igx_sig.getVal()
# C o n s t r u c t c u m u l a t i v e d i s t r i b u t i o n f u n c t i o n f r o m p d f
# -----------------------------------------------------------------------------------------------------
# Create the cumulative distribution function of gx
# i.e. calculate Int[-10,x] gx(x') dx'
gx_cdf = gx.createCdf(ROOT.RooArgSet(x))
# Plot cdf of gx versus x
frame = x.frame(ROOT.RooFit.Title("c.d.f of Gaussian p.d.f"))
gx_cdf.plotOn(frame)
# Draw plot on canvas
c = ROOT.TCanvas("rf110_normintegration",
"rf110_normintegration", 600, 600)
ROOT.gPad.SetLeftMargin(0.15)
frame.GetYaxis().SetTitleOffset(1.6)
frame.Draw()
c.SaveAs("rf110_normintegration.png")
if __name__ == "__main__":
rf110_normintegration()