#include <PhysicsTools/MVAComputer/interface/Spline.h>
Public Member Functions | |
double | eval (double x) const |
compute y coordinate at x coordinate x | |
double | getArea () const |
total area (integral between 0 and 1) under curve | |
double | integral (double x) const |
compute integral under curve between 0 and x | |
unsigned int | numberOfEntries () const |
return the number of entries | |
Spline & | operator= (const Spline &orig) |
void | set (unsigned int n, const double *vals) |
initialize spline from n y coordinates in array vals | |
Spline (unsigned int n, const double *vals) | |
construct spline from n y coordinates in array vals | |
Spline (const Spline &orig) | |
Spline () | |
~Spline () | |
Private Attributes | |
double | area |
unsigned int | n |
Segment * | segments |
Classes | |
struct | Segment |
internal class describing a "segment" (between two x points) More... |
This class implements cubic splines for n equidistant points in x between 0 and 1. It is constructed from an array of n y coordinates and can compute the interpolated y coordinate for a given x.
Definition at line 26 of file Spline.h.
PhysicsTools::Spline::Spline | ( | ) |
PhysicsTools::Spline::Spline | ( | const Spline & | orig | ) |
PhysicsTools::Spline::Spline | ( | unsigned int | n, | |
const double * | vals | |||
) |
PhysicsTools::Spline::~Spline | ( | ) |
double PhysicsTools::Spline::eval | ( | double | x | ) | const |
compute y coordinate at x coordinate x
Definition at line 122 of file Spline.cc.
References PhysicsTools::Spline::Segment::eval(), int, n, and segments.
00123 { 00124 if (x <= 0.0) 00125 return segments[0].eval(0.0); 00126 if (x >= 1.0) 00127 return segments[n - 1].eval(1.0); 00128 00129 double total; 00130 double rest = std::modf(x * n, &total); 00131 00132 return segments[(unsigned int)total].eval(rest); 00133 }
double PhysicsTools::Spline::getArea | ( | ) | const [inline] |
double PhysicsTools::Spline::integral | ( | double | x | ) | const |
compute integral under curve between 0 and x
Definition at line 135 of file Spline.cc.
References area, e, int, n, and segments.
00136 { 00137 if (x <= 0.0) 00138 return 0.0; 00139 if (x >= 1.0) 00140 return 1.0; 00141 00142 if (area < 1.0e-9) 00143 return 0.0; 00144 00145 double total; 00146 double rest = std::modf(x * n, &total); 00147 00148 return segments[(unsigned int)total].integral(rest) / area; 00149 }
unsigned int PhysicsTools::Spline::numberOfEntries | ( | ) | const [inline] |
initialize spline from n y coordinates in array vals
Definition at line 57 of file Spline.cc.
References PhysicsTools::Spline::Segment::area, area, PhysicsTools::Spline::Segment::coeffs, i, PhysicsTools::Spline::Segment::integral(), m1, n, seg, and segments.
00058 { 00059 n = n_ - 1; 00060 area = 0.0; 00061 00062 delete[] segments; 00063 segments = new Segment[n]; 00064 00065 if (n == 1) { 00066 Segment *seg = &segments[0]; 00067 seg->coeffs[0] = vals[0]; 00068 seg->coeffs[1] = vals[1] - vals[0]; 00069 seg->coeffs[2] = 0.0; 00070 seg->coeffs[3] = 0.0; 00071 seg->area = 0.0; 00072 area = seg->integral(1.0); 00073 return; 00074 } 00075 00076 double m0, m1; 00077 Segment *seg = &segments[0]; 00078 m0 = 0.0, m1 = 0.5 * (vals[2] - vals[0]); 00079 seg->coeffs[0] = vals[0]; 00080 seg->coeffs[1] = -2.0 * vals[0] + 2.0 * vals[1] - m1; 00081 seg->coeffs[2] = vals[0] - vals[1] + m1; 00082 seg->coeffs[3] = 0.0; 00083 seg->area = 0.0; 00084 area = seg->integral(1.0); 00085 m0 = m1; 00086 seg++, vals++; 00087 00088 for(unsigned int i = 1; i < n - 1; i++, seg++, vals++) { 00089 m1 = 0.5 * (vals[2] - vals[0]); 00090 seg->coeffs[0] = vals[0]; 00091 seg->coeffs[1] = m0; 00092 seg->coeffs[2] = -3.0 * vals[0] - 2.0 * m0 + 3.0 * vals[1] - m1; 00093 seg->coeffs[3] = 2.0 * vals[0] + m0 - 2.0 * vals[1] + m1; 00094 seg->area = area; 00095 area = seg->integral(1.0); 00096 m0 = m1; 00097 } 00098 00099 seg->coeffs[0] = vals[0]; 00100 seg->coeffs[1] = m0; 00101 seg->coeffs[2] = - vals[0] - m0 + vals[1]; 00102 seg->coeffs[3] = 0.0; 00103 seg->area = area; 00104 area = seg->integral(1.0); 00105 }
double PhysicsTools::Spline::area [private] |
Definition at line 64 of file Spline.h.
Referenced by getArea(), integral(), operator=(), and set().
unsigned int PhysicsTools::Spline::n [private] |
Definition at line 62 of file Spline.h.
Referenced by eval(), integral(), operator=(), set(), and Spline().
Segment* PhysicsTools::Spline::segments [private] |
Definition at line 63 of file Spline.h.
Referenced by eval(), integral(), operator=(), set(), Spline(), and ~Spline().