ROOT  6.06/09
Reference Guide
rf302_utilfuncs.cxx
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////////
2 //
3 // 'MULTIDIMENSIONAL MODELS' RooFit tutorial macro #302
4 //
5 // Utility functions classes available for use in tailoring
6 // of composite (multidimensional) pdfs
7 //
8 //
9 // 07/2008 - Wouter Verkerke
10 //
11 /////////////////////////////////////////////////////////////////////////
12 
13 #ifndef __CINT__
14 #include "RooGlobalFunc.h"
15 #endif
16 #include "RooRealVar.h"
17 #include "RooDataSet.h"
18 #include "RooGaussian.h"
19 #include "TCanvas.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 "TH1.h"
27 
28 using namespace RooFit ;
29 
30 
31 class TestBasic302 : public RooFitTestUnit
32 {
33 public:
34  TestBasic302(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("Sum and product utility functions",refFile,writeRef,verbose) {} ;
35  Bool_t testCode() {
36 
37  // 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
38  // -----------------------------------------------------------
39 
40  // Create observables
41  RooRealVar x("x","x",-5,5) ;
42  RooRealVar y("y","y",-5,5) ;
43 
44  // Create parameters
45  RooRealVar a0("a0","a0",-1.5,-5,5) ;
46  RooRealVar a1("a1","a1",-0.5,-1,1) ;
47  RooRealVar sigma("sigma","width of gaussian",0.5) ;
48 
49 
50  // 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
51  // -----------------------------------------------------------------------
52 
53  // Create interpreted function f(y) = a0 - a1*sqrt(10*abs(y))
54  RooFormulaVar fy_1("fy_1","a0-a1*sqrt(10*abs(y))",RooArgSet(y,a0,a1)) ;
55 
56  // Create gauss(x,f(y),s)
57  RooGaussian model_1("model_1","Gaussian with shifting mean",x,fy_1,sigma) ;
58 
59 
60 
61  // 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
62  // -----------------------------------------------------------------------
63 
64  // Create polynomial function f(y) = a0 + a1*y
65  RooPolyVar fy_2("fy_2","fy_2",y,RooArgSet(a0,a1)) ;
66 
67  // Create gauss(x,f(y),s)
68  RooGaussian model_2("model_2","Gaussian with shifting mean",x,fy_2,sigma) ;
69 
70 
71 
72  // 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
73  // -----------------------------------------------------------------------
74 
75  // Create sum function f(y) = a0 + y
76  RooAddition fy_3("fy_3","a0+y",RooArgSet(a0,y)) ;
77 
78  // Create gauss(x,f(y),s)
79  RooGaussian model_3("model_3","Gaussian with shifting mean",x,fy_3,sigma) ;
80 
81 
82 
83  // 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
84  // -----------------------------------------------------------------------
85 
86  // Create product function f(y) = a1*y
87  RooProduct fy_4("fy_4","a1*y",RooArgSet(a1,y)) ;
88 
89  // Create gauss(x,f(y),s)
90  RooGaussian model_4("model_4","Gaussian with shifting mean",x,fy_4,sigma) ;
91 
92 
93 
94  // P l o t a l l p d f s
95  // ----------------------------
96 
97  // Make two-dimensional plots in x vs y
98  TH1* hh_model_1 = model_1.createHistogram("hh_model_1",x,Binning(50),YVar(y,Binning(50))) ;
99  TH1* hh_model_2 = model_2.createHistogram("hh_model_2",x,Binning(50),YVar(y,Binning(50))) ;
100  TH1* hh_model_3 = model_3.createHistogram("hh_model_3",x,Binning(50),YVar(y,Binning(50))) ;
101  TH1* hh_model_4 = model_4.createHistogram("hh_model_4",x,Binning(50),YVar(y,Binning(50))) ;
102  hh_model_1->SetLineColor(kBlue) ;
103  hh_model_2->SetLineColor(kBlue) ;
104  hh_model_3->SetLineColor(kBlue) ;
105  hh_model_4->SetLineColor(kBlue) ;
106 
107  regTH(hh_model_1,"rf202_model2d_1") ;
108  regTH(hh_model_2,"rf202_model2d_2") ;
109  regTH(hh_model_3,"rf202_model2d_3") ;
110  regTH(hh_model_4,"rf202_model2d_4") ;
111 
112  return kTRUE ;
113  }
114 } ;
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Definition: TFile.h:45
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
Double_t x[n]
Definition: legend1.C:17
virtual void SetLineColor(Color_t lcolor)
Definition: TAttLine.h:54
bool verbose
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:80
Definition: Rtypes.h:61
const Bool_t kTRUE
Definition: Rtypes.h:91
RooCmdArg Binning(const RooAbsBinning &binning)