ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
rf207_comptools.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_roofit
3 /// 'ADDITION AND CONVOLUTION' RooFit tutorial macro #207
4 ///
5 /// Tools and utilities for manipulation of composite objects
6 ///
7 ///
8 /// \macro_code
9 /// \author 07/2008 - Wouter Verkerke
10 
11 
12 #ifndef __CINT__
13 #include "RooGlobalFunc.h"
14 #endif
15 #include "RooRealVar.h"
16 #include "RooDataSet.h"
17 #include "RooGaussian.h"
18 #include "RooChebychev.h"
19 #include "RooExponential.h"
20 #include "RooAddPdf.h"
21 #include "RooPlot.h"
22 #include "RooCustomizer.h"
23 #include "TCanvas.h"
24 #include "TAxis.h"
25 #include "TH1.h"
26 using namespace RooFit ;
27 
28 
29 
30 void rf207_comptools()
31 {
32 
33  // S e t u p c o m p o s i t e p d f, d a t a s e t
34  // --------------------------------------------------------
35 
36  // Declare observable x
37  RooRealVar x("x","x",0,10) ;
38 
39  // Create two Gaussian PDFs g1(x,mean1,sigma) anf g2(x,mean2,sigma) and their parameters
40  RooRealVar mean("mean","mean of gaussians",5) ;
41  RooRealVar sigma("sigma","width of gaussians",0.5) ;
42  RooGaussian sig("sig","Signal component 1",x,mean,sigma) ;
43 
44  // Build Chebychev polynomial p.d.f.
45  RooRealVar a0("a0","a0",0.5,0.,1.) ;
46  RooRealVar a1("a1","a1",-0.2,0.,1.) ;
47  RooChebychev bkg1("bkg1","Background 1",x,RooArgSet(a0,a1)) ;
48 
49  // Build expontential pdf
50  RooRealVar alpha("alpha","alpha",-1) ;
51  RooExponential bkg2("bkg2","Background 2",x,alpha) ;
52 
53  // Sum the background components into a composite background p.d.f.
54  RooRealVar bkg1frac("bkg1frac","fraction of component 1 in background",0.2,0.,1.) ;
55  RooAddPdf bkg("bkg","Signal",RooArgList(bkg1,bkg2),bkg1frac) ;
56 
57  // Sum the composite signal and background
58  RooRealVar bkgfrac("bkgfrac","fraction of background",0.5,0.,1.) ;
59  RooAddPdf model("model","g1+g2+a",RooArgList(bkg,sig),bkgfrac) ;
60 
61 
62 
63  // Create dummy dataset that has more observables than the above pdf
64  RooRealVar y("y","y",-10,10) ;
65  RooDataSet data("data","data",RooArgSet(x,y)) ;
66 
67 
68 
69 
70  //////////////////////////////////////////////////////////
71  // B a s i c i n f o r m a t i o n r e q u e s t s //
72  //////////////////////////////////////////////////////////
73 
74 
75  // G e t l i s t o f o b s e r v a b l e s
76  // ---------------------------------------------
77 
78  // Get list of observables of pdf in context of a dataset
79  //
80  // Observables are define each context as the variables
81  // shared between a model and a dataset. In this case
82  // that is the variable 'x'
83 
84  RooArgSet* model_obs = model.getObservables(data) ;
85  model_obs->Print("v") ;
86 
87 
88  // G e t l i s t o f p a r a m e t e r s
89  // -------------------------------------------
90 
91  // Get list of parameters, given list of observables
92  RooArgSet* model_params = model.getParameters(x) ;
93  model_params->Print("v") ;
94 
95  // Get list of parameters, given a dataset
96  // (Gives identical results to operation above)
97  RooArgSet* model_params2 = model.getParameters(data) ;
98  model_params2->Print() ;
99 
100 
101  // G e t l i s t o f c o m p o n e n t s
102  // -------------------------------------------
103 
104  // Get list of component objects, including top-level node
105  RooArgSet* model_comps = model.getComponents() ;
106  model_comps->Print("v") ;
107 
108 
109  /////////////////////////////////////////////////////////////////////////////////////
110  // M o d i f i c a t i o n s t o s t r u c t u r e o f c o m p o s i t e s //
111  /////////////////////////////////////////////////////////////////////////////////////
112 
113 
114  // Create a second Gaussian
115  RooRealVar sigma2("sigma2","width of gaussians",1) ;
116  RooGaussian sig2("sig2","Signal component 1",x,mean,sigma2) ;
117 
118  // Create a sum of the original Gaussian plus the new second Gaussian
119  RooRealVar sig1frac("sig1frac","fraction of component 1 in signal",0.8,0.,1.) ;
120  RooAddPdf sigsum("sigsum","sig+sig2",RooArgList(sig,sig2),sig1frac) ;
121 
122  // Construct a customizer utility to customize model
123  RooCustomizer cust(model,"cust") ;
124 
125  // Instruct the customizer to replace node 'sig' with node 'sigsum'
126  cust.replaceArg(sig,sigsum) ;
127 
128  // Build a clone of the input pdf according to the above customization
129  // instructions. Each node that requires modified is clone so that the
130  // original pdf remained untouched. The name of each cloned node is that
131  // of the original node suffixed by the name of the customizer object
132  //
133  // The returned head node own all nodes that were cloned as part of
134  // the build process so when cust_clone is deleted so will all other
135  // nodes that were created in the process.
136  RooAbsPdf* cust_clone = (RooAbsPdf*) cust.build(kTRUE) ;
137 
138  // Print structure of clone of model with sig->sigsum replacement.
139  cust_clone->Print("t") ;
140 
141 
142  delete cust_clone ;
143 
144 }
Double_t x[n]
Definition: legend1.C:17
virtual void Print(Option_t *options=0) const
Print TNamed name and title.
Definition: RooAbsArg.h:227
Plain Gaussian p.d.f.
Definition: RooGaussian.h:25
friend class RooArgSet
Definition: RooAbsArg.h:469
Exponential p.d.f.
const Double_t sigma
RooRealVar represents a fundamental (non-derived) real valued object.
Definition: RooRealVar.h:37
virtual void Print(Option_t *options=0) const
This method must be overridden when a class wants to print itself.
RooDataSet is a container class to hold unbinned data.
Definition: RooDataSet.h:29
Double_t y[n]
Definition: legend1.C:17
RooAbsPdf is the abstract interface for all probability density functions The class provides hybrid a...
Definition: RooAbsPdf.h:41
Chebychev polynomial p.d.f.
Definition: RooChebychev.h:25
const Bool_t kTRUE
Definition: Rtypes.h:91
RooAbsMoment * mean(RooRealVar &obs)
Definition: RooAbsReal.h:297