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

Detailed Description

View in nbviewer Open in SWAN
Special pdf's: 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)

#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", { {"accept", 1}, {"reject", 0} });
// Construct efficiency pdf 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 pdf 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
std::unique_ptr<RooDataSet> data{model.generate({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 pdf to data
effPdf.fitTo(*data, ConditionalObservables(x), PrintLevel(-1));
// 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);
frame1->GetYaxis()->SetTitleOffset(1.6);
frame1->Draw();
ca->cd(2);
frame2->GetYaxis()->SetTitleOffset(1.4);
frame2->Draw();
}
#define b(i)
Definition RSha256.hxx:100
#define c(i)
Definition RSha256.hxx:101
#define a(i)
Definition RSha256.hxx:99
@ kRed
Definition Rtypes.h:66
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
#define gPad
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition RooArgList.h:22
Object to represent discrete states.
Definition RooCategory.h:28
A PDF helper class to fit efficiencies parameterized by a supplied function F.
A RooFormulaVar is a generic implementation of a real-valued object, which takes a RooArgList of serv...
Plot frame and a container for graphics objects within that frame.
Definition RooPlot.h:43
static RooPlot * frame(const RooAbsRealLValue &var, double xmin, double xmax, Int_t nBins)
Create a new frame for a given variable in x.
Definition RooPlot.cxx:237
TAxis * GetYaxis() const
Definition RooPlot.cxx:1276
void Draw(Option_t *options=nullptr) override
Draw this plot and all of the elements it contains.
Definition RooPlot.cxx:649
RooPolynomial implements a polynomial p.d.f of the form.
Efficient implementation of a product of PDFs of the form.
Definition RooProdPdf.h:33
Variable that can be changed from the outside.
Definition RooRealVar.h:37
virtual void SetTitleOffset(Float_t offset=1)
Set distance between the axis and the axis title.
Definition TAttAxis.cxx:298
virtual void SetLeftMargin(Float_t leftmargin)
Set Pad left margin in fraction of the pad width.
Definition TAttPad.cxx:109
The Canvas class.
Definition TCanvas.h:23
TVirtualPad * cd(Int_t subpadnumber=0) override
Set current canvas & pad.
Definition TCanvas.cxx:719
void Divide(Int_t nx=1, Int_t ny=1, Float_t xmargin=0.01, Float_t ymargin=0.01, Int_t color=0) override
Automatic pad generation by division.
Definition TPad.cxx:1196
RooCmdArg Conditional(const RooArgSet &pdfSet, const RooArgSet &depSet, bool depsAreCond=false)
RooConstVar & RooConst(double val)
RooCmdArg Bins(Int_t nbin)
RooCmdArg PrintLevel(Int_t code)
RooCmdArg ConditionalObservables(Args_t &&... argsOrArgSet)
Create a RooCmdArg to declare conditional observables.
RooCmdArg MarkerColor(Color_t color)
RooCmdArg Cut(const char *cutSpec)
RooCmdArg Efficiency(const RooCategory &cat)
RooCmdArg LineColor(Color_t color)
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 JSONIO.h:26
const char * Title
Definition TXMLSetup.cxx:68
[#1] INFO:Fitting -- RooAbsPdf::fitTo(effPdf_over_effPdf_Int[cut]) fixing normalization set for coefficient determination to observables in data
[#1] INFO:Fitting -- using CPU computation library compiled with -mavx2
[#1] INFO:Fitting -- RooAddition::defaultErrorLevel(nll_effPdf_over_effPdf_Int[cut]_modelData) Summation contains a RooNLLVar, using its error level
[#1] INFO:Minimization -- RooAbsMinimizerFcn::setOptimizeConst: activating const optimization
[#1] INFO:Minimization -- RooAbsMinimizerFcn::setOptimizeConst: deactivating const optimization
[#1] INFO:Plotting -- RooTreeData::plotOn: plotting 8176 events out of 10000 total events
Date
July 2008
Author
Wouter Verkerke

Definition in file rf701_efficiencyfit.C.