Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v31r0 (aeb156f0)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
NumericalDefiniteIntegral.h
Go to the documentation of this file.
1 #ifndef GAUDIMATH_NUMERICALDEFINITEINTEGRAL_H
2 #define GAUDIMATH_NUMERICALDEFINITEINTEGRAL_H 1
3 // ============================================================================
4 // Include files
5 // ============================================================================
6 // STD & STL
7 // ============================================================================
8 #include <memory>
9 #include <string>
10 // ============================================================================
11 // GaudiKernel
12 // ============================================================================
13 #include "GaudiKernel/StatusCode.h"
14 // ============================================================================
15 // GaudiMath
16 // ============================================================================
17 #include "GaudiMath/Integration.h"
18 // ============================================================================
19 // CLHEP
20 // ============================================================================
21 #include "CLHEP/GenericFunctions/AbsFunction.hh"
22 // ============================================================================
23 #include "gsl/gsl_integration.h"
24 
25 #if defined( __clang__ ) || defined( __CLING__ )
26 # pragma clang diagnostic push
27 # pragma clang diagnostic ignored "-Winconsistent-missing-override"
28 #elif defined( __GNUC__ ) && __GNUC__ >= 5
29 # pragma GCC diagnostic push
30 # pragma GCC diagnostic ignored "-Wsuggest-override"
31 #endif
32 
33 namespace Genfun {
34  namespace GaudiMathImplementation {
78  class GAUDI_API NumericalDefiniteIntegral : public AbsFunction {
79  public:
80  struct _Workspace {
81  gsl_integration_workspace* ws;
82  };
83  struct _Function;
84 
85  public:
88 
89  public:
91  FUNCTION_OBJECT_DEF( NumericalDefiniteIntegral )
92 
93  public:
145  NumericalDefiniteIntegral( const AbsFunction& function, const size_t index, const double a, const double b,
148  const double epsabs = 1.e-10, const double epsrel = 1.e-7, const size_t size = 1000 );
149 
178  NumericalDefiniteIntegral( const AbsFunction& function, const size_t index, const double a, const double b,
179  const Points& points, const double epsabs = 1e-9, const double epsrel = 1.e-6,
180  const size_t size = 1000 );
181 
207  NumericalDefiniteIntegral( const AbsFunction& function, const size_t index, const double a,
209  const double epsabs = 1e-9, const double epsrel = 1.e-6, const size_t size = 1000 );
210 
236  NumericalDefiniteIntegral( const AbsFunction& function, const size_t index, const GaudiMath::Integration::Inf a,
237  const double b, const double epsabs = 1e-9, const double epsrel = 1.e-6,
238  const size_t size = 1000 );
239 
263  NumericalDefiniteIntegral( const AbsFunction& function, const size_t index,
264  // FIXME: The next two arguments should be "double" but are "float" to resolve the
265  // ambiguity with the first constructor when providing
266  // '(const Genfun::AbsFunction, const unsigned int, const double, const double)'
267  const float epsabs = 1e-9, const float epsrel = 1.e-6, const size_t size = 1000 );
268 
271 
272  public:
274  unsigned int dimensionality() const override { return m_DIM; }
275 
277  double operator()( double argument ) const override;
279  double operator()( const Argument& argument ) const override;
280 
282  bool hasAnalyticDerivative() const override { return true; }
283 
285  Genfun::Derivative partial( unsigned int index ) const override;
286 
287  public:
289  const AbsFunction& function() const { return *m_function; }
291  double a() const { return m_a; }
292  double b() const { return m_b; }
294  const Points& points() const { return m_points; }
296  double epsabs() const { return m_epsabs; }
298  double epsrel() const { return m_epsrel; }
299 
301  double result() const { return m_result; }
303  double error() const { return m_error; }
304 
305  // maximal number of bisection integvals for adaptive algorithms
306  size_t size() const { return m_size; }
307 
309  GaudiMath::Integration::Type type() const { return m_type; }
311  GaudiMath::Integration::Category category() const { return m_category; }
313  GaudiMath::Integration::KronrodRule rule() const { return m_rule; }
314 
315  protected:
316  // adaptive integration on infinite intervals
317  double QAGI( _Function* fun ) const;
318  // adaptive integration with known singular points
319  double QAGP( _Function* fun ) const;
320  // non-adaptive integration
321  double QNG( _Function* fun ) const;
322  // adaptive integration
323  double QAG( _Function* fun ) const;
324  // adaptive integral with singularities
325  double QAGS( _Function* fun ) const;
326 
327  // allocate the integration workspace
328  _Workspace* allocate() const;
329  // the integration workspace
330  _Workspace* ws() const { return m_ws.get(); };
331 
332  // throw the exception
333  StatusCode Exception( const std::string& message, const StatusCode& sc = StatusCode::FAILURE ) const;
334 
335  private:
336  // defautl constructor is disabled
338  // assignement is disabled
340 
341  public:
342  struct gsl_ws_deleter {
343  void operator()( _Workspace* p ) const {
344  if ( p ) gsl_integration_workspace_free( p->ws );
345  delete p;
346  }
347  };
348 
349  private:
351  size_t m_DIM = 0;
352  size_t m_index;
353 
356 
360 
361  Points m_points;
362 
363  double m_epsabs;
364  double m_epsrel;
365 
366  mutable double m_result = -std::numeric_limits<double>::infinity();
367  mutable double m_error = std::numeric_limits<double>::infinity();
368 
369  size_t m_size;
371 
372  mutable Argument m_argument;
373  mutable Argument m_argF;
374  };
376  FUNCTION_OBJECT_IMP( NumericalDefiniteIntegral )
377 
378  } // end of namespace GaudiMathImplementation
379 } // end of namespace Genfun
380 
381 #if defined( __clang__ ) || defined( __CLING__ )
382 # pragma clang diagnostic pop
383 #elif defined( __GNUC__ ) && __GNUC__ >= 5
384 # pragma GCC diagnostic pop
385 #endif
386 
387 // ============================================================================
388 // The END
389 // ============================================================================
390 #endif // GAUDIMATH_NUMERICALDEFINITEINTEGRAL_H
GaudiMath::Integration::Category category() const
integration category
Category
integration category
Definition: Integration.h:24
Genfun::GaudiMathImplementation::NumericalDerivative Derivative
Definition: GaudiMath.h:26
constexpr auto size(const C &c) noexcept(noexcept(c.size())) -> decltype(c.size())
PropertyMgr & operator=(const PropertyMgr &)=delete
STL class.
bool hasAnalyticDerivative() const override
Does this function have an analytic derivative?
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
Type
type of integration (for finite limits)
Definition: Integration.h:22
T infinity(T...args)
GaudiMath::Integration::Type type() const
integration type
std::vector< double > Points
typedef for vector of singular points
virtual Out operator()(const vector_of_const_< In > &inputs) const =0
double fun(const std::vector< double > &x)
Definition: PFuncTest.cpp:26
constexpr static const auto FAILURE
Definition: StatusCode.h:86
GaudiMath.h GaudiMath/GaudiMath.h.
Definition: Adapters.h:13
KronrodRule
integration rule
Definition: Integration.h:26
CLHEP.
Definition: IEqSolver.h:13
#define GAUDI_API
Definition: Kernel.h:71
Type
the list of available types for ntuples
Definition: TupleObj.h:80
GaudiMath::Integration::KronrodRule rule() const
integration rule
collection of common types for classes NumericalIndefiniteIntegral and NumericalDefiniteIntegral ...
This class allows the numerical evaluation of the following functions: