ROOT logo

From $ROOTSYS/tutorials/roofit/rf211_paramconv.C

/////////////////////////////////////////////////////////////////////////
//
// 'ADDITION AND CONVOLUTION' RooFit tutorial macro #211
// 
// Working a with a p.d.f. with a convolution operator in terms
// of a parameter
//
// (require ROOT to be compiled with --enable-fftw3)
// 
//
// 04/2009 - Wouter Verkerke 
//
/////////////////////////////////////////////////////////////////////////

#ifndef __CINT__
#include "RooGlobalFunc.h"
#endif
#include "RooRealVar.h"
#include "RooDataHist.h"
#include "RooGaussian.h"
#include "RooGenericPdf.h"
#include "RooFormulaVar.h"
#include "RooFFTConvPdf.h"
#include "RooPlot.h"
#include "TCanvas.h"
#include "TAxis.h"
#include "TH2.h"
using namespace RooFit ;


void rf211_paramconv()
{
  // S e t u p   c o m p o n e n t   p d f s 
  // ---------------------------------------
  
  // Gaussian g(x ; mean,sigma) 
  RooRealVar x("x","x",-10,10) ;
  RooRealVar mean("mean","mean",-3,3) ;
  RooRealVar sigma("sigma","sigma",0.5,0.1,10) ;
  RooGaussian modelx("gx","gx",x,mean,sigma) ;

  // Block function in mean
  RooRealVar a("a","a",2,1,10) ;
  RooGenericPdf model_mean("model_mean","abs(mean)<a",RooArgList(mean,a)) ;

  // Convolution in mean parameter model = g(x,mean,sigma) (x) block(mean)
  x.setBins(1000,"cache") ;
  mean.setBins(50,"cache") ;
  RooFFTConvPdf model("model","model",mean,modelx,model_mean) ;

  // Configure convolution to construct a 2-D cache in (x,mean)
  // rather than a 1-d cache in mean that needs to be recalculated
  // for each value of x
  model.setCacheObservables(x) ;
  model.setBufferFraction(1.0) ;

  // Integrate model over mean projModel = Int model dmean
  RooAbsPdf* projModel = model.createProjection(mean) ;

  // Generate 1000 toy events
  RooDataHist* d = projModel->generateBinned(x,1000) ;

  // Fit p.d.f. to toy data
  projModel->fitTo(*d,Verbose()) ;

  // Plot data and fitted p.d.f.
  RooPlot* frame = x.frame(Bins(25)) ;
  d->plotOn(frame) ;
  projModel->plotOn(frame) ;

  // Make 2d histogram of model(x;mean)
  TH1* hh = model.createHistogram("hh",x,Binning(50),YVar(mean,Binning(50)),ConditionalObservables(mean)) ;
  hh->SetTitle("histogram of model(x|mean)") ;
  hh->SetLineColor(kBlue) ;

  // Draw frame on canvas
  TCanvas* c = new TCanvas("rf211_paramconv","rf211_paramconv",800,400) ;
  c->Divide(2) ;
  c->cd(1) ; gPad->SetLeftMargin(0.15) ; frame->GetYaxis()->SetTitleOffset(1.4) ; frame->Draw() ;
  c->cd(2) ; gPad->SetLeftMargin(0.20) ; hh->GetZaxis()->SetTitleOffset(2.5) ; hh->Draw("surf") ;

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