Loading [MathJax]/extensions/tex2jax.js
Logo ROOT   6.16/01
Reference Guide
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
rf203_ranges.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_roofit
3/// \notebook -js
4/// 'ADDITION AND CONVOLUTION' RooFit tutorial macro #203
5///
6/// Fitting and plotting in sub ranges
7///
8/// \macro_image
9/// \macro_output
10/// \macro_code
11/// \author 07/2008 - Wouter Verkerke
12
13
14#include "RooRealVar.h"
15#include "RooDataSet.h"
16#include "RooGaussian.h"
17#include "RooConstVar.h"
18#include "RooPolynomial.h"
19#include "RooAddPdf.h"
20#include "RooFitResult.h"
21#include "RooPlot.h"
22#include "TCanvas.h"
23#include "TAxis.h"
24#include "TH1.h"
25using namespace RooFit ;
26
27
28void rf203_ranges()
29{
30 // S e t u p m o d e l
31 // ---------------------
32
33 // Construct observables x
34 RooRealVar x("x","x",-10,10) ;
35
36 // Construct gaussx(x,mx,1)
37 RooRealVar mx("mx","mx",0,-10,10) ;
38 RooGaussian gx("gx","gx",x,mx,RooConst(1)) ;
39
40 // Construct px = 1 (flat in x)
41 RooPolynomial px("px","px",x) ;
42
43 // Construct model = f*gx + (1-f)px
44 RooRealVar f("f","f",0.,1.) ;
45 RooAddPdf model("model","model",RooArgList(gx,px),f) ;
46
47 // Generated 10000 events in (x,y) from p.d.f. model
48 RooDataSet* modelData = model.generate(x,10000) ;
49
50 // F i t f u l l r a n g e
51 // ---------------------------
52
53 // Fit p.d.f to all data
54 RooFitResult* r_full = model.fitTo(*modelData,Save(kTRUE)) ;
55
56
57 // F i t p a r t i a l r a n g e
58 // ----------------------------------
59
60 // Define "signal" range in x as [-3,3]
61 x.setRange("signal",-3,3) ;
62
63 // Fit p.d.f only to data in "signal" range
64 RooFitResult* r_sig = model.fitTo(*modelData,Save(kTRUE),Range("signal")) ;
65
66
67 // P l o t / p r i n t r e s u l t s
68 // ---------------------------------------
69
70 // Make plot frame in x and add data and fitted model
71 RooPlot* frame = x.frame(Title("Fitting a sub range")) ;
72 modelData->plotOn(frame) ;
73 model.plotOn(frame,Range("Full"),LineStyle(kDashed),LineColor(kRed)) ; // Add shape in full ranged dashed
74 model.plotOn(frame) ; // By default only fitted range is shown
75
76 // Print fit results
77 cout << "result of fit on all data " << endl ;
78 r_full->Print() ;
79 cout << "result of fit in in signal region (note increased error on signal fraction)" << endl ;
80 r_sig->Print() ;
81
82 // Draw frame on canvas
83 new TCanvas("rf203_ranges","rf203_ranges",600,600) ;
84 gPad->SetLeftMargin(0.15) ; frame->GetYaxis()->SetTitleOffset(1.4) ; frame->Draw() ;
85
86 return ;
87
88}
#define f(i)
Definition: RSha256.hxx:104
const Bool_t kTRUE
Definition: RtypesCore.h:87
@ kRed
Definition: Rtypes.h:63
@ kDashed
Definition: TAttLine.h:48
#define gPad
Definition: TVirtualPad.h:286
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
Calls RooPlot* plotOn(RooPlot* frame, const RooLinkedList& cmdList) const ;.
Definition: RooAbsData.cxx:531
RooAddPdf is an efficient implementation of a sum of PDFs of the form.
Definition: RooAddPdf.h:29
RooDataSet is a container class to hold unbinned data.
Definition: RooDataSet.h:31
RooFitResult is a container class to hold the input and output of a PDF fit to a dataset.
Definition: RooFitResult.h:40
virtual void Print(Option_t *options=0) const
Print TNamed name and title.
Definition: RooFitResult.h:66
Plain Gaussian p.d.f.
Definition: RooGaussian.h:25
A RooPlot is a plot frame and a container for graphics objects within that frame.
Definition: RooPlot.h:41
TAxis * GetYaxis() const
Definition: RooPlot.cxx:1123
virtual void Draw(Option_t *options=0)
Draw this plot and all of the elements it contains.
Definition: RooPlot.cxx:558
RooPolynomial implements a polynomial p.d.f of the form.
Definition: RooPolynomial.h:28
RooRealVar represents a fundamental (non-derived) real valued object.
Definition: RooRealVar.h:36
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
The Canvas class.
Definition: TCanvas.h:31
Double_t x[n]
Definition: legend1.C:17
RooConstVar & RooConst(Double_t val)
RooCmdArg Save(Bool_t flag=kTRUE)
RooCmdArg LineColor(Color_t color)
RooCmdArg LineStyle(Style_t style)
const char * Title
Definition: TXMLSetup.cxx:67
Ta Range(0, 0, 1, 1)