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 namespace Genfun
25 {
26  namespace GaudiMathImplementation
27  {
71  class GAUDI_API NumericalDefiniteIntegral : public AbsFunction
72  {
73  public:
74  struct _Workspace { gsl_integration_workspace* ws ; };
75  struct _Function ;
76  public:
77 
79  typedef std::vector<double> Points ;
80 
81  public:
82 
84  FUNCTION_OBJECT_DEF( NumericalDefiniteIntegral )
85 
86  public:
87 
140  ( const AbsFunction& function ,
141  const size_t index ,
142  const double a ,
143  const double b ,
144  const GaudiMath::Integration::Type type =
146  const GaudiMath::Integration::KronrodRule rule =
148  const double epsabs = 1.e-10 ,
149  const double epsrel = 1.e-7 ,
150  const size_t size = 1000 );
151 
152 
182  ( const AbsFunction& function ,
183  const size_t index ,
184  const double a ,
185  const double b ,
186  const Points& points ,
187  const double epsabs = 1e-9 ,
188  const double epsrel = 1.e-6 ,
189  const size_t size = 1000 ) ;
190 
191 
218  ( const AbsFunction& function ,
219  const size_t index ,
220  const double a ,
221  const GaudiMath::Integration::Inf b =
223  const double epsabs = 1e-9 ,
224  const double epsrel = 1.e-6 ,
225  const size_t size = 1000 ) ;
226 
253  ( const AbsFunction& function ,
254  const size_t index ,
255  const GaudiMath::Integration::Inf a ,
256  const double b ,
257  const double epsabs = 1e-9 ,
258  const double epsrel = 1.e-6 ,
259  const size_t size = 1000 ) ;
260 
285  ( const AbsFunction& function ,
286  const size_t index ,
287  // FIXME: The next two arguments should be "double" but are "float" to resolve the
288  // ambiguity with the first constructor when providing
289  // '(const Genfun::AbsFunction, const unsigned int, const double, const double)'
290  const float epsabs = 1e-9 ,
291  const float epsrel = 1.e-6 ,
292  const size_t size = 1000 ) ;
293 
296 
298  virtual ~NumericalDefiniteIntegral() = default;
299 
300  public:
301 
303  virtual unsigned int dimensionality() const { return m_DIM ; }
304 
306  virtual double operator() ( double argument ) const ;
308  virtual double operator() ( const Argument& argument ) const ;
309 
311  virtual bool hasAnalyticDerivative() const { return true ;}
312 
314  virtual Genfun::Derivative partial ( unsigned int index ) const;
315 
316  public:
317 
319  const AbsFunction& function () const { return *m_function ; }
321  double a () const { return m_a ; }
322  double b () const { return m_b ; }
324  const Points& points () const { return m_points ; }
326  double epsabs () const { return m_epsabs ; }
328  double epsrel () const { return m_epsrel ; }
329 
331  double result () const { return m_result ; }
333  double error () const { return m_error ; }
334 
335  // maximal number of bisection integvals for adaptive algorithms
336  size_t size () const { return m_size ; }
337 
340  type () const { return m_type ; }
343  category () const { return m_category ; }
346  rule () const { return m_rule ; }
347 
348  protected:
349 
350  // adaptive integration on infinite intervals
351  double QAGI ( _Function* fun ) const ;
352  // adaptive integration with known singular points
353  double QAGP ( _Function* fun ) const ;
354  // non-adaptive integration
355  double QNG ( _Function* fun ) const ;
356  // adaptive integration
357  double QAG ( _Function* fun ) const ;
358  // adaptive integral with singularities
359  double QAGS ( _Function* fun ) const ;
360 
361  // allocate the integration workspace
362  _Workspace* allocate () const ;
363  // the integration workspace
364  _Workspace* ws () const
365  { return m_ws.get() ; };
366 
367  // throw the exception
368  StatusCode Exception
369  ( const std::string& message ,
370  const StatusCode& sc = StatusCode::FAILURE ) const ;
371 
372  private:
373 
374  // defautl constructor is disabled
376  // assignement is disabled
378 
379  public:
380  struct gsl_ws_deleter {
381  void operator()(_Workspace *p) const {
382  if (p) gsl_integration_workspace_free ( p->ws ) ;
383  delete p;
384  }
385  };
386  private:
387 
389  size_t m_DIM ;
390  size_t m_index ;
391 
392  double m_a ;
393  double m_b ;
394  bool m_ia ;
395  bool m_ib ;
396 
400 
401  Points m_points ;
403 
404  double m_epsabs ;
405  double m_epsrel ;
406 
407  mutable double m_result ;
408  mutable double m_error ;
409 
410  size_t m_size ;
412 
413  mutable Argument m_argument ;
414  mutable Argument m_argF ;
415 
416  };
417 
418  } // end of namespace GaudiMathImplementation
419 } // end of namespace Genfun
420 
421 // ============================================================================
422 // The END
423 // ============================================================================
424 #endif // GAUDIMATH_NUMERICALDEFINITEINTEGRAL_H
425 // ============================================================================
virtual bool hasAnalyticDerivative() const
Does this function have an analytic derivative?
GaudiMath::Integration::Category category() const
integration category
Category
integration category
Definition: Integration.h:30
Genfun::GaudiMathImplementation::NumericalDerivative Derivative
Definition: GaudiMath.h:29
STL class.
string type
Definition: gaudirun.py:151
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:25
GaudiMath::Integration::Type type() const
integration type
std::vector< double > Points
typedef for vector of singular points
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:34
CLHEP.
Definition: IEqSolver.h:13
#define GAUDI_API
Definition: Kernel.h:107
Type
the list of available types for ntuples
Definition: TupleObj.h:79
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: