ROOT logo
/////////////////////////////////////////////////////////////////////////
//
// 'MULTIDIMENSIONAL MODELS' RooFit tutorial macro #301
// 
// Multi-dimensional p.d.f.s through composition, e.g. substituting a 
// p.d.f parameter with a function that depends on other observables
// 
// pdf = gauss(x,f(y),s) with f(y) = a0 + a1*y
// 
//
// 07/2008 - Wouter Verkerke 
//
/////////////////////////////////////////////////////////////////////////

#ifndef __CINT__
#include "RooGlobalFunc.h"
#endif
#include "RooRealVar.h"
#include "RooDataSet.h"
#include "RooGaussian.h"
#include "RooPolyVar.h"
#include "RooPlot.h"
#include "TCanvas.h"
#include "TAxis.h"
#include "TH1.h"
using namespace RooFit ;



void rf301_composition()
{
  // 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 )
  // -----------------------------------------------------------------------

  // Create observables
  RooRealVar x("x","x",-5,5) ;
  RooRealVar y("y","y",-5,5) ;

  // Create function f(y) = a0 + a1*y
  RooRealVar a0("a0","a0",-0.5,-5,5) ;
  RooRealVar a1("a1","a1",-0.5,-1,1) ;
  RooPolyVar fy("fy","fy",y,RooArgSet(a0,a1)) ;

  // Creat gauss(x,f(y),s)
  RooRealVar sigma("sigma","width of gaussian",0.5) ;
  RooGaussian model("model","Gaussian with shifting mean",x,fy,sigma) ;  


  // 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 
  // ---------------------------------------------------------------------------------

  // Generate 10000 events in x and y from model
  RooDataSet *data = model.generate(RooArgSet(x,y),10000) ;

  // Plot x distribution of data and projection of model on x = Int(dy) model(x,y)
  RooPlot* xframe = x.frame() ;
  data->plotOn(xframe) ;
  model.plotOn(xframe) ; 

  // Plot x distribution of data and projection of model on y = Int(dx) model(x,y)
  RooPlot* yframe = y.frame() ;
  data->plotOn(yframe) ;
  model.plotOn(yframe) ; 

  // Make two-dimensional plot in x vs y
  TH1* hh_model = model.createHistogram("hh_model",x,Binning(50),YVar(y,Binning(50))) ;
  hh_model->SetLineColor(kBlue) ;



  // Make canvas and draw RooPlots
  TCanvas *c = new TCanvas("rf301_composition","rf301_composition",1200, 400);
  c->Divide(3);
  c->cd(1) ; gPad->SetLeftMargin(0.15) ; xframe->GetYaxis()->SetTitleOffset(1.4) ; xframe->Draw() ;
  c->cd(2) ; gPad->SetLeftMargin(0.15) ; yframe->GetYaxis()->SetTitleOffset(1.4) ; yframe->Draw() ;
  c->cd(3) ; gPad->SetLeftMargin(0.20) ; hh_model->GetZaxis()->SetTitleOffset(2.5) ; hh_model->Draw("surf") ;

}



 rf301_composition.C:1
 rf301_composition.C:2
 rf301_composition.C:3
 rf301_composition.C:4
 rf301_composition.C:5
 rf301_composition.C:6
 rf301_composition.C:7
 rf301_composition.C:8
 rf301_composition.C:9
 rf301_composition.C:10
 rf301_composition.C:11
 rf301_composition.C:12
 rf301_composition.C:13
 rf301_composition.C:14
 rf301_composition.C:15
 rf301_composition.C:16
 rf301_composition.C:17
 rf301_composition.C:18
 rf301_composition.C:19
 rf301_composition.C:20
 rf301_composition.C:21
 rf301_composition.C:22
 rf301_composition.C:23
 rf301_composition.C:24
 rf301_composition.C:25
 rf301_composition.C:26
 rf301_composition.C:27
 rf301_composition.C:28
 rf301_composition.C:29
 rf301_composition.C:30
 rf301_composition.C:31
 rf301_composition.C:32
 rf301_composition.C:33
 rf301_composition.C:34
 rf301_composition.C:35
 rf301_composition.C:36
 rf301_composition.C:37
 rf301_composition.C:38
 rf301_composition.C:39
 rf301_composition.C:40
 rf301_composition.C:41
 rf301_composition.C:42
 rf301_composition.C:43
 rf301_composition.C:44
 rf301_composition.C:45
 rf301_composition.C:46
 rf301_composition.C:47
 rf301_composition.C:48
 rf301_composition.C:49
 rf301_composition.C:50
 rf301_composition.C:51
 rf301_composition.C:52
 rf301_composition.C:53
 rf301_composition.C:54
 rf301_composition.C:55
 rf301_composition.C:56
 rf301_composition.C:57
 rf301_composition.C:58
 rf301_composition.C:59
 rf301_composition.C:60
 rf301_composition.C:61
 rf301_composition.C:62
 rf301_composition.C:63
 rf301_composition.C:64
 rf301_composition.C:65
 rf301_composition.C:66
 rf301_composition.C:67
 rf301_composition.C:68
 rf301_composition.C:69
 rf301_composition.C:70
 rf301_composition.C:71
 rf301_composition.C:72
 rf301_composition.C:73
 rf301_composition.C:74
 rf301_composition.C:75
 rf301_composition.C:76
 rf301_composition.C:77
 rf301_composition.C:78
 rf301_composition.C:79
 rf301_composition.C:80
 rf301_composition.C:81
 rf301_composition.C:82