rf108_plotbinning.cxx

Go to the documentation of this file.
00001 /////////////////////////////////////////////////////////////////////////
00002 //
00003 // 'BASIC FUNCTIONALITY' RooFit tutorial macro #108
00004 // 
00005 // Plotting unbinned data with alternate and variable binnings
00006 //
00007 // 
00008 // 07/2008 - Wouter Verkerke 
00009 // 
00010 /////////////////////////////////////////////////////////////////////////
00011 
00012 #ifndef __CINT__
00013 #include "RooGlobalFunc.h"
00014 #endif
00015 #include "RooRealVar.h"
00016 #include "RooDataSet.h"
00017 #include "RooGaussModel.h"
00018 #include "RooDecay.h"
00019 #include "RooBMixDecay.h"
00020 #include "RooCategory.h"
00021 #include "RooBinning.h"
00022 #include "RooPlot.h"
00023 #include "TCanvas.h"
00024 #include "TH1.h"
00025 using namespace RooFit ;
00026 
00027 
00028 class TestBasic108 : public RooFitTestUnit
00029 {
00030 public: 
00031   TestBasic108(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("Non-standard binning in counting and asymmetry plots",refFile,writeRef,verbose) {} ;
00032   Bool_t testCode() {
00033 
00034     // S e t u p   m o d e l 
00035     // ---------------------
00036     
00037     // Build a B decay p.d.f with mixing
00038     RooRealVar dt("dt","dt",-20,20) ;
00039     RooRealVar dm("dm","dm",0.472) ;
00040     RooRealVar tau("tau","tau",1.547) ;
00041     RooRealVar w("w","mistag rate",0.1) ;
00042     RooRealVar dw("dw","delta mistag rate",0.) ;
00043     
00044     RooCategory mixState("mixState","B0/B0bar mixing state") ;
00045     mixState.defineType("mixed",-1) ;
00046     mixState.defineType("unmixed",1) ;
00047     RooCategory tagFlav("tagFlav","Flavour of the tagged B0") ;
00048     tagFlav.defineType("B0",1) ;
00049     tagFlav.defineType("B0bar",-1) ;
00050     
00051     // Build a gaussian resolution model
00052     RooRealVar dterr("dterr","dterr",0.1,1.0) ;
00053     RooRealVar bias1("bias1","bias1",0) ;
00054     RooRealVar sigma1("sigma1","sigma1",0.1) ;  
00055     RooGaussModel gm1("gm1","gauss model 1",dt,bias1,sigma1) ;
00056     
00057     // Construct Bdecay (x) gauss
00058     RooBMixDecay bmix("bmix","decay",dt,mixState,tagFlav,tau,dm,w,dw,gm1,RooBMixDecay::DoubleSided) ;
00059     
00060     
00061     // S a m p l e   d a t a   f r o m   m o d e l
00062     // --------------------------------------------
00063     
00064     // Sample 2000 events in (dt,mixState,tagFlav) from bmix
00065     RooDataSet *data = bmix.generate(RooArgSet(dt,mixState,tagFlav),2000) ;
00066     
00067     
00068     
00069     // 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
00070     // -------------------------------------------------------------------------------
00071     
00072     // Make plot of dt distribution of data in range (-15,15) with fine binning for dt>0 and coarse binning for dt<0
00073     
00074     // Create binning object with range (-15,15)
00075     RooBinning tbins(-15,15) ;
00076     
00077     // Add 60 bins with uniform spacing in range (-15,0)
00078     tbins.addUniform(60,-15,0) ;
00079     
00080     // Add 15 bins with uniform spacing in range (0,15)
00081     tbins.addUniform(15,0,15) ;
00082     
00083     // Make plot with specified binning
00084     RooPlot* dtframe = dt.frame(Range(-15,15),Title("dt distribution with custom binning")) ;
00085     data->plotOn(dtframe,Binning(tbins)) ;
00086     bmix.plotOn(dtframe) ;
00087     
00088     // NB: Note that bin density for each bin is adjusted to that of default frame binning as shown
00089     // in Y axis label (100 bins --> Events/0.4*Xaxis-dim) so that all bins represent a consistent density distribution
00090     
00091     
00092     // 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
00093     // ------------------------------------------------------------------------------------
00094     
00095     // Make plot of dt distribution of data asymmetry in 'mixState' with variable binning 
00096     
00097     // Create binning object with range (-10,10)
00098     RooBinning abins(-10,10) ;
00099     
00100     // Add boundaries at 0, (-1,1), (-2,2), (-3,3), (-4,4) and (-6,6)
00101     abins.addBoundary(0) ;
00102     abins.addBoundaryPair(1) ;
00103     abins.addBoundaryPair(2) ;
00104     abins.addBoundaryPair(3) ;
00105     abins.addBoundaryPair(4) ;
00106     abins.addBoundaryPair(6) ;
00107     
00108     // Create plot frame in dt
00109     RooPlot* aframe = dt.frame(Range(-10,10),Title("mixState asymmetry distribution with custom binning")) ;
00110     
00111     // Plot mixState asymmetry of data with specified customg binning
00112     data->plotOn(aframe,Asymmetry(mixState),Binning(abins)) ;
00113     
00114     // Plot corresponding property of p.d.f
00115     bmix.plotOn(aframe,Asymmetry(mixState)) ;
00116     
00117     // Adjust vertical range of plot to sensible values for an asymmetry
00118     aframe->SetMinimum(-1.1) ;
00119     aframe->SetMaximum(1.1) ;
00120     
00121     // NB: For asymmetry distributions no density corrects are needed (and are thus not applied)
00122     
00123 
00124     regPlot(dtframe,"rf108_plot1") ;
00125     regPlot(aframe,"rf108_plot2") ;
00126 
00127     delete data ;
00128 
00129     return kTRUE ;
00130   }
00131 } ;

Generated on Tue Jul 5 15:07:46 2011 for ROOT_528-00b_version by  doxygen 1.5.1