Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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"
23 using namespace RooFit;
24 
25 void rf108_plotbinning()
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 }