MultiDim integrator bug when initializing without function

First of all I want to apologize for posting bug here instead of bug tracking but I do not have a CERN account.

When you create an AdaptiveIntegratorMultiDim without function in constructor then calling of Integral() function will fail saying that dimension is wrong.

This does not work:

AdaptiveIntegratorMultiDim ig;
ig.Integral(fun, xmax, xmin);

This works:

AdaptiveIntegratorMultiDim ig(fun);
ig.Integral(xmax, xmin);

I took a look into AdaptiveIntegratorMultiDim.cxx and seems that function Integral(const IMultiGenFunction &f, const double* xmin, const double * xmax) does not set member variable fDim, it just gets fFun and does integration.

double AdaptiveIntegratorMultiDim::Integral(const IMultiGenFunction &f, const double* xmin, const double * xmax)
{
   // calculate integral passing a function object
   fFun = &f;
   return Integral(xmin, xmax);

}

A quick fix would be to set fDim here

fDim = f.NDim();

But I suggest remove fDim at all and use fFun.NDim() instead. This is not a big perfomance issue but number of dimension will always be correct.

I attached simple macro to reproduce an issue. I tested it with 5.34.12 compiled with Microsoft Visual Studion 2010 (32 bit) on Windows 7. Here’s the usage:

D:\Users\ykish\tmp\ROOT>root -b -l
root [0] .L integratormultidim_bug.C+
...
root [1] DoTest()
Starting working test...
1
Starting NOT working test...
Warning in <ROOT::Math::AdaptiveIntegratorMultiDim::Integral>: Wrong function dimension; n = 0
0
root [2]

integratormultidim_bug.C (994 Bytes)