28#ifndef ROOT_Math_GSLMultiRootSolver
29#define ROOT_Math_GSLMultiRootSolver
31#include "gsl/gsl_vector.h"
32#include "gsl/gsl_matrix.h"
33#include "gsl/gsl_multiroots.h"
34#include "gsl/gsl_blas.h"
71 bool InitSolver(
const std::vector<ROOT::Math::IMultiGenFunction*> & funcVec,
const double *
x) {
74 unsigned int n = funcVec.size();
75 if (
n == 0)
return false;
77 unsigned int ndim = funcVec[0]->NDim();
80 MATH_ERROR_MSGVAL(
"GSLMultiRootSolver::InitSolver",
"Wrong function dimension",ndim);
92 virtual const std::string &
Name()
const = 0;
98 const double *
X()
const {
105 gsl_vector *
f =
GetF();
110 const double *
Dx()
const {
111 gsl_vector * dx =
GetDx();
119 gsl_vector * dx =
GetDx();
120 if (
x == 0 || dx == 0)
return -1;
121 return gsl_multiroot_test_delta(dx,
x, absTol, relTol);
127 gsl_vector *
f =
GetF();
128 if (
f == 0)
return -1;
129 return gsl_multiroot_test_residual(
f, absTol);
137 virtual int SetSolver(
const std::vector<ROOT::Math::IMultiGenFunction*> & funcVec,
const double *
x) = 0;
141 virtual gsl_vector *
GetF()
const = 0;
143 virtual gsl_vector *
GetDx()
const = 0;
175 if (
fVec != 0) gsl_vector_free(
fVec);
190 if (
this == &rhs)
return *
this;
203 fName = std::string(gsl_multiroot_fsolver_name(
fSolver) );
208 virtual int SetSolver(
const std::vector<ROOT::Math::IMultiGenFunction*> & funcVec,
const double *
x) {
212 unsigned int n = funcVec.size();
216 if (
fVec != 0) gsl_vector_free(
fVec);
217 fVec = gsl_vector_alloc(
n);
224 virtual const std::string &
Name()
const {
230 return gsl_multiroot_fsolver_iterate(
fSolver);
236 return gsl_multiroot_fsolver_root(
fSolver);
240 virtual gsl_vector *
GetF()
const {
242 return gsl_multiroot_fsolver_f(
fSolver);
246 virtual gsl_vector *
GetDx()
const {
248 return gsl_multiroot_fsolver_dx(
fSolver);
288 if (
fVec != 0) gsl_vector_free(
fVec);
303 if (
this == &rhs)
return *
this;
323 virtual int SetSolver(
const std::vector<ROOT::Math::IMultiGenFunction*> & funcVec,
const double *
x) {
328 unsigned int n = funcVec.size();
330 for (
unsigned int i = 0; i <
n; ++i) {
333 MATH_ERROR_MSG(
"GSLMultiRootSolver::SetSolver",
"Function does not provide gradient interface");
341 if (
fVec != 0) gsl_vector_free(
fVec);
342 fVec = gsl_vector_alloc(
n);
348 virtual const std::string &
Name()
const {
364 virtual gsl_vector *
GetF()
const {
370 virtual gsl_vector *
GetDx()
const {
#define MATH_ERROR_MSGVAL(loc, txt, x)
#define MATH_ERROR_MSG(loc, str)
GSLMultiRootBaseSolver, internal class for implementing GSL multi-root finders This is the base class...
int TestResidual(double absTol) const
test using abs tolerance Sum |f|_i < absTol
virtual gsl_vector * GetDx() const =0
virtual int SetSolver(const std::vector< ROOT::Math::IMultiGenFunction * > &funcVec, const double *x)=0
virtual gsl_vector * GetRoot() const =0
virtual gsl_vector * GetF() const =0
const double * FVal() const
return function values
const double * X() const
solution values at the current iteration
virtual const std::string & Name() const =0
return name
virtual ~GSLMultiRootBaseSolver()
virtual Destructor
const double * Dx() const
return function steps
bool InitSolver(const std::vector< ROOT::Math::IMultiGenFunction * > &funcVec, const double *x)
init the solver with function list and initial values
virtual int Iterate()=0
perform an iteration
int TestDelta(double absTol, double relTol) const
test using abs and relative tolerance |dx| < absTol + relTol*|x| for every component
wrapper to a multi-dim function with derivatives for multi roots algorithm
gsl_multiroot_function_fdf * GetFunctions()
void SetFunctions(const FuncVector &f, unsigned int n)
Fill gsl function structure from a C++ function iterator and size and number of residuals.
GSLMultiRootDerivSolver, internal class for implementing GSL multi-root finders using derivatives.
gsl_multiroot_fdfsolver * fDerivSolver
virtual const std::string & Name() const
return name
virtual gsl_vector * GetF() const
return function values
virtual int Iterate()
perform an iteration
virtual ~GSLMultiRootDerivSolver()
Destructor (no operations)
virtual gsl_vector * GetRoot() const
solution values at the current iteration
GSLMultiRootDerivSolver & operator=(const GSLMultiRootDerivSolver &rhs)
Assignment operator.
GSLMultiRootDerivSolver(const gsl_multiroot_fdfsolver_type *type, int n)
Constructor.
std::vector< ROOT::Math::IMultiGradFunction * > fGradFuncVec
void CreateSolver(const gsl_multiroot_fdfsolver_type *type, unsigned int n)
create the solver from the type and size of number of fitting points and number of parameters
GSLMultiRootDerivFunctionWrapper fDerivFunctions
virtual gsl_vector * GetDx() const
return function steps
GSLMultiRootDerivSolver(const GSLMultiRootDerivSolver &)
Copy constructor.
virtual int SetSolver(const std::vector< ROOT::Math::IMultiGenFunction * > &funcVec, const double *x)
set the solver parameters for the case of derivative
wrapper to a multi-dim function without derivatives for multi roots algorithm
gsl_multiroot_function * GetFunctions()
void SetFunctions(const FuncVector &f, unsigned int n)
Fill gsl function structure from a C++ function iterator and size and number of residuals.
GSLMultiRootSolver, internal class for implementing GSL multi-root finders not using derivatives.
virtual gsl_vector * GetF() const
return function values
virtual gsl_vector * GetRoot() const
solution values at the current iteration
virtual ~GSLMultiRootSolver()
Destructor (no operations)
void CreateSolver(const gsl_multiroot_fsolver_type *type, unsigned int n)
GSLMultiRootFunctionWrapper fFunctions
gsl_multiroot_fsolver * fSolver
GSLMultiRootSolver(const gsl_multiroot_fsolver_type *type, int n)
Constructor from type and simension of system (number of functions)
virtual int SetSolver(const std::vector< ROOT::Math::IMultiGenFunction * > &funcVec, const double *x)
set the solver parameters
virtual const std::string & Name() const
return name
virtual int Iterate()
perform an iteration
GSLMultiRootSolver & operator=(const GSLMultiRootSolver &rhs)
Assignment operator.
virtual gsl_vector * GetDx() const
return function steps
GSLMultiRootSolver(const GSLMultiRootSolver &)
Copy constructor.
Interface (abstract class) for multi-dimensional functions providing a gradient calculation.
Namespace for new Math classes and functions.
Namespace for new ROOT classes and functions.