Skip to content

Commit 669bcf0

Browse files
committed
[minuit2] Consider case when variable parameters=0
In this case we cdon;t need to start creating a seed and a Variable Metric Builder. Just return a result containing only the function value
1 parent 762d81e commit 669bcf0

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

math/minuit2/inc/Minuit2/MinimumParameters.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,23 @@ namespace Minuit2 {
2121
class MinimumParameters {
2222

2323
public:
24+
25+
enum Status {
26+
MnValid,
27+
MnInvalid
28+
};
29+
2430
MinimumParameters(unsigned int n, double fval = 0)
2531
: fPtr{new Data{MnAlgebraicVector(n), MnAlgebraicVector(n), fval, false, false}}
2632
{
2733
}
2834

35+
// constructor for case when function has no parameter and only function value
36+
MinimumParameters(double fval, Status status)
37+
: fPtr{ new Data{MnAlgebraicVector(0), MnAlgebraicVector(0), fval, status == MnValid, false}}
38+
{}
39+
40+
2941
/** takes the Parameter vector */
3042
MinimumParameters(const MnAlgebraicVector &avec, double fval)
3143
: fPtr{new Data{avec, MnAlgebraicVector(avec.size()), fval, true, false}}

math/minuit2/src/MnApplication.cxx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,18 @@ FunctionMinimum MnApplication::operator()(unsigned int maxfcn, double toler)
3737

3838
const FCNBase &fcn = Fcnbase();
3939

40+
41+
if (npar == 0) {
42+
double fval = fcn(fState.Params());
43+
print.Info("Function has zero parameters - returning current function value - ",fval);
44+
// create a valid Minuit-Parameter objects with just the function value
45+
MinimumParameters mparams(fval,MinimumParameters::MnValid);
46+
MinimumState mstate(mparams, 0., 1 );
47+
return FunctionMinimum( MinimumSeed(mstate, fState.Trafo()), fcn.Up());
48+
}
49+
4050
FunctionMinimum min = Minimizer().Minimize(fcn, fState, fStrategy, maxfcn, toler);
51+
4152
fNumCall += min.NFcn();
4253
fState = min.UserState();
4354

0 commit comments

Comments
 (0)