Logo ROOT   6.10/09
Reference Guide
rf304_uncorrprod.cxx
Go to the documentation of this file.
1 /////////////////////////////////////////////////////////////////////////
2 //
3 // 'MULTIDIMENSIONAL MODELS' RooFit tutorial macro #304
4 //
5 // Simple uncorrelated multi-dimensional p.d.f.s
6 //
7 // pdf = gauss(x,mx,sx) * gauss(y,my,sy)
8 //
9 //
10 // 07/2008 - Wouter Verkerke
11 //
12 /////////////////////////////////////////////////////////////////////////
13 
14 #ifndef __CINT__
15 #include "RooGlobalFunc.h"
16 #endif
17 #include "RooRealVar.h"
18 #include "RooDataSet.h"
19 #include "RooGaussian.h"
20 #include "RooProdPdf.h"
21 #include "TCanvas.h"
22 #include "RooPlot.h"
23 using namespace RooFit ;
24 
25 
26 
27 class TestBasic304 : public RooFitTestUnit
28 {
29 public:
30  TestBasic304(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("Product operator p.d.f. with uncorrelated terms",refFile,writeRef,verbose) {} ;
31  Bool_t testCode() {
32 
33  // C r e a t e c o m p o n e n t p d f s i n x a n d y
34  // ----------------------------------------------------------------
35 
36  // Create two p.d.f.s gaussx(x,meanx,sigmax) gaussy(y,meany,sigmay) and its variables
37  RooRealVar x("x","x",-5,5) ;
38  RooRealVar y("y","y",-5,5) ;
39 
40  RooRealVar meanx("mean1","mean of gaussian x",2) ;
41  RooRealVar meany("mean2","mean of gaussian y",-2) ;
42  RooRealVar sigmax("sigmax","width of gaussian x",1) ;
43  RooRealVar sigmay("sigmay","width of gaussian y",5) ;
44 
45  RooGaussian gaussx("gaussx","gaussian PDF",x,meanx,sigmax) ;
46  RooGaussian gaussy("gaussy","gaussian PDF",y,meany,sigmay) ;
47 
48 
49 
50  // C o n s t r u c t u n c o r r e l a t e d p r o d u c t p d f
51  // -------------------------------------------------------------------
52 
53  // Multiply gaussx and gaussy into a two-dimensional p.d.f. gaussxy
54  RooProdPdf gaussxy("gaussxy","gaussx*gaussy",RooArgList(gaussx,gaussy)) ;
55 
56 
57 
58  // S a m p l e p d f , p l o t p r o j e c t i o n o n x a n d y
59  // ---------------------------------------------------------------------------
60 
61  // Generate 10000 events in x and y from gaussxy
62  RooDataSet *data = gaussxy.generate(RooArgSet(x,y),10000) ;
63 
64  // Plot x distribution of data and projection of gaussxy on x = Int(dy) gaussxy(x,y)
65  RooPlot* xframe = x.frame(Title("X projection of gauss(x)*gauss(y)")) ;
66  data->plotOn(xframe) ;
67  gaussxy.plotOn(xframe) ;
68 
69  // Plot x distribution of data and projection of gaussxy on y = Int(dx) gaussxy(x,y)
70  RooPlot* yframe = y.frame(Title("Y projection of gauss(x)*gauss(y)")) ;
71  data->plotOn(yframe) ;
72  gaussxy.plotOn(yframe) ;
73 
74  regPlot(xframe,"rf304_plot1") ;
75  regPlot(yframe,"rf304_plot2") ;
76 
77  delete data ;
78 
79  return kTRUE ;
80  }
81 } ;
82 
83 
84 
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
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
const Bool_t kTRUE
Definition: RtypesCore.h:91