ROOT
CLING_PROFILE
Reference Guide
Loading...
Searching...
No Matches
rf106_plotdecoration.C
Go to the documentation of this file.
1
/// \file
2
/// \ingroup tutorial_roofit_main
3
/// \notebook -js
4
/// Basic functionality: adding boxes with parameters, statistics to RooPlots, decorating with arrows, text etc...
5
///
6
/// \macro_image
7
/// \macro_code
8
/// \macro_output
9
///
10
/// \date July 2008
11
/// \author Wouter Verkerke
12
13
#include "
RooRealVar.h
"
14
#include "
RooDataSet.h
"
15
#include "
RooGaussian.h
"
16
#include "
TCanvas.h
"
17
#include "
TAxis.h
"
18
#include "
RooPlot.h
"
19
#include "
TText.h
"
20
#include "
TArrow.h
"
21
#include "
TFile.h
"
22
using namespace
RooFit
;
23
24
void
rf106_plotdecoration()
25
{
26
// S e t u p m o d e l
27
// ---------------------
28
29
// Create observables
30
RooRealVar
x
(
"x"
,
"x"
, -10, 10);
31
32
// Create Gaussian
33
RooRealVar
sigma
(
"sigma"
,
"sigma"
, 1, 0.1, 10);
34
RooRealVar
mean(
"mean"
,
"mean"
, -3, -10, 10);
35
RooGaussian
gauss(
"gauss"
,
"gauss"
,
x
, mean,
sigma
);
36
37
// Generate a sample of 1000 events with sigma=3
38
std::unique_ptr<RooDataSet>
data
{gauss.generate(
x
, 1000)};
39
40
// Fit pdf to data
41
gauss.fitTo(*
data
,
PrintLevel
(-1));
42
43
// P l o t p . d . f a n d d a t a
44
// -------------------------------------
45
46
// Overlay projection of gauss on data
47
RooPlot
*frame =
x
.frame(
Name
(
"xframe"
),
Title
(
"RooPlot with decorations"
),
Bins(40));
48
data
->plotOn(frame);
49
gauss.plotOn(frame);
50
51
// A d d b o x w i t h p d f p a r a m e t e r s
52
// -----------------------------------------------------
53
54
// Left edge of box starts at 55% of Xaxis)
55
gauss.paramOn(frame,
Layout
(0.55));
56
57
// A d d b o x w i t h d a t a s t a t i s t i c s
58
// -------------------------------------------------------
59
60
// X size of box is from 55% to 99% of Xaxis range, top of box is at 80% of Yaxis range)
61
data
->statOn(frame,
Layout
(0.55, 0.99, 0.8));
62
63
// A d d t e x t a n d a r r o w
64
// -----------------------------------
65
66
// Add text to frame
67
TText
*txt =
new
TText
(2, 100,
"Signal"
);
68
txt->
SetTextSize
(0.04);
69
txt->
SetTextColor
(
kRed
);
70
frame->addObject(txt);
71
72
// Add arrow to frame
73
TArrow
*
arrow
=
new
TArrow
(2, 100, -1, 50, 0.01,
"|>"
);
74
arrow
->SetLineColor(
kRed
);
75
arrow
->SetFillColor(
kRed
);
76
arrow
->SetLineWidth(3);
77
frame->addObject(
arrow);
78
79
// 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
80
// ---------------------------------------------------------------------------------------------
81
82
TFile
f
(
"rf106_plotdecoration.root"
,
"RECREATE"
);
83
frame->Write();
84
f
.Close();
85
86
// To read back and plot frame with all decorations in clean root session do
87
// root> TFile f("rf106_plotdecoration.root") ;
88
// root> xframe->Draw() ;
89
90
new
TCanvas
(
"rf106_plotdecoration"
,
"rf106_plotdecoration"
, 600, 600);
91
gPad
->SetLeftMargin(0.15);
92
frame->GetYaxis()->SetTitleOffset(1.6);
93
frame->Draw();
94
}
f
#define f(i)
Definition
RSha256.hxx:104
RooDataSet.h
RooGaussian.h
RooPlot.h
RooRealVar.h
kRed
@ kRed
Definition
Rtypes.h:67
TArrow.h
TAxis.h
TCanvas.h
TFile.h
data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Definition
TGWin32VirtualXProxy.cxx:104
TText.h
gPad
#define gPad
Definition
TVirtualPad.h:322
RooGaussian
Plain Gaussian p.d.f.
Definition
RooGaussian.h:24
RooPlot
Plot frame and a container for graphics objects within that frame.
Definition
RooPlot.h:43
RooRealVar
Variable that can be changed from the outside.
Definition
RooRealVar.h:37
TArrow
Definition
TArrow.h:29
TAttText::SetTextColor
virtual void SetTextColor(Color_t tcolor=1)
Set the text color.
Definition
TAttText.h:50
TAttText::SetTextSize
virtual void SetTextSize(Float_t tsize=1)
Set the text size.
Definition
TAttText.h:53
TCanvas
The Canvas class.
Definition
TCanvas.h:23
TFile
Definition
TFile.h:130
TText
Definition
TText.h:22
RooFit::Title
RooCmdArg Title(const char *name)
Definition
RooGlobalFunc.cxx:532
RooFit::Bins
RooCmdArg Bins(Int_t nbin)
Definition
RooGlobalFunc.cxx:536
RooFit::Layout
RooCmdArg Layout(double xmin, double xmax=0.99, double ymin=0.95)
Definition
RooGlobalFunc.cxx:785
RooFit::PrintLevel
RooCmdArg PrintLevel(Int_t code)
Definition
RooGlobalFunc.cxx:659
RooFit::Name
RooCmdArg Name(const char *name)
Definition
RooGlobalFunc.cxx:261
sigma
const Double_t sigma
Definition
h1analysisProxy.h:11
x
Double_t x[n]
Definition
legend1.C:17
RooFit
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Definition
CodegenImpl.h:72
arrow
Definition
RArrowDS.hxx:17
rf106_plotdecoration
Definition
rf106_plotdecoration.py:1
rf601_intminuit.frame
frame
Definition
rf601_intminuit.py:88
rf601_intminuit.mean
mean
Definition
rf601_intminuit.py:28
tutorials
roofit
roofit
rf106_plotdecoration.C
ROOTCLING_PROFILE - Reference Guide Generated on
(GVA Time) using Doxygen 1.16.1