Basic functionality: normalization and integration of pdfs, construction of cumulative distribution monodimensional functions
Author: Wouter Verkerke
This notebook tutorial was automatically generated with ROOTBOOK-izer from the macro found in the ROOT repository on Wednesday, April 17, 2024 at 11:17 AM.
%%cpp -d
#include "RooRealVar.h"
#include "RooGaussian.h"
#include "RooAbsReal.h"
#include "RooPlot.h"
#include "TCanvas.h"
#include "TAxis.h"
using namespace RooFit;
Create observables x,y
RooRealVar x("x", "x", -10, 10);
Create pdf gaussx(x,-2,3)
RooGaussian gx("gx", "gx", x, -2.0, 3.0);
Return 'raw' unnormalized value of gx
cout << "gx = " << gx.getVal() << endl;
gx = 0.800737
Return value of gx normalized over x in range [-10,10]
RooArgSet nset(x);
cout << "gx_Norm[x] = " << gx.getVal(&nset) << endl;
gx_Norm[x] = 0.106896
Create object representing integral over gx which is used to calculate gx_Norm[x] == gx / gx_Int[x]
std::unique_ptr<RooAbsReal> igx{gx.createIntegral(x)};
cout << "gx_Int[x] = " << igx->getVal() << endl;
gx_Int[x] = 7.49084
Define a range named "signal" in x from -5,5
x.setRange("signal", -5, 5);
[#1] INFO:Eval -- RooRealVar::setRange(x) new range named 'signal' created with bounds [-5,5]
Create an integral of gx_Norm[x] over x in range "signal" This is the fraction of of pdf gx_Norm[x] which is in the range named "signal"
std::unique_ptr<RooAbsReal> igx_sig{gx.createIntegral(x, NormSet(x), Range("signal"))};
cout << "gx_Int[x|signal]_Norm[x] = " << igx_sig->getVal() << endl;
gx_Int[x|signal]_Norm[x] = 0.834753
Create the cumulative distribution function of gx i.e. calculate Int[-10,x] gx(x') dx'
std::unique_ptr<RooAbsReal> gx_cdf{gx.createCdf(x)};
Plot cdf of gx versus x
RooPlot *frame = x.frame(Title("cdf of Gaussian pdf"));
gx_cdf->plotOn(frame);
Draw plot on canvas
new TCanvas("rf110_normintegration", "rf110_normintegration", 600, 600);
gPad->SetLeftMargin(0.15);
frame->GetYaxis()->SetTitleOffset(1.6);
frame->Draw();
Draw all canvases
%jsroot on
gROOT->GetListOfCanvases()->Draw()