Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
rf511_wsfactory_basic.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_roofit
3/// \notebook -nodraw
4/// Organization and simultaneous fits: basic use of the 'object factory' associated with
5/// a workspace to rapidly build pdfs functions and their parameter components
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
24void rf511_wsfactory_basic(bool compact = false)
25{
26 RooWorkspace *w = new RooWorkspace("w");
27
28 // C r e a t i n g a n d a d d i n g b a s i c p . d . f . s
29 // ----------------------------------------------------------------
30
31 // Remake example pdf of tutorial rs502_wspacewrite.C:
32 //
33 // Basic pdf construction: ClassName::ObjectName(constructor arguments)
34 // Variable construction : VarName[x,xlo,xhi], VarName[xlo,xhi], VarName[x]
35 // P.d.f. addition : SUM::ObjectName(coef1*pdf1,...coefM*pdfM,pdfN)
36 //
37
38 if (!compact) {
39
40 // Use object factory to build pdf of tutorial rs502_wspacewrite
41 w->factory("Gaussian::sig1(x[-10,10],mean[5,0,10],0.5)");
42 w->factory("Gaussian::sig2(x,mean,1)");
43 w->factory("Chebychev::bkg(x,{a0[0.5,0.,1],a1[0.2,0.,1.]})");
44 w->factory("SUM::sig(sig1frac[0.8,0.,1.]*sig1,sig2)");
45 w->factory("SUM::model(bkgfrac[0.5,0.,1.]*bkg,sig)");
46
47 } else {
48
49 // Use object factory to build pdf of tutorial rs502_wspacewrite but
50 // - Contracted to a single line recursive expression,
51 // - Omitting explicit names for components that are not referred to explicitly later
52
53 w->factory("SUM::model(bkgfrac[0.5,0.,1.]*Chebychev::bkg(x[-10,10],{a0[0.5,0.,1],a1[0.2,0.,1.]}),"
54 "SUM(sig1frac[0.8,0.,1.]*Gaussian(x,mean[5,0,10],0.5), Gaussian(x,mean,1)))");
55 }
56
57 // A d v a n c e d p . d . f . c o n s t r u c t o r a r g u m e n t s
58 // ----------------------------------------------------------------
59 //
60 // P.d.f. constructor arguments may by any type of RooAbsArg, but also
61 //
62 // double --> converted to RooConst(...)
63 // {a,b,c} --> converted to RooArgSet() or RooArgList() depending on required ctor arg
64 // dataset name --> converted to RooAbsData reference for any dataset residing in the workspace
65 // enum --> Any enum label that belongs to an enum defined in the (base) class
66
67 // Make a dummy dataset pdf 'model' and import it in the workspace
68 std::unique_ptr<RooDataSet> data{w->pdf("model")->generate(*w->var("x"), 1000)};
69 w->import(*data, Rename("data"));
70
71 // Construct a KEYS pdf passing a dataset name and an enum type defining the
72 // mirroring strategy
73 w->factory("KeysPdf::k(x,data,NoMirror,0.2)");
74
75 // Print workspace contents
76 w->Print();
77}
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Persistable container for RooFit projects.
RooCmdArg Rename(const char *suffix)
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Definition JSONIO.h:26