A simple class for cubic splines. More...
#include <Spline.h>
Classes | |
struct | Segment |
internal class describing a "segment" (between two x points) More... | |
Public Member Functions | |
double | deriv (double x) const |
compute the derivate at x coordinate x | |
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 () | |
Spline (const Spline &orig) | |
Spline (unsigned int n, const double *vals) | |
construct spline from n y coordinates in array vals | |
~Spline () | |
Private Attributes | |
double | area |
unsigned int | n |
Segment * | segments |
A simple class for cubic splines.
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.
PhysicsTools::Spline::Spline | ( | ) |
PhysicsTools::Spline::Spline | ( | const Spline & | orig | ) |
PhysicsTools::Spline::Spline | ( | unsigned int | n, |
const double * | vals | ||
) |
PhysicsTools::Spline::~Spline | ( | ) |
double PhysicsTools::Spline::deriv | ( | double | x | ) | const |
compute the derivate at x coordinate x
Definition at line 145 of file Spline.cc.
References PhysicsTools::Spline::Segment::deriv(), n, segments, and pileupDistInMC::total.
double PhysicsTools::Spline::eval | ( | double | x | ) | const |
compute y coordinate at x coordinate x
Definition at line 132 of file Spline.cc.
References PhysicsTools::Spline::Segment::eval(), n, segments, and pileupDistInMC::total.
double PhysicsTools::Spline::getArea | ( | ) | const [inline] |
double PhysicsTools::Spline::integral | ( | double | x | ) | const |
compute integral under curve between 0 and x
Definition at line 160 of file Spline.cc.
References area, alignCSCRings::e, n, segments, and pileupDistInMC::total.
unsigned int PhysicsTools::Spline::numberOfEntries | ( | ) | const [inline] |
void PhysicsTools::Spline::set | ( | unsigned int | n, |
const double * | vals | ||
) |
initialize spline from n y coordinates in array vals
Definition at line 67 of file Spline.cc.
References PhysicsTools::Spline::Segment::area, area, PhysicsTools::Spline::Segment::coeffs, i, PhysicsTools::Spline::Segment::integral(), n, and segments.
{ n = n_ - 1; area = 0.0; delete[] segments; segments = new Segment[n]; if (n == 1) { Segment *seg = &segments[0]; seg->coeffs[0] = vals[0]; seg->coeffs[1] = vals[1] - vals[0]; seg->coeffs[2] = 0.0; seg->coeffs[3] = 0.0; seg->area = 0.0; area = seg->integral(1.0); return; } double m0, m1; Segment *seg = &segments[0]; m0 = 0.0, m1 = 0.5 * (vals[2] - vals[0]); seg->coeffs[0] = vals[0]; seg->coeffs[1] = -2.0 * vals[0] + 2.0 * vals[1] - m1; seg->coeffs[2] = vals[0] - vals[1] + m1; seg->coeffs[3] = 0.0; seg->area = 0.0; area = seg->integral(1.0); m0 = m1; seg++, vals++; for(unsigned int i = 1; i < n - 1; i++, seg++, vals++) { m1 = 0.5 * (vals[2] - vals[0]); seg->coeffs[0] = vals[0]; seg->coeffs[1] = m0; seg->coeffs[2] = -3.0 * vals[0] - 2.0 * m0 + 3.0 * vals[1] - m1; seg->coeffs[3] = 2.0 * vals[0] + m0 - 2.0 * vals[1] + m1; seg->area = area; area = seg->integral(1.0); m0 = m1; } seg->coeffs[0] = vals[0]; seg->coeffs[1] = m0; seg->coeffs[2] = - vals[0] - m0 + vals[1]; seg->coeffs[3] = 0.0; seg->area = area; area = seg->integral(1.0); }
double PhysicsTools::Spline::area [private] |
Definition at line 68 of file Spline.h.
Referenced by getArea(), integral(), PhysicsTools::Spline::Segment::integral(), operator=(), and set().
unsigned int PhysicsTools::Spline::n [private] |
Definition at line 66 of file Spline.h.
Referenced by deriv(), eval(), integral(), operator=(), set(), and Spline().
Segment* PhysicsTools::Spline::segments [private] |
Definition at line 67 of file Spline.h.
Referenced by deriv(), eval(), integral(), operator=(), set(), Spline(), and ~Spline().