Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
Integrator.cxx
Go to the documentation of this file.
1// @(#)root/mathmore:$Id: Integrator.cxx 19826 2007-09-19 19:56:11Z rdm $
2// Authors: L. Moneta, M. Slawinska 10/2007
3
4 /**********************************************************************
5 * *
6 * Copyright (c) 2004 ROOT Foundation, CERN/PH-SFT *
7 * *
8 * *
9 **********************************************************************/
10
11#include "Math/Integrator.h"
12
13#include "Math/Error.h"
14#include "Math/IFunction.h"
17
19
22
24
25
26#include "RConfigure.h"
27
28#include <algorithm>
29#include <functional>
30#include <cctype> // need to use c version of tolower defined here
31
32
33#include <cassert>
34
35#ifndef MATH_NO_PLUGIN_MANAGER
36
37#include "TROOT.h"
38#include "TPluginManager.h"
39
40#else // case no plugin manager is available
41#ifdef R__HAS_MATHMORE
42#include "Math/GSLIntegrator.h"
44#endif
45
46#endif
47
48
49
50namespace ROOT {
51namespace Math {
52
54 if (name == nullptr) return IntegrationOneDim::kDEFAULT;
55 std::string typeName(name);
56 std::transform(typeName.begin(), typeName.end(), typeName.begin(), (int(*)(int)) toupper );
57 if (typeName == "GAUSS") return IntegrationOneDim::kGAUSS;
58 if (typeName == "GAUSSLEGENDRE") return IntegrationOneDim::kLEGENDRE;
59 if (typeName == "ADAPTIVE") return IntegrationOneDim::kADAPTIVE;
60 if (typeName == "ADAPTIVESINGULAR") return IntegrationOneDim::kADAPTIVESINGULAR;
61 if (typeName == "NONADAPTIVE") return IntegrationOneDim::kNONADAPTIVE;
62 if (!typeName.empty()) MATH_WARN_MSG("IntegratorOneDim::GetType","Invalid type name specified - use default integrator" );
64}
65
68 if (type == IntegrationOneDim::kGAUSS) return "Gauss";
69 if (type == IntegrationOneDim::kLEGENDRE) return "GaussLegendre";
70 if (type == IntegrationOneDim::kADAPTIVE) return "Adaptive";
71 if (type == IntegrationOneDim::kADAPTIVESINGULAR) return "AdaptiveSingular";
72 if (type == IntegrationOneDim::kNONADAPTIVE) return "NonAdaptive";
73 MATH_WARN_MSG("IntegratorOneDim::GetType","Invalid type specified " );
74 return std::string("undefined");
75}
76
77
79 if (name == nullptr) return IntegrationMultiDim::kDEFAULT;
80 std::string typeName(name);
81 std::transform(typeName.begin(), typeName.end(), typeName.begin(), (int(*)(int)) toupper );
82 if (typeName == "ADAPTIVE") return IntegrationMultiDim::kADAPTIVE;
83 if (typeName == "VEGAS") return IntegrationMultiDim::kVEGAS;
84 if (typeName == "MISER") return IntegrationMultiDim::kMISER;
85 if (typeName == "PLAIN") return IntegrationMultiDim::kPLAIN;
86 if (!typeName.empty()) MATH_WARN_MSG("IntegratorMultiDim::GetType","Invalid type name specified - use default integrator " );
88}
89
92 if (type == IntegrationMultiDim::kADAPTIVE) return "ADAPTIVE";
93 if (type == IntegrationMultiDim::kVEGAS) return "VEGAS";
94 if (type == IntegrationMultiDim::kMISER) return "MISER";
95 if (type == IntegrationMultiDim::kPLAIN) return "PLAIN";
96 MATH_WARN_MSG("IntegratorMultiDim::GetType","Invalid type specified " );
97 return std::string("Undefined");
98}
99
100void IntegratorOneDim::SetFunction(const IMultiGenFunction &f, unsigned int icoord , const double * x ) {
101 // set function from a multi-dim function
102 // pass also x in case of multi-dim function express the other dimensions (which are fixed)
103 unsigned int ndim = f.NDim();
104 assert (icoord < ndim);
105 ROOT::Math::OneDimMultiFunctionAdapter<> adapter(f,ndim,icoord);
106 // case I pass a vector x which is needed (for example to compute I(y) = Integral( f(x,y) dx) ) need to setCX
107 if (x != nullptr) adapter.SetX(x, x+ ndim);
108 SetFunction(adapter,true); // need to copy this object
109}
110
111
112// methods to create integrators
113
114VirtualIntegratorOneDim * IntegratorOneDim::CreateIntegrator(IntegrationOneDim::Type type , double absTol, double relTol, unsigned int size, int rule) {
115 // create the concrete class for one-dimensional integration. Use the plug-in manager if needed
116
118 if (absTol < 0) absTol = IntegratorOneDimOptions::DefaultAbsTolerance();
119 if (relTol < 0) relTol = IntegratorOneDimOptions::DefaultRelTolerance();
121 if (rule <= 0) rule = IntegratorOneDimOptions::DefaultNPoints();
122 //if (ncall <= 0) ncall = IntegratorOneDimOptions::DefaultNCalls();
123
124
125
126
127#ifndef R__HAS_MATHMORE
128 // default type is GAUSS when Mathmore is not built
133#endif
134
136 return new GaussIntegrator(relTol);
138 return new GaussLegendreIntegrator(rule,relTol);
139 }
140
141 VirtualIntegratorOneDim * ig = nullptr;
142
143#ifdef MATH_NO_PLUGIN_MANAGER // no PM available
144#ifdef R__HAS_MATHMORE
145 ig = new GSLIntegrator(type, absTol, relTol, size);
146#else
147 MATH_ERROR_MSG("IntegratorOneDim::CreateIntegrator","Integrator type is not available in MathCore");
148#endif
149
150#else // case of using Plugin Manager
151
152
153 {
156 //gDebug = 3;
157 if ((h = gROOT->GetPluginManager()->FindHandler("ROOT::Math::VirtualIntegrator", "GSLIntegrator"))) {
158 if (h->LoadPlugin() == -1) {
159 MATH_WARN_MSG("IntegratorOneDim::CreateIntegrator","Error loading one dimensional GSL integrator - use Gauss integrator");
160 return new GaussIntegrator();
161 }
162
163 // plugin manager requires a string
164 std::string typeName = GetName(type);
165
166 ig = reinterpret_cast<ROOT::Math::VirtualIntegratorOneDim *>( h->ExecPlugin(5,typeName.c_str(), rule, absTol, relTol, (size_t) size ) );
167 assert(ig != nullptr);
168 }
169#ifdef DEBUG
170 std::cout << "Loaded Integrator " << typeid(*ig).name() << std::endl;
171#endif
172 }
173#endif
174
175 return ig;
176}
177
179 // create concrete class for multidimensional integration
180
181#ifndef R__HAS_MATHMORE
182 // when Mathmore is not built only possible type is ADAPTIVE. There is no other choice
184#endif
185
187 if (absTol < 0) absTol = IntegratorMultiDimOptions::DefaultAbsTolerance();
188 if (relTol < 0) relTol = IntegratorMultiDimOptions::DefaultRelTolerance();
189 if (ncall <= 0) ncall = IntegratorMultiDimOptions::DefaultNCalls();
191
192
193 // no need for PM in the adaptive case using Genz method (class is in MathCore)
195 return new AdaptiveIntegratorMultiDim(absTol, relTol, ncall, size);
196
197 // use now plugin-manager for creating the GSL integrator
198
199 VirtualIntegratorMultiDim * ig = nullptr;
200
201#ifdef MATH_NO_PLUGIN_MANAGER // no PM available
202#ifdef R__HAS_MATHMORE
203 ig = new GSLMCIntegrator(type, absTol, relTol, ncall);
204#else
205 MATH_ERROR_MSG("IntegratorMultiDim::CreateIntegrator","Integrator type is not available in MathCore");
206#endif
207
208#else // use ROOT Plugin-Manager to instantiate GSLMCIntegrator
209
210 {
212 const char * pluginName = "GSLMCIntegrator";
213 TPluginHandler *h = nullptr;
214 //gDebug = 3;
215 if ((h = gROOT->GetPluginManager()->FindHandler("ROOT::Math::VirtualIntegrator", pluginName))) {
216 if (h->LoadPlugin() == -1) {
217 MATH_WARN_MSG("IntegratorMultiDim::CreateIntegrator","Error loading GSL MC multidim integrator - use adaptive method");
218 return new AdaptiveIntegratorMultiDim(absTol, relTol, ncall);
219 }
220
221 std::string typeName = GetName(type);
222
223 ig = reinterpret_cast<ROOT::Math::VirtualIntegratorMultiDim *>( h->ExecPlugin(4,typeName.c_str(), absTol, relTol, ncall ) );
224 assert(ig != nullptr);
225
226#ifdef DEBUG
227 std::cout << "Loaded Integrator " << typeid(*ig).name() << std::endl;
228#endif
229 }
230 }
231#endif
232 return ig;
233}
234
235
236
237
238} // namespace Math
239} // namespace ROOT
#define MATH_ERROR_MSG(loc, str)
Definition Error.h:83
#define MATH_WARN_MSG(loc, str)
Definition Error.h:80
#define f(i)
Definition RSha256.hxx:104
#define h(i)
Definition RSha256.hxx:106
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
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
char name[80]
Definition TGX11.cxx:110
R__EXTERN TVirtualMutex * gROOTMutex
Definition TROOT.h:63
#define gROOT
Definition TROOT.h:406
#define R__LOCKGUARD(mutex)
Class for adaptive quadrature integration in multi-dimensions using rectangular regions.
Class for performing numerical integration of a function in one dimension.
User class for performing function integration.
User class for performing function integration.
Documentation for the abstract class IBaseFunctionMultiDim.
Definition IFunction.h:61
static std::string GetName(IntegrationMultiDim::Type)
static function to get a string from the enumeration
static IntegrationMultiDim::Type GetType(const char *name)
static function to get the enumeration from a string
VirtualIntegratorMultiDim * CreateIntegrator(IntegrationMultiDim::Type type, double absTol, double relTol, unsigned int ncall)
static IntegrationOneDim::Type DefaultIntegratorType()
static std::string GetName(IntegrationOneDim::Type)
static function to get a string from the enumeration
VirtualIntegratorOneDim * CreateIntegrator(IntegrationOneDim::Type type, double absTol, double relTol, unsigned int size, int rule)
void SetFunction(Function &f)
method to set the a generic integration function
Definition Integrator.h:492
static IntegrationOneDim::Type GetType(const char *name)
static function to get the enumeration from a string
OneDimMultiFunctionAdapter class to wrap a multidimensional function in one dimensional one.
void SetX(Iterator begin, Iterator end)
Set X values in case vector is own, iterator size must match previous set dimension.
Interface (abstract) class for multi numerical integration It must be implemented by the concrete Int...
Interface (abstract) class for 1D numerical integration It must be implemented by the concrete Integr...
Type
enumeration specifying the integration types.
@ kADAPTIVESINGULAR
default adaptive integration type which can be used in the case of the presence of singularities.
@ kNONADAPTIVE
to be used for smooth functions
@ kLEGENDRE
Gauss-Legendre integration.
@ kADAPTIVE
to be used for general functions without singularities
@ kGAUSS
simple Gauss integration method with fixed rule
@ kDEFAULT
default type specified in the static options
Type
enumeration specifying the integration types.
@ kADAPTIVE
adaptive multi-dimensional integration
@ kDEFAULT
default type specified in the static option
Double_t x[n]
Definition legend1.C:17
Namespace for new Math classes and functions.
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...