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"
17
18#include "RConfigure.h"
19
20#ifndef MATH_NO_PLUGIN_MANAGER
21
22#include "TROOT.h"
23#include "TPluginManager.h"
24
25#else // case no plugin manager is available
26#ifdef R__HAS_MATHMORE
28#endif
29
30#endif
31
32#include <cassert>
33
34#include "Math/Error.h"
35
36namespace ROOT {
37namespace Math {
38
39
41 fSolver(nullptr)
42{
43 // constructor passing type (default is kBRENT)
44 const bool success = SetMethod(type);
45 if (!success)
46 throw std::runtime_error("ROOT::Math::RootFinder: ROOT was built without the requested algorithm");
47}
48
50{
51 fSolver = nullptr;
52
53 // set method - Use the plug-in manager if method is implemented in MathMore
54 if ( type == RootFinder::kBRENT )
55 {
57 return true;
58 }
59
60#ifdef MATH_NO_PLUGIN_MANAGER // no PM available
61#ifdef R__HAS_MATHMORE
62
63 switch(type) {
64
65 case kGSL_BISECTION:
67 break;
68 case kGSL_FALSE_POS:
70 break;
71 case kGSL_BRENT:
73 break;
74 case kGSL_NEWTON:
76 break;
77 case kGSL_SECANT:
79 break;
80 case kGSL_STEFFENSON:
82 break;
83 default:
84 MATH_ERROR_MSG("RootFinder::SetMethod","RootFinderMethod type is not available in MathCore");
85 fSolver = 0;
86 return false;
87 break;
88 };
89
90#else
91 MATH_ERROR_MSG("RootFinder::SetMethod","RootFinderMethod type is not available in MathCore");
92 return false;
93#endif
94
95#else // case of using Plugin Manager
97 std::string stype;
98
99 switch(type) {
100
101 case kGSL_BISECTION:
102 stype = "Bisection";
103 break;
104 case kGSL_FALSE_POS:
105 stype = "FalsePos";
106 break;
107 case kGSL_BRENT:
108 stype = "Brent";
109 break;
110 case kGSL_NEWTON:
111 stype = "Newton";
112 break;
113 case kGSL_SECANT:
114 stype = "Secant";
115 break;
116 case kGSL_STEFFENSON:
117 stype = "Steffenson";
118 break;
119 default:
120 MATH_ERROR_MSG("RootFinder::SetMethod","RootFinderMethod type is not available in MathCore");
121 fSolver = nullptr;
122 return false;
123 break;
124 };
125
126 if ((h = gROOT->GetPluginManager()->FindHandler("ROOT::Math::IRootFinderMethod", stype.c_str() ))) {
127 if (h->LoadPlugin() == -1) {
128 MATH_ERROR_MSG("RootFinder::SetMethod","Error loading RootFinderMethod");
129 return false;
130 }
131
132 fSolver = reinterpret_cast<ROOT::Math::IRootFinderMethod *>(h->ExecPlugin(0));
133 }
134
135#endif
136
137 if (!fSolver) {
138 MATH_ERROR_MSG("RootFinder::SetMethod","Error loading RootFinderMethod");
139 return false;
140 }
141
142 return true;
143}
144
145
147{
148 // destructor
149 delete fSolver;
150}
151
152
153}
154}
#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:411
Class for finding the root of a one dimensional function using the Brent algorithm.
Interface for finding function roots of one-dimensional functions.
bool SetMethod(RootFinder::EType type=RootFinder::kBRENT)
RootFinder(RootFinder::EType type=RootFinder::kBRENT)
Construct a Root-Finder algorithm.
IRootFinderMethod * fSolver
Definition RootFinder.h:195
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.