Logo ROOT   6.19/01
Reference Guide
RootFinder.cxx
Go to the documentation of this file.
1 // @(#)root/mathcore:$Id$
2 // Authors: David Gonzalez Maline 01/2008
3 
4 /**********************************************************************
5  * *
6  * Copyright (c) 2006 , LCG ROOT MathLib Team *
7  * *
8  * *
9  **********************************************************************/
10 
11 #include "Math/RootFinder.h"
12 #include "Math/IRootFinderMethod.h"
13 #include "Math/BrentRootFinder.h"
14 
15 #include "RConfigure.h"
16 
17 #ifndef MATH_NO_PLUGIN_MANAGER
18 
19 #include "TROOT.h"
20 #include "TPluginManager.h"
21 
22 #else // case no plugin manager is available
23 #ifdef R__HAS_MATHMORE
25 #endif
26 
27 #endif
28 
29 #include <cassert>
30 
31 #include "Math/Error.h"
32 
33 namespace ROOT {
34 namespace Math {
35 
36 
38  fSolver(0)
39 {
40  // constructor passing type (default is kBRENT)
41  SetMethod(type);
42 }
43 
45 {
46  // set method - Use the plug-in manager if method is implemented in MathMore
47  if ( type == RootFinder::kBRENT )
48  {
49  fSolver = new BrentRootFinder();
50  return true;
51  }
52 
53 #ifdef MATH_NO_PLUGIN_MANAGER // no PM available
54 #ifdef R__HAS_MATHMORE
55 
56  switch(type) {
57 
58  case kGSL_BISECTION:
60  break;
61  case kGSL_FALSE_POS:
63  break;
64  case kGSL_BRENT:
66  break;
67  case kGSL_NEWTON:
69  break;
70  case kGSL_SECANT:
72  break;
73  case kGSL_STEFFENSON:
75  break;
76  default:
77  MATH_ERROR_MSG("RootFinder::SetMethod","RootFinderMethod type is not available in MathCore");
78  fSolver = 0;
79  return false;
80  break;
81  };
82 
83 #else
84  MATH_ERROR_MSG("RootFinder::SetMethod","RootFinderMethod type is not available in MathCore");
85  return false;
86 #endif
87 
88 #else // case of using Plugin Manager
90  std::string stype;
91 
92  switch(type) {
93 
94  case kGSL_BISECTION:
95  stype = "Bisection";
96  break;
97  case kGSL_FALSE_POS:
98  stype = "FalsePos";
99  break;
100  case kGSL_BRENT:
101  stype = "Brent";
102  break;
103  case kGSL_NEWTON:
104  stype = "Newton";
105  break;
106  case kGSL_SECANT:
107  stype = "Secant";
108  break;
109  case kGSL_STEFFENSON:
110  stype = "Steffenson";
111  break;
112  default:
113  MATH_ERROR_MSG("RootFinder::SetMethod","RootFinderMethod type is not available in MathCore");
114  fSolver = 0;
115  return false;
116  break;
117  };
118 
119  if ((h = gROOT->GetPluginManager()->FindHandler("ROOT::Math::IRootFinderMethod", stype.c_str() ))) {
120  if (h->LoadPlugin() == -1) {
121  MATH_ERROR_MSG("RootFinder::SetMethod","Error loading RootFinderMethod");
122  return false;
123  }
124 
125  fSolver = reinterpret_cast<ROOT::Math::IRootFinderMethod *>( h->ExecPlugin(0) );
126  assert(fSolver != 0);
127  }
128  else {
129  MATH_ERROR_MSG("RootFinder::SetMethod","Error loading RootFinderMethod");
130  return false;
131  }
132 
133 #endif
134 
135  return true;
136 }
137 
138 
140 {
141  // destructor
142  delete fSolver;
143 }
144 
145 
146 }
147 }
VSD Structures.
Definition: StringConv.hxx:21
Secant algorithm, simplified version of Newton method, which does not require the derivative at every...
#define gROOT
Definition: TROOT.h:414
Steffenson method, providing the fastes convergence.
a Newton algorithm, which computes the derivative at each iteration See the GSL manual for more infor...
Interface for finding function roots of one-dimensional functions.
Roots::Bisection Bisection algorithm, simplest algorithm for bracketing the roots of a function...
#define MATH_ERROR_MSG(loc, str)
Definition: Error.h:82
False Position algorithm based on linear interpolation.
RootFinder(RootFinder::EType type=RootFinder::kBRENT)
Construct a Root-Finder algorithm.
Definition: RootFinder.cxx:37
#define h(i)
Definition: RSha256.hxx:106
Class for finding the root of a one dimensional function using the Brent algorithm.
bool SetMethod(RootFinder::EType type=RootFinder::kBRENT)
Definition: RootFinder.cxx:44
int type
Definition: TGX11.cxx:120
IRootFinderMethod * fSolver
Definition: RootFinder.h:211
Namespace for new Math classes and functions.
Brent-Dekker algorithm which combines an interpolation strategy with the bisection algorithm See the ...