| The Gaudi Framework v29r1 (5cd95fa2)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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 // ============================================================================
21 #include "GaudiMath/Interpolation.h"
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 {
41 struct gsl_deleter {
42 void operator()( gsl_spline* p )
43 {
44 if ( p ) gsl_spline_free( p );
45 }
46 void operator()( gsl_interp_accel* p )
47 {
48 if ( p ) gsl_interp_accel_free( p );
49 }
50 };
51 }
52
53 class GAUDI_API SplineBase
54 {
55 public:
56 typedef std::vector<double> Data1D;
57 typedef std::vector<std::pair<double, double>> Data2D;
58
59 public:
65 SplineBase( const Data1D& x, const Data1D& y, const GaudiMath::Interpolation::Type type );
70 SplineBase( const Data2D& data, const GaudiMath::Interpolation::Type type );
77 template <class DATAX, class DATAY>
78 SplineBase( const GaudiMath::Interpolation::Type type, DATAX begin_x, DATAX end_x, DATAY begin_y )
79 : m_type( type )
80 {
81 auto size = std::distance( begin_x, end_x );
82 m_x.reserve( size );
83 std::copy_n( begin_x, size, std::back_inserter( m_x ) );
84 m_y.reserve( size );
85 std::copy_n( begin_y, size, std::back_inserter( m_y ) );
86 }
94 template <class DATA>
95 SplineBase( const GaudiMath::Interpolation::Type type, DATA begin, DATA end ) : m_type( type )
96 {
97 m_x.reserve( end - begin );
98 m_y.reserve( end - begin );
99 for ( ; begin != end; ++begin ) {
100 m_x.push_back( begin->first );
101 m_y.push_back( begin->second );
102 };
103 }
104
106 SplineBase( SplineBase&& ) = default;
108 SplineBase& operator=( SplineBase&& rhs ) = default;
110 SplineBase( const SplineBase& rhs ) : m_x( rhs.m_x ), m_y( rhs.m_y ), m_type( rhs.m_type )
111 // note that we do NOT copy m_spline, m_accel!
112 {
113 }
115 SplineBase& operator=( const SplineBase& rhs )
116 {
117 *this = SplineBase( rhs );
118 return *this;
119 }
120
121 public:
123 double eval( const double x ) const;
125 double deriv( const double x ) const;
127 double deriv2( const double x ) const;
129 double integ( const double a, const double b ) const;
130
131 protected:
132 // initialize
133 void initialize() const;
134
135 private:
136 std::vector<double> m_x;
137 std::vector<double> m_y;
138 mutable std::unique_ptr<gsl_spline, details::gsl_deleter> m_spline;
139 mutable std::unique_ptr<gsl_interp_accel, details::gsl_deleter> m_accel;
140 GaudiMath::Interpolation::Type m_type;
141 };
142
143 class GAUDI_API GSLSpline : public AbsFunction
144 {
145 public:
146 typedef SplineBase::Data1D Data1D;
147 typedef SplineBase::Data2D Data2D;
148
149 public:
150 // mandatory macro from CLHEP/GenericFunctions
151 FUNCTION_OBJECT_DEF( GSLSpline )
152 public:
173 GSLSpline( const Data1D& x, const Data1D& y, const GaudiMath::Interpolation::Type type );
192 GSLSpline( const Data2D& data, const GaudiMath::Interpolation::Type type );
219 template <class DATAX, class DATAY>
220 GSLSpline( const GaudiMath::Interpolation::Type type, DATAX begin_x, DATAX end_x, DATAY begin_y )
221 : m_spline( type, begin_x, end_x, begin_y )
222 {
223 }
235 template <class DATA>
236 GSLSpline( const GaudiMath::Interpolation::Type type, DATA begin, DATA end ) : m_spline( type, begin, end )
237 {
238 }
240 GSLSpline( const SplineBase& );
241
242 public:
244 double operator()( double a ) const override;
246 double operator()( const Argument& x ) const override;
247 unsigned int dimensionality() const override { return 1; }
249 bool hasAnalyticDerivative() const override { return true; }
251 Genfun::Derivative partial( unsigned int i ) const override;
252
253 public:
255 inline const SplineBase& spline() const { return m_spline; }
257 operator const SplineBase&() const { return spline(); }
259 GSLSpline& operator=( const GSLSpline& ) = delete;
260
261 private:
262 // the actual spline function
263 SplineBase m_spline;
264 };
265 // mandatory macro from CLHEP/GenericFunctions
266 FUNCTION_OBJECT_IMP( GSLSpline )
267
268 class GAUDI_API GSLSplineDeriv : public AbsFunction
269 {
270 public:
271 typedef SplineBase::Data1D Data1D;
272 typedef SplineBase::Data2D Data2D;
273
274 public:
275 // mandatory macro from CLHEP/GenericFunctions
276 FUNCTION_OBJECT_DEF( GSLSplineDeriv )
277 public:
298 GSLSplineDeriv( const Data1D& x, const Data1D& y, const GaudiMath::Interpolation::Type type );
317 GSLSplineDeriv( const Data2D& data, const GaudiMath::Interpolation::Type type );
344 template <class DATAX, class DATAY>
345 GSLSplineDeriv( const GaudiMath::Interpolation::Type type, DATAX begin_x, DATAX end_x, DATAY begin_y )
346 : AbsFunction(), m_spline( type, begin_x, end_x, begin_y )
347 {
348 }
360 template <class DATA>
361 GSLSplineDeriv( const GaudiMath::Interpolation::Type type, DATA begin, DATA end )
362 : AbsFunction(), m_spline( type, begin, end )
363 {
364 }
366 GSLSplineDeriv( const SplineBase& );
368 GSLSplineDeriv( const GSLSplineDeriv& );
369
370 public:
372 double operator()( double a ) const override;
374 double operator()( const Argument& x ) const override;
375 unsigned int dimensionality() const override { return 1; }
377 bool hasAnalyticDerivative() const override { return true; }
379 Genfun::Derivative partial( unsigned int i ) const override;
380
381 public:
383 inline const SplineBase& spline() const { return m_spline; }
385 operator const SplineBase&() const { return spline(); }
386
387 private:
389 GSLSplineDeriv();
391 GSLSplineDeriv& operator=( const GSLSplineDeriv& );
392
393 private:
394 // the actual spline function
395 SplineBase m_spline;
396 };
397 // mandatory macro from CLHEP/GenericFunctions
398 FUNCTION_OBJECT_IMP( GSLSplineDeriv )
399
400 class GAUDI_API GSLSplineDeriv2 : public AbsFunction
401 {
402 public:
403 typedef SplineBase::Data1D Data1D;
404 typedef SplineBase::Data2D Data2D;
405
406 public:
407 // mandatory macro from CLHEP/GenericFunctions
408 FUNCTION_OBJECT_DEF( GSLSplineDeriv2 )
409 public:
430 GSLSplineDeriv2( const Data1D& x, const Data1D& y, const GaudiMath::Interpolation::Type type );
449 GSLSplineDeriv2( const Data2D& data, const GaudiMath::Interpolation::Type type );
476 template <class DATAX, class DATAY>
477 GSLSplineDeriv2( const GaudiMath::Interpolation::Type type, DATAX begin_x, DATAX end_x, DATAY begin_y )
478 : AbsFunction(), m_spline( type, begin_x, end_x, begin_y )
479 {
480 }
492 template <class DATA>
493 GSLSplineDeriv2( const GaudiMath::Interpolation::Type type, DATA begin, DATA end )
494 : AbsFunction(), m_spline( type, begin, end )
495 {
496 }
498 GSLSplineDeriv2( const SplineBase& );
500 GSLSplineDeriv2( const GSLSplineDeriv2& ) = default;
501
502 public:
504 double operator()( double a ) const override;
506 double operator()( const Argument& x ) const override;
507 unsigned int dimensionality() const override { return 1; }
509 bool hasAnalyticDerivative() const override { return true; }
511 Genfun::Derivative partial( unsigned int i ) const override;
512
513 public:
515 inline const SplineBase& spline() const { return m_spline; }
517 operator const SplineBase&() const { return spline(); }
518
519 private:
521 GSLSplineDeriv2& operator=( const GSLSplineDeriv2& ) = delete;
522
523 private:
524 // the actual spline function
525 SplineBase m_spline;
526 };
527 // mandatory macro from CLHEP/GenericFunctions
528 FUNCTION_OBJECT_IMP( GSLSplineDeriv2 )
529
530 class GAUDI_API GSLSplineInteg : public AbsFunction
531 {
532 public:
533 typedef SplineBase::Data1D Data1D;
534 typedef SplineBase::Data2D Data2D;
535
536 public:
537 // mandatory macro from CLHEP/GenericFunctions
538 FUNCTION_OBJECT_DEF( GSLSplineInteg )
539 public:
560 GSLSplineInteg( const Data1D& x, const Data1D& y, const GaudiMath::Interpolation::Type type,
561 const double low = 0 );
581 GSLSplineInteg( const Data2D& data, const GaudiMath::Interpolation::Type type, const double low = 0 );
609 template <class DATAX, class DATAY>
610 GSLSplineInteg( const GaudiMath::Interpolation::Type type, DATAX begin_x, DATAX end_x, DATAY begin_y,
611 const double low )
612 : AbsFunction(), m_spline( type, begin_x, end_x, begin_y ), m_low( low )
613 {
614 }
627 template <class DATA>
628 GSLSplineInteg( const GaudiMath::Interpolation::Type type, DATA&& begin, DATA&& end, const double low )
629 : m_spline( type, std::forward<DATA>( begin ), std::forward<DATA>( end ) ), m_low( low )
630 {
631 }
633 GSLSplineInteg( const SplineBase&, const double low = 0 );
635 GSLSplineInteg( const GSLSplineInteg& ) = default;
636
637 public:
639 double operator()( double a ) const override;
641 double operator()( const Argument& x ) const override;
642 unsigned int dimensionality() const override { return 1; }
644 bool hasAnalyticDerivative() const override { return true; }
646 Genfun::Derivative partial( unsigned int i ) const override;
647
648 public:
650 inline const SplineBase& spline() const { return m_spline; }
652 operator const SplineBase&() const { return spline(); }
653
654 private:
656 GSLSplineInteg& operator=( const GSLSplineInteg& ) = delete;
657
658 private:
659 // the actual spline function
660 SplineBase m_spline;
661 double m_low;
662 };
663 // mandatory macro from CLHEP/GenericFunctions
664 FUNCTION_OBJECT_IMP( GSLSplineInteg )
665 }
666 }
667
668 #ifdef __clang__
669 #pragma clang diagnostic pop
670 #endif
671
672 #endif // GAUDIMATH_SPLINES_H
673 // ============================================================================
Genfun::GaudiMathImplementation::SplineBase::SplineBase
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:95
Genfun::GaudiMathImplementation::SplineBase::SplineBase
SplineBase(const SplineBase &rhs)
copy constructor
Definition: Splines.h:110
Kernel.h
Genfun::GaudiMathImplementation::GSLSplineInteg::spline
const SplineBase & spline() const
acess to the spline function
Definition: Splines.h:650
std::distance
T distance(T...args)
Genfun::GaudiMathImplementation::SplineBase::Data2D
std::vector< std::pair< double, double > > Data2D
Definition: Splines.h:57
Genfun::GaudiMathImplementation::GSLSplineDeriv2::GSLSplineDeriv2
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:493
Genfun::GaudiMathImplementation::GSLSplineDeriv::dimensionality
unsigned int dimensionality() const override
Definition: Splines.h:375
Genfun::GaudiMathImplementation::GSLSplineInteg::Data2D
SplineBase::Data2D Data2D
Definition: Splines.h:534
Genfun::GaudiMathImplementation::GSLSpline::Data2D
SplineBase::Data2D Data2D
Definition: Splines.h:147
Genfun::GaudiMathImplementation::SplineBase
Definition: Splines.h:53
Genfun::GaudiMathImplementation::GSLSpline::spline
const SplineBase & spline() const
acess to the spline function
Definition: Splines.h:255
Genfun::GaudiMathImplementation::GSLSplineInteg::Data1D
SplineBase::Data1D Data1D
Definition: Splines.h:533
Genfun::GaudiMathImplementation::GSLSplineDeriv::spline
const SplineBase & spline() const
acess to the spline function
Definition: Splines.h:383
Genfun::GaudiMathImplementation::GSLSplineDeriv2::m_spline
SplineBase m_spline
Definition: Splines.h:525
Genfun::GaudiMathImplementation::GSLSplineDeriv::GSLSplineDeriv
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:361
std
STL namespace.
Genfun::GaudiMathImplementation::SplineBase::m_spline
std::unique_ptr< gsl_spline, details::gsl_deleter > m_spline
Definition: Splines.h:138
Genfun::GaudiMathImplementation::GSLSplineDeriv2::Data2D
SplineBase::Data2D Data2D
Definition: Splines.h:404
std::copy_n
T copy_n(T...args)
class
#define class
Definition: HistogramPersistencySvc.cpp:45
GaudiMath::Derivative
Genfun::GaudiMathImplementation::NumericalDerivative Derivative
Definition: GaudiMath.h:27
begin
auto begin(reverse_wrapper< T > &w)
Definition: reverse.h:58
operator=
PropertyMgr & operator=(const PropertyMgr &)=delete
Genfun::GaudiMathImplementation::GSLSplineInteg::GSLSplineInteg
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:628
Genfun::GaudiMathImplementation::GSLSplineInteg::dimensionality
unsigned int dimensionality() const override
Definition: Splines.h:642
Genfun::GaudiMathImplementation::GSLSpline::Data1D
SplineBase::Data1D Data1D
Definition: Splines.h:146
Genfun::GaudiMathImplementation::details::gsl_deleter::operator()
void operator()(gsl_interp_accel *p)
Definition: Splines.h:46
Genfun::GaudiMathImplementation::GSLSpline::GSLSpline
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:236
Genfun::GaudiMathImplementation::GSLSplineDeriv2::hasAnalyticDerivative
bool hasAnalyticDerivative() const override
Does this function have an analytic derivative?
Definition: Splines.h:509
Genfun::GaudiMathImplementation::SplineBase::Data1D
std::vector< double > Data1D
Definition: Splines.h:56
Genfun::GaudiMathImplementation::SplineBase::m_type
GaudiMath::Interpolation::Type m_type
transient
Definition: Splines.h:140
Genfun::GaudiMathImplementation::GSLSplineDeriv::m_spline
SplineBase m_spline
Definition: Splines.h:395
gaudirun.type
type
Definition: gaudirun.py:133
Genfun::GaudiMathImplementation::SplineBase::operator=
SplineBase & operator=(const SplineBase &rhs)
assignment
Definition: Splines.h:115
end
auto end(reverse_wrapper< T > &w)
Definition: reverse.h:64
Genfun::GaudiMathImplementation::SplineBase::m_y
std::vector< double > m_y
Definition: Splines.h:137
Genfun::GaudiMathImplementation::GSLSplineDeriv2::Data1D
SplineBase::Data1D Data1D
Definition: Splines.h:403
Interpolation.h
Genfun::GaudiMathImplementation::SplineBase::SplineBase
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:78
Genfun::GaudiMathImplementation::GSLSplineDeriv::Data2D
SplineBase::Data2D Data2D
Definition: Splines.h:272
Genfun::GaudiMathImplementation::GSLSpline::dimensionality
unsigned int dimensionality() const override
Definition: Splines.h:247
Genfun::GaudiMathImplementation::GSLSpline::hasAnalyticDerivative
bool hasAnalyticDerivative() const override
Does this function have an analytic derivative?
Definition: Splines.h:249
std::vector< double >
Genfun::GaudiMathImplementation::GSLSplineInteg::hasAnalyticDerivative
bool hasAnalyticDerivative() const override
Does this function have an analytic derivative?
Definition: Splines.h:644
std::unique_ptr< gsl_spline, details::gsl_deleter >
Genfun::GaudiMathImplementation::GSLSplineDeriv::Data1D
SplineBase::Data1D Data1D
Definition: Splines.h:271
Genfun::GaudiMathImplementation::GSLSpline::m_spline
SplineBase m_spline
Definition: Splines.h:263
std::back_inserter
T back_inserter(T...args)
Genfun::GaudiMathImplementation::GSLSplineDeriv::hasAnalyticDerivative
bool hasAnalyticDerivative() const override
Does this function have an analytic derivative?
Definition: Splines.h:377
GaudiMath::Interpolation::Type
Type
Definition: Interpolation.h:15
GaudiMath
GaudiMath.h GaudiMath/GaudiMath.h.
Definition: Adapters.h:13
Genfun::GaudiMathImplementation::GSLSplineDeriv
Definition: Splines.h:268
Genfun::GaudiMathImplementation::GSLSpline
Definition: Splines.h:143
Genfun::GaudiMathImplementation::SplineBase::m_accel
std::unique_ptr< gsl_interp_accel, details::gsl_deleter > m_accel
transient
Definition: Splines.h:139
Genfun
CLHEP.
Definition: IEqSolver.h:13
Genfun::GaudiMathImplementation::GSLSplineDeriv2
Definition: Splines.h:400
Genfun::GaudiMathImplementation::GSLSplineDeriv2::spline
const SplineBase & spline() const
acess to the spline function
Definition: Splines.h:515
Genfun::GaudiMathImplementation::GSLSplineInteg
Definition: Splines.h:530
Genfun::GaudiMathImplementation::details::gsl_deleter::operator()
void operator()(gsl_spline *p)
Definition: Splines.h:42
GAUDI_API
#define GAUDI_API
Definition: Kernel.h:110
Tuples::Type
Type
the list of available types for ntuples
Definition: TupleObj.h:84
Genfun::GaudiMathImplementation::SplineBase::m_x
std::vector< double > m_x
Definition: Splines.h:136
Genfun::GaudiMathImplementation::GSLSplineDeriv2::dimensionality
unsigned int dimensionality() const override
Definition: Splines.h:507
Genfun::GaudiMathImplementation::details::gsl_deleter
Definition: Splines.h:41
Genfun::GaudiMathImplementation::GSLSplineInteg::m_spline
SplineBase m_spline
Definition: Splines.h:660
Genfun::GaudiMathImplementation::GSLSplineInteg::m_low
double m_low
Definition: Splines.h:661