rf108_plotbinning.C

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 "TAxis.h"
00025 #include "TH1.h"
00026 using namespace RooFit ;
00027 
00028 
00029 void rf108_plotbinning()
00030 {
00031 
00032   // S e t u p   m o d e l 
00033   // ---------------------
00034 
00035   // Build a B decay p.d.f with mixing
00036   RooRealVar dt("dt","dt",-20,20) ;
00037   RooRealVar dm("dm","dm",0.472) ;
00038   RooRealVar tau("tau","tau",1.547) ;
00039   RooRealVar w("w","mistag rate",0.1) ;
00040   RooRealVar dw("dw","delta mistag rate",0.) ;
00041 
00042   RooCategory mixState("mixState","B0/B0bar mixing state") ;
00043   mixState.defineType("mixed",-1) ;
00044   mixState.defineType("unmixed",1) ;
00045   RooCategory tagFlav("tagFlav","Flavour of the tagged B0") ;
00046   tagFlav.defineType("B0",1) ;
00047   tagFlav.defineType("B0bar",-1) ;
00048 
00049   // Build a gaussian resolution model
00050   RooRealVar dterr("dterr","dterr",0.1,1.0) ;
00051   RooRealVar bias1("bias1","bias1",0) ;
00052   RooRealVar sigma1("sigma1","sigma1",0.1) ;  
00053   RooGaussModel gm1("gm1","gauss model 1",dt,bias1,sigma1) ;
00054 
00055   // Construct Bdecay (x) gauss
00056   RooBMixDecay bmix("bmix","decay",dt,mixState,tagFlav,tau,dm,w,dw,gm1,RooBMixDecay::DoubleSided) ;
00057 
00058 
00059   // S a m p l e   d a t a   f r o m   m o d e l
00060   // --------------------------------------------
00061 
00062   // Sample 2000 events in (dt,mixState,tagFlav) from bmix
00063   RooDataSet *data = bmix.generate(RooArgSet(dt,mixState,tagFlav),2000) ;
00064 
00065 
00066 
00067   // 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
00068   // -------------------------------------------------------------------------------
00069 
00070   // Make plot of dt distribution of data in range (-15,15) with fine binning for dt>0 and coarse binning for dt<0
00071 
00072   // Create binning object with range (-15,15)
00073   RooBinning tbins(-15,15) ;
00074 
00075   // Add 60 bins with uniform spacing in range (-15,0)
00076   tbins.addUniform(60,-15,0) ;
00077 
00078   // Add 15 bins with uniform spacing in range (0,15)
00079   tbins.addUniform(15,0,15) ;
00080   
00081   // Make plot with specified binning
00082   RooPlot* dtframe = dt.frame(Range(-15,15),Title("dt distribution with custom binning")) ;
00083   data->plotOn(dtframe,Binning(tbins)) ;
00084   bmix.plotOn(dtframe) ;
00085 
00086   // NB: Note that bin density for each bin is adjusted to that of default frame binning as shown
00087   // in Y axis label (100 bins --> Events/0.4*Xaxis-dim) so that all bins represent a consistent density distribution
00088   
00089   
00090   // 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
00091   // ------------------------------------------------------------------------------------
00092 
00093   // Make plot of dt distribution of data asymmetry in 'mixState' with variable binning 
00094 
00095   // Create binning object with range (-10,10)
00096   RooBinning abins(-10,10) ;
00097 
00098   // Add boundaries at 0, (-1,1), (-2,2), (-3,3), (-4,4) and (-6,6)
00099   abins.addBoundary(0) ;
00100   abins.addBoundaryPair(1) ;
00101   abins.addBoundaryPair(2) ;
00102   abins.addBoundaryPair(3) ;
00103   abins.addBoundaryPair(4) ;
00104   abins.addBoundaryPair(6) ;
00105   
00106   // Create plot frame in dt
00107   RooPlot* aframe = dt.frame(Range(-10,10),Title("mixState asymmetry distribution with custom binning")) ;
00108 
00109   // Plot mixState asymmetry of data with specified customg binning
00110   data->plotOn(aframe,Asymmetry(mixState),Binning(abins)) ;
00111 
00112   // Plot corresponding property of p.d.f
00113   bmix.plotOn(aframe,Asymmetry(mixState)) ;
00114 
00115   // Adjust vertical range of plot to sensible values for an asymmetry
00116   aframe->SetMinimum(-1.1) ;
00117   aframe->SetMaximum(1.1) ;
00118 
00119   // NB: For asymmetry distributions no density corrects are needed (and are thus not applied)
00120 
00121 
00122   // Draw plots on canvas
00123   TCanvas* c = new TCanvas("rf108_plotbinning","rf108_plotbinning",800,400) ;
00124   c->Divide(2) ;
00125   c->cd(1) ; gPad->SetLeftMargin(0.15) ; dtframe->GetYaxis()->SetTitleOffset(1.6) ; dtframe->Draw() ;
00126   c->cd(2) ; gPad->SetLeftMargin(0.15) ; aframe->GetYaxis()->SetTitleOffset(1.6) ; aframe->Draw() ;
00127   
00128 }

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