 ROOT   Reference Guide rf301_composition.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_roofit
3 /// \notebook
4 ///
5 ///
6 /// \brief Multidimensional models: multi-dimensional p.d.f.s through composition
7 /// e.g. substituting a p.d.f parameter with a function that depends on other observables
8 ///
9 /// pdf = gauss(x,f(y),s) with f(y) = a0 + a1*y
10 ///
11 /// \macro_image
12 /// \macro_output
13 /// \macro_code
14 ///
15 /// \date 07/2008
16 /// \author Wouter Verkerke
17
18 #include "RooRealVar.h"
19 #include "RooDataSet.h"
20 #include "RooGaussian.h"
21 #include "RooPolyVar.h"
22 #include "RooPlot.h"
23 #include "TCanvas.h"
24 #include "TAxis.h"
25 #include "TH1.h"
26 using namespace RooFit;
27
28 void rf301_composition()
29 {
30  // S e t u p c o m p o s e d m o d e l g a u s s ( x , m ( y ) , s )
31  // -----------------------------------------------------------------------
32
33  // Create observables
34  RooRealVar x("x", "x", -5, 5);
35  RooRealVar y("y", "y", -5, 5);
36
37  // Create function f(y) = a0 + a1*y
38  RooRealVar a0("a0", "a0", -0.5, -5, 5);
39  RooRealVar a1("a1", "a1", -0.5, -1, 1);
40  RooPolyVar fy("fy", "fy", y, RooArgSet(a0, a1));
41
42  // Create gauss(x,f(y),s)
43  RooRealVar sigma("sigma", "width of gaussian", 0.5);
44  RooGaussian model("model", "Gaussian with shifting mean", x, fy, sigma);
45
46  // S a m p l e d a t a , p l o t d a t a a n d p d f o n x a n d y
47  // ---------------------------------------------------------------------------------
48
49  // Generate 10000 events in x and y from model
50  RooDataSet *data = model.generate(RooArgSet(x, y), 10000);
51
52  // Plot x distribution of data and projection of model on x = Int(dy) model(x,y)
53  RooPlot *xframe = x.frame();
54  data->plotOn(xframe);
55  model.plotOn(xframe);
56
57  // Plot x distribution of data and projection of model on y = Int(dx) model(x,y)
58  RooPlot *yframe = y.frame();
59  data->plotOn(yframe);
60  model.plotOn(yframe);
61
62  // Make two-dimensional plot in x vs y
63  TH1 *hh_model = model.createHistogram("hh_model", x, Binning(50), YVar(y, Binning(50)));
64  hh_model->SetLineColor(kBlue);
65
66  // Make canvas and draw RooPlots
67  TCanvas *c = new TCanvas("rf301_composition", "rf301_composition", 1200, 400);
68  c->Divide(3);
69  c->cd(1);
71  xframe->GetYaxis()->SetTitleOffset(1.4);
72  xframe->Draw();
73  c->cd(2);
75  yframe->GetYaxis()->SetTitleOffset(1.4);
76  yframe->Draw();
77  c->cd(3);
79  hh_model->GetZaxis()->SetTitleOffset(2.5);
80  hh_model->Draw("surf");
81 }
c
#define c(i)
Definition: RSha256.hxx:101
RooPlot::Draw
virtual void Draw(Option_t *options=0)
Draw this plot and all of the elements it contains.
Definition: RooPlot.cxx:691
RooGaussian.h
x
Double_t x[n]
Definition: legend1.C:17
RooGaussian
Plain Gaussian p.d.f.
Definition: RooGaussian.h:25
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:240
RooFit::Binning
RooCmdArg Binning(const RooAbsBinning &binning)
Definition: RooGlobalFunc.cxx:82
TH1::GetZaxis
TAxis * GetZaxis()
Definition: TH1.h:320
RooDataSet.h
RooPolyVar.h
RooFit
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Definition: RooCFunction1Binding.h:29
RooAbsData::plotOn
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
Definition: RooAbsData.cxx:547
RooPlot.h
RooPlot::GetYaxis
TAxis * GetYaxis() const
Definition: RooPlot.cxx:1258
RooPlot
A RooPlot is a plot frame and a container for graphics objects within that frame.
Definition: RooPlot.h:44
y
Double_t y[n]
Definition: legend1.C:17
RooRealVar.h
RooPolyVar
Class RooPolyVar is a RooAbsReal implementing a polynomial in terms of a list of RooAbsReal coefficie...
Definition: RooPolyVar.h:28
rf301_composition
Definition: rf301_composition.py:1
sigma
const Double_t sigma
Definition: h1analysisProxy.h:11
TCanvas
The Canvas class.
Definition: TCanvas.h:23
TAxis.h
TH1
TH1 is the base class of all histogramm classes in ROOT.
Definition: TH1.h:58
kBlue
@ kBlue
Definition: Rtypes.h:66
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:36
TH1.h
RooArgSet
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:28
TH1::Draw
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:3050