Logo ROOT  
Reference Guide
rf309_ndimplot.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_roofit
3 /// \notebook
4 /// Multidimensional models: making 2/3 dimensional plots of pdfs and datasets
5 ///
6 /// \macro_image
7 /// \macro_output
8 /// \macro_code
9 ///
10 /// \date July 2008
11 /// \author Wouter Verkerke
12 
13 #include "RooRealVar.h"
14 #include "RooDataSet.h"
15 #include "RooConstVar.h"
16 #include "RooGaussian.h"
17 #include "RooProdPdf.h"
18 #include "TCanvas.h"
19 #include "TAxis.h"
20 #include "TH1.h"
21 #include "RooPlot.h"
22 using namespace RooFit;
23 
24 void rf309_ndimplot()
25 {
26 
27  // C r e a t e 2 D m o d e l a n d d a t a s e t
28  // -----------------------------------------------------
29 
30  // Create observables
31  RooRealVar x("x", "x", -5, 5);
32  RooRealVar y("y", "y", -5, 5);
33 
34  // Create parameters
35  RooRealVar a0("a0", "a0", -3.5, -5, 5);
36  RooRealVar a1("a1", "a1", -1.5, -1, 1);
37  RooRealVar sigma("sigma", "width of gaussian", 1.5);
38 
39  // Create interpreted function f(y) = a0 - a1*sqrt(10*abs(y))
40  RooFormulaVar fy("fy", "a0-a1*sqrt(10*abs(y))", RooArgSet(y, a0, a1));
41 
42  // Create gauss(x,f(y),s)
43  RooGaussian model("model", "Gaussian with shifting mean", x, fy, sigma);
44 
45  // Sample dataset from gauss(x,y)
46  RooDataSet *data = model.generate(RooArgSet(x, y), 10000);
47 
48  // 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
49  // -------------------------------------------------------------
50 
51  // Create and fill ROOT 2D histogram (20x20 bins) with contents of dataset
52  // TH2D* hh_data = data->createHistogram("hh_data",x,Binning(20),YVar(y,Binning(20))) ;
53  TH1 *hh_data = data->createHistogram("x,y", 20, 20);
54 
55  // Create and fill ROOT 2D histogram (50x50 bins) with sampling of pdf
56  // TH2D* hh_pdf = model.createHistogram("hh_model",x,Binning(50),YVar(y,Binning(50))) ;
57  TH1 *hh_pdf = model.createHistogram("x,y", 50, 50);
58  hh_pdf->SetLineColor(kBlue);
59 
60  // C r e a t e 3 D m o d e l a n d d a t a s e t
61  // -----------------------------------------------------
62 
63  // Create observables
64  RooRealVar z("z", "z", -5, 5);
65 
66  RooGaussian gz("gz", "gz", z, RooConst(0), RooConst(2));
67  RooProdPdf model3("model3", "model3", RooArgSet(model, gz));
68 
69  RooDataSet *data3 = model3.generate(RooArgSet(x, y, z), 10000);
70 
71  // 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
72  // -------------------------------------------------------------
73 
74  // Create and fill ROOT 2D histogram (8x8x8 bins) with contents of dataset
75  TH1 *hh_data3 = data3->createHistogram("hh_data3", x, Binning(8), YVar(y, Binning(8)), ZVar(z, Binning(8)));
76 
77  // Create and fill ROOT 2D histogram (20x20x20 bins) with sampling of pdf
78  TH1 *hh_pdf3 = model3.createHistogram("hh_model3", x, Binning(20), YVar(y, Binning(20)), ZVar(z, Binning(20)));
79  hh_pdf3->SetFillColor(kBlue);
80 
81  TCanvas *c1 = new TCanvas("rf309_2dimplot", "rf309_2dimplot", 800, 800);
82  c1->Divide(2, 2);
83  c1->cd(1);
84  gPad->SetLeftMargin(0.15);
85  hh_data->GetZaxis()->SetTitleOffset(1.4);
86  hh_data->Draw("lego");
87  c1->cd(2);
88  gPad->SetLeftMargin(0.20);
89  hh_pdf->GetZaxis()->SetTitleOffset(2.5);
90  hh_pdf->Draw("surf");
91  c1->cd(3);
92  gPad->SetLeftMargin(0.15);
93  hh_data->GetZaxis()->SetTitleOffset(1.4);
94  hh_data->Draw("box");
95  c1->cd(4);
96  gPad->SetLeftMargin(0.15);
97  hh_pdf->GetZaxis()->SetTitleOffset(2.5);
98  hh_pdf->Draw("cont3");
99 
100  TCanvas *c2 = new TCanvas("rf309_3dimplot", "rf309_3dimplot", 800, 400);
101  c2->Divide(2);
102  c2->cd(1);
103  gPad->SetLeftMargin(0.15);
104  hh_data3->GetZaxis()->SetTitleOffset(1.4);
105  hh_data3->Draw("lego");
106  c2->cd(2);
107  gPad->SetLeftMargin(0.15);
108  hh_pdf3->GetZaxis()->SetTitleOffset(1.4);
109  hh_pdf3->Draw("iso");
110 }
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:1437
RooGaussian.h
x
Double_t x[n]
Definition: legend1.C:17
RooGaussian
Plain Gaussian p.d.f.
Definition: RooGaussian.h:24
rf309_ndimplot
Definition: rf309_ndimplot.py:1
TAttLine::SetLineColor
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition: TAttLine.h:40
TCanvas.h
RooFit::YVar
RooCmdArg YVar(const RooAbsRealLValue &var, const RooCmdArg &arg=RooCmdArg::none())
Definition: RooGlobalFunc.cxx:246
RooFit::Binning
RooCmdArg Binning(const RooAbsBinning &binning)
Definition: RooGlobalFunc.cxx:83
TH1::GetZaxis
TAxis * GetZaxis()
Definition: TH1.h:322
RooDataSet.h
RooFormulaVar
A RooFormulaVar is a generic implementation of a real-valued object, which takes a RooArgList of serv...
Definition: RooFormulaVar.h:30
RooProdPdf.h
RooFit
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Definition: RooCFunction1Binding.h:29
RooFit::ZVar
RooCmdArg ZVar(const RooAbsRealLValue &var, const RooCmdArg &arg=RooCmdArg::none())
Definition: RooGlobalFunc.cxx:247
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
The Canvas class.
Definition: TCanvas.h:23
TAttFill::SetFillColor
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition: TAttFill.h:37
TAxis.h
TH1
TH1 is the base class of all histogramm classes in ROOT.
Definition: TH1.h:58
kBlue
@ kBlue
Definition: Rtypes.h:66
c2
return c2
Definition: legend2.C:14
gPad
#define gPad
Definition: TVirtualPad.h:287
RooDataSet
RooDataSet is a container class to hold unbinned data.
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
RooRealVar represents a variable that can be changed from the outside.
Definition: RooRealVar.h:37
RooProdPdf
RooProdPdf is an efficient implementation of a product of PDFs of the form.
Definition: RooProdPdf.h:37
TH1.h
RooArgSet
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:29
TH1::Draw
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:3050
c1
return c1
Definition: legend1.C:41
RooFit::RooConst
RooConstVar & RooConst(Double_t val)
Definition: RooGlobalFunc.cxx:347