ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
rf107_plotstyles.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_roofit
3 /// 'BASIC FUNCTIONALITY' RooFit tutorial macro #107
4 ///
5 /// Demonstration of various plotting styles of data, functions
6 /// in a RooPlot
7 ///
8 /// \macro_code
9 /// \author 07/2008 - Wouter Verkerke
10 
11 
12 #ifndef __CINT__
13 #include "RooGlobalFunc.h"
14 #endif
15 #include "RooRealVar.h"
16 #include "RooDataSet.h"
17 #include "RooGaussian.h"
18 #include "TCanvas.h"
19 #include "TAxis.h"
20 #include "RooPlot.h"
21 using namespace RooFit ;
22 
23 
24 void rf107_plotstyles()
25 {
26 
27  // S e t u p m o d e l
28  // ---------------------
29 
30  // Create observables
31  RooRealVar x("x","x",-10,10) ;
32 
33  // Create Gaussian
34  RooRealVar sigma("sigma","sigma",3,0.1,10) ;
35  RooRealVar mean("mean","mean",-3,-10,10) ;
36  RooGaussian gauss("gauss","gauss",x,mean,sigma) ;
37 
38  // Generate a sample of 100 events with sigma=3
39  RooDataSet* data = gauss.generate(x,100) ;
40 
41  // Fit pdf to data
42  gauss.fitTo(*data) ;
43 
44 
45 
46  // M a k e p l o t f r a m e s
47  // -------------------------------
48 
49  // Make four plot frames to demonstrate various plotting features
50  RooPlot* frame1 = x.frame(Name("xframe"),Title("Red Curve / SumW2 Histo errors"),Bins(20)) ;
51  RooPlot* frame2 = x.frame(Name("xframe"),Title("Dashed Curve / No XError bars"),Bins(20)) ;
52  RooPlot* frame3 = x.frame(Name("xframe"),Title("Filled Curve / Blue Histo"),Bins(20)) ;
53  RooPlot* frame4 = x.frame(Name("xframe"),Title("Partial Range / Filled Bar chart"),Bins(20)) ;
54 
55 
56 
57  // D a t a p l o t t i n g s t y l e s
58  // ---------------------------------------
59 
60  // Use sqrt(sum(weights^2)) error instead of Poisson errors
61  data->plotOn(frame1,DataError(RooAbsData::SumW2)) ;
62 
63  // Remove horizontal error bars
64  data->plotOn(frame2,XErrorSize(0)) ;
65 
66  // Blue markers and error bors
67  data->plotOn(frame3,MarkerColor(kBlue),LineColor(kBlue)) ;
68 
69  // Filled bar chart
71 
72 
73 
74  // F u n c t i o n p l o t t i n g s t y l e s
75  // -----------------------------------------------
76 
77  // Change line color to red
78  gauss.plotOn(frame1,LineColor(kRed)) ;
79 
80  // Change line style to dashed
81  gauss.plotOn(frame2,LineStyle(kDashed)) ;
82 
83  // Filled shapes in green color
84  gauss.plotOn(frame3,DrawOption("F"),FillColor(kOrange),MoveToBack()) ;
85 
86  //
87  gauss.plotOn(frame4,Range(-8,3),LineColor(kMagenta)) ;
88 
89 
90 
91  TCanvas* c = new TCanvas("rf107_plotstyles","rf107_plotstyles",800,800) ;
92  c->Divide(2,2) ;
93  c->cd(1) ; gPad->SetLeftMargin(0.15) ; frame1->GetYaxis()->SetTitleOffset(1.6) ; frame1->Draw() ;
94  c->cd(2) ; gPad->SetLeftMargin(0.15) ; frame2->GetYaxis()->SetTitleOffset(1.6) ; frame2->Draw() ;
95  c->cd(3) ; gPad->SetLeftMargin(0.15) ; frame3->GetYaxis()->SetTitleOffset(1.6) ; frame3->Draw() ;
96  c->cd(4) ; gPad->SetLeftMargin(0.15) ; frame4->GetYaxis()->SetTitleOffset(1.6) ; frame4->Draw() ;
97 
98 
99 }
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:245
RooCmdArg DrawOption(const char *opt)
RooCmdArg LineColor(Color_t color)
Definition: Rtypes.h:61
Definition: Rtypes.h:60
TAxis * GetYaxis() const
Definition: RooPlot.cxx:1118
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
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:626
RooCmdArg MoveToBack()
RooRealVar represents a fundamental (non-derived) real valued object.
Definition: RooRealVar.h:37
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
RooCmdArg XErrorSize(Double_t width)
RooCmdArg FillColor(Color_t color)
RooCmdArg Bins(Int_t nbin)
#define gPad
Definition: TVirtualPad.h:288
Definition: Rtypes.h:61
RooCmdArg MarkerColor(Color_t color)
RooAbsMoment * mean(RooRealVar &obs)
Definition: RooAbsReal.h:297
Definition: Rtypes.h:62
virtual void Draw(Option_t *options=0)
Draw this plot and all of the elements it contains.
Definition: RooPlot.cxx:559