# Math::IntegratorMultiDims

**URL:** <https://root-forum.cern.ch/t/math-integratormultidims/53265>\
**Category:** Newbie\
**Created:** [January 25, 2023, 10:26am UTC](https://root-forum.cern.ch/t/math-integratormultidims/53265 "2023-01-25T10:26:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cas](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/c/77aa72/32.png) [@Cas](https://root-forum.cern.ch/u/Cas)\
**Post date:** [January 25, 2023, 10:26am UTC](https://root-forum.cern.ch/t/math-integratormultidims/53265/1 "2023-01-25T10:26:59Z")

</div>

Dear all,

I want to use ROOT::Math::IntegratorMultiDims to integrate a 2D function, and then in specific with vegas.  
There are some things that I am trying to understand, but fail to do so.  
My testing code looks like this:

```auto
#include "Math/IntegratorMultiDim.h"
#include "Math/Functor.h"

double f2(const double * x) {
   return x[0] + x[1];
}

int integralTest() {

   const double RESULT = 1.0;
   const double ERRORLIMIT = 1E-3;
   int status = 0;

   ROOT::Math::Functor wf(&f2,2);
   double a[2] = {0,0};
   double b[2] = {1,1};

   ROOT::Math::IntegratorMultiDimOptions opt2;
   opt2.SetIntegrator("VEGAS");
   opt2.SetDefaultNCalls(200000);
   opt2.Print();
   std::cout << "Extra options: " << opt2.ExtraOptions() << std::endl;
   ROOT::Math::IntegratorMultiDim ig2(ROOT::Math::IntegrationMultiDim::kVEGAS);
   std::cout << ig2.Name() << std::endl;

   ig2.Options().Print();
   // ig2.SetOptions(opt2);
   ig2.Options().Print();
   ig2.SetFunction(wf);
   double val = ig2.Integral(a,b);
   std::cout << "VEGAS: integral result is " << val << std::endl;
   status += std::fabs(val-RESULT) > ERRORLIMIT;

   return status;
}

```

The default settings for the integrator are  
Integrator Type : VEGAS  
Absolute tolerance : 0  
Relative tolerance : 1e-09  
Workspace size : 100000  
(max) function calls : 100000

And when I change the DefaultNCalls of the options, this works fine. This then also shows up when I request ig2.Options().Print() from the integrator. However, when I try to load it the options with ig2.SetOptions(opt2), then it reverts back to the default settings. Does anyone know why that is?

Then ig2.Options().Print(); also shows VEGAS specific options, being  
VEGAS specific options :  
iterations : 5  
mode : 1  
stage : 0  
verbose : -1  
alpha : 1.5  
By default.  
How do I change my integrator specific options? I thought I would have to do opt2.ExtraOptions()-\>Print(), but opt.ExtraOptions() returns a null pointer.

Any help would be appreciated.

Cheers,  
Cas

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [January 25, 2023, 11:22am UTC](https://root-forum.cern.ch/t/math-integratormultidims/53265/2 "2023-01-25T11:22:56Z")

</div>

I think @moneta can help
