Wrong RooAbsPdf.fitTo() interface called

Hi,

I have another mysterious problem where I try to fit a RooAbsPdf to data using its fitTo() interface. The problem I am seeing is that there are two fitTo interfaces: with a list and with RooCmdArgs (see link below), and a wrong one is always picked, no matter how I choose to call it.

http://root.cern.ch/root/html/RooAbsPdf.html#RooAbsPdf:fitTo

The following script illustrates the problem. See three fitTo lines at the end. Any of them should do the fit but all fail because every time the wrong method interface is guessed. Any advice would be welcome!

#!/usr/bin/env python

from ROOT import RooWorkspace
from ROOT import RooAbsData
from ROOT import RooDataSet
from ROOT import RooFit
from ROOT import RooLinkedList
from ROOT import RooCmdArg

from ROOT import gROOT
gROOT.LoadMacro( "roofit_iterators.h+" )

wspace = RooWorkspace('wspace')

# make model (taken from roostats tutorial pages)
wspace.factory("Poisson::on(non[0,1000], sum::splusb(s[40,0,100],b[100,0,300]))")
wspace.factory("Poisson::off(noff[0,5000], prod::taub(b,tau[5,3,7],rho[1,0,2]))")
wspace.factory("Poisson::onbar(nonbar[0,10000], bbar[1000,500,2000])")
wspace.factory("Poisson::offbar(noffbar[0,1000000], prod::lambdaoffbar(bbar, tau))")
wspace.factory("Gaussian::mcCons(rhonom[1.,0,2], rho, sigma[.2])")
wspace.factory("PROD::model(on,off,onbar,offbar,mcCons)")
wspace.defineSet("obs","non,noff,nonbar,noffbar,rhonom")

data = wspace.pdf("model").generate(wspace.set("obs"),1)
data2 = wspace.pdf("model").generate(wspace.set("obs"),1, RooFit.Name('data2'))

data.Print("v");
getattr(wspace, 'import')(data)
getattr(wspace, 'import')(data2)

# workspace contents
wspace.Print()

# try fitting
_rll = RooLinkedList()
_rll.Add(RooFit.Save())

_fit = wspace.pdf("model").fitTo(wspace.data("data"), RooFit.Save())
#_fit = wspace.pdf("model").fitTo(wspace.data("data"), RooFit.Save(), RooCmdArg.none())
#_fit = wspace.pdf("model").fitTo(wspace.data("data"), _rll)

Hi,

the code crashes for reasons that are not clear to me, but the correct fitTo is being called in all cases. How did you conclude otherwise? Note that RooFit internally calles the LinkedList version from the CmdArg version.

Cheers,
Wim

It looks like you’re right, even though the problem is still not fully resolved. The code snippet from the original message crashes if I call RooWorkspace::data() inside the call to fitTo(), like this:

pdf.fitTo(workspace.data("datasetName"), RooFit.Save())

However, if I get the dataset out of the workspace first, than call fitTo(), it works just fine:

data = workspace.data("datasetName")
pdf.fitTo(data, RooFit.Save())

Going further, even this “trick” does not help with a crash when I am trying to fit “combined” dataset with a RooSimultaneous PDF. I will need to prepare a test script to illustrate that…