Logo ROOT  
Reference Guide
rf306_condpereventerrors.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_roofit
3/// \notebook
4/// Multidimensional models: conditional pdf with per-event errors
5///
6/// \macro_image
7/// \macro_output
8/// \macro_code
9///
10/// \date July 2008
11/// \author Wouter Verkerke
12
13#include "RooRealVar.h"
14#include "RooDataSet.h"
15#include "RooGaussian.h"
16#include "RooGaussModel.h"
17#include "RooDecay.h"
18#include "RooLandau.h"
19#include "RooPlot.h"
20#include "TCanvas.h"
21#include "TAxis.h"
22#include "TH1.h"
23using namespace RooFit;
24
26{
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 // ----------------------------------------------------------------------------------------------
29
30 // Observables
31 RooRealVar dt("dt", "dt", -10, 10);
32 RooRealVar dterr("dterr", "per-event error on dt", 0.01, 10);
33
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);
38
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);
42
43 // C o n s t r u c t f a k e ' e x t e r n a l ' d a t a w i t h p e r - e v e n t e r r o r
44 // ------------------------------------------------------------------------------------------------------
45
46 // Use landau pdf to get somewhat realistic distribution with long tail
47 RooLandau pdfDtErr("pdfDtErr", "pdfDtErr", dterr, 1.0, 0.25);
48 RooDataSet *expDataDterr = pdfDtErr.generate(dterr, 10000);
49
50 // S a m p l e d a t a f r o m c o n d i t i o n a l d e c a y _ g m ( d t | d t e r r )
51 // ---------------------------------------------------------------------------------------------
52
53 // Specify external dataset with dterr values to use decay_dm as conditional pdf
54 RooDataSet *data = decay_gm.generate(dt, ProtoData(*expDataDterr));
55
56 // 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 )
57 // ---------------------------------------------------------------------
58
59 // Specify dterr as conditional observable
60 decay_gm.fitTo(*data, ConditionalObservables(dterr));
61
62 // 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 )
63 // ---------------------------------------------------------------------
64
65 // Make two-dimensional plot of conditional pdf in (dt,dterr)
66 TH1 *hh_decay = decay_gm.createHistogram("hh_decay", dt, Binning(50), YVar(dterr, Binning(50)));
67 hh_decay->SetLineColor(kBlue);
68
69 // Plot decay_gm(dt|dterr) at various values of dterr
70 RooPlot *frame = dt.frame(Title("Slices of decay(dt|dterr) at various dterr"));
71 for (Int_t ibin = 0; ibin < 100; ibin += 20) {
72 dterr.setBin(ibin);
73 decay_gm.plotOn(frame, Normalization(5.));
74 }
75
76 // Make projection of data an dt
77 RooPlot *frame2 = dt.frame(Title("Projection of decay(dt|dterr) on dt"));
78 data->plotOn(frame2);
79
80 // Make projection of decay(dt|dterr) on dt.
81 //
82 // Instead of integrating out dterr, make a weighted average of curves
83 // at values dterr_i as given in the external dataset.
84 // (The true argument bins the data before projection to speed up the process)
85 decay_gm.plotOn(frame2, ProjWData(*expDataDterr, true));
86
87 // Draw all frames on canvas
88 TCanvas *c = new TCanvas("rf306_condpereventerrors", "rf306_condperventerrors", 1200, 400);
89 c->Divide(3);
90 c->cd(1);
91 gPad->SetLeftMargin(0.20);
92 hh_decay->GetZaxis()->SetTitleOffset(2.5);
93 hh_decay->Draw("surf");
94 c->cd(2);
95 gPad->SetLeftMargin(0.15);
96 frame->GetYaxis()->SetTitleOffset(1.6);
97 frame->Draw();
98 c->cd(3);
99 gPad->SetLeftMargin(0.15);
100 frame2->GetYaxis()->SetTitleOffset(1.6);
101 frame2->Draw();
102}
#define c(i)
Definition: RSha256.hxx:101
int Int_t
Definition: RtypesCore.h:45
@ 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
Definition: TVirtualPad.h:302
RooDataSet is a container class to hold unbinned data.
Definition: RooDataSet.h:55
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.
Definition: RooGaussModel.h:25
Landau distribution p.d.f.
Definition: RooLandau.h:24
A RooPlot is a 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:239
TAxis * GetYaxis() const
Definition: RooPlot.cxx:1279
void Draw(Option_t *options=nullptr) override
Draw this plot and all of the elements it contains.
Definition: RooPlot.cxx:652
RooRealVar represents a variable that can be changed from the outside.
Definition: RooRealVar.h:40
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:58
TAxis * GetZaxis()
Definition: TH1.h:324
void Draw(Option_t *option="") override
Draw this histogram with options.
Definition: TH1.cxx:3060
RooCmdArg YVar(const RooAbsRealLValue &var, const RooCmdArg &arg=RooCmdArg::none())
RooCmdArg ConditionalObservables(Args_t &&... argsOrArgSet)
Create a RooCmdArg to declare conditional observables.
RooCmdArg ProtoData(const RooDataSet &protoData, bool randomizeOrder=false, bool resample=false)
RooCmdArg Binning(const RooAbsBinning &binning)
RooCmdArg ProjWData(const RooAbsData &projData, bool binData=false)
RooCmdArg Normalization(double scaleFactor)
const Double_t sigma
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Definition: Common.h:18
const char * Title
Definition: TXMLSetup.cxx:68