import ROOT
x = ROOT.RooRealVar("x", "x", -10, 10)
a = ROOT.RooRealVar("a", "a", 0.4, 0, 1)
b = ROOT.RooRealVar("b", "b", 5)
c = ROOT.RooRealVar("c", "c", -1, -10, 10)
effFunc = ROOT.RooFormulaVar("effFunc", "(1-a)+a*cos((x-c)/b)", [a, b, c, x])
cut = ROOT.RooCategory("cut", "cutr", {"accept": 1, "reject": 0})
effPdf = ROOT.RooEfficiency("effPdf", "effPdf", effFunc, cut, "accept")
shapePdf = ROOT.RooPolynomial("shapePdf", "shapePdf", x, [-0.095])
model = ROOT.RooProdPdf("model", "model", {shapePdf}, Conditional=({effPdf}, {cut}))
data = model.generate({x, cut}, 10000)
effPdf.fitTo(data, ConditionalObservables={x}, PrintLevel=-1)
frame1 = x.frame(Bins=20, Title="Data (all, accepted)")
data.plotOn(frame1)
data.plotOn(frame1, Cut="cut==cut::accept", MarkerColor="r", LineColor="r")
frame2 = x.frame(Bins=20, Title="Fitted efficiency")
data.plotOn(frame2, Efficiency=cut)
effFunc.plotOn(frame2, LineColor="r")
ca = ROOT.TCanvas("rf701_efficiency", "rf701_efficiency", 800, 400)
ca.Divide(2)
ca.cd(1)
ROOT.gPad.SetLeftMargin(0.15)
frame1.GetYaxis().SetTitleOffset(1.6)
frame1.Draw()
ca.cd(2)
ROOT.gPad.SetLeftMargin(0.15)
frame2.GetYaxis().SetTitleOffset(1.4)
frame2.Draw()
ca.SaveAs("rf701_efficiencyfit.png")
[#1] INFO:Fitting -- RooAbsPdf::fitTo(effPdf_over_effPdf_Int[cut]) fixing normalization set for coefficient determination to observables in data
[#1] INFO:Fitting -- using CPU computation library compiled with -mavx2
[#1] INFO:Fitting -- RooAddition::defaultErrorLevel(nll_effPdf_over_effPdf_Int[cut]_modelData) Summation contains a RooNLLVar, using its error level
[#1] INFO:Minimization -- RooAbsMinimizerFcn::setOptimizeConst: activating const optimization
[#1] INFO:Minimization -- RooAbsMinimizerFcn::setOptimizeConst: deactivating const optimization
[#1] INFO:Plotting -- RooTreeData::plotOn: plotting 8176 events out of 10000 total events