| The Gaudi Framework v28r2p1 (f1a77ff4)

- 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 <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 // ============================================================================
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
40 class GAUDI_API SplineBase
41 {
42 public:
43 typedef std::vector<double> Data1D ;
44 typedef std::vector<std::pair<double,double> > Data2D ;
45 public:
51 SplineBase
52 ( const Data1D& x ,
53 const Data1D& y ,
54 const GaudiMath::Interpolation::Type type ) ;
59 SplineBase
60 ( const Data2D& data ,
61 const GaudiMath::Interpolation::Type type ) ;
68 template <class DATAX, class DATAY>
69 SplineBase
70 ( const GaudiMath::Interpolation::Type type ,
71 DATAX begin_x ,
72 DATAX end_x ,
73 DATAY begin_y )
74 : m_dim ( end_x - begin_x )
75 , m_x ( new double[ end_x - begin_x ] )
76 , m_y ( new double[ end_x - begin_x ] )
77 , m_type ( type )
78 {
79 std::copy ( begin_x , end_x , m_x.get() ) ;
80 std::copy ( begin_y , begin_y + ( end_x - begin_x ) , m_y.get() ) ;
81 }
89 template <class DATA>
90 SplineBase
91 ( const GaudiMath::Interpolation::Type type ,
92 DATA begin ,
93 DATA end )
94 : m_dim ( end - begin )
95 , m_x ( new double[ end - begin ] )
96 , m_y ( new double[ end - begin ] )
97 , m_type ( type )
98 {
99 double* _x = m_x.get() ;
100 double* _y = m_y.get() ;
101 for ( auto it = begin ; end != it ; ++ it )
102 {
103 *_x++ = it -> first ;
104 *_y++ = it -> second ;
105 };
106 }
108 SplineBase( const SplineBase& ) ;
110 ~SplineBase();
111 public:
113 double eval ( const double x ) const ;
115 double deriv ( const double x ) const ;
117 double deriv2 ( const double x ) const ;
119 double integ ( const double a , const double b ) const ;
120 protected:
121 // initialize
122 void initialize () const ;
123 private:
124 // default constructor is disabled
125 SplineBase() = delete;
126 // assigenement operator is disabled
127 SplineBase& operator=( const SplineBase& ) = delete;
128 private:
129 mutable bool m_init = false;
130 size_t m_dim ;
131 std::unique_ptr<double[]> m_x ;
132 std::unique_ptr<double[]> m_y ;
133 mutable gsl_spline* m_spline = nullptr;
134 mutable gsl_interp_accel* m_accel = nullptr;
135 GaudiMath::Interpolation::Type m_type ;
136 };
137
138 class GAUDI_API GSLSpline : public AbsFunction
139 {
140 public:
141 typedef SplineBase::Data1D Data1D ;
142 typedef SplineBase::Data2D Data2D ;
143 public:
145 FUNCTION_OBJECT_DEF( GSLSpline )
146 public:
167 GSLSpline
168 ( const Data1D& x ,
169 const Data1D& y ,
170 const GaudiMath::Interpolation::Type type ) ;
189 GSLSpline
190 ( const Data2D& data ,
191 const GaudiMath::Interpolation::Type type ) ;
218 template <class DATAX, class DATAY>
219 GSLSpline
220 ( const GaudiMath::Interpolation::Type type ,
221 DATAX begin_x ,
222 DATAX end_x ,
223 DATAY begin_y )
224 : AbsFunction ( )
225 , m_spline( type , begin_x , end_x , begin_y )
226 {}
238 template <class DATA>
239 GSLSpline
240 ( const GaudiMath::Interpolation::Type type ,
241 DATA begin ,
242 DATA end )
243 : AbsFunction ( )
244 , m_spline( type , begin , end )
245 {}
247 GSLSpline ( const SplineBase& ) ;
249 GSLSpline ( const GSLSpline& ) ;
251 ~GSLSpline() override ;
252 public:
254 double operator() ( double a ) const override ;
256 double operator() ( const Argument& x ) const override ;
257 unsigned int dimensionality () const override { return 1 ; }
259 bool hasAnalyticDerivative() const override { return true ; }
261 Genfun::Derivative partial( unsigned int i ) const override ;
262 public:
264 inline const SplineBase& spline() const { return m_spline ; }
266 operator const SplineBase& () const { return spline() ; }
267 private:
269 GSLSpline() = delete;
271 GSLSpline& operator=( const GSLSpline& ) = delete;
272 private:
273 // the actual spline function
274 SplineBase m_spline ;
275 };
276
277 class GAUDI_API GSLSplineDeriv : public AbsFunction
278 {
279 public:
280 typedef SplineBase::Data1D Data1D ;
281 typedef SplineBase::Data2D Data2D ;
282 public:
284 FUNCTION_OBJECT_DEF( GSLSplineDeriv )
285 public:
306 GSLSplineDeriv
307 ( const Data1D& x ,
308 const Data1D& y ,
309 const GaudiMath::Interpolation::Type type ) ;
328 GSLSplineDeriv
329 ( const Data2D& data ,
330 const GaudiMath::Interpolation::Type type ) ;
357 template <class DATAX, class DATAY>
358 GSLSplineDeriv
359 ( const GaudiMath::Interpolation::Type type ,
360 DATAX begin_x ,
361 DATAX end_x ,
362 DATAY begin_y )
363 : AbsFunction ( )
364 , m_spline( type , begin_x , end_x , begin_y )
365 {}
377 template <class DATA>
378 GSLSplineDeriv
379 ( const GaudiMath::Interpolation::Type type ,
380 DATA begin ,
381 DATA end )
382 : AbsFunction ( )
383 , m_spline( type , begin , end )
384 {}
386 GSLSplineDeriv ( const SplineBase& ) ;
388 GSLSplineDeriv ( const GSLSplineDeriv& ) ;
390 ~GSLSplineDeriv() override;
391 public:
393 double operator() ( double a ) const override;
395 double operator() ( const Argument& x ) const override;
396 unsigned int dimensionality () const override { return 1 ; }
398 bool hasAnalyticDerivative() const override { return true ; }
400 Genfun::Derivative partial( unsigned int i ) const override ;
401 public:
403 inline const SplineBase& spline() const { return m_spline ; }
405 operator const SplineBase& () const { return spline() ; }
406 private:
408 GSLSplineDeriv() ;
410 GSLSplineDeriv& operator=( const GSLSplineDeriv& ) ;
411 private:
412 // the actual spline function
413 SplineBase m_spline ;
414 };
415
416 class GAUDI_API GSLSplineDeriv2 : public AbsFunction
417 {
418 public:
419 typedef SplineBase::Data1D Data1D ;
420 typedef SplineBase::Data2D Data2D ;
421 public:
423 FUNCTION_OBJECT_DEF( GSLSplineDeriv2 )
424 public:
445 GSLSplineDeriv2
446 ( const Data1D& x ,
447 const Data1D& y ,
448 const GaudiMath::Interpolation::Type type ) ;
467 GSLSplineDeriv2
468 ( const Data2D& data ,
469 const GaudiMath::Interpolation::Type type ) ;
496 template <class DATAX, class DATAY>
497 GSLSplineDeriv2
498 ( const GaudiMath::Interpolation::Type type ,
499 DATAX begin_x ,
500 DATAX end_x ,
501 DATAY begin_y )
502 : AbsFunction ( )
503 , m_spline( type , begin_x , end_x , begin_y )
504 {}
516 template <class DATA>
517 GSLSplineDeriv2
518 ( const GaudiMath::Interpolation::Type type ,
519 DATA begin ,
520 DATA end )
521 : AbsFunction ( )
522 , m_spline( type , begin , end )
523 {}
525 GSLSplineDeriv2 ( const SplineBase& ) ;
527 GSLSplineDeriv2 ( const GSLSplineDeriv2& ) ;
529 ~GSLSplineDeriv2() override;
530 public:
532 double operator() ( double a ) const override;
534 double operator() ( const Argument& x ) const override;
535 unsigned int dimensionality () const override { return 1 ; }
537 bool hasAnalyticDerivative() const override { return true ; }
539 Genfun::Derivative partial( unsigned int i ) const override;
540 public:
542 inline const SplineBase& spline() const { return m_spline ; }
544 operator const SplineBase& () const { return spline() ; }
545 private:
547 GSLSplineDeriv2() = delete;
549 GSLSplineDeriv2& operator=( const GSLSplineDeriv2& ) = delete;
550 private:
551 // the actual spline function
552 SplineBase m_spline ;
553 };
554
555
556 class GAUDI_API GSLSplineInteg : public AbsFunction
557 {
558 public:
559 typedef SplineBase::Data1D Data1D ;
560 typedef SplineBase::Data2D Data2D ;
561 public:
563 FUNCTION_OBJECT_DEF( GSLSplineInteg )
564 public:
585 GSLSplineInteg
586 ( const Data1D& x ,
587 const Data1D& y ,
588 const GaudiMath::Interpolation::Type type ,
589 const double low = 0 ) ;
609 GSLSplineInteg
610 ( const Data2D& data ,
611 const GaudiMath::Interpolation::Type type ,
612 const double low = 0 ) ;
640 template <class DATAX, class DATAY>
641 GSLSplineInteg
642 ( const GaudiMath::Interpolation::Type type ,
643 DATAX begin_x ,
644 DATAX end_x ,
645 DATAY begin_y ,
646 const double low )
647 : AbsFunction ( )
648 , m_spline ( type , begin_x , end_x , begin_y )
649 , m_low ( low )
650 {}
663 template <class DATA>
664 GSLSplineInteg
665 ( const GaudiMath::Interpolation::Type type ,
666 DATA&& begin ,
667 DATA&& end ,
668 const double low )
669 : m_spline ( type , std::forward<DATA>(begin) , std::forward<DATA>(end) )
670 , m_low ( low )
671 {}
673 GSLSplineInteg ( const SplineBase& ,
674 const double low = 0 ) ;
676 GSLSplineInteg ( const GSLSplineInteg& ) ;
678 ~GSLSplineInteg () override;
679 public:
681 double operator() ( double a ) const override;
683 double operator() ( const Argument& x ) const override;
684 unsigned int dimensionality () const override { return 1 ; }
686 bool hasAnalyticDerivative() const override { return true ; }
688 Genfun::Derivative partial( unsigned int i ) const override;
689 public:
691 inline const SplineBase& spline() const { return m_spline ; }
693 operator const SplineBase& () const { return spline() ; }
694 private:
696 GSLSplineInteg () = delete;
698 GSLSplineInteg& operator=( const GSLSplineInteg& ) = delete;
699 private:
700 // the actual spline function
701 SplineBase m_spline ;
702 double m_low ;
703 };
704
705 }
706 }
707
708 #ifdef __clang__
709 #pragma clang diagnostic pop
710 #endif
711
712 #endif // GAUDIMATH_SPLINES_H
713 // ============================================================================
Kernel.h
Genfun::GaudiMathImplementation::GSLSplineInteg::spline
const SplineBase & spline() const
acess to the spline function
Definition: Splines.h:691
std::copy
T copy(T...args)
Genfun::GaudiMathImplementation::GSLSplineDeriv::dimensionality
unsigned int dimensionality() const override
Definition: Splines.h:396
Genfun::GaudiMathImplementation::GSLSplineInteg::Data2D
SplineBase::Data2D Data2D
Definition: Splines.h:560
Genfun::GaudiMathImplementation::GSLSpline::Data2D
SplineBase::Data2D Data2D
Definition: Splines.h:142
Genfun::GaudiMathImplementation::SplineBase
Definition: Splines.h:40
Genfun::GaudiMathImplementation::GSLSpline::spline
const SplineBase & spline() const
acess to the spline function
Definition: Splines.h:264
Genfun::GaudiMathImplementation::GSLSplineInteg::Data1D
SplineBase::Data1D Data1D
Definition: Splines.h:559
Genfun::GaudiMathImplementation::GSLSplineDeriv::spline
const SplineBase & spline() const
acess to the spline function
Definition: Splines.h:403
Genfun::GaudiMathImplementation::GSLSplineDeriv2::m_spline
SplineBase m_spline
Definition: Splines.h:552
Genfun::GaudiMathImplementation::GSLSplineDeriv2::Data2D
SplineBase::Data2D Data2D
Definition: Splines.h:420
Genfun::GaudiMathImplementation::SplineBase::m_y
std::unique_ptr< double[]> m_y
Definition: Splines.h:132
class
#define class
Definition: HistogramPersistencySvc.cpp:45
GaudiMath::Derivative
Genfun::GaudiMathImplementation::NumericalDerivative Derivative
Definition: GaudiMath.h:29
begin
auto begin(reverse_wrapper< T > &w)
Definition: reverse.h:48
operator=
PropertyMgr & operator=(const PropertyMgr &)=delete
Genfun::GaudiMathImplementation::GSLSplineInteg::dimensionality
unsigned int dimensionality() const override
Definition: Splines.h:684
Gaudi::Units::second
constexpr double second
Definition: SystemOfUnits.h:122
Genfun::GaudiMathImplementation::GSLSpline::Data1D
SplineBase::Data1D Data1D
Definition: Splines.h:141
Genfun::GaudiMathImplementation::GSLSplineDeriv2::hasAnalyticDerivative
bool hasAnalyticDerivative() const override
Does this function have an analytic derivative?
Definition: Splines.h:537
Genfun::GaudiMathImplementation::SplineBase::Data1D
std::vector< double > Data1D
Definition: Splines.h:43
Genfun::GaudiMathImplementation::SplineBase::m_type
GaudiMath::Interpolation::Type m_type
Definition: Splines.h:135
Genfun::GaudiMathImplementation::GSLSplineDeriv::m_spline
SplineBase m_spline
Definition: Splines.h:413
Genfun::GaudiMathImplementation::SplineBase::m_x
std::unique_ptr< double[]> m_x
Definition: Splines.h:131
gaudirun.type
type
Definition: gaudirun.py:125
end
auto end(reverse_wrapper< T > &w)
Definition: reverse.h:50
Genfun::GaudiMathImplementation::GSLSplineDeriv2::Data1D
SplineBase::Data1D Data1D
Definition: Splines.h:419
Interpolation.h
Genfun::GaudiMathImplementation::GSLSplineDeriv::Data2D
SplineBase::Data2D Data2D
Definition: Splines.h:281
Genfun::GaudiMathImplementation::GSLSpline::dimensionality
unsigned int dimensionality() const override
Definition: Splines.h:257
Genfun::GaudiMathImplementation::GSLSpline::hasAnalyticDerivative
bool hasAnalyticDerivative() const override
Does this function have an analytic derivative?
Definition: Splines.h:259
std::vector< double >
Genfun::GaudiMathImplementation::GSLSplineInteg::hasAnalyticDerivative
bool hasAnalyticDerivative() const override
Does this function have an analytic derivative?
Definition: Splines.h:686
std::unique_ptr< double[]>
Gaudi::Functional::operator()
virtual Out operator()(const vector_of_const_< In > &inputs) const =0
Genfun::GaudiMathImplementation::GSLSplineDeriv::Data1D
SplineBase::Data1D Data1D
Definition: Splines.h:280
Genfun::GaudiMathImplementation::GSLSpline::m_spline
SplineBase m_spline
Definition: Splines.h:274
Genfun::GaudiMathImplementation::GSLSplineDeriv::hasAnalyticDerivative
bool hasAnalyticDerivative() const override
Does this function have an analytic derivative?
Definition: Splines.h:398
Genfun::GaudiMathImplementation::SplineBase::m_dim
size_t m_dim
Definition: Splines.h:130
GaudiMath::Interpolation::Type
Type
Definition: Interpolation.h:11
GaudiMath
GaudiMath.h GaudiMath/GaudiMath.h.
Definition: Adapters.h:13
Genfun::GaudiMathImplementation::GSLSplineDeriv
Definition: Splines.h:277
Genfun::GaudiMathImplementation::GSLSpline
Definition: Splines.h:138
Genfun
CLHEP.
Definition: IEqSolver.h:13
Genfun::GaudiMathImplementation::GSLSplineDeriv2
Definition: Splines.h:416
Genfun::GaudiMathImplementation::GSLSplineDeriv2::spline
const SplineBase & spline() const
acess to the spline function
Definition: Splines.h:542
Genfun::GaudiMathImplementation::GSLSplineInteg
Definition: Splines.h:556
GAUDI_API
#define GAUDI_API
Definition: Kernel.h:107
Tuples::Type
Type
the list of available types for ntuples
Definition: TupleObj.h:79
Genfun::GaudiMathImplementation::GSLSplineDeriv2::dimensionality
unsigned int dimensionality() const override
Definition: Splines.h:535
Genfun::GaudiMathImplementation::SplineBase::Data2D
std::vector< std::pair< double, double > > Data2D
Definition: Splines.h:44
Genfun::GaudiMathImplementation::GSLSplineInteg::m_spline
SplineBase m_spline
Definition: Splines.h:701
Genfun::GaudiMathImplementation::GSLSplineInteg::m_low
double m_low
Definition: Splines.h:702