| The Gaudi Framework v27r1

- 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 namespace Genfun
31 {
32 namespace GaudiMathImplementation
33 {
34
35 class GAUDI_API SplineBase
36 {
37 public:
38 typedef std::vector<double> Data1D ;
39 typedef std::vector<std::pair<double,double> > Data2D ;
40 public:
46 SplineBase
47 ( const Data1D& x ,
48 const Data1D& y ,
49 const GaudiMath::Interpolation::Type type ) ;
54 SplineBase
55 ( const Data2D& data ,
56 const GaudiMath::Interpolation::Type type ) ;
63 template <class DATAX, class DATAY>
64 SplineBase
65 ( const GaudiMath::Interpolation::Type type ,
66 DATAX begin_x ,
67 DATAX end_x ,
68 DATAY begin_y )
69 : m_dim ( end_x - begin_x )
70 , m_x ( new double[ end_x - begin_x ] )
71 , m_y ( new double[ end_x - begin_x ] )
72 , m_type ( type )
73 {
74 std::copy ( begin_x , end_x , m_x.get() ) ;
75 std::copy ( begin_y , begin_y + ( end_x - begin_x ) , m_y.get() ) ;
76 }
84 template <class DATA>
85 SplineBase
86 ( const GaudiMath::Interpolation::Type type ,
87 DATA begin ,
88 DATA end )
89 : m_dim ( end - begin )
90 , m_x ( new double[ end - begin ] )
91 , m_y ( new double[ end - begin ] )
92 , m_type ( type )
93 {
94 double* _x = m_x.get() ;
95 double* _y = m_y.get() ;
96 for ( auto it = begin ; end != it ; ++ it )
97 {
98 *_x++ = it -> first ;
99 *_y++ = it -> second ;
100 };
101 }
103 SplineBase( const SplineBase& ) ;
105 virtual ~SplineBase();
106 public:
108 double eval ( const double x ) const ;
110 double deriv ( const double x ) const ;
112 double deriv2 ( const double x ) const ;
114 double integ ( const double a , const double b ) const ;
115 protected:
116 // initialize
117 void initialize () const ;
118 private:
119 // default constructor is disabled
120 SplineBase() = delete;
121 // assigenement operator is disabled
122 SplineBase& operator=( const SplineBase& ) = delete;
123 private:
124 mutable bool m_init = false;
125 size_t m_dim ;
126 std::unique_ptr<double[]> m_x ;
127 std::unique_ptr<double[]> m_y ;
128 mutable gsl_spline* m_spline = nullptr;
129 mutable gsl_interp_accel* m_accel = nullptr;
130 GaudiMath::Interpolation::Type m_type ;
131 };
132
133 class GAUDI_API GSLSpline : public AbsFunction
134 {
135 public:
136 typedef SplineBase::Data1D Data1D ;
137 typedef SplineBase::Data2D Data2D ;
138 public:
140 FUNCTION_OBJECT_DEF( GSLSpline )
141 public:
162 GSLSpline
163 ( const Data1D& x ,
164 const Data1D& y ,
165 const GaudiMath::Interpolation::Type type ) ;
184 GSLSpline
185 ( const Data2D& data ,
186 const GaudiMath::Interpolation::Type type ) ;
213 template <class DATAX, class DATAY>
214 GSLSpline
215 ( const GaudiMath::Interpolation::Type type ,
216 DATAX begin_x ,
217 DATAX end_x ,
218 DATAY begin_y )
219 : AbsFunction ( )
220 , m_spline( type , begin_x , end_x , begin_y )
221 {}
233 template <class DATA>
234 GSLSpline
235 ( const GaudiMath::Interpolation::Type type ,
236 DATA begin ,
237 DATA end )
238 : AbsFunction ( )
239 , m_spline( type , begin , end )
240 {}
242 GSLSpline ( const SplineBase& ) ;
244 GSLSpline ( const GSLSpline& ) ;
246 virtual ~GSLSpline() ;
247 public:
249 virtual double operator() ( double a ) const ;
251 virtual double operator() ( const Argument& x ) const ;
252 virtual unsigned int dimensionality () const { return 1 ; }
254 virtual bool hasAnalyticDerivative() const { return true ; }
256 virtual Genfun::Derivative partial( unsigned int i ) const ;
257 public:
259 inline const SplineBase& spline() const { return m_spline ; }
261 operator const SplineBase& () const { return spline() ; }
262 private:
264 GSLSpline() = delete;
266 GSLSpline& operator=( const GSLSpline& ) = delete;
267 private:
268 // the actual spline function
269 SplineBase m_spline ;
270 };
271
272 class GAUDI_API GSLSplineDeriv : public AbsFunction
273 {
274 public:
275 typedef SplineBase::Data1D Data1D ;
276 typedef SplineBase::Data2D Data2D ;
277 public:
279 FUNCTION_OBJECT_DEF( GSLSplineDeriv )
280 public:
301 GSLSplineDeriv
302 ( const Data1D& x ,
303 const Data1D& y ,
304 const GaudiMath::Interpolation::Type type ) ;
323 GSLSplineDeriv
324 ( const Data2D& data ,
325 const GaudiMath::Interpolation::Type type ) ;
352 template <class DATAX, class DATAY>
353 GSLSplineDeriv
354 ( const GaudiMath::Interpolation::Type type ,
355 DATAX begin_x ,
356 DATAX end_x ,
357 DATAY begin_y )
358 : AbsFunction ( )
359 , m_spline( type , begin_x , end_x , begin_y )
360 {}
372 template <class DATA>
373 GSLSplineDeriv
374 ( const GaudiMath::Interpolation::Type type ,
375 DATA begin ,
376 DATA end )
377 : AbsFunction ( )
378 , m_spline( type , begin , end )
379 {}
381 GSLSplineDeriv ( const SplineBase& ) ;
383 GSLSplineDeriv ( const GSLSplineDeriv& ) ;
385 ~GSLSplineDeriv() override;
386 public:
388 double operator() ( double a ) const override;
390 double operator() ( const Argument& x ) const override;
391 unsigned int dimensionality () const override { return 1 ; }
393 bool hasAnalyticDerivative() const override { return true ; }
395 Genfun::Derivative partial( unsigned int i ) const override ;
396 public:
398 inline const SplineBase& spline() const { return m_spline ; }
400 operator const SplineBase& () const { return spline() ; }
401 private:
403 GSLSplineDeriv() ;
405 GSLSplineDeriv& operator=( const GSLSplineDeriv& ) ;
406 private:
407 // the actual spline function
408 SplineBase m_spline ;
409 };
410
411 class GAUDI_API GSLSplineDeriv2 : public AbsFunction
412 {
413 public:
414 typedef SplineBase::Data1D Data1D ;
415 typedef SplineBase::Data2D Data2D ;
416 public:
418 FUNCTION_OBJECT_DEF( GSLSplineDeriv2 )
419 public:
440 GSLSplineDeriv2
441 ( const Data1D& x ,
442 const Data1D& y ,
443 const GaudiMath::Interpolation::Type type ) ;
462 GSLSplineDeriv2
463 ( const Data2D& data ,
464 const GaudiMath::Interpolation::Type type ) ;
491 template <class DATAX, class DATAY>
492 GSLSplineDeriv2
493 ( const GaudiMath::Interpolation::Type type ,
494 DATAX begin_x ,
495 DATAX end_x ,
496 DATAY begin_y )
497 : AbsFunction ( )
498 , m_spline( type , begin_x , end_x , begin_y )
499 {}
511 template <class DATA>
512 GSLSplineDeriv2
513 ( const GaudiMath::Interpolation::Type type ,
514 DATA begin ,
515 DATA end )
516 : AbsFunction ( )
517 , m_spline( type , begin , end )
518 {}
520 GSLSplineDeriv2 ( const SplineBase& ) ;
522 GSLSplineDeriv2 ( const GSLSplineDeriv2& ) ;
524 ~GSLSplineDeriv2() override;
525 public:
527 double operator() ( double a ) const override;
529 double operator() ( const Argument& x ) const override;
530 unsigned int dimensionality () const override { return 1 ; }
532 bool hasAnalyticDerivative() const override { return true ; }
534 Genfun::Derivative partial( unsigned int i ) const override;
535 public:
537 inline const SplineBase& spline() const { return m_spline ; }
539 operator const SplineBase& () const { return spline() ; }
540 private:
542 GSLSplineDeriv2() = delete;
544 GSLSplineDeriv2& operator=( const GSLSplineDeriv2& ) = delete;
545 private:
546 // the actual spline function
547 SplineBase m_spline ;
548 };
549
550
551 class GAUDI_API GSLSplineInteg : public AbsFunction
552 {
553 public:
554 typedef SplineBase::Data1D Data1D ;
555 typedef SplineBase::Data2D Data2D ;
556 public:
558 FUNCTION_OBJECT_DEF( GSLSplineInteg )
559 public:
580 GSLSplineInteg
581 ( const Data1D& x ,
582 const Data1D& y ,
583 const GaudiMath::Interpolation::Type type ,
584 const double low = 0 ) ;
604 GSLSplineInteg
605 ( const Data2D& data ,
606 const GaudiMath::Interpolation::Type type ,
607 const double low = 0 ) ;
635 template <class DATAX, class DATAY>
636 GSLSplineInteg
637 ( const GaudiMath::Interpolation::Type type ,
638 DATAX begin_x ,
639 DATAX end_x ,
640 DATAY begin_y ,
641 const double low )
642 : AbsFunction ( )
643 , m_spline ( type , begin_x , end_x , begin_y )
644 , m_low ( low )
645 {}
658 template <class DATA>
659 GSLSplineInteg
660 ( const GaudiMath::Interpolation::Type type ,
661 DATA&& begin ,
662 DATA&& end ,
663 const double low )
664 : m_spline ( type , std::forward<DATA>(begin) , std::forward<DATA>(end) )
665 , m_low ( low )
666 {}
668 GSLSplineInteg ( const SplineBase& ,
669 const double low = 0 ) ;
671 GSLSplineInteg ( const GSLSplineInteg& ) ;
673 ~GSLSplineInteg () override;
674 public:
676 double operator() ( double a ) const override;
678 double operator() ( const Argument& x ) const override;
679 unsigned int dimensionality () const override { return 1 ; }
681 bool hasAnalyticDerivative() const override { return true ; }
683 Genfun::Derivative partial( unsigned int i ) const override;
684 public:
686 inline const SplineBase& spline() const { return m_spline ; }
688 operator const SplineBase& () const { return spline() ; }
689 private:
691 GSLSplineInteg () = delete;
693 GSLSplineInteg& operator=( const GSLSplineInteg& ) = delete;
694 private:
695 // the actual spline function
696 SplineBase m_spline ;
697 double m_low ;
698 };
699
700 }
701 }
702
703 #endif // GAUDIMATH_SPLINES_H
704 // ============================================================================
Kernel.h
Genfun::GaudiMathImplementation::GSLSplineInteg::spline
const SplineBase & spline() const
acess to the spline function
Definition: Splines.h:686
std::copy
T copy(T...args)
AnalysisTest.initialize
def initialize()
Definition: AnalysisTest.py:12
Genfun::GaudiMathImplementation::GSLSplineInteg::Data2D
SplineBase::Data2D Data2D
Definition: Splines.h:555
Genfun::GaudiMathImplementation::GSLSpline::Data2D
SplineBase::Data2D Data2D
Definition: Splines.h:137
Genfun::GaudiMathImplementation::GSLSpline::dimensionality
virtual unsigned int dimensionality() const
Definition: Splines.h:252
Genfun::GaudiMathImplementation::SplineBase
Definition: Splines.h:35
Genfun::GaudiMathImplementation::GSLSpline::spline
const SplineBase & spline() const
acess to the spline function
Definition: Splines.h:259
Genfun::GaudiMathImplementation::GSLSplineInteg::Data1D
SplineBase::Data1D Data1D
Definition: Splines.h:554
Genfun::GaudiMathImplementation::GSLSplineDeriv::spline
const SplineBase & spline() const
acess to the spline function
Definition: Splines.h:398
Genfun::GaudiMathImplementation::GSLSplineDeriv2::m_spline
SplineBase m_spline
Definition: Splines.h:547
Genfun::GaudiMathImplementation::GSLSpline::hasAnalyticDerivative
virtual bool hasAnalyticDerivative() const
Does this function have an analytic derivative?
Definition: Splines.h:254
Genfun::GaudiMathImplementation::GSLSplineDeriv2::Data2D
SplineBase::Data2D Data2D
Definition: Splines.h:415
Genfun::GaudiMathImplementation::SplineBase::m_y
std::unique_ptr< double[]> m_y
Definition: Splines.h:127
GaudiMath::Derivative
Genfun::GaudiMathImplementation::NumericalDerivative Derivative
Definition: GaudiMath.h:29
Genfun::GaudiMathImplementation::GSLSplineDeriv2::hasAnalyticDerivative
bool hasAnalyticDerivative() const override
Does this function have an analytic derivative?
Definition: Splines.h:532
Genfun::GaudiMathImplementation::GSLSplineDeriv::hasAnalyticDerivative
bool hasAnalyticDerivative() const override
Does this function have an analytic derivative?
Definition: Splines.h:393
begin
auto begin(reverse_wrapper< T > &w)
Definition: reverse.h:45
Gaudi::Units::second
constexpr double second
Definition: SystemOfUnits.h:122
Genfun::GaudiMathImplementation::GSLSpline::Data1D
SplineBase::Data1D Data1D
Definition: Splines.h:136
gaudirun.type
string type
Definition: gaudirun.py:151
Genfun::GaudiMathImplementation::GSLSplineDeriv2::dimensionality
unsigned int dimensionality() const override
Definition: Splines.h:530
Genfun::GaudiMathImplementation::SplineBase::Data1D
std::vector< double > Data1D
Definition: Splines.h:38
Genfun::GaudiMathImplementation::SplineBase::m_type
GaudiMath::Interpolation::Type m_type
Definition: Splines.h:130
Genfun::GaudiMathImplementation::GSLSplineDeriv::m_spline
SplineBase m_spline
Definition: Splines.h:408
Genfun::GaudiMathImplementation::SplineBase::m_x
std::unique_ptr< double[]> m_x
Definition: Splines.h:126
end
auto end(reverse_wrapper< T > &w)
Definition: reverse.h:47
Genfun::GaudiMathImplementation::GSLSplineInteg::hasAnalyticDerivative
bool hasAnalyticDerivative() const override
Does this function have an analytic derivative?
Definition: Splines.h:681
Genfun::GaudiMathImplementation::GSLSplineDeriv2::Data1D
SplineBase::Data1D Data1D
Definition: Splines.h:414
Interpolation.h
Genfun::GaudiMathImplementation::GSLSplineDeriv::Data2D
SplineBase::Data2D Data2D
Definition: Splines.h:276
std::vector< double >
class
#define class
Definition: AIDA_visibility_hack.h:24
std::unique_ptr< double[]>
Genfun::GaudiMathImplementation::GSLSplineDeriv::Data1D
SplineBase::Data1D Data1D
Definition: Splines.h:275
Genfun::GaudiMathImplementation::GSLSpline::m_spline
SplineBase m_spline
Definition: Splines.h:269
Genfun::GaudiMathImplementation::SplineBase::m_dim
size_t m_dim
Definition: Splines.h:125
Genfun::GaudiMathImplementation::GSLSplineDeriv::dimensionality
unsigned int dimensionality() const override
Definition: Splines.h:391
GaudiMath::Interpolation::Type
Type
Definition: Interpolation.h:11
GaudiMath
GaudiMath.h GaudiMath/GaudiMath.h.
Definition: Adapters.h:13
Genfun::GaudiMathImplementation::GSLSplineInteg::dimensionality
unsigned int dimensionality() const override
Definition: Splines.h:679
Genfun::GaudiMathImplementation::GSLSplineDeriv
Definition: Splines.h:272
Genfun::GaudiMathImplementation::GSLSpline
Definition: Splines.h:133
Genfun
CLHEP.
Definition: IEqSolver.h:13
Genfun::GaudiMathImplementation::GSLSplineDeriv2
Definition: Splines.h:411
Genfun::GaudiMathImplementation::GSLSplineDeriv2::spline
const SplineBase & spline() const
acess to the spline function
Definition: Splines.h:537
Genfun::GaudiMathImplementation::GSLSplineInteg
Definition: Splines.h:551
GAUDI_API
#define GAUDI_API
Definition: Kernel.h:107
ana.i
list i
Definition: ana.py:128
Tuples::Type
Type
the list of available types for ntuples
Definition: TupleObj.h:79
Genfun::GaudiMathImplementation::SplineBase::Data2D
std::vector< std::pair< double, double > > Data2D
Definition: Splines.h:39
Genfun::GaudiMathImplementation::GSLSplineInteg::m_spline
SplineBase m_spline
Definition: Splines.h:696
Genfun::GaudiMathImplementation::GSLSplineInteg::m_low
double m_low
Definition: Splines.h:697