Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
rf601_intminuit.C File Reference

Detailed Description

View in nbviewer Open in SWAN
Likelihood and minimization: interactive minimization with MINUIT

#include "RooRealVar.h"
#include "RooDataSet.h"
#include "RooGaussian.h"
#include "RooProdPdf.h"
#include "RooAddPdf.h"
#include "RooMinimizer.h"
#include "RooFitResult.h"
#include "RooPlot.h"
#include "TCanvas.h"
#include "TAxis.h"
#include "TH1.h"
using namespace RooFit;
{
// S e t u p p d f a n d l i k e l i h o o d
// -----------------------------------------------
// Observable
RooRealVar x("x", "x", -20, 20);
// Model (intentional strong correlations)
RooRealVar mean("mean", "mean of g1 and g2", 0);
RooRealVar sigma_g1("sigma_g1", "width of g1", 3);
RooGaussian g1("g1", "g1", x, mean, sigma_g1);
RooRealVar sigma_g2("sigma_g2", "width of g2", 4, 3.0, 6.0);
RooGaussian g2("g2", "g2", x, mean, sigma_g2);
RooRealVar frac("frac", "frac", 0.5, 0.0, 1.0);
RooAddPdf model("model", "model", RooArgList(g1, g2), frac);
// Generate 1000 events
std::unique_ptr<RooDataSet> data{model.generate(x, 1000)};
// Construct unbinned likelihood of model w.r.t. data
std::unique_ptr<RooAbsReal> nll{model.createNLL(*data)};
// I n t e r a c t i v e m i n i m i z a t i o n , e r r o r a n a l y s i s
// -------------------------------------------------------------------------------
// Create MINUIT interface object
RooMinimizer m(*nll);
// Activate verbose logging of MINUIT parameter space stepping
m.setVerbose(true);
// Call MIGRAD to minimize the likelihood
m.migrad();
// Print values of all parameters, that reflect values (and error estimates)
// that are back propagated from MINUIT
std::unique_ptr<RooArgSet>{model.getParameters(x)}->Print("s");
// Disable verbose logging
m.setVerbose(false);
// Run HESSE to calculate errors from d2L/dp2
m.hesse();
// Print value (and error) of sigma_g2 parameter, that reflects
// value and error back propagated from MINUIT
sigma_g2.Print();
// Run MINOS on sigma_g2 parameter only
m.minos(sigma_g2);
// Print value (and error) of sigma_g2 parameter, that reflects
// value and error back propagated from MINUIT
sigma_g2.Print();
// S a v i n g r e s u l t s , c o n t o u r p l o t s
// ---------------------------------------------------------
// Save a snapshot of the fit result. This object contains the initial
// fit parameters, the final fit parameters, the complete correlation
// matrix, the EDM, the minimized FCN , the last MINUIT status code and
// the number of times the RooFit function object has indicated evaluation
// problems (e.g. zero probabilities during likelihood evaluation)
std::unique_ptr<RooFitResult> fitResult{m.save()};
// Make contour plot of mx vs sx at 1,2,3 sigma
RooPlot *frame = m.contour(frac, sigma_g2, 1, 2, 3);
frame->SetTitle("Minuit contour plot");
// Print the fit result snapshot
fitResult->Print("v");
// C h a n g e p a r a m e t e r v a l u e s , f l o a t i n g
// -----------------------------------------------------------------
// At any moment you can manually change the value of a (constant)
// parameter
mean = 0.3;
// Rerun MIGRAD,HESSE
m.migrad();
m.hesse();
frac.Print();
// Now fix sigma_g2
sigma_g2.setConstant(true);
// Rerun MIGRAD,HESSE
m.migrad();
m.hesse();
frac.Print();
new TCanvas("rf601_intminuit", "rf601_intminuit", 600, 600);
gPad->SetLeftMargin(0.15);
frame->GetYaxis()->SetTitleOffset(1.4);
frame->Draw();
}
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
#define gPad
Efficient implementation of a sum of PDFs of the form.
Definition RooAddPdf.h:33
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition RooArgList.h:22
Plain Gaussian p.d.f.
Definition RooGaussian.h:24
Wrapper class around ROOT::Math::Minimizer that provides a seamless interface between the minimizer f...
Plot frame and a container for graphics objects within that frame.
Definition RooPlot.h:43
void SetTitle(const char *name) override
Set the title of the RooPlot to 'title'.
Definition RooPlot.cxx:1203
TAxis * GetYaxis() const
Definition RooPlot.cxx:1224
void Draw(Option_t *options=nullptr) override
Draw this plot and all of the elements it contains.
Definition RooPlot.cxx:597
Variable that can be changed from the outside.
Definition RooRealVar.h:37
virtual void SetTitleOffset(Float_t offset=1)
Set distance between the axis and the axis title.
Definition TAttAxis.cxx:298
The Canvas class.
Definition TCanvas.h:23
void Print(Option_t *option="") const override
Dump this marker with its attributes.
Definition TMarker.cxx:339
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 CodegenImpl.h:64
TMarker m
Definition textangle.C:8
[#0] WARNING:InputArguments -- The parameter 'sigma_g1' with range [-inf, inf] of the RooGaussian 'g1' exceeds the safe range of (0, inf). Advise to limit its range.
[#1] INFO:Fitting -- RooAbsPdf::fitTo(model) fixing normalization set for coefficient determination to observables in data
[#1] INFO:Fitting -- using CPU computation library compiled with -mavx2
[#1] INFO:Fitting -- RooAddition::defaultErrorLevel(nll_model_modelData) Summation contains a RooNLLVar, using its error level
[#0] WARNING:Minimization -- RooAbsMinimizerFcn::synchronize: WARNING: no initial error estimate available for frac: using 0.1
[#0] WARNING:Minimization -- RooAbsMinimizerFcn::synchronize: WARNING: no initial error estimate available for sigma_g2: using 0.3
Minuit2Minimizer: Minimize with max-calls 1000 convergence for edm < 1 strategy 1
prevFCN = 2660.220684 frac=0.5036,
prevFCN = 2660.181264 frac=0.4964,
prevFCN = 2660.261875 frac=0.5, sigma_g2=4.011,
prevFCN = 2660.278974 sigma_g2=3.989,
prevFCN = 2660.167705 sigma_g2=4.005,
prevFCN = 2660.248509 sigma_g2=3.995,
prevFCN = 2660.194127 frac=0.5812, sigma_g2=3.889,
prevFCN = 2660.146969 frac=0.5429, sigma_g2=3.941,
prevFCN = 2659.83839 frac=0.5459,
prevFCN = 2659.836693 frac=0.5398,
prevFCN = 2659.841351 frac=0.5429, sigma_g2=3.946,
prevFCN = 2659.835035 sigma_g2=3.936,
prevFCN = 2659.842919 frac=0.5497, sigma_g2=3.955,
prevFCN = 2659.823248 frac=0.5767, sigma_g2=4.011,
prevFCN = 2659.774616 frac=0.6314, sigma_g2=4.128,
prevFCN = 2659.73914 frac=0.6266, sigma_g2=4.117,
prevFCN = 2659.738319 frac=0.6296,
prevFCN = 2659.740343 frac=0.6237,
prevFCN = 2659.737969 frac=0.6266, sigma_g2=4.123,
prevFCN = 2659.737996 sigma_g2=4.112,
prevFCN = 2659.739643 frac=0.6227, sigma_g2=4.114,
prevFCN = 2659.737959 frac=0.6236, sigma_g2=4.115,
prevFCN = 2659.737923 frac=0.6262,
prevFCN = 2659.738617 frac=0.621,
prevFCN = 2659.738491 frac=0.6236, sigma_g2=4.121,
prevFCN = 2659.738401 sigma_g2=4.108,
prevFCN = 2659.738723 sigma_g2=4.115,
prevFCN = 2659.737923 frac=0.6262,
prevFCN = 2659.738617 frac=0.621,
prevFCN = 2659.738491 frac=0.6236, sigma_g2=4.121,
prevFCN = 2659.738401 sigma_g2=4.108,
prevFCN = 2659.738723 frac=0.6241, sigma_g2=4.115,
prevFCN = 2659.737961 frac=0.6231,
prevFCN = 2659.737935 frac=0.6236, sigma_g2=4.116,
prevFCN = 2659.737916 sigma_g2=4.113,
prevFCN = 2659.737981 frac=0.6262, sigma_g2=4.121,
prevFCN = 2659.737949 Minuit2Minimizer : Valid minimum - status = 0
FVAL = 2659.73792283928833
Edm = 2.4027910430005747e-05
Nfcn = 37
frac = 0.6236 +/- 0.164 (limited)
sigma_g2 = 4.115 +/- 0.405 (limited)
frac=0.6236, sigma_g2=4.115, 1) RooRealVar:: frac = 0.6236 +/- 0.164
2) RooRealVar:: mean = 0
3) RooRealVar:: sigma_g1 = 3
4) RooRealVar:: sigma_g2 = 4.115 +/- 0.405
RooRealVar::sigma_g2 = 4.115 +/- 0.4057 L(3 - 6)
******************************************************************************************************
Minuit2Minimizer::GetMinosError - Run MINOS LOWER error for parameter #1 : sigma_g2 using max-calls 1000, tolerance 1
******************************************************************************************************
Minuit2Minimizer::GetMinosError - Run MINOS UPPER error for parameter #1 : sigma_g2 using max-calls 1000, tolerance 1
Minos: Lower error for parameter sigma_g2 : -0.3794
Minos: Upper error for parameter sigma_g2 : 0.4574
RooRealVar::sigma_g2 = 4.115 +/- (-0.3794,0.4574) L(3 - 6)
RooFitResult: minimized FCN value: 2660, estimated distance to minimum: 2.409e-05
covariance matrix quality: Full, accurate covariance matrix
Status : MIGRAD=0 HESSE=0 MINOS=0
Constant Parameter Value
-------------------- ------------
mean 0.0000e+00
sigma_g1 3.0000e+00
Floating Parameter InitialValue FinalValue (+HiError,-LoError) GblCorr.
-------------------- ------------ ---------------------------------- --------
frac 5.0000e-01 6.2360e-01 +/- 1.64e-01 <none>
sigma_g2 4.0000e+00 4.1146e+00 (+4.57e-01,-3.79e-01) <none>
Minuit2Minimizer: Minimize with max-calls 1000 convergence for edm < 1 strategy 1
Minuit2Minimizer : Valid minimum - status = 0
FVAL = 2663.35774508719987
Edm = 9.56369873007578491e-05
Nfcn = 38
frac = 0.5655 +/- 0.1961 (limited)
sigma_g2 = 4.005 +/- 0.3917 (limited)
RooRealVar::frac = 0.5655 +/- 0.1961 L(0 - 1)
Minuit2Minimizer: Minimize with max-calls 1000 convergence for edm < 1 strategy 1
Minuit2Minimizer : Valid minimum - status = 0
FVAL = 2663.35774092453448
Edm = 1.35713798793672428e-10
Nfcn = 15
frac = 0.5652 +/- 0.08029 (limited)
sigma_g2 = 4.005 (fixed)
RooRealVar::frac = 0.5652 +/- 0.08029 L(0 - 1)
Date
July 2008
Author
Wouter Verkerke

Definition in file rf601_intminuit.C.