Logo ROOT   6.08/07
Reference Guide
rf210_angularconv.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_roofit
3 /// \notebook -js
4 /// 'ADDITION AND CONVOLUTION' RooFit tutorial macro #210
5 ///
6 /// Convolution in cyclical angular observables theta, and
7 /// construction of p.d.f in terms of transformed angular
8 /// coordinates, e.g. cos(theta), where the convolution
9 /// is performed in theta rather than cos(theta)
10 ///
11 /// (require ROOT to be compiled with --enable-fftw3)
12 ///
13 /// pdf(theta) = T(theta) (x) gauss(theta)
14 /// pdf(cosTheta) = T(acos(cosTheta)) (x) gauss(acos(cosTheta))
15 ///
16 /// \macro_image
17 /// \macro_output
18 /// \macro_code
19 /// \author 04/2009 - Wouter Verkerke
20 
21 
22 #include "RooRealVar.h"
23 #include "RooDataSet.h"
24 #include "RooGaussian.h"
25 #include "RooGenericPdf.h"
26 #include "RooFormulaVar.h"
27 #include "RooFFTConvPdf.h"
28 #include "RooPlot.h"
29 #include "TCanvas.h"
30 #include "TAxis.h"
31 #include "TH1.h"
32 using namespace RooFit ;
33 
34 
35 
36 void rf210_angularconv()
37 {
38  // S e t u p c o m p o n e n t p d f s
39  // ---------------------------------------
40 
41  // Define angle psi
42  RooRealVar psi("psi","psi",0,3.14159268) ;
43 
44  // Define physics p.d.f T(psi)
45  RooGenericPdf Tpsi("Tpsi","1+sin(2*@0)",psi) ;
46 
47  // Define resolution R(psi)
48  RooRealVar gbias("gbias","gbias",0.2,0.,1) ;
49  RooRealVar greso("greso","greso",0.3,0.1,1.0) ;
50  RooGaussian Rpsi("Rpsi","Rpsi",psi,gbias,greso) ;
51 
52  // Define cos(psi) and function psif that calculates psi from cos(psi)
53  RooRealVar cpsi("cpsi","cos(psi)",-1,1) ;
54  RooFormulaVar psif("psif","acos(cpsi)",cpsi) ;
55 
56  // Define physics p.d.f. also as function of cos(psi): T(psif(cpsi)) = T(cpsi) ;
57  RooGenericPdf Tcpsi("T","1+sin(2*@0)",psif) ;
58 
59 
60 
61  // C o n s t r u c t c o n v o l u t i o n p d f i n p s i
62  // --------------------------------------------------------------
63 
64  // Define convoluted p.d.f. as function of psi: M=[T(x)R](psi) = M(psi)
65  RooFFTConvPdf Mpsi("Mf","Mf",psi,Tpsi,Rpsi) ;
66 
67  // Set the buffer fraction to zero to obtain a true cyclical convolution
68  Mpsi.setBufferFraction(0) ;
69 
70 
71 
72  // S a m p l e , f i t a n d p l o t c o n v o l u t e d p d f ( p s i )
73  // --------------------------------------------------------------------------------
74 
75  // Generate some events in observable psi
76  RooDataSet* data_psi = Mpsi.generate(psi,10000) ;
77 
78  // Fit convoluted model as function of angle psi
79  Mpsi.fitTo(*data_psi) ;
80 
81  // Plot cos(psi) frame with Mf(cpsi)
82  RooPlot* frame1 = psi.frame(Title("Cyclical convolution in angle psi")) ;
83  data_psi->plotOn(frame1) ;
84  Mpsi.plotOn(frame1) ;
85 
86  // Overlay comparison to unsmeared physics p.d.f T(psi)
87  Tpsi.plotOn(frame1,LineColor(kRed)) ;
88 
89 
90 
91  // C o n s t r u c t c o n v o l u t i o n p d f i n c o s ( p s i )
92  // --------------------------------------------------------------------------
93 
94 
95  // Define convoluted p.d.f. as function of cos(psi): M=[T(x)R](psif(cpsi)) = M(cpsi)
96  //
97  // Need to give both observable psi here (for definition of convolution)
98  // and function psif here (for definition of observables, ultimately in cpsi)
99  RooFFTConvPdf Mcpsi("Mf","Mf",psif,psi,Tpsi,Rpsi) ;
100 
101  // Set the buffer fraction to zero to obtain a true cyclical convolution
102  Mcpsi.setBufferFraction(0) ;
103 
104 
105  // S a m p l e , f i t a n d p l o t c o n v o l u t e d p d f ( c o s p s i )
106  // --------------------------------------------------------------------------------
107 
108  // Generate some events
109  RooDataSet* data_cpsi = Mcpsi.generate(cpsi,10000) ;
110 
111  // set psi constant to exclude to be a parameter of the fit
112  psi.setConstant(true);
113 
114  // Fit convoluted model as function of cos(psi)
115  Mcpsi.fitTo(*data_cpsi) ;
116 
117  // Plot cos(psi) frame with Mf(cpsi)
118  RooPlot* frame2 = cpsi.frame(Title("Same convolution in psi, expressed in cos(psi)")) ;
119  data_cpsi->plotOn(frame2) ;
120  Mcpsi.plotOn(frame2) ;
121 
122  // Overlay comparison to unsmeared physics p.d.f Tf(cpsi)
123  Tcpsi.plotOn(frame2,LineColor(kRed)) ;
124 
125 
126 
127  // Draw frame on canvas
128  TCanvas* c = new TCanvas("rf210_angularconv","rf210_angularconv",800,400) ;
129  c->Divide(2) ;
130  c->cd(1) ; gPad->SetLeftMargin(0.15) ; frame1->GetYaxis()->SetTitleOffset(1.4) ; frame1->Draw() ;
131  c->cd(2) ; gPad->SetLeftMargin(0.15) ; frame2->GetYaxis()->SetTitleOffset(1.4) ; frame2->Draw() ;
132 
133 }
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:262
TAxis * GetYaxis() const
Definition: RooPlot.cxx:1118
virtual RooPlot * plotOn(RooPlot *frame, const RooCmdArg &arg1=RooCmdArg::none(), const RooCmdArg &arg2=RooCmdArg::none(), const RooCmdArg &arg3=RooCmdArg::none(), const RooCmdArg &arg4=RooCmdArg::none(), const RooCmdArg &arg5=RooCmdArg::none(), const RooCmdArg &arg6=RooCmdArg::none(), const RooCmdArg &arg7=RooCmdArg::none(), const RooCmdArg &arg8=RooCmdArg::none()) const
Plot dataset on specified frame.
Definition: RooAbsData.cxx:552
RooCmdArg LineColor(Color_t color)
return c
Definition: Rtypes.h:61
TVirtualPad * cd(Int_t subpadnumber=0)
Set current canvas & pad.
Definition: TCanvas.cxx:659
RooCmdArg Title(const char *name)
Plain Gaussian p.d.f.
Definition: RooGaussian.h:25
RooRealVar represents a fundamental (non-derived) real valued object.
Definition: RooRealVar.h:37
RooDataSet is a container class to hold unbinned data.
Definition: RooDataSet.h:29
A RooPlot is a plot frame and a container for graphics objects within that frame. ...
Definition: RooPlot.h:41
The Canvas class.
Definition: TCanvas.h:41
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:1089
#define gPad
Definition: TVirtualPad.h:289
RooGenericPdf is a concrete implementation of a probability density function, which takes a RooArgLis...
Definition: RooGenericPdf.h:25
virtual void Draw(Option_t *options=0)
Draw this plot and all of the elements it contains.
Definition: RooPlot.cxx:559