CMS 3D CMS Logo

Public Member Functions | Static Private Member Functions | Private Attributes

fftjetcms::LinInterpolatedTable1D Class Reference

#include <LinInterpolatedTable1D.h>

List of all members.

Public Member Functions

const double * data () const
std::auto_ptr
< LinInterpolatedTable1D
inverse (unsigned npoints, bool leftExtrapolationLinear, bool rightExtrapolationLinear) const
bool isMonotonous () const
bool leftExtrapolationLinear () const
template<typename RealN >
 LinInterpolatedTable1D (const RealN *data, unsigned npoints, double x_min, double x_max, bool leftExtrapolationLinear, bool rightExtrapolationLinear)
template<typename RealN >
 LinInterpolatedTable1D (const std::vector< std::pair< RealN, RealN > > &v, unsigned npoints, bool leftExtrapolationLinear, bool rightExtrapolationLinear)
 LinInterpolatedTable1D (double c)
unsigned npoints () const
bool operator!= (const LinInterpolatedTable1D &r) const
virtual double operator() (const double &x) const
bool operator== (const LinInterpolatedTable1D &r) const
bool rightExtrapolationLinear () const
double xmax () const
double xmin () const
virtual ~LinInterpolatedTable1D ()

Static Private Member Functions

static double interpolateSimple (const double x0, const double x1, const double y0, const double y1, const double x)

Private Attributes

double binwidth_
std::vector< double > data_
bool leftExtrapolationLinear_
bool monotonicityKnown_
bool monotonous_
unsigned npoints_
bool rightExtrapolationLinear_
double xmax_
double xmin_

Detailed Description

Definition at line 24 of file LinInterpolatedTable1D.h.


Constructor & Destructor Documentation

template<typename RealN >
fftjetcms::LinInterpolatedTable1D::LinInterpolatedTable1D ( const RealN *  data,
unsigned  npoints,
double  x_min,
double  x_max,
bool  leftExtrapolationLinear,
bool  rightExtrapolationLinear 
) [inline]

Definition at line 114 of file LinInterpolatedTable1D.h.

References Exception.

Referenced by inverse().

        : data_(data, data+npoints),
          xmin_(x_min),
          xmax_(x_max),
          binwidth_((x_max - x_min)/(npoints - 1U)),
          npoints_(npoints),
          leftExtrapolationLinear_(leftExtrapolationLinear),
          rightExtrapolationLinear_(rightExtrapolationLinear),
          monotonous_(false),
          monotonicityKnown_(false)
    {
        if (!data)
            throw cms::Exception("FFTJetBadConfig")
                << "No data configured" << std::endl;
        if (npoints <= 1U)
            throw cms::Exception("FFTJetBadConfig")
                << "Not enough data points" << std::endl;
    }
template<typename RealN >
fftjetcms::LinInterpolatedTable1D::LinInterpolatedTable1D ( const std::vector< std::pair< RealN, RealN > > &  v,
unsigned  npoints,
bool  leftExtrapolationLinear,
bool  rightExtrapolationLinear 
)

Definition at line 138 of file LinInterpolatedTable1D.h.

