Number of parameters in the pyrootRooFit will affect the speed of fitting?

Dear ROOTExperts,

I encountered a problem when I using pyroot.

The time consumed by RooFit varies greatly for C++RooFit and pyROOTRooFit.

There are 10 parameters in my models. When I fit the data using C++, the fit result will come out rapidly(minutes). But when I use pyroot to fit data, it consumes a lots of time(hours). While I cancel the Gaussian convolution, the speed of Roofit using pyroot get normal! Strange!

What can I do to speed up the process of rootfit using pyroot?

sigshape = ROOT.RooHistPdf("sigshape", "", RooArgSet(mBC), hshape)
mean1  = RooRealVar("mean1", "", -0.005, 0.005)
mean2  = RooRealVar("mean2", "", -0.003, 0.003)
sigma1 = RooRealVar("sigma1", "", 0., 0.001)
sigma2 = RooRealVar("sigma2", "", 0., 0.001)
frac1  = RooRealVar("frac1","", 0.96, 0.0, 1.0)
endpt  = RooRealVar("endpt","", 1.8865)
kappa  = RooRealVar("kappa","", -25, -40., 0.)
arg2   = RooRealVar("arg2", "", 0.8, 0.,  1.)
Nsig   = RooRealVar("Nsig","", 8.2e+5, 0.0, sum_data)
Nbkg   = RooRealVar("Nbkg","", 1.4e+5, 0.0, sum_data)

gauss1 = ROOT.RooGaussian("gauss1", "", mBC, mean1, sigma1 )
gauss2 = ROOT.RooGaussian("gauss2", "", mBC, mean2, sigma2 )
list1  = ROOT.RooArgList(gauss1, gauss2)
gauss  = ROOT.RooAddModel("gauss","", RooArgList(gauss1, gauss2), RooArgList(frac1))
sigpdf = ROOT.RooFFTConvPdf("sigpdf", "", mBC, sigshape, gauss)
bkg    = ROOT.RooArgusBG("bkg","", mBC, endpt, kappa, arg2)
model  = ROOT.RooAddPdf("model", "", RooArgList(sigpdf,bkg), RooArgList(Nsig,Nbkg))

The re should don’t be visible differences from using ROOFIT from PyROOT or directly in C++, since all the computation is done in C++.
If you have a large difference is due to some problematic issue in your code. You should then share your full code and input data/workspace to reproduce it


1 Like

Dear moneta,
I found the real problem lies in the root version.
The C++ code run fast in C++ root version.
but the pyroot code run slowly in pyroot version. Quite strange like Doc. Strange.
the version of pyroot I use is


This problem is solved!
I replace

gauss  = ROOT.RooAddModel("gauss","", RooArgList(gauss1, gauss2), RooArgList(frac1))


gauss  = ROOT.RooAddPdf("gauss","", RooArgList(gauss1, gauss2), RooArgList(frac1))

It works!

RoAddModel is a derived class of ROoResolutionModel and should be used incase of analytical convolutions, not with FFT as in your case.
But the same problem should be seen in both C++ and Python

1 Like

Thanks for your nice reply! :wink:

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