14 #ifndef ROOT_Math_Integrator
15 #define ROOT_Math_Integrator
94 class IntegratorOneDim {
98 typedef IntegrationOneDim::Type Type;
119 IntegratorOneDim(IntegrationOneDim::Type type = IntegrationOneDim::kDEFAULT,
double absTol = -1,
double relTol = -1,
unsigned int size = 0,
unsigned int rule = 0) :
120 fIntegrator(0), fFunc(0)
122 fIntegrator = CreateIntegrator(type, absTol, relTol, size, rule);
138 IntegratorOneDim(
const IGenFunction &f, IntegrationOneDim::Type type = IntegrationOneDim::kDEFAULT,
double absTol = -1,
double relTol = -1,
unsigned int size = 0,
int rule = 0) :
139 fIntegrator(0), fFunc(0)
141 fIntegrator = CreateIntegrator(type, absTol, relTol, size, rule);
159 template<
class Function>
161 IntegratorOneDim(Function & f, IntegrationOneDim::Type type = IntegrationOneDim::kDEFAULT,
double absTol = -1,
double relTol = -1,
unsigned int size = 0,
int rule = 0) :
162 fIntegrator(0), fFunc(0)
164 fIntegrator = CreateIntegrator(type, absTol, relTol, size, rule);
169 virtual ~IntegratorOneDim() {
170 if (fIntegrator)
delete fIntegrator;
171 if (fFunc)
delete fFunc;
177 IntegratorOneDim(
const IntegratorOneDim &) : fIntegrator(0), fFunc(0) {}
178 IntegratorOneDim & operator=(
const IntegratorOneDim &) {
return *
this; }
192 template<
class Function>
193 inline void SetFunction(Function & f);
198 void SetFunction (
const IGenFunction &f,
bool copy =
false) {
199 if (!fIntegrator)
return;
201 if (fFunc)
delete fFunc;
203 fIntegrator->SetFunction(*fFunc);
206 fIntegrator->SetFunction(f);
217 void SetFunction(
const IMultiGenFunction &f,
unsigned int icoord ,
const double * x );
227 template<
class Function>
228 double Integral(Function & f,
double a,
double b);
237 double Integral(
const IGenFunction & f,
double a,
double b) {
238 SetFunction(f,
false);
239 return Integral(a,b);
254 double Integral(
const IGenFunction & f) {
255 SetFunction(f,
false);
274 double IntegralUp(
const IGenFunction & f,
double a ) {
275 SetFunction(f,
false);
276 return IntegralUp(a);
292 double IntegralLow(
const IGenFunction & f,
double b ) {
293 SetFunction(f,
false);
294 return IntegralLow(b);
303 template<
class Function>
304 double Integral(Function & f,
const std::vector<double> & pts );
312 double Integral(
const IGenFunction & f,
const std::vector<double> & pts ) {
313 SetFunction(f,
false);
314 return Integral(pts);
325 template<
class Function>
326 double IntegralCauchy(Function & f,
double a,
double b,
double c);
336 double IntegralCauchy(
const IGenFunction & f,
double a,
double b,
double c) {
337 SetFunction(f,
false);
338 return IntegralCauchy(a,b,c);
351 double Integral(
double a,
double b) {
352 return fIntegrator == 0 ? 0 : fIntegrator->Integral(a,b);
361 return fIntegrator == 0 ? 0 : fIntegrator->Integral();
368 double IntegralUp(
double a ) {
369 return fIntegrator == 0 ? 0 : fIntegrator->IntegralUp(a);
376 double IntegralLow(
double b ) {
377 return fIntegrator == 0 ? 0 : fIntegrator->IntegralLow(b);
382 double operator() (
double x) {
383 return IntegralLow(x);
392 double Integral(
const std::vector<double> & pts) {
393 return fIntegrator == 0 ? 0 : fIntegrator->Integral(pts);
400 double IntegralCauchy(
double a,
double b,
double c) {
401 return fIntegrator == 0 ? 0 : fIntegrator->IntegralCauchy(a,b,c);
407 double Result()
const {
return fIntegrator == 0 ? 0 : fIntegrator->Result(); }
412 double Error()
const {
return fIntegrator == 0 ? 0 : fIntegrator->Error(); }
417 int Status()
const {
return fIntegrator == 0 ? -1 : fIntegrator->Status(); }
423 int NEval()
const {
return fIntegrator == 0 ? -1 : fIntegrator->NEval(); }
431 void SetRelTolerance(
double relTolerance) {
if (fIntegrator) fIntegrator->SetRelTolerance(relTolerance); }
437 void SetAbsTolerance(
double absTolerance) {
if (fIntegrator) fIntegrator->SetAbsTolerance(absTolerance); }
442 VirtualIntegratorOneDim * GetIntegrator() {
return fIntegrator; }
447 void SetOptions(
const ROOT::Math::IntegratorOneDimOptions & opt) {
if (fIntegrator) fIntegrator->SetOptions(opt); }
452 ROOT::Math::IntegratorOneDimOptions Options()
const {
return (fIntegrator) ? fIntegrator->Options() : IntegratorOneDimOptions(); }
455 std::string Name()
const {
return (fIntegrator) ? Options().Integrator() : std::string(
""); }
458 static IntegrationOneDim::Type GetType(
const char * name);
461 static std::string GetName(IntegrationOneDim::Type);
466 VirtualIntegratorOneDim * CreateIntegrator(IntegrationOneDim::Type type ,
double absTol,
double relTol,
unsigned int size,
int rule);
470 VirtualIntegratorOneDim * fIntegrator;
471 IGenFunction * fFunc;
476 typedef IntegratorOneDim Integrator;
488 template<
class Function>
489 void ROOT::Math::IntegratorOneDim::SetFunction( Function & f) {
490 ::ROOT::Math::WrappedFunction<Function &> wf(f);
492 SetFunction(wf,
true);
495 template<
class Function>
496 double ROOT::Math::IntegratorOneDim::Integral(Function & f,
double a,
double b) {
497 ::ROOT::Math::WrappedFunction< Function &> wf(f);
498 SetFunction(wf,
false);
499 return Integral(a,b);
525 template<
class Function>
526 double ROOT::Math::IntegratorOneDim::Integral(Function & f,
const std::vector<double> & pts) {
527 ::ROOT::Math::WrappedFunction<Function &> wf(f);
528 SetFunction(wf,
false);
529 return Integral(pts);
532 template<
class Function>
533 double ROOT::Math::IntegratorOneDim::IntegralCauchy(Function & f,
double a,
double b,
double c) {
534 ::ROOT::Math::WrappedFunction<Function & > wf(f);
535 SetFunction(wf,
false);
536 return IntegralCauchy(a,b,c);