# MnHesse on Minuit2 standalone: too many arguments

**URL:** <https://root-forum.cern.ch/t/mnhesse-on-minuit2-standalone-too-many-arguments/40668>\
**Category:** Newbie\
**Created:** [July 27, 2020, 10:41am UTC](https://root-forum.cern.ch/t/mnhesse-on-minuit2-standalone-too-many-arguments/40668 "2020-07-27T10:41:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rdat](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/r/cab0a1/32.png) [@Rdat](https://root-forum.cern.ch/u/Rdat)\
**Post date:** [July 27, 2020, 10:41am UTC](https://root-forum.cern.ch/t/mnhesse-on-minuit2-standalone-too-many-arguments/40668/1 "2020-07-27T10:41:24Z")

</div>

I am using MINUIT 5.34.14 standalone version (downloaded from [http://seal.web.cern.ch/seal/snapshot/work-packages/mathlibs/minuit/](http://seal.web.cern.ch/seal/snapshot/work-packages/mathlibs/minuit/)) on Ubuntu 20.04 on WSL.

I am trying to use the MnHesse class to estimate the covariance matrix of my fit, since MIGRAD alone sometimes provides negative variances. The fit itself goes smoothly and MIGRAD converges. However, no matter the syntax I use, MnHesse gives me a “too many arguments” error at compiling time. Of course, when I state that the program runs smoothly I mean without the call to MnHess. Here is the relevant code:

```auto
ROOT::Minuit2::MnUserParameters params;
params.Add("energy", initEn, initEnErr);
params.Add("pos", initPos, initPosErr);
params.Add("sigma", initSigma, initSigmaErr);
params.Add("pitch", anodePitch, 0);

FitFunc fitFunc(dataOn, anodesOn, datavarOn); //FitFunc is the fitting function class that requires, x, y and sigma^2(y). It is a class derived from ROOT::Minuit2::FCNBase
ROOT::Minuit2::MnMigrad migrad(fitFunc, params);
migrad.Fix("pitch");
ROOT::Minuit2::FunctionMinimum fmin = migrad();

ROOT::Minuit2::MnHesse hesse();
hesse(fitFunc, fmin);
// I have also attempted the following, in alternative to the previous line:
// fmin.UserState() = hesse(fitFunc, fmin.UserParameters());
// but the error is still there

```

To be clear, I checked the header of MnHesse and it seems to me that my attempts should work. Here is also the MnHesse operators I can finde in Minuit2/MnHesse.h:

```auto
   ///
   /// low-level API
   ///
   /// FCN + parameters + errors
   MnUserParameterState operator()(const FCNBase&, const std::vector<double>&, const std::vector<double>&, unsigned int maxcalls=0) const;
   /// FCN + parameters + covariance
   MnUserParameterState operator()(const FCNBase&, const std::vector<double>&, unsigned int nrow, const std::vector<double>&, unsigned int maxcalls = 0) const;
   /// FCN + parameters + MnUserCovariance
   MnUserParameterState operator()(const FCNBase&, const std::vector<double>&, const MnUserCovariance&, unsigned int maxcalls=0) const;
   ///
   /// high-level API
   ///
   /// FCN + MnUserParameters
   MnUserParameterState operator()(const FCNBase&, const MnUserParameters&, unsigned int maxcalls=0) const;
   /// FCN + MnUserParameters + MnUserCovariance
   MnUserParameterState operator()(const FCNBase&, const MnUserParameters&, const MnUserCovariance&, unsigned int maxcalls=0) const;
   /// FCN + MnUserParameterState
   MnUserParameterState operator()(const FCNBase&, const MnUserParameterState&, unsigned int maxcalls=0) const;
   /// 
   /// API to use MnHesse after minimization when function mimimum is avalilable, otherwise information on the last state will be 
   /// lost. (It would be needed to re-call the gradient and spend extra useless function calls) 
   /// The Function Minimum is updated (modified) by adding the Hesse results as last state of minimization
   ///
   void operator()(const FCNBase&, FunctionMinimum&, unsigned int maxcalls=0) const;
   

   /// internal interface
   ///
   MinimumState operator()(const MnFcn&, const MinimumState&, const MnUserTransformation&, unsigned int maxcalls=0) const;

```

Any insights on what I am doing wrong?

\_ROOT Version: MINUIT 5.34.14 standalone  
\_Platform: Ubuntu 20.04 on WSL  
\_Compiler: gcc (Ubuntu 9.3.0-10ubuntu2) 9.3.0

* * *

---

<div class="post-metadata">

**Author:** ![eguiraud](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/eguiraud/32/32217_2.png) [@eguiraud](https://root-forum.cern.ch/u/eguiraud)\
**Post date:** [July 28, 2020, 10:50am UTC](https://root-forum.cern.ch/t/mnhesse-on-minuit2-standalone-too-many-arguments/40668/2 "2020-07-28T10:50:57Z")

</div>

Hi @Rdat,  
sorry for the high latency! This question is really for @moneta but he is currently off.  
Please ping us again in two weeks if you don’t hear anything before then!

Cheers,  
Enrico

---

<div class="post-metadata">

**Author:** ![moneta](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/moneta/32/19423_2.png) [@moneta](https://root-forum.cern.ch/u/moneta)\
**Post date:** [August 11, 2020, 8:46am UTC](https://root-forum.cern.ch/t/mnhesse-on-minuit2-standalone-too-many-arguments/40668/3 "2020-08-11T08:46:14Z")

</div>

Hi,

Can you please attach your code and the compilation error. At first sight , it seems correct, you should use after minimization this interface of MnHesse,  
[https://root.cern.ch/doc/master/classROOT\_1\_1Minuit2\_1\_1MnHesse.html#a3b6ba68a41260029bc6bde433170e600](https://root.cern.ch/doc/master/classROOT_1_1Minuit2_1_1MnHesse.html#a3b6ba68a41260029bc6bde433170e600)

In general, I think it is easier to use the Minuit2Minimizer interface, where internally you can call Migrad and Hesse.  
You can see also from its implementation how you should call MnHesse,  
[https://root.cern.ch/doc/master/Minuit2Minimizer\_8cxx\_source.html#l01116](https://root.cern.ch/doc/master/Minuit2Minimizer_8cxx_source.html#l01116)

If you need an example on how to use the Minuit2Minimizer, you can see this ROOT tutorial,  
[https://root.cern.ch/doc/master/NumericalMinimization\_8C.html](https://root.cern.ch/doc/master/NumericalMinimization_8C.html)

If you having the standaonle Minuit version, you need just to create directly the Minuit2Minimizer class instead of using the Factory class, i.e. replace the line

```auto
 ROOT::Math::Minimizer* minimum = ROOT::Math::Factory::CreateMinimizer(minName, algoName);

```

with

```auto
 ROOT::Math::Minimizer* minimum = new ROOT::Minuit2::Minuit2Minimizer(algoName);

```

Lorenzo
