Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:23:37

0001 #ifndef PhysicsTools_MVAComputer_Spline_h
0002 #define PhysicsTools_MVAComputer_Spline_h
0003 // -*- C++ -*-
0004 //
0005 // Package:     MVAComputer
0006 // Class  :     Spline
0007 //
0008 
0009 //
0010 // Author:  Christophe Saout <christophe.saout@cern.ch>
0011 // Created:     Sat Apr 24 15:18 CEST 2007
0012 //
0013 
0014 namespace PhysicsTools {
0015 
0016   /** \class Spline
0017  *
0018  * \short A simple class for cubic splines
0019  *
0020  * This class implements cubic splines for n equidistant points in x
0021  * between 0 and 1. It is constructed from an array of n y coordinates
0022  * and can compute the interpolated y coordinate for a given x.
0023  *
0024  ************************************************************/
0025   class Spline {
0026   public:
0027     Spline();
0028     Spline(const Spline &orig);
0029 
0030     /// construct spline from \a n y coordinates in array \a vals
0031     Spline(unsigned int n, const double *vals);
0032     ~Spline();
0033 
0034     Spline &operator=(const Spline &orig);
0035 
0036     /// initialize spline from \a n y coordinates in array \a vals
0037     void set(unsigned int n, const double *vals);
0038 
0039     /// compute y coordinate at x coordinate \a x
0040     float eval(float x) const;
0041 
0042     /// compute the derivate at x coordinate \a x
0043     float deriv(float x) const;
0044 
0045     /// compute integral under curve between 0 and \a x
0046     float integral(float x) const;
0047 
0048     /// total area (integral between 0 and 1) under curve
0049     float getArea() const { return area; }
0050 
0051     /// return the number of entries
0052     inline unsigned int numberOfEntries() const { return n + 1; }
0053 
0054   private:
0055     /// internal class describing a "segment" (between two x points)
0056     struct Segment {
0057       float coeffs[4];
0058       float area;
0059 
0060       float eval(float x) const;
0061       float deriv(float x) const;
0062       float integral(float x) const;
0063     };
0064 
0065     unsigned int n;
0066     Segment *segments;
0067     float area;
0068   };
0069 
0070 }  // namespace PhysicsTools
0071 
0072 #endif  // PhysicsTools_MVAComputer_Spline_h