Multidimensional models: performing fits in multiple (disjoint) ranges in one or more dimensions 
 
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, PrintLevel=-1)
 
r_sb2 = model.fitTo(modelData, Range="SB2", Save=True, PrintLevel=-1)
 
 
r_sb12 = model.fitTo(modelData, Range="SB1,SB2", Save=True, PrintLevel=-1)
 
r_sb1.Print()
r_sb2.Print()
r_sb12.Print()
  [#1] INFO:Eval -- RooRealVar::setRange(x) new range named 'SB1' created with bounds [-10,10]
[#1] INFO:Eval -- RooRealVar::setRange(y) new range named 'SB1' created with bounds [-10,0]
[#1] INFO:Eval -- RooRealVar::setRange(x) new range named 'SB2' created with bounds [-10,0]
[#1] INFO:Eval -- RooRealVar::setRange(y) new range named 'SB2' created with bounds [0,10]
[#1] INFO:Eval -- RooRealVar::setRange(x) new range named 'SIG' created with bounds [0,10]
[#1] INFO:Eval -- RooRealVar::setRange(y) new range named 'SIG' created with bounds [0,10]
[#1] INFO:Eval -- RooRealVar::setRange(x) new range named 'FULL' created with bounds [-10,10]
[#1] INFO:Eval -- RooRealVar::setRange(y) new range named 'FULL' created with bounds [-10,10]
[#1] INFO:Eval -- RooRealVar::setRange(x) new range named 'fit_nll_model_modelData' created with bounds [-10,10]
[#1] INFO:Eval -- RooRealVar::setRange(y) new range named 'fit_nll_model_modelData' created with bounds [-10,0]
[#1] INFO:Fitting -- RooAbsOptTestStatistic::ctor(nll_model_modelData) constructing test statistic for sub-range named SB1
[#1] INFO:Minimization -- RooAbsMinimizerFcn::setOptimizeConst: activating const optimization
[#1] INFO:Minimization --  The following expressions have been identified as constant and will be precalculated and cached: (bkg)
[#1] INFO:Minimization --  The following expressions will be evaluated in cache-and-track mode: (gx,gy)
[#1] INFO:Minimization -- RooAbsMinimizerFcn::setOptimizeConst: deactivating const optimization
[#1] INFO:Fitting -- RooAbsOptTestStatistic::ctor(nll_model_modelData) constructing test statistic for sub-range named SB2
[#1] INFO:Minimization -- RooAbsMinimizerFcn::setOptimizeConst: activating const optimization
[#1] INFO:Minimization --  The following expressions have been identified as constant and will be precalculated and cached: (bkg)
[#1] INFO:Minimization --  The following expressions will be evaluated in cache-and-track mode: (gx,gy)
[#1] INFO:Minimization -- RooAbsMinimizerFcn::setOptimizeConst: deactivating const optimization
[#1] INFO:Eval -- RooRealVar::setRange(x) new range named 'fit_nll_model_modelData_SB1' created with bounds [-10,10]
[#1] INFO:Eval -- RooRealVar::setRange(y) new range named 'fit_nll_model_modelData_SB1' created with bounds [-10,0]
[#1] INFO:Eval -- RooRealVar::setRange(x) new range named 'fit_nll_model_modelData_SB2' created with bounds [-10,0]
[#1] INFO:Eval -- RooRealVar::setRange(y) new range named 'fit_nll_model_modelData_SB2' created with bounds [0,10]
[#1] INFO:Fitting -- RooAbsOptTestStatistic::ctor(nll_model_modelData) constructing test statistic for sub-range named SB1,SB2
[#1] INFO:Minimization -- RooAbsMinimizerFcn::setOptimizeConst: activating const optimization
[#1] INFO:Minimization --  The following expressions have been identified as constant and will be precalculated and cached: (bkg)
[#1] INFO:Minimization --  The following expressions will be evaluated in cache-and-track mode: (gx,gy)
[#1] INFO:Minimization -- RooAbsMinimizerFcn::setOptimizeConst: deactivating const optimization
 
  RooFitResult: minimized FCN value: 16261.4, estimated distance to minimum: 6.53276e-08
                covariance matrix quality: Full, accurate covariance matrix
                Status : MINIMIZE=0 HESSE=0 
 
    Floating Parameter    FinalValue +/-  Error   
  --------------------  --------------------------
                     f    5.1132e-01 +/-  3.55e-02
                    mx    9.8741e-01 +/-  4.03e-02
                    my    9.9296e-01 +/-  9.33e-02
 
 
  RooFitResult: minimized FCN value: 7578.28, estimated distance to minimum: 5.96577e-06
                covariance matrix quality: Full, accurate covariance matrix
                Status : MINIMIZE=0 HESSE=0 
 
    Floating Parameter    FinalValue +/-  Error   
  --------------------  --------------------------
                     f    5.4587e-01 +/-  4.46e-02
                    mx    1.1276e+00 +/-  1.10e-01
                    my    9.6462e-01 +/-  5.60e-02
 
 
  RooFitResult: minimized FCN value: 27252.6, estimated distance to minimum: 4.50477e-06
                covariance matrix quality: Full, accurate covariance matrix
                Status : MINIMIZE=0 HESSE=0 
 
    Floating Parameter    FinalValue +/-  Error   
  --------------------  --------------------------
                     f    5.0082e-01 +/-  1.29e-02
                    mx    1.0100e+00 +/-  3.26e-02
                    my    9.6348e-01 +/-  3.31e-02
 
- Date
 - February 2018 
 
- Authors
 - Clemens Lange, Wouter Verkerke (C++ version) 
 
Definition in file rf312_multirangefit.py.