rf311_rangeplot.C

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 "RooConstVar.h"
00020 #include "RooProdPdf.h"
00021 #include "RooAddPdf.h"
00022 #include "RooPolynomial.h"
00023 #include "TCanvas.h"
00024 #include "TAxis.h"
00025 #include "RooPlot.h"
00026 using namespace RooFit ;
00027 
00028 
00029 void rf311_rangeplot()
00030 {
00031 
00032   // C r e a t e   3 D   p d f   a n d   d a t a 
00033   // -------------------------------------------
00034 
00035   // Create observables
00036   RooRealVar x("x","x",-5,5) ;
00037   RooRealVar y("y","y",-5,5) ;
00038   RooRealVar z("z","z",-5,5) ;
00039 
00040   // Create signal pdf gauss(x)*gauss(y)*gauss(z) 
00041   RooGaussian gx("gx","gx",x,RooConst(0),RooConst(1)) ;
00042   RooGaussian gy("gy","gy",y,RooConst(0),RooConst(1)) ;
00043   RooGaussian gz("gz","gz",z,RooConst(0),RooConst(1)) ;
00044   RooProdPdf sig("sig","sig",RooArgSet(gx,gy,gz)) ;
00045 
00046   // Create background pdf poly(x)*poly(y)*poly(z) 
00047   RooPolynomial px("px","px",x,RooArgSet(RooConst(-0.1),RooConst(0.004))) ;
00048   RooPolynomial py("py","py",y,RooArgSet(RooConst(0.1),RooConst(-0.004))) ;
00049   RooPolynomial pz("pz","pz",z) ;
00050   RooProdPdf bkg("bkg","bkg",RooArgSet(px,py,pz)) ;
00051 
00052   // Create composite pdf sig+bkg
00053   RooRealVar fsig("fsig","signal fraction",0.1,0.,1.) ;
00054   RooAddPdf model("model","model",RooArgList(sig,bkg),fsig) ;
00055 
00056   RooDataSet* data = model.generate(RooArgSet(x,y,z),20000) ;
00057 
00058 
00059 
00060   // P r o j e c t   p d f   a n d   d a t a   o n   x
00061   // -------------------------------------------------
00062 
00063   // Make plain projection of data and pdf on x observable
00064   RooPlot* frame = x.frame(Title("Projection of 3D data and pdf on X"),Bins(40)) ;
00065   data->plotOn(frame) ;
00066   model.plotOn(frame) ;
00067   
00068 
00069 
00070   // 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
00071   // ----------------------------------------------------------------------------------
00072   
00073   // Define signal region in y and z observables
00074   y.setRange("sigRegion",-1,1) ;
00075   z.setRange("sigRegion",-1,1) ;
00076 
00077   // Make plot frame
00078   RooPlot* frame2 = x.frame(Title("Same projection on X in signal range of (Y,Z)"),Bins(40)) ;
00079 
00080   // Plot subset of data in which all observables are inside "sigRegion"
00081   // For observables that do not have an explicit "sigRegion" range defined (e.g. observable)
00082   // an implicit definition is used that is identical to the full range (i.e. [-5,5] for x)
00083   data->plotOn(frame2,CutRange("sigRegion")) ;
00084 
00085   // Project model on x, integrating projected observables (y,z) only in "sigRegion"
00086   model.plotOn(frame2,ProjectionRange("sigRegion")) ;
00087 
00088 
00089 
00090   TCanvas* c = new TCanvas("rf311_rangeplot","rf310_rangeplot",800,400) ;
00091   c->Divide(2) ;
00092   c->cd(1) ; gPad->SetLeftMargin(0.15) ; frame->GetYaxis()->SetTitleOffset(1.4) ; frame->Draw() ;
00093   c->cd(2) ; gPad->SetLeftMargin(0.15) ; frame2->GetYaxis()->SetTitleOffset(1.4) ; frame2->Draw() ;
00094 
00095 
00096 }

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