Logo ROOT  
Reference Guide
rf107_plotstyles.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_roofit
3 /// \notebook -js
4 ///
5 /// Basic functionality: various plotting styles of data, functions in a RooPlot
6 ///
7 /// \macro_image
8 /// \macro_output
9 /// \macro_code
10 ///
11 /// \date 07/2008
12 /// \author Wouter Verkerke
13 
14 #include "RooRealVar.h"
15 #include "RooDataSet.h"
16 #include "RooGaussian.h"
17 #include "TCanvas.h"
18 #include "TAxis.h"
19 #include "RooPlot.h"
20 using namespace RooFit;
21 
22 void rf107_plotstyles()
23 {
24 
25  // S e t u p m o d e l
26  // ---------------------
27 
28  // Create observables
29  RooRealVar x("x", "x", -10, 10);
30 
31  // Create Gaussian
32  RooRealVar sigma("sigma", "sigma", 3, 0.1, 10);
33  RooRealVar mean("mean", "mean", -3, -10, 10);
34  RooGaussian gauss("gauss", "gauss", x, mean, sigma);
35 
36  // Generate a sample of 100 events with sigma=3
37  RooDataSet *data = gauss.generate(x, 100);
38 
39  // Fit pdf to data
40  gauss.fitTo(*data);
41 
42  // M a k e p l o t f r a m e s
43  // -------------------------------
44 
45  // Make four plot frames to demonstrate various plotting features
46  RooPlot *frame1 = x.frame(Name("xframe"), Title("Red Curve / SumW2 Histo errors"), Bins(20));
47  RooPlot *frame2 = x.frame(Name("xframe"), Title("Dashed Curve / No XError bars"), Bins(20));
48  RooPlot *frame3 = x.frame(Name("xframe"), Title("Filled Curve / Blue Histo"), Bins(20));
49  RooPlot *frame4 = x.frame(Name("xframe"), Title("Partial Range / Filled Bar chart"), Bins(20));
50 
51  // D a t a p l o t t i n g s t y l e s
52  // ---------------------------------------
53 
54  // Use sqrt(sum(weights^2)) error instead of Poisson errors
55  data->plotOn(frame1, DataError(RooAbsData::SumW2));
56 
57  // Remove horizontal error bars
58  data->plotOn(frame2, XErrorSize(0));
59 
60  // Blue markers and error bors
61  data->plotOn(frame3, MarkerColor(kBlue), LineColor(kBlue));
62 
63  // Filled bar chart
65 
66  // F u n c t i o n p l o t t i n g s t y l e s
67  // -----------------------------------------------
68 
69  // Change line color to red
70  gauss.plotOn(frame1, LineColor(kRed));
71 
72  // Change line style to dashed
73  gauss.plotOn(frame2, LineStyle(kDashed));
74 
75  // Filled shapes in green color
76  gauss.plotOn(frame3, DrawOption("F"), FillColor(kOrange), MoveToBack());
77 
78  //
79  gauss.plotOn(frame4, Range(-8, 3), LineColor(kMagenta));
80 
81  TCanvas *c = new TCanvas("rf107_plotstyles", "rf107_plotstyles", 800, 800);
82  c->Divide(2, 2);
83  c->cd(1);
84  gPad->SetLeftMargin(0.15);
85  frame1->GetYaxis()->SetTitleOffset(1.6);
86  frame1->Draw();
87  c->cd(2);
88  gPad->SetLeftMargin(0.15);
89  frame2->GetYaxis()->SetTitleOffset(1.6);
90  frame2->Draw();
91  c->cd(3);
92  gPad->SetLeftMargin(0.15);
93  frame3->GetYaxis()->SetTitleOffset(1.6);
94  frame3->Draw();
95  c->cd(4);
96  gPad->SetLeftMargin(0.15);
97  frame4->GetYaxis()->SetTitleOffset(1.6);
98  frame4->Draw();
99 }
c
#define c(i)
Definition: RSha256.hxx:119
RooPlot::Draw
virtual void Draw(Option_t *options=0)
Draw this plot and all of the elements it contains.
Definition: RooPlot.cxx:691
RooFit::Bins
RooCmdArg Bins(Int_t nbin)
Definition: RooGlobalFunc.cxx:174
RooAbsData::SumW2
@ SumW2
Definition: RooAbsData.h:96
RooFit::DataError
RooCmdArg DataError(Int_t)
Definition: RooGlobalFunc.cxx:156
RooGaussian.h
RooFit::XErrorSize
RooCmdArg XErrorSize(Double_t width)
Definition: RooGlobalFunc.cxx:90
kOrange
@ kOrange
Definition: Rtypes.h:67
x
Double_t x[n]
Definition: legend1.C:17
RooGaussian
Definition: RooGaussian.h:25
TCanvas.h
RooFit::FillColor
RooCmdArg FillColor(Color_t color)
Definition: RooGlobalFunc.cxx:59
RooFit::MoveToBack
RooCmdArg MoveToBack()
Definition: RooGlobalFunc.cxx:66
RooDataSet.h
RooFit::DrawOption
RooCmdArg DrawOption(const char *opt)
Definition: RooGlobalFunc.cxx:38
kMagenta
@ kMagenta
Definition: Rtypes.h:66
TGeant4Unit::gauss
static constexpr double gauss
Definition: TGeant4SystemOfUnits.h:269
RooFit
Definition: RooCFunction1Binding.h:29
RooAbsData::plotOn
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
Definition: RooAbsData.cxx:547
RooFit::Name
RooCmdArg Name(const char *name)
Definition: RooGlobalFunc.cxx:62
RooPlot.h
RooPlot::GetYaxis
TAxis * GetYaxis() const
Definition: RooPlot.cxx:1256
RooPlot
Definition: RooPlot.h:44
RooRealVar.h
kRed
@ kRed
Definition: Rtypes.h:66
RooAbsData::None
@ None
Definition: RooAbsData.h:96
sigma
const Double_t sigma
Definition: h1analysisProxy.h:11
RooFit::LineColor
RooCmdArg LineColor(Color_t color)
Definition: RooGlobalFunc.cxx:56
TCanvas
Definition: TCanvas.h:23
rf107_plotstyles
Definition: rf107_plotstyles.py:1
TAxis.h
RooFit::Range
RooCmdArg Range(const char *rangeName, Bool_t adjustNorm=kTRUE)
Definition: RooGlobalFunc.cxx:52
kBlue
@ kBlue
Definition: Rtypes.h:66
kDashed
@ kDashed
Definition: TAttLine.h:48
gPad
#define gPad
Definition: TVirtualPad.h:287
RooDataSet
Definition: RooDataSet.h:33
RooFit::MarkerColor
RooCmdArg MarkerColor(Color_t color)
Definition: RooGlobalFunc.cxx:87
kGray
@ kGray
Definition: Rtypes.h:65
RooFit::LineStyle
RooCmdArg LineStyle(Style_t style)
Definition: RooGlobalFunc.cxx:57
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