Re: Using Minuit in ROOT without global variables

From: Lorenzo Moneta <Lorenzo.Moneta_at_cern.ch>
Date: Tue, 12 Jul 2011 10:46:41 +0000


Hi,

 If you are using TMInuit you need to pass the function to be minimized as a free global function, so all the extra data needed in the function must be global. You can however use the new C++ version of Minuit, Minuit2 which has an OO interface, where your function to be minimized can be an object implementing a well defined interface. The best way to use Minuit2 (and also TMinuit) is by using the ROOT::Math::Minimizer interface. In this case the library will be loaded automatically via the plug-in manager, you can use the same code for both algorithms and in the case of TMinuit the problems with the global is also hided from the user (it is done internally and you can pass an object a s a function).

An example to use this interface for Minuit and Minuit2 is the tutorial NumericalMinimization.C, see

 http://root.cern.ch/root/html/tutorials/fit/NumericalMinimization.C.html

and see also
http://root.cern.ch/drupal/content/numerical-minimization#multidim_minim

and
http://root.cern.ch/drupal/content/how-implement-mathematical-function-inside-framework

to see how to pass a function object.
Also these post could be useful:

http://root.cern.ch/phpBB3//viewtopic.php?f=15&t=12972&p=55781&hilit=NUmericalMinimization#p55915 http://root.cern.ch/phpBB3//viewtopic.php?f=15&t=12649&p=54581&hilit=NUmericalMinimization#p54581

Best Regards

 Lorenzo
On Jul 12, 2011, at 11:26 AM, Hermann Fuchs wrote:

> Hello
>
> I am trying to use TMinuit in order to optimize some functions.
> It seems there is no real tutorial using TMinuit (I found plenty of code
> for the old standalone Minuit,though).
>
> It seems to me, in order to calculate chisquare or simply a difference
> between the optimized function and a reference function, the reference
> data has to be in a global variable.
> Is there a way around that?
>
> The Minuit optimization is only a very small part of my program so I
> would like to avoid having a lot of data in global variables.
> I have attached my current source file to provide a basis for the
> discussion.
>
> Cheers,
> Hermann
>
> --
> -------------
> DI Hermann Fuchs
> Div. Medical Radiation Physics
> Department of Radiotherapy
> Med. Univ. Vienna / AKH Vienna
> Währinger Gürtel 18-20
> A-1090 Wien
>
> Tel. + 43 / 1 / 40 400 7271
> Mail. hermann.fuchs_at_meduniwien.ac.at
> <tosend.cpp>
Received on Tue Jul 12 2011 - 12:46:53 CEST

This archive was generated by hypermail 2.2.0 : Wed Jul 13 2011 - 11:50:02 CEST