Logo ROOT   6.14/05
Reference Guide
rf604_constraints.C File Reference

Detailed Description

View in nbviewer Open in SWAN 'LIKELIHOOD AND MINIMIZATION' RooFit tutorial macro #604

Fitting with constraints

0.0232419967651
3.78628587723
Processing /mnt/build/workspace/root-makedoc-v614/rootspi/rdoc/src/v6-14-00-patches/tutorials/roofit/rf604_constraints.C...
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
[#1] INFO:Minization -- RooMinimizer::optimizeConst: activating const optimization
[#1] INFO:Minization -- The following expressions have been identified as constant and will be precalculated and cached: (poly)
[#1] INFO:Minization -- The following expressions will be evaluated in cache-and-track mode: (gauss)
**********
** 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 m 0.00000e+00 2.00000e+00 -1.00000e+01 1.00000e+01
3 s 2.00000e+00 9.50000e-01 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=136.523 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.00000e-01 1.00000e-01 2.01358e-01 -3.71768e+00
2 m 0.00000e+00 2.00000e+00 2.01358e-01 -2.53753e+01
3 s 2.00000e+00 9.50000e-01 2.51381e-01 -1.22085e+00
ERR DEF= 0.5
MIGRAD MINIMIZATION HAS CONVERGED.
MIGRAD WILL VERIFY CONVERGENCE AND ERROR MATRIX.
COVARIANCE MATRIX CALCULATED SUCCESSFULLY
FCN=134.849 FROM MIGRAD STATUS=CONVERGED 50 CALLS 51 TOTAL
EDM=4.23315e-05 STRATEGY= 1 ERROR MATRIX ACCURATE
EXT PARAMETER STEP FIRST
NO. NAME VALUE ERROR SIZE DERIVATIVE
1 f 6.49867e-01 1.21447e-01 1.78337e-03 -1.77163e-02
2 m 7.18243e-01 4.96576e-01 3.89020e-04 8.83234e-02
3 s 2.18801e+00 4.61197e-01 7.70631e-04 3.46910e-03
ERR DEF= 0.5
EXTERNAL ERROR MATRIX. NDIM= 25 NPAR= 3 ERR DEF=0.5
1.508e-02 -6.689e-03 2.798e-02
-6.689e-03 2.468e-01 -3.900e-02
2.798e-02 -3.900e-02 2.136e-01
PARAMETER CORRELATION COEFFICIENTS
NO. GLOBAL 1 2 3
1 0.49373 1.000 -0.110 0.493
2 0.17244 -0.110 1.000 -0.170
3 0.50660 0.493 -0.170 1.000
**********
** 7 **SET ERR 0.5
**********
**********
** 8 **SET PRINT 1
**********
**********
** 9 **HESSE 1500
**********
COVARIANCE MATRIX CALCULATED SUCCESSFULLY
FCN=134.849 FROM HESSE STATUS=OK 16 CALLS 67 TOTAL
EDM=4.23315e-05 STRATEGY= 1 ERROR MATRIX ACCURATE
EXT PARAMETER INTERNAL INTERNAL
NO. NAME VALUE ERROR STEP SIZE VALUE
1 f 6.49867e-01 1.21452e-01 3.56674e-04 3.04414e-01
2 m 7.18243e-01 4.96642e-01 7.78041e-05 7.18862e-02
3 s 2.18801e+00 4.61289e-01 1.54126e-04 -6.16495e-01
ERR DEF= 0.5
EXTERNAL ERROR MATRIX. NDIM= 25 NPAR= 3 ERR DEF=0.5
1.508e-02 -6.686e-03 2.800e-02
-6.686e-03 2.469e-01 -3.921e-02
2.800e-02 -3.921e-02 2.137e-01
PARAMETER CORRELATION COEFFICIENTS
NO. GLOBAL 1 2 3
1 0.49379 1.000 -0.110 0.493
2 0.17319 -0.110 1.000 -0.171
3 0.50690 0.493 -0.171 1.000
[#1] INFO:Minization -- RooMinimizer::optimizeConst: deactivating const optimization
[#1] INFO:Minization -- Including the following contraint terms in minimization: (fconstraint)
[#1] INFO:Fitting -- RooAddition::defaultErrorLevel(nll_modelc_modelData_with_constr) Summation contains a RooNLLVar, using its error level
[#1] INFO:Minization -- RooMinimizer::optimizeConst: activating const optimization
[#1] INFO:Minization -- The following expressions have been identified as constant and will be precalculated and cached: (poly)
[#1] INFO:Minization -- The following expressions will be evaluated in cache-and-track mode: (gauss)
**********
** 10 **SET PRINT 1
**********
**********
** 11 **SET NOGRAD
**********
PARAMETER DEFINITIONS:
NO. NAME VALUE STEP SIZE LIMITS
1 f 6.49867e-01 1.21452e-01 0.00000e+00 1.00000e+00
2 m 7.18243e-01 4.96642e-01 -1.00000e+01 1.00000e+01
3 s 2.18801e+00 4.61289e-01 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=134.57 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 6.49867e-01 1.21452e-01 2.58356e-01 -7.17922e+00
2 m 7.18243e-01 4.96642e-01 4.98137e-02 8.83296e-02
3 s 2.18801e+00 4.61289e-01 1.14852e-01 3.40490e-03
ERR DEF= 0.5
MIGRAD MINIMIZATION HAS CONVERGED.
MIGRAD WILL VERIFY CONVERGENCE AND ERROR MATRIX.
COVARIANCE MATRIX CALCULATED SUCCESSFULLY
FCN=133.901 FROM MIGRAD STATUS=CONVERGED 49 CALLS 50 TOTAL
EDM=1.19281e-05 STRATEGY= 1 ERROR MATRIX ACCURATE
EXT PARAMETER STEP FIRST
NO. NAME VALUE ERROR SIZE DERIVATIVE
1 f 7.37845e-01 7.53250e-02 1.23810e-03 -1.57311e-02
2 m 6.63502e-01 5.03905e-01 3.96948e-04 3.86989e-02
3 s 2.38847e+00 4.94425e-01 8.49681e-04 1.29931e-03
ERR DEF= 0.5
EXTERNAL ERROR MATRIX. NDIM= 25 NPAR= 3 ERR DEF=0.5
5.730e-03 -4.407e-03 1.626e-02
-4.407e-03 2.541e-01 -4.564e-02
1.626e-02 -4.564e-02 2.456e-01
PARAMETER CORRELATION COEFFICIENTS
NO. GLOBAL 1 2 3
1 0.43507 1.000 -0.115 0.434
2 0.18708 -0.115 1.000 -0.183
3 0.45360 0.434 -0.183 1.000
**********
** 16 **SET ERR 0.5
**********
**********
** 17 **SET PRINT 1
**********
**********
** 18 **HESSE 1500
**********
COVARIANCE MATRIX CALCULATED SUCCESSFULLY
FCN=133.901 FROM HESSE STATUS=OK 16 CALLS 66 TOTAL
EDM=1.19334e-05 STRATEGY= 1 ERROR MATRIX ACCURATE
EXT PARAMETER INTERNAL INTERNAL
NO. NAME VALUE ERROR STEP SIZE VALUE
1 f 7.37845e-01 7.53286e-02 2.47620e-04 4.95747e-01
2 m 6.63502e-01 5.04046e-01 7.93895e-05 6.63990e-02
3 s 2.38847e+00 4.94571e-01 1.69936e-04 -5.67687e-01
ERR DEF= 0.5
EXTERNAL ERROR MATRIX. NDIM= 25 NPAR= 3 ERR DEF=0.5
5.731e-03 -4.424e-03 1.627e-02
-4.424e-03 2.543e-01 -4.605e-02
1.627e-02 -4.605e-02 2.458e-01
PARAMETER CORRELATION COEFFICIENTS
NO. GLOBAL 1 2 3
1 0.43517 1.000 -0.116 0.434
2 0.18852 -0.116 1.000 -0.184
3 0.45412 0.434 -0.184 1.000
[#1] INFO:Minization -- RooMinimizer::optimizeConst: deactivating const optimization
[#1] INFO:Minization -- Including the following contraint terms in minimization: (fconstext)
[#1] INFO:Fitting -- RooAddition::defaultErrorLevel(nll_model_modelData_with_constr) Summation contains a RooNLLVar, using its error level
[#1] INFO:Minization -- RooMinimizer::optimizeConst: activating const optimization
[#1] INFO:Minization -- The following expressions have been identified as constant and will be precalculated and cached: (poly)
[#1] INFO:Minization -- The following expressions will be evaluated in cache-and-track mode: (gauss)
**********
** 19 **SET PRINT 1
**********
**********
** 20 **SET NOGRAD
**********
PARAMETER DEFINITIONS:
NO. NAME VALUE STEP SIZE LIMITS
1 f 7.37845e-01 7.53286e-02 0.00000e+00 1.00000e+00
2 m 6.63502e-01 5.04046e-01 -1.00000e+01 1.00000e+01
3 s 2.38847e+00 4.94571e-01 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=148.171 FROM MIGRAD STATUS=INITIATE 8 CALLS 9 TOTAL
EDM= unknown STRATEGY= 1 NO ERROR MATRIX
EXT PARAMETER CURRENT GUESS STEP FIRST
NO. NAME VALUE ERROR SIZE DERIVATIVE
1 f 7.37845e-01 7.53286e-02 1.72906e-01 2.63727e+01
2 m 6.63502e-01 5.04046e-01 5.05377e-02 3.86969e-02
3 s 2.38847e+00 4.94571e-01 1.19129e-01 1.23471e-03
ERR DEF= 0.5
MIGRAD MINIMIZATION HAS CONVERGED.
MIGRAD WILL VERIFY CONVERGENCE AND ERROR MATRIX.
COVARIANCE MATRIX CALCULATED SUCCESSFULLY
FCN=137.195 FROM MIGRAD STATUS=CONVERGED 53 CALLS 54 TOTAL
EDM=1.42978e-05 STRATEGY= 1 ERROR MATRIX ACCURATE
EXT PARAMETER STEP FIRST
NO. NAME VALUE ERROR SIZE DERIVATIVE
1 f 3.61760e-01 8.15392e-02 1.26267e-03 -9.51465e-03
2 m 7.01307e-01 5.88303e-01 4.68744e-04 -5.20060e-02
3 s 1.70500e+00 4.76397e-01 9.62001e-04 -2.74993e-03
ERR DEF= 0.5
EXTERNAL ERROR MATRIX. NDIM= 25 NPAR= 3 ERR DEF=0.5
6.713e-03 6.048e-03 1.567e-02
6.048e-03 3.465e-01 5.113e-02
1.567e-02 5.113e-02 2.283e-01
PARAMETER CORRELATION COEFFICIENTS
NO. GLOBAL 1 2 3
1 0.40375 1.000 0.125 0.400
2 0.19067 0.125 1.000 0.182
3 0.42161 0.400 0.182 1.000
**********
** 25 **SET ERR 0.5
**********
**********
** 26 **SET PRINT 1
**********
**********
** 27 **HESSE 1500
**********
COVARIANCE MATRIX CALCULATED SUCCESSFULLY
FCN=137.195 FROM HESSE STATUS=OK 16 CALLS 70 TOTAL
EDM=1.4321e-05 STRATEGY= 1 ERROR MATRIX ACCURATE
EXT PARAMETER INTERNAL INTERNAL
NO. NAME VALUE ERROR STEP SIZE VALUE
1 f 3.61760e-01 8.15756e-02 2.52534e-04 -2.80129e-01
2 m 7.01307e-01 5.88447e-01 9.37488e-05 7.01883e-02
3 s 1.70500e+00 4.76649e-01 1.92400e-04 -7.41992e-01
ERR DEF= 0.5
EXTERNAL ERROR MATRIX. NDIM= 25 NPAR= 3 ERR DEF=0.5
6.720e-03 6.102e-03 1.572e-02
6.102e-03 3.467e-01 5.150e-02
1.572e-02 5.150e-02 2.285e-01
PARAMETER CORRELATION COEFFICIENTS
NO. GLOBAL 1 2 3
1 0.40469 1.000 0.126 0.401
2 0.19191 0.126 1.000 0.183
3 0.42266 0.401 0.183 1.000
[#1] INFO:Minization -- RooMinimizer::optimizeConst: deactivating const optimization
fit result without constraint (data generated at f=0.5)
RooFitResult: minimized FCN value: 134.849, estimated distance to minimum: 4.23315e-05
covariance matrix quality: Full, accurate covariance matrix
Status : MINIMIZE=0 HESSE=0
Floating Parameter InitialValue FinalValue +/- Error GblCorr.
-------------------- ------------ -------------------------- --------
f 5.0000e-01 6.4987e-01 +/- 1.21e-01 <none>
m 0.0000e+00 7.1824e-01 +/- 4.97e-01 <none>
s 2.0000e+00 2.1880e+00 +/- 4.61e-01 <none>
fit result with internal constraint (data generated at f=0.5, constraint is f=0.8+/-0.2)
RooFitResult: minimized FCN value: 133.901, estimated distance to minimum: 1.19334e-05
covariance matrix quality: Full, accurate covariance matrix
Status : MINIMIZE=0 HESSE=0
Floating Parameter InitialValue FinalValue +/- Error GblCorr.
-------------------- ------------ -------------------------- --------
f 6.4987e-01 7.3784e-01 +/- 7.53e-02 <none>
m 7.1824e-01 6.6350e-01 +/- 5.04e-01 <none>
s 2.1880e+00 2.3885e+00 +/- 4.95e-01 <none>
fit result with (another) external constraint (data generated at f=0.5, constraint is f=0.2+/-0.1)
RooFitResult: minimized FCN value: 137.195, estimated distance to minimum: 1.4321e-05
covariance matrix quality: Full, accurate covariance matrix
Status : MINIMIZE=0 HESSE=0
Floating Parameter InitialValue FinalValue +/- Error GblCorr.
-------------------- ------------ -------------------------- --------
f 7.3784e-01 3.6176e-01 +/- 8.16e-02 <none>
m 6.6350e-01 7.0131e-01 +/- 5.88e-01 <none>
s 2.3885e+00 1.7050e+00 +/- 4.77e-01 <none>
#include "RooRealVar.h"
#include "RooDataSet.h"
#include "RooGaussian.h"
#include "RooConstVar.h"
#include "RooPolynomial.h"
#include "RooAddPdf.h"
#include "RooProdPdf.h"
#include "RooFitResult.h"
#include "RooPlot.h"
#include "TCanvas.h"
#include "TAxis.h"
#include "TH1.h"
using namespace RooFit ;
void rf604_constraints()
{
// C r e a t e m o d e l a n d d a t a s e t
// ----------------------------------------------
// Construct a Gaussian p.d.f
RooRealVar x("x","x",-10,10) ;
RooRealVar m("m","m",0,-10,10) ;
RooRealVar s("s","s",2,0.1,10) ;
RooGaussian gauss("gauss","gauss(x,m,s)",x,m,s) ;
// Construct a flat p.d.f (polynomial of 0th order)
RooPolynomial poly("poly","poly(x)",x) ;
// Construct model = f*gauss + (1-f)*poly
RooRealVar f("f","f",0.5,0.,1.) ;
RooAddPdf model("model","model",RooArgSet(gauss,poly),f) ;
// Generate small dataset for use in fitting below
RooDataSet* d = model.generate(x,50) ;
// C r e a t e c o n s t r a i n t p d f
// -----------------------------------------
// Construct Gaussian constraint p.d.f on parameter f at 0.8 with resolution of 0.1
RooGaussian fconstraint("fconstraint","fconstraint",f,RooConst(0.8),RooConst(0.1)) ;
// M E T H O D 1 - A d d i n t e r n a l c o n s t r a i n t t o m o d e l
// -------------------------------------------------------------------------------------
// Multiply constraint term with regular p.d.f using RooProdPdf
// Specify in fitTo() that internal constraints on parameter f should be used
// Multiply constraint with p.d.f
RooProdPdf modelc("modelc","model with constraint",RooArgSet(model,fconstraint)) ;
// Fit model (without use of constraint term)
RooFitResult* r1 = model.fitTo(*d,Save()) ;
// Fit modelc with constraint term on parameter f
RooFitResult* r2 = modelc.fitTo(*d,Constrain(f),Save()) ;
// M E T H O D 2 - S p e c i f y e x t e r n a l c o n s t r a i n t w h e n f i t t i n g
// -------------------------------------------------------------------------------------------------------
// Construct another Gaussian constraint p.d.f on parameter f at 0.8 with resolution of 0.1
RooGaussian fconstext("fconstext","fconstext",f,RooConst(0.2),RooConst(0.1)) ;
// Fit with external constraint
RooFitResult* r3 = model.fitTo(*d,ExternalConstraints(fconstext),Save()) ;
// Print the fit results
cout << "fit result without constraint (data generated at f=0.5)" << endl ;
r1->Print("v") ;
cout << "fit result with internal constraint (data generated at f=0.5, constraint is f=0.8+/-0.2)" << endl ;
r2->Print("v") ;
cout << "fit result with (another) external constraint (data generated at f=0.5, constraint is f=0.2+/-0.1)" << endl ;
r3->Print("v") ;
}
Author
07/2008 - Wouter Verkerke

Definition in file rf604_constraints.C.