Logo ROOT   6.14/05
Reference Guide
rf302_utilfuncs.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_roofit
3 /// \notebook
4 /// 'MULTIDIMENSIONAL MODELS' RooFit tutorial macro #302
5 ///
6 /// Utility functions classes available for use in tailoring
7 /// of composite (multidimensional) pdfs
8 ///
9 /// \macro_image
10 /// \macro_output
11 /// \macro_code
12 /// \author 07/2008 - Wouter Verkerke
13 
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 
32 void rf302_utilfuncs()
33 {
34  // 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
35  // -----------------------------------------------------------
36 
37  // Create observables
38  RooRealVar x("x","x",-5,5) ;
39  RooRealVar y("y","y",-5,5) ;
40 
41  // Create parameters
42  RooRealVar a0("a0","a0",-1.5,-5,5) ;
43  RooRealVar a1("a1","a1",-0.5,-1,1) ;
44  RooRealVar sigma("sigma","width of gaussian",0.5) ;
45 
46 
47  // 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
48  // -----------------------------------------------------------------------
49 
50  // Create interpreted function f(y) = a0 - a1*sqrt(10*abs(y))
51  RooFormulaVar fy_1("fy_1","a0-a1*sqrt(10*abs(y))",RooArgSet(y,a0,a1)) ;
52 
53  // Create gauss(x,f(y),s)
54  RooGaussian model_1("model_1","Gaussian with shifting mean",x,fy_1,sigma) ;
55 
56 
57 
58  // 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
59  // -----------------------------------------------------------------------
60 
61  // Create polynomial function f(y) = a0 + a1*y
62  RooPolyVar fy_2("fy_2","fy_2",y,RooArgSet(a0,a1)) ;
63 
64  // Create gauss(x,f(y),s)
65  RooGaussian model_2("model_2","Gaussian with shifting mean",x,fy_2,sigma) ;
66 
67 
68 
69  // 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
70  // -----------------------------------------------------------------------
71 
72  // Create sum function f(y) = a0 + y
73  RooAddition fy_3("fy_3","a0+y",RooArgSet(a0,y)) ;
74 
75  // Create gauss(x,f(y),s)
76  RooGaussian model_3("model_3","Gaussian with shifting mean",x,fy_3,sigma) ;
77 
78 
79 
80  // 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
81  // -----------------------------------------------------------------------
82 
83  // Create product function f(y) = a1*y
84  RooProduct fy_4("fy_4","a1*y",RooArgSet(a1,y)) ;
85 
86  // Create gauss(x,f(y),s)
87  RooGaussian model_4("model_4","Gaussian with shifting mean",x,fy_4,sigma) ;
88 
89 
90 
91  // P l o t a l l p d f s
92  // ----------------------------
93 
94  // Make two-dimensional plots in x vs y
95  TH1* hh_model_1 = model_1.createHistogram("hh_model_1",x,Binning(50),YVar(y,Binning(50))) ;
96  TH1* hh_model_2 = model_2.createHistogram("hh_model_2",x,Binning(50),YVar(y,Binning(50))) ;
97  TH1* hh_model_3 = model_3.createHistogram("hh_model_3",x,Binning(50),YVar(y,Binning(50))) ;
98  TH1* hh_model_4 = model_4.createHistogram("hh_model_4",x,Binning(50),YVar(y,Binning(50))) ;
99  hh_model_1->SetLineColor(kBlue) ;
100  hh_model_2->SetLineColor(kBlue) ;
101  hh_model_3->SetLineColor(kBlue) ;
102  hh_model_4->SetLineColor(kBlue) ;
103 
104  // Make canvas and draw RooPlots
105  TCanvas *c = new TCanvas("rf302_utilfuncs","rf302_utilfuncs",800, 800);
106  c->Divide(2,2);
107  c->cd(1) ; gPad->SetLeftMargin(0.20) ; hh_model_1->GetZaxis()->SetTitleOffset(2.5) ; hh_model_1->Draw("surf") ;
108  c->cd(2) ; gPad->SetLeftMargin(0.20) ; hh_model_2->GetZaxis()->SetTitleOffset(2.5) ; hh_model_2->Draw("surf") ;
109  c->cd(3) ; gPad->SetLeftMargin(0.20) ; hh_model_3->GetZaxis()->SetTitleOffset(2.5) ; hh_model_3->Draw("surf") ;
110  c->cd(4) ; gPad->SetLeftMargin(0.20) ; hh_model_4->GetZaxis()->SetTitleOffset(2.5) ; hh_model_4->Draw("surf") ;
111 
112 }
virtual void SetTitleOffset(Float_t offset=1)
Set distance between the axis and the axis title Offset is a correction factor with respect to the "s...
Definition: TAttAxis.cxx:294
TVirtualPad * cd(Int_t subpadnumber=0)
Set current canvas & pad.
Definition: TCanvas.cxx:688
Double_t x[n]
Definition: legend1.C:17
Plain Gaussian p.d.f.
Definition: RooGaussian.h:25
const Double_t sigma
Class RooPolyVar is a RooAbsReal implementing a polynomial in terms of a list of RooAbsReal coefficie...
Definition: RooPolyVar.h:28
RooRealVar represents a fundamental (non-derived) real valued object.
Definition: RooRealVar.h:36
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition: TAttLine.h:40
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2974
RooProduct a RooAbsReal implementation that represent the product of a given set of other RooAbsReal ...
Definition: RooProduct.h:32
The Canvas class.
Definition: TCanvas.h:31
RooCmdArg YVar(const RooAbsRealLValue &var, const RooCmdArg &arg=RooCmdArg::none())
Double_t y[n]
Definition: legend1.C:17
The TH1 histogram class.
Definition: TH1.h:56
TAxis * GetZaxis()
Definition: TH1.h:317
virtual void Divide(Int_t nx=1, Int_t ny=1, Float_t xmargin=0.01, Float_t ymargin=0.01, Int_t color=0)
Automatic pad generation by division.
Definition: TPad.cxx:1162
#define gPad
Definition: TVirtualPad.h:285
#define c(i)
Definition: RSha256.hxx:101
Definition: Rtypes.h:59
RooAddition calculates the sum of a set of RooAbsReal terms, or when constructed with two sets...
Definition: RooAddition.h:26
RooCmdArg Binning(const RooAbsBinning &binning)