Minimizing problem

Hi there,

As a non-expert ROOT user, I am trying to use one of the existing examples to minimize a function (a chi-square function, to be precise).
I took one of the examples called NumericalMinimization which shows the usage with all the possible minimizers with the Rosenbrock function (a 2D -function). I thought i was easy to modify this macro to use any function I want, but it turned out not to be so.
My problem is that I need the function to minimize to be a kind of complicated chi-square function which depends on some other parameters.

double chi2(const double *xx, double *exp1, double *error, double *the1, double *NCb, int r1,double **ntuple, int ns, double dmn31, double sn2th, double integ)

Then, when using either


I thought I should pass all the parameters in chi2(), but an error message is displayed:

Error: Function chi2(obs,err,t1,NC_background,N_BINS,ntuple,NUM_SAMPLES,dmn31,sn2th,int_minos_no_osc) is not defined in current scope  chi2Minim_22Jun11.C:275:
*** Interpreter error recovered ***


Error: Can't call Functor::Functor(&chi2,N_params,obs,err,t1,NC_background,N_BINS,ntuple,NUM_SAMPLES,dmn31,sn2th,int_minos_no_osc) in current scope chi2Minim_22Jun11.C:274: Possible candidates are... Error: class,struct,union or type Functor not defined chi2Minim_22Jun11.C:274: *** Interpreter error recovered *** respectively.

So the point is, how do I pass the necessary parameters to the function I want to minimize (it has N_params = 3 parameters to be “fitted”)?

Thanks in advance.

Mario AAO.

Hi there,

With the help of a friend (and collaborator) of mine I managed to solve the problem, and I thought it could be useful for someone here, so I decided to post it.

So, by using the existing example, I found no way to pass more parameters to the function I wanted to minimize,

double chi2(const double *xx, double *exp1, double *error, double *the1, double *NCb, int r1,double **ntuple, int ns, double dmn31, double sn2th, double integ)
so that the construction

would not work.
I was then suggested to declare all the “extra” parameters (err,t1,NC_background,N_BINS,ntuple,NUM_SAMPLES,dmn31,sn2th,int_minos_no_osc) as global parameters, at the very beginning of my code. It makes the program to run correctly :smiley: .
This might be too naive, but for me it wasn’t :unamused: . Hope it could help someone else.


Mario AAO.


A functor is a function with a state. So you can define all the extra parameters you need as data member of
the function class you are going to use for the minimization.
In the tutorial NumericalMinimization.C a free function is used. The only way to pass extra parameters to a free function is to use global variable.
However you could have defined the function as a calling object as follow:

[ struct RosenBrock { double operator() (const double *xx ) const { const Double_t x = xx[0]; const Double_t y = xx[1]; const Double_t tmp1 = y-x*x; const Double_t tmp2 = 1-x; return 100*tmp1*tmp1+tmp2*tmp2; } };

and set all the extra parameters as data member of that class