ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
rf309_ndimplot.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_roofit
3 /// 'MULTIDIMENSIONAL MODELS' RooFit tutorial macro #308
4 ///
5 /// Making 2/3 dimensional plots of p.d.f.s and datasets
6 ///
7 ///
8 ///
9 /// \macro_code
10 /// \author 07/2008 - Wouter Verkerke
11 
12 
13 #ifndef __CINT__
14 #include "RooGlobalFunc.h"
15 #endif
16 #include "RooRealVar.h"
17 #include "RooDataSet.h"
18 #include "RooConstVar.h"
19 #include "RooGaussian.h"
20 #include "RooProdPdf.h"
21 #include "TCanvas.h"
22 #include "TAxis.h"
23 #include "TH1.h"
24 #include "RooPlot.h"
25 using namespace RooFit ;
26 
27 
28 void rf309_ndimplot()
29 {
30 
31  // C r e a t e 2 D m o d e l a n d d a t a s e t
32  // -----------------------------------------------------
33 
34  // Create observables
35  RooRealVar x("x","x",-5,5) ;
36  RooRealVar y("y","y",-5,5) ;
37 
38  // Create parameters
39  RooRealVar a0("a0","a0",-3.5,-5,5) ;
40  RooRealVar a1("a1","a1",-1.5,-1,1) ;
41  RooRealVar sigma("sigma","width of gaussian",1.5) ;
42 
43  // Create interpreted function f(y) = a0 - a1*sqrt(10*abs(y))
44  RooFormulaVar fy("fy","a0-a1*sqrt(10*abs(y))",RooArgSet(y,a0,a1)) ;
45 
46  // Create gauss(x,f(y),s)
47  RooGaussian model("model","Gaussian with shifting mean",x,fy,sigma) ;
48 
49  // Sample dataset from gauss(x,y)
50  RooDataSet* data = model.generate(RooArgSet(x,y),10000) ;
51 
52 
53  // M a k e 2 D p l o t s o f d a t a a n d m o d e l
54  // -------------------------------------------------------------
55 
56  // Create and fill ROOT 2D histogram (20x20 bins) with contents of dataset
57  //TH2D* hh_data = data->createHistogram("hh_data",x,Binning(20),YVar(y,Binning(20))) ;
58  TH1* hh_data = data->createHistogram("x,y",20,20) ;
59 
60  // Create and fill ROOT 2D histogram (50x50 bins) with sampling of pdf
61  //TH2D* hh_pdf = model.createHistogram("hh_model",x,Binning(50),YVar(y,Binning(50))) ;
62  TH1* hh_pdf = model.createHistogram("x,y",50,50) ;
63  hh_pdf->SetLineColor(kBlue) ;
64 
65 
66  // C r e a t e 3 D m o d e l a n d d a t a s e t
67  // -----------------------------------------------------
68 
69  // Create observables
70  RooRealVar z("z","z",-5,5) ;
71 
72  RooGaussian gz("gz","gz",z,RooConst(0),RooConst(2)) ;
73  RooProdPdf model3("model3","model3",RooArgSet(model,gz)) ;
74 
75  RooDataSet* data3 = model3.generate(RooArgSet(x,y,z),10000) ;
76 
77 
78  // M a k e 3 D p l o t s o f d a t a a n d m o d e l
79  // -------------------------------------------------------------
80 
81  // Create and fill ROOT 2D histogram (8x8x8 bins) with contents of dataset
82  TH1* hh_data3 = data3->createHistogram("hh_data3",x,Binning(8),YVar(y,Binning(8)),ZVar(z,Binning(8))) ;
83 
84  // Create and fill ROOT 2D histogram (20x20x20 bins) with sampling of pdf
85  TH1* hh_pdf3 = model3.createHistogram("hh_model3",x,Binning(20),YVar(y,Binning(20)),ZVar(z,Binning(20))) ;
86  hh_pdf3->SetFillColor(kBlue) ;
87 
88 
89 
90  TCanvas* c1 = new TCanvas("rf309_2dimplot","rf309_2dimplot",800,800) ;
91  c1->Divide(2,2) ;
92  c1->cd(1) ; gPad->SetLeftMargin(0.15) ; hh_data->GetZaxis()->SetTitleOffset(1.4) ; hh_data->Draw("lego") ;
93  c1->cd(2) ; gPad->SetLeftMargin(0.20) ; hh_pdf->GetZaxis()->SetTitleOffset(2.5) ; hh_pdf->Draw("surf") ;
94  c1->cd(3) ; gPad->SetLeftMargin(0.15) ; hh_data->GetZaxis()->SetTitleOffset(1.4) ; hh_data->Draw("box") ;
95  c1->cd(4) ; gPad->SetLeftMargin(0.15) ; hh_pdf->GetZaxis()->SetTitleOffset(2.5) ; hh_pdf->Draw("cont3") ;
96 
97  TCanvas* c2 = new TCanvas("rf309_3dimplot","rf309_3dimplot",800,400) ;
98  c2->Divide(2) ;
99  c2->cd(1) ; gPad->SetLeftMargin(0.15) ; hh_data3->GetZaxis()->SetTitleOffset(1.4) ; hh_data3->Draw("lego") ;
100  c2->cd(2) ; gPad->SetLeftMargin(0.15) ; hh_pdf3->GetZaxis()->SetTitleOffset(1.4) ; hh_pdf3->Draw("iso") ;
101 
102 }
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:245
RooCmdArg ZVar(const RooAbsRealLValue &var, const RooCmdArg &arg=RooCmdArg::none())
RooProdPdf is an efficient implementation of a product of PDFs of the form.
Definition: RooProdPdf.h:31
Double_t x[n]
Definition: legend1.C:17
Plain Gaussian p.d.f.
Definition: RooGaussian.h:25
friend class RooArgSet
Definition: RooAbsArg.h:469
const Double_t sigma
Float_t z[5]
Definition: Ifit.C:16
RooRealVar represents a fundamental (non-derived) real valued object.
Definition: RooRealVar.h:37
virtual void SetLineColor(Color_t lcolor)
Definition: TAttLine.h:54
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2878
virtual void SetFillColor(Color_t fcolor)
Definition: TAttFill.h:50
RooDataSet is a container class to hold unbinned data.
Definition: RooDataSet.h:29
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
TH2F * createHistogram(const RooAbsRealLValue &var1, const RooAbsRealLValue &var2, const char *cuts="", const char *name="hist") const
Create a TH2F histogram of the distribution of the specified variable using this dataset.
TAxis * GetZaxis()
Definition: TH1.h:321
RooConstVar & RooConst(Double_t val)
#define gPad
Definition: TVirtualPad.h:288
Definition: Rtypes.h:61
RooCmdArg Binning(const RooAbsBinning &binning)