import ROOT
x = ROOT.RooRealVar("x", "x", -10, 10)
mean = ROOT.RooRealVar("mean", "mean", -3, 3)
sigma = ROOT.RooRealVar("sigma", "sigma", 0.5, 0.1, 10)
modelx = ROOT.RooGaussian("gx", "gx", x, mean, sigma)
a = ROOT.RooRealVar("a", "a", 2, 1, 10)
model_mean = ROOT.RooGenericPdf("model_mean", "abs(mean)<a", [mean, a])
x.setBins(1000, "cache")
mean.setBins(50, "cache")
model = ROOT.RooFFTConvPdf("model", "model", mean, modelx, model_mean)
model.setCacheObservables({x})
model.setBufferFraction(1.0)
projModel = model.createProjection({mean})
d = projModel.generateBinned({x}, 1000)
projModel.fitTo(d, Verbose=True)
frame = x.frame(Bins=25)
d.plotOn(frame)
projModel.plotOn(frame)
hh = model.createHistogram(
"hh",
x,
Binning=50,
YVar=dict(var=mean, Binning=50),
ConditionalObservables={mean},
)
hh.SetTitle("histogram of model(x|mean)")
hh.SetLineColor(ROOT.kBlue)
c = ROOT.TCanvas("rf211_paramconv", "rf211_paramconv", 800, 400)
c.Divide(2)
c.cd(1)
ROOT.gPad.SetLeftMargin(0.15)
frame.GetYaxis().SetTitleOffset(1.4)
frame.Draw()
c.cd(2)
ROOT.gPad.SetLeftMargin(0.20)
hh.GetZaxis().SetTitleOffset(2.5)
hh.Draw("surf")
c.SaveAs("rf211_paramconv.png")