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