Loading [MathJax]/extensions/tex2jax.js
Logo ROOT   6.16/01
Reference Guide
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
rf108_plotbinning.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_roofit
3/// \notebook -js
4/// 'BASIC FUNCTIONALITY' RooFit tutorial macro #108
5///
6/// Plotting unbinned data with alternate and variable binnings
7/// \macro_image
8/// \macro_output
9/// \macro_code
10///
11/// \author 07/2008 - Wouter Verkerke
12
13
14#include "RooRealVar.h"
15#include "RooDataSet.h"
16#include "RooGaussModel.h"
17#include "RooDecay.h"
18#include "RooBMixDecay.h"
19#include "RooCategory.h"
20#include "RooBinning.h"
21#include "RooPlot.h"
22#include "TCanvas.h"
23#include "TAxis.h"
24#include "TH1.h"
25using namespace RooFit ;
26
27
29{
30
31 // S e t u p m o d e l
32 // ---------------------
33
34 // Build a B decay p.d.f with mixing
35 RooRealVar dt("dt","dt",-20,20) ;
36 RooRealVar dm("dm","dm",0.472) ;
37 RooRealVar tau("tau","tau",1.547) ;
38 RooRealVar w("w","mistag rate",0.1) ;
39 RooRealVar dw("dw","delta mistag rate",0.) ;
40
41 RooCategory mixState("mixState","B0/B0bar mixing state") ;
42 mixState.defineType("mixed",-1) ;
43 mixState.defineType("unmixed",1) ;
44 RooCategory tagFlav("tagFlav","Flavour of the tagged B0") ;
45 tagFlav.defineType("B0",1) ;
46 tagFlav.defineType("B0bar",-1) ;
47
48 // Build a gaussian resolution model
49 RooRealVar bias1("bias1","bias1",0) ;
50 RooRealVar sigma1("sigma1","sigma1",0.1) ;
51 RooGaussModel gm1("gm1","gauss model 1",dt,bias1,sigma1) ;
52
53 // Construct Bdecay (x) gauss
54 RooBMixDecay bmix("bmix","decay",dt,mixState,tagFlav,tau,dm,w,dw,gm1,RooBMixDecay::DoubleSided) ;
55
56
57 // S a m p l e d a t a f r o m m o d e l
58 // --------------------------------------------
59
60 // Sample 2000 events in (dt,mixState,tagFlav) from bmix
61 RooDataSet *data = bmix.generate(RooArgSet(dt,mixState,tagFlav),2000) ;
62
63
64
65 // 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
66 // -------------------------------------------------------------------------------
67
68 // Make plot of dt distribution of data in range (-15,15) with fine binning for dt>0 and coarse binning for dt<0
69
70 // Create binning object with range (-15,15)
71 RooBinning tbins(-15,15) ;
72
73 // Add 60 bins with uniform spacing in range (-15,0)
74 tbins.addUniform(60,-15,0) ;
75
76 // Add 15 bins with uniform spacing in range (0,15)
77 tbins.addUniform(15,0,15) ;
78
79 // Make plot with specified binning
80 RooPlot* dtframe = dt.frame(Range(-15,15),Title("dt distribution with custom binning")) ;
81 data->plotOn(dtframe,Binning(tbins)) ;
82 bmix.plotOn(dtframe) ;
83
84 // NB: Note that bin density for each bin is adjusted to that of default frame binning as shown
85 // in Y axis label (100 bins --> Events/0.4*Xaxis-dim) so that all bins represent a consistent density distribution
86
87
88 // 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
89 // ------------------------------------------------------------------------------------
90
91 // Make plot of dt distribution of data asymmetry in 'mixState' with variable binning
92
93 // Create binning object with range (-10,10)
94 RooBinning abins(-10,10) ;
95
96 // Add boundaries at 0, (-1,1), (-2,2), (-3,3), (-4,4) and (-6,6)
97 abins.addBoundary(0) ;
98 abins.addBoundaryPair(1) ;
99 abins.addBoundaryPair(2) ;
100 abins.addBoundaryPair(3) ;
101 abins.addBoundaryPair(4) ;
102 abins.addBoundaryPair(6) ;
103
104 // Create plot frame in dt
105 RooPlot* aframe = dt.frame(Range(-10,10),Title("mixState asymmetry distribution with custom binning")) ;
106
107 // Plot mixState asymmetry of data with specified custom binning
108 data->plotOn(aframe,Asymmetry(mixState),Binning(abins)) ;
109
110 // Plot corresponding property of p.d.f
111 bmix.plotOn(aframe,Asymmetry(mixState)) ;
112
113 // Adjust vertical range of plot to sensible values for an asymmetry
114 aframe->SetMinimum(-1.1) ;
115 aframe->SetMaximum(1.1) ;
116
117 // NB: For asymmetry distributions no density corrects are needed (and are thus not applied)
118
119
120 // Draw plots on canvas
121 TCanvas* c = new TCanvas("rf108_plotbinning","rf108_plotbinning",800,400) ;
122 c->Divide(2) ;
123 c->cd(1) ; gPad->SetLeftMargin(0.15) ; dtframe->GetYaxis()->SetTitleOffset(1.6) ; dtframe->Draw() ;
124 c->cd(2) ; gPad->SetLeftMargin(0.15) ; aframe->GetYaxis()->SetTitleOffset(1.6) ; aframe->Draw() ;
125
126}
#define c(i)
Definition: RSha256.hxx:101
#define gPad
Definition: TVirtualPad.h:286
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:41
virtual void SetMinimum(Double_t minimum=-1111)
Set minimum value of Y axis.
Definition: RooPlot.cxx:958
TAxis * GetYaxis() const
Definition: RooPlot.cxx:1123
virtual void SetMaximum(Double_t maximum=-1111)
Set maximum value of Y axis.
Definition: RooPlot.cxx:948
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
RooCmdArg Binning(const RooAbsBinning &binning)
RooCmdArg Asymmetry(const RooCategory &cat)
const char * Title
Definition: TXMLSetup.cxx:67
Ta Range(0, 0, 1, 1)