26 #include "RConfigure.h"
35 #ifndef MATH_NO_PLUGIN_MANAGER
40 #else // case no plugin manager is available
41 #ifdef R__HAS_MATHMORE
53 IntegrationOneDim::Type IntegratorOneDim::GetType(
const char *name) {
54 if (name == 0)
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" );
63 return IntegrationOneDim::kDEFAULT;
66 std::string IntegratorOneDim::GetName(IntegrationOneDim::Type type) {
67 if (type == IntegrationOneDim::kDEFAULT) type = GetType(IntegratorOneDimOptions::DefaultIntegrator().c_str() );
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");
78 IntegrationMultiDim::Type IntegratorMultiDim::GetType(
const char *name) {
79 if (name == 0)
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 " );
87 return IntegrationMultiDim::kDEFAULT;
90 std::string IntegratorMultiDim::GetName(IntegrationMultiDim::Type type) {
91 if (type == IntegrationMultiDim::kDEFAULT) type = GetType(IntegratorMultiDimOptions::DefaultIntegrator().c_str() );
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");
100 void IntegratorOneDim::SetFunction(
const IMultiGenFunction &f,
unsigned int icoord ,
const double * x ) {
103 unsigned int ndim = f.NDim();
104 assert (icoord < ndim);
105 ROOT::Math::OneDimMultiFunctionAdapter<> adapter(f,ndim,icoord);
107 if (x != 0) adapter.SetX(x, x+ ndim);
108 SetFunction(adapter,
true);
114 VirtualIntegratorOneDim * IntegratorOneDim::CreateIntegrator(IntegrationOneDim::Type type ,
double absTol,
double relTol,
unsigned int size,
int rule) {
117 if (type == IntegrationOneDim::kDEFAULT) type = IntegratorOneDimOptions::DefaultIntegratorType();
118 if (absTol < 0) absTol = IntegratorOneDimOptions::DefaultAbsTolerance();
119 if (relTol < 0) relTol = IntegratorOneDimOptions::DefaultRelTolerance();
120 if (size <= 0) size = IntegratorOneDimOptions::DefaultWKSize();
121 if (rule <= 0) rule = IntegratorOneDimOptions::DefaultNPoints();
127 #ifndef R__HAS_MATHMORE
129 if (type == IntegrationOneDim::kADAPTIVE ||
130 type == IntegrationOneDim::kADAPTIVESINGULAR ||
131 type == IntegrationOneDim::kNONADAPTIVE )
132 type = IntegrationOneDim::kGAUSS;
135 if (type == IntegrationOneDim::kGAUSS)
136 return new GaussIntegrator(relTol);
137 if (type == IntegrationOneDim::kLEGENDRE) {
138 return new GaussLegendreIntegrator(rule,relTol);
141 VirtualIntegratorOneDim * ig = 0;
143 #ifdef MATH_NO_PLUGIN_MANAGER // no PM available
144 #ifdef R__HAS_MATHMORE
145 ig =
new GSLIntegrator(type, absTol, relTol, size);
147 MATH_ERROR_MSG(
"IntegratorOneDim::CreateIntegrator",
"Integrator type is not available in MathCore");
150 #else // case of using Plugin Manager
154 R__LOCKGUARD(gROOTMutex);
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();
164 std::string typeName = GetName(type);
166 ig =
reinterpret_cast<ROOT::Math::VirtualIntegratorOneDim *
>( h->ExecPlugin(5,typeName.c_str(), rule, absTol, relTol, size ) );
170 std::cout <<
"Loaded Integrator " <<
typeid(*ig).name() << std::endl;
178 VirtualIntegratorMultiDim * IntegratorMultiDim::CreateIntegrator(IntegrationMultiDim::Type type ,
double absTol,
double relTol,
unsigned int ncall) {
181 #ifndef R__HAS_MATHMORE
183 type = IntegrationMultiDim::kADAPTIVE;
186 if (type == IntegrationMultiDim::kDEFAULT) type = GetType(IntegratorMultiDimOptions::DefaultIntegrator().c_str());
187 if (absTol < 0) absTol = IntegratorMultiDimOptions::DefaultAbsTolerance();
188 if (relTol < 0) relTol = IntegratorMultiDimOptions::DefaultRelTolerance();
189 if (ncall <= 0) ncall = IntegratorMultiDimOptions::DefaultNCalls();
190 unsigned int size = IntegratorMultiDimOptions::DefaultWKSize();
194 if (type == IntegrationMultiDim::kADAPTIVE)
195 return new AdaptiveIntegratorMultiDim(absTol, relTol, ncall, size);
199 VirtualIntegratorMultiDim * ig = 0;
201 #ifdef MATH_NO_PLUGIN_MANAGER // no PM available
202 #ifdef R__HAS_MATHMORE
203 ig =
new GSLMCIntegrator(type, absTol, relTol, ncall);
205 MATH_ERROR_MSG(
"IntegratorMultiDim::CreateIntegrator",
"Integrator type is not available in MathCore");
208 #else // use ROOT Plugin-Manager to instantiate GSLMCIntegrator
211 R__LOCKGUARD(gROOTMutex);
212 const char * pluginName =
"GSLMCIntegrator";
213 TPluginHandler *h =
nullptr;
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);
221 std::string typeName = GetName(type);
223 ig =
reinterpret_cast<ROOT::Math::VirtualIntegratorMultiDim *
>( h->ExecPlugin(4,typeName.c_str(), absTol, relTol, ncall ) );
227 std::cout <<
"Loaded Integrator " <<
typeid(*ig).name() << std::endl;