ROOT  6.06/09
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 #ifndef ROOT_Math_Error
32 #include "Math/Error.h"
33 #endif
34 
35 namespace ROOT {
36 namespace Math {
37 
38 
40  fSolver(0)
41 {
42  // constructor passing type (default is kBRENT)
43  SetMethod(type);
44 }
45 
47 {
48  // set method - Use the plug-in manager if method is implemented in MathMore
49  if ( type == RootFinder::kBRENT )
50  {
51  fSolver = new BrentRootFinder();
52  return true;
53  }
54 
55 #ifdef MATH_NO_PLUGIN_MANAGER // no PM available
56 #ifdef R__HAS_MATHMORE
57 
58  switch(type) {
59 
60  case kGSL_BISECTION:
62  break;
63  case kGSL_FALSE_POS:
65  break;
66  case kGSL_BRENT:
68  break;
69  case kGSL_NEWTON:
71  break;
72  case kGSL_SECANT:
74  break;
75  case kGSL_STEFFENSON:
77  break;
78  default:
79  MATH_ERROR_MSG("RootFinder::SetMethod","RootFinderMethod type is not available in MathCore");
80  fSolver = 0;
81  return false;
82  break;
83  };
84 
85 #else
86  MATH_ERROR_MSG("RootFinder::SetMethod","RootFinderMethod type is not available in MathCore");
87  return false;
88 #endif
89 
90 #else // case of using Plugin Manager
92  std::string stype;
93 
94  switch(type) {
95 
96  case kGSL_BISECTION:
97  stype = "Bisection";
98  break;
99  case kGSL_FALSE_POS:
100  stype = "FalsePos";
101  break;
102  case kGSL_BRENT:
103  stype = "Brent";
104  break;
105  case kGSL_NEWTON:
106  stype = "Newton";
107  break;
108  case kGSL_SECANT:
109  stype = "Secant";
110  break;
111  case kGSL_STEFFENSON:
112  stype = "Steffenson";
113  break;
114  default:
115  MATH_ERROR_MSG("RootFinder::SetMethod","RootFinderMethod type is not available in MathCore");
116  fSolver = 0;
117  return false;
118  break;
119  };
120 
121  if ((h = gROOT->GetPluginManager()->FindHandler("ROOT::Math::IRootFinderMethod", stype.c_str() ))) {
122  if (h->LoadPlugin() == -1) {
123  MATH_ERROR_MSG("RootFinder::SetMethod","Error loading RootFinderMethod");
124  return false;
125  }
126 
127  fSolver = reinterpret_cast<ROOT::Math::IRootFinderMethod *>( h->ExecPlugin(0) );
128  assert(fSolver != 0);
129  }
130  else {
131  MATH_ERROR_MSG("RootFinder::SetMethod","Error loading RootFinderMethod");
132  return false;
133  }
134 
135 #endif
136 
137  return true;
138 }
139 
140 
142 {
143  // destructor
144  delete fSolver;
145 }
146 
147 
148 }
149 }
Namespace for new ROOT classes and functions.
Definition: ROOT.py:1
Secant algorithm, simplified version of Newton method, which does not require the derivative at every...
#define assert(cond)
Definition: unittest.h:542
TH1 * h
Definition: legend2.C:5
#define gROOT
Definition: TROOT.h:340
Int_t LoadPlugin()
Load the plugin library for this handler.
Long_t ExecPlugin(int nargs, const T &...params)
const char Int_t const char TProof Int_t stype
Definition: TXSlave.cxx:46
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:50
False Position algorithm based on linear interpolation.
RootFinder(RootFinder::EType type=RootFinder::kBRENT)
Construct a Root-Finder algorithm.
Definition: RootFinder.cxx:39
Class for finding the root of a one dimensional function using the Brent algorithm.
bool SetMethod(RootFinder::EType type=RootFinder::kBRENT)
Definition: RootFinder.cxx:46
int type
Definition: TGX11.cxx:120
IRootFinderMethod * fSolver
Definition: RootFinder.h:215
Namespace for new Math classes and functions.
Brent-Dekker algorithm which combines an interpolation strategy with the bisection algorithm See the ...