Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v31r0 (aeb156f0)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Integral.cpp
Go to the documentation of this file.
1 // ============================================================================
2 // Include files
3 // ============================================================================
4 // GaudiKernel
5 // ============================================================================
7 // ============================================================================
8 // GaudiMath
9 // ============================================================================
10 #include "GaudiMath/Constant.h"
11 #include "GaudiMath/Integral.h"
13 // ============================================================================
14 
15 #ifdef __ICC
16 // disable icc remark #1572: floating-point equality and inequality comparisons are unreliable
17 // The comparison are meant
18 # pragma warning( disable : 1572 )
19 // disable icc remark #2259: non-pointer conversion from "double" to "float" may lose significant bits
20 # pragma warning( disable : 2259 )
21 #endif
22 
23 namespace GaudiMath {
24 
25  double Integral( const Genfun::AbsFunction& function, const double a, const double b,
27  const double epsabs, const double epsrel, const size_t size ) {
28  if ( 1 != function.dimensionality() ) {
29  throw GaudiException( "GaudiMath::Integral: illegal function dimension", "*GaudiMath*", StatusCode::FAILURE );
30  }
31 
32  const Genfun::AbsFunction& one = Genfun::GaudiMathImplementation::Constant( 1.0, 1 );
33 
34  const Genfun::AbsFunction& cross = Genfun::FunctionDirectProduct( &one, &function );
35 
36  const Genfun::AbsFunction& result =
37  Genfun::GaudiMathImplementation::NumericalDefiniteIntegral( cross, 1, a, b, type, rule, epsabs, epsrel, size );
38 
39  return result( Genfun::Argument( 1 ) );
40  }
41 
42  double Integral( const Genfun::AbsFunction& function, const double a, const double b,
43  const std::vector<double>& points, const double epsabs, const double epsrel, const size_t size ) {
44 
45  if ( 1 != function.dimensionality() ) {
46  throw GaudiException( "GaudiMath::Integral: illegal function dimension", "*GaudiMath*", StatusCode::FAILURE );
47  }
48 
49  const Genfun::AbsFunction& one = Genfun::GaudiMathImplementation::Constant( 1.0, 1 );
50 
51  const Genfun::AbsFunction& cross = Genfun::FunctionDirectProduct( &one, &function );
52 
53  const Genfun::AbsFunction& result =
54  Genfun::GaudiMathImplementation::NumericalDefiniteIntegral( cross, 1, a, b, points, epsabs, epsrel, size );
55 
56  return result( Genfun::Argument( 1 ) );
57  }
58 
59  double Integral( const Genfun::AbsFunction& function, const double a, const GaudiMath::Integration::Inf b,
60  const double epsabs, const double epsrel, const size_t size ) {
61  if ( 1 != function.dimensionality() ) {
62  throw GaudiException( "GaudiMath::Integral: illegal function dimension", "*GaudiMath*", StatusCode::FAILURE );
63  }
64 
65  const Genfun::AbsFunction& one = Genfun::GaudiMathImplementation::Constant( 1.0, 1 );
66 
67  const Genfun::AbsFunction& cross = Genfun::FunctionDirectProduct( &one, &function );
68 
69  const Genfun::AbsFunction& result =
70  Genfun::GaudiMathImplementation::NumericalDefiniteIntegral( cross, 1, a, b, epsabs, epsrel, size );
71 
72  return result( Genfun::Argument( 1 ) );
73  }
74 
75  double Integral( const Genfun::AbsFunction& function, const GaudiMath::Integration::Inf a, const double b,
76  const double epsabs, const double epsrel, const size_t size ) {
77  if ( 1 != function.dimensionality() ) {
78  throw GaudiException( "GaudiMath::Integral: illegal function dimension", "*GaudiMath*", StatusCode::FAILURE );
79  }
80 
81  const Genfun::AbsFunction& one = Genfun::GaudiMathImplementation::Constant( 1.0, 1 );
82 
83  const Genfun::AbsFunction& cross = Genfun::FunctionDirectProduct( &one, &function );
84 
85  const Genfun::AbsFunction& result =
86  Genfun::GaudiMathImplementation::NumericalDefiniteIntegral( cross, 1, a, b, epsabs, epsrel, size );
87 
88  return result( Genfun::Argument( 1 ) );
89  }
90 
91  double Integral( const Genfun::AbsFunction& function, const GaudiMath::Integration::Inf /* a */,
92  const GaudiMath::Integration::Inf /* b */, const double epsabs, const double epsrel,
93  const size_t size ) {
94  if ( 1 != function.dimensionality() ) {
95  throw GaudiException( "GaudiMath::Integral: illegal function dimension", "*GaudiMath*", StatusCode::FAILURE );
96  }
97 
98  const Genfun::AbsFunction& one = Genfun::GaudiMathImplementation::Constant( 1.0, 1 );
99 
100  const Genfun::AbsFunction& cross = Genfun::FunctionDirectProduct( &one, &function );
101 
102  // FIXME: (MCl) the static_cast below are needed to avoid warnings and to
103  // match the signature in NumericalDefiniteIntegral.h (around line 288).
104  const Genfun::AbsFunction& result = Genfun::GaudiMathImplementation::NumericalDefiniteIntegral(
105  cross, 1, static_cast<float>( epsabs ), static_cast<float>( epsrel ), size );
106 
107  return result( Genfun::Argument( 1 ) );
108  }
109 } // namespace GaudiMath
110 
111 // ============================================================================
112 // The END
113 // ============================================================================
Define general base for Gaudi exception.
constexpr auto size(const C &c) noexcept(noexcept(c.size())) -> decltype(c.size())
Type
type of integration (for finite limits)
Definition: Integration.h:22
constexpr static const auto FAILURE
Definition: StatusCode.h:86
GaudiMath.h GaudiMath/GaudiMath.h.
Definition: Adapters.h:13
GAUDI_API double Integral(const Genfun::AbsFunction &function, const double a, const double b, const GaudiMath::Integration::Type type=GaudiMath::Integration::Adaptive, const GaudiMath::Integration::KronrodRule rule=GaudiMath::Integration::Default, const double epsabs=1.e-10, const double epsrel=1.e-7, const size_t size=1000)
Definition: Integral.cpp:25
KronrodRule
integration rule
Definition: Integration.h:26
Genfun::GaudiMathImplementation::Constant Constant
Definition: GaudiMath.h:25
This class allows the numerical evaluation of the following functions: