Logo ROOT  
Reference Guide
rf604_constraints.C File Reference

Detailed Description

View in nbviewer Open in SWAN

Likelihood and minimization: fitting with constraints

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 constraint 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.268 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 -1.80809e+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.40505e-03
ERR DEF= 0.5
MIGRAD MINIMIZATION HAS CONVERGED.
MIGRAD WILL VERIFY CONVERGENCE AND ERROR MATRIX.
COVARIANCE MATRIX CALCULATED SUCCESSFULLY
FCN=134.19 FROM MIGRAD STATUS=CONVERGED 48 CALLS 49 TOTAL
EDM=7.15556e-07 STRATEGY= 1 ERROR MATRIX ACCURATE
EXT PARAMETER STEP FIRST
NO. NAME VALUE ERROR SIZE DERIVATIVE
1 f 6.90394e-01 1.01488e-01 1.56024e-03 -2.66326e-03
2 m 6.95291e-01 4.98410e-01 3.92779e-04 4.60363e-03
3 s 2.26976e+00 4.75435e-01 8.11598e-04 -2.57087e-03
ERR DEF= 0.5
EXTERNAL ERROR MATRIX. NDIM= 25 NPAR= 3 ERR DEF=0.5
1.047e-02 -6.212e-03 2.307e-02
-6.212e-03 2.486e-01 -4.460e-02
2.307e-02 -4.460e-02 2.271e-01
PARAMETER CORRELATION COEFFICIENTS
NO. GLOBAL 1 2 3
1 0.47437 1.000 -0.122 0.473
2 0.19139 -0.122 1.000 -0.188
3 0.49100 0.473 -0.188 1.000
**********
** 16 **SET ERR 0.5
**********
**********
** 17 **SET PRINT 1
**********
**********
** 18 **HESSE 1500
**********
COVARIANCE MATRIX CALCULATED SUCCESSFULLY
FCN=134.19 FROM HESSE STATUS=OK 16 CALLS 65 TOTAL
EDM=7.15613e-07 STRATEGY= 1 ERROR MATRIX ACCURATE
EXT PARAMETER INTERNAL INTERNAL
NO. NAME VALUE ERROR STEP SIZE VALUE
1 f 6.90394e-01 1.01490e-01 3.12047e-04 3.90649e-01
2 m 6.95291e-01 4.98516e-01 7.85557e-05 6.95852e-02
3 s 2.26976e+00 4.75547e-01 1.62320e-04 -5.96397e-01
ERR DEF= 0.5
EXTERNAL ERROR MATRIX. NDIM= 25 NPAR= 3 ERR DEF=0.5
1.047e-02 -6.221e-03 2.308e-02
-6.221e-03 2.487e-01 -4.490e-02
2.308e-02 -4.490e-02 2.272e-01
PARAMETER CORRELATION COEFFICIENTS
NO. GLOBAL 1 2 3
1 0.47441 1.000 -0.122 0.473
2 0.19247 -0.122 1.000 -0.189
3 0.49137 0.473 -0.189 1.000
[#1] INFO:Minization -- RooMinimizer::optimizeConst: deactivating const optimization
[#1] INFO:Minization -- Including the following constraint 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 6.90394e-01 1.01490e-01 0.00000e+00 1.00000e+00
2 m 6.95291e-01 4.98516e-01 -1.00000e+01 1.00000e+01
3 s 2.26976e+00 4.75547e-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=145.521 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.90394e-01 1.01490e-01 2.22303e-01 2.39366e+01
2 m 6.95291e-01 4.98516e-01 4.99937e-02 4.60680e-03
3 s 2.26976e+00 4.75547e-01 1.16751e-01 -2.63987e-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 52 CALLS 53 TOTAL
EDM=4.81135e-05 STRATEGY= 1 ERROR MATRIX ACCURATE
EXT PARAMETER STEP FIRST
NO. NAME VALUE ERROR SIZE DERIVATIVE
1 f 3.61995e-01 8.14207e-02 1.26319e-03 -1.14476e-02
2 m 7.06198e-01 5.87858e-01 4.68561e-04 7.19385e-02
3 s 1.70830e+00 4.74684e-01 9.56739e-04 4.09583e-02
ERR DEF= 0.5
EXTERNAL ERROR MATRIX. NDIM= 25 NPAR= 3 ERR DEF=0.5
6.694e-03 5.868e-03 1.544e-02
5.868e-03 3.460e-01 4.994e-02
1.544e-02 4.994e-02 2.266e-01
PARAMETER CORRELATION COEFFICIENTS
NO. GLOBAL 1 2 3
1 0.39975 1.000 0.122 0.396
2 0.18688 0.122 1.000 0.178
3 0.41743 0.396 0.178 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 69 TOTAL
EDM=4.81665e-05 STRATEGY= 1 ERROR MATRIX ACCURATE
EXT PARAMETER INTERNAL INTERNAL
NO. NAME VALUE ERROR STEP SIZE VALUE
1 f 3.61995e-01 8.14561e-02 2.52637e-04 -2.79640e-01
2 m 7.06198e-01 5.87996e-01 9.37122e-05 7.06786e-02
3 s 1.70830e+00 4.74927e-01 1.91348e-04 -7.41089e-01
ERR DEF= 0.5
EXTERNAL ERROR MATRIX. NDIM= 25 NPAR= 3 ERR DEF=0.5
6.700e-03 5.921e-03 1.549e-02
5.921e-03 3.461e-01 5.029e-02
1.549e-02 5.029e-02 2.268e-01
PARAMETER CORRELATION COEFFICIENTS
NO. GLOBAL 1 2 3
1 0.40067 1.000 0.123 0.397
2 0.18809 0.123 1.000 0.179
3 0.41846 0.397 0.179 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: 134.19, estimated distance to minimum: 7.15613e-07
covariance matrix quality: Full, accurate covariance matrix
Status : MINIMIZE=0 HESSE=0
Floating Parameter InitialValue FinalValue +/- Error GblCorr.
-------------------- ------------ -------------------------- --------
f 6.4987e-01 6.9039e-01 +/- 1.01e-01 <none>
m 7.1824e-01 6.9529e-01 +/- 4.99e-01 <none>
s 2.1880e+00 2.2698e+00 +/- 4.76e-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: 4.81665e-05
covariance matrix quality: Full, accurate covariance matrix
Status : MINIMIZE=0 HESSE=0
Floating Parameter InitialValue FinalValue +/- Error GblCorr.
-------------------- ------------ -------------------------- --------
f 6.9039e-01 3.6200e-01 +/- 8.15e-02 <none>
m 6.9529e-01 7.0620e-01 +/- 5.88e-01 <none>
s 2.2698e+00 1.7083e+00 +/- 4.75e-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;
{
// 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.2));
// 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.2 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");
}
Date
07/2008
Author
Wouter Verkerke

Definition in file rf604_constraints.C.

m
auto * m
Definition: textangle.C:8
RooAddPdf
RooAddPdf is an efficient implementation of a sum of PDFs of the form.
Definition: RooAddPdf.h:32
f
#define f(i)
Definition: RSha256.hxx:104
RooGaussian.h
TGeant4Unit::s
static constexpr double s
Definition: TGeant4SystemOfUnits.h:162
x
Double_t x[n]
Definition: legend1.C:17
RooGaussian
Plain Gaussian p.d.f.
Definition: RooGaussian.h:25
RooAddPdf.h
TCanvas.h
RooDataSet.h
RooFit::ExternalConstraints
RooCmdArg ExternalConstraints(const RooArgSet &constraintPdfs)
Definition: RooGlobalFunc.cxx:204
RooFitResult
RooFitResult is a container class to hold the input and output of a PDF fit to a dataset.
Definition: RooFitResult.h:40
RooPolynomial.h
RooProdPdf.h
TGeant4Unit::gauss
static constexpr double gauss
Definition: TGeant4SystemOfUnits.h:263
RooFit
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Definition: RooCFunction1Binding.h:29
RooPolynomial
RooPolynomial implements a polynomial p.d.f of the form.
Definition: RooPolynomial.h:28
RooFit::Constrain
RooCmdArg Constrain(const RooArgSet &params)
Definition: RooGlobalFunc.cxx:200
RooPlot.h
RooRealVar.h
RooFitResult.h
RooConstVar.h
rf604_constraints
Definition: rf604_constraints.py:1
TAxis.h
RooFitResult::Print
virtual void Print(Option_t *options=0) const
Print TNamed name and title.
Definition: RooFitResult.h:66
d
#define d(i)
Definition: RSha256.hxx:102
RooDataSet
RooDataSet is a container class to hold unbinned data.
Definition: RooDataSet.h:33
make_cnn_model.model
model
Definition: make_cnn_model.py:6
RooRealVar
RooRealVar represents a variable that can be changed from the outside.
Definition: RooRealVar.h:36
RooFit::Save
RooCmdArg Save(Bool_t flag=kTRUE)
Definition: RooGlobalFunc.cxx:187
RooProdPdf
RooProdPdf is an efficient implementation of a product of PDFs of the form.
Definition: RooProdPdf.h:33
TH1.h
RooArgSet
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:28
RooFit::RooConst
RooConstVar & RooConst(Double_t val)
Definition: RooGlobalFunc.cxx:341