Logo ROOT  
Reference Guide
rf604_constraints.C File Reference

Detailed Description

View in nbviewer Open in SWAN Likelihood and minimization: fitting with constraints

[#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: (poly)
[#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (gauss)
[#1] INFO:Minimization -- RooAbsMinimizerFcn::setOptimizeConst: deactivating const optimization
[#1] INFO:Minimization -- Including the following constraint terms in minimization: (fconstraint)
[#1] INFO:Minimization -- The global observables are not defined , normalize constraints with respect to the parameters (f)
[#1] INFO:Fitting -- RooAddition::defaultErrorLevel(nll_modelc_modelData_with_constr) 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: (poly)
[#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (gauss)
[#1] INFO:Minimization -- RooAbsMinimizerFcn::setOptimizeConst: deactivating const optimization
[#1] INFO:Minimization -- Including the following constraint terms in minimization: (fconstext)
[#1] INFO:Minimization -- The global observables are not defined , normalize constraints with respect to the parameters (f,m,s)
[#1] INFO:Fitting -- RooAddition::defaultErrorLevel(nll_model_modelData_with_constr) 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: (poly)
[#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (gauss)
[#1] INFO:Minimization -- RooAbsMinimizerFcn::setOptimizeConst: 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 pdf
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 pdf (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 pdf 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 pdf using RooProdPdf
// Specify in fitTo() that internal constraints on parameter f should be used
// Multiply constraint with pdf
RooProdPdf modelc("modelc", "model with constraint", RooArgSet(model, fconstraint));
// Fit model (without use of constraint term)
RooFitResult *r1 = model.fitTo(*d, Save(), PrintLevel(-1));
// Fit modelc with constraint term on parameter f
RooFitResult *r2 = modelc.fitTo(*d, Constrain(f), Save(), PrintLevel(-1));
// 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 pdf 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(), PrintLevel(-1));
// 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");
}
#define d(i)
Definition: RSha256.hxx:102
#define f(i)
Definition: RSha256.hxx:104
RooAddPdf is an efficient implementation of a sum of PDFs of the form.
Definition: RooAddPdf.h:34
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:56
RooDataSet is a container class to hold unbinned data.
Definition: RooDataSet.h:55
RooFitResult is a container class to hold the input and output of a PDF fit to a dataset.
Definition: RooFitResult.h:40
void Print(Option_t *options=0) const override
Print TNamed name and title.
Definition: RooFitResult.h:66
Plain Gaussian p.d.f.
Definition: RooGaussian.h:24
RooPolynomial implements a polynomial p.d.f of the form.
Definition: RooPolynomial.h:28
RooProdPdf is an efficient implementation of a product of PDFs of the form.
Definition: RooProdPdf.h:33
RooRealVar represents a variable that can be changed from the outside.
Definition: RooRealVar.h:40
RooConstVar & RooConst(double val)
RooCmdArg Constrain(const RooArgSet &params)
RooCmdArg Save(bool flag=true)
RooCmdArg ExternalConstraints(const RooArgSet &constraintPdfs)
RooCmdArg PrintLevel(Int_t code)
Double_t x[n]
Definition: legend1.C:17
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Definition: Common.h:18
static constexpr double s
static constexpr double gauss
TMarker m
Definition: textangle.C:8
Date
07/2008
Author
Wouter Verkerke

Definition in file rf604_constraints.C.