Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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 CERN *
7 * All rights reserved. *
8 * *
9 * For the licensing terms see $ROOTSYS/LICENSE. *
10 * For the list of contributors see $ROOTSYS/README/CREDITS. *
11 * *
12 **********************************************************************/
13
14#include "Math/RootFinder.h"
18
19#include "RConfigure.h"
20
21#ifndef MATH_NO_PLUGIN_MANAGER
22
23#include "TROOT.h"
24#include "TPluginManager.h"
25
26#else // case no plugin manager is available
27#ifdef R__HAS_MATHMORE
29#endif
30
31#endif
32
33#include <cassert>
34
35#include "Math/Error.h"
36
37namespace ROOT {
38namespace Math {
39
40
42 fSolver(nullptr)
43{
44 // constructor passing type (default is kBRENT)
45 const bool success = SetMethod(type);
46 if (!success)
47 throw std::runtime_error("ROOT::Math::RootFinder: ROOT was built without the requested algorithm");
48}
49
51{
52 fSolver = nullptr;
53
54 // set method - Use the plug-in manager if method is implemented in MathMore
55 if ( type == RootFinder::kBRENT )
56 {
58 return true;
59 }
60
62 {
64 return true;
65 }
66
67#ifdef MATH_NO_PLUGIN_MANAGER // no PM available
68#ifdef R__HAS_MATHMORE
69
70 switch(type) {
71
72 case kGSL_BISECTION:
74 break;
75 case kGSL_FALSE_POS:
77 break;
78 case kGSL_BRENT:
80 break;
81 case kGSL_NEWTON:
83 break;
84 case kGSL_SECANT:
86 break;
87 case kGSL_STEFFENSON:
89 break;
90 default:
91 MATH_ERROR_MSG("RootFinder::SetMethod","RootFinderMethod type is not available in MathCore");
92 fSolver = 0;
93 return false;
94 break;
95 };
96
97#else
98 MATH_ERROR_MSG("RootFinder::SetMethod","RootFinderMethod type is not available in MathCore");
99 return false;
100#endif
101
102#else // case of using Plugin Manager
104 std::string stype;
105
106 switch(type) {
107
108 case kGSL_BISECTION:
109 stype = "Bisection";
110 break;
111 case kGSL_FALSE_POS:
112 stype = "FalsePos";
113 break;
114 case kGSL_BRENT:
115 stype = "Brent";
116 break;
117 case kGSL_NEWTON:
118 stype = "Newton";
119 break;
120 case kGSL_SECANT:
121 stype = "Secant";
122 break;
123 case kGSL_STEFFENSON:
124 stype = "Steffenson";
125 break;
126 default:
127 MATH_ERROR_MSG("RootFinder::SetMethod","RootFinderMethod type is not available in MathCore");
128 fSolver = nullptr;
129 return false;
130 break;
131 };
132
133 if ((h = gROOT->GetPluginManager()->FindHandler("ROOT::Math::IRootFinderMethod", stype.c_str() ))) {
134 if (h->LoadPlugin() == -1) {
135 MATH_ERROR_MSG("RootFinder::SetMethod","Error loading RootFinderMethod");
136 return false;
137 }
138
139 fSolver = reinterpret_cast<ROOT::Math::IRootFinderMethod *>(h->ExecPlugin(0));
140 }
141
142#endif
143
144 if (!fSolver) {
145 MATH_ERROR_MSG("RootFinder::SetMethod","Error loading RootFinderMethod");
146 return false;
147 }
148
149 return true;
150}
151
152
154{
155 // destructor
156 delete fSolver;
157}
158
159
160}
161}
#define MATH_ERROR_MSG(loc, str)
Definition Error.h:83
#define h(i)
Definition RSha256.hxx:106
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
#define gROOT
Definition TROOT.h:414
Class for finding the root of a one dimensional function using the Brent algorithm.
Interface for finding function roots of one-dimensional functions.
Class for finding the root of a one dimensional function using the ModAB algorithm.
bool SetMethod(RootFinder::EType type=RootFinder::kBRENT)
RootFinder(RootFinder::EType type=RootFinder::kBRENT)
Construct a Root-Finder algorithm.
IRootFinderMethod * fSolver
Definition RootFinder.h:197
Roots::Bisection Bisection algorithm, simplest algorithm for bracketing the roots of a function,...
Brent-Dekker algorithm which combines an interpolation strategy with the bisection algorithm See the ...
False Position algorithm based on linear interpolation.
a Newton algorithm, which computes the derivative at each iteration See the GSL manual for more infor...
Secant algorithm, simplified version of Newton method, which does not require the derivative at every...
Steffenson method, providing the fastes convergence.
Namespace for new Math classes and functions.