Logo ROOT   6.16/01
Reference Guide
rf203_ranges.C File Reference

Detailed Description

View in nbviewer Open in SWAN 'ADDITION AND CONVOLUTION' RooFit tutorial macro #203

Fitting and plotting in sub ranges

␛[1mRooFit v3.60 -- Developed by Wouter Verkerke and David Kirkby␛[0m
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: (px)
[#1] INFO:Minization -- The following expressions will be evaluated in cache-and-track mode: (gx)
**********
** 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 mx 0.00000e+00 2.00000e+00 -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 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=25940.4 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 5.00000e-01 1.00000e-01 2.01358e-01 -5.48446e+01
2 mx 0.00000e+00 2.00000e+00 2.01358e-01 6.82864e+02
ERR DEF= 0.5
MIGRAD MINIMIZATION HAS CONVERGED.
MIGRAD WILL VERIFY CONVERGENCE AND ERROR MATRIX.
COVARIANCE MATRIX CALCULATED SUCCESSFULLY
FCN=25939.4 FROM MIGRAD STATUS=CONVERGED 23 CALLS 24 TOTAL
EDM=7.58337e-06 STRATEGY= 1 ERROR MATRIX ACCURATE
EXT PARAMETER STEP FIRST
NO. NAME VALUE ERROR SIZE DERIVATIVE
1 f 5.04406e-01 6.32281e-03 1.40982e-03 6.67377e-02
2 mx -2.16053e-02 1.77430e-02 1.97826e-04 -1.47892e+00
ERR DEF= 0.5
EXTERNAL ERROR MATRIX. NDIM= 25 NPAR= 2 ERR DEF=0.5
3.998e-05 3.708e-07
3.708e-07 3.148e-04
PARAMETER CORRELATION COEFFICIENTS
NO. GLOBAL 1 2
1 0.00331 1.000 0.003
2 0.00331 0.003 1.000
**********
** 7 **SET ERR 0.5
**********
**********
** 8 **SET PRINT 1
**********
**********
** 9 **HESSE 1000
**********
COVARIANCE MATRIX CALCULATED SUCCESSFULLY
FCN=25939.4 FROM HESSE STATUS=OK 10 CALLS 34 TOTAL
EDM=7.58116e-06 STRATEGY= 1 ERROR MATRIX ACCURATE
EXT PARAMETER INTERNAL INTERNAL
NO. NAME VALUE ERROR STEP SIZE VALUE
1 f 5.04406e-01 6.32281e-03 2.81963e-04 8.81295e-03
2 mx -2.16053e-02 1.77430e-02 3.95651e-05 -2.16053e-03
ERR DEF= 0.5
EXTERNAL ERROR MATRIX. NDIM= 25 NPAR= 2 ERR DEF=0.5
3.998e-05 4.063e-07
4.063e-07 3.148e-04
PARAMETER CORRELATION COEFFICIENTS
NO. GLOBAL 1 2
1 0.00362 1.000 0.004
2 0.00362 0.004 1.000
[#1] INFO:Minization -- RooMinimizer::optimizeConst: deactivating const optimization
[#1] INFO:Eval -- RooRealVar::setRange(x) new range named 'signal' created with bounds [-3,3]
[#1] INFO:Fitting -- RooAbsOptTestStatistic::ctor(nll_model_modelData) constructing test statistic for sub-range named signal
[#1] INFO:Eval -- RooRealVar::setRange(x) new range named 'NormalizationRangeForsignal' created with bounds [-10,10]
[#1] INFO:Eval -- RooRealVar::setRange(x) new range named 'fit_nll_model_modelData' created with bounds [-3,3]
[#1] INFO:Fitting -- RooAbsOptTestStatistic::ctor(nll_model_modelData) fixing interpretation of coefficients of any RooAddPdf to full domain of observables
[#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: (px)
[#1] INFO:Minization -- The following expressions will be evaluated in cache-and-track mode: (gx)
**********
** 10 **SET PRINT 1
**********
**********
** 11 **SET NOGRAD
**********
PARAMETER DEFINITIONS:
NO. NAME VALUE STEP SIZE LIMITS
1 f 5.04406e-01 6.32281e-03 0.00000e+00 1.00000e+00
2 mx -2.16053e-02 1.77430e-02 -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 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=10339.9 FROM MIGRAD STATUS=INITIATE 6 CALLS 7 TOTAL
EDM= unknown STRATEGY= 1 NO ERROR MATRIX
EXT PARAMETER CURRENT GUESS STEP FIRST
NO. NAME VALUE ERROR SIZE DERIVATIVE
1 f 5.04406e-01 6.32281e-03 1.26465e-02 2.65620e+01
2 mx -2.16053e-02 1.77430e-02 1.77431e-03 -2.76970e+00
ERR DEF= 0.5
MIGRAD MINIMIZATION HAS CONVERGED.
MIGRAD WILL VERIFY CONVERGENCE AND ERROR MATRIX.
COVARIANCE MATRIX CALCULATED SUCCESSFULLY
FCN=10339.5 FROM MIGRAD STATUS=CONVERGED 28 CALLS 29 TOTAL
EDM=3.38795e-07 STRATEGY= 1 ERROR MATRIX ACCURATE
EXT PARAMETER STEP FIRST
NO. NAME VALUE ERROR SIZE DERIVATIVE
1 f 4.90142e-01 1.61947e-02 2.27369e-03 1.69088e-02
2 mx -2.17006e-02 1.79160e-02 1.25822e-04 1.06356e-01
ERR DEF= 0.5
EXTERNAL ERROR MATRIX. NDIM= 25 NPAR= 2 ERR DEF=0.5
2.624e-04 3.238e-06
3.238e-06 3.210e-04
PARAMETER CORRELATION COEFFICIENTS
NO. GLOBAL 1 2
1 0.01116 1.000 0.011
2 0.01116 0.011 1.000
**********
** 16 **SET ERR 0.5
**********
**********
** 17 **SET PRINT 1
**********
**********
** 18 **HESSE 1000
**********
COVARIANCE MATRIX CALCULATED SUCCESSFULLY
FCN=10339.5 FROM HESSE STATUS=OK 10 CALLS 39 TOTAL
EDM=3.38988e-07 STRATEGY= 1 ERROR MATRIX ACCURATE
EXT PARAMETER INTERNAL INTERNAL
NO. NAME VALUE ERROR STEP SIZE VALUE
1 f 4.90142e-01 1.61948e-02 9.09474e-05 -1.97171e-02
2 mx -2.17006e-02 1.79161e-02 2.51643e-05 -2.17006e-03
ERR DEF= 0.5
EXTERNAL ERROR MATRIX. NDIM= 25 NPAR= 2 ERR DEF=0.5
2.624e-04 3.402e-06
3.402e-06 3.210e-04
PARAMETER CORRELATION COEFFICIENTS
NO. GLOBAL 1 2
1 0.01172 1.000 0.012
2 0.01172 0.012 1.000
[#1] INFO:Minization -- RooMinimizer::optimizeConst: deactivating const optimization
[#1] INFO:Plotting -- RooAbsPdf::plotOn(model) p.d.f was fitted in range and no explicit norm range was specified, using fit range as default
[#1] INFO:Plotting -- RooAbsPdf::plotOn(model) only plotting range 'Full'
[#1] INFO:Plotting -- RooAbsPdf::plotOn(model) p.d.f. curve is normalized using explicit choice of ranges 'fit_nll_model_modelData'
[#1] INFO:Plotting -- RooAbsPdf::plotOn(model) p.d.f was fitted in range and no explicit plot,norm range was specified, using fit range as default
[#1] INFO:Plotting -- RooAbsPdf::plotOn(model) only plotting range 'fit_nll_model_modelData'
[#1] INFO:Plotting -- RooAbsPdf::plotOn(model) p.d.f. curve is normalized using explicit choice of ranges 'fit_nll_model_modelData'
result of fit on all data
RooFitResult: minimized FCN value: 25939.4, estimated distance to minimum: 7.58116e-06
covariance matrix quality: Full, accurate covariance matrix
Status : MINIMIZE=0 HESSE=0
Floating Parameter FinalValue +/- Error
-------------------- --------------------------
f 5.0441e-01 +/- 6.32e-03
mx -2.1605e-02 +/- 1.77e-02
result of fit in in signal region (note increased error on signal fraction)
RooFitResult: minimized FCN value: 10339.5, estimated distance to minimum: 3.38988e-07
covariance matrix quality: Full, accurate covariance matrix
Status : MINIMIZE=0 HESSE=0
Floating Parameter FinalValue +/- Error
-------------------- --------------------------
f 4.9014e-01 +/- 1.62e-02
mx -2.1701e-02 +/- 1.79e-02
#include "RooRealVar.h"
#include "RooDataSet.h"
#include "RooGaussian.h"
#include "RooConstVar.h"
#include "RooPolynomial.h"
#include "RooAddPdf.h"
#include "RooFitResult.h"
#include "RooPlot.h"
#include "TCanvas.h"
#include "TAxis.h"
#include "TH1.h"
using namespace RooFit ;
{
// S e t u p m o d e l
// ---------------------
// Construct observables x
RooRealVar x("x","x",-10,10) ;
// Construct gaussx(x,mx,1)
RooRealVar mx("mx","mx",0,-10,10) ;
RooGaussian gx("gx","gx",x,mx,RooConst(1)) ;
// Construct px = 1 (flat in x)
RooPolynomial px("px","px",x) ;
// Construct model = f*gx + (1-f)px
RooRealVar f("f","f",0.,1.) ;
RooAddPdf model("model","model",RooArgList(gx,px),f) ;
// Generated 10000 events in (x,y) from p.d.f. model
RooDataSet* modelData = model.generate(x,10000) ;
// F i t f u l l r a n g e
// ---------------------------
// Fit p.d.f to all data
RooFitResult* r_full = model.fitTo(*modelData,Save(kTRUE)) ;
// F i t p a r t i a l r a n g e
// ----------------------------------
// Define "signal" range in x as [-3,3]
x.setRange("signal",-3,3) ;
// Fit p.d.f only to data in "signal" range
RooFitResult* r_sig = model.fitTo(*modelData,Save(kTRUE),Range("signal")) ;
// P l o t / p r i n t r e s u l t s
// ---------------------------------------
// Make plot frame in x and add data and fitted model
RooPlot* frame = x.frame(Title("Fitting a sub range")) ;
modelData->plotOn(frame) ;
model.plotOn(frame,Range("Full"),LineStyle(kDashed),LineColor(kRed)) ; // Add shape in full ranged dashed
model.plotOn(frame) ; // By default only fitted range is shown
// Print fit results
cout << "result of fit on all data " << endl ;
r_full->Print() ;
cout << "result of fit in in signal region (note increased error on signal fraction)" << endl ;
r_sig->Print() ;
// Draw frame on canvas
new TCanvas("rf203_ranges","rf203_ranges",600,600) ;
gPad->SetLeftMargin(0.15) ; frame->GetYaxis()->SetTitleOffset(1.4) ; frame->Draw() ;
return ;
}
#define f(i)
Definition: RSha256.hxx:104
const Bool_t kTRUE
Definition: RtypesCore.h:87
@ kRed
Definition: Rtypes.h:63
@ kDashed
Definition: TAttLine.h:48
#define gPad
Definition: TVirtualPad.h:286
virtual RooPlot * plotOn(RooPlot *frame, const RooCmdArg &arg1=RooCmdArg::none(), const RooCmdArg &arg2=RooCmdArg::none(), const RooCmdArg &arg3=RooCmdArg::none(), const RooCmdArg &arg4=RooCmdArg::none(), const RooCmdArg &arg5=RooCmdArg::none(), const RooCmdArg &arg6=RooCmdArg::none(), const RooCmdArg &arg7=RooCmdArg::none(), const RooCmdArg &arg8=RooCmdArg::none()) const
Calls RooPlot* plotOn(RooPlot* frame, const RooLinkedList& cmdList) const ;.
Definition: RooAbsData.cxx:531
RooAddPdf is an efficient implementation of a sum of PDFs of the form.
Definition: RooAddPdf.h:29
RooDataSet is a container class to hold unbinned data.
Definition: RooDataSet.h:31
RooFitResult is a container class to hold the input and output of a PDF fit to a dataset.
Definition: RooFitResult.h:40
virtual void Print(Option_t *options=0) const
Print TNamed name and title.
Definition: RooFitResult.h:66
Plain Gaussian p.d.f.
Definition: RooGaussian.h:25
A RooPlot is a plot frame and a container for graphics objects within that frame.
Definition: RooPlot.h:41
TAxis * GetYaxis() const
Definition: RooPlot.cxx:1123
virtual void Draw(Option_t *options=0)
Draw this plot and all of the elements it contains.
Definition: RooPlot.cxx:558
RooPolynomial implements a polynomial p.d.f of the form.
Definition: RooPolynomial.h:28
RooRealVar represents a fundamental (non-derived) real valued object.
Definition: RooRealVar.h:36
virtual void SetTitleOffset(Float_t offset=1)
Set distance between the axis and the axis title Offset is a correction factor with respect to the "s...
Definition: TAttAxis.cxx:294
The Canvas class.
Definition: TCanvas.h:31
Double_t x[n]
Definition: legend1.C:17
RooConstVar & RooConst(Double_t val)
RooCmdArg Save(Bool_t flag=kTRUE)
RooCmdArg LineColor(Color_t color)
RooCmdArg LineStyle(Style_t style)
const char * Title
Definition: TXMLSetup.cxx:67
Ta Range(0, 0, 1, 1)
Author
07/2008 - Wouter Verkerke

Definition in file rf203_ranges.C.