Logo ROOT  
Reference Guide
rf302_utilfuncs.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_roofit
3 /// \notebook
4 ///
5 /// Multidimensional models: utility functions classes available for use in tailoring of
6 /// composite (multidimensional) pdfs
7 ///
8 /// \macro_image
9 /// \macro_output
10 /// \macro_code
11 ///
12 /// \date 07/2008
13 /// \author Wouter Verkerke
14 
15 #include "RooRealVar.h"
16 #include "RooDataSet.h"
17 #include "RooGaussian.h"
18 #include "TCanvas.h"
19 #include "TAxis.h"
20 #include "RooPlot.h"
21 #include "RooFormulaVar.h"
22 #include "RooAddition.h"
23 #include "RooProduct.h"
24 #include "RooPolyVar.h"
25 #include "TCanvas.h"
26 #include "TAxis.h"
27 #include "TH1.h"
28 
29 using namespace RooFit;
30 
31 void rf302_utilfuncs()
32 {
33  // 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
34  // -----------------------------------------------------------
35 
36  // Create observables
37  RooRealVar x("x", "x", -5, 5);
38  RooRealVar y("y", "y", -5, 5);
39 
40  // Create parameters
41  RooRealVar a0("a0", "a0", -1.5, -5, 5);
42  RooRealVar a1("a1", "a1", -0.5, -1, 1);
43  RooRealVar sigma("sigma", "width of gaussian", 0.5);
44 
45  // 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
46  // -----------------------------------------------------------------------
47 
48  // Create interpreted function f(y) = a0 - a1*sqrt(10*abs(y))
49  RooFormulaVar fy_1("fy_1", "a0-a1*sqrt(10*abs(y))", RooArgSet(y, a0, a1));
50 
51  // Create gauss(x,f(y),s)
52  RooGaussian model_1("model_1", "Gaussian with shifting mean", x, fy_1, sigma);
53 
54  // 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
55  // -----------------------------------------------------------------------
56 
57  // Create polynomial function f(y) = a0 + a1*y
58  RooPolyVar fy_2("fy_2", "fy_2", y, RooArgSet(a0, a1));
59 
60  // Create gauss(x,f(y),s)
61  RooGaussian model_2("model_2", "Gaussian with shifting mean", x, fy_2, sigma);
62 
63  // 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
64  // -----------------------------------------------------------------------
65 
66  // Create sum function f(y) = a0 + y
67  RooAddition fy_3("fy_3", "a0+y", RooArgSet(a0, y));
68 
69  // Create gauss(x,f(y),s)
70  RooGaussian model_3("model_3", "Gaussian with shifting mean", x, fy_3, sigma);
71 
72  // 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
73  // -----------------------------------------------------------------------
74 
75  // Create product function f(y) = a1*y
76  RooProduct fy_4("fy_4", "a1*y", RooArgSet(a1, y));
77 
78  // Create gauss(x,f(y),s)
79  RooGaussian model_4("model_4", "Gaussian with shifting mean", x, fy_4, sigma);
80 
81  // P l o t a l l p d f s
82  // ----------------------------
83 
84  // Make two-dimensional plots in x vs y
85  TH1 *hh_model_1 = model_1.createHistogram("hh_model_1", x, Binning(50), YVar(y, Binning(50)));
86  TH1 *hh_model_2 = model_2.createHistogram("hh_model_2", x, Binning(50), YVar(y, Binning(50)));
87  TH1 *hh_model_3 = model_3.createHistogram("hh_model_3", x, Binning(50), YVar(y, Binning(50)));
88  TH1 *hh_model_4 = model_4.createHistogram("hh_model_4", x, Binning(50), YVar(y, Binning(50)));
89  hh_model_1->SetLineColor(kBlue);
90  hh_model_2->SetLineColor(kBlue);
91  hh_model_3->SetLineColor(kBlue);
92  hh_model_4->SetLineColor(kBlue);
93 
94  // Make canvas and draw RooPlots
95  TCanvas *c = new TCanvas("rf302_utilfuncs", "rf302_utilfuncs", 800, 800);
96  c->Divide(2, 2);
97  c->cd(1);
98  gPad->SetLeftMargin(0.20);
99  hh_model_1->GetZaxis()->SetTitleOffset(2.5);
100  hh_model_1->Draw("surf");
101  c->cd(2);
102  gPad->SetLeftMargin(0.20);
103  hh_model_2->GetZaxis()->SetTitleOffset(2.5);
104  hh_model_2->Draw("surf");
105  c->cd(3);
106  gPad->SetLeftMargin(0.20);
107  hh_model_3->GetZaxis()->SetTitleOffset(2.5);
108  hh_model_3->Draw("surf");
109  c->cd(4);
110  gPad->SetLeftMargin(0.20);
111  hh_model_4->GetZaxis()->SetTitleOffset(2.5);
112  hh_model_4->Draw("surf");
113 }
RooFormulaVar.h
c
#define c(i)
Definition: RSha256.hxx:119
RooGaussian.h
x
Double_t x[n]
Definition: legend1.C:17
RooGaussian
Definition: RooGaussian.h:25
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:319
RooDataSet.h
RooPolyVar.h
RooProduct
Definition: RooProduct.h:30
RooFormulaVar
Definition: RooFormulaVar.h:30
RooFit
Definition: RooCFunction1Binding.h:29
RooPlot.h
RooAddition
Definition: RooAddition.h:27
RooAddition.h
y
Double_t y[n]
Definition: legend1.C:17
RooRealVar.h
RooPolyVar
Definition: RooPolyVar.h:28
RooProduct.h
sigma
const Double_t sigma
Definition: h1analysisProxy.h:11
TCanvas
Definition: TCanvas.h:23
rf302_utilfuncs
Definition: rf302_utilfuncs.py:1
TAxis.h
TH1
Definition: TH1.h:57
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
Definition: RooRealVar.h:35
TH1.h
RooArgSet
Definition: RooArgSet.h:28
TH1::Draw
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2997