Logo ROOT   6.07/09
Reference Guide
rf305_condcorrprod.cxx
Go to the documentation of this file.
1 /////////////////////////////////////////////////////////////////////////
2 //
3 // 'MULTIDIMENSIONAL MODELS' RooFit tutorial macro #305
4 //
5 // Multi-dimensional p.d.f.s with conditional p.d.fs in product
6 //
7 // pdf = gauss(x,f(y),sx | y ) * gauss(y,ms,sx) with f(y) = a0 + a1*y
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 "RooPolyVar.h"
21 #include "RooProdPdf.h"
22 #include "RooPlot.h"
23 #include "TCanvas.h"
24 #include "TH1.h"
25 using namespace RooFit ;
26 
27 
28 
29 class TestBasic305 : public RooFitTestUnit
30 {
31 public:
32  TestBasic305(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("Product operator p.d.f. with conditional term",refFile,writeRef,verbose) {} ;
33  Bool_t testCode() {
34 
35  // C r e a t e c o n d i t i o n a l p d f g x ( x | y )
36  // -----------------------------------------------------------
37 
38  // Create observables
39  RooRealVar x("x","x",-5,5) ;
40  RooRealVar y("y","y",-5,5) ;
41 
42  // Create function f(y) = a0 + a1*y
43  RooRealVar a0("a0","a0",-0.5,-5,5) ;
44  RooRealVar a1("a1","a1",-0.5,-1,1) ;
45  RooPolyVar fy("fy","fy",y,RooArgSet(a0,a1)) ;
46 
47  // Create gaussx(x,f(y),sx)
48  RooRealVar sigmax("sigma","width of gaussian",0.5) ;
49  RooGaussian gaussx("gaussx","Gaussian in x with shifting mean in y",x,fy,sigmax) ;
50 
51 
52 
53  // C r e a t e p d f g y ( y )
54  // -----------------------------------------------------------
55 
56  // Create gaussy(y,0,5)
57  RooGaussian gaussy("gaussy","Gaussian in y",y,RooConst(0),RooConst(3)) ;
58 
59 
60 
61  // C r e a t e p r o d u c t g x ( x | y ) * g y ( y )
62  // -------------------------------------------------------
63 
64  // Create gaussx(x,sx|y) * gaussy(y)
65  RooProdPdf model("model","gaussx(x|y)*gaussy(y)",gaussy,Conditional(gaussx,x)) ;
66 
67 
68 
69  // S a m p l e , f i t a n d p l o t p r o d u c t p d f
70  // ---------------------------------------------------------------
71 
72  // Generate 1000 events in x and y from model
73  RooDataSet *data = model.generate(RooArgSet(x,y),10000) ;
74 
75  // Plot x distribution of data and projection of model on x = Int(dy) model(x,y)
76  RooPlot* xframe = x.frame() ;
77  data->plotOn(xframe) ;
78  model.plotOn(xframe) ;
79 
80  // Plot x distribution of data and projection of model on y = Int(dx) model(x,y)
81  RooPlot* yframe = y.frame() ;
82  data->plotOn(yframe) ;
83  model.plotOn(yframe) ;
84 
85  // Make two-dimensional plot in x vs y
86  TH1* hh_model = model.createHistogram("hh_model_rf305",x,Binning(50),YVar(y,Binning(50))) ;
87  hh_model->SetLineColor(kBlue) ;
88 
89  regTH(hh_model,"rf305_model2d") ;
90  regPlot(xframe,"rf305_plot1") ;
91  regPlot(yframe,"rf305_plot2") ;
92 
93  delete data ;
94 
95  return kTRUE ;
96 
97  }
98 } ;
99 
100 
101 
RooProdPdf is an efficient implementation of a product of PDFs of the form.
Definition: RooProdPdf.h:31
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Definition: TFile.h:50
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
Double_t x[n]
Definition: legend1.C:17
Plain Gaussian p.d.f.
Definition: RooGaussian.h:25
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
Class RooPolyVar is a RooAbsReal implementing a polynomial in terms of a list of RooAbsReal coefficie...
Definition: RooPolyVar.h:28
RooRealVar represents a fundamental (non-derived) real valued object.
Definition: RooRealVar.h:37
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition: TAttLine.h:46
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
RooCmdArg YVar(const RooAbsRealLValue &var, const RooCmdArg &arg=RooCmdArg::none())
Double_t y[n]
Definition: legend1.C:17
The TH1 histogram class.
Definition: TH1.h:80
RooConstVar & RooConst(Double_t val)
Definition: Rtypes.h:61
const Bool_t kTRUE
Definition: Rtypes.h:91
RooCmdArg Binning(const RooAbsBinning &binning)