Logo ROOT  
Reference Guide
rf306_condpereventerrors.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_roofit
3 /// \notebook
4 ///
5 /// Multidimensional models: conditional p.d.f. with per-event errors
6 ///
7 /// \macro_image
8 /// \macro_output
9 /// \macro_code
10 ///
11 /// \date 07/2008
12 /// \author Wouter Verkerke
13 
14 #include "RooRealVar.h"
15 #include "RooDataSet.h"
16 #include "RooGaussian.h"
17 #include "RooConstVar.h"
18 #include "RooGaussModel.h"
19 #include "RooDecay.h"
20 #include "RooLandau.h"
21 #include "RooPlot.h"
22 #include "TCanvas.h"
23 #include "TAxis.h"
24 #include "TH2D.h"
25 using namespace RooFit;
26 
28 {
29  // 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
30  // ----------------------------------------------------------------------------------------------
31 
32  // Observables
33  RooRealVar dt("dt", "dt", -10, 10);
34  RooRealVar dterr("dterr", "per-event error on dt", 0.01, 10);
35 
36  // Build a gaussian resolution model scaled by the per-event error = gauss(dt,bias,sigma*dterr)
37  RooRealVar bias("bias", "bias", 0, -10, 10);
38  RooRealVar sigma("sigma", "per-event error scale factor", 1, 0.1, 10);
39  RooGaussModel gm("gm1", "gauss model scaled bt per-event error", dt, bias, sigma, dterr);
40 
41  // Construct decay(dt) (x) gauss1(dt|dterr)
42  RooRealVar tau("tau", "tau", 1.548);
43  RooDecay decay_gm("decay_gm", "decay", dt, tau, gm, RooDecay::DoubleSided);
44 
45  // 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
46  // ------------------------------------------------------------------------------------------------------
47 
48  // Use landau p.d.f to get somewhat realistic distribution with long tail
49  RooLandau pdfDtErr("pdfDtErr", "pdfDtErr", dterr, RooConst(1), RooConst(0.25));
50  RooDataSet *expDataDterr = pdfDtErr.generate(dterr, 10000);
51 
52  // 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 )
53  // ---------------------------------------------------------------------------------------------
54 
55  // Specify external dataset with dterr values to use decay_dm as conditional p.d.f.
56  RooDataSet *data = decay_gm.generate(dt, ProtoData(*expDataDterr));
57 
58  // 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 )
59  // ---------------------------------------------------------------------
60 
61  // Specify dterr as conditional observable
62  decay_gm.fitTo(*data, ConditionalObservables(dterr));
63 
64  // 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 )
65  // ---------------------------------------------------------------------
66 
67  // Make two-dimensional plot of conditional p.d.f in (dt,dterr)
68  TH1 *hh_decay = decay_gm.createHistogram("hh_decay", dt, Binning(50), YVar(dterr, Binning(50)));
69  hh_decay->SetLineColor(kBlue);
70 
71  // Plot decay_gm(dt|dterr) at various values of dterr
72  RooPlot *frame = dt.frame(Title("Slices of decay(dt|dterr) at various dterr"));
73  for (Int_t ibin = 0; ibin < 100; ibin += 20) {
74  dterr.setBin(ibin);
75  decay_gm.plotOn(frame, Normalization(5.));
76  }
77 
78  // Make projection of data an dt
79  RooPlot *frame2 = dt.frame(Title("Projection of decay(dt|dterr) on dt"));
80  data->plotOn(frame2);
81 
82  // Make projection of decay(dt|dterr) on dt.
83  //
84  // Instead of integrating out dterr, make a weighted average of curves
85  // at values dterr_i as given in the external dataset.
86  // (The kTRUE argument bins the data before projection to speed up the process)
87  decay_gm.plotOn(frame2, ProjWData(*expDataDterr, kTRUE));
88 
89  // Draw all frames on canvas
90  TCanvas *c = new TCanvas("rf306_condpereventerrors", "rf306_condperventerrors", 1200, 400);
91  c->Divide(3);
92  c->cd(1);
93  gPad->SetLeftMargin(0.20);
94  hh_decay->GetZaxis()->SetTitleOffset(2.5);
95  hh_decay->Draw("surf");
96  c->cd(2);
97  gPad->SetLeftMargin(0.15);
98  frame->GetYaxis()->SetTitleOffset(1.6);
99  frame->Draw();
100  c->cd(3);
101  gPad->SetLeftMargin(0.15);
102  frame2->GetYaxis()->SetTitleOffset(1.6);
103  frame2->Draw();
104 }
c
#define c(i)
Definition: RSha256.hxx:119
RooPlot::Draw
virtual void Draw(Option_t *options=0)
Draw this plot and all of the elements it contains.
Definition: RooPlot.cxx:691
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
RooGaussModel.h
RooFit::ProjWData
RooCmdArg ProjWData(const RooAbsData &projData, Bool_t binData=kFALSE)
Definition: RooGlobalFunc.cxx:46
RooLandau
Definition: RooLandau.h:24
RooGaussian.h
RooFit::Normalization
RooCmdArg Normalization(Double_t scaleFactor)
Definition: RooGlobalFunc.cxx:51
RooDecay.h
TCanvas.h
RooFit::YVar
RooCmdArg YVar(const RooAbsRealLValue &var, const RooCmdArg &arg=RooCmdArg::none())
Definition: RooGlobalFunc.cxx:240
RooFit::Binning
RooCmdArg Binning(const RooAbsBinning &binning)
Definition: RooGlobalFunc.cxx:82
TH1::GetZaxis
TAxis * GetZaxis()
Definition: TH1.h:319
RooDataSet.h
RooPlot::frame
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
rf306_condpereventerrors
Definition: rf306_condpereventerrors.py:1
RooFit::ProtoData
RooCmdArg ProtoData(const RooDataSet &protoData, Bool_t randomizeOrder=kFALSE, Bool_t resample=kFALSE)
Definition: RooGlobalFunc.cxx:228
TH2D.h
RooFit
Definition: RooCFunction1Binding.h:29
RooDecay
Definition: RooDecay.h:22
RooAbsData::plotOn
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
Definition: RooAbsData.cxx:547
RooPlot.h
RooPlot::GetYaxis
TAxis * GetYaxis() const
Definition: RooPlot.cxx:1256
RooPlot
Definition: RooPlot.h:44
RooRealVar.h
RooFit::ConditionalObservables
RooCmdArg ConditionalObservables(const RooArgSet &set)
Definition: RooGlobalFunc.cxx:196
RooConstVar.h
sigma
const Double_t sigma
Definition: h1analysisProxy.h:11
TCanvas
Definition: TCanvas.h:23
TAxis.h
TH1
Definition: TH1.h:57
kBlue
@ kBlue
Definition: Rtypes.h:66
gPad
#define gPad
Definition: TVirtualPad.h:287
RooDataSet
Definition: RooDataSet.h:33
TAttAxis::SetTitleOffset
virtual void SetTitleOffset(Float_t offset=1)
Set distance between the axis and the axis title.
Definition: TAttAxis.cxx:293
RooDecay::DoubleSided
@ DoubleSided
Definition: RooDecay.h:53
RooRealVar
Definition: RooRealVar.h:35
RooGaussModel
Definition: RooGaussModel.h:26
RooFit::Title
RooCmdArg Title(const char *name)
Definition: RooGlobalFunc.cxx:173
int
RooLandau.h
TH1::Draw
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2997
RooFit::RooConst
RooConstVar & RooConst(Double_t val)
Definition: RooGlobalFunc.cxx:341