Logo ROOT   6.10/09
Reference Guide
rf108_plotbinning.cxx
Go to the documentation of this file.
1 /////////////////////////////////////////////////////////////////////////
2 //
3 // 'BASIC FUNCTIONALITY' RooFit tutorial macro #108
4 //
5 // Plotting unbinned data with alternate and variable binnings
6 //
7 //
8 // 07/2008 - Wouter Verkerke
9 //
10 /////////////////////////////////////////////////////////////////////////
11 
12 #ifndef __CINT__
13 #include "RooGlobalFunc.h"
14 #endif
15 #include "RooRealVar.h"
16 #include "RooDataSet.h"
17 #include "RooGaussModel.h"
18 #include "RooDecay.h"
19 #include "RooBMixDecay.h"
20 #include "RooCategory.h"
21 #include "RooBinning.h"
22 #include "RooPlot.h"
23 #include "TCanvas.h"
24 #include "TH1.h"
25 using namespace RooFit ;
26 
27 
28 class TestBasic108 : public RooFitTestUnit
29 {
30 public:
31  TestBasic108(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("Non-standard binning in counting and asymmetry plots",refFile,writeRef,verbose) {} ;
32  Bool_t testCode() {
33 
34  // S e t u p m o d e l
35  // ---------------------
36 
37  // Build a B decay p.d.f with mixing
38  RooRealVar dt("dt","dt",-20,20) ;
39  RooRealVar dm("dm","dm",0.472) ;
40  RooRealVar tau("tau","tau",1.547) ;
41  RooRealVar w("w","mistag rate",0.1) ;
42  RooRealVar dw("dw","delta mistag rate",0.) ;
43 
44  RooCategory mixState("mixState","B0/B0bar mixing state") ;
45  mixState.defineType("mixed",-1) ;
46  mixState.defineType("unmixed",1) ;
47  RooCategory tagFlav("tagFlav","Flavour of the tagged B0") ;
48  tagFlav.defineType("B0",1) ;
49  tagFlav.defineType("B0bar",-1) ;
50 
51  // Build a gaussian resolution model
52  RooRealVar dterr("dterr","dterr",0.1,1.0) ;
53  RooRealVar bias1("bias1","bias1",0) ;
54  RooRealVar sigma1("sigma1","sigma1",0.1) ;
55  RooGaussModel gm1("gm1","gauss model 1",dt,bias1,sigma1) ;
56 
57  // Construct Bdecay (x) gauss
58  RooBMixDecay bmix("bmix","decay",dt,mixState,tagFlav,tau,dm,w,dw,gm1,RooBMixDecay::DoubleSided) ;
59 
60 
61  // S a m p l e d a t a f r o m m o d e l
62  // --------------------------------------------
63 
64  // Sample 2000 events in (dt,mixState,tagFlav) from bmix
65  RooDataSet *data = bmix.generate(RooArgSet(dt,mixState,tagFlav),2000) ;
66 
67 
68 
69  // 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
70  // -------------------------------------------------------------------------------
71 
72  // Make plot of dt distribution of data in range (-15,15) with fine binning for dt>0 and coarse binning for dt<0
73 
74  // Create binning object with range (-15,15)
75  RooBinning tbins(-15,15) ;
76 
77  // Add 60 bins with uniform spacing in range (-15,0)
78  tbins.addUniform(60,-15,0) ;
79 
80  // Add 15 bins with uniform spacing in range (0,15)
81  tbins.addUniform(15,0,15) ;
82 
83  // Make plot with specified binning
84  RooPlot* dtframe = dt.frame(Range(-15,15),Title("dt distribution with custom binning")) ;
85  data->plotOn(dtframe,Binning(tbins)) ;
86  bmix.plotOn(dtframe) ;
87 
88  // NB: Note that bin density for each bin is adjusted to that of default frame binning as shown
89  // in Y axis label (100 bins --> Events/0.4*Xaxis-dim) so that all bins represent a consistent density distribution
90 
91 
92  // 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
93  // ------------------------------------------------------------------------------------
94 
95  // Make plot of dt distribution of data asymmetry in 'mixState' with variable binning
96 
97  // Create binning object with range (-10,10)
98  RooBinning abins(-10,10) ;
99 
100  // Add boundaries at 0, (-1,1), (-2,2), (-3,3), (-4,4) and (-6,6)
101  abins.addBoundary(0) ;
102  abins.addBoundaryPair(1) ;
103  abins.addBoundaryPair(2) ;
104  abins.addBoundaryPair(3) ;
105  abins.addBoundaryPair(4) ;
106  abins.addBoundaryPair(6) ;
107 
108  // Create plot frame in dt
109  RooPlot* aframe = dt.frame(Range(-10,10),Title("mixState asymmetry distribution with custom binning")) ;
110 
111  // Plot mixState asymmetry of data with specified customg binning
112  data->plotOn(aframe,Asymmetry(mixState),Binning(abins)) ;
113 
114  // Plot corresponding property of p.d.f
115  bmix.plotOn(aframe,Asymmetry(mixState)) ;
116 
117  // Adjust vertical range of plot to sensible values for an asymmetry
118  aframe->SetMinimum(-1.1) ;
119  aframe->SetMaximum(1.1) ;
120 
121  // NB: For asymmetry distributions no density corrects are needed (and are thus not applied)
122 
123 
124  regPlot(dtframe,"rf108_plot1") ;
125  regPlot(aframe,"rf108_plot2") ;
126 
127  delete data ;
128 
129  return kTRUE ;
130  }
131 } ;
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)
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
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
bool verbose
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
const Bool_t kTRUE
Definition: RtypesCore.h:91
Class RooGaussModel implements a RooResolutionModel that models a Gaussian distribution.
Definition: RooGaussModel.h:26
RooCmdArg Binning(const RooAbsBinning &binning)