Minuit2: how change params inside my own fcn

I need to change variable parameters (value, limits) inside my own minuit2 fcn function for each call to fcn.
class MyFcn : public ROOT::Minuit2::FCNBase
{
public:
MyFcn(…) : …;
double operator()( const std::vector& d ) const;
double Up() const ;
private:

};

The create and set initial parametrs values was done through
ROOT::Minuit2::MnUserParameters upar;
upar.Add(…);

ROOT::Minuit2::MnMigrad migrad( myfcn, upar);
ROOT::Minuit2::FunctionMinimum min = migrad();

from Minuit2 manual the body of mymy fcn is the body of
double operator()( const std::vector& d ) const {

how to change the upar values,limits,errors here ???

}

Hi,

I am not sure I understand your use case. The FCN function is called by Minuit and it is evaluated for the parameter values which Minuit decides.
You can change as you preferred the passed value of the parameters in the implementation of
double operator()( const std::vector& d ) const;

The user needs to supply only initial parameter values (and limits and step sizes). If you want to change those you can use MnUserParameterState or MnUserParameters.
You can in principle change the MnUserParameters inside the double operator()( const std::vector& d ) function. You just need to cache a MnUserParameterState in your MyFcn class.
However this will be useless. Minuit will use the user parameters only at the beginning of the minimization.

Best Regards

Lorenzo

Really need to change the limits & errors only - not parameters values.

Hi,

You can probably try to change the values in the MinuitParameter class. The lower/upper value will be probably updated, but the errors is used, I think, only in the first iteration to compute the scale for the gradient

Best Regards

Lorenzo

Thanks, Lorenzo!
I’l check it.

And additional question - why the migrad() call my fcn function one time only?
Each of 15 parameter has valid value,limits & error. May be need set something else?

Hi,
migrad() should call several times your objective function (the fcn). If it doesn’t there is maybe a problem with your code. TO help you, please post a shortest version of your code reproducing this problem

Lorenzo

Hi, Lorenzo!
The problem was in setting parameters.
The wrong way is
upar.add(namepar,value);
upar.SetError(namepar,error);
upar.SetLimits(namepar,leftbound,rightbound);
and when i change it to
upar.Add(namepar,value,error,leftbound,rightbound);
the migrad() work fine - this very strangely for me.
The open question is the moving limits during minimization but for check it need few days.
In any case thank you for help.
Vladimir