import ROOT
x = ROOT.RooRealVar("x", "x", -10, 10)
y = ROOT.RooRealVar("y", "y", -10, 10)
mx = ROOT.RooRealVar("mx", "mx", 1, -10, 10)
my = ROOT.RooRealVar("my", "my", 1, -10, 10)
gx = ROOT.RooGaussian("gx", "gx", x, mx, ROOT.RooFit.RooConst(1))
gy = ROOT.RooGaussian("gy", "gy", y, my, ROOT.RooFit.RooConst(1))
sig = ROOT.RooProdPdf("sig", "sig", gx, gy)
px = ROOT.RooPolynomial("px", "px", x)
py = ROOT.RooPolynomial("py", "py", y)
bkg = ROOT.RooProdPdf("bkg", "bkg", px, py)
f = ROOT.RooRealVar("f", "f", 0.0, 1.0)
model = ROOT.RooAddPdf("model", "model", [sig, bkg], [f])
modelData = model.generate({x, y}, 10000)
x.setRange("SB1", -10, +10)
y.setRange("SB1", -10, 0)
x.setRange("SB2", -10, 0)
y.setRange("SB2", 0, +10)
x.setRange("SIG", 0, +10)
y.setRange("SIG", 0, +10)
x.setRange("FULL", -10, +10)
y.setRange("FULL", -10, +10)
r_sb1 = model.fitTo(modelData, Range="SB1", Save=True)
r_sb2 = model.fitTo(modelData, Range="SB2", Save=True)
r_sb12 = model.fitTo(modelData, Range="SB1,SB2", Save=True)
r_sb1.Print()
r_sb2.Print()
r_sb12.Print()