The Gaudi Framework  v30r3 (a5ef0a68)
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 {
35  namespace GaudiMathImplementation
36  {
80  class GAUDI_API NumericalDefiniteIntegral : public AbsFunction
81  {
82  public:
83  struct _Workspace {
84  gsl_integration_workspace* ws;
85  };
86  struct _Function;
87 
88  public:
91 
92  public:
94  FUNCTION_OBJECT_DEF( NumericalDefiniteIntegral )
95 
96  public:
148  NumericalDefiniteIntegral( const AbsFunction& function, const size_t index, const double a, const double b,
151  const double epsabs = 1.e-10, const double epsrel = 1.e-7, const size_t size = 1000 );
152 
181  NumericalDefiniteIntegral( const AbsFunction& function, const size_t index, const double a, const double b,
182  const Points& points, const double epsabs = 1e-9, const double epsrel = 1.e-6,
183  const size_t size = 1000 );
184 
210  NumericalDefiniteIntegral( const AbsFunction& function, const size_t index, const double a,
212  const double epsabs = 1e-9, const double epsrel = 1.e-6, const size_t size = 1000 );
213 
239  NumericalDefiniteIntegral( const AbsFunction& function, const size_t index, const GaudiMath::Integration::Inf a,
240  const double b, const double epsabs = 1e-9, const double epsrel = 1.e-6,
241  const size_t size = 1000 );
242 
266  NumericalDefiniteIntegral( const AbsFunction& function, const size_t index,
267  // FIXME: The next two arguments should be "double" but are "float" to resolve the
268  // ambiguity with the first constructor when providing
269  // '(const Genfun::AbsFunction, const unsigned int, const double, const double)'
270  const float epsabs = 1e-9, const float epsrel = 1.e-6, const size_t size = 1000 );
271 
274 
275  public:
277  unsigned int dimensionality() const override { return m_DIM; }
278 
280  double operator()( double argument ) const override;
282  double operator()( const Argument& argument ) const override;
283 
285  bool hasAnalyticDerivative() const override { return true; }
286 
288  Genfun::Derivative partial( unsigned int index ) const override;
289 
290  public:
292  const AbsFunction& function() const { return *m_function; }
294  double a() const { return m_a; }
295  double b() const { return m_b; }
297  const Points& points() const { return m_points; }
299  double epsabs() const { return m_epsabs; }
301  double epsrel() const { return m_epsrel; }
302 
304  double result() const { return m_result; }
306  double error() const { return m_error; }
307 
308  // maximal number of bisection integvals for adaptive algorithms
309  size_t size() const { return m_size; }
310 
312  GaudiMath::Integration::Type type() const { return m_type; }
314  GaudiMath::Integration::Category category() const { return m_category; }
316  GaudiMath::Integration::KronrodRule rule() const { return m_rule; }
317 
318  protected:
319  // adaptive integration on infinite intervals
320  double QAGI( _Function* fun ) const;
321  // adaptive integration with known singular points
322  double QAGP( _Function* fun ) const;
323  // non-adaptive integration
324  double QNG( _Function* fun ) const;
325  // adaptive integration
326  double QAG( _Function* fun ) const;
327  // adaptive integral with singularities
328  double QAGS( _Function* fun ) const;
329 
330  // allocate the integration workspace
331  _Workspace* allocate() const;
332  // the integration workspace
333  _Workspace* ws() const { return m_ws.get(); };
334 
335  // throw the exception
336  StatusCode Exception( const std::string& message, const StatusCode& sc = StatusCode::FAILURE ) const;
337 
338  private:
339  // defautl constructor is disabled
341  // assignement is disabled
343 
344  public:
345  struct gsl_ws_deleter {
346  void operator()( _Workspace* p ) const
347  {
348  if ( p ) gsl_integration_workspace_free( p->ws );
349  delete p;
350  }
351  };
352 
353  private:
355  size_t m_DIM = 0;
356  size_t m_index;
357 
360 
364 
365  Points m_points;
366 
367  double m_epsabs;
368  double m_epsrel;
369 
370  mutable double m_result = -std::numeric_limits<double>::infinity();
371  mutable double m_error = std::numeric_limits<double>::infinity();
372 
373  size_t m_size;
375 
376  mutable Argument m_argument;
377  mutable Argument m_argF;
378  };
380  FUNCTION_OBJECT_IMP( NumericalDefiniteIntegral )
381 
382  } // end of namespace GaudiMathImplementation
383 } // end of namespace Genfun
384 
385 #if defined( __clang__ ) || defined( __CLING__ )
386 #pragma clang diagnostic pop
387 #elif defined( __GNUC__ ) && __GNUC__ >= 5
388 #pragma GCC diagnostic pop
389 #endif
390 
391 // ============================================================================
392 // The END
393 // ============================================================================
394 #endif // GAUDIMATH_NUMERICALDEFINITEINTEGRAL_H
constexpr static const auto FAILURE
Definition: StatusCode.h:88
GaudiMath::Integration::Category category() const
integration category
Category
integration category
Definition: Integration.h:26
Genfun::GaudiMathImplementation::NumericalDerivative Derivative
Definition: GaudiMath.h:27
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:51
Type
type of integration (for finite limits)
Definition: Integration.h:24
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
GaudiMath.h GaudiMath/GaudiMath.h.
KronrodRule
integration rule
Definition: Integration.h:28
#define GAUDI_API
Definition: Kernel.h:104
Type
the list of available types for ntuples
Definition: TupleObj.h:83
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: