Logo ROOT   6.10/09
Reference Guide
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"
25 using namespace RooFit ;
26 
27 
28 void rf108_plotbinning()
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 }
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:262
TAxis * GetYaxis() const
Definition: RooPlot.cxx:1118
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:552
RooCmdArg Asymmetry(const RooCategory &cat)
TVirtualPad * cd(Int_t subpadnumber=0)
Set current canvas & pad.
Definition: TCanvas.cxx:679
RooCmdArg Title(const char *name)
RooCmdArg Range(const char *rangeName, Bool_t adjustNorm=kTRUE)
virtual void SetMinimum(Double_t minimum=-1111)
Set minimum value of Y axis.
Definition: RooPlot.cxx:959
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t tau
Definition: TRolke.cxx:630
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, posing no constraints on the choice of binning, thus allowing variable bin sizes.
Definition: RooBinning.h:29
RooRealVar represents a fundamental (non-derived) real valued object.
Definition: RooRealVar.h:36
virtual void SetMaximum(Double_t maximum=-1111)
Set maximum value of Y axis.
Definition: RooPlot.cxx:949
RooDataSet is a container class to hold unbinned data.
Definition: RooDataSet.h:29
RooCategory represents a fundamental (non-derived) discrete value object.
Definition: RooCategory.h:24
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
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:1135
#define gPad
Definition: TVirtualPad.h:284
virtual void Draw(Option_t *options=0)
Draw this plot and all of the elements it contains.
Definition: RooPlot.cxx:559
Class RooGaussModel implements a RooResolutionModel that models a Gaussian distribution.
Definition: RooGaussModel.h:26
RooCmdArg Binning(const RooAbsBinning &binning)