Using factory to create objects directly in the workspace

I follow the RooFit QuickStart guide:

section 1.3.1

I create a workspace:

root [0] RooWorkspace w("w", kTRUE)

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

[#1] INFO:ObjectHandling -- RooWorkspace::exportToCint(w) INFO: references to all objects in this workspace will be created in CINT in 'namespace w'
(RooWorkspace &) Name: w Title: w

Then I use factory to create objects directly in the workspace:

root [1] w.factory("Gaussian::g(x[-10,10],mean[0],sigma[3])");

and get a problem:

input_line_16:1:11: error: redefinition of 'w' as different kind of symbol
namespace w { RooRealVar& x = *(RooRealVar *)0x20366e0 ; }
          ^
ROOT_prompt_0:1:14: note: previous definition is here
RooWorkspace w("w", kTRUE)
             ^
input_line_17:1:11: error: redefinition of 'w' as different kind of symbol
namespace w { RooRealVar& mean = *(RooRealVar *)0x2038960 ; }
          ^
ROOT_prompt_0:1:14: note: previous definition is here
RooWorkspace w("w", kTRUE)
             ^
input_line_18:1:11: error: redefinition of 'w' as different kind of symbol
namespace w { RooRealVar& sigma = *(RooRealVar *)0x205e390 ; }
          ^
ROOT_prompt_0:1:14: note: previous definition is here
RooWorkspace w("w", kTRUE)
             ^
input_line_19:1:11: error: redefinition of 'w' as different kind of symbol
namespace w { RooGaussian& g = *(RooGaussian *)0x227ce50 ; }
          ^
ROOT_prompt_0:1:14: note: previous definition is here
RooWorkspace w("w", kTRUE)

What is wrong?

An answer is really appreciated.

@Viesturs, i tried your code, where “p” is name of workspace and “workspace” is declared RooWorkspace variable (check https://root.cern.ch/doc/master/classRooWorkspace.html):

root [3] RooWorkspace workspace("p", kTRUE)
[#1] INFO:ObjectHandling -- RooWorkspace::exportToCint(p) INFO: references to all objects in this workspace will be created in CINT in 'namespace p'
(RooWorkspace &) Name: p Title: p
root [4] workspace.factory("Gaussian::g(x[-10,10],mean[0],sigma[3])");

1 Like

The idea is to give RooWorkspace object a different name than the symbol name?

yes, it works for me in a such a way.

To make a complete answer g will be addressed as in:

p::g.Print()

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.