Logo ROOT  
Reference Guide
rf309_ndimplot.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_roofit
3 /// \notebook
4 ///
5 /// Multidimensional models: making 2/3 dimensional plots of p.d.f.s and datasets
6 ///
7 /// \macro_image
8 /// \macro_output
9 /// \macro_code
10 ///
11 /// \date 07/2008
12 /// \author Wouter Verkerke
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 void rf309_ndimplot()
26 {
27 
28  // C r e a t e 2 D m o d e l a n d d a t a s e t
29  // -----------------------------------------------------
30 
31  // Create observables
32  RooRealVar x("x", "x", -5, 5);
33  RooRealVar y("y", "y", -5, 5);
34 
35  // Create parameters
36  RooRealVar a0("a0", "a0", -3.5, -5, 5);
37  RooRealVar a1("a1", "a1", -1.5, -1, 1);
38  RooRealVar sigma("sigma", "width of gaussian", 1.5);
39 
40  // Create interpreted function f(y) = a0 - a1*sqrt(10*abs(y))
41  RooFormulaVar fy("fy", "a0-a1*sqrt(10*abs(y))", RooArgSet(y, a0, a1));
42 
43  // Create gauss(x,f(y),s)
44  RooGaussian model("model", "Gaussian with shifting mean", x, fy, sigma);
45 
46  // Sample dataset from gauss(x,y)
47  RooDataSet *data = model.generate(RooArgSet(x, y), 10000);
48 
49  // 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
50  // -------------------------------------------------------------
51 
52  // Create and fill ROOT 2D histogram (20x20 bins) with contents of dataset
53  // TH2D* hh_data = data->createHistogram("hh_data",x,Binning(20),YVar(y,Binning(20))) ;
54  TH1 *hh_data = data->createHistogram("x,y", 20, 20);
55 
56  // Create and fill ROOT 2D histogram (50x50 bins) with sampling of pdf
57  // TH2D* hh_pdf = model.createHistogram("hh_model",x,Binning(50),YVar(y,Binning(50))) ;
58  TH1 *hh_pdf = model.createHistogram("x,y", 50, 50);
59  hh_pdf->SetLineColor(kBlue);
60 
61  // C r e a t e 3 D m o d e l a n d d a t a s e t
62  // -----------------------------------------------------
63 
64  // Create observables
65  RooRealVar z("z", "z", -5, 5);
66 
67  RooGaussian gz("gz", "gz", z, RooConst(0), RooConst(2));
68  RooProdPdf model3("model3", "model3", RooArgSet(model, gz));
69 
70  RooDataSet *data3 = model3.generate(RooArgSet(x, y, z), 10000);
71 
72  // 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
73  // -------------------------------------------------------------
74 
75  // Create and fill ROOT 2D histogram (8x8x8 bins) with contents of dataset
76  TH1 *hh_data3 = data3->createHistogram("hh_data3", x, Binning(8), YVar(y, Binning(8)), ZVar(z, Binning(8)));
77 
78  // Create and fill ROOT 2D histogram (20x20x20 bins) with sampling of pdf
79  TH1 *hh_pdf3 = model3.createHistogram("hh_model3", x, Binning(20), YVar(y, Binning(20)), ZVar(z, Binning(20)));
80  hh_pdf3->SetFillColor(kBlue);
81 
82  TCanvas *c1 = new TCanvas("rf309_2dimplot", "rf309_2dimplot", 800, 800);
83  c1->Divide(2, 2);
84  c1->cd(1);
85  gPad->SetLeftMargin(0.15);
86  hh_data->GetZaxis()->SetTitleOffset(1.4);
87  hh_data->Draw("lego");
88  c1->cd(2);
89  gPad->SetLeftMargin(0.20);
90  hh_pdf->GetZaxis()->SetTitleOffset(2.5);
91  hh_pdf->Draw("surf");
92  c1->cd(3);
93  gPad->SetLeftMargin(0.15);
94  hh_data->GetZaxis()->SetTitleOffset(1.4);
95  hh_data->Draw("box");
96  c1->cd(4);
97  gPad->SetLeftMargin(0.15);
98  hh_pdf->GetZaxis()->SetTitleOffset(2.5);
99  hh_pdf->Draw("cont3");
100 
101  TCanvas *c2 = new TCanvas("rf309_3dimplot", "rf309_3dimplot", 800, 400);
102  c2->Divide(2);
103  c2->cd(1);
104  gPad->SetLeftMargin(0.15);
105  hh_data3->GetZaxis()->SetTitleOffset(1.4);
106  hh_data3->Draw("lego");
107  c2->cd(2);
108  gPad->SetLeftMargin(0.15);
109  hh_pdf3->GetZaxis()->SetTitleOffset(1.4);
110  hh_pdf3->Draw("iso");
111 }
RooDataSet::createHistogram
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.
Definition: RooDataSet.cxx:1419
RooGaussian.h
x
Double_t x[n]
Definition: legend1.C:17
RooGaussian
Definition: RooGaussian.h:25
rf309_ndimplot
Definition: rf309_ndimplot.py:1
TCanvas.h
RooFit::YVar
RooCmdArg YVar(const RooAbsRealLValue &var, const RooCmdArg &arg=RooCmdArg::none())
Definition: RooGlobalFunc.cxx:240
RooFit::Binning
RooCmdArg Binning(const RooAbsBinning &binning)
Definition: RooGlobalFunc.cxx:82
TH1::GetZaxis
TAxis * GetZaxis()
Definition: TH1.h:319
RooDataSet.h
RooFormulaVar
Definition: RooFormulaVar.h:30
RooProdPdf.h
RooFit
Definition: RooCFunction1Binding.h:29
RooFit::ZVar
RooCmdArg ZVar(const RooAbsRealLValue &var, const RooCmdArg &arg=RooCmdArg::none())
Definition: RooGlobalFunc.cxx:241
RooPlot.h
y
Double_t y[n]
Definition: legend1.C:17
RooRealVar.h
RooConstVar.h
sigma
const Double_t sigma
Definition: h1analysisProxy.h:11
TCanvas
Definition: TCanvas.h:23
TAxis.h
TH1
Definition: TH1.h:57
kBlue
@ kBlue
Definition: Rtypes.h:66
c2
return c2
Definition: legend2.C:14
gPad
#define gPad
Definition: TVirtualPad.h:287
RooDataSet
Definition: RooDataSet.h:33
make_cnn_model.model
model
Definition: make_cnn_model.py:6
TAttAxis::SetTitleOffset
virtual void SetTitleOffset(Float_t offset=1)
Set distance between the axis and the axis title.
Definition: TAttAxis.cxx:293
RooRealVar
Definition: RooRealVar.h:35
RooProdPdf
Definition: RooProdPdf.h:33
TH1.h
RooArgSet
Definition: RooArgSet.h:28
TH1::Draw
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2997
c1
return c1
Definition: legend1.C:41
RooFit::RooConst
RooConstVar & RooConst(Double_t val)
Definition: RooGlobalFunc.cxx:341