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