ROOT logo

From $ROOTSYS/tutorials/roofit/rf512_wsfactory_oper.C

/////////////////////////////////////////////////////////////////////////
//
// 'ORGANIZATION AND SIMULTANEOUS FITS' RooFit tutorial macro #512
// 
//  Illustration of operator expressions and expression-based
//  basic p.d.f.s in the workspace factory syntax
//
// 04/2009 - Wouter Verkerke 
//
/////////////////////////////////////////////////////////////////////////

#ifndef __CINT__
#include "RooGlobalFunc.h"
#endif
#include "RooRealVar.h"
#include "RooDataSet.h"
#include "RooGaussian.h"
#include "RooConstVar.h"
#include "RooChebychev.h"
#include "RooAddPdf.h"
#include "RooWorkspace.h"
#include "RooPlot.h"
#include "TCanvas.h"
#include "TAxis.h"
using namespace RooFit ;


void rf512_wsfactory_oper()
{
  RooWorkspace* w = new RooWorkspace("w") ;

  // You can define typedefs for even shorter construction semantics
  w->factory("$Typedef(Gaussian,Gaus)") ;
  w->factory("$Typedef(Chebychev,Cheby)") ;


  // O p e r a t o r   p . d . f .   e x a m p l e s 
  // ------------------------------------------------

  // PDF addition is done with SUM (coef1*pdf1,pdf2)
  w->factory("SUM::summodel( f[0,1]*Gaussian::gx(x[-10,10],m[0],1.0), Chebychev::ch(x,{0.1,0.2,-0.3}) )") ;
  

  // Extended PDF addition is done with SUM (yield1*pdf1,yield2*pdf2)
  w->factory("SUM::extsummodel( Nsig[0,1000]*gx, Nbkg[0,1000]*ch )") ;
  

  // PDF multiplication is done with PROD ( pdf1, pdf2 ) 
  w->factory("PROD::gxz( gx, Gaussian::gz(z[-10,10],0,1) )") ;


  // Conditional p.d.f multiplication is done with PROD ( pdf1|obs, pdf2 )
  w->factory("Gaussian::gy( y[-10,10], x, 1.0 )") ;
  w->factory("PROD::gxycond( gy|x, gx )") ;


  // Convolution (numeric/ fft) is done with NCONV/FCONV (obs,pdf1,pdf2)
  w->factory("FCONV::lxg( x, Gaussian::g(x,mg[0],1), Landau::lc(x,0,1) )") ;


  // Simultaneous p.d.f.s are constructed with SIMUL( index, state1=pdf1, state2=pdf2,...)
  w->factory("SIMUL::smodel( c[A=0,B=1], A=Gaussian::gs(x,m,s[1]), B=Landau::ls(x,0,1) )") ; 




  // O p e r a t o r   f u n c t i o n   e x a m p l e s 
  // ---------------------------------------------------
  
  // Function multiplication is done with prod (func1, func2,...)
  w->factory("prod::uv(u[10],v[10])") ;


  // Function addition is done with sum(func1,func2)
  w->factory("sum::uv2(u,v)") ;



  // I n t e r p r e t e d   a n d   c o m p i l e d   e x p r e s s i o n   b a s e d   p . d . f . s .
  // ---------------------------------------------------------------------------------------------------

  // Create a RooGenericPdf interpreted p.d.f. You can use single quotes to pass the expression string argument
  w->factory("EXPR::G('x*x+1',x)") ;

  // Create a custom compiled p.d.f similar to the above interpreted p.d.f.
  // The code required to make this p.d.f. is automatically embedded in the workspace
  w->factory("CEXPR::GC('x*x+a',{x,a[1]})") ;


  // Compiled and interpreted functions (rather than p.d.f.s) can be made with the lower case 
  // 'expr' and 'cexpr' types

  // Print workspace contents
  w->Print() ;

  // Make workspace visible on command line
  gDirectory->Add(w) ;
}


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