rf301_composition.C

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 "TAxis.h"
00025 #include "TH1.h"
00026 using namespace RooFit ;
00027 
00028 
00029 
00030 void rf301_composition()
00031 {
00032   // 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 )
00033   // -----------------------------------------------------------------------
00034 
00035   // Create observables
00036   RooRealVar x("x","x",-5,5) ;
00037   RooRealVar y("y","y",-5,5) ;
00038 
00039   // Create function f(y) = a0 + a1*y
00040   RooRealVar a0("a0","a0",-0.5,-5,5) ;
00041   RooRealVar a1("a1","a1",-0.5,-1,1) ;
00042   RooPolyVar fy("fy","fy",y,RooArgSet(a0,a1)) ;
00043 
00044   // Creat gauss(x,f(y),s)
00045   RooRealVar sigma("sigma","width of gaussian",0.5) ;
00046   RooGaussian model("model","Gaussian with shifting mean",x,fy,sigma) ;  
00047 
00048 
00049   // 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 
00050   // ---------------------------------------------------------------------------------
00051 
00052   // Generate 10000 events in x and y from model
00053   RooDataSet *data = model.generate(RooArgSet(x,y),10000) ;
00054 
00055   // Plot x distribution of data and projection of model on x = Int(dy) model(x,y)
00056   RooPlot* xframe = x.frame() ;
00057   data->plotOn(xframe) ;
00058   model.plotOn(xframe) ; 
00059 
00060   // Plot x distribution of data and projection of model on y = Int(dx) model(x,y)
00061   RooPlot* yframe = y.frame() ;
00062   data->plotOn(yframe) ;
00063   model.plotOn(yframe) ; 
00064 
00065   // Make two-dimensional plot in x vs y
00066   TH1* hh_model = model.createHistogram("hh_model",x,Binning(50),YVar(y,Binning(50))) ;
00067   hh_model->SetLineColor(kBlue) ;
00068 
00069 
00070 
00071   // Make canvas and draw RooPlots
00072   TCanvas *c = new TCanvas("rf301_composition","rf301_composition",1200, 400);
00073   c->Divide(3);
00074   c->cd(1) ; gPad->SetLeftMargin(0.15) ; xframe->GetYaxis()->SetTitleOffset(1.4) ; xframe->Draw() ;
00075   c->cd(2) ; gPad->SetLeftMargin(0.15) ; yframe->GetYaxis()->SetTitleOffset(1.4) ; yframe->Draw() ;
00076   c->cd(3) ; gPad->SetLeftMargin(0.20) ; hh_model->GetZaxis()->SetTitleOffset(2.5) ; hh_model->Draw("surf") ;
00077 
00078 }
00079 
00080 
00081 

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