| # Gaudi Framework, version v25r0 |

Home |  | Generated: Mon Feb 17 2014

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

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Splines.h
Go to the documentation of this file.
1 // $Id: Splines.h,v 1.2 2005/11/25 10:27:03 mato Exp $
2 // ============================================================================
3 #ifndef GAUDIMATH_SPLINES_H
4 #define GAUDIMATH_SPLINES_H 1
5 // ============================================================================
6 // Include files
7 // ============================================================================
8 // STD/STL
9 // ============================================================================
10 #include <vector>
11 #include <utility>
12 #include <algorithm>
13 // ============================================================================
14 // from CLHEP
15 // ============================================================================
16 #include "CLHEP/GenericFunctions/GenericFunctions.hh"
17 #include "CLHEP/GenericFunctions/Argument.hh"
18 #include "CLHEP/GenericFunctions/AbsFunction.hh"
19 // ============================================================================
20 // GaudiGSL/GaudiMath
21 // ============================================================================
22 #include "GaudiMath/Interpolation.h"
23 // ============================================================================
24 // GSL
25 // ============================================================================
26 #include "gsl/gsl_interp.h"
27 #include "gsl/gsl_spline.h"
28 // ============================================================================
29 #include "GaudiKernel/Kernel.h"
30
31 namespace Genfun
32 {
33 namespace GaudiMathImplementation
34 {
35
36 class GAUDI_API SplineBase
37 {
38 public:
39 typedef std::vector<double> Data1D ;
40 typedef std::vector<std::pair<double,double> > Data2D ;
41 public:
47 SplineBase
48 ( const Data1D& x ,
49 const Data1D& y ,
50 const GaudiMath::Interpolation::Type type ) ;
55 SplineBase
56 ( const Data2D& data ,
57 const GaudiMath::Interpolation::Type type ) ;
64 template <class DATAX, class DATAY>
65 SplineBase
66 ( const GaudiMath::Interpolation::Type type ,
67 DATAX begin_x ,
68 DATAX end_x ,
69 DATAY begin_y )
70 : m_init ( false )
71 , m_dim ( end_x - begin_x )
72 , m_x ( new double[ end_x - begin_x ] )
73 , m_y ( new double[ end_x - begin_x ] )
74 , m_spline ( 0 )
75 , m_accel ( 0 )
76 , m_type ( type )
77 {
78 std::copy ( begin_x , end_x , m_x ) ;
79 std::copy ( begin_y , begin_y + ( end_x - begin_x ) , m_y ) ;
80 }
88 template <class DATA>
89 SplineBase
90 ( const GaudiMath::Interpolation::Type type ,
91 DATA begin ,
92 DATA end )
93 : m_init ( false )
94 , m_dim ( end - begin )
95 , m_x ( new double[ end - begin ] )
96 , m_y ( new double[ end - begin ] )
97 , m_spline ( 0 )
98 , m_accel ( 0 )
99 , m_type ( type )
100 {
101 double* _x = m_x ;
102 double* _y = m_y ;
103 for ( DATA it = begin ; end != it ; ++ it )
104 {
105 *_x = it -> first ; ++_x ;
106 *_y = it -> second ; ++_y ;
107 };
108 }
110 SplineBase( const SplineBase& ) ;
112 virtual ~SplineBase();
113 public:
115 double eval ( const double x ) const ;
117 double deriv ( const double x ) const ;
119 double deriv2 ( const double x ) const ;
121 double integ ( const double a , const double b ) const ;
122 protected:
123 // initialize
124 void initialize () const ;
125 private:
126 // default constructor is disabled
127 SplineBase() ;
128 // assigenement operator is disabled
129 SplineBase& operator=( const SplineBase& ) ;
130 private:
131 mutable bool m_init ;
132 size_t m_dim ;
133 double* m_x ;
134 double* m_y ;
135 mutable gsl_spline* m_spline ;
136 mutable gsl_interp_accel* m_accel ;
137 GaudiMath::Interpolation::Type m_type ;
138 };
139
140 class GAUDI_API GSLSpline : public AbsFunction
141 {
142 public:
143 typedef SplineBase::Data1D Data1D ;
144 typedef SplineBase::Data2D Data2D ;
145 public:
147 FUNCTION_OBJECT_DEF( GSLSpline )
148 public:
169 GSLSpline
170 ( const Data1D& x ,
171 const Data1D& y ,
172 const GaudiMath::Interpolation::Type type ) ;
191 GSLSpline
192 ( const Data2D& data ,
193 const GaudiMath::Interpolation::Type type ) ;
220 template <class DATAX, class DATAY>
221 GSLSpline
222 ( const GaudiMath::Interpolation::Type type ,
223 DATAX begin_x ,
224 DATAX end_x ,
225 DATAY begin_y )
226 : AbsFunction ( )
227 , m_spline( type , begin_x , end_x , begin_y )
228 {}
240 template <class DATA>
241 GSLSpline
242 ( const GaudiMath::Interpolation::Type type ,
243 DATA begin ,
244 DATA end )
245 : AbsFunction ( )
246 , m_spline( type , begin , end )
247 {}
249 GSLSpline ( const SplineBase& ) ;
251 GSLSpline ( const GSLSpline& ) ;
253 virtual ~GSLSpline() ;
254 public:
256 virtual double operator() ( double a ) const ;
258 virtual double operator() ( const Argument& x ) const ;
259 virtual unsigned int dimensionality () const { return 1 ; }
261 virtual bool hasAnalyticDerivative() const { return true ; }
263 virtual Genfun::Derivative partial( unsigned int i ) const ;
264 public:
266 inline const SplineBase& spline() const { return m_spline ; }
268 operator const SplineBase& () const { return spline() ; }
269 private:
271 GSLSpline() ;
273 GSLSpline& operator=( const GSLSpline& ) ;
274 private:
275 // the actual spline function
276 SplineBase m_spline ;
277 };
278
279 class GAUDI_API GSLSplineDeriv : public AbsFunction
280 {
281 public:
282 typedef SplineBase::Data1D Data1D ;
283 typedef SplineBase::Data2D Data2D ;
284 public:
286 FUNCTION_OBJECT_DEF( GSLSplineDeriv )
287 public:
308 GSLSplineDeriv
309 ( const Data1D& x ,
310 const Data1D& y ,
311 const GaudiMath::Interpolation::Type type ) ;
330 GSLSplineDeriv
331 ( const Data2D& data ,
332 const GaudiMath::Interpolation::Type type ) ;
359 template <class DATAX, class DATAY>
360 GSLSplineDeriv
361 ( const GaudiMath::Interpolation::Type type ,
362 DATAX begin_x ,
363 DATAX end_x ,
364 DATAY begin_y )
365 : AbsFunction ( )
366 , m_spline( type , begin_x , end_x , begin_y )
367 {}
379 template <class DATA>
380 GSLSplineDeriv
381 ( const GaudiMath::Interpolation::Type type ,
382 DATA begin ,
383 DATA end )
384 : AbsFunction ( )
385 , m_spline( type , begin , end )
386 {}
388 GSLSplineDeriv ( const SplineBase& ) ;
390 GSLSplineDeriv ( const GSLSplineDeriv& ) ;
392 virtual ~GSLSplineDeriv() ;
393 public:
395 virtual double operator() ( double a ) const ;
397 virtual double operator() ( const Argument& x ) const ;
398 virtual unsigned int dimensionality () const { return 1 ; }
400 virtual bool hasAnalyticDerivative() const { return true ; }
402 virtual Genfun::Derivative partial( unsigned int i ) const ;
403 public:
405 inline const SplineBase& spline() const { return m_spline ; }
407 operator const SplineBase& () const { return spline() ; }
408 private:
410 GSLSplineDeriv() ;
412 GSLSplineDeriv& operator=( const GSLSplineDeriv& ) ;
413 private:
414 // the actual spline function
415 SplineBase m_spline ;
416 };
417
418 class GAUDI_API GSLSplineDeriv2 : public AbsFunction
419 {
420 public:
421 typedef SplineBase::Data1D Data1D ;
422 typedef SplineBase::Data2D Data2D ;
423 public:
425 FUNCTION_OBJECT_DEF( GSLSplineDeriv2 )
426 public:
447 GSLSplineDeriv2
448 ( const Data1D& x ,
449 const Data1D& y ,
450 const GaudiMath::Interpolation::Type type ) ;
469 GSLSplineDeriv2
470 ( const Data2D& data ,
471 const GaudiMath::Interpolation::Type type ) ;
498 template <class DATAX, class DATAY>
499 GSLSplineDeriv2
500 ( const GaudiMath::Interpolation::Type type ,
501 DATAX begin_x ,
502 DATAX end_x ,
503 DATAY begin_y )
504 : AbsFunction ( )
505 , m_spline( type , begin_x , end_x , begin_y )
506 {}
518 template <class DATA>
519 GSLSplineDeriv2
520 ( const GaudiMath::Interpolation::Type type ,
521 DATA begin ,
522 DATA end )
523 : AbsFunction ( )
524 , m_spline( type , begin , end )
525 {}
527 GSLSplineDeriv2 ( const SplineBase& ) ;
529 GSLSplineDeriv2 ( const GSLSplineDeriv2& ) ;
531 virtual ~GSLSplineDeriv2() ;
532 public:
534 virtual double operator() ( double a ) const ;
536 virtual double operator() ( const Argument& x ) const ;
537 virtual unsigned int dimensionality () const { return 1 ; }
539 virtual bool hasAnalyticDerivative() const { return true ; }
541 virtual Genfun::Derivative partial( unsigned int i ) const ;
542 public:
544 inline const SplineBase& spline() const { return m_spline ; }
546 operator const SplineBase& () const { return spline() ; }
547 private:
549 GSLSplineDeriv2() ;
551 GSLSplineDeriv2& operator=( const GSLSplineDeriv2& ) ;
552 private:
553 // the actual spline function
554 SplineBase m_spline ;
555 };
556
557
558 class GAUDI_API GSLSplineInteg : public AbsFunction
559 {
560 public:
561 typedef SplineBase::Data1D Data1D ;
562 typedef SplineBase::Data2D Data2D ;
563 public:
565 FUNCTION_OBJECT_DEF( GSLSplineInteg )
566 public:
587 GSLSplineInteg
588 ( const Data1D& x ,
589 const Data1D& y ,
590 const GaudiMath::Interpolation::Type type ,
591 const double low = 0 ) ;
611 GSLSplineInteg
612 ( const Data2D& data ,
613 const GaudiMath::Interpolation::Type type ,
614 const double low = 0 ) ;
642 template <class DATAX, class DATAY>
643 GSLSplineInteg
644 ( const GaudiMath::Interpolation::Type type ,
645 DATAX begin_x ,
646 DATAX end_x ,
647 DATAY begin_y ,
648 const double low )
649 : AbsFunction ( )
650 , m_spline ( type , begin_x , end_x , begin_y )
651 , m_low ( low )
652 {}
665 template <class DATA>
666 GSLSplineInteg
667 ( const GaudiMath::Interpolation::Type type ,
668 DATA begin ,
669 DATA end ,
670 const double low )
671 : AbsFunction ( )
672 , m_spline ( type , begin , end )
673 , m_low ( low )
674 {}
676 GSLSplineInteg ( const SplineBase& ,
677 const double low = 0 ) ;
679 GSLSplineInteg ( const GSLSplineInteg& ) ;
681 virtual ~GSLSplineInteg () ;
682 public:
684 virtual double operator() ( double a ) const ;
686 virtual double operator() ( const Argument& x ) const ;
687 virtual unsigned int dimensionality () const { return 1 ; }
689 virtual bool hasAnalyticDerivative() const { return true ; }
691 virtual Genfun::Derivative partial( unsigned int i ) const ;
692 public:
694 inline const SplineBase& spline() const { return m_spline ; }
696 operator const SplineBase& () const { return spline() ; }
697 private:
699 GSLSplineInteg () ;
701 GSLSplineInteg& operator=( const GSLSplineInteg& ) ;
702 private:
703 // the actual spline function
704 SplineBase m_spline ;
705 double m_low ;
706 };
707
708 }
709 }
710
711
712 #endif // GAUDIMATH_SPLINES_H
713 // ============================================================================