Rf 3 0 7_Fullpereventerrors

Multidimensional models: full pdf with per-event errors

Author: Wouter Verkerke
This notebook tutorial was automatically generated with ROOTBOOK-izer from the macro found in the ROOT repository on Monday, January 17, 2022 at 09:58 AM.

In [1]:
%%cpp -d
#include "RooRealVar.h"
#include "RooDataSet.h"
#include "RooGaussian.h"
#include "RooGaussModel.h"
#include "RooConstVar.h"
#include "RooDecay.h"
#include "RooLandau.h"
#include "RooProdPdf.h"
#include "RooHistPdf.h"
#include "RooPlot.h"
#include "TCanvas.h"
#include "TAxis.h"
#include "TH1.h"
In [2]:
%%cpp -d
// This is a workaround to make sure the namespace is used inside functions
using namespace RooFit;

B-physics pdf with per-event gaussian resolution

Observables

In [3]:
RooRealVar dt("dt", "dt", -10, 10);
RooRealVar dterr("dterr", "per-event error on dt", 0.01, 10);
RooFit v3.60 -- Developed by Wouter Verkerke and David Kirkby 
                Copyright (C) 2000-2013 NIKHEF, University of California & Stanford University
                All rights reserved, please read http://roofit.sourceforge.net/license.txt

Build a gaussian resolution model scaled by the per-event error = gauss(dt,bias,sigma*dterr)

In [4]:
RooRealVar bias("bias", "bias", 0, -10, 10);
RooRealVar sigma("sigma", "per-event error scale factor", 1, 0.1, 10);
RooGaussModel gm("gm1", "gauss model scaled bt per-event error", dt, bias, sigma, dterr);

Construct decay(dt) (x) gauss1(dt|dterr)

In [5]:
RooRealVar tau("tau", "tau", 1.548);
RooDecay decay_gm("decay_gm", "decay", dt, tau, gm, RooDecay::DoubleSided);

Construct empirical pdf for per-event error

Use landau pdf to get empirical distribution with long tail

In [6]:
RooLandau pdfDtErr("pdfDtErr", "pdfDtErr", dterr, RooConst(1), RooConst(0.25));
RooDataSet *expDataDterr = pdfDtErr.generate(dterr, 10000);

Construct a histogram pdf to describe the shape of the dterr distribution

In [7]:
RooDataHist *expHistDterr = expDataDterr->binnedClone();
RooHistPdf pdfErr("pdfErr", "pdfErr", dterr, *expHistDterr);

Construct conditional product decay_dm(dt|dterr)*pdf(dter

r )

Construct production of conditional decay_dm(dt|dterr) with empirical pdferr(dterr)

In [8]:
RooProdPdf model("model", "model", pdfErr, Conditional(decay_gm, dt));

(alternatively you could also use the landau shape pdfdterr) RooProdPdf model("model","model",pdfDtErr,Conditional(decay_gm,dt)) ;

Sample, fit and plot product model

Specify external dataset with dterr values to use model_dm as conditional pdf

In [9]:
RooDataSet *data = model.generate(RooArgSet(dt, dterr), 10000);

Fit conditional decay_dm(dt|dterr)

Specify dterr as conditional observable

In [10]:
model.fitTo(*data);
input_line_63:2:15: error: reference to 'data' is ambiguous
 model.fitTo(*data);
              ^
input_line_62:2:14: note: candidate found by name lookup is '__cling_N527::data'
 RooDataSet *data = model.generate(RooArgSet(dt, dterr), 10000);
             ^
/usr/include/c++/9/bits/range_access.h:318:5: note: candidate found by name lookup is 'std::data'
    data(initializer_list<_Tp> __il) noexcept
    ^
/usr/include/c++/9/bits/range_access.h:289:5: note: candidate found by name lookup is 'std::data'
    data(_Container& __cont) noexcept(noexcept(__cont.data()))
    ^
/usr/include/c++/9/bits/range_access.h:299:5: note: candidate found by name lookup is 'std::data'
    data(const _Container& __cont) noexcept(noexcept(__cont.data()))
    ^
/usr/include/c++/9/bits/range_access.h:309:5: note: candidate found by name lookup is 'std::data'
    data(_Tp (&__array)[_Nm]) noexcept
    ^

Plot conditional decay_dm(dt|dterr)

Make two-dimensional plot of conditional pdf in (dt,dterr)

In [11]:
TH1 *hh_model = model.createHistogram("hh_model", dt, Binning(50), YVar(dterr, Binning(50)));
hh_model->SetLineColor(kBlue);

Make projection of data an dt

In [12]:
RooPlot *frame = dt.frame(Title("Projection of model(dt|dterr) on dt"));
data->plotOn(frame);
model.plotOn(frame);
input_line_65:3:1: error: reference to 'data' is ambiguous
data->plotOn(frame);
^
input_line_62:2:14: note: candidate found by name lookup is '__cling_N527::data'
 RooDataSet *data = model.generate(RooArgSet(dt, dterr), 10000);
             ^
/usr/include/c++/9/bits/range_access.h:318:5: note: candidate found by name lookup is 'std::data'
    data(initializer_list<_Tp> __il) noexcept
    ^
/usr/include/c++/9/bits/range_access.h:289:5: note: candidate found by name lookup is 'std::data'
    data(_Container& __cont) noexcept(noexcept(__cont.data()))
    ^
/usr/include/c++/9/bits/range_access.h:299:5: note: candidate found by name lookup is 'std::data'
    data(const _Container& __cont) noexcept(noexcept(__cont.data()))
    ^
/usr/include/c++/9/bits/range_access.h:309:5: note: candidate found by name lookup is 'std::data'
    data(_Tp (&__array)[_Nm]) noexcept
    ^

Draw all frames on canvas

In [13]:
TCanvas *c = new TCanvas("rf307_fullpereventerrors", "rf307_fullperventerrors", 800, 400);
c->Divide(2);
c->cd(1);
gPad->SetLeftMargin(0.20);
hh_model->GetZaxis()->SetTitleOffset(2.5);
hh_model->Draw("surf");
c->cd(2);
gPad->SetLeftMargin(0.15);
frame->GetYaxis()->SetTitleOffset(1.6);
frame->Draw();
input_line_67:2:3: error: use of undeclared identifier 'frame'
 (frame->GetYaxis()->SetTitleOffset(1.6000000000000001))
  ^
Error in <HandleInterpreterException>: Error evaluating expression (frame->GetYaxis()->SetTitleOffset(1.6000000000000001))
Execution of your code was aborted.

Draw all canvases

In [14]:
gROOT->GetListOfCanvases()->Draw()