From $ROOTSYS/tutorials/roofit/rf107_plotstyles.C

//////////////////////////////////////////////////////////////////////////
//
// 'BASIC FUNCTIONALITY' RooFit tutorial macro #107
// 
//  Demonstration of various plotting styles of data, functions
//  in a RooPlot
//
// 07/2008 - Wouter Verkerke 
// 
/////////////////////////////////////////////////////////////////////////

#ifndef __CINT__
#include "RooGlobalFunc.h"
#endif
#include "RooRealVar.h"
#include "RooDataSet.h"
#include "RooGaussian.h"
#include "TCanvas.h"
#include "TAxis.h"
#include "RooPlot.h"
using namespace RooFit ;


void rf107_plotstyles()
{

  // S e t u p   m o d e l 
  // ---------------------

  // Create observables
  RooRealVar x("x","x",-10,10) ;

  // Create Gaussian
  RooRealVar sigma("sigma","sigma",3,0.1,10) ;
  RooRealVar mean("mean","mean",-3,-10,10) ;
  RooGaussian gauss("gauss","gauss",x,mean,sigma) ;

  // Generate a sample of 100 events with sigma=3
  RooDataSet* data = gauss.generate(x,100) ;

  // Fit pdf to data
  gauss.fitTo(*data) ;



  // M a k e   p l o t   f r a m e s
  // -------------------------------

  // Make four plot frames to demonstrate various plotting features
  RooPlot* frame1 = x.frame(Name("xframe"),Title("Red Curve / SumW2 Histo errors"),Bins(20)) ;
  RooPlot* frame2 = x.frame(Name("xframe"),Title("Dashed Curve / No XError bars"),Bins(20)) ;
  RooPlot* frame3 = x.frame(Name("xframe"),Title("Filled Curve / Blue Histo"),Bins(20)) ;
  RooPlot* frame4 = x.frame(Name("xframe"),Title("Partial Range / Filled Bar chart"),Bins(20)) ;



  // D a t a   p l o t t i n g   s t y l e s 
  // ---------------------------------------

  // Use sqrt(sum(weights^2)) error instead of Poisson errors
  data->plotOn(frame1,DataError(RooAbsData::SumW2)) ;

  // Remove horizontal error bars
  data->plotOn(frame2,XErrorSize(0)) ;

  // Blue markers and error bors
  data->plotOn(frame3,MarkerColor(kBlue),LineColor(kBlue)) ;

  // Filled bar chart
  data->plotOn(frame4,DrawOption("B"),DataError(RooAbsData::None),XErrorSize(0),FillColor(kGray)) ;



  // F u n c t i o n   p l o t t i n g   s t y l e s 
  // -----------------------------------------------

  // Change line color to red
  gauss.plotOn(frame1,LineColor(kRed)) ;

  // Change line style to dashed
  gauss.plotOn(frame2,LineStyle(kDashed)) ;

  // Filled shapes in green color
  gauss.plotOn(frame3,DrawOption("F"),FillColor(kOrange),MoveToBack()) ;

  //
  gauss.plotOn(frame4,Range(-8,3),LineColor(kMagenta)) ;



  TCanvas* c = new TCanvas("rf107_plotstyles","rf107_plotstyles",800,800) ;
  c->Divide(2,2) ;
  c->cd(1) ; gPad->SetLeftMargin(0.15) ; frame1->GetYaxis()->SetTitleOffset(1.6) ; frame1->Draw() ;
  c->cd(2) ; gPad->SetLeftMargin(0.15) ; frame2->GetYaxis()->SetTitleOffset(1.6) ; frame2->Draw() ;
  c->cd(3) ; gPad->SetLeftMargin(0.15) ; frame3->GetYaxis()->SetTitleOffset(1.6) ; frame3->Draw() ;
  c->cd(4) ; gPad->SetLeftMargin(0.15) ; frame4->GetYaxis()->SetTitleOffset(1.6) ; frame4->Draw() ;

  
}
 rf107_plotstyles.C:1
 rf107_plotstyles.C:2
 rf107_plotstyles.C:3
 rf107_plotstyles.C:4
 rf107_plotstyles.C:5
 rf107_plotstyles.C:6
 rf107_plotstyles.C:7
 rf107_plotstyles.C:8
 rf107_plotstyles.C:9
 rf107_plotstyles.C:10
 rf107_plotstyles.C:11
 rf107_plotstyles.C:12
 rf107_plotstyles.C:13
 rf107_plotstyles.C:14
 rf107_plotstyles.C:15
 rf107_plotstyles.C:16
 rf107_plotstyles.C:17
 rf107_plotstyles.C:18
 rf107_plotstyles.C:19
 rf107_plotstyles.C:20
 rf107_plotstyles.C:21
 rf107_plotstyles.C:22
 rf107_plotstyles.C:23
 rf107_plotstyles.C:24
 rf107_plotstyles.C:25
 rf107_plotstyles.C:26
 rf107_plotstyles.C:27
 rf107_plotstyles.C:28
 rf107_plotstyles.C:29
 rf107_plotstyles.C:30
 rf107_plotstyles.C:31
 rf107_plotstyles.C:32
 rf107_plotstyles.C:33
 rf107_plotstyles.C:34
 rf107_plotstyles.C:35
 rf107_plotstyles.C:36
 rf107_plotstyles.C:37
 rf107_plotstyles.C:38
 rf107_plotstyles.C:39
 rf107_plotstyles.C:40
 rf107_plotstyles.C:41
 rf107_plotstyles.C:42
 rf107_plotstyles.C:43
 rf107_plotstyles.C:44
 rf107_plotstyles.C:45
 rf107_plotstyles.C:46
 rf107_plotstyles.C:47
 rf107_plotstyles.C:48
 rf107_plotstyles.C:49
 rf107_plotstyles.C:50
 rf107_plotstyles.C:51
 rf107_plotstyles.C:52
 rf107_plotstyles.C:53
 rf107_plotstyles.C:54
 rf107_plotstyles.C:55
 rf107_plotstyles.C:56
 rf107_plotstyles.C:57
 rf107_plotstyles.C:58
 rf107_plotstyles.C:59
 rf107_plotstyles.C:60
 rf107_plotstyles.C:61
 rf107_plotstyles.C:62
 rf107_plotstyles.C:63
 rf107_plotstyles.C:64
 rf107_plotstyles.C:65
 rf107_plotstyles.C:66
 rf107_plotstyles.C:67
 rf107_plotstyles.C:68
 rf107_plotstyles.C:69
 rf107_plotstyles.C:70
 rf107_plotstyles.C:71
 rf107_plotstyles.C:72
 rf107_plotstyles.C:73
 rf107_plotstyles.C:74
 rf107_plotstyles.C:75
 rf107_plotstyles.C:76
 rf107_plotstyles.C:77
 rf107_plotstyles.C:78
 rf107_plotstyles.C:79
 rf107_plotstyles.C:80
 rf107_plotstyles.C:81
 rf107_plotstyles.C:82
 rf107_plotstyles.C:83
 rf107_plotstyles.C:84
 rf107_plotstyles.C:85
 rf107_plotstyles.C:86
 rf107_plotstyles.C:87
 rf107_plotstyles.C:88
 rf107_plotstyles.C:89
 rf107_plotstyles.C:90
 rf107_plotstyles.C:91
 rf107_plotstyles.C:92
 rf107_plotstyles.C:93
 rf107_plotstyles.C:94
 rf107_plotstyles.C:95
 rf107_plotstyles.C:96
 rf107_plotstyles.C:97
 rf107_plotstyles.C:98
 rf107_plotstyles.C:99
 rf107_plotstyles.C:100