Rf 1 0 5_Funcbinding¶

'BASIC FUNCTIONALITY' RooFit tutorial macro #105 Demonstration of binding ROOT Math functions as RooFit functions and pdfs

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

In [ ]:
import ROOT

Bind ROOT TMath::Erf C function¶

Bind one-dimensional ROOT.TMath.Erf function as ROOT.RooAbsReal function Directly trying this in python doesn't work: x = ROOT.RooRealVar("x", "x", -3, 3) erf = ROOT.RooFit.bindFunction("erf", ROOT.TMath.Erf, x) Need to go through C interface

In [ ]:
ROOT.gInterpreter.ProcessLine(
'auto x = RooRealVar("x", "x", -3, 3); auto myerf = RooFit::bindFunction("erf", TMath::Erf, x)'
)
x = ROOT.x
erf = ROOT.myerf

Print erf definition

In [ ]:
erf.Print()

Plot erf on frame

In [ ]:
frame1 = x.frame(Title="TMath.Erf bound as ROOT.RooFit function")
erf.plotOn(frame1)

Bind ROOT::Math::beta_pdf C function¶

Bind pdf ROOT.Math.Beta with three variables as ROOT.RooAbsPdf function As above, this does not work directly in python x2 = ROOT.RooRealVar("x2", "x2", 0, 0.999) a = ROOT.RooRealVar("a", "a", 5, 0, 10) b = ROOT.RooRealVar("b", "b", 2, 0, 10) beta = ROOT.RooFit.bindPdf("beta", ROOT.Math.beta_pdf, x2, a, b)

In [ ]:
ROOT.gInterpreter.ProcessLine(
'auto x2 = RooRealVar("x2", "x2", 0, 0.999);\
auto a = RooRealVar("a", "a", 5, 0, 10);\
auto b = RooRealVar("b", "b", 5, 0, 10);\
auto beta = RooFit::bindPdf("beta", ROOT::Math::beta_pdf, x2, a, b)'
)
x2 = ROOT.x2
a = ROOT.a
b = ROOT.b
beta = ROOT.beta

Perf beta definition

In [ ]:
beta.Print()

Generate some events and fit

In [ ]:
data = beta.generate({x2}, 10000)
beta.fitTo(data)

Plot data and pdf on frame

In [ ]:
frame2 = x2.frame(Title="ROOT.Math.Beta bound as ROOT.RooFit pdf")
data.plotOn(frame2)
beta.plotOn(frame2)

Bind ROOT TF1 as RooFit function¶

Create a ROOT TF1 function

In [ ]:
fa1 = ROOT.TF1("fa1", "sin(x)/x", 0, 10)

Create an observable

In [ ]:
x3 = ROOT.RooRealVar("x3", "x3", 0.01, 20)

Create binding of TF1 object to above observable

In [ ]:
rfa1 = ROOT.RooFit.bindFunction(fa1, x3)

Print rfa1 definition

In [ ]:
rfa1.Print()

Make plot frame in observable, TF1 binding function

In [ ]:
frame3 = x3.frame(Title="TF1 bound as ROOT.RooFit function")
rfa1.plotOn(frame3)

c = ROOT.TCanvas("rf105_funcbinding", "rf105_funcbinding", 1200, 400)
c.Divide(3)
c.cd(1)
frame1.GetYaxis().SetTitleOffset(1.6)
frame1.Draw()
c.cd(2)
frame2.GetYaxis().SetTitleOffset(1.6)
frame2.Draw()
c.cd(3)