Rf 3 1 2_Multirangefit

Multidimensional models: performing fits in multiple (disjoint) ranges in one or more dimensions

Author: Wouter Verkerke
This notebook tutorial was automatically generated with ROOTBOOK-izer from the macro found in the ROOT repository on Monday, January 17, 2022 at 10:00 AM.

In [1]:
%%cpp -d
#include "RooRealVar.h"
#include "RooDataSet.h"
#include "RooGaussian.h"
#include "RooConstVar.h"
#include "RooProdPdf.h"
#include "RooAddPdf.h"
#include "RooPolynomial.h"
#include "TCanvas.h"
#include "TAxis.h"
#include "RooPlot.h"
#include "RooFitResult.h"
In [2]:
%%cpp -d
// This is a workaround to make sure the namespace is used inside functions
using namespace RooFit;

Create 2d pdf and data

Define observables x,y

In [3]:
RooRealVar x("x", "x", -10, 10);
RooRealVar y("y", "y", -10, 10);
RooFit v3.60 -- Developed by Wouter Verkerke and David Kirkby 
                Copyright (C) 2000-2013 NIKHEF, University of California & Stanford University
                All rights reserved, please read http://roofit.sourceforge.net/license.txt

Construct the signal pdf gauss(x)*gauss(y)

In [4]:
RooRealVar mx("mx", "mx", 1, -10, 10);
RooRealVar my("my", "my", 1, -10, 10);

RooGaussian gx("gx", "gx", x, mx, RooConst(1));
RooGaussian gy("gy", "gy", y, my, RooConst(1));

RooProdPdf sig("sig", "sig", gx, gy);

Construct the background pdf (flat in x,y)

In [5]:
RooPolynomial px("px", "px", x);
RooPolynomial py("py", "py", y);
RooProdPdf bkg("bkg", "bkg", px, py);

Construct the composite model sig+bkg

In [6]:
RooRealVar f("f", "f", 0., 1.);
RooAddPdf model("model", "model", RooArgList(sig, bkg), f);

Sample 10000 events in (x,y) from the model

In [7]:
RooDataSet *modelData = model.generate(RooArgSet(x, y), 10000);

Define signal and sideband regions

Construct the sideband1,sideband2,signal regions

                |
  +-------------+-----------+
  |             |           |
  |    Side     |   Sig     |
  |    Band1    |   nal     |
  |             |           |
--+-------------+-----------+--
  |                         |
  |           Side          |
  |           Band2         |
  |                         |
  +-------------+-----------+
                |
