| # Gaudi Framework, version v20r4
Generated: 8 Jan 2009

# Splines.h

Go to the documentation of this file.

    00001 // $Id: Splines.h,v 1.2 2005/11/25 10:27:03 mato Exp $
    00002 // ============================================================================
    00003 #ifndef GAUDIMATH_SPLINES_H
    00004 #define GAUDIMATH_SPLINES_H 1
    00005 // ============================================================================
    00006 // Include files
    00007 // ============================================================================
    00008 // STD/STL
    00009 // ============================================================================
    00010 #include <vector>
    00011 #include <utility>
    00012 #include <algorithm>
    00013 // ============================================================================
    00014 // from CLHEP
    00015 // ============================================================================
    00016 #include "CLHEP/GenericFunctions/GenericFunctions.hh"
    00017 #include "CLHEP/GenericFunctions/Argument.hh"
    00018 #include "CLHEP/GenericFunctions/AbsFunction.hh"
    00019 // ============================================================================
    00020 // GaudiGSL/GaudiMath
    00021 // ============================================================================
    00022 #include "GaudiMath/Interpolation.h"
    00023 // ============================================================================
    00024 // GSL
    00025 // ============================================================================
    00026 #include "gsl/gsl_interp.h"
    00027 #include "gsl/gsl_spline.h"
    00028 // ============================================================================
    00029
    00030 namespace Genfun
    00031 {
    00032   namespace GaudiMathImplementation
    00033   {
    00034
    00035     class  SplineBase
    00036     {
    00037     public:
    00038       typedef std::vector<double>                    Data1D ;
    00039       typedef std::vector<std::pair<double,double> > Data2D ;
    00040     public:
    00046       SplineBase
    00047       ( const Data1D&                        x    ,
    00048         const Data1D&                        y    ,
    00049         const GaudiMath::Interpolation::Type type ) ;
    00054       SplineBase
    00055       ( const Data2D&                        data ,
    00056         const GaudiMath::Interpolation::Type type ) ;
    00063       template <class DATAX, class DATAY>
    00064       SplineBase
    00065       ( const GaudiMath::Interpolation::Type type    ,
    00066         DATAX                                begin_x ,
    00067         DATAX                                end_x   ,
    00068         DATAY                                begin_y )
    00069         : m_init      ( false           )
    00070         , m_dim       ( end_x - begin_x )
    00071         , m_x         ( new double[ end_x - begin_x ] )
    00072         , m_y         ( new double[ end_x - begin_x ] )
    00073         , m_spline    ( 0    )
    00074         , m_accel     ( 0    )
    00075         , m_type      ( type )
    00076       {
    00077         std::copy ( begin_x , end_x                         , m_x ) ;
    00078         std::copy ( begin_y , begin_y + ( end_x - begin_x ) , m_y ) ;
    00079       };
    00087       template <class DATA>
    00088       SplineBase
    00089       ( const GaudiMath::Interpolation::Type type  ,
    00090         DATA                                 begin ,
    00091         DATA                                 end   )
    00092         : m_init      ( false        )
    00093         , m_dim       ( end - begin  )
    00094         , m_x         ( new double[ end - begin ] )
    00095         , m_y         ( new double[ end - begin ] )
    00096         , m_spline    ( 0    )
    00097         , m_accel     ( 0    )
    00098         , m_type      ( type )
    00099       {
    00100         double* _x = m_x ;
    00101         double* _y = m_y ;
    00102         for ( DATA it = begin ; end != it ; ++ it )
    00103         {
    00104           *_x = it -> first  ; ++_x ;
    00105           *_y = it -> second ; ++_y ;
    00106         };
    00107       };
    00109       SplineBase( const SplineBase& ) ;
    00111       virtual ~SplineBase();
    00112     public:
    00114       double eval   ( const double x ) const ;
    00116       double deriv  ( const double x ) const ;
    00118       double deriv2 ( const double x ) const ;
    00120       double integ  ( const double a , const double b ) const ;
    00121     protected:
    00122       // initialize
    00123       void initialize () const ;
    00124     private:
    00125       // default constructor is disabled
    00126       SplineBase() ;
    00127       // assigenement operator  is disabled
    00128       SplineBase& operator=( const SplineBase& ) ;
    00129     private:
    00130       mutable bool                   m_init   ;
    00131       size_t                         m_dim    ;
    00132       double*                        m_x      ;
    00133       double*                        m_y      ;
    00134       mutable gsl_spline*            m_spline ;
    00135       mutable gsl_interp_accel*      m_accel  ;
    00136       GaudiMath::Interpolation::Type m_type   ;
    00137     };
    00138
    00139     class GSLSpline : public AbsFunction
    00140     {
    00141     public:
    00142       typedef SplineBase::Data1D Data1D ;
    00143       typedef SplineBase::Data2D Data2D ;
    00144     public:
    00146       FUNCTION_OBJECT_DEF( GSLSpline ) ;
    00147     public:
    00168       GSLSpline
    00169       ( const Data1D&                        x    ,
    00170         const Data1D&                        y    ,
    00171         const GaudiMath::Interpolation::Type type ) ;
    00190       GSLSpline
    00191       ( const Data2D&                        data ,
    00192         const GaudiMath::Interpolation::Type type ) ;
    00219       template <class DATAX, class DATAY>
    00220       GSLSpline
    00221       ( const GaudiMath::Interpolation::Type type    ,
    00222         DATAX                                begin_x ,
    00223         DATAX                                end_x   ,
    00224         DATAY                                begin_y )
    00225         : AbsFunction ( )
    00226         , m_spline( type , begin_x , end_x , begin_y )
    00227       {};
    00239       template <class DATA>
    00240       GSLSpline
    00241       ( const GaudiMath::Interpolation::Type type  ,
    00242         DATA                                 begin ,
    00243         DATA                                 end   )
    00244         : AbsFunction ( )
    00245         , m_spline( type , begin , end )
    00246       {};
    00248       GSLSpline ( const SplineBase& ) ;
    00250       GSLSpline ( const GSLSpline& ) ;
    00252       virtual ~GSLSpline() ;
    00253     public:
    00255       virtual double operator() ( double a          ) const ;
    00257       virtual double operator() ( const Argument& x ) const ;
    00258       virtual unsigned int dimensionality () const { return 1   ; }
    00260       virtual bool  hasAnalyticDerivative() const { return true ; }
    00262       virtual Genfun::Derivative partial( unsigned int i  ) const ;
    00263     public:
    00265       inline   const SplineBase& spline() const { return m_spline ; }
    00267       operator const SplineBase&       () const { return spline() ; }
    00268     private:
    00270       GSLSpline() ;
    00272       GSLSpline& operator=( const GSLSpline& ) ;
    00273     private:
    00274       // the actual spline function
    00275       SplineBase m_spline ;
    00276     };
    00277
    00278     class GSLSplineDeriv : public AbsFunction
    00279     {
    00280     public:
    00281       typedef SplineBase::Data1D Data1D ;
    00282       typedef SplineBase::Data2D Data2D ;
    00283     public:
    00285       FUNCTION_OBJECT_DEF( GSLSplineDeriv ) ;
    00286     public:
    00307       GSLSplineDeriv
    00308       ( const Data1D&                        x    ,
    00309         const Data1D&                        y    ,
    00310         const GaudiMath::Interpolation::Type type ) ;
    00329       GSLSplineDeriv
    00330       ( const Data2D&                        data ,
    00331         const GaudiMath::Interpolation::Type type ) ;
    00358       template <class DATAX, class DATAY>
    00359       GSLSplineDeriv
    00360       ( const GaudiMath::Interpolation::Type type    ,
    00361         DATAX                                begin_x ,
    00362         DATAX                                end_x   ,
    00363         DATAY                                begin_y )
    00364         : AbsFunction ( )
    00365         , m_spline( type , begin_x , end_x , begin_y )
    00366       {};
    00378       template <class DATA>
    00379       GSLSplineDeriv
    00380       ( const GaudiMath::Interpolation::Type type  ,
    00381         DATA                                 begin ,
    00382         DATA                                 end   )
    00383         : AbsFunction ( )
    00384         , m_spline( type , begin , end )
    00385       {};
    00387       GSLSplineDeriv ( const SplineBase&     ) ;
    00389       GSLSplineDeriv ( const GSLSplineDeriv& ) ;
    00391       virtual ~GSLSplineDeriv() ;
    00392     public:
    00394       virtual double operator() ( double a          ) const ;
    00396       virtual double operator() ( const Argument& x ) const ;
    00397       virtual unsigned int dimensionality () const { return 1   ; }
    00399       virtual bool  hasAnalyticDerivative() const { return true ; }
    00401       virtual Genfun::Derivative partial( unsigned int i  ) const ;
    00402     public:
    00404       inline   const SplineBase& spline() const { return m_spline ; }
    00406       operator const SplineBase&       () const { return spline() ; }
    00407     private:
    00409       GSLSplineDeriv() ;
    00411       GSLSplineDeriv& operator=( const GSLSplineDeriv& ) ;
    00412     private:
    00413       // the actual spline function
    00414       SplineBase m_spline ;
    00415     };
    00416
    00417     class GSLSplineDeriv2 : public AbsFunction
    00418     {
    00419     public:
    00420       typedef SplineBase::Data1D Data1D ;
    00421       typedef SplineBase::Data2D Data2D ;
    00422     public:
    00424       FUNCTION_OBJECT_DEF( GSLSplineDeriv2 ) ;
    00425     public:
    00446       GSLSplineDeriv2
    00447       ( const Data1D&                        x    ,
    00448         const Data1D&                        y    ,
    00449         const GaudiMath::Interpolation::Type type ) ;
    00468       GSLSplineDeriv2
    00469       ( const Data2D&                        data ,
    00470         const GaudiMath::Interpolation::Type type ) ;
    00497       template <class DATAX, class DATAY>
    00498       GSLSplineDeriv2
    00499       ( const GaudiMath::Interpolation::Type type    ,
    00500         DATAX                                begin_x ,
    00501         DATAX                                end_x   ,
    00502         DATAY                                begin_y )
    00503         : AbsFunction ( )
    00504         , m_spline( type , begin_x , end_x , begin_y )
    00505       {};
    00517       template <class DATA>
    00518       GSLSplineDeriv2
    00519       ( const GaudiMath::Interpolation::Type type  ,
    00520         DATA                                 begin ,
    00521         DATA                                 end   )
    00522         : AbsFunction ( )
    00523         , m_spline( type , begin , end )
    00524       {};
    00526       GSLSplineDeriv2 ( const SplineBase&      ) ;
    00528       GSLSplineDeriv2 ( const GSLSplineDeriv2& ) ;
    00530       virtual ~GSLSplineDeriv2() ;
    00531     public:
    00533       virtual double operator() ( double a          ) const ;
    00535       virtual double operator() ( const Argument& x ) const ;
    00536       virtual unsigned int dimensionality () const { return 1   ; }
    00538       virtual bool  hasAnalyticDerivative() const { return true ; }
    00540       virtual Genfun::Derivative partial( unsigned int i  ) const ;
    00541     public:
    00543       inline   const SplineBase& spline() const { return m_spline ; }
    00545       operator const SplineBase&       () const { return spline() ; }
    00546     private:
    00548       GSLSplineDeriv2() ;
    00550       GSLSplineDeriv2& operator=( const GSLSplineDeriv2& ) ;
    00551     private:
    00552       // the actual spline function
    00553       SplineBase m_spline ;
    00554     };
    00555
    00556
    00557     class GSLSplineInteg : public AbsFunction
    00558     {
    00559     public:
    00560       typedef SplineBase::Data1D Data1D ;
    00561       typedef SplineBase::Data2D Data2D ;
    00562     public:
    00564       FUNCTION_OBJECT_DEF( GSLSplineInteg ) ;
    00565     public:
    00586       GSLSplineInteg
    00587       ( const Data1D&                        x        ,
    00588         const Data1D&                        y        ,
    00589         const GaudiMath::Interpolation::Type type     ,
    00590         const double                         low  = 0 ) ;
    00610       GSLSplineInteg
    00611       ( const Data2D&                        data     ,
    00612         const GaudiMath::Interpolation::Type type     ,
    00613         const double                         low  = 0 ) ;
    00641       template <class DATAX, class DATAY>
    00642       GSLSplineInteg
    00643       ( const GaudiMath::Interpolation::Type type    ,
    00644         DATAX                                begin_x ,
    00645         DATAX                                end_x   ,
    00646         DATAY                                begin_y ,
    00647         const double                         low     )
    00648         : AbsFunction (      )
    00649         , m_spline    ( type , begin_x , end_x , begin_y )
    00650         , m_low       ( low  )
    00651       {};
    00664       template <class DATA>
    00665       GSLSplineInteg
    00666       ( const GaudiMath::Interpolation::Type type  ,
    00667         DATA                                 begin ,
    00668         DATA                                 end   ,
    00669         const double                         low   )
    00670         : AbsFunction (      )
    00671         , m_spline    ( type , begin , end )
    00672         , m_low       ( low  )
    00673       {};
    00675       GSLSplineInteg ( const SplineBase&              ,
    00676                        const double           low = 0 ) ;
    00678       GSLSplineInteg ( const GSLSplineInteg&      ) ;
    00680       virtual ~GSLSplineInteg () ;
    00681     public:
    00683       virtual double operator() ( double a          ) const ;
    00685       virtual double operator() ( const Argument& x ) const ;
    00686       virtual unsigned int dimensionality () const { return 1   ; }
    00688       virtual bool  hasAnalyticDerivative() const { return true ; }
    00690       virtual Genfun::Derivative partial( unsigned int i  ) const ;
    00691     public:
    00693       inline   const SplineBase& spline() const { return m_spline ; }
    00695       operator const SplineBase&       () const { return spline() ; }
    00696     private:
    00698       GSLSplineInteg () ;
    00700       GSLSplineInteg& operator=( const GSLSplineInteg& ) ;
    00701     private:
    00702       // the actual spline function
    00703       SplineBase m_spline ;
    00704       double     m_low    ;
    00705     };
    00706
    00707   };
    00708 };
    00709
    00710
    00711 #endif // GAUDIMATH_SPLINES_H
    00712 // ============================================================================