Logo ROOT  
Reference Guide
No Matches
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_roofit
3/// \notebook
4/// Multidimensional models: full pdf with per-event errors
6/// \macro_code
8/// \date July 2008
9/// \author Wouter Verkerke
11#include "RooRealVar.h"
12#include "RooDataSet.h"
13#include "RooGaussian.h"
14#include "RooGaussModel.h"
15#include "RooDecay.h"
16#include "RooLandau.h"
17#include "RooProdPdf.h"
18#include "RooHistPdf.h"
19#include "RooPlot.h"
20#include "TCanvas.h"
21#include "TAxis.h"
22#include "TH1.h"
23using namespace RooFit;
27 // B - p h y s i c s p d f w i t h p e r - e v e n t G a u s s i a n r e s o l u t i o n
28 // ----------------------------------------------------------------------------------------------
30 // Observables
31 RooRealVar dt("dt", "dt", -10, 10);
32 RooRealVar dterr("dterr", "per-event error on dt", 0.01, 10);
34 // Build a gaussian resolution model scaled by the per-event error = gauss(dt,bias,sigma*dterr)
35 RooRealVar bias("bias", "bias", 0, -10, 10);
36 RooRealVar sigma("sigma", "per-event error scale factor", 1, 0.1, 10);
37 RooGaussModel gm("gm1", "gauss model scaled bt per-event error", dt, bias, sigma, dterr);
39 // Construct decay(dt) (x) gauss1(dt|dterr)
40 RooRealVar tau("tau", "tau", 1.548);
41 RooDecay decay_gm("decay_gm", "decay", dt, tau, gm, RooDecay::DoubleSided);
43 // C o n s t r u c t e m p i r i c a l p d f f o r p e r - e v e n t e r r o r
44 // -----------------------------------------------------------------
46 // Use landau pdf to get empirical distribution with long tail
47 RooLandau pdfDtErr("pdfDtErr", "pdfDtErr", dterr, 1.0, 0.25);
48 std::unique_ptr<RooDataSet> expDataDterr{pdfDtErr.generate(dterr, 10000)};
50 // Construct a histogram pdf to describe the shape of the dtErr distribution
51 std::unique_ptr<RooDataHist> expHistDterr{expDataDterr->binnedClone()};
52 RooHistPdf pdfErr("pdfErr", "pdfErr", dterr, *expHistDterr);
54 // C o n s t r u c t c o n d i t i o n a l p r o d u c t d e c a y _ d m ( d t | d t e r r ) * p d f ( d t e r
55 // r )
56 // ----------------------------------------------------------------------------------------------------------------------
58 // Construct production of conditional decay_dm(dt|dterr) with empirical pdfErr(dterr)
59 RooProdPdf model("model", "model", pdfErr, Conditional(decay_gm, dt));
61 // (Alternatively you could also use the landau shape pdfDtErr)
62 // RooProdPdf model("model","model",pdfDtErr,Conditional(decay_gm,dt)) ;
64 // S a m p l e, f i t a n d p l o t p r o d u c t m o d e l
65 // ------------------------------------------------------------------
67 // Specify external dataset with dterr values to use model_dm as conditional pdf
68 std::unique_ptr<RooDataSet> data{model.generate({dt, dterr}, 10000)};
70 // F i t c o n d i t i o n a l d e c a y _ d m ( d t | d t e r r )
71 // ---------------------------------------------------------------------
73 // Specify dterr as conditional observable
74 model.fitTo(*data, PrintLevel(-1));
76 // P l o t c o n d i t i o n a l d e c a y _ d m ( d t | d t e r r )
77 // ---------------------------------------------------------------------
79 // Make two-dimensional plot of conditional pdf in (dt,dterr)
80 TH1 *hh_model = model.createHistogram("hh_model", dt, Binning(50), YVar(dterr, Binning(50)));
81 hh_model->SetLineColor(kBlue);
83 // Make projection of data an dt
84 RooPlot *frame = dt.frame(Title("Projection of model(dt|dterr) on dt"));
85 data->plotOn(frame);
86 model.plotOn(frame);
88 // Draw all frames on canvas
89 TCanvas *c = new TCanvas("rf307_fullpereventerrors", "rf307_fullperventerrors", 800, 400);
90 c->Divide(2);
91 c->cd(1);
92 gPad->SetLeftMargin(0.20);
93 hh_model->GetZaxis()->SetTitleOffset(2.5);
94 hh_model->Draw("surf");
95 c->cd(2);
96 gPad->SetLeftMargin(0.15);
97 frame->GetYaxis()->SetTitleOffset(1.6);
98 frame->Draw();
#define c(i)
Definition RSha256.hxx:101
@ kBlue
Definition Rtypes.h:66
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
#define gPad
Single or double sided decay function that can be analytically convolved with any RooResolutionModel ...
Definition RooDecay.h:22
@ DoubleSided
Definition RooDecay.h:25
Class RooGaussModel implements a RooResolutionModel that models a Gaussian distribution.
A propability density function sampled from a multidimensional histogram.
Definition RooHistPdf.h:30
Landau distribution p.d.f.
Definition RooLandau.h:24
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
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 SetLineColor(Color_t lcolor)
Set the line color.
Definition TAttLine.h:40
The Canvas class.
Definition TCanvas.h:23
TH1 is the base class of all histogram classes in ROOT.
Definition TH1.h:59
TAxis * GetZaxis()
Definition TH1.h:326
void Draw(Option_t *option="") override
Draw this histogram with options.
Definition TH1.cxx:3066
RooCmdArg YVar(const RooAbsRealLValue &var, const RooCmdArg &arg={})
RooCmdArg Conditional(const RooArgSet &pdfSet, const RooArgSet &depSet, bool depsAreCond=false)
RooCmdArg PrintLevel(Int_t code)
RooCmdArg Binning(const RooAbsBinning &binning)
const Double_t sigma
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