Logo ROOT   6.10/09
Reference Guide
rf307_fullpereventerrors.cxx
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////////
2 //
3 // 'MULTIDIMENSIONAL MODELS' RooFit tutorial macro #307
4 //
5 // Complete example with use of full p.d.f. with per-event errors
6 //
7 //
8 //
9 // 07/2008 - Wouter Verkerke
10 //
11 /////////////////////////////////////////////////////////////////////////
12 
13 #ifndef __CINT__
14 #include "RooGlobalFunc.h"
15 #endif
16 #include "RooRealVar.h"
17 #include "RooDataSet.h"
18 #include "RooGaussian.h"
19 #include "RooGaussModel.h"
20 #include "RooDecay.h"
21 #include "RooLandau.h"
22 #include "RooProdPdf.h"
23 #include "RooHistPdf.h"
24 #include "RooPlot.h"
25 #include "TCanvas.h"
26 #include "TH1.h"
27 using namespace RooFit ;
28 
29 
30 class TestBasic307 : public RooFitTestUnit
31 {
32 public:
33  TestBasic307(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("Full per-event error p.d.f. F(t|dt)G(dt)",refFile,writeRef,verbose) {} ;
34  Bool_t testCode() {
35 
36  // 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
37  // ----------------------------------------------------------------------------------------------
38 
39  // Observables
40  RooRealVar dt("dt","dt",-10,10) ;
41  RooRealVar dterr("dterr","per-event error on dt",0.1,10) ;
42 
43  // Build a gaussian resolution model scaled by the per-event error = gauss(dt,bias,sigma*dterr)
44  RooRealVar bias("bias","bias",0,-10,10) ;
45  RooRealVar sigma("sigma","per-event error scale factor",1,0.1,10) ;
46  RooGaussModel gm("gm1","gauss model scaled bt per-event error",dt,bias,sigma,dterr) ;
47 
48  // Construct decay(dt) (x) gauss1(dt|dterr)
49  RooRealVar tau("tau","tau",1.548) ;
50  RooDecay decay_gm("decay_gm","decay",dt,tau,gm,RooDecay::DoubleSided) ;
51 
52 
53 
54  // 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
55  // -----------------------------------------------------------------
56 
57  // Use landau p.d.f to get empirical distribution with long tail
58  RooLandau pdfDtErr("pdfDtErr","pdfDtErr",dterr,RooConst(1),RooConst(0.25)) ;
59  RooDataSet* expDataDterr = pdfDtErr.generate(dterr,10000) ;
60 
61  // Construct a histogram pdf to describe the shape of the dtErr distribution
62  RooDataHist* expHistDterr = expDataDterr->binnedClone() ;
63  RooHistPdf pdfErr("pdfErr","pdfErr",dterr,*expHistDterr) ;
64 
65 
66  // 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 r )
67  // ----------------------------------------------------------------------------------------------------------------------
68 
69  // Construct production of conditional decay_dm(dt|dterr) with empirical pdfErr(dterr)
70  RooProdPdf model("model","model",pdfErr,Conditional(decay_gm,dt)) ;
71 
72  // (Alternatively you could also use the landau shape pdfDtErr)
73  //RooProdPdf model("model","model",pdfDtErr,Conditional(decay_gm,dt)) ;
74 
75 
76 
77  // 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
78  // ------------------------------------------------------------------
79 
80  // Specify external dataset with dterr values to use model_dm as conditional p.d.f.
81  RooDataSet* data = model.generate(RooArgSet(dt,dterr),10000) ;
82 
83 
84 
85  // 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 )
86  // ---------------------------------------------------------------------
87 
88  // Specify dterr as conditional observable
89  model.fitTo(*data) ;
90 
91 
92 
93  // 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 )
94  // ---------------------------------------------------------------------
95 
96 
97  // Make projection of data an dt
98  RooPlot* frame = dt.frame(Title("Projection of model(dt|dterr) on dt")) ;
99  data->plotOn(frame) ;
100  model.plotOn(frame) ;
101 
102 
103  regPlot(frame,"rf307_plot1") ;
104 
105  delete expDataDterr ;
106  delete expHistDterr ;
107  delete data ;
108 
109  return kTRUE ;
110 
111  }
112 } ;
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
Plot dataset on specified frame.
Definition: RooAbsData.cxx:552
RooProdPdf is an efficient implementation of a product of PDFs of the form.
Definition: RooProdPdf.h:31
RooCmdArg Conditional(const RooArgSet &pdfSet, const RooArgSet &depSet, Bool_t depsAreCond=kFALSE)
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
Landau Distribution p.d.f.
Definition: RooLandau.h:24
RooCmdArg Title(const char *name)
RooDataSet is a container class to hold N-dimensional binned data.
Definition: RooDataHist.h:40
RooDataHist * binnedClone(const char *newName=0, const char *newTitle=0) const
Return binned clone of this dataset.
Definition: RooDataSet.cxx:981
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t tau
Definition: TRolke.cxx:630
const Double_t sigma
RooRealVar represents a fundamental (non-derived) real valued object.
Definition: RooRealVar.h:36
RooHistPdf implements a probablity density function sampled from a multidimensional histogram...
Definition: RooHistPdf.h:28
bool verbose
RooDataSet is a container class to hold unbinned data.
Definition: RooDataSet.h:29
A RooPlot is a plot frame and a container for graphics objects within that frame. ...
Definition: RooPlot.h:41
RooConstVar & RooConst(Double_t val)
const Bool_t kTRUE
Definition: RtypesCore.h:91
Single or double sided decay function that can be analytically convolved with any RooResolutionModel ...
Definition: RooDecay.h:22
Class RooGaussModel implements a RooResolutionModel that models a Gaussian distribution.
Definition: RooGaussModel.h:26