Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
rf512_wsfactory_oper.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_roofit
3/// \notebook -nodraw
4/// Organization and simultaneous fits: operator expressions and expression-based basic
5/// pdfs in the workspace factory syntax
6///
7/// \macro_code
8/// \macro_output
9///
10/// \date July 2009
11/// \author Wouter Verkerke
12
13#include "RooRealVar.h"
14#include "RooDataSet.h"
15#include "RooGaussian.h"
16#include "RooChebychev.h"
17#include "RooAddPdf.h"
18#include "RooWorkspace.h"
19#include "RooPlot.h"
20#include "TCanvas.h"
21#include "TAxis.h"
22using namespace RooFit;
23
25{
26 RooWorkspace *w = new RooWorkspace("w");
27
28 // You can define typedefs for even shorter construction semantics
29 w->factory("$Typedef(Gaussian,Gaus)");
30 w->factory("$Typedef(Chebychev,Cheby)");
31
32 // O p e r a t o r p . d . f . e x a m p l e s
33 // ------------------------------------------------
34
35 // PDF addition is done with SUM (coef1*pdf1,pdf2)
36 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}) )");
37
38 // Extended PDF addition is done with SUM (yield1*pdf1,yield2*pdf2)
39 w->factory("SUM::extsummodel( Nsig[0,1000]*gx, Nbkg[0,1000]*ch )");
40
41 // PDF multiplication is done with PROD ( pdf1, pdf2 )
42 w->factory("PROD::gxz( gx, Gaussian::gz(z[-10,10],0,1) )");
43
44 // Conditional pdf multiplication is done with PROD ( pdf1|obs, pdf2 )
45 w->factory("Gaussian::gy( y[-10,10], x, 1.0 )");
46 w->factory("PROD::gxycond( gy|x, gx )");
47
48 // Convolution (numeric/ fft) is done with NCONV/FCONV (obs,pdf1,pdf2)
49 w->factory("FCONV::lxg( x, Gaussian::g(x,mg[0],1), Landau::lc(x,0,1) )");
50
51 // Simultaneous pdfs are constructed with SIMUL( index, state1=pdf1, state2=pdf2,...)
52 w->factory("SIMUL::smodel( c[A=0,B=1], A=Gaussian::gs(x,m,s[1.0, 0.01, 10.0]), B=Landau::ls(x,0,1) )");
53
54 // O p e r a t o r f u n c t i o n e x a m p l e s
55 // ---------------------------------------------------
56
57 // Function multiplication is done with prod (func1, func2,...)
58 w->factory("prod::uv(u[10],v[10])");
59
60 // Function addition is done with sum(func1,func2)
61 w->factory("sum::uv2(u,v)");
62
63 // Lagrangian morphing function for the example shown in rf711_lagrangianmorph
64 std::string infilename = std::string(gROOT->GetTutorialDir()) + "/roofit/input_histos_rf_lagrangianmorph.root";
65 w->factory(("lagrangianmorph::morph($fileName('"+infilename+"'),$observableName('pTV'),$couplings({cHq3[0,1],SM[1]}),$NewPhysics(cHq3=1,SM=0),$folders({'SM_NPsq0','cHq3_NPsq1','cHq3_NPsq2'}))").c_str());
66
67
68 // Taylor expansion is done with taylorexpand(func,{var1,var2,...},val,order)
69 w->factory("taylorexpand::te(expr::poly('x^4+5*x^3+2*x^2+x+1',x),{x},0.0,2)");
70
71
72 // 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 .
73 // ---------------------------------------------------------------------------------------------------
74
75 // Create a RooGenericPdf interpreted pdf You can use single quotes to pass the expression string argument
76 w->factory("EXPR::G('x*x+1',x)");
77
78 // Create a custom compiled pdf similar to the above interpreted pdf
79 // The code required to make this pdf is automatically embedded in the workspace
80 w->factory("CEXPR::GC('x*x+a',{x,a[1]})");
81
82 // Compiled and interpreted functions (rather than pdfs) can be made with the lower case
83 // 'expr' and 'cexpr' types
84
85 // Print workspace contents
86 w->Print();
87
88 // Make workspace visible on command line
89 gDirectory->Add(w);
90}
#define gDirectory
Definition TDirectory.h:384
#define gROOT
Definition TROOT.h:406
Persistable container for RooFit projects.
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Definition CodegenImpl.h:64