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

Detailed Description

View in nbviewer Open in SWAN Setting up an extended maximum likelihood fit.

␛[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
[#0] WARNING:InputArguments -- The parameter 'sigma1' with range [-1e+30, 1e+30] of the RooGaussian 'sig1' exceeds the safe range of (0, inf). Advise to limit its range.
[#0] WARNING:InputArguments -- The parameter 'sigma2' with range [-1e+30, 1e+30] of the RooGaussian 'sig2' exceeds the safe range of (0, inf). Advise to limit its range.
[#1] INFO:Minimization -- p.d.f. provides expected number of events, including extended term in likelihood.
[#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: (sig1,sig2)
[#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (bkg)
**********
** 1 **SET PRINT 1
**********
**********
** 2 **SET NOGRAD
**********
PARAMETER DEFINITIONS:
NO. NAME VALUE STEP SIZE LIMITS
1 a0 5.00000e-01 1.00000e-01 0.00000e+00 1.00000e+00
2 a1 2.00000e-01 1.00000e-01 0.00000e+00 1.00000e+00
3 nbkg 5.00000e+02 2.50000e+02 0.00000e+00 1.00000e+04
4 nsig 5.00000e+02 2.50000e+02 0.00000e+00 1.00000e+04
5 sig1frac 8.00000e-01 1.00000e-01 0.00000e+00 1.00000e+00
**********
** 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 2500 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=-3945.08 FROM MIGRAD STATUS=INITIATE 14 CALLS 15 TOTAL
EDM= unknown STRATEGY= 1 NO ERROR MATRIX
EXT PARAMETER CURRENT GUESS STEP FIRST
NO. NAME VALUE ERROR SIZE DERIVATIVE
1 a0 5.00000e-01 1.00000e-01 2.01358e-01 5.55992e+00
2 a1 2.00000e-01 1.00000e-01 2.57889e-01 -1.57427e+00
3 nbkg 5.00000e+02 2.50000e+02 1.18625e-01 2.53685e+00
4 nsig 5.00000e+02 2.50000e+02 1.18625e-01 -2.53775e+00
5 sig1frac 8.00000e-01 1.00000e-01 2.57889e-01 -2.02142e+00
ERR DEF= 0.5
MIGRAD MINIMIZATION HAS CONVERGED.
MIGRAD WILL VERIFY CONVERGENCE AND ERROR MATRIX.
COVARIANCE MATRIX CALCULATED SUCCESSFULLY
FCN=-3945.49 FROM MIGRAD STATUS=CONVERGED 98 CALLS 99 TOTAL
EDM=1.34919e-05 STRATEGY= 1 ERROR MATRIX ACCURATE
EXT PARAMETER STEP FIRST
NO. NAME VALUE ERROR SIZE DERIVATIVE
1 a0 4.41701e-01 7.31971e-02 6.37371e-03 -2.20459e-02
2 a1 2.01081e-01 1.18245e-01 8.18002e-03 7.34208e-03
3 nbkg 5.04206e+02 3.94549e+01 4.96630e-04 1.70657e-02
4 nsig 4.95799e+02 3.93537e+01 4.96929e-04 6.32307e-03
5 sig1frac 8.37341e-01 1.17266e-01 8.52165e-03 -5.56323e-04
ERR DEF= 0.5
EXTERNAL ERROR MATRIX. NDIM= 25 NPAR= 5 ERR DEF=0.5
5.397e-03 1.216e-03 -3.098e-01 3.099e-01 -1.021e-03
1.216e-03 1.441e-02 -3.254e+00 3.254e+00 -9.763e-03
-3.098e-01 -3.254e+00 1.557e+03 -1.053e+03 3.292e+00
3.099e-01 3.254e+00 -1.053e+03 1.549e+03 -3.293e+00
-1.021e-03 -9.763e-03 3.292e+00 -3.293e+00 1.424e-02
PARAMETER CORRELATION COEFFICIENTS
NO. GLOBAL 1 2 3 4 5
1 0.14135 1.000 0.138 -0.107 0.107 -0.116
2 0.77063 0.138 1.000 -0.687 0.689 -0.682
3 0.77292 -0.107 -0.687 1.000 -0.678 0.699
4 0.77488 0.107 0.689 -0.678 1.000 -0.701
5 0.78168 -0.116 -0.682 0.699 -0.701 1.000
**********
** 7 **SET ERR 0.5
**********
**********
** 8 **SET PRINT 1
**********
**********
** 9 **HESSE 2500
**********
COVARIANCE MATRIX CALCULATED SUCCESSFULLY
FCN=-3945.49 FROM HESSE STATUS=OK 31 CALLS 130 TOTAL
EDM=1.34689e-05 STRATEGY= 1 ERROR MATRIX ACCURATE
EXT PARAMETER INTERNAL INTERNAL
NO. NAME VALUE ERROR STEP SIZE VALUE
1 a0 4.41701e-01 7.31850e-02 1.27474e-03 -1.16864e-01
2 a1 2.01081e-01 1.17613e-01 3.27201e-04 -6.40802e-01
3 nbkg 5.04206e+02 3.93107e+01 9.93261e-05 -1.11784e+00
4 nsig 4.95799e+02 3.92054e+01 1.98772e-05 -1.12170e+00
5 sig1frac 8.37341e-01 1.16841e-01 3.40866e-04 7.40533e-01
ERR DEF= 0.5
EXTERNAL ERROR MATRIX. NDIM= 25 NPAR= 5 ERR DEF=0.5
5.395e-03 1.200e-03 -3.051e-01 3.051e-01 -1.005e-03
1.200e-03 1.425e-02 -3.209e+00 3.209e+00 -9.625e-03
-3.051e-01 -3.209e+00 1.545e+03 -1.041e+03 3.258e+00
3.051e-01 3.209e+00 -1.041e+03 1.537e+03 -3.258e+00
-1.005e-03 -9.625e-03 3.258e+00 -3.258e+00 1.413e-02
PARAMETER CORRELATION COEFFICIENTS
NO. GLOBAL 1 2 3 4 5
1 0.14023 1.000 0.137 -0.106 0.106 -0.115
2 0.76770 0.137 1.000 -0.684 0.686 -0.678
3 0.77101 -0.106 -0.684 1.000 -0.676 0.697
4 0.77292 0.106 0.686 -0.676 1.000 -0.699
5 0.77980 -0.115 -0.678 0.697 -0.699 1.000
[#1] INFO:Minimization -- RooAbsMinimizerFcn::setOptimizeConst: deactivating const optimization
[#1] INFO:Plotting -- RooAbsPdf::plotOn(model) directly selected PDF components: (bkg)
[#1] INFO:Plotting -- RooAbsPdf::plotOn(model) indirectly selected PDF components: ()
[#1] INFO:Plotting -- RooAbsPdf::plotOn(model) directly selected PDF components: (bkg,sig2)
[#1] INFO:Plotting -- RooAbsPdf::plotOn(model) indirectly selected PDF components: (sig)
0x7ffd606ee538 RooAddPdf::model = 0.898614/1 [Auto,Clean]
0x7ffd606ef030/V- RooChebychev::bkg = 0.798919 [Auto,Dirty]
0x7ffd606eec48/V- RooRealVar::x = 5
0x7ffd606f0fe8/V- RooRealVar::a0 = 0.441701 +/- 0.073185
0x7ffd606f0c00/V- RooRealVar::a1 = 0.201081 +/- 0.117613
0x7ffd606ef550/V- RooRealVar::nbkg = 504.206 +/- 39.3107
0x7ffd606f0108/V- RooAddPdf::sig = 1/1 [Auto,Clean]
0x7ffd606f20f0/V- RooGaussian::sig1 = 1 [Auto,Dirty]
0x7ffd606eec48/V- RooRealVar::x = 5
0x7ffd606efd20/V- RooRealVar::mean = 5
0x7ffd606f17b8/V- RooRealVar::sigma1 = 0.5
0x7ffd606f0818/V- RooRealVar::sig1frac = 0.837341 +/- 0.116841
0x7ffd606f1ba0/V- RooGaussian::sig2 = 1 [Auto,Dirty]
0x7ffd606eec48/V- RooRealVar::x = 5
0x7ffd606efd20/V- RooRealVar::mean = 5
0x7ffd606f13d0/V- RooRealVar::sigma2 = 1
0x7ffd606ef938/V- RooRealVar::nsig = 495.799 +/- 39.2054
#include "RooRealVar.h"
#include "RooDataSet.h"
#include "RooGaussian.h"
#include "RooChebychev.h"
#include "RooAddPdf.h"
#include "RooExtendPdf.h"
#include "TCanvas.h"
#include "TAxis.h"
#include "RooPlot.h"
using namespace RooFit;
{
// S e t u p c o m p o n e n t p d f s
// ---------------------------------------
// Declare observable x
RooRealVar x("x", "x", 0, 10);
// Create two Gaussian PDFs g1(x,mean1,sigma) anf g2(x,mean2,sigma) and their parameters
RooRealVar mean("mean", "mean of gaussians", 5);
RooRealVar sigma1("sigma1", "width of gaussians", 0.5);
RooRealVar sigma2("sigma2", "width of gaussians", 1);
RooGaussian sig1("sig1", "Signal component 1", x, mean, sigma1);
RooGaussian sig2("sig2", "Signal component 2", x, mean, sigma2);
// Build Chebychev polynomial pdf
RooRealVar a0("a0", "a0", 0.5, 0., 1.);
RooRealVar a1("a1", "a1", 0.2, 0., 1.);
RooChebychev bkg("bkg", "Background", x, RooArgSet(a0, a1));
// Sum the signal components into a composite signal pdf
RooRealVar sig1frac("sig1frac", "fraction of component 1 in signal", 0.8, 0., 1.);
RooAddPdf sig("sig", "Signal", RooArgList(sig1, sig2), sig1frac);
//----------------
// M E T H O D 1
//================
// C o n s t r u c t e x t e n d e d c o m p o s i t e m o d e l
// -------------------------------------------------------------------
// Sum the composite signal and background into an extended pdf nsig*sig+nbkg*bkg
RooRealVar nsig("nsig", "number of signal events", 500, 0., 10000);
RooRealVar nbkg("nbkg", "number of background events", 500, 0, 10000);
RooAddPdf model("model", "(g1+g2)+a", RooArgList(bkg, sig), RooArgList(nbkg, nsig));
// S a m p l e , f i t a n d p l o t e x t e n d e d m o d e l
// ---------------------------------------------------------------------
// Generate a data sample of expected number events in x from model
// = model.expectedEvents() = nsig+nbkg
RooDataSet *data = model.generate(x);
// Fit model to data, extended ML term automatically included
model.fitTo(*data);
// Plot data and PDF overlaid, use expected number of events for pdf projection normalization
// rather than observed number of events (==data->numEntries())
RooPlot *xframe = x.frame(Title("extended ML fit example"));
data->plotOn(xframe);
model.plotOn(xframe, Normalization(1.0, RooAbsReal::RelativeExpected));
// Overlay the background component of model with a dashed line
model.plotOn(xframe, Components(bkg), LineStyle(kDashed), Normalization(1.0, RooAbsReal::RelativeExpected));
// Overlay the background+sig2 components of model with a dotted line
model.plotOn(xframe, Components(RooArgSet(bkg, sig2)), LineStyle(kDotted),
Normalization(1.0, RooAbsReal::RelativeExpected));
// Print structure of composite pdf
model.Print("t");
//----------------
// M E T H O D 2
//================
// C o n s t r u c t e x t e n d e d c o m p o n e n t s f i r s t
// ---------------------------------------------------------------------
// Associated nsig/nbkg as expected number of events with sig/bkg
RooExtendPdf esig("esig", "extended signal pdf", sig, nsig);
RooExtendPdf ebkg("ebkg", "extended background pdf", bkg, nbkg);
// S u m e x t e n d e d c o m p o n e n t s w i t h o u t c o e f s
// -------------------------------------------------------------------------
// Construct sum of two extended pdf (no coefficients required)
RooAddPdf model2("model2", "(g1+g2)+a", RooArgList(ebkg, esig));
// Draw the frame on the canvas
new TCanvas("rf202_composite", "rf202_composite", 600, 600);
gPad->SetLeftMargin(0.15);
xframe->GetYaxis()->SetTitleOffset(1.4);
xframe->Draw();
}
@ kDashed
Definition TAttLine.h:48
@ kDotted
Definition TAttLine.h:48
#define gPad
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
RooAddPdf is an efficient implementation of a sum of PDFs of the form.
Definition RooAddPdf.h:32
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition RooArgList.h:22
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:35
Chebychev polynomial p.d.f.
RooDataSet is a container class to hold unbinned data.
Definition RooDataSet.h:36
RooExtendPdf is a wrapper around an existing PDF that adds a parameteric extended likelihood term to ...
Plain Gaussian p.d.f.
Definition RooGaussian.h:24
A RooPlot is a plot frame and a container for graphics objects within that frame.
Definition RooPlot.h:44
TAxis * GetYaxis() const
Definition RooPlot.cxx:1278
static RooPlot * frame(const RooAbsRealLValue &var, Double_t xmin, Double_t xmax, Int_t nBins)
Create a new frame for a given variable in x.
Definition RooPlot.cxx:249
virtual void Print(Option_t *options=0) const
Print TNamed name and title.
Definition RooPlot.h:131
virtual void Draw(Option_t *options=0)
Draw this plot and all of the elements it contains.
Definition RooPlot.cxx:661
RooRealVar represents a variable that can be changed from the outside.
Definition RooRealVar.h:39
virtual void SetTitleOffset(Float_t offset=1)
Set distance between the axis and the axis title.
Definition TAttAxis.cxx:302
The Canvas class.
Definition TCanvas.h:23
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
Date
July 2008
Author
Wouter Verkerke

Definition in file rf202_extendedmlfit.C.