Question: How to get a functor/function/method from a rooworkspace?


I am wondering how to obtain a functor/function in pyroot provided a RooFormulaVar.

So, a set of corrections is given in the form of a workspace with various RooFormulaVar objects inside. The corrections should be applied in an event loop and I would like to be able to omit to keep an argset=w.argset(...) and to do argset.setRealValue("a", X) for each of the parameters and instead store functions that just accept a list of input parameters (as they expect). I assume this is possible using functor but I haven’t figured how to do it correctly. Perhaps anyone else knows this?

# Lets say in the workspace I have:
#`RooFormulaVar::em_qcd_osss_2jet_unc2_down[ actualVars=(njets,dR) formula="(@0>=2)*(3.040602+-0.383167*@1)" ] = 0`
>>> argset = m_workspace.argSet("njets,dR")
>>> fn = m_workspace.function("em_qcd_osss_2jet_unc2_down")
>>> func = fn.functor(argset) # will not work
TypeError: RooFunctor* RooAbsReal::functor(const RooArgList& obs, const RooArgList& pars = RooArgList(), const RooArgSet& nset = RooArgSet()) =>
    could not convert argument 1

>>> type(argset)
<class 'ROOT.RooArgSet'>
>>> argset.Print()
RooArgSet:: = (dR,njets)
>>> type(fn)
<class 'ROOT.RooFormulaVar'>
>>> fn.Print()
RooFormulaVar::em_qcd_osss_2jet_unc2_down[ actualVars=(njets,dR) formula="(@0>=2)*(3.040602+-0.383167*@1)" ] = 0

# This will work but is inconvenient to use
>>> argset.setRealValue('njets', 2)
>>> argset.setRealValue('dR', 0.015)
>>> fn.getVal(argset)

Hi @Olena,
sorry for the late reply, maybe @moneta can help.


Hi @Olena,

in the TypeError you can see that fn.functor() needs a RooArgList as parameter. Try to create one like this:

arglist = ROOT.RooArgList(argset)
func = fn.functor(arglist)
1 Like

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