ROOT   Reference Guide
Searching...
No Matches
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 "RooConstVar.h"
18#include "RooDecay.h"
19#include "RooLandau.h"
20#include "RooPlot.h"
21#include "TCanvas.h"
22#include "TAxis.h"
23#include "TH1.h"
24using namespace RooFit;
25
27{
28 // 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
29 // ----------------------------------------------------------------------------------------------
30
31 // Observables
32 RooRealVar dt("dt", "dt", -10, 10);
33 RooRealVar dterr("dterr", "per-event error on dt", 0.01, 10);
34
35 // Build a gaussian resolution model scaled by the per-event error = gauss(dt,bias,sigma*dterr)
36 RooRealVar bias("bias", "bias", 0, -10, 10);
37 RooRealVar sigma("sigma", "per-event error scale factor", 1, 0.1, 10);
38 RooGaussModel gm("gm1", "gauss model scaled bt per-event error", dt, bias, sigma, dterr);
39
40 // Construct decay(dt) (x) gauss1(dt|dterr)
41 RooRealVar tau("tau", "tau", 1.548);
42 RooDecay decay_gm("decay_gm", "decay", dt, tau, gm, RooDecay::DoubleSided);
43
44 // 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
45 // ------------------------------------------------------------------------------------------------------
46
47 // Use landau pdf to get somewhat realistic distribution with long tail
48 RooLandau pdfDtErr("pdfDtErr", "pdfDtErr", dterr, RooConst(1), RooConst(0.25));
49 RooDataSet *expDataDterr = pdfDtErr.generate(dterr, 10000);
50
51 // 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 )
52 // ---------------------------------------------------------------------------------------------
53
54 // Specify external dataset with dterr values to use decay_dm as conditional pdf
55 RooDataSet *data = decay_gm.generate(dt, ProtoData(*expDataDterr));
56
57 // 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 )
58 // ---------------------------------------------------------------------
59
60 // Specify dterr as conditional observable
61 decay_gm.fitTo(*data, ConditionalObservables(dterr));
62
63 // 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 )
64 // ---------------------------------------------------------------------
65
66 // Make two-dimensional plot of conditional pdf in (dt,dterr)
67 TH1 *hh_decay = decay_gm.createHistogram("hh_decay", dt, Binning(50), YVar(dterr, Binning(50)));
68 hh_decay->SetLineColor(kBlue);
69
70 // Plot decay_gm(dt|dterr) at various values of dterr
71 RooPlot *frame = dt.frame(Title("Slices of decay(dt|dterr) at various dterr"));
72 for (Int_t ibin = 0; ibin < 100; ibin += 20) {
73 dterr.setBin(ibin);
74 decay_gm.plotOn(frame, Normalization(5.));
75 }
76
77 // Make projection of data an dt
78 RooPlot *frame2 = dt.frame(Title("Projection of decay(dt|dterr) on dt"));
79 data->plotOn(frame2);
80
81 // Make projection of decay(dt|dterr) on dt.
82 //
83 // Instead of integrating out dterr, make a weighted average of curves
84 // at values dterr_i as given in the external dataset.
85 // (The kTRUE argument bins the data before projection to speed up the process)
87
88 // Draw all frames on canvas
89 TCanvas *c = new TCanvas("rf306_condpereventerrors", "rf306_condperventerrors", 1200, 400);
90 c->Divide(3);
91 c->cd(1);
93 hh_decay->GetZaxis()->SetTitleOffset(2.5);
94 hh_decay->Draw("surf");
95 c->cd(2);
97 frame->GetYaxis()->SetTitleOffset(1.6);
98 frame->Draw();
99 c->cd(3);
101 frame2->GetYaxis()->SetTitleOffset(1.6);
102 frame2->Draw();
103}
#define c(i)
Definition RSha256.hxx:101
int Int_t
Definition RtypesCore.h:45
const Bool_t kTRUE
Definition RtypesCore.h:91
@ kBlue
Definition Rtypes.h:66
virtual RooPlot * plotOn(RooPlot *frame, const RooCmdArg &arg1=RooCmdArg::none(), const RooCmdArg &arg2=RooCmdArg::none(), const RooCmdArg &arg3=RooCmdArg::none(), const RooCmdArg &arg4=RooCmdArg::none(), const RooCmdArg &arg5=RooCmdArg::none(), const RooCmdArg &arg6=RooCmdArg::none(), const RooCmdArg &arg7=RooCmdArg::none(), const RooCmdArg &arg8=RooCmdArg::none()) const
RooDataSet is a container class to hold unbinned data.
Definition RooDataSet.h:33
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.
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:44
TAxis * GetYaxis() const
Definition RooPlot.cxx:1263
static RooPlot * frame(const RooAbsRealLValue &var, Double_t xmin, Double_t xmax, Int_t nBins)
Create a new frame for a given variable in x.
Definition RooPlot.cxx:249
virtual void Draw(Option_t *options=0)
Draw this plot and all of the elements it contains.
Definition RooPlot.cxx:691
RooRealVar represents a variable that can be changed from the outside.
Definition RooRealVar.h:39
virtual void SetTitleOffset(Float_t offset=1)
Set distance between the axis and the axis title.
Definition TAttAxis.cxx:293
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:322
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition TH1.cxx:3073
RooCmdArg YVar(const RooAbsRealLValue &var, const RooCmdArg &arg=RooCmdArg::none())
RooConstVar & RooConst(Double_t val)
RooCmdArg ConditionalObservables(const RooArgSet &set)
RooCmdArg ProtoData(const RooDataSet &protoData, Bool_t randomizeOrder=kFALSE, Bool_t resample=kFALSE)
RooCmdArg ProjWData(const RooAbsData &projData, Bool_t binData=kFALSE)
RooCmdArg Binning(const RooAbsBinning &binning)
RooCmdArg Normalization(Double_t scaleFactor)
const Double_t sigma
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
const char * Title
Definition TXMLSetup.cxx:68