In [8]:
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);
[#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]

Perform fits in individual sideband regions

Perform fit in sideband1 region (rooaddpdf coefficients will be interpreted in full range)

In [9]:
RooFitResult *r_sb1 = model.fitTo(*modelData, Range("SB1"), Save());
[#1] INFO:Fitting -- RooAbsOptTestStatistic::ctor(nll_model_modelData) constructing test statistic for sub-range named SB1
[#1] INFO:Eval -- RooRealVar::setRange(x) new range named 'NormalizationRangeForSB1' 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 'NormalizationRangeForSB1' 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) fixing interpretation of coefficients of any RooAddPdf to full domain of observables 
[#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 **SET PRINT           1
 **********
 **********
 **    2 **SET NOGRAD
 **********
 PARAMETER DEFINITIONS:
    NO.   NAME         VALUE      STEP SIZE      LIMITS
     1 f            5.00000e-01  1.00000e-01    0.00000e+00  1.00000e+00
     2 mx           1.00000e+00  2.00000e+00   -1.00000e+01  1.00000e+01
     3 my           1.00000e+00  2.00000e+00   -1.00000e+01  1.00000e+01
 **********
 **    3 **SET ERR         0.5
 **********
 **********
 **    4 **SET PRINT           1
 **********
 **********
 **    5 **SET STR           1
 **********
 NOW USING STRATEGY  1: TRY TO BALANCE SPEED AGAINST RELIABILITY
 **********
 **    6 **MIGRAD        1500           1
 **********
 FIRST CALL TO USER FUNCTION AT NEW START POINT, WITH IFLAG=4.
 START MIGRAD MINIMIZATION.  STRATEGY  1.  CONVERGENCE WHEN EDM .LT. 1.00e-03
 FCN=16262.2 FROM MIGRAD    STATUS=INITIATE       12 CALLS          13 TOTAL
                     EDM= unknown      STRATEGY= 1      NO ERROR MATRIX       
  EXT PARAMETER               CURRENT GUESS       STEP         FIRST   
  NO.   NAME      VALUE            ERROR          SIZE      DERIVATIVE 
   1  f            5.00000e-01   1.00000e-01   2.01358e-01  -5.77275e+01
   2  mx           1.00000e+00   2.00000e+00   2.02430e-01   7.82209e+01
   3  my           1.00000e+00   2.00000e+00   2.02430e-01   4.26863e+02
                               ERR DEF= 0.5
 MIGRAD MINIMIZATION HAS CONVERGED.
 MIGRAD WILL VERIFY CONVERGENCE AND ERROR MATRIX.
 COVARIANCE MATRIX CALCULATED SUCCESSFULLY
 FCN=16261.4 FROM MIGRAD    STATUS=CONVERGED      65 CALLS          66 TOTAL
                     EDM=6.58779e-08    STRATEGY= 1      ERROR MATRIX ACCURATE 
  EXT PARAMETER                                   STEP         FIRST   
  NO.   NAME      VALUE            ERROR          SIZE      DERIVATIVE 
   1  f            5.11324e-01   3.57757e-02   1.91429e-03  -3.36872e-03
   2  mx           9.87405e-01   4.03232e-02   3.56822e-04   2.97325e-02
   3  my           9.92960e-01   9.38758e-02   2.52190e-04   1.62080e-03
                               ERR DEF= 0.5
 EXTERNAL ERROR MATRIX.    NDIM=  25    NPAR=  3    ERR DEF=0.5
  1.282e-03  1.633e-06  3.203e-03 
  1.633e-06  1.626e-03 -2.189e-06 
  3.203e-03 -2.189e-06  8.813e-03 
 PARAMETER  CORRELATION COEFFICIENTS  
       NO.  GLOBAL      1      2      3
        1  0.95284   1.000  0.001  0.953
        2  0.00557   0.001  1.000 -0.001
        3  0.95284   0.953 -0.001  1.000
 **********
 **    7 **SET ERR         0.5
 **********
 **********
 **    8 **SET PRINT           1
 **********
 **********
 **    9 **HESSE        1500
 **********
 COVARIANCE MATRIX CALCULATED SUCCESSFULLY
 FCN=16261.4 FROM HESSE     STATUS=OK             16 CALLS          82 TOTAL
                     EDM=6.53294e-08    STRATEGY= 1      ERROR MATRIX ACCURATE 
  EXT PARAMETER                                INTERNAL      INTERNAL  
  NO.   NAME      VALUE            ERROR       STEP SIZE       VALUE   
   1  f            5.11324e-01   3.55416e-02   7.65715e-05   2.26501e-02
   2  mx           9.87405e-01   4.03233e-02   7.13643e-05   9.89017e-02
   3  my           9.92960e-01   9.32603e-02   1.00876e-05   9.94599e-02
                               ERR DEF= 0.5
 EXTERNAL ERROR MATRIX.    NDIM=  25    NPAR=  3    ERR DEF=0.5
  1.265e-03  1.698e-06  3.159e-03 
  1.698e-06  1.626e-03 -2.338e-06 
  3.159e-03 -2.338e-06  8.698e-03 
 PARAMETER  CORRELATION COEFFICIENTS  
       NO.  GLOBAL      1      2      3
        1  0.95220   1.000  0.001  0.952
        2  0.00585   0.001  1.000 -0.001
        3  0.95220   0.952 -0.001  1.000
[#1] INFO:Minimization -- RooAbsMinimizerFcn::setOptimizeConst: deactivating const optimization

Perform fit in sideband2 region (rooaddpdf coefficients will be interpreted in full range)

In [10]:
RooFitResult *r_sb2 = model.fitTo(*modelData, Range("SB2"), Save());
[#1] INFO:Fitting -- RooAbsOptTestStatistic::ctor(nll_model_modelData) constructing test statistic for sub-range named SB2
[#1] INFO:Eval -- RooRealVar::setRange(x) new range named 'NormalizationRangeForSB2' created with bounds [-10,10]
[#1] INFO:Eval -- RooRealVar::setRange(y) new range named 'NormalizationRangeForSB2' created with bounds [-10,10]
[#1] INFO:Fitting -- RooAbsOptTestStatistic::ctor(nll_model_modelData) fixing interpretation of coefficients of any RooAddPdf to full domain of observables 
[#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)
 **********
 **   10 **SET PRINT           1
 **********
 **********
 **   11 **SET NOGRAD
 **********
 PARAMETER DEFINITIONS:
    NO.   NAME         VALUE      STEP SIZE      LIMITS
     1 f            5.11324e-01  3.55416e-02    0.00000e+00  1.00000e+00
     2 mx           9.87405e-01  4.03233e-02   -1.00000e+01  1.00000e+01
     3 my           9.92960e-01  9.32603e-02   -1.00000e+01  1.00000e+01
 **********
 **   12 **SET ERR         0.5
 **********
 **********
 **   13 **SET PRINT           1
 **********
 **********
 **   14 **SET STR           1
 **********
 NOW USING STRATEGY  1: TRY TO BALANCE SPEED AGAINST RELIABILITY
 **********
 **   15 **MIGRAD        1500           1
 **********
 FIRST CALL TO USER FUNCTION AT NEW START POINT, WITH IFLAG=4.
 START MIGRAD MINIMIZATION.  STRATEGY  1.  CONVERGENCE WHEN EDM .LT. 1.00e-03
 FCN=7580.37 FROM MIGRAD    STATUS=INITIATE       10 CALLS          11 TOTAL
                     EDM= unknown      STRATEGY= 1      NO ERROR MATRIX       
  EXT PARAMETER               CURRENT GUESS       STEP         FIRST   
  NO.   NAME      VALUE            ERROR          SIZE      DERIVATIVE 
   1  f            5.11324e-01   3.55416e-02   7.11616e-02   5.76142e+01
   2  mx           9.87405e-01   4.03233e-02   4.05214e-03  -5.36255e+02
   3  my           9.92960e-01   9.32603e-02   9.37249e-03   1.50798e+02
                               ERR DEF= 0.5
 MIGRAD MINIMIZATION HAS CONVERGED.
 MIGRAD WILL VERIFY CONVERGENCE AND ERROR MATRIX.
 COVARIANCE MATRIX CALCULATED SUCCESSFULLY
 FCN=7578.28 FROM MIGRAD    STATUS=CONVERGED      58 CALLS          59 TOTAL
                     EDM=5.99393e-06    STRATEGY= 1      ERROR MATRIX ACCURATE 
  EXT PARAMETER                                   STEP         FIRST   
  NO.   NAME      VALUE            ERROR          SIZE      DERIVATIVE 
   1  f            5.45866e-01   4.48627e-02   1.58044e-03   2.70551e-02
   2  mx           1.12762e+00   1.10647e-01   1.95873e-04  -3.91797e-01
   3  my           9.64618e-01   5.59523e-02   3.27587e-04   2.27176e-01
                               ERR DEF= 0.5
 EXTERNAL ERROR MATRIX.    NDIM=  25    NPAR=  3    ERR DEF=0.5
  2.018e-03  4.741e-03 -2.496e-04 
  4.741e-03  1.224e-02 -1.695e-04 
 -2.496e-04 -1.695e-04  3.131e-03 
 PARAMETER  CORRELATION COEFFICIENTS  
       NO.  GLOBAL      1      2      3
        1  0.95665   1.000  0.954 -0.099
        2  0.95624   0.954  1.000 -0.027
        3  0.24521  -0.099 -0.027  1.000
 **********
 **   16 **SET ERR         0.5
 **********
 **********
 **   17 **SET PRINT           1
 **********
 **********
 **   18 **HESSE        1500
 **********
 COVARIANCE MATRIX CALCULATED SUCCESSFULLY
 FCN=7578.28 FROM HESSE     STATUS=OK             16 CALLS          75 TOTAL
                     EDM=5.96577e-06    STRATEGY= 1      ERROR MATRIX ACCURATE 
  EXT PARAMETER                                INTERNAL      INTERNAL  
  NO.   NAME      VALUE            ERROR       STEP SIZE       VALUE   
   1  f            5.45866e-01   4.46434e-02   3.16088e-04   9.18610e-02
   2  mx           1.12762e+00   1.10110e-01   3.91746e-05   1.13002e-01
   3  my           9.64618e-01   5.59522e-02   6.55175e-05   9.66120e-02
                               ERR DEF= 0.5
 EXTERNAL ERROR MATRIX.    NDIM=  25    NPAR=  3    ERR DEF=0.5
  1.998e-03  4.693e-03 -2.465e-04 
  4.693e-03  1.212e-02 -1.613e-04 
 -2.465e-04 -1.613e-04  3.131e-03 
 PARAMETER  CORRELATION COEFFICIENTS  
       NO.  GLOBAL      1      2      3
        1  0.95621   1.000  0.953 -0.099
        2  0.95580   0.953  1.000 -0.026
        3  0.24520  -0.099 -0.026  1.000
[#1] INFO:Minimization -- RooAbsMinimizerFcn::setOptimizeConst: deactivating const optimization

Perform fits in joint sideband regions

Now perform fit to joint 'l-shaped' sideband region 'sb1|sb2' (RooAddPdf coefficients will be interpreted in full range)

In [11]:
RooFitResult *r_sb12 = model.fitTo(*modelData, Range("SB1,SB2"), Save());
[#1] INFO:Fitting -- RooAbsOptTestStatistic::ctor(nll_model_modelData_SB1) constructing test statistic for sub-range named SB1
[#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:Fitting -- RooAbsOptTestStatistic::ctor(nll_model_modelData_SB1) fixing interpretation of coefficients of any RooAddPdf to full domain of observables 
[#1] INFO:Fitting -- RooAbsOptTestStatistic::ctor(nll_model_modelData_SB2) constructing test statistic for sub-range named SB2
[#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_SB2) fixing interpretation of coefficients of any RooAddPdf to full domain of observables 
[#1] INFO:InputArguments -- The formula select claims to use the variables (x,y) but only () seem to be in use.
  inputs:         1
[#1] INFO:InputArguments -- The formula select claims to use the variables (x,y) but only () seem to be in use.
  inputs:         1
[#1] INFO:Fitting -- RooAddition::defaultErrorLevel(nll_model_modelData) Summation contains a RooNLLVar, using its error level
[#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 --  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)
 **********
 **   19 **SET PRINT           1
 **********
 **********
 **   20 **SET NOGRAD
 **********
 PARAMETER DEFINITIONS:
    NO.   NAME         VALUE      STEP SIZE      LIMITS
     1 f            5.45866e-01  4.46434e-02    0.00000e+00  1.00000e+00
     2 mx           1.12762e+00  1.10110e-01   -1.00000e+01  1.00000e+01
     3 my           9.64618e-01  5.59522e-02   -1.00000e+01  1.00000e+01
 **********
 **   21 **SET ERR         0.5
 **********
 **********
 **   22 **SET PRINT           1
 **********
 **********
 **   23 **SET STR           1
 **********
 NOW USING STRATEGY  1: TRY TO BALANCE SPEED AGAINST RELIABILITY
 **********
 **   24 **MIGRAD        1500           1
 **********
 FIRST CALL TO USER FUNCTION AT NEW START POINT, WITH IFLAG=4.
 START MIGRAD MINIMIZATION.  STRATEGY  1.  CONVERGENCE WHEN EDM .LT. 1.00e-03
 FCN=27267.9 FROM MIGRAD    STATUS=INITIATE       12 CALLS          13 TOTAL
                     EDM= unknown      STRATEGY= 1      NO ERROR MATRIX       
  EXT PARAMETER               CURRENT GUESS       STEP         FIRST   
  NO.   NAME      VALUE            ERROR          SIZE      DERIVATIVE 
   1  f            5.45866e-01   4.46434e-02   8.97886e-02   1.97712e+02
   2  mx           1.12762e+00   1.10110e-01   1.10819e-02   1.15163e+03
   3  my           9.64618e-01   5.59522e-02   5.62146e-03  -1.74029e+03
                               ERR DEF= 0.5
 MIGRAD MINIMIZATION HAS CONVERGED.
 MIGRAD WILL VERIFY CONVERGENCE AND ERROR MATRIX.
 COVARIANCE MATRIX CALCULATED SUCCESSFULLY
 FCN=27252.6 FROM MIGRAD    STATUS=CONVERGED      61 CALLS          62 TOTAL
                     EDM=4.50567e-06    STRATEGY= 1      ERROR MATRIX ACCURATE 
  EXT PARAMETER                                   STEP         FIRST   
  NO.   NAME      VALUE            ERROR          SIZE      DERIVATIVE 
   1  f            5.00817e-01   1.28637e-02   1.90048e-03   3.39326e-02
   2  mx           1.00996e+00   3.26250e-02   2.68988e-04  -8.24741e-01
   3  my           9.63478e-01   3.30502e-02   2.68810e-04   5.27050e-01
                               ERR DEF= 0.5
 EXTERNAL ERROR MATRIX.    NDIM=  25    NPAR=  3    ERR DEF=0.5
  1.655e-04  2.824e-04  2.906e-04 
  2.824e-04  1.064e-03  6.316e-04 
  2.906e-04  6.316e-04  1.092e-03 
 PARAMETER  CORRELATION COEFFICIENTS  
       NO.  GLOBAL      1      2      3
        1  0.76162   1.000  0.673  0.683
        2  0.69460   0.673  1.000  0.586
        3  0.70423   0.683  0.586  1.000
 **********
 **   25 **SET ERR         0.5
 **********
 **********
 **   26 **SET PRINT           1
 **********
 **********
 **   27 **HESSE        1500
 **********
 COVARIANCE MATRIX CALCULATED SUCCESSFULLY
 FCN=27252.6 FROM HESSE     STATUS=OK             16 CALLS          78 TOTAL
                     EDM=4.50477e-06    STRATEGY= 1      ERROR MATRIX ACCURATE 
  EXT PARAMETER                                INTERNAL      INTERNAL  
  NO.   NAME      VALUE            ERROR       STEP SIZE       VALUE   
   1  f            5.00817e-01   1.28678e-02   7.60193e-05   1.63302e-03
   2  mx           1.00996e+00   3.26365e-02   5.37976e-05   1.01169e-01
   3  my           9.63478e-01   3.30609e-02   5.37620e-05   9.64975e-02
                               ERR DEF= 0.5
 EXTERNAL ERROR MATRIX.    NDIM=  25    NPAR=  3    ERR DEF=0.5
  1.656e-04  2.827e-04  2.908e-04 
  2.827e-04  1.065e-03  6.324e-04 
  2.908e-04  6.324e-04  1.093e-03 
 PARAMETER  CORRELATION COEFFICIENTS  
       NO.  GLOBAL      1      2      3
        1  0.76180   1.000  0.673  0.684
        2  0.69486   0.673  1.000  0.586
        3  0.70447   0.684  0.586  1.000
[#1] INFO:Minimization -- RooAbsMinimizerFcn::setOptimizeConst: deactivating const optimization

Print results for comparison

In [12]:
r_sb1->Print();
r_sb2->Print();
r_sb12->Print();
  RooFitResult: minimized FCN value: 16261.4, estimated distance to minimum: 6.53294e-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