Logo ROOT   6.10/09
Reference Guide
rf309_ndimplot.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_roofit
3 /// \notebook
4 /// 'MULTIDIMENSIONAL MODELS' RooFit tutorial macro #308
5 ///
6 /// Making 2/3 dimensional plots of p.d.f.s and datasets
7 ///
8 /// \macro_image
9 /// \macro_output
10 /// \macro_code
11 /// \author 07/2008 - Wouter Verkerke
12 
13 
14 #include "RooRealVar.h"
15 #include "RooDataSet.h"
16 #include "RooConstVar.h"
17 #include "RooGaussian.h"
18 #include "RooProdPdf.h"
19 #include "TCanvas.h"
20 #include "TAxis.h"
21 #include "TH1.h"
22 #include "RooPlot.h"
23 using namespace RooFit ;
24 
25 
26 void rf309_ndimplot()
27 {
28 
29  // C r e a t e 2 D m o d e l a n d d a t a s e t
30  // -----------------------------------------------------
31 
32  // Create observables
33  RooRealVar x("x","x",-5,5) ;
34  RooRealVar y("y","y",-5,5) ;
35 
36  // Create parameters
37  RooRealVar a0("a0","a0",-3.5,-5,5) ;
38  RooRealVar a1("a1","a1",-1.5,-1,1) ;
39  RooRealVar sigma("sigma","width of gaussian",1.5) ;
40 
41  // Create interpreted function f(y) = a0 - a1*sqrt(10*abs(y))
42  RooFormulaVar fy("fy","a0-a1*sqrt(10*abs(y))",RooArgSet(y,a0,a1)) ;
43 
44  // Create gauss(x,f(y),s)
45  RooGaussian model("model","Gaussian with shifting mean",x,fy,sigma) ;
46 
47  // Sample dataset from gauss(x,y)
48  RooDataSet* data = model.generate(RooArgSet(x,y),10000) ;
49 
50 
51  // 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
52  // -------------------------------------------------------------
53 
54  // Create and fill ROOT 2D histogram (20x20 bins) with contents of dataset
55  //TH2D* hh_data = data->createHistogram("hh_data",x,Binning(20),YVar(y,Binning(20))) ;
56  TH1* hh_data = data->createHistogram("x,y",20,20) ;
57 
58  // Create and fill ROOT 2D histogram (50x50 bins) with sampling of pdf
59  //TH2D* hh_pdf = model.createHistogram("hh_model",x,Binning(50),YVar(y,Binning(50))) ;
60  TH1* hh_pdf = model.createHistogram("x,y",50,50) ;
61  hh_pdf->SetLineColor(kBlue) ;
62 
63 
64  // C r e a t e 3 D m o d e l a n d d a t a s e t
65  // -----------------------------------------------------
66 
67  // Create observables
68  RooRealVar z("z","z",-5,5) ;
69 
70  RooGaussian gz("gz","gz",z,RooConst(0),RooConst(2)) ;
71  RooProdPdf model3("model3","model3",RooArgSet(model,gz)) ;
72 
73  RooDataSet* data3 = model3.generate(RooArgSet(x,y,z),10000) ;
74 
75 
76  // 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
77  // -------------------------------------------------------------
78 
79  // Create and fill ROOT 2D histogram (8x8x8 bins) with contents of dataset
80  TH1* hh_data3 = data3->createHistogram("hh_data3",x,Binning(8),YVar(y,Binning(8)),ZVar(z,Binning(8))) ;
81 
82  // Create and fill ROOT 2D histogram (20x20x20 bins) with sampling of pdf
83  TH1* hh_pdf3 = model3.createHistogram("hh_model3",x,Binning(20),YVar(y,Binning(20)),ZVar(z,Binning(20))) ;
84  hh_pdf3->SetFillColor(kBlue) ;
85 
86 
87 
88  TCanvas* c1 = new TCanvas("rf309_2dimplot","rf309_2dimplot",800,800) ;
89  c1->Divide(2,2) ;
90  c1->cd(1) ; gPad->SetLeftMargin(0.15) ; hh_data->GetZaxis()->SetTitleOffset(1.4) ; hh_data->Draw("lego") ;
91  c1->cd(2) ; gPad->SetLeftMargin(0.20) ; hh_pdf->GetZaxis()->SetTitleOffset(2.5) ; hh_pdf->Draw("surf") ;
92  c1->cd(3) ; gPad->SetLeftMargin(0.15) ; hh_data->GetZaxis()->SetTitleOffset(1.4) ; hh_data->Draw("box") ;
93  c1->cd(4) ; gPad->SetLeftMargin(0.15) ; hh_pdf->GetZaxis()->SetTitleOffset(2.5) ; hh_pdf->Draw("cont3") ;
94 
95  TCanvas* c2 = new TCanvas("rf309_3dimplot","rf309_3dimplot",800,400) ;
96  c2->Divide(2) ;
97  c2->cd(1) ; gPad->SetLeftMargin(0.15) ; hh_data3->GetZaxis()->SetTitleOffset(1.4) ; hh_data3->Draw("lego") ;
98  c2->cd(2) ; gPad->SetLeftMargin(0.15) ; hh_pdf3->GetZaxis()->SetTitleOffset(1.4) ; hh_pdf3->Draw("iso") ;
99 
100 }
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
RooCmdArg ZVar(const RooAbsRealLValue &var, const RooCmdArg &arg=RooCmdArg::none())
return c1
Definition: legend1.C:41
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
Double_t x[n]
Definition: legend1.C:17
Plain Gaussian p.d.f.
Definition: RooGaussian.h:25
const Double_t sigma
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
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition: TAttFill.h:37
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.
RooDataSet is a container class to hold unbinned data.
Definition: RooDataSet.h:29
The Canvas class.
Definition: TCanvas.h:31
return c2
Definition: legend2.C:14
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
you should not use this method at all Int_t Int_t z
Definition: TRolke.cxx:630
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
RooCmdArg Binning(const RooAbsBinning &binning)