Logo ROOT   6.16/01
Reference Guide
rf106_plotdecoration.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_roofit
3/// \notebook -js
4/// 'BASIC FUNCTIONALITY' RooFit tutorial macro #106
5///
6/// Adding boxes with parameters, statistics to RooPlots.
7/// Decorating RooPlots with arrows, text etc...
8/// \macro_image
9/// \macro_output
10/// \macro_code
11/// \author 07/2008 - Wouter Verkerke
12
13
14
15#include "RooRealVar.h"
16#include "RooDataSet.h"
17#include "RooGaussian.h"
18#include "TCanvas.h"
19#include "TAxis.h"
20#include "RooPlot.h"
21#include "TText.h"
22#include "TArrow.h"
23#include "TFile.h"
24using namespace RooFit ;
25
26
28{
29 // S e t u p m o d e l
30 // ---------------------
31
32 // Create observables
33 RooRealVar x("x","x",-10,10) ;
34
35 // Create Gaussian
36 RooRealVar sigma("sigma","sigma",1,0.1,10) ;
37 RooRealVar mean("mean","mean",-3,-10,10) ;
38 RooGaussian gauss("gauss","gauss",x,mean,sigma) ;
39
40 // Generate a sample of 1000 events with sigma=3
41 RooDataSet* data = gauss.generate(x,1000) ;
42
43 // Fit pdf to data
44 gauss.fitTo(*data) ;
45
46
47 // P l o t p . d . f a n d d a t a
48 // -------------------------------------
49
50 // Overlay projection of gauss on data
51 RooPlot* frame = x.frame(Name("xframe"),Title("RooPlot with decorations"),Bins(40)) ;
52 data->plotOn(frame) ;
53 gauss.plotOn(frame) ;
54
55
56 // A d d b o x w i t h p d f p a r a m e t e r s
57 // -----------------------------------------------------
58
59 // Left edge of box starts at 55% of Xaxis)
60 gauss.paramOn(frame,Layout(0.55)) ;
61
62
63 // A d d b o x w i t h d a t a s t a t i s t i c s
64 // -------------------------------------------------------
65
66 // X size of box is from 55% to 99% of Xaxis range, top of box is at 80% of Yaxis range)
67 data->statOn(frame,Layout(0.55,0.99,0.8)) ;
68
69
70 // A d d t e x t a n d a r r o w
71 // -----------------------------------
72
73 // Add text to frame
74 TText* txt = new TText(2,100,"Signal") ;
75 txt->SetTextSize(0.04) ;
76 txt->SetTextColor(kRed) ;
77 frame->addObject(txt) ;
78
79 // Add arrow to frame
80 TArrow* arrow = new TArrow(2,100,-1,50,0.01,"|>") ;
81 arrow->SetLineColor(kRed) ;
82 arrow->SetFillColor(kRed) ;
83 arrow->SetLineWidth(3) ;
84 frame->addObject(arrow) ;
85
86
87 // P e r s i s t f r a m e w i t h a l l d e c o r a t i o n s i n R O O T f i l e
88 // ---------------------------------------------------------------------------------------------
89
90 TFile f("rf106_plotdecoration.root","RECREATE") ;
91 frame->Write() ;
92 f.Close() ;
93
94 // To read back and plot frame with all decorations in clean root session do
95 // root> TFile f("rf106_plotdecoration.root") ;
96 // root> xframe->Draw() ;
97
98 new TCanvas("rf106_plotdecoration","rf106_plotdecoration",600,600) ;
99 gPad->SetLeftMargin(0.15) ; frame->GetYaxis()->SetTitleOffset(1.6) ; frame->Draw() ;
100
101}
#define f(i)
Definition: RSha256.hxx:104
@ kRed
Definition: Rtypes.h:63
#define gPad
Definition: TVirtualPad.h:286
RooDataSet is a container class to hold unbinned data.
Definition: RooDataSet.h:31
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
void addObject(TObject *obj, Option_t *drawOptions="", Bool_t invisible=kFALSE)
Add a generic object to this plot.
Definition: RooPlot.cxx:391
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
RooRealVar represents a fundamental (non-derived) real valued object.
Definition: RooRealVar.h:36
Draw all kinds of Arrows.
Definition: TArrow.h:29
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
virtual void SetTextColor(Color_t tcolor=1)
Set the text color.
Definition: TAttText.h:43
virtual void SetTextSize(Float_t tsize=1)
Set the text size.
Definition: TAttText.h:46
The Canvas class.
Definition: TCanvas.h:31
virtual Int_t Write(const char *name=0, Int_t option=0, Int_t bufsize=0)
Write this object to the current directory.
Definition: TObject.cxx:785
Base class for several text objects.
Definition: TText.h:23
const Double_t sigma
Double_t x[n]
Definition: legend1.C:17
RooCmdArg Layout(Double_t xmin, Double_t xmax=0.99, Double_t ymin=0.95)
RooCmdArg Bins(Int_t nbin)
static constexpr double gauss
const char * Name
Definition: TXMLSetup.cxx:66
const char * Title
Definition: TXMLSetup.cxx:67