Logo ROOT   6.14/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' 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"
20 using namespace RooFit ;
21 
22 
23 void rf107_plotstyles()
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 }
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
RooCmdArg DrawOption(const char *opt)
TAxis * GetYaxis() const
Definition: RooPlot.cxx:1117
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
Plot dataset on specified frame.
Definition: RooAbsData.cxx:568
RooCmdArg LineColor(Color_t color)
Definition: Rtypes.h:59
TVirtualPad * cd(Int_t subpadnumber=0)
Set current canvas & pad.
Definition: TCanvas.cxx:688
Definition: Rtypes.h:58
RooCmdArg Title(const char *name)
RooCmdArg Range(const char *rangeName, Bool_t adjustNorm=kTRUE)
Double_t x[n]
Definition: legend1.C:17
RooCmdArg DataError(Int_t)
RooCmdArg LineStyle(Style_t style)
Plain Gaussian p.d.f.
Definition: RooGaussian.h:25
const Double_t sigma
RooCmdArg MoveToBack()
RooRealVar represents a fundamental (non-derived) real valued object.
Definition: RooRealVar.h:36
RooCmdArg Name(const char *name)
RooDataSet is a container class to hold unbinned data.
Definition: RooDataSet.h:29
A RooPlot is a plot frame and a container for graphics objects within that frame. ...
Definition: RooPlot.h:41
The Canvas class.
Definition: TCanvas.h:31
static constexpr double gauss
RooCmdArg XErrorSize(Double_t width)
RooCmdArg FillColor(Color_t color)
virtual void Divide(Int_t nx=1, Int_t ny=1, Float_t xmargin=0.01, Float_t ymargin=0.01, Int_t color=0)
Automatic pad generation by division.
Definition: TPad.cxx:1162
RooCmdArg Bins(Int_t nbin)
#define gPad
Definition: TVirtualPad.h:285
#define c(i)
Definition: RSha256.hxx:101
Definition: Rtypes.h:59
RooCmdArg MarkerColor(Color_t color)
Definition: Rtypes.h:60
virtual void Draw(Option_t *options=0)
Draw this plot and all of the elements it contains.
Definition: RooPlot.cxx:558