A RooLinkedList can only be used once?

Dear experts,

This script crashes (in ROOT 6.26/06) at the last line:

#!/usr/bin/env python3

import ROOT

w = ROOT.RooWorkspace("w")
w.factory('Gaussian::model(x[-10,10],mean[1,0,2],sigma[1,0.2,5])')
x = w['x']

x.setRange('rA',-10,3)

a = ROOT.RooLinkedList()
a.Add(ROOT.RooFit.Range('rA'))
a.Print('v')

xframe = w['x'].frame()
w.pdf('model').plotOn(xframe, a)
xframe.Draw()

tt = input('aaa:')

a.Print('v')

It seems the RooLinkedList object breaks after being used in the plotOn function. Is this normal? Thanks.

@jonas could you have a look here?

Hi! Yes, that’s normal. As you can also guess from the signature of RooAbsReal::plotOn(), it will change the state of the RooLinkedList because it takes a RooLinkedList & reference and not a RooLinkedList const& const reference.

The common pattern in RooFit is to copy the list before passing it to the function:

plotArgs = ROOT.RooLinkedList(a)
w.pdf('model').plotOn(xframe, plotArgs)

By the way, starting from 6.26 you can use the keyword argument Pythonizations which make the code much nicer I think:

#!/usr/bin/env python3

import ROOT

w = ROOT.RooWorkspace("w")
w.factory('Gaussian::model(x[-10,10],mean[1,0,2],sigma[1,0.2,5])')
x = w['x']

x.setRange('rA',-10,3)

a = {"Range" : "rA"}
print(a)

xframe = w['x'].frame()
w.pdf('model').plotOn(xframe, **a)
xframe.Draw()

tt = input('aaa:')
print(a) # it will also not clear your input arguments

Hope this helps!
Jonas

I see. Thanks a lot for the explanation!

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