Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v31r0 (aeb156f0)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Splines.h
Go to the documentation of this file.
1 #ifndef GAUDIMATH_SPLINES_H
2 #define GAUDIMATH_SPLINES_H 1
3 // ============================================================================
4 // Include files
5 // ============================================================================
6 // STD/STL
7 // ============================================================================
8 #include <algorithm>
9 #include <memory>
10 #include <utility>
11 #include <vector>
12 // ============================================================================
13 // from CLHEP
14 // ============================================================================
15 #include "CLHEP/GenericFunctions/AbsFunction.hh"
16 #include "CLHEP/GenericFunctions/Argument.hh"
17 #include "CLHEP/GenericFunctions/GenericFunctions.hh"
18 // ============================================================================
19 // GaudiGSL/GaudiMath
20 // ============================================================================
22 // ============================================================================
23 // GSL
24 // ============================================================================
25 #include "gsl/gsl_interp.h"
26 #include "gsl/gsl_spline.h"
27 // ============================================================================
28 #include "GaudiKernel/Kernel.h"
29 
30 #ifdef __clang__
31 # pragma clang diagnostic push
32 # pragma clang diagnostic ignored "-Winconsistent-missing-override"
33 #endif
34 
35 namespace Genfun {
36  namespace GaudiMathImplementation {
37  namespace details {
38  struct gsl_deleter {
39  void operator()( gsl_spline* p ) {
40  if ( p ) gsl_spline_free( p );
41  }
42  void operator()( gsl_interp_accel* p ) {
43  if ( p ) gsl_interp_accel_free( p );
44  }
45  };
46  } // namespace details
47 
49  public:
52 
53  public:
59  SplineBase( const Data1D& x, const Data1D& y, const GaudiMath::Interpolation::Type type );
64  SplineBase( const Data2D& data, const GaudiMath::Interpolation::Type type );
71  template <class DATAX, class DATAY>
72  SplineBase( const GaudiMath::Interpolation::Type type, DATAX begin_x, DATAX end_x, DATAY begin_y )
73  : m_type( type ) {
74  auto size = std::distance( begin_x, end_x );
75  m_x.reserve( size );
76  std::copy_n( begin_x, size, std::back_inserter( m_x ) );
77  m_y.reserve( size );
78  std::copy_n( begin_y, size, std::back_inserter( m_y ) );
79  }
87  template <class DATA>
88  SplineBase( const GaudiMath::Interpolation::Type type, DATA begin, DATA end ) : m_type( type ) {
89  m_x.reserve( end - begin );
90  m_y.reserve( end - begin );
91  for ( ; begin != end; ++begin ) {
92  m_x.push_back( begin->first );
93  m_y.push_back( begin->second );
94  };
95  }
96 
98  SplineBase( SplineBase&& ) = default;
100  SplineBase& operator=( SplineBase&& rhs ) = default;
102  SplineBase( const SplineBase& rhs )
103  : m_x( rhs.m_x )
104  , m_y( rhs.m_y )
105  , m_type( rhs.m_type )
106  // note that we do NOT copy m_spline, m_accel!
107  {}
109  SplineBase& operator=( const SplineBase& rhs ) {
110  *this = SplineBase( rhs );
111  return *this;
112  }
113 
114  public:
116  double eval( const double x ) const;
118  double deriv( const double x ) const;
120  double deriv2( const double x ) const;
122  double integ( const double a, const double b ) const;
123 
124  protected:
125  // initialize
126  void initialize() const;
127 
128  private:
134  };
135 
136  class GAUDI_API GSLSpline : public AbsFunction {
137  public:
140 
141  public:
142  // mandatory macro from CLHEP/GenericFunctions
143  FUNCTION_OBJECT_DEF( GSLSpline )
144  public:
165  GSLSpline( const Data1D& x, const Data1D& y, const GaudiMath::Interpolation::Type type );
184  GSLSpline( const Data2D& data, const GaudiMath::Interpolation::Type type );
211  template <class DATAX, class DATAY>
212  GSLSpline( const GaudiMath::Interpolation::Type type, DATAX begin_x, DATAX end_x, DATAY begin_y )
213  : m_spline( type, begin_x, end_x, begin_y ) {}
225  template <class DATA>
226  GSLSpline( const GaudiMath::Interpolation::Type type, DATA begin, DATA end ) : m_spline( type, begin, end ) {}
228  GSLSpline( const SplineBase& );
229 
230  public:
232  double operator()( double a ) const override;
234  double operator()( const Argument& x ) const override;
235  unsigned int dimensionality() const override { return 1; }
237  bool hasAnalyticDerivative() const override { return true; }
239  Genfun::Derivative partial( unsigned int i ) const override;
240 
241  public:
243  inline const SplineBase& spline() const { return m_spline; }
245  operator const SplineBase&() const { return spline(); }
247  GSLSpline& operator=( const GSLSpline& ) = delete;
248 
249  private:
250  // the actual spline function
252  };
253  // mandatory macro from CLHEP/GenericFunctions
254  FUNCTION_OBJECT_IMP( GSLSpline )
255 
256  class GAUDI_API GSLSplineDeriv : public AbsFunction {
257  public:
260 
261  public:
262  // mandatory macro from CLHEP/GenericFunctions
263  FUNCTION_OBJECT_DEF( GSLSplineDeriv )
264  public:
285  GSLSplineDeriv( const Data1D& x, const Data1D& y, const GaudiMath::Interpolation::Type type );
304  GSLSplineDeriv( const Data2D& data, const GaudiMath::Interpolation::Type type );
331  template <class DATAX, class DATAY>
332  GSLSplineDeriv( const GaudiMath::Interpolation::Type type, DATAX begin_x, DATAX end_x, DATAY begin_y )
333  : AbsFunction(), m_spline( type, begin_x, end_x, begin_y ) {}
345  template <class DATA>
347  : AbsFunction(), m_spline( type, begin, end ) {}
349  GSLSplineDeriv( const SplineBase& );
351  GSLSplineDeriv( const GSLSplineDeriv& );
352 
353  public:
355  double operator()( double a ) const override;
357  double operator()( const Argument& x ) const override;
358  unsigned int dimensionality() const override { return 1; }
360  bool hasAnalyticDerivative() const override { return true; }
362  Genfun::Derivative partial( unsigned int i ) const override;
363 
364  public:
366  inline const SplineBase& spline() const { return m_spline; }
368  operator const SplineBase&() const { return spline(); }
369 
370  private:
372  GSLSplineDeriv();
375 
376  private:
377  // the actual spline function
379  };
380  // mandatory macro from CLHEP/GenericFunctions
381  FUNCTION_OBJECT_IMP( GSLSplineDeriv )
382 
383  class GAUDI_API GSLSplineDeriv2 : public AbsFunction {
384  public:
387 
388  public:
389  // mandatory macro from CLHEP/GenericFunctions
390  FUNCTION_OBJECT_DEF( GSLSplineDeriv2 )
391  public:
412  GSLSplineDeriv2( const Data1D& x, const Data1D& y, const GaudiMath::Interpolation::Type type );
431  GSLSplineDeriv2( const Data2D& data, const GaudiMath::Interpolation::Type type );
458  template <class DATAX, class DATAY>
459  GSLSplineDeriv2( const GaudiMath::Interpolation::Type type, DATAX begin_x, DATAX end_x, DATAY begin_y )
460  : AbsFunction(), m_spline( type, begin_x, end_x, begin_y ) {}
472  template <class DATA>
474  : AbsFunction(), m_spline( type, begin, end ) {}
476  GSLSplineDeriv2( const SplineBase& );
478  GSLSplineDeriv2( const GSLSplineDeriv2& ) = default;
479 
480  public:
482  double operator()( double a ) const override;
484  double operator()( const Argument& x ) const override;
485  unsigned int dimensionality() const override { return 1; }
487  bool hasAnalyticDerivative() const override { return true; }
489  Genfun::Derivative partial( unsigned int i ) const override;
490 
491  public:
493  inline const SplineBase& spline() const { return m_spline; }
495  operator const SplineBase&() const { return spline(); }
496 
497  private:
499  GSLSplineDeriv2& operator=( const GSLSplineDeriv2& ) = delete;
500 
501  private:
502  // the actual spline function
504  };
505  // mandatory macro from CLHEP/GenericFunctions
506  FUNCTION_OBJECT_IMP( GSLSplineDeriv2 )
507 
508  class GAUDI_API GSLSplineInteg : public AbsFunction {
509  public:
512 
513  public:
514  // mandatory macro from CLHEP/GenericFunctions
515  FUNCTION_OBJECT_DEF( GSLSplineInteg )
516  public:
537  GSLSplineInteg( const Data1D& x, const Data1D& y, const GaudiMath::Interpolation::Type type,
538  const double low = 0 );
558  GSLSplineInteg( const Data2D& data, const GaudiMath::Interpolation::Type type, const double low = 0 );
586  template <class DATAX, class DATAY>
587  GSLSplineInteg( const GaudiMath::Interpolation::Type type, DATAX begin_x, DATAX end_x, DATAY begin_y,
588  const double low )
589  : AbsFunction(), m_spline( type, begin_x, end_x, begin_y ), m_low( low ) {}
602  template <class DATA>
603  GSLSplineInteg( const GaudiMath::Interpolation::Type type, DATA&& begin, DATA&& end, const double low )
604  : m_spline( type, std::forward<DATA>( begin ), std::forward<DATA>( end ) ), m_low( low ) {}
606  GSLSplineInteg( const SplineBase&, const double low = 0 );
608  GSLSplineInteg( const GSLSplineInteg& ) = default;
609 
610  public:
612  double operator()( double a ) const override;
614  double operator()( const Argument& x ) const override;
615  unsigned int dimensionality() const override { return 1; }
617  bool hasAnalyticDerivative() const override { return true; }
619  Genfun::Derivative partial( unsigned int i ) const override;
620 
621  public:
623  inline const SplineBase& spline() const { return m_spline; }
625  operator const SplineBase&() const { return spline(); }
626 
627  private:
629  GSLSplineInteg& operator=( const GSLSplineInteg& ) = delete;
630 
631  private:
632  // the actual spline function
634  double m_low;
635  };
636  // mandatory macro from CLHEP/GenericFunctions
637  FUNCTION_OBJECT_IMP( GSLSplineInteg )
638  } // namespace GaudiMathImplementation
639 } // namespace Genfun
640 
641 #ifdef __clang__
642 # pragma clang diagnostic pop
643 #endif
644 
645 #endif // GAUDIMATH_SPLINES_H
SplineBase(const GaudiMath::Interpolation::Type type, DATA begin, DATA end)
templated constructor from the sequence of (x,y(x)) pairs as sequence of pairs the class TabulatedPro...
Definition: Splines.h:88
SplineBase(const SplineBase &rhs)
copy constructor
Definition: Splines.h:102
const SplineBase & spline() const
acess to the spline function
Definition: Splines.h:623
T distance(T...args)
std::vector< std::pair< double, double > > Data2D
Definition: Splines.h:51
GSLSplineDeriv2(const GaudiMath::Interpolation::Type type, DATA begin, DATA end)
templated constructor from the sequence of pairs as sequence of pairs the class TabulatedProperty can...
Definition: Splines.h:473
unsigned int dimensionality() const override
Definition: Splines.h:358
const SplineBase & spline() const
acess to the spline function
Definition: Splines.h:243
const SplineBase & spline() const
acess to the spline function
Definition: Splines.h:366
GSLSplineDeriv(const GaudiMath::Interpolation::Type type, DATA begin, DATA end)
templated constructor from the sequence of pairs as sequence of pairs the class TabulatedProperty can...
Definition: Splines.h:346
STL namespace.
std::unique_ptr< gsl_spline, details::gsl_deleter > m_spline
Definition: Splines.h:131
T copy_n(T...args)
#define class
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
GSLSplineInteg(const GaudiMath::Interpolation::Type type, DATA &&begin, DATA &&end, const double low)
templated constructor from the sequence of pairs as sequence of pairs the class TabulatedProperty can...
Definition: Splines.h:603
unsigned int dimensionality() const override
Definition: Splines.h:615
GSLSpline(const GaudiMath::Interpolation::Type type, DATA begin, DATA end)
templated constructor from the sequence of pairs as sequence of pairs the class TabulatedProperty can...
Definition: Splines.h:226
bool hasAnalyticDerivative() const override
Does this function have an analytic derivative?
Definition: Splines.h:487
GaudiMath::Interpolation::Type m_type
transient
Definition: Splines.h:133
SplineBase & operator=(const SplineBase &rhs)
assignment
Definition: Splines.h:109
SplineBase(const GaudiMath::Interpolation::Type type, DATAX begin_x, DATAX end_x, DATAY begin_y)
templated constructor in the spirit of STL-algorithms
Definition: Splines.h:72
unsigned int dimensionality() const override
Definition: Splines.h:235
bool hasAnalyticDerivative() const override
Does this function have an analytic derivative?
Definition: Splines.h:237
bool hasAnalyticDerivative() const override
Does this function have an analytic derivative?
Definition: Splines.h:617
T back_inserter(T...args)
bool hasAnalyticDerivative() const override
Does this function have an analytic derivative?
Definition: Splines.h:360
GaudiMath.h GaudiMath/GaudiMath.h.
Definition: Adapters.h:13
std::unique_ptr< gsl_interp_accel, details::gsl_deleter > m_accel
transient
Definition: Splines.h:132
CLHEP.
Definition: IEqSolver.h:13
const SplineBase & spline() const
acess to the spline function
Definition: Splines.h:493
AttribStringParser::Iterator begin(const AttribStringParser &parser)
#define GAUDI_API
Definition: Kernel.h:71
Type
the list of available types for ntuples
Definition: TupleObj.h:80
unsigned int dimensionality() const override
Definition: Splines.h:485