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

Detailed Description

View in nbviewer Open in SWAN 'SPECIAL PDFS' RooFit tutorial macro #701

Unbinned maximum likelihood fit of an efficiency eff(x) function to a dataset D(x,cut), where cut is a category encoding a selection, of which the efficiency as function of x should be described by eff(x)

␛[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 **SET PRINT 1
**********
**********
** 2 **SET NOGRAD
**********
PARAMETER DEFINITIONS:
NO. NAME VALUE STEP SIZE LIMITS
1 a 4.00000e-01 1.00000e-01 0.00000e+00 1.00000e+00
2 c -1.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=3887.11 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 4.00000e-01 1.00000e-01 2.05758e-01 8.51804e+01
2 c -1.00000e+00 2.00000e+00 2.02430e-01 7.00873e+01
ERR DEF= 0.5
MIGRAD MINIMIZATION HAS CONVERGED.
MIGRAD WILL VERIFY CONVERGENCE AND ERROR MATRIX.
COVARIANCE MATRIX CALCULATED SUCCESSFULLY
FCN=3886.26 FROM MIGRAD STATUS=CONVERGED 30 CALLS 31 TOTAL
EDM=2.277e-05 STRATEGY= 1 ERROR MATRIX ACCURATE
EXT PARAMETER STEP FIRST
NO. NAME VALUE ERROR SIZE DERIVATIVE
1 a 3.89817e-01 8.14984e-03 6.58343e-04 -2.65715e-01
2 c -9.91750e-01 6.56208e-02 2.58326e-04 -6.57933e-01
ERR DEF= 0.5
EXTERNAL ERROR MATRIX. NDIM= 25 NPAR= 2 ERR DEF=0.5
6.643e-05 -2.189e-04
-2.189e-04 4.306e-03
PARAMETER CORRELATION COEFFICIENTS
NO. GLOBAL 1 2
1 0.40934 1.000 -0.409
2 0.40934 -0.409 1.000
**********
** 7 **SET ERR 0.5
**********
**********
** 8 **SET PRINT 1
**********
**********
** 9 **HESSE 1000
**********
COVARIANCE MATRIX CALCULATED SUCCESSFULLY
FCN=3886.26 FROM HESSE STATUS=OK 10 CALLS 41 TOTAL
EDM=2.27764e-05 STRATEGY= 1 ERROR MATRIX ACCURATE
EXT PARAMETER INTERNAL INTERNAL
NO. NAME VALUE ERROR STEP SIZE VALUE
1 a 3.89817e-01 8.14814e-03 1.31669e-04 -2.22191e-01
2 c -9.91750e-01 6.56071e-02 5.16653e-05 -9.93383e-02
ERR DEF= 0.5
EXTERNAL ERROR MATRIX. NDIM= 25 NPAR= 2 ERR DEF=0.5
6.640e-05 -2.186e-04
-2.186e-04 4.304e-03
PARAMETER CORRELATION COEFFICIENTS
NO. GLOBAL 1 2
1 0.40891 1.000 -0.409
2 0.40891 -0.409 1.000
[#1] INFO:Minization -- RooMinimizer::optimizeConst: deactivating const optimization
[#1] INFO:Plotting -- RooTreeData::plotOn: plotting 8176 events out of 10000 total events
#include "RooRealVar.h"
#include "RooDataSet.h"
#include "RooGaussian.h"
#include "RooConstVar.h"
#include "RooFormulaVar.h"
#include "RooProdPdf.h"
#include "RooEfficiency.h"
#include "RooPolynomial.h"
#include "RooCategory.h"
#include "TCanvas.h"
#include "TAxis.h"
#include "RooPlot.h"
using namespace RooFit ;
{
// C o n s t r u c t e f f i c i e n c y f u n c t i o n e ( x )
// -------------------------------------------------------------------
// Declare variables x,mean,sigma with associated name, title, initial value and allowed range
RooRealVar x("x","x",-10,10) ;
// Efficiency function eff(x;a,b)
RooRealVar a("a","a",0.4,0,1) ;
RooRealVar b("b","b",5) ;
RooRealVar c("c","c",-1,-10,10) ;
RooFormulaVar effFunc("effFunc","(1-a)+a*cos((x-c)/b)",RooArgList(a,b,c,x)) ;
// C o n s t r u c t c o n d i t i o n a l e f f i c i e n c y p d f E ( c u t | x )
// ------------------------------------------------------------------------------------------
// Acceptance state cut (1 or 0)
RooCategory cut("cut","cutr") ;
cut.defineType("accept",1) ;
cut.defineType("reject",0) ;
// Construct efficiency p.d.f eff(cut|x)
RooEfficiency effPdf("effPdf","effPdf",effFunc,cut,"accept") ;
// G e n e r a t e d a t a ( x , c u t ) f r o m a t o y m o d e l
// -----------------------------------------------------------------------------
// Construct global shape p.d.f shape(x) and product model(x,cut) = eff(cut|x)*shape(x)
// (These are _only_ needed to generate some toy MC here to be used later)
RooPolynomial shapePdf("shapePdf","shapePdf",x,RooConst(-0.095)) ;
RooProdPdf model("model","model",shapePdf,Conditional(effPdf,cut)) ;
// Generate some toy data from model
RooDataSet* data = model.generate(RooArgSet(x,cut),10000) ;
// F i t c o n d i t i o n a l e f f i c i e n c y p d f t o d a t a
// --------------------------------------------------------------------------
// Fit conditional efficiency p.d.f to data
effPdf.fitTo(*data,ConditionalObservables(x)) ;
// P l o t f i t t e d , d a t a e f f i c i e n c y
// --------------------------------------------------------
// Plot distribution of all events and accepted fraction of events on frame
RooPlot* frame1 = x.frame(Bins(20),Title("Data (all, accepted)")) ;
data->plotOn(frame1) ;
data->plotOn(frame1,Cut("cut==cut::accept"),MarkerColor(kRed),LineColor(kRed)) ;
// Plot accept/reject efficiency on data overlay fitted efficiency curve
RooPlot* frame2 = x.frame(Bins(20),Title("Fitted efficiency")) ;
data->plotOn(frame2,Efficiency(cut)) ; // needs ROOT version >= 5.21
effFunc.plotOn(frame2,LineColor(kRed)) ;
// Draw all frames on a canvas
TCanvas* ca = new TCanvas("rf701_efficiency","rf701_efficiency",800,400) ;
ca->Divide(2) ;
ca->cd(1) ; gPad->SetLeftMargin(0.15) ; frame1->GetYaxis()->SetTitleOffset(1.6) ; frame1->Draw() ;
ca->cd(2) ; gPad->SetLeftMargin(0.15) ; frame2->GetYaxis()->SetTitleOffset(1.4) ; frame2->Draw() ;
}
#define b(i)
Definition: RSha256.hxx:100
#define c(i)
Definition: RSha256.hxx:101
@ kRed
Definition: Rtypes.h:63
#define gPad
Definition: TVirtualPad.h:286
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:28
RooCategory represents a fundamental (non-derived) discrete value object.
Definition: RooCategory.h:24
RooDataSet is a container class to hold unbinned data.
Definition: RooDataSet.h:31
RooEfficiency is a PDF helper class to fit efficiencies parameterized by a supplied function F.
Definition: RooEfficiency.h:27
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
RooProdPdf is an efficient implementation of a product of PDFs of the form.
Definition: RooProdPdf.h:31
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
TVirtualPad * cd(Int_t subpadnumber=0)
Set current canvas & pad.
Definition: TCanvas.cxx:693
virtual void Divide(Int_t nx=1, Int_t ny=1, Float_t xmargin=0.01, Float_t ymargin=0.01, Int_t color=0)
Automatic pad generation by division.
Definition: TPad.cxx:1162
Double_t x[n]
Definition: legend1.C:17
RooCmdArg MarkerColor(Color_t color)
RooConstVar & RooConst(Double_t val)
RooCmdArg Cut(const char *cutSpec)
RooCmdArg ConditionalObservables(const RooArgSet &set)
RooCmdArg LineColor(Color_t color)
RooCmdArg Efficiency(const RooCategory &cat)
RooCmdArg Conditional(const RooArgSet &pdfSet, const RooArgSet &depSet, Bool_t depsAreCond=kFALSE)
RooCmdArg Bins(Int_t nbin)
const char * Title
Definition: TXMLSetup.cxx:67
auto * a
Definition: textangle.C:12
Author
07/2008 - Wouter Verkerke

Definition in file rf701_efficiencyfit.C.