Logo ROOT   6.10/09
Reference Guide
rf305_condcorrprod.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_roofit
3 /// \notebook
4 /// 'MULTIDIMENSIONAL MODELS' RooFit tutorial macro #305
5 ///
6 /// Multi-dimensional p.d.f.s with conditional p.d.fs in product
7 ///
8 /// pdf = gauss(x,f(y),sx | y ) * gauss(y,ms,sx) with f(y) = a0 + a1*y
9 ///
10 /// \macro_image
11 /// \macro_output
12 /// \macro_code
13 /// \author 07/2008 - Wouter Verkerke
14 
15 
16 #include "RooRealVar.h"
17 #include "RooDataSet.h"
18 #include "RooGaussian.h"
19 #include "RooConstVar.h"
20 #include "RooPolyVar.h"
21 #include "RooProdPdf.h"
22 #include "RooPlot.h"
23 #include "TCanvas.h"
24 #include "TAxis.h"
25 #include "TH1.h"
26 using namespace RooFit ;
27 
28 
29 
30 void rf305_condcorrprod()
31 {
32  // C r e a t e c o n d i t i o n a l p d f g x ( x | y )
33  // -----------------------------------------------------------
34 
35  // Create observables
36  RooRealVar x("x","x",-5,5) ;
37  RooRealVar y("y","y",-5,5) ;
38 
39  // Create function f(y) = a0 + a1*y
40  RooRealVar a0("a0","a0",-0.5,-5,5) ;
41  RooRealVar a1("a1","a1",-0.5,-1,1) ;
42  RooPolyVar fy("fy","fy",y,RooArgSet(a0,a1)) ;
43 
44  // Create gaussx(x,f(y),sx)
45  RooRealVar sigmax("sigma","width of gaussian",0.5) ;
46  RooGaussian gaussx("gaussx","Gaussian in x with shifting mean in y",x,fy,sigmax) ;
47 
48 
49 
50  // C r e a t e p d f g y ( y )
51  // -----------------------------------------------------------
52 
53  // Create gaussy(y,0,5)
54  RooGaussian gaussy("gaussy","Gaussian in y",y,RooConst(0),RooConst(3)) ;
55 
56 
57 
58  // C r e a t e p r o d u c t g x ( x | y ) * g y ( y )
59  // -------------------------------------------------------
60 
61  // Create gaussx(x,sx|y) * gaussy(y)
62  RooProdPdf model("model","gaussx(x|y)*gaussy(y)",gaussy,Conditional(gaussx,x)) ;
63 
64 
65 
66  // 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
67  // ---------------------------------------------------------------
68 
69  // Generate 1000 events in x and y from model
70  RooDataSet *data = model.generate(RooArgSet(x,y),10000) ;
71 
72  // Plot x distribution of data and projection of model on x = Int(dy) model(x,y)
73  RooPlot* xframe = x.frame() ;
74  data->plotOn(xframe) ;
75  model.plotOn(xframe) ;
76 
77  // Plot x distribution of data and projection of model on y = Int(dx) model(x,y)
78  RooPlot* yframe = y.frame() ;
79  data->plotOn(yframe) ;
80  model.plotOn(yframe) ;
81 
82  // Make two-dimensional plot in x vs y
83  TH1* hh_model = model.createHistogram("hh_model",x,Binning(50),YVar(y,Binning(50))) ;
84  hh_model->SetLineColor(kBlue) ;
85 
86 
87 
88  // Make canvas and draw RooPlots
89  TCanvas *c = new TCanvas("rf305_condcorrprod","rf05_condcorrprod",1200, 400);
90  c->Divide(3);
91  c->cd(1) ; gPad->SetLeftMargin(0.15) ; xframe->GetYaxis()->SetTitleOffset(1.6) ; xframe->Draw() ;
92  c->cd(2) ; gPad->SetLeftMargin(0.15) ; yframe->GetYaxis()->SetTitleOffset(1.6) ; yframe->Draw() ;
93  c->cd(3) ; gPad->SetLeftMargin(0.20) ; hh_model->GetZaxis()->SetTitleOffset(2.5) ; hh_model->Draw("surf") ;
94 
95 }
96 
97 
98 
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:262
TAxis * GetYaxis() const
Definition: RooPlot.cxx:1118
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
TVirtualPad * cd(Int_t subpadnumber=0)
Set current canvas & pad.
Definition: TCanvas.cxx:679
RooCmdArg Conditional(const RooArgSet &pdfSet, const RooArgSet &depSet, Bool_t depsAreCond=kFALSE)
Double_t x[n]
Definition: legend1.C:17
Plain Gaussian p.d.f.
Definition: RooGaussian.h:25
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:36
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition: TAttLine.h:40
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2851
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
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:56
TAxis * GetZaxis()
Definition: TH1.h:302
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:1135
#define gPad
Definition: TVirtualPad.h:284
Definition: Rtypes.h:56
virtual void Draw(Option_t *options=0)
Draw this plot and all of the elements it contains.
Definition: RooPlot.cxx:559
RooCmdArg Binning(const RooAbsBinning &binning)