# Rf 3 0 6_Condpereventerrors¶

Multidimensional models: conditional 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 "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



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 fake 'external' data with per-event error¶

Use landau pdf to get somewhat realistic distribution with long tail

In [6]:
RooLandau pdfDtErr("pdfDtErr", "pdfDtErr", dterr, RooConst(1), RooConst(0.25));


## Sample data from conditional decay_gm(dt|dterr)¶

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

In [7]:
RooDataSet *data = decay_gm.generate(dt, ProtoData(*expDataDterr));


## Fit conditional decay_dm(dt|dterr)¶

Specify dterr as conditional observable

In [8]:
decay_gm.fitTo(*data, ConditionalObservables(dterr));

input_line_61:2:18: error: reference to 'data' is ambiguous
decay_gm.fitTo(*data, ConditionalObservables(dterr));
^
input_line_60:2:14: note: candidate found by name lookup is '__cling_N525::data'
^
/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 [9]:
TH1 *hh_decay = decay_gm.createHistogram("hh_decay", dt, Binning(50), YVar(dterr, Binning(50)));
hh_decay->SetLineColor(kBlue);

[#1] INFO:NumericIntegration -- RooRealIntegral::init(gm1_conv_exp(-abs(@0)/@1)_dt_tau_[decay_gm]_Int[dt,dterr]) using numeric integrator RooIntegrator1D to calculate Int(dterr)


Plot decay_gm(dt|dterr) at various values of dterr

In [10]:
RooPlot *frame = dt.frame(Title("Slices of decay(dt|dterr) at various dterr"));
for (Int_t ibin = 0; ibin < 100; ibin += 20) {
dterr.setBin(ibin);
decay_gm.plotOn(frame, Normalization(5.));
}


Make projection of data an dt

In [11]:
RooPlot *frame2 = dt.frame(Title("Projection of decay(dt|dterr) on dt"));
data->plotOn(frame2);

input_line_64:3:1: error: reference to 'data' is ambiguous
data->plotOn(frame2);
^
input_line_60:2:14: note: candidate found by name lookup is '__cling_N525::data'
^
/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
^


Make projection of decay(dt|dterr) on dt.

Instead of integrating out dterr, make a weighted average of curves at values dterr_i as given in the external dataset. (The kTRUE argument bins the data before projection to speed up the process)

In [12]:
decay_gm.plotOn(frame2, ProjWData(*expDataDterr, kTRUE));

input_line_65:2:26: error: cannot initialize an array element of type 'void *' with an rvalue of type 'RooCmdArg (*)(const RooAbsData &, Bool_t)' (aka 'RooCmdArg (*)(const RooAbsData &, bool)')
^~~~~~~~~
input_line_65:2:51: error: cannot initialize an array element of type 'void *' with an rvalue of type 'const Bool_t *' (aka 'const bool *')
^~~~~


Draw all frames on canvas

In [13]:
TCanvas *c = new TCanvas("rf306_condpereventerrors", "rf306_condperventerrors", 1200, 400);
c->Divide(3);
c->cd(1);
hh_decay->GetZaxis()->SetTitleOffset(2.5);
hh_decay->Draw("surf");
c->cd(2);
frame->GetYaxis()->SetTitleOffset(1.6);
frame->Draw();
c->cd(3);
frame2->GetYaxis()->SetTitleOffset(1.6);
frame2->Draw();

IncrementalExecutor::executeFunction: symbol '_ZN5cling7runtime8internal9EvaluateTIvEET_PNS1_15DynamicExprInfoEPN5clang11DeclContextE' unresolved while linking function '_GLOBAL__sub_I_cling_module_282'!
You are probably missing the definition of void cling::runtime::internal::EvaluateT<void>(cling::runtime::internal::DynamicExprInfo*, clang::DeclContext*)
Maybe you need to load the corresponding shared library?
Error in <HandleInterpreterException>: Trying to dereference null pointer or trying to call routine taking non-null arguments
Execution of your code was aborted.
input_line_66:3:1: warning: null passed to a callee that requires a non-null argument [-Wnonnull]
c->Divide(3);
^


Draw all canvases

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