Logo ROOT   6.14/05
Reference Guide
rf311_rangeplot.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_roofit
3 /// \notebook -js
4 /// 'MULTIDIMENSIONAL MODELS' RooFit tutorial macro #310
5 ///
6 /// Projecting p.d.f and data ranges in continuous observables
7 ///
8 /// \macro_image
9 /// \macro_output
10 /// \macro_code
11 /// \author 07/2008 - Wouter Verkerke
12 
13 
14 #include "RooRealVar.h"
15 #include "RooDataSet.h"
16 #include "RooGaussian.h"
17 #include "RooConstVar.h"
18 #include "RooProdPdf.h"
19 #include "RooAddPdf.h"
20 #include "RooPolynomial.h"
21 #include "TCanvas.h"
22 #include "TAxis.h"
23 #include "RooPlot.h"
24 using namespace RooFit ;
25 
26 
27 void rf311_rangeplot()
28 {
29 
30  // C r e a t e 3 D p d f a n d d a t a
31  // -------------------------------------------
32 
33  // Create observables
34  RooRealVar x("x","x",-5,5) ;
35  RooRealVar y("y","y",-5,5) ;
36  RooRealVar z("z","z",-5,5) ;
37 
38  // Create signal pdf gauss(x)*gauss(y)*gauss(z)
39  RooGaussian gx("gx","gx",x,RooConst(0),RooConst(1)) ;
40  RooGaussian gy("gy","gy",y,RooConst(0),RooConst(1)) ;
41  RooGaussian gz("gz","gz",z,RooConst(0),RooConst(1)) ;
42  RooProdPdf sig("sig","sig",RooArgSet(gx,gy,gz)) ;
43 
44  // Create background pdf poly(x)*poly(y)*poly(z)
45  RooPolynomial px("px","px",x,RooArgSet(RooConst(-0.1),RooConst(0.004))) ;
46  RooPolynomial py("py","py",y,RooArgSet(RooConst(0.1),RooConst(-0.004))) ;
47  RooPolynomial pz("pz","pz",z) ;
48  RooProdPdf bkg("bkg","bkg",RooArgSet(px,py,pz)) ;
49 
50  // Create composite pdf sig+bkg
51  RooRealVar fsig("fsig","signal fraction",0.1,0.,1.) ;
52  RooAddPdf model("model","model",RooArgList(sig,bkg),fsig) ;
53 
54  RooDataSet* data = model.generate(RooArgSet(x,y,z),20000) ;
55 
56 
57 
58  // P r o j e c t p d f a n d d a t a o n x
59  // -------------------------------------------------
60 
61  // Make plain projection of data and pdf on x observable
62  RooPlot* frame = x.frame(Title("Projection of 3D data and pdf on X"),Bins(40)) ;
63  data->plotOn(frame) ;
64  model.plotOn(frame) ;
65 
66 
67 
68  // 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
69  // ----------------------------------------------------------------------------------
70 
71  // Define signal region in y and z observables
72  y.setRange("sigRegion",-1,1) ;
73  z.setRange("sigRegion",-1,1) ;
74 
75  // Make plot frame
76  RooPlot* frame2 = x.frame(Title("Same projection on X in signal range of (Y,Z)"),Bins(40)) ;
77 
78  // Plot subset of data in which all observables are inside "sigRegion"
79  // For observables that do not have an explicit "sigRegion" range defined (e.g. observable)
80  // an implicit definition is used that is identical to the full range (i.e. [-5,5] for x)
81  data->plotOn(frame2,CutRange("sigRegion")) ;
82 
83  // Project model on x, integrating projected observables (y,z) only in "sigRegion"
84  model.plotOn(frame2,ProjectionRange("sigRegion")) ;
85 
86 
87 
88  TCanvas* c = new TCanvas("rf311_rangeplot","rf310_rangeplot",800,400) ;
89  c->Divide(2) ;
90  c->cd(1) ; gPad->SetLeftMargin(0.15) ; frame->GetYaxis()->SetTitleOffset(1.4) ; frame->Draw() ;
91  c->cd(2) ; gPad->SetLeftMargin(0.15) ; frame2->GetYaxis()->SetTitleOffset(1.4) ; frame2->Draw() ;
92 
93 
94 }
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:294
RooAddPdf is an efficient implementation of a sum of PDFs of the form.
Definition: RooAddPdf.h:29
TAxis * GetYaxis() const
Definition: RooPlot.cxx:1117
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:568
RooProdPdf is an efficient implementation of a product of PDFs of the form.
Definition: RooProdPdf.h:31
TVirtualPad * cd(Int_t subpadnumber=0)
Set current canvas & pad.
Definition: TCanvas.cxx:688
RooCmdArg Title(const char *name)
Double_t x[n]
Definition: legend1.C:17
Plain Gaussian p.d.f.
Definition: RooGaussian.h:25
RooRealVar represents a fundamental (non-derived) real valued object.
Definition: RooRealVar.h:36
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
The Canvas class.
Definition: TCanvas.h:31
Double_t y[n]
Definition: legend1.C:17
RooCmdArg ProjectionRange(const char *rangeName)
you should not use this method at all Int_t Int_t z
Definition: TRolke.cxx:630
RooConstVar & RooConst(Double_t val)
virtual void Divide(Int_t nx=1, Int_t ny=1, Float_t xmargin=0.01, Float_t ymargin=0.01, Int_t color=0)
Automatic pad generation by division.
Definition: TPad.cxx:1162
RooCmdArg Bins(Int_t nbin)
#define gPad
Definition: TVirtualPad.h:285
#define c(i)
Definition: RSha256.hxx:101
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:558