Logo ROOT   6.16/01
Reference Guide
rf107_plotstyles.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_roofit
3/// \notebook -js
4/// 'BASIC FUNCTIONALITY' RooFit tutorial macro #107
5///
6/// Demonstration of various plotting styles of data, functions
7/// in a RooPlot
8/// \macro_image
9/// \macro_output
10/// \macro_code
11/// \author 07/2008 - Wouter Verkerke
12
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"
20using namespace RooFit ;
21
22
24{
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",3,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 100 events with sigma=3
38 RooDataSet* data = gauss.generate(x,100) ;
39
40 // Fit pdf to data
41 gauss.fitTo(*data) ;
42
43
44
45 // M a k e p l o t f r a m e s
46 // -------------------------------
47
48 // Make four plot frames to demonstrate various plotting features
49 RooPlot* frame1 = x.frame(Name("xframe"),Title("Red Curve / SumW2 Histo errors"),Bins(20)) ;
50 RooPlot* frame2 = x.frame(Name("xframe"),Title("Dashed Curve / No XError bars"),Bins(20)) ;
51 RooPlot* frame3 = x.frame(Name("xframe"),Title("Filled Curve / Blue Histo"),Bins(20)) ;
52 RooPlot* frame4 = x.frame(Name("xframe"),Title("Partial Range / Filled Bar chart"),Bins(20)) ;
53
54
55
56 // D a t a p l o t t i n g s t y l e s
57 // ---------------------------------------
58
59 // Use sqrt(sum(weights^2)) error instead of Poisson errors
60 data->plotOn(frame1,DataError(RooAbsData::SumW2)) ;
61
62 // Remove horizontal error bars
63 data->plotOn(frame2,XErrorSize(0)) ;
64
65 // Blue markers and error bors
66 data->plotOn(frame3,MarkerColor(kBlue),LineColor(kBlue)) ;
67
68 // Filled bar chart
70
71
72
73 // F u n c t i o n p l o t t i n g s t y l e s
74 // -----------------------------------------------
75
76 // Change line color to red
77 gauss.plotOn(frame1,LineColor(kRed)) ;
78
79 // Change line style to dashed
80 gauss.plotOn(frame2,LineStyle(kDashed)) ;
81
82 // Filled shapes in green color
83 gauss.plotOn(frame3,DrawOption("F"),FillColor(kOrange),MoveToBack()) ;
84
85 //
86 gauss.plotOn(frame4,Range(-8,3),LineColor(kMagenta)) ;
87
88
89
90 TCanvas* c = new TCanvas("rf107_plotstyles","rf107_plotstyles",800,800) ;
91 c->Divide(2,2) ;
92 c->cd(1) ; gPad->SetLeftMargin(0.15) ; frame1->GetYaxis()->SetTitleOffset(1.6) ; frame1->Draw() ;
93 c->cd(2) ; gPad->SetLeftMargin(0.15) ; frame2->GetYaxis()->SetTitleOffset(1.6) ; frame2->Draw() ;
94 c->cd(3) ; gPad->SetLeftMargin(0.15) ; frame3->GetYaxis()->SetTitleOffset(1.6) ; frame3->Draw() ;
95 c->cd(4) ; gPad->SetLeftMargin(0.15) ; frame4->GetYaxis()->SetTitleOffset(1.6) ; frame4->Draw() ;
96
97
98}
#define c(i)
Definition: RSha256.hxx:101
@ kGray
Definition: Rtypes.h:62
@ kRed
Definition: Rtypes.h:63
@ kOrange
Definition: Rtypes.h:64
@ kMagenta
Definition: Rtypes.h:63
@ kBlue
Definition: Rtypes.h:63
@ kDashed
Definition: TAttLine.h:48
#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
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
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)