Logo ROOT  
Reference Guide
rf108_plotbinning.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_roofit
3/// \notebook -js
4/// Basic functionality: plotting unbinned data with alternate and variable binnings
5///
6/// \macro_image
7/// \macro_output
8/// \macro_code
9///
10/// \author 07/2008 - Wouter Verkerke
11
12#include "RooRealVar.h"
13#include "RooDataSet.h"
14#include "RooGaussModel.h"
15#include "RooDecay.h"
16#include "RooBMixDecay.h"
17#include "RooCategory.h"
18#include "RooBinning.h"
19#include "RooPlot.h"
20#include "TCanvas.h"
21#include "TAxis.h"
22#include "TH1.h"
23using namespace RooFit;
24
26{
27
28 // S e t u p m o d e l
29 // ---------------------
30
31 // Build a B decay p.d.f with mixing
32 RooRealVar dt("dt", "dt", -20, 20);
33 RooRealVar dm("dm", "dm", 0.472);
34 RooRealVar tau("tau", "tau", 1.547);
35 RooRealVar w("w", "mistag rate", 0.1);
36 RooRealVar dw("dw", "delta mistag rate", 0.);
37
38 RooCategory mixState("mixState", "B0/B0bar mixing state");
39 mixState.defineType("mixed", -1);
40 mixState.defineType("unmixed", 1);
41 RooCategory tagFlav("tagFlav", "Flavour of the tagged B0");
42 tagFlav.defineType("B0", 1);
43 tagFlav.defineType("B0bar", -1);
44
45 // Build a gaussian resolution model
46 RooRealVar bias1("bias1", "bias1", 0);
47 RooRealVar sigma1("sigma1", "sigma1", 0.1);
48 RooGaussModel gm1("gm1", "gauss model 1", dt, bias1, sigma1);
49
50 // Construct Bdecay (x) gauss
51 RooBMixDecay bmix("bmix", "decay", dt, mixState, tagFlav, tau, dm, w, dw, gm1, RooBMixDecay::DoubleSided);
52
53 // S a m p l e d a t a f r o m m o d e l
54 // --------------------------------------------
55
56 // Sample 2000 events in (dt,mixState,tagFlav) from bmix
57 RooDataSet *data = bmix.generate(RooArgSet(dt, mixState, tagFlav), 2000);
58
59 // S h o w d t d i s t r i b u t i o n w i t h c u s t o m b i n n i n g
60 // -------------------------------------------------------------------------------
61
62 // Make plot of dt distribution of data in range (-15,15) with fine binning for dt>0 and coarse binning for dt<0
63
64 // Create binning object with range (-15,15)
65 RooBinning tbins(-15, 15);
66
67 // Add 60 bins with uniform spacing in range (-15,0)
68 tbins.addUniform(60, -15, 0);
69
70 // Add 15 bins with uniform spacing in range (0,15)
71 tbins.addUniform(15, 0, 15);
72
73 // Make plot with specified binning
74 RooPlot *dtframe = dt.frame(Range(-15, 15), Title("dt distribution with custom binning"));
75 data->plotOn(dtframe, Binning(tbins));
76 bmix.plotOn(dtframe);
77
78 // NB: Note that bin density for each bin is adjusted to that of default frame binning as shown
79 // in Y axis label (100 bins --> Events/0.4*Xaxis-dim) so that all bins represent a consistent density distribution
80
81 // S h o w m i x s t a t e a s y m m e t r y w i t h c u s t o m b i n n i n g
82 // ------------------------------------------------------------------------------------
83
84 // Make plot of dt distribution of data asymmetry in 'mixState' with variable binning
85
86 // Create binning object with range (-10,10)
87 RooBinning abins(-10, 10);
88
89 // Add boundaries at 0, (-1,1), (-2,2), (-3,3), (-4,4) and (-6,6)
90 abins.addBoundary(0);
91 abins.addBoundaryPair(1);
92 abins.addBoundaryPair(2);
93 abins.addBoundaryPair(3);
94 abins.addBoundaryPair(4);
95 abins.addBoundaryPair(6);
96
97 // Create plot frame in dt
98 RooPlot *aframe = dt.frame(Range(-10, 10), Title("mixState asymmetry distribution with custom binning"));
99
100 // Plot mixState asymmetry of data with specified custom binning
101 data->plotOn(aframe, Asymmetry(mixState), Binning(abins));
102
103 // Plot corresponding property of p.d.f
104 bmix.plotOn(aframe, Asymmetry(mixState));
105
106 // Adjust vertical range of plot to sensible values for an asymmetry
107 aframe->SetMinimum(-1.1);
108 aframe->SetMaximum(1.1);
109
110 // NB: For asymmetry distributions no density corrects are needed (and are thus not applied)
111
112 // Draw plots on canvas
113 TCanvas *c = new TCanvas("rf108_plotbinning", "rf108_plotbinning", 800, 400);
114 c->Divide(2);
115 c->cd(1);
116 gPad->SetLeftMargin(0.15);
117 dtframe->GetYaxis()->SetTitleOffset(1.6);
118 dtframe->Draw();
119 c->cd(2);
120 gPad->SetLeftMargin(0.15);
121 aframe->GetYaxis()->SetTitleOffset(1.6);
122 aframe->Draw();
123}
#define c(i)
Definition: RSha256.hxx:101
#define gPad
Definition: TVirtualPad.h:286
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
Calls RooPlot* plotOn(RooPlot* frame, const RooLinkedList& cmdList) const ;.
Definition: RooAbsData.cxx:550
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:28
Class RooBMixDecay is a RooAbsAnaConvPdf implementation that describes the decay of B mesons with the...
Definition: RooBMixDecay.h:23
Class RooBinning is an implements RooAbsBinning in terms of an array of boundary values,...
Definition: RooBinning.h:29
RooCategory represents a fundamental (non-derived) discrete value object.
Definition: RooCategory.h:24
RooDataSet is a container class to hold unbinned data.
Definition: RooDataSet.h:31
Class RooGaussModel implements a RooResolutionModel that models a Gaussian distribution.
Definition: RooGaussModel.h:26
A RooPlot is a plot frame and a container for graphics objects within that frame.
Definition: RooPlot.h:44
virtual void SetMinimum(Double_t minimum=-1111)
Set minimum value of Y axis.
Definition: RooPlot.cxx:1112
TAxis * GetYaxis() const
Definition: RooPlot.cxx:1277
static RooPlot * frame(const RooAbsRealLValue &var, Double_t xmin, Double_t xmax, Int_t nBins)
Create a new frame for a given variable in x.
Definition: RooPlot.cxx:277
virtual void SetMaximum(Double_t maximum=-1111)
Set maximum value of Y axis.
Definition: RooPlot.cxx:1102
virtual void Draw(Option_t *options=0)
Draw this plot and all of the elements it contains.
Definition: RooPlot.cxx:712
RooRealVar represents a variable that can be changed from the outside.
Definition: RooRealVar.h:35
virtual void SetTitleOffset(Float_t offset=1)
Set distance between the axis and the axis title.
Definition: TAttAxis.cxx:294
The Canvas class.
Definition: TCanvas.h:31
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
RooCmdArg Binning(const RooAbsBinning &binning)
RooCmdArg Asymmetry(const RooCategory &cat)
const char * Title
Definition: TXMLSetup.cxx:67
Ta Range(0, 0, 1, 1)