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 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;
   139    virtual gsl_vector * 
GetRoot() 
const = 0;
   141    virtual gsl_vector * 
GetF() 
const = 0;
   143    virtual gsl_vector * 
GetDx() 
const = 0;
   166       CreateSolver(type, n);
   173       if (fSolver) gsl_multiroot_fsolver_free(fSolver);
   174       if (fVec != 0) gsl_vector_free(fVec);
   189       if (
this == &rhs) 
return *
this;  
   200       if (fSolver) gsl_multiroot_fsolver_free(fSolver);
   201       fSolver = gsl_multiroot_fsolver_alloc(type, n);
   207    virtual int SetSolver(
const std::vector<ROOT::Math::IMultiGenFunction*> & funcVec, 
const double * 
x) {
   211       unsigned int n = funcVec.size();
   213       fFunctions.SetFunctions(funcVec, funcVec.size() );
   215       if (fVec != 0) gsl_vector_free(fVec);
   216       fVec = gsl_vector_alloc( n);
   217       std::copy(x,x+n, fVec->data);
   219       assert(fSolver != 0);
   220       return gsl_multiroot_fsolver_set(fSolver, fFunctions.GetFunctions(), fVec);
   223    virtual std::string 
Name()
 const {
   224       if (fSolver == 0 ) 
return "undefined";
   225       return std::string(gsl_multiroot_fsolver_name(fSolver) );
   229       if (fSolver == 0) 
return -1;
   230       return gsl_multiroot_fsolver_iterate(fSolver);
   235       if (fSolver == 0) 
return 0;
   236       return  gsl_multiroot_fsolver_root(fSolver);
   240    virtual gsl_vector * 
GetF()
 const {
   241       if (fSolver == 0) 
return 0;
   242       return  gsl_multiroot_fsolver_f(fSolver);
   246    virtual gsl_vector * 
GetDx()
 const {
   247       if (fSolver == 0) 
return 0;
   248       return gsl_multiroot_fsolver_dx(fSolver);
   278       CreateSolver(type, n);
   285       if (fDerivSolver) gsl_multiroot_fdfsolver_free(fDerivSolver);
   286       if (fVec != 0) gsl_vector_free(fVec);
   301       if (
this == &rhs) 
return *
this;  
   313       if (fDerivSolver) gsl_multiroot_fdfsolver_free(fDerivSolver);
   314       fDerivSolver = gsl_multiroot_fdfsolver_alloc(type, n);
   320    virtual int SetSolver(
const std::vector<ROOT::Math::IMultiGenFunction*> & funcVec, 
const double * 
x) {
   324       assert(fDerivSolver !=0);
   325       unsigned int n = funcVec.size();
   326       fGradFuncVec.reserve( n );
   327       for (
unsigned int i = 0; i < 
n; ++i) {
   330             MATH_ERROR_MSG(
"GSLMultiRootSolver::SetSolver",
"Function does not provide gradient interface");
   333          fGradFuncVec.push_back( func);
   336       fDerivFunctions.SetFunctions(fGradFuncVec, funcVec.size() );
   338       if (fVec != 0) gsl_vector_free(fVec);
   339       fVec = gsl_vector_alloc( n);
   340       std::copy(x,x+n, fVec->data);
   342       return gsl_multiroot_fdfsolver_set(fDerivSolver, fDerivFunctions.GetFunctions(), fVec);
   345    virtual std::string 
Name()
 const {
   346       if (fDerivSolver == 0 ) 
return "undefined";
   347       return std::string(gsl_multiroot_fdfsolver_name(fDerivSolver) );
   351       if (fDerivSolver == 0) 
return -1;
   352       return gsl_multiroot_fdfsolver_iterate(fDerivSolver);
   357       if (fDerivSolver == 0) 
return 0;
   358       return gsl_multiroot_fdfsolver_root(fDerivSolver);
   362    virtual gsl_vector * 
GetF()
 const {
   363       if (fDerivSolver == 0) 
return 0;
   364       return  gsl_multiroot_fdfsolver_f(fDerivSolver);
   368    virtual gsl_vector * 
GetDx()
 const {
   369       if (fDerivSolver == 0) 
return 0;
   370       return  gsl_multiroot_fdfsolver_dx(fDerivSolver);
 Interface (abstract class) for multi-dimensional functions providing a gradient calculation. 
 
This namespace contains pre-defined functions to be used in conjuction with TExecutor::Map and TExecu...
 
virtual std::string Name() const
return name 
 
GSLMultiRootBaseSolver, internal class for implementing GSL multi-root finders This is the base class...
 
virtual gsl_vector * GetRoot() const
solution values at the current iteration 
 
GSLMultiRootSolver(const GSLMultiRootSolver &)
Copy constructor. 
 
virtual gsl_vector * GetRoot() const
solution values at the current iteration 
 
virtual int SetSolver(const std::vector< ROOT::Math::IMultiGenFunction *> &funcVec, const double *x)=0
 
GSLMultiRootDerivSolver(const GSLMultiRootDerivSolver &)
Copy constructor. 
 
gsl_multiroot_fsolver * fSolver
 
GSLMultiRootDerivSolver(const gsl_multiroot_fdfsolver_type *type, int n)
Constructor. 
 
std::vector< ROOT::Math::IMultiGradFunction * > fGradFuncVec
 
int TestResidual(double absTol) const
test using abs tolerance Sum |f|_i < absTol 
 
#define MATH_ERROR_MSGVAL(loc, str, x)
 
virtual ~GSLMultiRootSolver()
Destructor (no operations) 
 
virtual gsl_vector * GetDx() const =0
 
bool InitSolver(const std::vector< ROOT::Math::IMultiGenFunction *> &funcVec, const double *x)
init the solver with function list and initial values 
 
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 without derivatives for multi roots algorithm 
 
virtual ~GSLMultiRootBaseSolver()
virtual Destructor 
 
const double * FVal() const
return function values 
 
virtual int Iterate()=0
perform an iteration 
 
virtual gsl_vector * GetRoot() const =0
 
virtual ~GSLMultiRootDerivSolver()
Destructor (no operations) 
 
virtual std::string Name() const
return name 
 
#define MATH_ERROR_MSG(loc, str)
 
virtual gsl_vector * GetF() const
return function values 
 
virtual int Iterate()
perform an iteration 
 
const double * Dx() const
return function steps 
 
virtual gsl_vector * GetF() const
return function values 
 
GSLMultiRootSolver, internal class for implementing GSL multi-root finders not using derivatives...
 
virtual int SetSolver(const std::vector< ROOT::Math::IMultiGenFunction *> &funcVec, const double *x)
set the solver parameters for the case of derivative 
 
virtual int SetSolver(const std::vector< ROOT::Math::IMultiGenFunction *> &funcVec, const double *x)
set the solver parameters 
 
GSLMultiRootFunctionWrapper fFunctions
 
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 ...
 
virtual gsl_vector * GetDx() const
return function steps 
 
virtual std::string Name() const =0
return name 
 
GSLMultiRootSolver(const gsl_multiroot_fsolver_type *type, int n)
Constructor from type and simension of system (number of functions) 
 
double func(double *x, double *p)
 
Namespace for new Math classes and functions. 
 
wrapper to a multi-dim function with derivatives for multi roots algorithm 
 
gsl_multiroot_fdfsolver * fDerivSolver
 
virtual gsl_vector * GetDx() const
return function steps 
 
virtual int Iterate()
perform an iteration 
 
GSLMultiRootDerivFunctionWrapper fDerivFunctions
 
GSLMultiRootDerivSolver, internal class for implementing GSL multi-root finders using derivatives...
 
void CreateSolver(const gsl_multiroot_fsolver_type *type, unsigned int n)
 
const double * X() const
solution values at the current iteration 
 
virtual gsl_vector * GetF() const =0