The Gaudi Framework  v28r3 (cc1cf868)
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 <vector>
9 #include <utility>
10 #include <algorithm>
11 #include <memory>
12 // ============================================================================
13 // from CLHEP
14 // ============================================================================
15 #include "CLHEP/GenericFunctions/GenericFunctions.hh"
16 #include "CLHEP/GenericFunctions/Argument.hh"
17 #include "CLHEP/GenericFunctions/AbsFunction.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 {
37  namespace GaudiMathImplementation
38  {
39  namespace details {
40  struct gsl_deleter {
41  void operator()(gsl_spline* p) { if (p) gsl_spline_free(p); }
42  void operator()(gsl_interp_accel* p) { if (p) gsl_interp_accel_free(p); }
43  };
44  }
45 
47  {
48  public:
51  public:
58  ( const Data1D& x ,
59  const Data1D& y ,
66  ( const Data2D& data ,
74  template <class DATAX, class DATAY>
77  DATAX begin_x ,
78  DATAX end_x ,
79  DATAY begin_y )
80  : m_type ( type )
81  {
82  auto size = std::distance(begin_x,end_x);
83  m_x.reserve(size);
84  std::copy_n ( begin_x , size , std::back_inserter(m_x) ) ;
85  m_y.reserve(size);
86  std::copy_n ( begin_y , size , std::back_inserter(m_y) ) ;
87  }
95  template <class DATA>
98  DATA begin ,
99  DATA end )
100  : m_type ( type )
101  {
102  m_x.reserve(end-begin);
103  m_y.reserve(end-begin);
104  for ( ; begin != end ; ++begin ) {
105  m_x.push_back( begin -> first ) ;
106  m_y.push_back( begin -> second) ;
107  };
108  }
109 
111  SplineBase( SplineBase&& ) = default;
113  SplineBase& operator=( SplineBase&& rhs ) = default;
115  SplineBase( const SplineBase& rhs)
116  : m_x ( rhs.m_x )
117  , m_y ( rhs.m_y )
118  , m_type ( rhs.m_type )
119  // note that we do NOT copy m_spline, m_accel!
120  {}
122  SplineBase& operator=( const SplineBase& rhs ) { *this = SplineBase(rhs); return *this; }
123 
124  public:
126  double eval ( const double x ) const ;
128  double deriv ( const double x ) const ;
130  double deriv2 ( const double x ) const ;
132  double integ ( const double a , const double b ) const ;
133  protected:
134  // initialize
135  void initialize () const ;
136  private:
142  };
143 
144  class GAUDI_API GSLSpline : public AbsFunction
145  {
146  public:
149  public:
151  FUNCTION_OBJECT_DEF( GSLSpline )
152  public:
173  GSLSpline
174  ( const Data1D& x ,
175  const Data1D& y ,
176  const GaudiMath::Interpolation::Type type ) ;
195  GSLSpline
196  ( const Data2D& data ,
197  const GaudiMath::Interpolation::Type type ) ;
224  template <class DATAX, class DATAY>
225  GSLSpline
226  ( const GaudiMath::Interpolation::Type type ,
227  DATAX begin_x ,
228  DATAX end_x ,
229  DATAY begin_y )
230  : m_spline( type , begin_x , end_x , begin_y )
231  {}
243  template <class DATA>
245  DATA begin ,
246  DATA end )
247  : m_spline( type , begin , end )
248  {}
250  GSLSpline ( const SplineBase& ) ;
251  public:
253  double operator() ( double a ) const override ;
255  double operator() ( const Argument& x ) const override ;
256  unsigned int dimensionality () const override { return 1 ; }
258  bool hasAnalyticDerivative() const override { return true ; }
260  Genfun::Derivative partial( unsigned int i ) const override ;
261  public:
263  inline const SplineBase& spline() const { return m_spline ; }
265  operator const SplineBase& () const { return spline() ; }
267  GSLSpline& operator=( const GSLSpline& ) = delete;
268  private:
269  // the actual spline function
271  };
272 
273  class GAUDI_API GSLSplineDeriv : public AbsFunction
274  {
275  public:
278  public:
280  FUNCTION_OBJECT_DEF( GSLSplineDeriv )
281  public:
303  ( const Data1D& x ,
304  const Data1D& y ,
305  const GaudiMath::Interpolation::Type type ) ;
325  ( const Data2D& data ,
326  const GaudiMath::Interpolation::Type type ) ;
353  template <class DATAX, class DATAY>
355  ( const GaudiMath::Interpolation::Type type ,
356  DATAX begin_x ,
357  DATAX end_x ,
358  DATAY begin_y )
359  : AbsFunction ( )
360  , m_spline( type , begin_x , end_x , begin_y )
361  {}
373  template <class DATA>
376  DATA begin ,
377  DATA end )
378  : AbsFunction ( )
379  , m_spline( type , begin , end )
380  {}
382  GSLSplineDeriv ( const SplineBase& ) ;
384  GSLSplineDeriv ( const GSLSplineDeriv& ) ;
385  public:
387  double operator() ( double a ) const override;
389  double operator() ( const Argument& x ) const override;
390  unsigned int dimensionality () const override { return 1 ; }
392  bool hasAnalyticDerivative() const override { return true ; }
394  Genfun::Derivative partial( unsigned int i ) const override ;
395  public:
397  inline const SplineBase& spline() const { return m_spline ; }
399  operator const SplineBase& () const { return spline() ; }
400  private:
402  GSLSplineDeriv() ;
405  private:
406  // the actual spline function
408  };
409 
410  class GAUDI_API GSLSplineDeriv2 : public AbsFunction
411  {
412  public:
415  public:
417  FUNCTION_OBJECT_DEF( GSLSplineDeriv2 )
418  public:
440  ( const Data1D& x ,
441  const Data1D& y ,
442  const GaudiMath::Interpolation::Type type ) ;
462  ( const Data2D& data ,
463  const GaudiMath::Interpolation::Type type ) ;
490  template <class DATAX, class DATAY>
492  ( const GaudiMath::Interpolation::Type type ,
493  DATAX begin_x ,
494  DATAX end_x ,
495  DATAY begin_y )
496  : AbsFunction ( )
497  , m_spline( type , begin_x , end_x , begin_y )
498  {}
510  template <class DATA>
513  DATA begin ,
514  DATA end )
515  : AbsFunction ( )
516  , m_spline( type , begin , end )
517  {}
519  GSLSplineDeriv2 ( const SplineBase& ) ;
521  GSLSplineDeriv2 ( const GSLSplineDeriv2& ) = default;
522  public:
524  double operator() ( double a ) const override;
526  double operator() ( const Argument& x ) const override;
527  unsigned int dimensionality () const override { return 1 ; }
529  bool hasAnalyticDerivative() const override { return true ; }
531  Genfun::Derivative partial( unsigned int i ) const override;
532  public:
534  inline const SplineBase& spline() const { return m_spline ; }
536  operator const SplineBase& () const { return spline() ; }
537  private:
539  GSLSplineDeriv2& operator=( const GSLSplineDeriv2& ) = delete;
540  private:
541  // the actual spline function
543  };
544 
545 
546  class GAUDI_API GSLSplineInteg : public AbsFunction
547  {
548  public:
551  public:
553  FUNCTION_OBJECT_DEF( GSLSplineInteg )
554  public:
576  ( const Data1D& x ,
577  const Data1D& y ,
578  const GaudiMath::Interpolation::Type type ,
579  const double low = 0 ) ;
600  ( const Data2D& data ,
601  const GaudiMath::Interpolation::Type type ,
602  const double low = 0 ) ;
630  template <class DATAX, class DATAY>
632  ( const GaudiMath::Interpolation::Type type ,
633  DATAX begin_x ,
634  DATAX end_x ,
635  DATAY begin_y ,
636  const double low )
637  : AbsFunction ( )
638  , m_spline ( type , begin_x , end_x , begin_y )
639  , m_low ( low )
640  {}
653  template <class DATA>
656  DATA&& begin ,
657  DATA&& end ,
658  const double low )
659  : m_spline ( type , std::forward<DATA>(begin) , std::forward<DATA>(end) )
660  , m_low ( low )
661  {}
663  GSLSplineInteg ( const SplineBase& ,
664  const double low = 0 ) ;
666  GSLSplineInteg ( const GSLSplineInteg& ) = default;
667  public:
669  double operator() ( double a ) const override;
671  double operator() ( const Argument& x ) const override;
672  unsigned int dimensionality () const override { return 1 ; }
674  bool hasAnalyticDerivative() const override { return true ; }
676  Genfun::Derivative partial( unsigned int i ) const override;
677  public:
679  inline const SplineBase& spline() const { return m_spline ; }
681  operator const SplineBase& () const { return spline() ; }
682  private:
684  GSLSplineInteg& operator=( const GSLSplineInteg& ) = delete;
685  private:
686  // the actual spline function
688  double m_low ;
689  };
690 
691  }
692 }
693 
694 #ifdef __clang__
695 #pragma clang diagnostic pop
696 #endif
697 
698 #endif // GAUDIMATH_SPLINES_H
699 // ============================================================================
SplineBase(const SplineBase &rhs)
copy constructor
Definition: Splines.h:115
const SplineBase & spline() const
acess to the spline function
Definition: Splines.h:679
T distance(T...args)
unsigned int dimensionality() const override
Definition: Splines.h:390
const SplineBase & spline() const
acess to the spline function
Definition: Splines.h:263
const SplineBase & spline() const
acess to the spline function
Definition: Splines.h:397
T copy_n(T...args)
#define class
Genfun::GaudiMathImplementation::NumericalDerivative Derivative
Definition: GaudiMath.h:29
auto begin(reverse_wrapper< T > &w)
Definition: reverse.h:48
PropertyMgr & operator=(const PropertyMgr &)=delete
unsigned int dimensionality() const override
Definition: Splines.h:672
constexpr double second
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:244
bool hasAnalyticDerivative() const override
Does this function have an analytic derivative?
Definition: Splines.h:529
GaudiMath::Interpolation::Type m_type
transient
Definition: Splines.h:141
SplineBase & operator=(const SplineBase &rhs)
assignment
Definition: Splines.h:122
auto end(reverse_wrapper< T > &w)
Definition: reverse.h:50
unsigned int dimensionality() const override
Definition: Splines.h:256
bool hasAnalyticDerivative() const override
Does this function have an analytic derivative?
Definition: Splines.h:258
bool hasAnalyticDerivative() const override
Does this function have an analytic derivative?
Definition: Splines.h:674
T back_inserter(T...args)
bool hasAnalyticDerivative() const override
Does this function have an analytic derivative?
Definition: Splines.h:392
GaudiMath.h GaudiMath/GaudiMath.h.
Definition: Adapters.h:13
CLHEP.
Definition: IEqSolver.h:13
std::unique_ptr< gsl_interp_accel, details::gsl_deleter > m_accel
transient
Definition: Splines.h:140
const SplineBase & spline() const
acess to the spline function
Definition: Splines.h:534
#define GAUDI_API
Definition: Kernel.h:107
Type
the list of available types for ntuples
Definition: TupleObj.h:80
unsigned int dimensionality() const override
Definition: Splines.h:527
std::vector< std::pair< double, double > > Data2D
Definition: Splines.h:50
std::unique_ptr< gsl_spline, details::gsl_deleter > m_spline
Definition: Splines.h:139