References binwidth_, data_, Exception, first, i, interpolateSimple(), npoints_, edm::second(), edm::shift, v, x, xmax_, and xmin_.

        : xmin_(v[0].first),
          xmax_(v[v.size() - 1U].first),
          binwidth_((xmax_ - xmin_)/(npoints - 1U)),
          npoints_(npoints),
          leftExtrapolationLinear_(leftExtrapolationLinear),
          rightExtrapolationLinear_(rightExtrapolationLinear),
          monotonous_(false),
          monotonicityKnown_(false)
    {
        const unsigned len = v.size();
        if (len <= 1U)
            throw cms::Exception("FFTJetBadConfig")
                << "Not enough data for interpolation"
                << std::endl;

        if (npoints <= 1U)
            throw cms::Exception("FFTJetBadConfig")
                << "Not enough interpolation table entries"
                << std::endl;

        const std::pair<RealN,RealN>* vdata = &v[0];
        for (unsigned i=1; i<len; ++i)
            if (vdata[i-1U].first >= vdata[i].first)
                throw cms::Exception("FFTJetBadConfig")
                    << "Input data is not sorted properly"
                    << std::endl;

        unsigned shift = 0U;
        if (leftExtrapolationLinear)
        {
            ++npoints_;
            xmin_ -= binwidth_;
            shift = 1U;
        }
        if (rightExtrapolationLinear)
        {
            ++npoints_;
            xmax_ += binwidth_;
        }

        data_.resize(npoints_);

        if (leftExtrapolationLinear)
        {
            data_[0] = interpolateSimple(
                vdata[0].first, vdata[1].first,
                vdata[0].second, vdata[1].second, xmin_);
        }
        if (rightExtrapolationLinear)
        {
            data_[npoints_-1U] = interpolateSimple(
                vdata[len - 2U].first, vdata[len - 1U].first,
                vdata[len - 2U].second, vdata[len - 1U].second, xmax_);
        }

        data_[shift] = vdata[0].second;
        data_[npoints - 1U + shift] = vdata[len - 1U].second;
        unsigned ibelow = 0, iabove = 1;
        for (unsigned i=1; i<npoints-1; ++i)
        {
            const double x = xmin_ + (i + shift)*binwidth_;
            while (static_cast<double>(v[iabove].first) <= x)
            {
                ++ibelow;
                ++iabove;
            }
            if (v[ibelow].first == v[iabove].first)
                data_[i + shift] = (v[ibelow].second + v[iabove].second)/2.0;
            else
                data_[i + shift] = interpolateSimple(
                    v[ibelow].first, v[iabove].first,
                    v[ibelow].second, v[iabove].second, x);
        }
    }
fftjetcms::LinInterpolatedTable1D::LinInterpolatedTable1D ( double  c) [explicit]

Definition at line 4 of file LinInterpolatedTable1D.cc.

        : data_(2, c),
          xmin_(0.0),
          xmax_(1.0),
          binwidth_(1.0),
          npoints_(2U),
          leftExtrapolationLinear_(false),
          rightExtrapolationLinear_(false),
          monotonous_(false),
          monotonicityKnown_(true)
    {
    }
virtual fftjetcms::LinInterpolatedTable1D::~LinInterpolatedTable1D ( ) [inline, virtual]

Definition at line 50 of file LinInterpolatedTable1D.h.

{}

Member Function Documentation

const double* fftjetcms::LinInterpolatedTable1D::data ( ) const [inline]

Definition at line 68 of file LinInterpolatedTable1D.h.

References data_.

{return &data_[0];}
static double fftjetcms::LinInterpolatedTable1D::interpolateSimple ( const double  x0,
const double  x1,
const double  y0,
const double  y1,
const double  x 
) [inline, static, private]

Definition at line 90 of file LinInterpolatedTable1D.h.

Referenced by LinInterpolatedTable1D().

        {
            return y0 + (y1 - y0)*((x - x0)/(x1 - x0));
        }
std::auto_ptr< LinInterpolatedTable1D > fftjetcms::LinInterpolatedTable1D::inverse ( unsigned  npoints,
bool  leftExtrapolationLinear,
bool  rightExtrapolationLinear 
) const

Definition at line 46 of file LinInterpolatedTable1D.cc.

References binwidth_, data_, i, isMonotonous(), LinInterpolatedTable1D(), npoints_, NULL, xmax_, and xmin_.

    {
        if (!isMonotonous())
            return std::auto_ptr<LinInterpolatedTable1D>(NULL);

        std::vector<std::pair<double,double> > points;
        points.reserve(npoints_);

        if (data_[npoints_ - 1U] > data_[0])
        {
            points.push_back(std::pair<double,double>(data_[0], xmin_));
            for (unsigned i=1; i<npoints_ - 1U; ++i)
                points.push_back(std::pair<double,double>(data_[i], xmin_+i*binwidth_));
            points.push_back(std::pair<double,double>(data_[npoints_ - 1U], xmax_));
        }
        else
        {
            points.push_back(std::pair<double,double>(data_[npoints_ - 1U], xmax_));
            for (unsigned i=npoints_ - 2U; i>0; --i)
                points.push_back(std::pair<double,double>(data_[i], xmin_+i*binwidth_));
            points.push_back(std::pair<double,double>(data_[0], xmin_));
        }

        return std::auto_ptr<LinInterpolatedTable1D>(
            new LinInterpolatedTable1D(points, npoints,
                                       leftExtrapolationLinear,
                                       rightExtrapolationLinear));
    }
bool fftjetcms::LinInterpolatedTable1D::isMonotonous ( ) const

Definition at line 29 of file LinInterpolatedTable1D.cc.

References data_, delta, i, monotonicityKnown_, monotonous_, and npoints_.

