Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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_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"
19using namespace RooFit;
20
22{
23
24 // S e t u p m o d e l
25 // ---------------------
26
27 // Create observables
28 RooRealVar x("x", "x", -10, 10);
29
30 // Create Gaussian
31 RooRealVar sigma("sigma", "sigma", 3, 0.1, 10);
32 RooRealVar mean("mean", "mean", -3, -10, 10);
33 RooGaussian gauss("gauss", "gauss", x, mean, sigma);
34
35 // Generate a sample of 100 events with sigma=3
36 std::unique_ptr<RooDataSet> data{gauss.generate(x, 100)};
37
38 // Fit pdf to data
39 gauss.fitTo(*data, PrintLevel(-1));
40
41 // M a k e p l o t f r a m e s
42 // -------------------------------
43
44 // Make four plot frames to demonstrate various plotting features
45 RooPlot *frame1 = x.frame(Name("xframe"), Title("Red Curve / SumW2 Histo errors"), Bins(20));
46 RooPlot *frame2 = x.frame(Name("xframe"), Title("Dashed Curve / No XError bars"), Bins(20));
47 RooPlot *frame3 = x.frame(Name("xframe"), Title("Filled Curve / Blue Histo"), Bins(20));
48 RooPlot *frame4 = x.frame(Name("xframe"), Title("Partial Range / Filled Bar chart"), Bins(20));
49
50 // D a t a p l o t t i n g s t y l e s
51 // ---------------------------------------
52
53 // Use sqrt(sum(weights^2)) error instead of Poisson errors
54 data->plotOn(frame1, DataError(RooAbsData::SumW2));
55
56 // Remove horizontal error bars
57 data->plotOn(frame2, XErrorSize(0));
58
59 // Blue markers and error bors
60 data->plotOn(frame3, MarkerColor(kBlue), LineColor(kBlue));
61
62 // Filled bar chart
64
65 // F u n c t i o n p l o t t i n g s t y l e s
66 // -----------------------------------------------
67
68 // Change line color to red
69 gauss.plotOn(frame1, LineColor(kRed));
70
71 // Change line style to dashed
72 gauss.plotOn(frame2, LineStyle(kDashed));
73
74 // Filled shapes in green color
75 gauss.plotOn(frame3, DrawOption("F"), FillColor(kOrange), MoveToBack());
76
77 //
78 gauss.plotOn(frame4, Range(-8, 3), LineColor(kMagenta));
79
80 TCanvas *c = new TCanvas("rf107_plotstyles", "rf107_plotstyles", 800, 800);
81 c->Divide(2, 2);
82 c->cd(1);
83 gPad->SetLeftMargin(0.15);
84 frame1->GetYaxis()->SetTitleOffset(1.6);
85 frame1->Draw();
86 c->cd(2);
87 gPad->SetLeftMargin(0.15);
88 frame2->GetYaxis()->SetTitleOffset(1.6);
89 frame2->Draw();
90 c->cd(3);
91 gPad->SetLeftMargin(0.15);
92 frame3->GetYaxis()->SetTitleOffset(1.6);
93 frame3->Draw();
94 c->cd(4);
95 gPad->SetLeftMargin(0.15);
96 frame4->GetYaxis()->SetTitleOffset(1.6);
97 frame4->Draw();
98}
#define c(i)
Definition RSha256.hxx:101
@ kGray
Definition Rtypes.h:65
@ kRed
Definition Rtypes.h:66
@ kOrange
Definition Rtypes.h:67
@ kMagenta
Definition Rtypes.h:66
@ kBlue
Definition Rtypes.h:66
@ kDashed
Definition TAttLine.h:48
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
#define gPad
Plain Gaussian p.d.f.
Definition RooGaussian.h:24
Plot frame and a container for graphics objects within that frame.
Definition RooPlot.h:43
static RooPlot * frame(const RooAbsRealLValue &var, double xmin, double xmax, Int_t nBins)
Create a new frame for a given variable in x.
Definition RooPlot.cxx:237
TAxis * GetYaxis() const
Definition RooPlot.cxx:1276
void Draw(Option_t *options=nullptr) override
Draw this plot and all of the elements it contains.
Definition RooPlot.cxx:649
Variable that can be changed from the outside.
Definition RooRealVar.h:37
virtual void SetTitleOffset(Float_t offset=1)
Set distance between the axis and the axis title.
Definition TAttAxis.cxx:298
The Canvas class.
Definition TCanvas.h:23
RooCmdArg Bins(Int_t nbin)
RooCmdArg DataError(Int_t)
RooCmdArg PrintLevel(Int_t code)
RooCmdArg MarkerColor(Color_t color)
RooCmdArg FillColor(Color_t color)
RooCmdArg DrawOption(const char *opt)
RooCmdArg XErrorSize(double width)
RooCmdArg MoveToBack()
RooCmdArg LineColor(Color_t color)
RooCmdArg LineStyle(Style_t style)
const Double_t sigma
Double_t x[n]
Definition legend1.C:17
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Definition JSONIO.h:26
const char * Name
Definition TXMLSetup.cxx:67
const char * Title
Definition TXMLSetup.cxx:68
Ta Range(0, 0, 1, 1)