The Gaudi Framework  v30r1 (5d4f4ae2)
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 
274  public:
276  unsigned int dimensionality() const override { return m_DIM; }
277 
279  double operator()( double argument ) const override;
281  double operator()( const Argument& argument ) const override;
282 
284  bool hasAnalyticDerivative() const override { return true; }
285 
287  Genfun::Derivative partial( unsigned int index ) const override;
288 
289  public:
291  const AbsFunction& function() const { return *m_function; }
293  double a() const { return m_a; }
294  double b() const { return m_b; }
296  const Points& points() const { return m_points; }
298  double epsabs() const { return m_epsabs; }
300  double epsrel() const { return m_epsrel; }
301 
303  double result() const { return m_result; }
305  double error() const { return m_error; }
306 
307  // maximal number of bisection integvals for adaptive algorithms
308  size_t size() const { return m_size; }
309 
311  GaudiMath::Integration::Type type() const { return m_type; }
313  GaudiMath::Integration::Category category() const { return m_category; }
315  GaudiMath::Integration::KronrodRule rule() const { return m_rule; }
316 
317  protected:
318  // adaptive integration on infinite intervals
319  double QAGI( _Function* fun ) const;
320  // adaptive integration with known singular points
321  double QAGP( _Function* fun ) const;
322  // non-adaptive integration
323  double QNG( _Function* fun ) const;
324  // adaptive integration
325  double QAG( _Function* fun ) const;
326  // adaptive integral with singularities
327  double QAGS( _Function* fun ) const;
328 
329  // allocate the integration workspace
330  _Workspace* allocate() const;
331  // the integration workspace
332  _Workspace* ws() const { return m_ws.get(); };
333 
334  // throw the exception
335  StatusCode Exception( const std::string& message, const StatusCode& sc = StatusCode::FAILURE ) const;
336 
337  private:
338  // defautl constructor is disabled
340  // assignement is disabled
342 
343  public:
344  struct gsl_ws_deleter {
345  void operator()( _Workspace* p ) const
346  {
347  if ( p ) gsl_integration_workspace_free( p->ws );
348  delete p;
349  }
350  };
351 
352  private:
354  size_t m_DIM = 0;
355  size_t m_index;
356 
359 
363 
364  Points m_points;
365 
366  double m_epsabs;
367  double m_epsrel;
368 
369  mutable double m_result = -std::numeric_limits<double>::infinity();
370  mutable double m_error = std::numeric_limits<double>::infinity();
371 
372  size_t m_size;
374 
375  mutable Argument m_argument;
376  mutable Argument m_argF;
377  };
379  FUNCTION_OBJECT_IMP( NumericalDefiniteIntegral )
380 
381  } // end of namespace GaudiMathImplementation
382 } // end of namespace Genfun
383 
384 #if defined( __clang__ ) || defined( __CLING__ )
385 #pragma clang diagnostic pop
386 #elif defined( __GNUC__ ) && __GNUC__ >= 5
387 #pragma GCC diagnostic pop
388 #endif
389 
390 // ============================================================================
391 // The END
392 // ============================================================================
393 #endif // GAUDIMATH_NUMERICALDEFINITEINTEGRAL_H
394 // ============================================================================
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:26
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: