Logo ROOT   6.10/09
Reference Guide
rf311_rangeplot.cxx
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////////
2 //
3 // 'MULTIDIMENSIONAL MODELS' RooFit tutorial macro #310
4 //
5 // Projecting p.d.f and data ranges in continuous observables
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 "RooProdPdf.h"
20 #include "RooAddPdf.h"
21 #include "RooPolynomial.h"
22 #include "TCanvas.h"
23 #include "RooPlot.h"
24 using namespace RooFit ;
25 
26 
27 class TestBasic311 : public RooFitTestUnit
28 {
29 public:
30  TestBasic311(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("Data and p.d.f projection in sub range",refFile,writeRef,verbose) {} ;
31  Bool_t testCode() {
32 
33  // C r e a t e 3 D p d f a n d d a t a
34  // -------------------------------------------
35 
36  // Create observables
37  RooRealVar x("x","x",-5,5) ;
38  RooRealVar y("y","y",-5,5) ;
39  RooRealVar z("z","z",-5,5) ;
40 
41  // Create signal pdf gauss(x)*gauss(y)*gauss(z)
42  RooGaussian gx("gx","gx",x,RooConst(0),RooConst(1)) ;
43  RooGaussian gy("gy","gy",y,RooConst(0),RooConst(1)) ;
44  RooGaussian gz("gz","gz",z,RooConst(0),RooConst(1)) ;
45  RooProdPdf sig("sig","sig",RooArgSet(gx,gy,gz)) ;
46 
47  // Create background pdf poly(x)*poly(y)*poly(z)
48  RooPolynomial px("px","px",x,RooArgSet(RooConst(-0.1),RooConst(0.004))) ;
49  RooPolynomial py("py","py",y,RooArgSet(RooConst(0.1),RooConst(-0.004))) ;
50  RooPolynomial pz("pz","pz",z) ;
51  RooProdPdf bkg("bkg","bkg",RooArgSet(px,py,pz)) ;
52 
53  // Create composite pdf sig+bkg
54  RooRealVar fsig("fsig","signal fraction",0.1,0.,1.) ;
55  RooAddPdf model("model","model",RooArgList(sig,bkg),fsig) ;
56 
57  RooDataSet* data = model.generate(RooArgSet(x,y,z),20000) ;
58 
59 
60 
61  // P r o j e c t p d f a n d d a t a o n x
62  // -------------------------------------------------
63 
64  // Make plain projection of data and pdf on x observable
65  RooPlot* frame = x.frame(Title("Projection of 3D data and pdf on X"),Bins(40)) ;
66  data->plotOn(frame) ;
67  model.plotOn(frame) ;
68 
69 
70 
71  // 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
72  // ----------------------------------------------------------------------------------
73 
74  // Define signal region in y and z observables
75  y.setRange("sigRegion",-1,1) ;
76  z.setRange("sigRegion",-1,1) ;
77 
78  // Make plot frame
79  RooPlot* frame2 = x.frame(Title("Same projection on X in signal range of (Y,Z)"),Bins(40)) ;
80 
81  // Plot subset of data in which all observables are inside "sigRegion"
82  // For observables that do not have an explicit "sigRegion" range defined (e.g. observable)
83  // an implicit definition is used that is identical to the full range (i.e. [-5,5] for x)
84  data->plotOn(frame2,CutRange("sigRegion")) ;
85 
86  // Project model on x, integrating projected observables (y,z) only in "sigRegion"
87  model.plotOn(frame2,ProjectionRange("sigRegion")) ;
88 
89 
90  regPlot(frame,"rf311_plot1") ;
91  regPlot(frame2,"rf312_plot2") ;
92 
93  delete data ;
94 
95  return kTRUE ;
96  }
97 } ;
RooAddPdf is an efficient implementation of a sum of PDFs of the form.
Definition: RooAddPdf.h:29
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
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
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
bool verbose
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)
you should not use this method at all Int_t Int_t z
Definition: TRolke.cxx:630
RooConstVar & RooConst(Double_t val)
RooCmdArg Bins(Int_t nbin)
RooPolynomial implements a polynomial p.d.f of the form By default coefficient a_0 is chosen to be 1...
Definition: RooPolynomial.h:28
const Bool_t kTRUE
Definition: RtypesCore.h:91