Basic functionality: examples on normalization and integration of pdfs, construction of cumulative distribution functions from monodimensional pdfs
Author: Clemens Lange, Wouter Verkerke (C++ version)
This notebook tutorial was automatically generated with ROOTBOOK-izer from the macro found in the ROOT repository on Tuesday, March 19, 2024 at 07:15 PM.
from __future__ import print_function
import ROOT
Create observables x,y
x = ROOT.RooRealVar("x", "x", -10, 10)
Create pdf gaussx(x,-2,3)
gx = ROOT.RooGaussian("gx", "gx", x, -2, 3)
Return 'raw' unnormalized value of gx
print("gx = ", gx.getVal())
gx = 0.8007374029168081
Return value of gx normalized over x in range [-10,10]
nset = {x}
print("gx_Norm[x] = ", gx.getVal(nset))
gx_Norm[x] = 0.1068955044839622
Create object representing integral over gx which is used to calculate gx_Norm[x] == gx / gx_Int[x]
igx = gx.createIntegral({x})
print("gx_Int[x] = ", igx.getVal())
gx_Int[x] = 7.490842639102233
Define a range named "signal" in x from -5,5
x.setRange("signal", -5, 5)
[#1] INFO:Eval -- RooRealVar::setRange(x) new range named 'signal' created with bounds [-5,5]
Create an integral of gx_Norm[x] over x in range "signal" ROOT.This is the fraction of of pdf gx_Norm[x] which is in the range named "signal"
xset = {x}
igx_sig = gx.createIntegral(xset, NormSet=xset, Range="signal")
print("gx_Int[x|signal]_Norm[x] = ", igx_sig.getVal())
gx_Int[x|signal]_Norm[x] = 0.8347532778470285
Create the cumulative distribution function of gx i.e. calculate Int[-10,x] gx(x') dx'
gx_cdf = gx.createCdf({x})
Plot cdf of gx versus x
frame = x.frame(Title="cdf of Gaussian pdf")
gx_cdf.plotOn(frame)
<cppyy.gbl.RooPlot object at 0x9f70990>
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")
Info in <TCanvas::Print>: png file rf110_normintegration.png has been created
Draw all canvases
from ROOT import gROOT
gROOT.GetListOfCanvases().Draw()