Logo ROOT  
Reference Guide
rf702_efficiencyfit_2D.C File Reference

Detailed Description

View in nbviewer Open in SWAN

Special p.d.f.'s: unbinned maximum likelihood fit of an efficiency eff(x) function to a dataset D(x,cut), cut is a category encoding a selection whose 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
[#0] WARNING:Generation -- RooAcceptReject::ctor(effPdf_Int[]_Norm[cut]) WARNING: performing accept/reject sampling on a p.d.f in 2 dimensions without prior knowledge on maximum value of p.d.f. Determining maximum value by taking 200000 trial samples. If p.d.f contains sharp peaks smaller than average distance between trial sampling points these may be missed and p.d.f. may be sampled incorrectly.
[#0] WARNING:Generation -- RooAcceptReject::ctor(effPdf_Int[]_Norm[cut]): WARNING: 200000 trial samples requested by p.d.f for 2-dimensional accept/reject sampling, this may take some time
[#1] INFO:Minization -- RooMinimizer::optimizeConst: activating const optimization
**********
** 1 **SET PRINT 1
**********
**********
** 2 **SET NOGRAD
**********
PARAMETER DEFINITIONS:
NO. NAME VALUE STEP SIZE LIMITS
1 ax 6.00000e-01 1.00000e-01 0.00000e+00 1.00000e+00
2 ay 2.00000e-01 1.00000e-01 0.00000e+00 1.00000e+00
3 cx -1.00000e+00 2.00000e+00 -1.00000e+01 1.00000e+01
4 cy -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 2000 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=5447.45 FROM MIGRAD STATUS=INITIATE 16 CALLS 17 TOTAL
EDM= unknown STRATEGY= 1 NO ERROR MATRIX
EXT PARAMETER CURRENT GUESS STEP FIRST
NO. NAME VALUE ERROR SIZE DERIVATIVE
1 ax 6.00000e-01 1.00000e-01 2.05758e-01 2.07611e+01
2 ay 2.00000e-01 1.00000e-01 2.57889e-01 6.35766e+01
3 cx -1.00000e+00 2.00000e+00 2.02430e-01 3.98906e+02
4 cy -1.00000e+00 2.00000e+00 2.02430e-01 -1.37299e+02
ERR DEF= 0.5
MIGRAD MINIMIZATION HAS CONVERGED.
MIGRAD WILL VERIFY CONVERGENCE AND ERROR MATRIX.
COVARIANCE MATRIX CALCULATED SUCCESSFULLY
FCN=5441.98 FROM MIGRAD STATUS=CONVERGED 79 CALLS 80 TOTAL
EDM=2.10777e-05 STRATEGY= 1 ERROR MATRIX ACCURATE
EXT PARAMETER STEP FIRST
NO. NAME VALUE ERROR SIZE DERIVATIVE
1 ax 6.10442e-01 9.85749e-03 8.90018e-04 1.06907e-01
2 ay 2.06325e-01 1.06819e-02 9.76478e-04 2.34590e-01
3 cx -1.13975e+00 5.97322e-02 2.77681e-04 6.58278e-02
4 cy -5.30427e-01 2.15761e-01 8.34515e-04 -2.03235e-01
ERR DEF= 0.5
EXTERNAL ERROR MATRIX. NDIM= 25 NPAR= 4 ERR DEF=0.5
9.718e-05 -2.419e-05 -2.246e-04 2.779e-05
-2.419e-05 1.141e-04 -2.514e-05 1.447e-03
-2.246e-04 -2.514e-05 3.568e-03 1.894e-05
2.779e-05 1.447e-03 1.894e-05 4.656e-02
PARAMETER CORRELATION COEFFICIENTS
NO. GLOBAL 1 2 3 4
1 0.50176 1.000 -0.230 -0.381 0.013
2 0.68607 -0.230 1.000 -0.039 0.628
3 0.42040 -0.381 -0.039 1.000 0.001
4 0.65573 0.013 0.628 0.001 1.000
**********
** 7 **SET ERR 0.5
**********
**********
** 8 **SET PRINT 1
**********
**********
** 9 **HESSE 2000
**********
COVARIANCE MATRIX CALCULATED SUCCESSFULLY
FCN=5441.98 FROM HESSE STATUS=OK 23 CALLS 103 TOTAL
EDM=2.1074e-05 STRATEGY= 1 ERROR MATRIX ACCURATE
EXT PARAMETER INTERNAL INTERNAL
NO. NAME VALUE ERROR STEP SIZE VALUE
1 ax 6.10442e-01 9.85365e-03 1.78004e-04 2.22720e-01
2 ay 2.06325e-01 1.06842e-02 1.95296e-04 -6.27781e-01
3 cx -1.13975e+00 5.97056e-02 5.55362e-05 -1.14223e-01
4 cy -5.30427e-01 2.15797e-01 1.66903e-04 -5.30676e-02
ERR DEF= 0.5
EXTERNAL ERROR MATRIX. NDIM= 25 NPAR= 4 ERR DEF=0.5
9.711e-05 -2.421e-05 -2.238e-04 2.765e-05
-2.421e-05 1.142e-04 -2.530e-05 1.448e-03
-2.238e-04 -2.530e-05 3.565e-03 1.965e-05
2.765e-05 1.448e-03 1.965e-05 4.658e-02
PARAMETER CORRELATION COEFFICIENTS
NO. GLOBAL 1 2 3 4
1 0.50117 1.000 -0.230 -0.380 0.013
2 0.68624 -0.230 1.000 -0.040 0.628
3 0.41953 -0.380 -0.040 1.000 0.002
4 0.65587 0.013 0.628 0.002 1.000
[#1] INFO:Minization -- RooMinimizer::optimizeConst: deactivating const optimization
[#0] WARNING:InputArguments -- RooAbsReal::createHistogram(effFunc) WARNING extended mode requested for a non-pdf object, ignored
#include "RooRealVar.h"
#include "RooDataSet.h"
#include "RooGaussian.h"
#include "RooConstVar.h"
#include "RooCategory.h"
#include "RooEfficiency.h"
#include "RooPolynomial.h"
#include "RooProdPdf.h"
#include "RooFormulaVar.h"
#include "TCanvas.h"
#include "TAxis.h"
#include "TH1.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 , y )
// -----------------------------------------------------------------------
// Declare variables x,mean,sigma with associated name, title, initial value and allowed range
RooRealVar x("x", "x", -10, 10);
RooRealVar y("y", "y", -10, 10);
// Efficiency function eff(x;a,b)
RooRealVar ax("ax", "ay", 0.6, 0, 1);
RooRealVar bx("bx", "by", 5);
RooRealVar cx("cx", "cy", -1, -10, 10);
RooRealVar ay("ay", "ay", 0.2, 0, 1);
RooRealVar by("by", "by", 5);
RooRealVar cy("cy", "cy", -1, -10, 10);
RooFormulaVar effFunc("effFunc", "((1-ax)+ax*cos((x-cx)/bx))*((1-ay)+ay*cos((y-cy)/by))",
RooArgList(ax, bx, cx, x, ay, by, cy, y));
// Acceptance state cut (1 or 0)
RooCategory cut("cut", "cutr", { {"accept", 1}, {"reject", 0} });
// 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 , y )
// ---------------------------------------------------------------------------------------------
// 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 , y , 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 shapePdfX("shapePdfX", "shapePdfX", x, RooConst(flat ? 0 : -0.095));
RooPolynomial shapePdfY("shapePdfY", "shapePdfY", y, RooConst(flat ? 0 : +0.095));
RooProdPdf shapePdf("shapePdf", "shapePdf", RooArgSet(shapePdfX, shapePdfY));
RooProdPdf model("model", "model", shapePdf, Conditional(effPdf, cut));
// Generate some toy data from model
RooDataSet *data = model.generate(RooArgSet(x, y, 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(RooArgSet(x, y)));
// P l o t f i t t e d , d a t a e f f i c i e n c y
// --------------------------------------------------------
// Make 2D histograms of all data, selected data and efficiency function
TH1 *hh_data_all = data->createHistogram("hh_data_all", x, Binning(8), YVar(y, Binning(8)));
TH1 *hh_data_sel = data->createHistogram("hh_data_sel", x, Binning(8), YVar(y, Binning(8)), Cut("cut==cut::accept"));
TH1 *hh_eff = effFunc.createHistogram("hh_eff", x, Binning(50), YVar(y, Binning(50)));
// Some adjustment for good visualization
hh_data_all->SetMinimum(0);
hh_data_sel->SetMinimum(0);
hh_eff->SetMinimum(0);
hh_eff->SetLineColor(kBlue);
// Draw all frames on a canvas
TCanvas *ca = new TCanvas("rf702_efficiency_2D", "rf702_efficiency_2D", 1200, 400);
ca->Divide(3);
ca->cd(1);
gPad->SetLeftMargin(0.15);
hh_data_all->GetZaxis()->SetTitleOffset(1.8);
hh_data_all->Draw("lego");
ca->cd(2);
gPad->SetLeftMargin(0.15);
hh_data_sel->GetZaxis()->SetTitleOffset(1.8);
hh_data_sel->Draw("lego");
ca->cd(3);
gPad->SetLeftMargin(0.15);
hh_eff->GetZaxis()->SetTitleOffset(1.8);
hh_eff->Draw("surf");
return;
}
const Bool_t kFALSE
Definition: RtypesCore.h:90
bool Bool_t
Definition: RtypesCore.h:61
@ kBlue
Definition: Rtypes.h:64
#define gPad
Definition: TVirtualPad.h:287
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgList.h:21
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:28
RooCategory is an object to represent discrete states.
Definition: RooCategory.h:23
RooDataSet is a container class to hold unbinned data.
Definition: RooDataSet.h:33
TH2F * createHistogram(const RooAbsRealLValue &var1, const RooAbsRealLValue &var2, const char *cuts="", const char *name="hist") const
Create a TH2F histogram of the distribution of the specified variable using this dataset.
RooEfficiency is a PDF helper class to fit efficiencies parameterized by a supplied function F.
Definition: RooEfficiency.h:27
A RooFormulaVar is a generic implementation of a real-valued object, which takes a RooArgList of serv...
Definition: RooFormulaVar.h:29
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 variable that can be changed from the outside.
Definition: RooRealVar.h:35
virtual void SetTitleOffset(Float_t offset=1)
Set distance between the axis and the axis title.
Definition: TAttAxis.cxx:294
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition: TAttLine.h:40
The Canvas class.
Definition: TCanvas.h:27
TVirtualPad * cd(Int_t subpadnumber=0)
Set current canvas & pad.
Definition: TCanvas.cxx:701
The TH1 histogram class.
Definition: TH1.h:56
TAxis * GetZaxis()
Definition: TH1.h:318
virtual void SetMinimum(Double_t minimum=-1111)
Definition: TH1.h:395
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2998
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:1165
RooCmdArg YVar(const RooAbsRealLValue &var, const RooCmdArg &arg=RooCmdArg::none())
RooConstVar & RooConst(Double_t val)
RooCmdArg Conditional(const RooArgSet &pdfSet, const RooArgSet &depSet, Bool_t depsAreCond=kFALSE)
RooCmdArg ConditionalObservables(const RooArgSet &set)
RooCmdArg Binning(const RooAbsBinning &binning)
RooCmdArg Cut(const char *cutSpec)
Double_t y[n]
Definition: legend1.C:17
Double_t x[n]
Definition: legend1.C:17
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Date
February 2018
Authors
Clemens Lange, Wouter Verkerke (C++ version)

Definition in file rf702_efficiencyfit_2D.C.