Logo ROOT  
Reference Guide
rf302_utilfuncs.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_roofit
3/// \notebook
4/// Multidimensional models: utility functions classes available for use in tailoring of composite (multidimensional)
5/// pdfs
6///
7/// \macro_image
8/// \macro_output
9/// \macro_code
10/// \author 07/2008 - Wouter Verkerke
11
12#include "RooRealVar.h"
13#include "RooDataSet.h"
14#include "RooGaussian.h"
15#include "TCanvas.h"
16#include "TAxis.h"
17#include "RooPlot.h"
18#include "RooFormulaVar.h"
19#include "RooAddition.h"
20#include "RooProduct.h"
21#include "RooPolyVar.h"
22#include "TCanvas.h"
23#include "TAxis.h"
24#include "TH1.h"
25
26using namespace RooFit;
27
28void rf302_utilfuncs()
29{
30 // C r e a t e o b s e r v a b l e s , p a r a m e t e r s
31 // -----------------------------------------------------------
32
33 // Create observables
34 RooRealVar x("x", "x", -5, 5);
35 RooRealVar y("y", "y", -5, 5);
36
37 // Create parameters
38 RooRealVar a0("a0", "a0", -1.5, -5, 5);
39 RooRealVar a1("a1", "a1", -0.5, -1, 1);
40 RooRealVar sigma("sigma", "width of gaussian", 0.5);
41
42 // U s i n g R o o F o r m u l a V a r t o t a i l o r p d f
43 // -----------------------------------------------------------------------
44
45 // Create interpreted function f(y) = a0 - a1*sqrt(10*abs(y))
46 RooFormulaVar fy_1("fy_1", "a0-a1*sqrt(10*abs(y))", RooArgSet(y, a0, a1));
47
48 // Create gauss(x,f(y),s)
49 RooGaussian model_1("model_1", "Gaussian with shifting mean", x, fy_1, sigma);
50
51 // U s i n g R o o P o l y V a r t o t a i l o r p d f
52 // -----------------------------------------------------------------------
53
54 // Create polynomial function f(y) = a0 + a1*y
55 RooPolyVar fy_2("fy_2", "fy_2", y, RooArgSet(a0, a1));
56
57 // Create gauss(x,f(y),s)
58 RooGaussian model_2("model_2", "Gaussian with shifting mean", x, fy_2, sigma);
59
60 // U s i n g R o o A d d i t i o n t o t a i l o r p d f
61 // -----------------------------------------------------------------------
62
63 // Create sum function f(y) = a0 + y
64 RooAddition fy_3("fy_3", "a0+y", RooArgSet(a0, y));
65
66 // Create gauss(x,f(y),s)
67 RooGaussian model_3("model_3", "Gaussian with shifting mean", x, fy_3, sigma);
68
69 // U s i n g R o o P r o d u c t t o t a i l o r p d f
70 // -----------------------------------------------------------------------
71
72 // Create product function f(y) = a1*y
73 RooProduct fy_4("fy_4", "a1*y", RooArgSet(a1, y));
74
75 // Create gauss(x,f(y),s)
76 RooGaussian model_4("model_4", "Gaussian with shifting mean", x, fy_4, sigma);
77
78 // P l o t a l l p d f s
79 // ----------------------------
80
81 // Make two-dimensional plots in x vs y
82 TH1 *hh_model_1 = model_1.createHistogram("hh_model_1", x, Binning(50), YVar(y, Binning(50)));
83 TH1 *hh_model_2 = model_2.createHistogram("hh_model_2", x, Binning(50), YVar(y, Binning(50)));
84 TH1 *hh_model_3 = model_3.createHistogram("hh_model_3", x, Binning(50), YVar(y, Binning(50)));
85 TH1 *hh_model_4 = model_4.createHistogram("hh_model_4", x, Binning(50), YVar(y, Binning(50)));
86 hh_model_1->SetLineColor(kBlue);
87 hh_model_2->SetLineColor(kBlue);
88 hh_model_3->SetLineColor(kBlue);
89 hh_model_4->SetLineColor(kBlue);
90
91 // Make canvas and draw RooPlots
92 TCanvas *c = new TCanvas("rf302_utilfuncs", "rf302_utilfuncs", 800, 800);
93 c->Divide(2, 2);
94 c->cd(1);
95 gPad->SetLeftMargin(0.20);
96 hh_model_1->GetZaxis()->SetTitleOffset(2.5);
97 hh_model_1->Draw("surf");
98 c->cd(2);
99 gPad->SetLeftMargin(0.20);
100 hh_model_2->GetZaxis()->SetTitleOffset(2.5);
101 hh_model_2->Draw("surf");
102 c->cd(3);
103 gPad->SetLeftMargin(0.20);
104 hh_model_3->GetZaxis()->SetTitleOffset(2.5);
105 hh_model_3->Draw("surf");
106 c->cd(4);
107 gPad->SetLeftMargin(0.20);
108 hh_model_4->GetZaxis()->SetTitleOffset(2.5);
109 hh_model_4->Draw("surf");
110}
#define c(i)
Definition: RSha256.hxx:101
@ kBlue
Definition: Rtypes.h:64
#define gPad
Definition: TVirtualPad.h:286
RooAddition calculates the sum of a set of RooAbsReal terms, or when constructed with two sets,...
Definition: RooAddition.h:26
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:28
A RooFormulaVar is a generic implementation of a real-valued object, which takes a RooArgList of serv...
Definition: RooFormulaVar.h:29
Plain Gaussian p.d.f.
Definition: RooGaussian.h:25
Class RooPolyVar is a RooAbsReal implementing a polynomial in terms of a list of RooAbsReal coefficie...
Definition: RooPolyVar.h:28
A RooProduct represents the product of a given set of RooAbsReal objects.
Definition: RooProduct.h:32
RooRealVar represents a variable that can be changed from the outside.
Definition: RooRealVar.h:35
virtual void SetTitleOffset(Float_t offset=1)
Set distance between the axis and the axis title.
Definition: TAttAxis.cxx:294
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition: TAttLine.h:40
The Canvas class.
Definition: TCanvas.h:31
The TH1 histogram class.
Definition: TH1.h:56
TAxis * GetZaxis()
Definition: TH1.h:318
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2998
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...
RooCmdArg Binning(const RooAbsBinning &binning)
RooCmdArg YVar(const RooAbsRealLValue &var, const RooCmdArg &arg=RooCmdArg::none())