Logo ROOT  
Reference Guide
rf609_xychi2fit.C File Reference

Detailed Description

View in nbviewer Open in SWAN

Likelihood and minimization: setting up a chi^2 fit to an unbinned dataset with X,Y,err(Y) values (and optionally err(X) values)

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 **SET PRINT 1
**********
**********
** 2 **SET NOGRAD
**********
PARAMETER DEFINITIONS:
NO. NAME VALUE STEP SIZE LIMITS
1 a 0.00000e+00 2.00000e+00 -1.00000e+01 1.00000e+01
2 b 0.00000e+00 2.00000e+01 -1.00000e+02 1.00000e+02
**********
** 3 **SET ERR 1
**********
**********
** 4 **SET PRINT 1
**********
**********
** 5 **SET STR 1
**********
NOW USING STRATEGY 1: TRY TO BALANCE SPEED AGAINST RELIABILITY
**********
** 6 **MIGRAD 1000 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=2.04222 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 a 0.00000e+00 2.00000e+00 2.01358e-01 1.35235e+01
2 b 0.00000e+00 2.00000e+01 2.01358e-01 -3.08578e+02
MIGRAD MINIMIZATION HAS CONVERGED.
MIGRAD WILL VERIFY CONVERGENCE AND ERROR MATRIX.
COVARIANCE MATRIX CALCULATED SUCCESSFULLY
FCN=1.43197 FROM MIGRAD STATUS=CONVERGED 32 CALLS 33 TOTAL
EDM=3.23329e-05 STRATEGY= 1 ERROR MATRIX ACCURATE
EXT PARAMETER STEP FIRST
NO. NAME VALUE ERROR SIZE DERIVATIVE
1 a -1.60654e-01 5.24023e-01 3.93124e-05 1.09375e-01
2 b 3.34226e-01 4.91235e-01 3.85614e-06 -1.06196e+00
EXTERNAL ERROR MATRIX. NDIM= 25 NPAR= 2 ERR DEF=1
2.749e-01 -1.964e-02
-1.964e-02 2.413e-01
PARAMETER CORRELATION COEFFICIENTS
NO. GLOBAL 1 2
1 0.07625 1.000 -0.076
2 0.07625 -0.076 1.000
**********
** 7 **SET ERR 1
**********
**********
** 8 **SET PRINT 1
**********
**********
** 9 **HESSE 1000
**********
COVARIANCE MATRIX CALCULATED SUCCESSFULLY
FCN=1.43197 FROM HESSE STATUS=OK 10 CALLS 43 TOTAL
EDM=3.23291e-05 STRATEGY= 1 ERROR MATRIX ACCURATE
EXT PARAMETER INTERNAL INTERNAL
NO. NAME VALUE ERROR STEP SIZE VALUE
1 a -1.60654e-01 5.24019e-01 7.86248e-06 -1.60660e-02
2 b 3.34226e-01 4.91231e-01 7.71228e-07 3.34226e-03
EXTERNAL ERROR MATRIX. NDIM= 25 NPAR= 2 ERR DEF=1
2.748e-01 -1.961e-02
-1.961e-02 2.413e-01
PARAMETER CORRELATION COEFFICIENTS
NO. GLOBAL 1 2
1 0.07614 1.000 -0.076
2 0.07614 -0.076 1.000
[#1] INFO:Minization -- RooMinimizer::optimizeConst: activating const optimization
**********
** 10 **SET PRINT 1
**********
**********
** 11 **SET NOGRAD
**********
PARAMETER DEFINITIONS:
NO. NAME VALUE STEP SIZE LIMITS
1 a -1.60654e-01 5.24019e-01 -1.00000e+01 1.00000e+01
2 b 3.34226e-01 4.91231e-01 -1.00000e+02 1.00000e+02
**********
** 12 **SET ERR 1
**********
**********
** 13 **SET PRINT 1
**********
**********
** 14 **SET STR 1
**********
NOW USING STRATEGY 1: TRY TO BALANCE SPEED AGAINST RELIABILITY
**********
** 15 **MIGRAD 1000 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=176984 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 a -1.60654e-01 5.24019e-01 5.24327e-02 -8.81282e+03
2 b 3.34226e-01 4.91231e-01 4.91235e-03 2.93731e+07
MIGRAD MINIMIZATION HAS CONVERGED.
MIGRAD WILL VERIFY CONVERGENCE AND ERROR MATRIX.
COVARIANCE MATRIX CALCULATED SUCCESSFULLY
FCN=76478.7 FROM MIGRAD STATUS=CONVERGED 30 CALLS 31 TOTAL
EDM=2.56889e-08 STRATEGY= 1 ERROR MATRIX ACCURATE
EXT PARAMETER STEP FIRST
NO. NAME VALUE ERROR SIZE DERIVATIVE
1 a -5.61220e-02 1.57588e-02 2.12800e-04 -1.43819e-01
2 b -3.49788e-01 2.15812e-03 2.91421e-06 -1.32588e-01
EXTERNAL ERROR MATRIX. NDIM= 25 NPAR= 2 ERR DEF=1
2.483e-04 3.343e-08
3.343e-08 4.657e-06
PARAMETER CORRELATION COEFFICIENTS
NO. GLOBAL 1 2
1 0.00098 1.000 0.001
2 0.00098 0.001 1.000
**********
** 16 **SET ERR 1
**********
**********
** 17 **SET PRINT 1
**********
**********
** 18 **HESSE 1000
**********
COVARIANCE MATRIX CALCULATED SUCCESSFULLY
FCN=76478.7 FROM HESSE STATUS=OK 10 CALLS 41 TOTAL
EDM=2.56903e-08 STRATEGY= 1 ERROR MATRIX ACCURATE
EXT PARAMETER INTERNAL INTERNAL
NO. NAME VALUE ERROR STEP SIZE VALUE
1 a -5.61220e-02 1.57588e-02 4.25601e-05 -5.61223e-03
2 b -3.49788e-01 2.15812e-03 5.82843e-07 -3.49789e-03
EXTERNAL ERROR MATRIX. NDIM= 25 NPAR= 2 ERR DEF=1
2.483e-04 3.343e-08
3.343e-08 4.657e-06
PARAMETER CORRELATION COEFFICIENTS
NO. GLOBAL 1 2
1 0.00098 1.000 0.001
2 0.00098 0.001 1.000
#include "RooRealVar.h"
#include "RooDataSet.h"
#include "RooPolyVar.h"
#include "RooConstVar.h"
#include "RooChi2Var.h"
#include "TCanvas.h"
#include "TAxis.h"
#include "RooPlot.h"
#include "TRandom.h"
using namespace RooFit;
{
// C r e a t e d a t a s e t w i t h X a n d Y v a l u e s
// -------------------------------------------------------------------
// Make weighted XY dataset with asymmetric errors stored
// The StoreError() argument is essential as it makes
// the dataset store the error in addition to the values
// of the observables. If errors on one or more observables
// are asymmetric, one can store the asymmetric error
// using the StoreAsymError() argument
RooRealVar x("x", "x", -11, 11);
RooRealVar y("y", "y", -10, 200);
RooDataSet dxy("dxy", "dxy", RooArgSet(x, y), StoreError(RooArgSet(x, y)));
// Fill an example dataset with X,err(X),Y,err(Y) values
for (int i = 0; i <= 10; i++) {
// Set X value and error
x = -10 + 2 * i;
x.setError(i < 5 ? 0.5 / 1. : 1.0 / 1.);
// Set Y value and error
y = x.getVal() * x.getVal() + 4 * fabs(gRandom->Gaus());
y.setError(sqrt(y.getVal()));
dxy.add(RooArgSet(x, y));
}
// P e r f o r m c h i 2 f i t t o X + / - d x a n d Y + / - d Y v a l u e s
// ---------------------------------------------------------------------------------------
// Make fit function
RooRealVar a("a", "a", 0.0, -10, 10);
RooRealVar b("b", "b", 0.0, -100, 100);
RooPolyVar f("f", "f", x, RooArgList(b, a, RooConst(1)));
// Plot dataset in X-Y interpretation
RooPlot *frame = x.frame(Title("Chi^2 fit of function set of (X#pmdX,Y#pmdY) values"));
dxy.plotOnXY(frame, YVar(y));
// Fit chi^2 using X and Y errors
f.chi2FitTo(dxy, YVar(y));
// Overlay fitted function
f.plotOn(frame);
// Alternative: fit chi^2 integrating f(x) over ranges defined by X errors, rather
// than taking point at center of bin
f.chi2FitTo(dxy, YVar(y), Integrate(kTRUE));
// Overlay alternate fit result
f.plotOn(frame, LineStyle(kDashed), LineColor(kRed));
// Draw the plot on a canvas
new TCanvas("rf609_xychi2fit", "rf609_xychi2fit", 600, 600);
gPad->SetLeftMargin(0.15);
frame->GetYaxis()->SetTitleOffset(1.4);
frame->Draw();
}
Date
07/2008
Author
Wouter Verkerke

Definition in file rf609_xychi2fit.C.

RooPlot::Draw
virtual void Draw(Option_t *options=0)
Draw this plot and all of the elements it contains.
Definition: RooPlot.cxx:691
TRandom::Gaus
virtual Double_t Gaus(Double_t mean=0, Double_t sigma=1)
Samples a random number from the standard Normal (Gaussian) Distribution with the given mean and sigm...
Definition: TRandom.cxx:263
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
f
#define f(i)
Definition: RSha256.hxx:122
rf609_xychi2fit
Definition: rf609_xychi2fit.py:1
RooArgList
Definition: RooArgList.h:21
TRandom.h
x
Double_t x[n]
Definition: legend1.C:17
TCanvas.h
RooFit::YVar
RooCmdArg YVar(const RooAbsRealLValue &var, const RooCmdArg &arg=RooCmdArg::none())
Definition: RooGlobalFunc.cxx:240
RooDataSet.h
RooFit::Integrate
RooCmdArg Integrate(Bool_t flag)
Definition: RooGlobalFunc.cxx:210
b
#define b(i)
Definition: RSha256.hxx:118
RooChi2Var.h
RooFit::StoreError
RooCmdArg StoreError(const RooArgSet &aset)
Definition: RooGlobalFunc.cxx:130
RooPolyVar.h
ROOT::Math::fabs
VecExpr< UnaryOp< Fabs< T >, VecExpr< A, T, D >, T >, T, D > fabs(const VecExpr< A, T, D > &rhs)
Definition: UnaryOperators.h:131
RooFit
Definition: RooCFunction1Binding.h:29
a
auto * a
Definition: textangle.C:12
RooPlot.h
RooPlot::GetYaxis
TAxis * GetYaxis() const
Definition: RooPlot.cxx:1256
gRandom
R__EXTERN TRandom * gRandom
Definition: TRandom.h:62
RooPlot
Definition: RooPlot.h:44
y
Double_t y[n]
Definition: legend1.C:17
sqrt
double sqrt(double)
RooRealVar.h
kRed
@ kRed
Definition: Rtypes.h:66
RooPolyVar
Definition: RooPolyVar.h:28
RooConstVar.h
RooFit::LineColor
RooCmdArg LineColor(Color_t color)
Definition: RooGlobalFunc.cxx:56
TCanvas
Definition: TCanvas.h:23
TAxis.h
kDashed
@ kDashed
Definition: TAttLine.h:48
gPad
#define gPad
Definition: TVirtualPad.h:287
RooDataSet
Definition: RooDataSet.h:33
RooFit::LineStyle
RooCmdArg LineStyle(Style_t style)
Definition: RooGlobalFunc.cxx:57
TAttAxis::SetTitleOffset
virtual void SetTitleOffset(Float_t offset=1)
Set distance between the axis and the axis title.
Definition: TAttAxis.cxx:293
RooRealVar
Definition: RooRealVar.h:35
RooFit::Title
RooCmdArg Title(const char *name)
Definition: RooGlobalFunc.cxx:173
RooArgSet
Definition: RooArgSet.h:28
RooFit::RooConst
RooConstVar & RooConst(Double_t val)
Definition: RooGlobalFunc.cxx:341