import ROOT
x = ROOT.RooRealVar("x", "x", -20, 20)
alpha = ROOT.RooRealVar("alpha", "alpha", 5, 0.1, 10)
genpdf = ROOT.RooGenericPdf(
"genpdf",
"genpdf",
"(1+0.1*abs(x)+sin(sqrt(abs(x*alpha+0.1))))",
ROOT.RooArgList(
x,
alpha))
data = genpdf.generate(ROOT.RooArgSet(x), 10000)
genpdf.fitTo(data)
xframe = x.frame(ROOT.RooFit.Title("Interpreted expression pdf"))
data.plotOn(xframe)
genpdf.plotOn(xframe)
mean2 = ROOT.RooRealVar("mean2", "mean^2", 10, 0, 200)
sigma = ROOT.RooRealVar("sigma", "sigma", 3, 0.1, 10)
mean = ROOT.RooFormulaVar(
"mean", "mean", "sqrt(mean2)", ROOT.RooArgList(mean2))
g2 = ROOT.RooGaussian("g2", "h2", x, mean, sigma)
g1 = ROOT.RooGaussian("g1", "g1", x, ROOT.RooFit.RooConst(
10), ROOT.RooFit.RooConst(3))
data2 = g1.generate(ROOT.RooArgSet(x), 1000)
r = g2.fitTo(data2, ROOT.RooFit.Save())
r.Print()
xframe2 = x.frame(ROOT.RooFit.Title("Tailored Gaussian pdf"))
data2.plotOn(xframe2)
g2.plotOn(xframe2)
c = ROOT.TCanvas("rf103_interprfuncs", "rf103_interprfuncs", 800, 400)
c.Divide(2)
c.cd(1)
ROOT.gPad.SetLeftMargin(0.15)
xframe.GetYaxis().SetTitleOffset(1.4)
xframe.Draw()
c.cd(2)
ROOT.gPad.SetLeftMargin(0.15)
xframe2.GetYaxis().SetTitleOffset(1.4)
xframe2.Draw()
c.SaveAs("rf103_interprfuncs.png")