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