Referenced by inverse().

    {
        if (!monotonicityKnown_)
        {
            monotonous_ = true;
            const double delta = data_[npoints_ - 1U] - data_[0];
            if (delta == 0.0)
                monotonous_ = false;
            const double sg = delta > 0.0 ? 1.0 : -1.0;
            for (unsigned i=1; i<npoints_ && monotonous_; ++i)
                if ((data_[i] - data_[i-1])*sg <= 0.0)
                    monotonous_ = false;
            monotonicityKnown_ = true;
        }
        return monotonous_;
    }
bool fftjetcms::LinInterpolatedTable1D::leftExtrapolationLinear ( ) const [inline]

Definition at line 64 of file LinInterpolatedTable1D.h.

References leftExtrapolationLinear_.

unsigned fftjetcms::LinInterpolatedTable1D::npoints ( ) const [inline]

Definition at line 63 of file LinInterpolatedTable1D.h.

References npoints_.

{return npoints_;}
bool fftjetcms::LinInterpolatedTable1D::operator!= ( const LinInterpolatedTable1D r) const [inline]

Definition at line 57 of file LinInterpolatedTable1D.h.

References alignCSCRings::r.

            {return !(*this == r);}
double fftjetcms::LinInterpolatedTable1D::operator() ( const double &  x) const [virtual]

Definition at line 77 of file LinInterpolatedTable1D.cc.

References binwidth_, data_, delta, leftExtrapolationLinear_, npoints_, rightExtrapolationLinear_, xmax_, and xmin_.

    {
        if (x <= xmin_)
        {
            if (leftExtrapolationLinear_)
                return data_[0] + (data_[1]-data_[0])*((x-xmin_)/binwidth_);
            else
                return data_[0];
        }
        else if (x >= xmax_)
        {
            if (rightExtrapolationLinear_)
                return data_[npoints_ - 1U] - (
                  data_[npoints_-2U]-data_[npoints_-1U])*((x-xmax_)/binwidth_);
            else
                return data_[npoints_ - 1U];
        }
        else
        {
            const unsigned ux = static_cast<unsigned>((x - xmin_)/binwidth_);
            if (ux >= npoints_ - 1U)
                return data_[npoints_ - 1U];
            const double delta = x - (ux*binwidth_ + xmin_);
            return data_[ux] + (data_[ux+1U]-data_[ux])*delta/binwidth_;
        }
    }
bool fftjetcms::LinInterpolatedTable1D::operator== ( const LinInterpolatedTable1D r) const

Definition at line 17 of file LinInterpolatedTable1D.cc.

References binwidth_, data_, leftExtrapolationLinear_, npoints_, rightExtrapolationLinear_, xmax_, and xmin_.

    {
        return xmin_ == r.xmin_ &&
               xmax_ == r.xmax_ &&
               binwidth_ == r.binwidth_ &&
               npoints_ == r.npoints_ &&
               leftExtrapolationLinear_ == r.leftExtrapolationLinear_ &&
               rightExtrapolationLinear_ == r.rightExtrapolationLinear_ &&
               data_ == r.data_;
    }
bool fftjetcms::LinInterpolatedTable1D::rightExtrapolationLinear ( ) const [inline]

Definition at line 66 of file LinInterpolatedTable1D.h.

References rightExtrapolationLinear_.

double fftjetcms::LinInterpolatedTable1D::xmax ( ) const [inline]

Definition at line 62 of file LinInterpolatedTable1D.h.

References xmax_.

{return xmax_;}
double fftjetcms::LinInterpolatedTable1D::xmin ( ) const [inline]

Definition at line 61 of file LinInterpolatedTable1D.h.

References xmin_.

{return xmin_;}

Member Data Documentation

Definition at line 101 of file LinInterpolatedTable1D.h.

Referenced by inverse(), LinInterpolatedTable1D(), operator()(), and operator==().

std::vector<double> fftjetcms::LinInterpolatedTable1D::data_ [private]

Definition at line 103 of file LinInterpolatedTable1D.h.

Referenced by leftExtrapolationLinear(), operator()(), and operator==().

Definition at line 106 of file LinInterpolatedTable1D.h.

Referenced by isMonotonous().

Definition at line 105 of file LinInterpolatedTable1D.h.

Referenced by isMonotonous().

Definition at line 104 of file LinInterpolatedTable1D.h.

Referenced by operator()(), operator==(), and rightExtrapolationLinear().