rf311_rangeplot.cxx

Go to the documentation of this file.
00001 //////////////////////////////////////////////////////////////////////////
00002 //
00003 // 'MULTIDIMENSIONAL MODELS' RooFit tutorial macro #310
00004 // 
00005 // Projecting p.d.f and data ranges in continuous observables
00006 //
00007 //
00008 //
00009 // 07/2008 - Wouter Verkerke 
00010 // 
00011 /////////////////////////////////////////////////////////////////////////
00012 
00013 #ifndef __CINT__
00014 #include "RooGlobalFunc.h"
00015 #endif
00016 #include "RooRealVar.h"
00017 #include "RooDataSet.h"
00018 #include "RooGaussian.h"
00019 #include "RooProdPdf.h"
00020 #include "RooAddPdf.h"
00021 #include "RooPolynomial.h"
00022 #include "TCanvas.h"
00023 #include "RooPlot.h"
00024 using namespace RooFit ;
00025 
00026 
00027 class TestBasic311 : public RooFitTestUnit
00028 {
00029 public: 
00030   TestBasic311(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("Data and p.d.f projection in sub range",refFile,writeRef,verbose) {} ;
00031   Bool_t testCode() {
00032 
00033   // C r e a t e   3 D   p d f   a n d   d a t a 
00034   // -------------------------------------------
00035 
00036   // Create observables
00037   RooRealVar x("x","x",-5,5) ;
00038   RooRealVar y("y","y",-5,5) ;
00039   RooRealVar z("z","z",-5,5) ;
00040 
00041   // Create signal pdf gauss(x)*gauss(y)*gauss(z) 
00042   RooGaussian gx("gx","gx",x,RooConst(0),RooConst(1)) ;
00043   RooGaussian gy("gy","gy",y,RooConst(0),RooConst(1)) ;
00044   RooGaussian gz("gz","gz",z,RooConst(0),RooConst(1)) ;
00045   RooProdPdf sig("sig","sig",RooArgSet(gx,gy,gz)) ;
00046 
00047   // Create background pdf poly(x)*poly(y)*poly(z) 
00048   RooPolynomial px("px","px",x,RooArgSet(RooConst(-0.1),RooConst(0.004))) ;
00049   RooPolynomial py("py","py",y,RooArgSet(RooConst(0.1),RooConst(-0.004))) ;
00050   RooPolynomial pz("pz","pz",z) ;
00051   RooProdPdf bkg("bkg","bkg",RooArgSet(px,py,pz)) ;
00052 
00053   // Create composite pdf sig+bkg
00054   RooRealVar fsig("fsig","signal fraction",0.1,0.,1.) ;
00055   RooAddPdf model("model","model",RooArgList(sig,bkg),fsig) ;
00056 
00057   RooDataSet* data = model.generate(RooArgSet(x,y,z),20000) ;
00058 
00059 
00060 
00061   // P r o j e c t   p d f   a n d   d a t a   o n   x
00062   // -------------------------------------------------
00063 
00064   // Make plain projection of data and pdf on x observable
00065   RooPlot* frame = x.frame(Title("Projection of 3D data and pdf on X"),Bins(40)) ;
00066   data->plotOn(frame) ;
00067   model.plotOn(frame) ;
00068   
00069 
00070 
00071   // P r o j e c t   p d f   a n d   d a t a   o n   x   i n   s i g n a l   r a n g e
00072   // ----------------------------------------------------------------------------------
00073   
00074   // Define signal region in y and z observables
00075   y.setRange("sigRegion",-1,1) ;
00076   z.setRange("sigRegion",-1,1) ;
00077 
00078   // Make plot frame
00079   RooPlot* frame2 = x.frame(Title("Same projection on X in signal range of (Y,Z)"),Bins(40)) ;
00080 
00081   // Plot subset of data in which all observables are inside "sigRegion"
00082   // For observables that do not have an explicit "sigRegion" range defined (e.g. observable)
00083   // an implicit definition is used that is identical to the full range (i.e. [-5,5] for x)
00084   data->plotOn(frame2,CutRange("sigRegion")) ;
00085 
00086   // Project model on x, integrating projected observables (y,z) only in "sigRegion"
00087   model.plotOn(frame2,ProjectionRange("sigRegion")) ;
00088 
00089 
00090   regPlot(frame,"rf311_plot1") ;
00091   regPlot(frame2,"rf312_plot2") ;
00092 
00093   delete data ;
00094 
00095   return kTRUE ;
00096   }
00097 } ;

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