Logo ROOT  
Reference Guide
No Matches
rs701_BayesianCalculator.C File Reference

Detailed Description

View in nbviewer Open in SWAN
Bayesian calculator: basic example

Bayesian Result using a Flat prior
0.9% CL central interval: [ 0.50606 - 6.89326 ] or 0.95% CL limits
Bayesian Result using a 1/sqrt(s) prior
0.9% CL central interval: [ 0.0746294 - 5.85425 ] or 0.95% CL limits
#include "RooRealVar.h"
#include "RooWorkspace.h"
#include "RooDataSet.h"
#include "RooPlot.h"
#include "RooMsgService.h"
#include "TCanvas.h"
using namespace RooFit;
using namespace RooStats;
void rs701_BayesianCalculator(bool useBkg = true, double confLevel = 0.90)
RooAbsPdf *model = w->pdf("model"); // pdf*priorNuisance
RooArgSet nuisanceParameters(*(w->var("b")));
RooAbsRealLValue *POI = w->var("s");
RooAbsPdf *priorPOI = (RooAbsPdf *)w->factory("Uniform::priorPOI(s)");
RooAbsPdf *priorPOI2 = (RooAbsPdf *)w->factory("GenericPdf::priorPOI2('1/sqrt(@0)',s)");
w->factory("n[3]"); // observed number of events
// create a data set with n observed events
RooDataSet data("data", "", RooArgSet(*(w->var("x")), *(w->var("n"))), "n");
data.add(RooArgSet(*(w->var("x"))), w->var("n")->getVal());
// to suppress messages when pdf goes to zero
RooArgSet *nuisPar = nullptr;
if (useBkg)
nuisPar = &nuisanceParameters;
// if (!useBkg) ((RooRealVar *)w->var("b"))->setVal(0);
double size = 1. - confLevel;
std::cout << "\nBayesian Result using a Flat prior " << std::endl;
BayesianCalculator bcalc(data, *model, RooArgSet(*POI), *priorPOI, nuisPar);
SimpleInterval *interval = bcalc.GetInterval();
double cl = bcalc.ConfidenceLevel();
std::cout << cl << "% CL central interval: [ " << interval->LowerLimit() << " - " << interval->UpperLimit()
<< " ] or " << cl + (1. - cl) / 2 << "% CL limits\n";
RooPlot *plot = bcalc.GetPosteriorPlot();
TCanvas *c1 = new TCanvas("c1", "Bayesian Calculator Result");
c1->Divide(1, 2);
std::cout << "\nBayesian Result using a 1/sqrt(s) prior " << std::endl;
BayesianCalculator bcalc2(data, *model, RooArgSet(*POI), *priorPOI2, nuisPar);
SimpleInterval *interval2 = bcalc2.GetInterval();
cl = bcalc2.ConfidenceLevel();
std::cout << cl << "% CL central interval: [ " << interval2->LowerLimit() << " - " << interval2->UpperLimit()
<< " ] or " << cl + (1. - cl) / 2 << "% CL limits\n";
RooPlot *plot2 = bcalc2.GetPosteriorPlot();
// observe one event while expecting one background event -> the 95% CL upper limit on s is 4.10
// observe one event while expecting zero background event -> the 95% CL upper limit on s is 4.74
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
winID h TVirtualViewer3D TVirtualGLPainter char TVirtualGLPainter plot
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
#define gPad
Abstract interface for all probability density functions.
Definition RooAbsPdf.h:40
RooAbsRealLValue is the common abstract base class for objects that represent a real value that may a...
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:55
RooDataSet is a container class to hold unbinned data.
Definition RooDataSet.h:57
static RooMsgService & instance()
Return reference to singleton instance.
void setGlobalKillBelow(RooFit::MsgLevel level)
A RooPlot is a plot frame and a container for graphics objects within that frame.
Definition RooPlot.h:43
void Draw(Option_t *options=nullptr) override
Draw this plot and all of the elements it contains.
Definition RooPlot.cxx:652
BayesianCalculator is a concrete implementation of IntervalCalculator, providing the computation of a...
SimpleInterval is a concrete implementation of the ConfInterval interface.
virtual double UpperLimit()
return the interval upper limit
double ConfidenceLevel() const override
return the confidence interval
virtual double LowerLimit()
return the interval lower limit
Persistable container for RooFit projects.
The Canvas class.
Definition TCanvas.h:23
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
Definition TObject.cxx:274
return c1
Definition legend1.C:41
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Definition JSONIO.h:26
Namespace for the RooStats classes.
Definition Asimov.h:19
Gregory Schott

Definition in file rs701_BayesianCalculator.C.