ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
rf311_rangeplot.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_roofit
3 /// 'MULTIDIMENSIONAL MODELS' RooFit tutorial macro #310
4 ///
5 /// Projecting p.d.f and data ranges in continuous observables
6 ///
7 ///
8 ///
9 /// \macro_code
10 /// \author 07/2008 - Wouter Verkerke
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 "RooConstVar.h"
20 #include "RooProdPdf.h"
21 #include "RooAddPdf.h"
22 #include "RooPolynomial.h"
23 #include "TCanvas.h"
24 #include "TAxis.h"
25 #include "RooPlot.h"
26 using namespace RooFit ;
27 
28 
29 void rf311_rangeplot()
30 {
31 
32  // C r e a t e 3 D p d f a n d d a t a
33  // -------------------------------------------
34 
35  // Create observables
36  RooRealVar x("x","x",-5,5) ;
37  RooRealVar y("y","y",-5,5) ;
38  RooRealVar z("z","z",-5,5) ;
39 
40  // Create signal pdf gauss(x)*gauss(y)*gauss(z)
41  RooGaussian gx("gx","gx",x,RooConst(0),RooConst(1)) ;
42  RooGaussian gy("gy","gy",y,RooConst(0),RooConst(1)) ;
43  RooGaussian gz("gz","gz",z,RooConst(0),RooConst(1)) ;
44  RooProdPdf sig("sig","sig",RooArgSet(gx,gy,gz)) ;
45 
46  // Create background pdf poly(x)*poly(y)*poly(z)
47  RooPolynomial px("px","px",x,RooArgSet(RooConst(-0.1),RooConst(0.004))) ;
48  RooPolynomial py("py","py",y,RooArgSet(RooConst(0.1),RooConst(-0.004))) ;
49  RooPolynomial pz("pz","pz",z) ;
50  RooProdPdf bkg("bkg","bkg",RooArgSet(px,py,pz)) ;
51 
52  // Create composite pdf sig+bkg
53  RooRealVar fsig("fsig","signal fraction",0.1,0.,1.) ;
54  RooAddPdf model("model","model",RooArgList(sig,bkg),fsig) ;
55 
56  RooDataSet* data = model.generate(RooArgSet(x,y,z),20000) ;
57 
58 
59 
60  // P r o j e c t p d f a n d d a t a o n x
61  // -------------------------------------------------
62 
63  // Make plain projection of data and pdf on x observable
64  RooPlot* frame = x.frame(Title("Projection of 3D data and pdf on X"),Bins(40)) ;
65  data->plotOn(frame) ;
66  model.plotOn(frame) ;
67 
68 
69 
70  // P r o j e c t p d f a n d d a t a o n x i n s i g n a l r a n g e
71  // ----------------------------------------------------------------------------------
72 
73  // Define signal region in y and z observables
74  y.setRange("sigRegion",-1,1) ;
75  z.setRange("sigRegion",-1,1) ;
76 
77  // Make plot frame
78  RooPlot* frame2 = x.frame(Title("Same projection on X in signal range of (Y,Z)"),Bins(40)) ;
79 
80  // Plot subset of data in which all observables are inside "sigRegion"
81  // For observables that do not have an explicit "sigRegion" range defined (e.g. observable)
82  // an implicit definition is used that is identical to the full range (i.e. [-5,5] for x)
83  data->plotOn(frame2,CutRange("sigRegion")) ;
84 
85  // Project model on x, integrating projected observables (y,z) only in "sigRegion"
86  model.plotOn(frame2,ProjectionRange("sigRegion")) ;
87 
88 
89 
90  TCanvas* c = new TCanvas("rf311_rangeplot","rf310_rangeplot",800,400) ;
91  c->Divide(2) ;
92  c->cd(1) ; gPad->SetLeftMargin(0.15) ; frame->GetYaxis()->SetTitleOffset(1.4) ; frame->Draw() ;
93  c->cd(2) ; gPad->SetLeftMargin(0.15) ; frame2->GetYaxis()->SetTitleOffset(1.4) ; frame2->Draw() ;
94 
95 
96 }
virtual void SetTitleOffset(Float_t offset=1)
Set distance between the axis and the axis title Offset is a correction factor with respect to the "s...
Definition: TAttAxis.cxx:245
Float_t pz
Definition: hprod.C:33
RooProdPdf is an efficient implementation of a product of PDFs of the form.
Definition: RooProdPdf.h:31
TAxis * GetYaxis() const
Definition: RooPlot.cxx:1118
Float_t py
Definition: hprod.C:33
RooCmdArg Title(const char *name)
Double_t x[n]
Definition: legend1.C:17
Plain Gaussian p.d.f.
Definition: RooGaussian.h:25
friend class RooArgSet
Definition: RooAbsArg.h:469
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:626
Float_t z[5]
Definition: Ifit.C:16
RooRealVar represents a fundamental (non-derived) real valued object.
Definition: RooRealVar.h:37
RooCmdArg CutRange(const char *rangeName)
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
Double_t y[n]
Definition: legend1.C:17
RooCmdArg ProjectionRange(const char *rangeName)
Float_t px
Definition: hprod.C:33
RooConstVar & RooConst(Double_t val)
RooCmdArg Bins(Int_t nbin)
#define gPad
Definition: TVirtualPad.h:288
RooPolynomial implements a polynomial p.d.f of the form By default coefficient a_0 is chosen to be 1...
Definition: RooPolynomial.h:28
virtual void Draw(Option_t *options=0)
Draw this plot and all of the elements it contains.
Definition: RooPlot.cxx:559