The Gaudi Framework  v29r0 (ff2e7097)
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 <string>
9 // ============================================================================
10 // GaudiKernel
11 // ============================================================================
12 #include "GaudiKernel/StatusCode.h"
13 // ============================================================================
14 // GaudiMath
15 // ============================================================================
16 #include "GaudiMath/Integration.h"
17 // ============================================================================
18 // CLHEP
19 // ============================================================================
20 #include "CLHEP/GenericFunctions/AbsFunction.hh"
21 // ============================================================================
22 #include "gsl/gsl_integration.h"
23 
24 #if defined( __clang__ ) || defined( __CLING__ )
25 #pragma clang diagnostic push
26 #pragma clang diagnostic ignored "-Winconsistent-missing-override"
27 #elif defined( __GNUC__ ) && __GNUC__ >= 5
28 #pragma GCC diagnostic push
29 #pragma GCC diagnostic ignored "-Wsuggest-override"
30 #endif
31 
32 namespace Genfun
33 {
34  namespace GaudiMathImplementation
35  {
79  class GAUDI_API NumericalDefiniteIntegral : public AbsFunction
80  {
81  public:
82  struct _Workspace {
83  gsl_integration_workspace* ws;
84  };
85  struct _Function;
86 
87  public:
90 
91  public:
93  FUNCTION_OBJECT_DEF( NumericalDefiniteIntegral )
94 
95  public:
147  NumericalDefiniteIntegral( const AbsFunction& function, const size_t index, const double a, const double b,
150  const double epsabs = 1.e-10, const double epsrel = 1.e-7, const size_t size = 1000 );
151 
180  NumericalDefiniteIntegral( const AbsFunction& function, const size_t index, const double a, const double b,
181  const Points& points, const double epsabs = 1e-9, const double epsrel = 1.e-6,
182  const size_t size = 1000 );
183 
209  NumericalDefiniteIntegral( const AbsFunction& function, const size_t index, const double a,
211  const double epsabs = 1e-9, const double epsrel = 1.e-6, const size_t size = 1000 );
212 
238  NumericalDefiniteIntegral( const AbsFunction& function, const size_t index, const GaudiMath::Integration::Inf a,
239  const double b, const double epsabs = 1e-9, const double epsrel = 1.e-6,
240  const size_t size = 1000 );
241 
265  NumericalDefiniteIntegral( const AbsFunction& function, const size_t index,
266  // FIXME: The next two arguments should be "double" but are "float" to resolve the
267  // ambiguity with the first constructor when providing
268  // '(const Genfun::AbsFunction, const unsigned int, const double, const double)'
269  const float epsabs = 1e-9, const float epsrel = 1.e-6, const size_t size = 1000 );
270 
273 
275  ~NumericalDefiniteIntegral() override = default;
276 
277  public:
279  unsigned int dimensionality() const override { return m_DIM; }
280 
282  double operator()( double argument ) const override;
284  double operator()( const Argument& argument ) const override;
285 
287  bool hasAnalyticDerivative() const override { return true; }
288 
290  Genfun::Derivative partial( unsigned int index ) const override;
291 
292  public:
294  const AbsFunction& function() const { return *m_function; }
296  double a() const { return m_a; }
297  double b() const { return m_b; }
299  const Points& points() const { return m_points; }
301  double epsabs() const { return m_epsabs; }
303  double epsrel() const { return m_epsrel; }
304 
306  double result() const { return m_result; }
308  double error() const { return m_error; }
309 
310  // maximal number of bisection integvals for adaptive algorithms
311  size_t size() const { return m_size; }
312 
314  GaudiMath::Integration::Type type() const { return m_type; }
316  GaudiMath::Integration::Category category() const { return m_category; }
318  GaudiMath::Integration::KronrodRule rule() const { return m_rule; }
319 
320  protected:
321  // adaptive integration on infinite intervals
322  double QAGI( _Function* fun ) const;
323  // adaptive integration with known singular points
324  double QAGP( _Function* fun ) const;
325  // non-adaptive integration
326  double QNG( _Function* fun ) const;
327  // adaptive integration
328  double QAG( _Function* fun ) const;
329  // adaptive integral with singularities
330  double QAGS( _Function* fun ) const;
331 
332  // allocate the integration workspace
333  _Workspace* allocate() const;
334  // the integration workspace
335  _Workspace* ws() const { return m_ws.get(); };
336 
337  // throw the exception
338  StatusCode Exception( const std::string& message, const StatusCode& sc = StatusCode::FAILURE ) const;
339 
340  private:
341  // defautl constructor is disabled
343  // assignement is disabled
345 
346  public:
347  struct gsl_ws_deleter {
348  void operator()( _Workspace* p ) const
349  {
350  if ( p ) gsl_integration_workspace_free( p->ws );
351  delete p;
352  }
353  };
354 
355  private:
357  size_t m_DIM = 0;
358  size_t m_index;
359 
362 
366 
367  Points m_points;
368 
369  double m_epsabs;
370  double m_epsrel;
371 
372  mutable double m_result = -std::numeric_limits<double>::infinity();
373  mutable double m_error = std::numeric_limits<double>::infinity();
374 
375  size_t m_size;
377 
378  mutable Argument m_argument;
379  mutable Argument m_argF;
380  };
382  FUNCTION_OBJECT_IMP( NumericalDefiniteIntegral )
383 
384  } // end of namespace GaudiMathImplementation
385 } // end of namespace Genfun
386 
387 #if defined( __clang__ ) || defined( __CLING__ )
388 #pragma clang diagnostic pop
389 #elif defined( __GNUC__ ) && __GNUC__ >= 5
390 #pragma GCC diagnostic pop
391 #endif
392 
393 // ============================================================================
394 // The END
395 // ============================================================================
396 #endif // GAUDIMATH_NUMERICALDEFINITEINTEGRAL_H
397 // ============================================================================
GaudiMath::Integration::Category category() const
integration category
Category
integration category
Definition: Integration.h:26
Genfun::GaudiMathImplementation::NumericalDerivative Derivative
Definition: GaudiMath.h:27
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:28
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.
Definition: Adapters.h:13
KronrodRule
integration rule
Definition: Integration.h:28
CLHEP.
Definition: IEqSolver.h:13
#define GAUDI_API
Definition: Kernel.h:110
Type
the list of available types for ntuples
Definition: TupleObj.h:84
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: