Logo ROOT  
Reference Guide
rf110_normintegration.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_roofit
3 /// \notebook -js
4 ///
5 /// Basic functionality: normalization and integration of p.d.fs, construction of cumulative distribution
6 /// monodimensional functions
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 "RooGaussian.h"
17 #include "RooConstVar.h"
18 #include "RooAbsReal.h"
19 #include "RooPlot.h"
20 #include "TCanvas.h"
21 #include "TAxis.h"
22 using namespace RooFit;
23 
25 {
26  // S e t u p m o d e l
27  // ---------------------
28 
29  // Create observables x,y
30  RooRealVar x("x", "x", -10, 10);
31 
32  // Create p.d.f. gaussx(x,-2,3)
33  RooGaussian gx("gx", "gx", x, RooConst(-2), RooConst(3));
34 
35  // R e t r i e v e r a w & n o r m a l i z e d v a l u e s o f R o o F i t p . d . f . s
36  // --------------------------------------------------------------------------------------------------
37 
38  // Return 'raw' unnormalized value of gx
39  cout << "gx = " << gx.getVal() << endl;
40 
41  // Return value of gx normalized over x in range [-10,10]
42  RooArgSet nset(x);
43  cout << "gx_Norm[x] = " << gx.getVal(&nset) << endl;
44 
45  // Create object representing integral over gx
46  // which is used to calculate gx_Norm[x] == gx / gx_Int[x]
47  RooAbsReal *igx = gx.createIntegral(x);
48  cout << "gx_Int[x] = " << igx->getVal() << endl;
49 
50  // I n t e g r a t e n o r m a l i z e d p d f o v e r s u b r a n g e
51  // ----------------------------------------------------------------------------
52 
53  // Define a range named "signal" in x from -5,5
54  x.setRange("signal", -5, 5);
55 
56  // Create an integral of gx_Norm[x] over x in range "signal"
57  // This is the fraction of of p.d.f. gx_Norm[x] which is in the
58  // range named "signal"
59  RooAbsReal *igx_sig = gx.createIntegral(x, NormSet(x), Range("signal"));
60  cout << "gx_Int[x|signal]_Norm[x] = " << igx_sig->getVal() << endl;
61 
62  // C o n s t r u c t c u m u l a t i v e d i s t r i b u t i o n f u n c t i o n f r o m p d f
63  // -----------------------------------------------------------------------------------------------------
64 
65  // Create the cumulative distribution function of gx
66  // i.e. calculate Int[-10,x] gx(x') dx'
67  RooAbsReal *gx_cdf = gx.createCdf(x);
68 
69  // Plot cdf of gx versus x
70  RooPlot *frame = x.frame(Title("c.d.f of Gaussian p.d.f"));
71  gx_cdf->plotOn(frame);
72 
73  // Draw plot on canvas
74  new TCanvas("rf110_normintegration", "rf110_normintegration", 600, 600);
75  gPad->SetLeftMargin(0.15);
76  frame->GetYaxis()->SetTitleOffset(1.6);
77  frame->Draw();
78 }
RooPlot::Draw
virtual void Draw(Option_t *options=0)
Draw this plot and all of the elements it contains.
Definition: RooPlot.cxx:691
RooAbsReal.h
RooAbsReal::createIntegral
RooAbsReal * createIntegral(const RooArgSet &iset, const RooCmdArg &arg1, 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
Create an object that represents the integral of the function over one or more observables listed in ...
Definition: RooAbsReal.cxx:561
RooGaussian.h
RooAbsReal::getVal
Double_t getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
Definition: RooAbsReal.h:91
x
Double_t x[n]
Definition: legend1.C:17
RooGaussian
Definition: RooGaussian.h:25
RooAbsReal
Definition: RooAbsReal.h:61
TCanvas.h
RooFit
Definition: RooCFunction1Binding.h:29
RooPlot.h
RooPlot::GetYaxis
TAxis * GetYaxis() const
Definition: RooPlot.cxx:1256
RooPlot
Definition: RooPlot.h:44
RooRealVar.h
rf110_normintegration
Definition: rf110_normintegration.py:1
RooConstVar.h
RooAbsReal::plotOn
virtual RooPlot * plotOn(RooPlot *frame, const RooCmdArg &arg1=RooCmdArg(), const RooCmdArg &arg2=RooCmdArg(), const RooCmdArg &arg3=RooCmdArg(), const RooCmdArg &arg4=RooCmdArg(), const RooCmdArg &arg5=RooCmdArg(), const RooCmdArg &arg6=RooCmdArg(), const RooCmdArg &arg7=RooCmdArg(), const RooCmdArg &arg8=RooCmdArg(), const RooCmdArg &arg9=RooCmdArg(), const RooCmdArg &arg10=RooCmdArg()) const
Plot (project) PDF on specified frame.
Definition: RooAbsReal.cxx:1714
RooFit::NormSet
RooCmdArg NormSet(const RooArgSet &nset)
Definition: RooGlobalFunc.cxx:256
TCanvas
Definition: TCanvas.h:23
TAxis.h
RooFit::Range
RooCmdArg Range(const char *rangeName, Bool_t adjustNorm=kTRUE)
Definition: RooGlobalFunc.cxx:52
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
RooFit::Title
RooCmdArg Title(const char *name)
Definition: RooGlobalFunc.cxx:173
RooArgSet
Definition: RooArgSet.h:28
RooFit::RooConst
RooConstVar & RooConst(Double_t val)
Definition: RooGlobalFunc.cxx:341