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
5 /// composite (multidimensional) pdfs
6 ///
7 /// \macro_image
8 /// \macro_output
9 /// \macro_code
10 ///
11 /// \date July 2008
12 /// \author Wouter Verkerke
13 
14 #include "RooRealVar.h"
15 #include "RooDataSet.h"
16 #include "RooGaussian.h"
17 #include "TCanvas.h"
18 #include "TAxis.h"
19 #include "RooPlot.h"
20 #include "RooFormulaVar.h"
21 #include "RooAddition.h"
22 #include "RooProduct.h"
23 #include "RooPolyVar.h"
24 #include "TCanvas.h"
25 #include "TAxis.h"
26 #include "TH1.h"
27 
28 using namespace RooFit;
29 
30 void rf302_utilfuncs()
31 {
32  // 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
33  // -----------------------------------------------------------
34 
35  // Create observables
36  RooRealVar x("x", "x", -5, 5);
37  RooRealVar y("y", "y", -5, 5);
38 
39  // Create parameters
40  RooRealVar a0("a0", "a0", -1.5, -5, 5);
41  RooRealVar a1("a1", "a1", -0.5, -1, 1);
42  RooRealVar sigma("sigma", "width of gaussian", 0.5);
43 
44  // 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
45  // -----------------------------------------------------------------------
46 
47  // Create interpreted function f(y) = a0 - a1*sqrt(10*abs(y))
48  RooFormulaVar fy_1("fy_1", "a0-a1*sqrt(10*abs(y))", RooArgSet(y, a0, a1));
49 
50  // Create gauss(x,f(y),s)
51  RooGaussian model_1("model_1", "Gaussian with shifting mean", x, fy_1, sigma);
52 
53  // 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
54  // -----------------------------------------------------------------------
55 
56  // Create polynomial function f(y) = a0 + a1*y
57  RooPolyVar fy_2("fy_2", "fy_2", y, RooArgSet(a0, a1));
58 
59  // Create gauss(x,f(y),s)
60  RooGaussian model_2("model_2", "Gaussian with shifting mean", x, fy_2, sigma);
61 
62  // 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
63  // -----------------------------------------------------------------------
64 
65  // Create sum function f(y) = a0 + y
66  RooAddition fy_3("fy_3", "a0+y", RooArgSet(a0, y));
67 
68  // Create gauss(x,f(y),s)
69  RooGaussian model_3("model_3", "Gaussian with shifting mean", x, fy_3, sigma);
70 
71  // 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
72  // -----------------------------------------------------------------------
73 
74  // Create product function f(y) = a1*y
75  RooProduct fy_4("fy_4", "a1*y", RooArgSet(a1, y));
76 
77  // Create gauss(x,f(y),s)
78  RooGaussian model_4("model_4", "Gaussian with shifting mean", x, fy_4, sigma);
79 
80  // P l o t a l l p d f s
81  // ----------------------------
82 
83  // Make two-dimensional plots in x vs y
84  TH1 *hh_model_1 = model_1.createHistogram("hh_model_1", x, Binning(50), YVar(y, Binning(50)));
85  TH1 *hh_model_2 = model_2.createHistogram("hh_model_2", x, Binning(50), YVar(y, Binning(50)));
86  TH1 *hh_model_3 = model_3.createHistogram("hh_model_3", x, Binning(50), YVar(y, Binning(50)));
87  TH1 *hh_model_4 = model_4.createHistogram("hh_model_4", x, Binning(50), YVar(y, Binning(50)));
88  hh_model_1->SetLineColor(kBlue);
89  hh_model_2->SetLineColor(kBlue);
90  hh_model_3->SetLineColor(kBlue);
91  hh_model_4->SetLineColor(kBlue);
92 
93  // Make canvas and draw RooPlots
94  TCanvas *c = new TCanvas("rf302_utilfuncs", "rf302_utilfuncs", 800, 800);
95  c->Divide(2, 2);
96  c->cd(1);
97  gPad->SetLeftMargin(0.20);
98  hh_model_1->GetZaxis()->SetTitleOffset(2.5);
99  hh_model_1->Draw("surf");
100  c->cd(2);
101  gPad->SetLeftMargin(0.20);
102  hh_model_2->GetZaxis()->SetTitleOffset(2.5);
103  hh_model_2->Draw("surf");
104  c->cd(3);
105  gPad->SetLeftMargin(0.20);
106  hh_model_3->GetZaxis()->SetTitleOffset(2.5);
107  hh_model_3->Draw("surf");
108  c->cd(4);
109  gPad->SetLeftMargin(0.20);
110  hh_model_4->GetZaxis()->SetTitleOffset(2.5);
111  hh_model_4->Draw("surf");
112 }
RooFormulaVar.h
c
#define c(i)
Definition: RSha256.hxx:101
RooGaussian.h
x
Double_t x[n]
Definition: legend1.C:17
RooGaussian
Plain Gaussian p.d.f.
Definition: RooGaussian.h:24
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
RooPolyVar.h
RooProduct
A RooProduct represents the product of a given set of RooAbsReal objects.
Definition: RooProduct.h:30
RooFormulaVar
A RooFormulaVar is a generic implementation of a real-valued object, which takes a RooArgList of serv...
Definition: RooFormulaVar.h:30
RooFit
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Definition: RooCFunction1Binding.h:29
RooPlot.h
RooAddition
RooAddition calculates the sum of a set of RooAbsReal terms, or when constructed with two sets,...
Definition: RooAddition.h:27
RooAddition.h
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
RooProduct.h
sigma
const Double_t sigma
Definition: h1analysisProxy.h:11
TCanvas
The Canvas class.
Definition: TCanvas.h:23
rf302_utilfuncs
Definition: rf302_utilfuncs.py:1
TAxis.h
TH1
TH1 is the base class of all histogramm classes in ROOT.
Definition: TH1.h:58
kBlue
@ kBlue
Definition: Rtypes.h:66
gPad
#define gPad
Definition: TVirtualPad.h:287
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
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