Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
rf301_composition.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_roofit
3/// \notebook
4/// Multidimensional models: multi-dimensional pdfs through composition
5/// e.g. substituting a pdf parameter with a function that depends on other observables
6///
7/// `pdf = gauss(x,f(y),s)` with `f(y) = a0 + a1*y`
8///
9/// \macro_image
10/// \macro_code
11/// \macro_output
12///
13/// \date July 2008
14/// \author Wouter Verkerke
15
16#include "RooRealVar.h"
17#include "RooDataSet.h"
18#include "RooGaussian.h"
19#include "RooPolyVar.h"
20#include "RooPlot.h"
21#include "TCanvas.h"
22#include "TAxis.h"
23#include "TH1.h"
24using namespace RooFit;
25
27{
28 // 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 )
29 // -----------------------------------------------------------------------
30
31 // Create observables
32 RooRealVar x("x", "x", -5, 5);
33 RooRealVar y("y", "y", -5, 5);
34
35 // Create function f(y) = a0 + a1*y
36 RooRealVar a0("a0", "a0", -0.5, -5, 5);
37 RooRealVar a1("a1", "a1", -0.5, -1, 1);
38 RooPolyVar fy("fy", "fy", y, RooArgSet(a0, a1));
39
40 // Create gauss(x,f(y),s)
41 RooRealVar sigma("sigma", "width of gaussian", 0.5);
42 RooGaussian model("model", "Gaussian with shifting mean", x, fy, sigma);
43
44 // 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
45 // ---------------------------------------------------------------------------------
46
47 // Generate 10000 events in x and y from model
48 std::unique_ptr<RooDataSet> data{model.generate({x, y}, 10000)};
49
50 // Plot x distribution of data and projection of model on x = Int(dy) model(x,y)
51 RooPlot *xframe = x.frame();
52 data->plotOn(xframe);
53 model.plotOn(xframe);
54
55 // Plot x distribution of data and projection of model on y = Int(dx) model(x,y)
56 RooPlot *yframe = y.frame();
57 data->plotOn(yframe);
58 model.plotOn(yframe);
59
60 // Make two-dimensional plot in x vs y
61 TH1 *hh_model = model.createHistogram("hh_model", x, Binning(50), YVar(y, Binning(50)));
62 hh_model->SetLineColor(kBlue);
63
64 // Make canvas and draw RooPlots
65 TCanvas *c = new TCanvas("rf301_composition", "rf301_composition", 1200, 400);
66 c->Divide(3);
67 c->cd(1);
68 gPad->SetLeftMargin(0.15);
69 xframe->GetYaxis()->SetTitleOffset(1.4);
70 xframe->Draw();
71 c->cd(2);
72 gPad->SetLeftMargin(0.15);
73 yframe->GetYaxis()->SetTitleOffset(1.4);
74 yframe->Draw();
75 c->cd(3);
76 gPad->SetLeftMargin(0.20);
77 hh_model->GetZaxis()->SetTitleOffset(2.5);
78 hh_model->Draw("surf");
79}
#define c(i)
Definition RSha256.hxx:101
@ kBlue
Definition Rtypes.h:66
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
#define gPad
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:55
Plain Gaussian p.d.f.
Definition RooGaussian.h:24
A RooPlot is a plot frame and a container for graphics objects within that frame.
Definition RooPlot.h:43
static RooPlot * frame(const RooAbsRealLValue &var, double xmin, double xmax, Int_t nBins)
Create a new frame for a given variable in x.
Definition RooPlot.cxx:239
TAxis * GetYaxis() const
Definition RooPlot.cxx:1279
void Draw(Option_t *options=nullptr) override
Draw this plot and all of the elements it contains.
Definition RooPlot.cxx:652
Class RooPolyVar is a RooAbsReal implementing a polynomial in terms of a list of RooAbsReal coefficie...
Definition RooPolyVar.h:25
RooRealVar represents a variable that can be changed from the outside.
Definition RooRealVar.h:37
virtual void SetTitleOffset(Float_t offset=1)
Set distance between the axis and the axis title.
Definition TAttAxis.cxx:298
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition TAttLine.h:40
The Canvas class.
Definition TCanvas.h:23
TH1 is the base class of all histogram classes in ROOT.
Definition TH1.h:58
TAxis * GetZaxis()
Definition TH1.h:324
void Draw(Option_t *option="") override
Draw this histogram with options.
Definition TH1.cxx:3067
RooCmdArg YVar(const RooAbsRealLValue &var, const RooCmdArg &arg={})
RooCmdArg Binning(const RooAbsBinning &binning)
const Double_t sigma
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Definition JSONIO.h:26