Rf 5 1 2_Wsfactory_Oper

Organization and simultaneous fits: operator expressions and expression-based basic pdfs in the workspace factory syntax

Author: Wouter Verkerke
This notebook tutorial was automatically generated with ROOTBOOK-izer from the macro found in the ROOT repository on Wednesday, January 19, 2022 at 10:25 AM.

In [1]:
%%cpp -d
#include "RooRealVar.h"
#include "RooDataSet.h"
#include "RooGaussian.h"
#include "RooChebychev.h"
#include "RooAddPdf.h"
#include "RooWorkspace.h"
#include "RooPlot.h"
#include "TCanvas.h"
#include "TAxis.h"
In [2]:
%%cpp -d
// This is a workaround to make sure the namespace is used inside functions
using namespace RooFit;
In [3]:
RooWorkspace *w = new RooWorkspace("w");
RooFit v3.60 -- Developed by Wouter Verkerke and David Kirkby 
                Copyright (C) 2000-2013 NIKHEF, University of California & Stanford University
                All rights reserved, please read http://roofit.sourceforge.net/license.txt

You can define typedefs for even shorter construction semantics

In [4]:
w->factory("$Typedef(Gaussian,Gaus)");
w->factory("$Typedef(Chebychev,Cheby)");

Operator p.d.f. examples

Pdf addition is done with sum (coef1*pdf1,pdf2)

In [5]:
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 (yield1pdf1,yield2pdf2)

In [6]:
w->factory("SUM::extsummodel( Nsig[0,1000]*gx, Nbkg[0,1000]*ch )");

Pdf multiplication is done with prod ( pdf1, pdf2 )

In [7]:
w->factory("PROD::gxz( gx, Gaussian::gz(z[-10,10],0,1) )");

Conditional pdf multiplication is done with prod ( pdf1|obs, pdf2 )

In [8]:
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)

In [9]:
w->factory("FCONV::lxg( x, Gaussian::g(x,mg[0],1), Landau::lc(x,0,1) )");
[#1] INFO:Caching -- Changing internal binning of variable 'x' in FFT 'lxg' from 100 to 930 to improve the precision of the numerical FFT. This can be done manually by setting an additional binning named 'cache'.

Simultaneous pdfs are constructed with simul( index, state1=pdf1, state2=pdf2,...)

In [10]:
w->factory("SIMUL::smodel( c[A=0,B=1], A=Gaussian::gs(x,m,s[1]), B=Landau::ls(x,0,1) )");
[#0] WARNING:InputArguments -- The parameter 's' with range [-1e+30, 1e+30] of the RooGaussian 'gs' exceeds the safe range of (0, inf). Advise to limit its range.

Operator function examples

Function multiplication is done with prod (func1, func2,...)

In [11]:
w->factory("prod::uv(u[10],v[10])");

Function addition is done with sum(func1,func2)

In [12]:
w->factory("sum::uv2(u,v)");

Interpreted and compiled expression based p.d.f.s.

Create a roogenericpdf interpreted pdf you can use single quotes to pass the expression string argument

In [13]:
w->factory("EXPR::G('x*x+1',x)");

Create a custom compiled pdf similar to the above interpreted pdf The code required to make this pdf is automatically embedded in the workspace

In [14]:
w->factory("CEXPR::GC('x*x+a',{x,a[1]})");
[#1] INFO:ObjectHandling -- RooWorkspace::autoImportClass(w) importing code of class RooCFAuto000Pdf from /home/sftnight/build/workspace/root-makedoc-master/rootspi/rdoc/master_TMP/notebooks/RooCFAuto000Pdf.cxx and RooCFAuto000Pdf.h
Info in <TUnixSystem::ACLiC>: creating shared library /home/sftnight/build/workspace/root-makedoc-master/rootspi/rdoc/master_TMP/notebooks/RooCFAuto000Pdf_cxx.so

Compiled and interpreted functions (rather than pdfs) can be made with the lower case 'expr' and 'cexpr' types

Print workspace contents

In [15]:
w->Print();
RooWorkspace(w) w contents

variables
---------
(Nbkg,Nsig,a,c,f,m,mg,s,u,v,x,y,z)

p.d.f.s
-------
RooGenericPdf::G[ actualVars=(x) formula="x[0]*x[0]+1" ] = 1
RooCFAuto000Pdf::GC[ x=x a=a ] = 1
RooChebychev::ch[ x=x coefList=(0.1,0.2,-0.3) ] = 0.8
RooAddPdf::extsummodel[ Nsig * gx + Nbkg * ch ] = 0.9
RooGaussian::g[ x=x mean=mg sigma=1 ] = 1
RooGaussian::gs[ x=x mean=m sigma=s ] = 1
RooGaussian::gx[ x=x mean=m sigma=1 ] = 1
RooProdPdf::gxycond[ gx * gy|x ] = 1
RooProdPdf::gxz[ gx * gz ] = 1
RooGaussian::gy[ x=y mean=x sigma=1 ] = 1
RooGaussian::gz[ x=z mean=0 sigma=1 ] = 1
RooLandau::lc[ x=x mean=0 sigma=1 ] = 0.178854
RooLandau::ls[ x=x mean=0 sigma=1 ] = 0.178854
RooFFTConvPdf::lxg[ g(x) (*) lc(x) ] = 0.171832
RooSimultaneous::smodel[ indexCat=c A=gs B=ls ] = 1
RooAddPdf::summodel[ f * gx + [%] * ch ] = 0.9

functions
--------
RooProduct::uv[ u * v ] = 100
RooAddition::uv2[ u + v ] = 20

embedded class code
-------------------
RooCFAuto000Pdf

embedded precalculated expensive components
-------------------------------------------
uid = 0 key=lxg_g_CONV_lc_CACHEHIST_Obs[x]_BufFrac0.1_BufStrat0 value=RooDataHist::lxg_g_CONV_lc_CACHEHIST_Obs[x]_BufFrac0.1_BufStrat0 parameters=( mg=0 )

Make workspace visible on command line

In [16]:
gDirectory->Add(w);