Logo ROOT  
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
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 }
ROOT::Math::RootFinder::kGSL_BISECTION
@ kGSL_BISECTION
Definition: RootFinder.h:89
ROOT::Math::RootFinder::~RootFinder
virtual ~RootFinder()
Definition: RootFinder.cxx:149
ROOT::Math::RootFinder::kGSL_SECANT
@ kGSL_SECANT
Definition: RootFinder.h:90
ROOT::Math::RootFinder::kGSL_BRENT
@ kGSL_BRENT
Definition: RootFinder.h:89
ROOT::Math::RootFinder::kBRENT
@ kBRENT
Definition: RootFinder.h:88
IRootFinderMethod.h
RootFinderAlgorithms.h
ROOT::Math::Roots::Newton
a Newton algorithm, which computes the derivative at each iteration See the GSL manual for more infor...
Definition: RootFinderAlgorithms.h:189
ROOT::Math::Roots::Steffenson
Steffenson method, providing the fastes convergence.
Definition: RootFinderAlgorithms.h:235
BrentRootFinder.h
MATH_ERROR_MSG
#define MATH_ERROR_MSG(loc, str)
Definition: Error.h:83
ROOT::Math::Roots::FalsePos
False Position algorithm based on linear interpolation.
Definition: RootFinderAlgorithms.h:136
TROOT.h
ROOT::Math::IRootFinderMethod
Interface for finding function roots of one-dimensional functions.
Definition: IRootFinderMethod.h:44
TPluginHandler
Definition: TPluginManager.h:101
ROOT::Math::Roots::Secant
Secant algorithm, simplified version of Newton method, which does not require the derivative at every...
Definition: RootFinderAlgorithms.h:212
h
#define h(i)
Definition: RSha256.hxx:124
ROOT::Math::RootFinder::kGSL_NEWTON
@ kGSL_NEWTON
Definition: RootFinder.h:90
Error.h
ROOT::Math::RootFinder::RootFinder
RootFinder(RootFinder::EType type=RootFinder::kBRENT)
Construct a Root-Finder algorithm.
Definition: RootFinder.cxx:47
RootFinder.h
ROOT::Math::RootFinder::EType
EType
Definition: RootFinder.h:88
ROOT::Math::Roots::Bisection
Roots::Bisection Bisection algorithm, simplest algorithm for bracketing the roots of a function,...
Definition: RootFinderAlgorithms.h:114
ROOT::Math::RootFinder::fSolver
IRootFinderMethod * fSolver
Definition: RootFinder.h:211
TPluginManager.h
ROOT::Math::RootFinder::SetMethod
bool SetMethod(RootFinder::EType type=RootFinder::kBRENT)
Definition: RootFinder.cxx:54
ROOT::Math::RootFinder::kGSL_FALSE_POS
@ kGSL_FALSE_POS
Definition: RootFinder.h:89
ROOT::Math::BrentRootFinder
Class for finding the root of a one dimensional function using the Brent algorithm.
Definition: BrentRootFinder.h:100
type
int type
Definition: TGX11.cxx:121
ROOT::Math::RootFinder::kGSL_STEFFENSON
@ kGSL_STEFFENSON
Definition: RootFinder.h:90
ROOT
VSD Structures.
Definition: StringConv.hxx:21
Math
gROOT
#define gROOT
Definition: TROOT.h:406
ROOT::Math::Roots::Brent
Brent-Dekker algorithm which combines an interpolation strategy with the bisection algorithm See the ...
Definition: RootFinderAlgorithms.h:161