rf301_composition.cxx

Go to the documentation of this file.
00001 /////////////////////////////////////////////////////////////////////////
00002 //
00003 // 'MULTIDIMENSIONAL MODELS' RooFit tutorial macro #301
00004 // 
00005 // Multi-dimensional p.d.f.s through composition, e.g. substituting a 
00006 // p.d.f parameter with a function that depends on other observables
00007 // 
00008 // pdf = gauss(x,f(y),s) with f(y) = a0 + a1*y
00009 // 
00010 //
00011 // 07/2008 - Wouter Verkerke 
00012 //
00013 /////////////////////////////////////////////////////////////////////////
00014 
00015 #ifndef __CINT__
00016 #include "RooGlobalFunc.h"
00017 #endif
00018 #include "RooRealVar.h"
00019 #include "RooDataSet.h"
00020 #include "RooGaussian.h"
00021 #include "RooPolyVar.h"
00022 #include "RooPlot.h"
00023 #include "TCanvas.h"
00024 #include "TH1.h"
00025 using namespace RooFit ;
00026 
00027 
00028 
00029 class TestBasic301 : public RooFitTestUnit
00030 {
00031 public: 
00032   TestBasic301(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("Composition extension of basic p.d.f",refFile,writeRef,verbose) {} ;
00033   Bool_t testCode() {
00034 
00035   // S e t u p   c o m p o s e d   m o d e l   g a u s s ( x , m ( y ) , s )
00036   // -----------------------------------------------------------------------
00037 
00038   // Create observables
00039   RooRealVar x("x","x",-5,5) ;
00040   RooRealVar y("y","y",-5,5) ;
00041 
00042   // Create function f(y) = a0 + a1*y
00043   RooRealVar a0("a0","a0",-0.5,-5,5) ;
00044   RooRealVar a1("a1","a1",-0.5,-1,1) ;
00045   RooPolyVar fy("fy","fy",y,RooArgSet(a0,a1)) ;
00046 
00047   // Creat gauss(x,f(y),s)
00048   RooRealVar sigma("sigma","width of gaussian",0.5) ;
00049   RooGaussian model("model","Gaussian with shifting mean",x,fy,sigma) ;  
00050 
00051 
00052   // S a m p l e   d a t a ,   p l o t   d a t a   a n d   p d f   o n   x   a n d   y 
00053   // ---------------------------------------------------------------------------------
00054 
00055   // Generate 10000 events in x and y from model
00056   RooDataSet *data = model.generate(RooArgSet(x,y),10000) ;
00057 
00058   // Plot x distribution of data and projection of model on x = Int(dy) model(x,y)
00059   RooPlot* xframe = x.frame() ;
00060   data->plotOn(xframe) ;
00061   model.plotOn(xframe) ; 
00062 
00063   // Plot x distribution of data and projection of model on y = Int(dx) model(x,y)
00064   RooPlot* yframe = y.frame() ;
00065   data->plotOn(yframe) ;
00066   model.plotOn(yframe) ; 
00067 
00068   // Make two-dimensional plot in x vs y
00069   TH1* hh_model = model.createHistogram("hh_model",x,Binning(50),YVar(y,Binning(50))) ;
00070   hh_model->SetLineColor(kBlue) ;
00071 
00072 
00073   regPlot(xframe,"rf301_plot1") ;
00074   regPlot(yframe,"rf302_plot2") ;
00075   regTH(hh_model,"rf302_model2d") ;
00076 
00077   delete data ;
00078   return kTRUE ;
00079   }
00080 } ;
00081 
00082 

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