Math Libraries
MathCore
MathCore includes now classes which were previously contained in libCore, like TMath, TComplex and the TRandom classes. Furthermore, some of the algorithms implemented in the TF1 class have been moved to MathCore. This implies that all other ROOT library using one of these classes, such as libHist, have a direct dependency on the Mathcore library.
Linking with libMathCore is therefore required for running any major ROOT application. It has been added to the list of libraries obtained when doing root-config --libs.
N.B.: users building ROOT applications and not using root-config MUST add libMathCore to their list of linking libraries.
Together with the libraries merge, many changes have been applied to both TMath and the other mathcore classes.
TMath
A major clean-up and re-structuring has been done for the functions present in TMath. Some functions have been implemented using the STL algorithms, which have better performances in term of CPU time and a template interface has been also added.
Some of the basic special mathematical functions of TMath, like the error function or the gamma and beta functions use now the Cephes implementation from Stephen L. Moshier, which is used as well by the ROOT::Math functions. This implementation has been found to be more accurate and in some cases more efficient in term of CPU time. More detailed information on the new mathematical functions can be found in this presentation from M. Slawinska at a ROOT team meeting.
- define the functions as template functions instead of having the same re-definition for all the various basic types. This is done for TMath::Mean,TMath::GeomMean, TMath::Median, TMath::KOrdStat
- Use STL to implement the following algorithms:
- TMath::Sort is re-implemented using std::sort.
- TMath::BinarySearch is re-implemented using the STL algorithm std::lower_bound
The STL algorithms have been found for these cases to be perform better in term of CPU time. For some other algorithms like TMath::LocMin, TMath::LocMax or TMath::Permute the original implementation is faster than STL and has been maintained.
- Add a generic iterator interface, similar to the STL algorithm interface, to the following TMath functions:
MinElement, MaxElemen, LocMin, LocMax, Mean, GeomMean, RMS,
BinarySearch. The iterator interface for sort is called
TMath::SortItr to avoid a compilation ambiguity. For example,
for finding the mean of a std::vector<double> v, one simply needs to call TMath::Mean(v.begin(), v.end() ) .
- Various changes have been applied to the mathematical functions to remove duplications in the implementation with the special and statistical functions defined in ROOT::Math. The functions which have been changed and thus they can return a sightly different result than before are:
- TMath::Erf and TMath::Erfc call ROOT::Math::erf and ROOT::math::erfc which are implemented using the Cephes algorithms, which is accurate at the required double precision level.
- TMath::Gamma(z) is implemented with ROOT::Math::tgamma, which again uses Cephes.
- The incomplete gamma function, TMath::Gamma(a,x) it is implemented using ROOT::Math::inc_gamma based on a corresponding Cephes function.
- TMath::Prob (the upper chi2 probability) is implemented also using ROOT::Math::chisquared_cdf_c which uses ROOT::Math::inc_gamma_c based on a corresponding Cephes function. Now the implementation does not suffer anymore from large numerical error present when the result of TMath::Prob was approaching zero.
- TMath::LnGamma(z) is implemented using ROOT::Math::lgamma. This affects also TMath::Beta which is implemented using the log of the gamma function.
- TMath::BetaIncomplete is implemented using ROOT::Math::beta_inc.
- TMath::GammaDist is implemented using ROOT::Math::gamma_pdf.
- TMath::LogNormal is implemented using ROOT::Math::lognormal_pdf.
- TMath::PoissonI: fixed a problem for large values and is implemented using directly TMath::Poisson with integer values.
Fit
Mathcore include now new classes for performing fits and minimization of multi-dimensional functions. The aim of these classes is to extend and improve the fitting functionality provided in ROOT via the TVirtualFitter classes and the fitting methods present in many data analysis object, such as TH1::Fit.
The fit data are decoupled from the fitter class and described by the dedicated fit data classes like the ROOT::Fit::BinData for bin data containing coordinate values of any dimensions, bin content values and optionally errors in coordinate and bin content, and ROOT::Fit::UnBinData classes for any dimension un-bin data.
The fitter class, ROOT::Fit::Fitter, provides the functionality for fitting those data with any model function implementing the parametric function interface, ROOT::Math::IParamMultiFunction. Fit methods such as least square, bin and un-bin likelihood are supported. The fit solution is then found by using the ROOT::Math::Minimizer interface class and the results are stored in the ROOT::Fit::FitResult class. Fit parameter can be configured individually using the ROOT::Fit::FitParameterSettings class.
Various implementation of the minimizer interface can be used automatically using the ROOT plug-in manager mechanism, including the linear fitter for a fast and direct solution, in case of a linear least square model, or by using Minuit, Minuit2 or GSL minimization methods provided by the MathMore library.
Functions for filling the new ROOT::Fit::BinData classes with all the histogram and graph types have been added in the histogram library (libHist) and graph library:
- ROOT::Fit::FillData( BinData & , const TH1 *, TF1 * ) for histograms (in libHist)
- ROOT::Fit::FillData( BinData & , const TGraph2D *, TF1 * ) for 2D graphs (in libHist)
- ROOT::Fit::FillData( BinData & , const TGraph *, TF1 * ) for all 1D graphs (in libGraf)
- ROOT::Fit::FillData( BinData & , const TMultiGraph *, TF1 * ) for multi-graphs (in libGraf)
MathCore Numerical Algorithms
Classes implementing numerical methods which can be used by all the other ROOT library have been added in MathCore. These originate mainly from methods present previously in the implementation of the TF1 class. Now they can be used also outside this class. In addition, in order to have a common entry point, interfaces classes for these numerical algorithms have been
included.
These interfaces are as well implemented by classes using the GSL library and located in the MathMore library. The library can be loaded automatically using the ROOT plug-in manager.
In detail, the new classes containing implementations present previously in TF1 are:
- GaussIntegrator and GaussLegendreIntegrator for numerical integration of one-dimensional functions. The first class uses Gaussian 8 and 16 point quadrature approximation, it provides the translation of the CERNLIB algorithm
DGAUSS by Sigfried Kolbig, and it is used by the TF1::Integral method. The second one uses the Gauss Legendre quadrature formula. It is used by the TF1::IntegralFast method.
These classes implement both the same virtual interface as the adaptive integration methods provided by the MathMore library. They can all be created and used easily via the common class ROOT::Math::IntegratorOneDim providing the interfaces for numerical integration.
New template methods have been also included in the common Integration class in order to be able to integrate automatically any C++ callable object.
- ROOT::Math::RichardsonDerivator implementing numerical derivation using the Richardson's extrapolation formula (use 2 derivative estimates to compute a third, more accurate estimation). This is used by the TD1::Derivative method.
- BrentRootFinder for finding the root of one-dimensional function using the Brent algorithm. The class inherits from a virtual interface, which is also implemented by the MathMore root finder methods. The user can instantiate, via the common ROOT::Math::RootFinder class, all the various root finder algorithms. The BrentRootFinder class is used by TF1::GetX .
- A similar class, BrentMinimizer1D, provides the possibility to find the minimum of one-dimensional functions using the Brent algorithm. This class is used by TF1::GetMinimum or TF1::GetMaximum
Use ROOT convention for all enumeration names defining the type of numerical algorithms (start with k, like kADAPTIVE for the integration type). This affects both MathCore and MathMore.
In addition we use now the ROOT convention for all enumeration names defining the type of numerical algorithms. The names start with k, like kADAPTIVE for the integration type. This change affects both MathCore and MathMore and it breaks backward compatibility.
MathCore Function interfaces
Mathcore provides as well interfaces for the evaluation of mathematical and parametric functions to be used in the the numerical methods. This release contains the following changes:
- The ROOT::Math::IParamFunction, ROOT::Math::IParamMultiFunction interfaces (used mainly for fitting) require now a pointer to the parameters (type const double *), when evaluating the function. The derived classes must implement now the const
method DoEvalPar (and not DoEval as before). In addition the method
operator()(const double * x, const double * p) is now const. This change makes the caching of parameter not hidden and the interface is now
thread-safe.
- A similar change in the ROOT::Math::IParamGradFunction, ROOT::Math::IParamMultiGradFunction interfaces, where the parameter values are now required for calculating the partial derivatives with respect to the parameters.
This changes the signature of the pure abstract method, DoParameterDerivative(const double *x, const double * p, , which takes also a pointer (type const double *) to the parameters.
In addition, these classes do not inherit anymore from the function gradient interface (ROOT::Math::IGradFunction and ROOT::Math::IMultiGradFunction). They define only the parameter gradient which is needed for fitting and not the coordinate gradient. A derived class, like ROOT::Math::Polynomial, implementing both functionality (coordinate and parameter gradient) inherits then from both interfaces.
-
More detailed description of the current MathCore release can be found at this location.
MathMore
This new release contains:
- Modify and rename the class ROOT::Math::RootFinder to ROOT::Math::GSLRootFinder to distinguish from the main interface class which has been put in the Mathcore library and it can create the GSLRootFinder using the plug-in manager. Furthermore, the class ROOT::Math::GSLRootFinder is not anymore a template class on the algorithm. They type of root-finder algorithm can now be selected via an enumeration
- Fixed a bug in the ROOT::Math::GSLNLSMutiFi class.
- Changes also in the class for the new enumeration names (all names start with k, like kADAPTIVE for the integration types).
More detailed description of the current MathMore release can be found at this location.
GenVector
The new physics vector classes have been moved out from the MathCore library in a new library, libGenVector. The library contains as well the CINT dictionary including main instantiations for the template classes. For this release the instantiation of some extra methods, in particular of the class ROOT::Math::TRansform3D have been added in the dictionary library.
Due to a CINT limitation, the dictionary for explicit template constructors of the Rotation classes, taking as input any other type
of rotation are missing. Therefore code like the following one will now work in CINT (or Python):
ROOT::Math::Rotation3D r;
ROOT::Math::EulerAngles eulerRot(r);
A possible solution is to use the operator=:
ROOT::Math::EulerAngles eulerRot; eulerRot = r;
In addition the setter methods for the 2D,3D and 4D vector classes have been extended following a suggestion by G. Raven. Functions like SetX instead of returning a void return now a reference to the vector class itself (*this).
Detailed description of the current GenVector release can be found at this location.
SMatrix
Fix a bug discovered by Harals Soleng in the addition of two matrix expressions. Remove also some compilation warning found on Windows when compiling matrices instantiated using float types.
Detailed description of the current SMatrix release can be found at this location.
Minuit
Two new classes have been added:
- TMinuitMinimizer: implementation of the ROOT::Math::Minimizer interface with TMinuit. This class is used for example by the new Fitter class.
- TLinearMinimizer: implementation of the ROOT::Math::Minimizer interface with the TLinearFitter.
In addition, the method TLinearFitter::SetBasisFunction(TObjArray * f) has been added to set directly the linear terms of the fit function.
Minuit2
Various fixes have been applied to different problems discovered mainly by a test program from Alfio Lazzaro. In detail:
-
Fix a bug in MnMinos which was setting wrong initial values when the parameters were limited.
This was resulting in a much larger number of function calls used inside MnMinos.
- Improve MnHesse by returning in the final state the improved gradient step values used in HessianGradientCalculator. With this change same results are obtained from using Hesse in Minuit2 or TMinuit. In addition, the interface of MnHesse (MnHesse::operator() ) has been improved to use it from the FunctionMinimum object (similar to MnMinos) in order to be called after the minimization (Migrad). The API with a MnUserParameterState should not be used after minimization, because in that case the latest state information resulting from the minimum (gradient values and step sizes) is lost.
- Add support in MnMigrad and MnMinimize for user provided analytical gradient of the FCN function. One needs to pass an instance of a function implementing the ROOT::Minuit2::FcnGradientBase interface.
- Use now std::string for storing parameter names. This removes the un-necessary limitation on the length of parameter name (10 characters) existing before. The method Name() of MinuitParameter (and of MnUserParameterState and MnUserParameters) still returns a const char * (for backward compatibility). A new method, GetName() has been added to return a std::string
-
The Minuit2Minimizer class has been improved by having an option to always run Hesse if it was not done before during the minimization. Method to retrieve the correlation coefficients have been also added.
More detailed description of the current Minuit2 release can be found at this location.
Unuran
A new version, 1.2.4, has been added to fix mainly some problems found in gcc 4.3. For the detailed changes of this new UNU.RAN version see the file $ROOTSYS/math/unuran/src/unuran-1.2.4-root/NEWS.
Last modified: Tue Jun 24 17:22:42 CEST 2008