CMS 3D CMS Logo

Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Friends

npstat::LinInterpolatedTableND< Numeric, Axis > Class Template Reference

#include <LinInterpolatedTableND.h>

List of all members.

Public Types

typedef Axis axis_type
typedef Numeric value_type

Public Member Functions

void getCoords (unsigned long linearIndex, double *coords, unsigned coordsBufferSize) const
template<class Functor1 , class Functor2 >
CPP11_auto_ptr
< LinInterpolatedTableND
invertRatioResponse (unsigned axisNumber, const Axis &replacementAxis, bool newAxisLeftLinear, bool newAxisRightLinear, Functor1 invg, Functor2 invh, const char *functionLabel=0) const
template<typename ConvertibleToUnsigned >
CPP11_auto_ptr
< LinInterpolatedTableND
invertWRTAxis (ConvertibleToUnsigned axisNumber, const Axis &replacementAxis, bool newAxisLeftLinear, bool newAxisRightLinear, const char *functionLabel=0) const
bool isUniformlyBinned () const
bool isWithinLimits (const double *point, unsigned dim) const
 LinInterpolatedTableND (const Axis &xAxis, bool leftX, bool rightX, const char *functionLabel=0)
 LinInterpolatedTableND (const std::vector< Axis > &axes, const std::vector< std::pair< bool, bool > > &extrapolationType, const char *functionLabel=0)
 LinInterpolatedTableND (const Axis &xAxis, bool leftX, bool rightX, const Axis &yAxis, bool leftY, bool rightY, const Axis &zAxis, bool leftZ, bool rightZ, const char *functionLabel=0)
 LinInterpolatedTableND (const Axis &xAxis, bool leftX, bool rightX, const Axis &yAxis, bool leftY, bool rightY, const Axis &zAxis, bool leftZ, bool rightZ, const Axis &tAxis, bool leftT, bool rightT, const char *functionLabel=0)
 LinInterpolatedTableND (const Axis &xAxis, bool leftX, bool rightX, const Axis &yAxis, bool leftY, bool rightY, const char *functionLabel=0)
template<class Num2 >
 LinInterpolatedTableND (const LinInterpolatedTableND< Num2, Axis > &)
 LinInterpolatedTableND (const Axis &xAxis, bool leftX, bool rightX, const Axis &yAxis, bool leftY, bool rightY, const Axis &zAxis, bool leftZ, bool rightZ, const Axis &tAxis, bool leftT, bool rightT, const Axis &vAxis, bool leftV, bool rightV, const char *functionLabel=0)
bool operator!= (const LinInterpolatedTableND &r) const
Numeric operator() (const double *point, unsigned dim) const
bool operator== (const LinInterpolatedTableND &) const
void setFunctionLabel (const char *newlabel)
Numeric operator() (const double &x0) const
Numeric operator() (const double &x0, const double &x1) const
Numeric operator() (const double &x0, const double &x1, const double &x2) const
Numeric operator() (const double &x0, const double &x1, const double &x2, const double &x3) const
Numeric operator() (const double &x0, const double &x1, const double &x2, const double &x3, const double &x4) const
unsigned dim () const
const std::vector< Axis > & axes () const
const Axis & axis (const unsigned i) const
unsigned long length () const
bool leftInterpolationLinear (unsigned i) const
bool rightInterpolationLinear (unsigned i) const
std::vector< std::pair< bool,
bool > > 
interpolationType () const
const std::string & functionLabel () const
const ArrayND< Numeric > & table () const
ArrayND< Numeric > & table ()
gs::ClassId classId () const
bool write (std::ostream &of) const

Static Public Member Functions

static const char * classname ()
static LinInterpolatedTableNDread (const gs::ClassId &id, std::istream &in)
static unsigned version ()

Private Member Functions

bool allConstInterpolated () const
 LinInterpolatedTableND ()
 LinInterpolatedTableND (const ArrayND< Numeric > &data, const std::vector< Axis > &axes, const char *leftInterpolation, const char *rightInterpolation, const std::string &label)

Static Private Member Functions

template<class Functor1 >
static void invert1DResponse (const ArrayND< Numeric > &fromSlice, const Axis &fromAxis, const Axis &toAxis, bool newLeftLinear, bool newRightLinear, Functor1 invg, const double *rawx, const double *rawf, double *workspace, ArrayND< Numeric > *toSlice)
template<class Functor1 >
static double solveForRatioArg (double xmin, double xmax, double rmin, double rmax, double fval, Functor1 invg)

Private Attributes

bool allConstInterpolated_
std::vector< Axis > axes_
ArrayND< Numeric > data_
unsigned dim_
std::string functionLabel_
char leftInterpolationLinear_ [CHAR_BIT *sizeof(unsigned long)]
char rightInterpolationLinear_ [CHAR_BIT *sizeof(unsigned long)]

Friends

class LinInterpolatedTableND

Detailed Description

template<class Numeric, class Axis = UniformAxis>
class npstat::LinInterpolatedTableND< Numeric, Axis >

Template for multilinear interpolation/extrapolation of values provided on a rectangular coordinate grid. "Numeric" is the type stored in the table. "Axis" should be one of GridAxis, UniformAxis, or DualAxis classes or a user-provided class with a similar set of methods.

Definition at line 31 of file LinInterpolatedTableND.h.


Member Typedef Documentation

template<class Numeric, class Axis = UniformAxis>
typedef Axis npstat::LinInterpolatedTableND< Numeric, Axis >::axis_type

Definition at line 38 of file LinInterpolatedTableND.h.

template<class Numeric, class Axis = UniformAxis>
typedef Numeric npstat::LinInterpolatedTableND< Numeric, Axis >::value_type

Definition at line 37 of file LinInterpolatedTableND.h.


Constructor & Destructor Documentation

template<typename Numeric , class Axis >
npstat::LinInterpolatedTableND< Numeric, Axis >::LinInterpolatedTableND ( const std::vector< Axis > &  axes,
const std::vector< std::pair< bool, bool > > &  extrapolationType,
const char *  functionLabel = 0 
)

Main constructor for arbitrary-dimensional interpolators.

"axes" are the axes of the rectangular coordinate grid.

In each pair provided by the "extrapolationType" argument, the first element of the pair specifies whether the extrapolation to negative infinity should be linear (if "true") or constant (if "false"). The second element of the pair specifies whether to extrapolate linearly to positive infinity.

"functionLabel" is an arbitrary string which can potentially be used by plotting programs and such.

Definition at line 566 of file LinInterpolatedTableND.h.

References npstat::LinInterpolatedTableND< Numeric, Axis >::allConstInterpolated(), npstat::LinInterpolatedTableND< Numeric, Axis >::allConstInterpolated_, npstat::LinInterpolatedTableND< Numeric, Axis >::dim_, i, npstat::LinInterpolatedTableND< Numeric, Axis >::interpolationType(), npstat::LinInterpolatedTableND< Numeric, Axis >::leftInterpolationLinear_, and npstat::LinInterpolatedTableND< Numeric, Axis >::rightInterpolationLinear_.

        : data_(Private::makeTableShape(axes)),
          axes_(axes),
          functionLabel_(label ? label : ""),
          dim_(axes.size())
    {
        if (dim_ == 0 || dim_ >= CHAR_BIT*sizeof(unsigned long))
            throw npstat::NpstatInvalidArgument(
                "In npstat::LinInterpolatedTableND constructor: requested "
                "table dimensionality is not supported");
        if (dim_ != interpolationType.size())
            throw npstat::NpstatInvalidArgument(
                "In npstat::LinInterpolatedTableND constructor: "
                "incompatible number of interpolation specifications");
        for (unsigned i=0; i<dim_; ++i)
        {
            const std::pair<bool,bool>& pair(interpolationType[i]);
            leftInterpolationLinear_[i] = pair.first;
            rightInterpolationLinear_[i] = pair.second;
        }

        allConstInterpolated_ = allConstInterpolated();
    }
template<typename Numeric , class Axis >
npstat::LinInterpolatedTableND< Numeric, Axis >::LinInterpolatedTableND ( const Axis &  xAxis,
bool  leftX,
bool  rightX,
const char *  functionLabel = 0 
)
template<typename Numeric , class Axis >
npstat::LinInterpolatedTableND< Numeric, Axis >::LinInterpolatedTableND ( const Axis &  xAxis,
bool  leftX,
bool  rightX,
const Axis &  yAxis,
bool  leftY,
bool  rightY,
const char *  functionLabel = 0 
)
template<typename Numeric , class Axis >
npstat::LinInterpolatedTableND< Numeric, Axis >::LinInterpolatedTableND ( const Axis &  xAxis,
bool  leftX,
bool  rightX,
const Axis &  yAxis,
bool  leftY,
bool  rightY,
const Axis &  zAxis,
bool  leftZ,
bool  rightZ,
const char *  functionLabel = 0 
)
template<typename Numeric , class Axis >
npstat::LinInterpolatedTableND< Numeric, Axis >::LinInterpolatedTableND ( const Axis &  xAxis,
bool  leftX,
bool  rightX,
const Axis &  yAxis,
bool  leftY,
bool  rightY,
const Axis &  zAxis,
bool  leftZ,
bool  rightZ,
const Axis &  tAxis,
bool  leftT,
bool  rightT,
const char *  functionLabel = 0 
)
template<typename Numeric , class Axis >
npstat::LinInterpolatedTableND< Numeric, Axis >::LinInterpolatedTableND ( const Axis &  xAxis,
bool  leftX,
bool  rightX,
const Axis &  yAxis,
bool  leftY,
bool  rightY,
const Axis &  zAxis,
bool  leftZ,
bool  rightZ,
const Axis &  tAxis,
bool  leftT,
bool  rightT,
const Axis &  vAxis,
bool  leftV,
bool  rightV,
const char *  functionLabel = 0 
)
template<typename Numeric , class Axis >
template<class Num2 >
npstat::LinInterpolatedTableND< Numeric, Axis >::LinInterpolatedTableND ( const LinInterpolatedTableND< Num2, Axis > &  r)

Converting copy constructor from interpolator with another storage type

Definition at line 595 of file LinInterpolatedTableND.h.

References npstat::LinInterpolatedTableND< Numeric, Axis >::dim_, i, npstat::LinInterpolatedTableND< Numeric, Axis >::leftInterpolationLinear_, and npstat::LinInterpolatedTableND< Numeric, Axis >::rightInterpolationLinear_.

        : data_(r.data_),
          axes_(r.axes_),
          functionLabel_(r.functionLabel_),
          dim_(r.dim_),
          allConstInterpolated_(r.allConstInterpolated_)
    {
        for (unsigned i=0; i<dim_; ++i)
        {
            leftInterpolationLinear_[i] = r.leftInterpolationLinear_[i];
            rightInterpolationLinear_[i] = r.rightInterpolationLinear_[i];
        }
    }
template<class Numeric, class Axis = UniformAxis>
npstat::LinInterpolatedTableND< Numeric, Axis >::LinInterpolatedTableND ( ) [private]
template<typename Numeric , class Axis >
npstat::LinInterpolatedTableND< Numeric, Axis >::LinInterpolatedTableND ( const ArrayND< Numeric > &  data,
const std::vector< Axis > &  axes,
const char *  leftInterpolation,
const char *  rightInterpolation,
const std::string &  label 
) [private]

Member Function Documentation

template<class Numeric , class Axis >
bool npstat::LinInterpolatedTableND< Numeric, Axis >::allConstInterpolated ( ) const [private]

Definition at line 444 of file LinInterpolatedTableND.h.

References i.

Referenced by npstat::LinInterpolatedTableND< Numeric, Axis >::LinInterpolatedTableND().

    {
        for (unsigned i=0; i<dim_; ++i)
            if (leftInterpolationLinear_[i] || rightInterpolationLinear_[i])
                return false;
        return true;
    }
template<class Numeric, class Axis = UniformAxis>
const std::vector<Axis>& npstat::LinInterpolatedTableND< Numeric, Axis >::axes ( ) const [inline]
template<class Numeric, class Axis = UniformAxis>
const Axis& npstat::LinInterpolatedTableND< Numeric, Axis >::axis ( const unsigned  i) const [inline]

Definition at line 119 of file LinInterpolatedTableND.h.

References npstat::LinInterpolatedTableND< Numeric, Axis >::axes_.

            {return axes_.at(i);}
template<class Numeric, class Axis = UniformAxis>
gs::ClassId npstat::LinInterpolatedTableND< Numeric, Axis >::classId ( ) const [inline]

Definition at line 205 of file LinInterpolatedTableND.h.

Referenced by npstat::StorableInterpolationFunctor< Numeric, Axis, Converter >::write().

{return gs::ClassId(*this);}
template<typename Numeric , class Axis >
const char * npstat::LinInterpolatedTableND< Numeric, Axis >::classname ( ) [static]

Definition at line 471 of file LinInterpolatedTableND.h.

References AlCaHLTBitMon_QueryRunRegistry::string.

    {
        static const std::string myClass(gs::template_class_name<Numeric,Axis>(
                                           "npstat::LinInterpolatedTableND"));
        return myClass.c_str();
    }
template<class Numeric, class Axis = UniformAxis>
unsigned npstat::LinInterpolatedTableND< Numeric, Axis >::dim ( ) const [inline]
template<class Numeric, class Axis = UniformAxis>
const std::string& npstat::LinInterpolatedTableND< Numeric, Axis >::functionLabel ( ) const [inline]
template<typename Numeric , class Axis >
void npstat::LinInterpolatedTableND< Numeric, Axis >::getCoords ( unsigned long  linearIndex,
double *  coords,
unsigned  coordsBufferSize 
) const

Convenience function for getting coordinates of the grid points

Definition at line 920 of file LinInterpolatedTableND.h.

References i, and getHLTprescales::index.

    {
        if (coordsBufferSize < dim_) throw npstat::NpstatInvalidArgument(
            "In LinInterpolatedTableND::getCoords: "
            "insufficient buffer size");
        assert(coords);
        unsigned index[CHAR_BIT*sizeof(unsigned long)];
        data_.convertLinearIndex(linearIndex, index, dim_);
        for (unsigned i=0; i<dim_; ++i)
            coords[i] = axes_[i].coordinate(index[i]);
    }
template<typename Numeric , class Axis >
std::vector< std::pair< bool, bool > > npstat::LinInterpolatedTableND< Numeric, Axis >::interpolationType ( ) const

Definition at line 555 of file LinInterpolatedTableND.h.

References i.

Referenced by npstat::LinInterpolatedTableND< Numeric, Axis >::LinInterpolatedTableND().

    {
        std::vector<std::pair<bool,bool> > vec;
        vec.reserve(dim_);
        for (unsigned i=0; i<dim_; ++i)
            vec.push_back(std::pair<bool, bool>(leftInterpolationLinear_[i],
                                                rightInterpolationLinear_[i]));
        return vec;
    }
template<typename Numeric , class Axis >
template<class Functor1 >
void npstat::LinInterpolatedTableND< Numeric, Axis >::invert1DResponse ( const ArrayND< Numeric > &  fromSlice,
const Axis &  fromAxis,
const Axis &  toAxis,
bool  newLeftLinear,
bool  newRightLinear,
Functor1  invg,
const double *  rawx,
const double *  rawf,
double *  workspace,
ArrayND< Numeric > *  toSlice 
) [static, private]

Definition at line 1168 of file LinInterpolatedTableND.h.

References npstat::ArrayND< Numeric, StackLen, StackDim >::data(), i, npstat::ArrayND< Numeric, StackLen, StackDim >::length(), npstat::ArrayND< Numeric, StackLen, StackDim >::rank(), x, detailsBasic3DVector::y, and zero.

    {
        assert(toSlice);
        assert(fromSlice.rank() == 1U);
        assert(toSlice->rank() == 1U);

        const Numeric zero = Numeric();
        const Numeric* fromData = fromSlice.data();
        const unsigned fromLen = fromSlice.length();
        assert(fromLen > 1U);
        assert(fromLen == fromAxis.nCoords());
        Numeric* toD = const_cast<Numeric*>(toSlice->data());
        const unsigned nAxisPoints = toAxis.nCoords();
        assert(toSlice->length() == nAxisPoints);

        for (unsigned i=0; i<fromLen; ++i)
        {
            if (fromData[i] <= zero) throw npstat::NpstatDomainError(
                "In LinInterpolatedTableND::invert1DResponse: "
                "non-positive response found. This ratio "
                "response table is not invertible.");
            workspace[i] = rawx[i]*fromData[i];
        }

        const double yfirst = workspace[0];
        const double ylast = workspace[fromLen - 1U];

        bool adjustZero = false;
        unsigned nBelow = 0;
        for (unsigned ipt=0; ipt<nAxisPoints; ++ipt)
        {
            const double y = rawf[ipt];
            unsigned i0 = 0;
            bool solve = false;
            if (y == 0.0)
            {
                assert(ipt == 0U);
                if (newLeftLinear)
                    adjustZero = true;
            }
            else if (y <= yfirst)
            {
                ++nBelow;
                solve = newLeftLinear;
            }
            else if (y >= ylast)
            {
                solve = newRightLinear;
                i0 = solve ? fromLen-2 : fromLen-1;
            }
            else
            {
                solve = true;
                i0 = static_cast<unsigned>(std::lower_bound(
                         workspace,workspace+fromLen,y) - workspace) - 1U;
            }
            if (solve)
            {
                const double x = solveForRatioArg(fromAxis.coordinate(i0),
                                                  fromAxis.coordinate(i0+1),
                                                  fromData[i0], fromData[i0+1],
                                                  y, invg);
                toD[ipt] = invg(x)/y;
            }
            else
                toD[ipt] = 1.0/fromData[i0];
        }
        if (adjustZero && nBelow)
            toD[0] = toD[1];
    }
template<typename Numeric , class Axis >
template<class Functor1 , class Functor2 >
CPP11_auto_ptr< LinInterpolatedTableND< Numeric, Axis > > npstat::LinInterpolatedTableND< Numeric, Axis >::invertRatioResponse ( unsigned  axisNumber,
const Axis &  replacementAxis,
bool  newAxisLeftLinear,
bool  newAxisRightLinear,
Functor1  invg,
Functor2  invh,
const char *  functionLabel = 0 
) const

This method inverts the ratio response. That is, we assume that the table encodes r(x) for some function f(x) = x*r(x). We also assume that the original axis does not represent x directly -- instead, axis coordinates are given by g(x) (in practice, g is often the natural log). We will also assume that the new axis is not going to represent f(x) directly -- it will be h(f(x)) instead. The functors "invg" and "invh" below must do the inverse: taking the axes coordinates to the actual values of x and f(x). Both "invg" and "invh" must be monotonously increasing functions. The code assumes that x*r(x) -> 0 when x->0 (that is, r(x) is bounded at 0) and it also assumes (but does not check explicitly) that x*r(x) is monotonously increasing with x.

The returned interpolation table encodes the values of x/f(x). Of course, they are just 1/r(x), but the trick is to be able to look them up quickly as a function of h(f(x)). Naturally, this whole operation is meaningful only in case "Numeric" type is either float or double.

Definition at line 827 of file LinInterpolatedTableND.h.

References prof2calltree::count, f, i, npstat::ArrayNDScanner::isValid(), and x.

    {
        if (axisNumber >= dim_)
            throw npstat::NpstatOutOfRange(
                "In npstat::LinInterpolatedTableND::invertRatioResponse: "
                "axis number is out of range");

        // Generate the new set of axes
        std::vector<Axis> newAxes(axes_);
        newAxes[axisNumber] = replacementAxis;

        std::vector<std::pair<bool,bool> > iType(interpolationType());
        iType[axisNumber] = std::pair<bool,bool>(leftLinear, rightLinear);

        // Transform the original axis to the raw x values
        const Axis& oldAxis(axes_[axisNumber]);
        std::vector<double> rawx;
        const unsigned nCoords = oldAxis.nCoords();
        rawx.reserve(nCoords);
        for (unsigned i=0; i<nCoords; ++i)
        {
            const double x = invg(oldAxis.coordinate(i));
            if (x < 0.0)
                throw npstat::NpstatInvalidArgument(
                    "In npstat::LinInterpolatedTableND::invertRatioResponse: "
                    "invalid original axis definition (negative transformed "
                    "coordinate)");
            rawx.push_back(x);
        }

        // Transform the new axis to the raw f(x) values
        std::vector<double> rawf;
        const unsigned nFuncs = replacementAxis.nCoords();
        rawf.reserve(nFuncs);
        for (unsigned i=0; i<nFuncs; ++i)
        {
            const double f = invh(replacementAxis.coordinate(i));
            if (f < 0.0)
                throw npstat::NpstatInvalidArgument(
                    "In npstat::LinInterpolatedTableND::invertRatioResponse: "
                    "invalid new axis definition (negative transformed "
                    "coordinate)");
            rawf.push_back(f);
        }

        // Workspace needed for the inversion code
        std::vector<double> workspace(nCoords);

        // Create the new table
        CPP11_auto_ptr<LinInterpolatedTableND> pTable(
            new LinInterpolatedTableND(newAxes, iType, functionLabel));

        if (dim_ > 1U)
        {
            // Prepare array slices
            unsigned sliceIndex[CHAR_BIT*sizeof(unsigned long)];
            unsigned fixedIndices[CHAR_BIT*sizeof(unsigned long)];
            unsigned count = 0;
            for (unsigned i=0; i<dim_; ++i)
                if (i != axisNumber)
                {
                    sliceIndex[count] = data_.span(i);
                    fixedIndices[count++] = i;
                }
            ArrayND<Numeric> parentSlice(data_, fixedIndices, count);
            ArrayND<Numeric> dauSlice(pTable->data_, fixedIndices, count);

            // Cycle over the slices
            for (ArrayNDScanner scan(sliceIndex,count); scan.isValid(); ++scan)
            {
                scan.getIndex(sliceIndex, count);
                data_.exportSlice(&parentSlice, fixedIndices,
                                  sliceIndex, count);
                invert1DResponse(parentSlice, oldAxis,
                                 replacementAxis, leftLinear, rightLinear,
                                 invg, &rawx[0], &rawf[0], &workspace[0],
                                 &dauSlice);
                pTable->data_.importSlice(dauSlice, fixedIndices,
                                          sliceIndex, count);
            }
        }
        else
            invert1DResponse(data_, oldAxis, replacementAxis, leftLinear,
                             rightLinear, invg, &rawx[0], &rawf[0],
                             &workspace[0], &pTable->data_);
        return pTable;
    }
template<typename Numeric , class Axis >
template<typename ConvertibleToUnsigned >
CPP11_auto_ptr< LinInterpolatedTableND< Numeric, Axis > > npstat::LinInterpolatedTableND< Numeric, Axis >::invertWRTAxis ( ConvertibleToUnsigned  axisNumber,
const Axis &  replacementAxis,
bool  newAxisLeftLinear,
bool  newAxisRightLinear,
const char *  functionLabel = 0 
) const

Invert the function w.r.t. the variable represented by one of the axes. The function values must change monotonously along the chosen axis. Note that this operation is meaningful only in case "Numeric" type is either float or double.

Definition at line 766 of file LinInterpolatedTableND.h.

References prof2calltree::count, i, npstat::ArrayNDScanner::isValid(), and npstat::Private::lind_invert1DSlice().

    {
        const unsigned axisNumber = static_cast<unsigned>(axisNumC);

        if (axisNumber >= dim_)
            throw npstat::NpstatOutOfRange(
                "In npstat::LinInterpolatedTableND::invertAxis: "
                "axis number is out of range");

        // Generate the new set of axes
        std::vector<Axis> newAxes(axes_);
        newAxes[axisNumber] = replacementAxis;

        std::vector<std::pair<bool,bool> > iType(interpolationType());
        iType[axisNumber] = std::pair<bool,bool>(leftLinear, rightLinear);

        // Create the new table
        CPP11_auto_ptr<LinInterpolatedTableND> pTable(
            new LinInterpolatedTableND(newAxes, iType, functionLabel));

        if (dim_ > 1U)
        {
            // Prepare array slices
            unsigned sliceIndex[CHAR_BIT*sizeof(unsigned long)];
            unsigned fixedIndices[CHAR_BIT*sizeof(unsigned long)];
            unsigned count = 0;
            for (unsigned i=0; i<dim_; ++i)
                if (i != axisNumber)
                {
                    sliceIndex[count] = data_.span(i);
                    fixedIndices[count++] = i;
                }
            ArrayND<Numeric> parentSlice(data_, fixedIndices, count);
            ArrayND<Numeric> dauSlice(pTable->data_, fixedIndices, count);

            // Cycle over the slices
            for (ArrayNDScanner scan(sliceIndex,count); scan.isValid(); ++scan)
            {
                scan.getIndex(sliceIndex, count);
                data_.exportSlice(&parentSlice, fixedIndices,
                                  sliceIndex, count);
                Private::lind_invert1DSlice(
                    parentSlice, axes_[axisNumber], replacementAxis,
                    leftLinear, rightLinear, &dauSlice);
                pTable->data_.importSlice(dauSlice, fixedIndices,
                                          sliceIndex, count);
            }
        }
        else
            Private::lind_invert1DSlice(
                data_, axes_[0], replacementAxis,
                leftLinear, rightLinear, &pTable->data_);
        return pTable;
    }
template<typename Numeric , class Axis >
bool npstat::LinInterpolatedTableND< Numeric, Axis >::isUniformlyBinned ( ) const

This method returns "true" if the method isUniform() of each interpolator axis returns "true"

Definition at line 545 of file LinInterpolatedTableND.h.

References i.

    {
        for (unsigned i=0; i<dim_; ++i)
            if (!axes_[i].isUniform())
                return false;
        return true;
    }
template<typename Numeric , class Axis >
bool npstat::LinInterpolatedTableND< Numeric, Axis >::isWithinLimits ( const double *  point,
unsigned  dim 
) const

This method will return "true" if the point is inside the grid limits or on the boundary

Definition at line 935 of file LinInterpolatedTableND.h.

References i, max(), and min.

    {
        if (len != dim_)
            throw npstat::NpstatInvalidArgument(
                "In npstat::LinInterpolatedTableND::isWithinLimits: "
                "incompatible point dimensionality");
        assert(point);

        for (unsigned i=0; i<dim_; ++i)
            if (point[i] < axes_[i].min() || point[i] > axes_[i].max())
                return false;
        return true;
    }
template<typename Numeric , class Axis >
bool npstat::LinInterpolatedTableND< Numeric, Axis >::leftInterpolationLinear ( unsigned  i) const

Definition at line 525 of file LinInterpolatedTableND.h.

References i.

    {
        if (i >= dim_) throw npstat::NpstatOutOfRange(
            "In npstat::LinInterpolatedTableND::leftInterpolationLinear: "
            "index out of range");
        return leftInterpolationLinear_[i];
    }
template<class Numeric, class Axis = UniformAxis>
unsigned long npstat::LinInterpolatedTableND< Numeric, Axis >::length ( ) const [inline]
template<class Numeric, class Axis = UniformAxis>
bool npstat::LinInterpolatedTableND< Numeric, Axis >::operator!= ( const LinInterpolatedTableND< Numeric, Axis > &  r) const [inline]

Logical negation of operator==

Definition at line 200 of file LinInterpolatedTableND.h.

References alignCSCRings::r.

            {return !(*this == r);}
template<typename Numeric , class Axis >
Numeric npstat::LinInterpolatedTableND< Numeric, Axis >::operator() ( const double &  x0,
const double &  x1,
const double &  x2 
) const

Definition at line 1057 of file LinInterpolatedTableND.h.

References tmp.

    {
        const unsigned nArgs = 3U;
        if (dim_ != nArgs) throw npstat::NpstatInvalidArgument(
            "In npstat::LinInterpolatedTableND::operator(): number of "
            "arguments, 3, is incompatible with the interpolator dimensionality");
        double tmp[nArgs];
        tmp[0] = x0;
        tmp[1] = x1;
        tmp[2] = x2;
        return operator()(tmp, nArgs);
    }
template<typename Numeric , class Axis >
Numeric npstat::LinInterpolatedTableND< Numeric, Axis >::operator() ( const double &  x0) const

Convenience function for low-dimensional interpolators

Definition at line 1030 of file LinInterpolatedTableND.h.

References tmp.

    {
        const unsigned nArgs = 1U;
        if (dim_ != nArgs) throw npstat::NpstatInvalidArgument(
            "In npstat::LinInterpolatedTableND::operator(): number of "
            "arguments, 1, is incompatible with the interpolator dimensionality");
        double tmp[nArgs];
        tmp[0] = x0;
        return operator()(tmp, nArgs);
    }
template<typename Numeric , class Axis >
Numeric npstat::LinInterpolatedTableND< Numeric, Axis >::operator() ( const double &  x0,
const double &  x1,
const double &  x2,
const double &  x3 
) const

Definition at line 1072 of file LinInterpolatedTableND.h.

References tmp.

    {
        const unsigned nArgs = 4U;
        if (dim_ != nArgs) throw npstat::NpstatInvalidArgument(
            "In npstat::LinInterpolatedTableND::operator(): number of "
            "arguments, 4, is incompatible with the interpolator dimensionality");
        double tmp[nArgs];
        tmp[0] = x0;
        tmp[1] = x1;
        tmp[2] = x2;
        tmp[3] = x3;
        return operator()(tmp, nArgs);
    }
template<typename Numeric , class Axis >
Numeric npstat::LinInterpolatedTableND< Numeric, Axis >::operator() ( const double *  point,
unsigned  dim 
) const

Basic interpolation result. Argument point dimensionality must be compatible with the interpolator dimensionality.

Definition at line 951 of file LinInterpolatedTableND.h.

References i, max(), min, w(), and histoStyle::weight.

    {
        typedef typename ProperDblFromCmpl<Numeric>::type proper_double;

        if (len != dim_)
            throw npstat::NpstatInvalidArgument(
                "In npstat::LinInterpolatedTableND::operator(): "
                "incompatible point dimensionality");
        assert(point);

        bool interpolateArray = true;
        if (!allConstInterpolated_)
            for (unsigned i=0; i<dim_; ++i)
                if ((leftInterpolationLinear_[i] && point[i] < axes_[i].min()) ||
                    (rightInterpolationLinear_[i] && point[i] > axes_[i].max()))
                {
                    interpolateArray = false;
                    break;
                }

        if (interpolateArray)
        {
            // Translate coordinates into the array system and
            // simply use the ArrayND interpolation facilities
            double buf[CHAR_BIT*sizeof(unsigned long)];
            for (unsigned i=0; i<dim_; ++i)
            {
                const std::pair<unsigned,double>& pair = 
                    axes_[i].getInterval(point[i]);
                buf[i] = pair.first + 1U - pair.second;
            }
            return data_.interpolate1(buf, dim_);
        }
        else
        {
            unsigned ix[CHAR_BIT*sizeof(unsigned long)];
            double weight[CHAR_BIT*sizeof(unsigned long)];
            for (unsigned i=0; i<dim_; ++i)
            {
                const bool linear = (leftInterpolationLinear_[i] && 
                                     point[i] < axes_[i].min()) ||
                                    (rightInterpolationLinear_[i] && 
                                     point[i] > axes_[i].max());
                const std::pair<unsigned,double>& pair = linear ?
                    axes_[i].linearInterval(point[i]) :
                    axes_[i].getInterval(point[i]);
                ix[i] = pair.first;
                weight[i] = pair.second;
            }

            Numeric sum = Numeric();
            const unsigned long maxcycle = 1UL << dim_;
            const unsigned long* strides = data_.strides();
            const Numeric* dat = data_.data();
            for (unsigned long icycle=0UL; icycle<maxcycle; ++icycle)
            {
                double w = 1.0;
                unsigned long icell = 0UL;
                for (unsigned i=0; i<dim_; ++i)
                {
                    if (icycle & (1UL << i))
                    {
                        w *= (1.0 - weight[i]);
                        icell += strides[i]*(ix[i] + 1U);
                    }
                    else
                    {
                        w *= weight[i];
                        icell += strides[i]*ix[i];
                    }
                }
                sum += dat[icell]*static_cast<proper_double>(w);
            }
            return sum;
        }
    }
template<typename Numeric , class Axis >
Numeric npstat::LinInterpolatedTableND< Numeric, Axis >::operator() ( const double &  x0,
const double &  x1,
const double &  x2,
const double &  x3,
const double &  x4 
) const

Definition at line 1089 of file LinInterpolatedTableND.h.

References tmp.

    {
        const unsigned nArgs = 5U;
        if (dim_ != nArgs) throw npstat::NpstatInvalidArgument(
            "In npstat::LinInterpolatedTableND::operator(): number of "
            "arguments, 5, is incompatible with the interpolator dimensionality");
        double tmp[nArgs];
        tmp[0] = x0;
        tmp[1] = x1;
        tmp[2] = x2;
        tmp[3] = x3;
        tmp[4] = x4;
        return operator()(tmp, nArgs);
    }
template<typename Numeric , class Axis >
Numeric npstat::LinInterpolatedTableND< Numeric, Axis >::operator() ( const double &  x0,
const double &  x1 
) const

Definition at line 1043 of file LinInterpolatedTableND.h.

References tmp.

    {
        const unsigned nArgs = 2U;
        if (dim_ != nArgs) throw npstat::NpstatInvalidArgument(
            "In npstat::LinInterpolatedTableND::operator(): number of "
            "arguments, 2, is incompatible with the interpolator dimensionality");
        double tmp[nArgs];
        tmp[0] = x0;
        tmp[1] = x1;
        return operator()(tmp, nArgs);
    }
template<class Numeric , class Axis >
bool npstat::LinInterpolatedTableND< Numeric, Axis >::operator== ( const LinInterpolatedTableND< Numeric, Axis > &  r) const
template<typename Numeric , class Axis >
LinInterpolatedTableND< Numeric, Axis > * npstat::LinInterpolatedTableND< Numeric, Axis >::read ( const gs::ClassId &  id,
std::istream &  in 
) [static]

Definition at line 495 of file LinInterpolatedTableND.h.

References cond::rpcobimon::current, data, diffTwoXMLs::label, npstat::ArrayND< Numeric, StackLen, StackDim >::rank(), npstat::ArrayND< Numeric, StackLen, StackDim >::restore(), and AlCaHLTBitMon_QueryRunRegistry::string.

    {
        static const gs::ClassId current(
            gs::ClassId::makeId<LinInterpolatedTableND<Numeric,Axis> >());
        current.ensureSameId(id);

        gs::ClassId ida(in, 1);
        ArrayND<Numeric> data;
        ArrayND<Numeric>::restore(ida, in, &data);
        std::vector<Axis> axes;
        gs::read_heap_obj_vector_as_placed(in, &axes);
        const unsigned dim = axes.size();
        if (dim > CHAR_BIT*sizeof(unsigned long) || data.rank() != dim)
            throw gs::IOInvalidData(
                "In npstat::LinInterpolatedTableND::read: "
                "read back invalid dimensionality");
        char leftInterpolation[CHAR_BIT*sizeof(unsigned long)];
        gs::read_pod_array(in, leftInterpolation, dim);
        char rightInterpolation[CHAR_BIT*sizeof(unsigned long)];
        gs::read_pod_array(in, rightInterpolation, dim);
        std::string label;
        gs::read_pod(in, &label);
        if (in.fail()) throw gs::IOReadFailure(
            "In npstat::LinInterpolatedTableND::read: input stream failure");
        return new LinInterpolatedTableND(
            data, axes, leftInterpolation, rightInterpolation, label);
    }
template<typename Numeric , class Axis >
bool npstat::LinInterpolatedTableND< Numeric, Axis >::rightInterpolationLinear ( unsigned  i) const

Definition at line 535 of file LinInterpolatedTableND.h.

References i.

    {
        if (i >= dim_) throw npstat::NpstatOutOfRange(
            "In npstat::LinInterpolatedTableND::rightInterpolationLinear: "
            "index out of range");
        return rightInterpolationLinear_[i];
    }
template<class Numeric, class Axis = UniformAxis>
void npstat::LinInterpolatedTableND< Numeric, Axis >::setFunctionLabel ( const char *  newlabel) [inline]

Modifier for the function label

Definition at line 152 of file LinInterpolatedTableND.h.

References npstat::LinInterpolatedTableND< Numeric, Axis >::functionLabel_.

            {functionLabel_ = newlabel ? newlabel : "";}
template<typename Numeric , class Axis >
template<class Functor1 >
double npstat::LinInterpolatedTableND< Numeric, Axis >::solveForRatioArg ( double  xmin,
double  xmax,
double  rmin,
double  rmax,
double  fval,
Functor1  invg 
) [static, private]

Definition at line 1108 of file LinInterpolatedTableND.h.

References abs, npstat::Private::lind_interpolateSimple(), relval_parameters_module::step, SiStripMonitorClusterAlca_cfi::xmax, and SiStripMonitorClusterAlca_cfi::xmin.

    {
        // Find two values of x so that f(x0) <= fval <= f(x1)
        double x0 = xmin;
        double x1 = xmax;
        double fmin = invg(xmin)*rmin;
        double fmax = invg(xmax)*rmax;
        const double step = xmax - xmin;
        assert(fmin < fmax);
        assert(step > 0.0);

        unsigned stepcount = 0;
        const unsigned maxSteps = 1000U;
        for (double stepfactor = 1.0; (fval < fmin || fval > fmax) &&
                 stepcount < maxSteps; stepfactor *= 2.0, ++stepcount)
            if (fval < fmin)
            {
                x1 = x0;
                fmax = fmin;
                x0 -= stepfactor*step;
                fmin = invg(x0)*Private::lind_interpolateSimple(
                    xmin, xmax, rmin, rmax, x0);
            }
            else
            {
                x0 = x1;
                fmin = fmax;
                x1 += stepfactor*step;
                fmax = invg(x1)*Private::lind_interpolateSimple(
                    xmin, xmax, rmin, rmax, x1);
            }
        if (stepcount == maxSteps) throw npstat::NpstatRuntimeError(
            "In LinInterpolatedTableND::solveForRatioArg: "
            "faled to bracket the root");

        assert(x1 >= x0);
        while ((x1 - x0)/(std::abs(x1) + std::abs(x0) + DBL_EPSILON) > 4.0*DBL_EPSILON)
        {
            const double xhalf = (x1 + x0)/2.0;
            const double fhalf = invg(xhalf)*Private::lind_interpolateSimple(
                xmin, xmax, rmin, rmax, xhalf);
            if (fval < fhalf)
            {
                x1 = xhalf;
                fmax = fhalf;
            }
            else
            {
                x0 = xhalf;
                fmin = fhalf;
            }    
        }
        return (x1 + x0)/2.0;
    }
template<class Numeric, class Axis = UniformAxis>
ArrayND<Numeric>& npstat::LinInterpolatedTableND< Numeric, Axis >::table ( ) [inline]
template<class Numeric, class Axis = UniformAxis>
const ArrayND<Numeric>& npstat::LinInterpolatedTableND< Numeric, Axis >::table ( ) const [inline]

Access the interpolator table data

Definition at line 131 of file LinInterpolatedTableND.h.

References npstat::LinInterpolatedTableND< Numeric, Axis >::data_.

Referenced by npstat::StorableInterpolationFunctor< Numeric, Axis, Converter >::table().

{return data_;}
template<class Numeric, class Axis = UniformAxis>
static unsigned npstat::LinInterpolatedTableND< Numeric, Axis >::version ( ) [inline, static]

Definition at line 210 of file LinInterpolatedTableND.h.

{return 1;}
template<typename Numeric , class Axis >
bool npstat::LinInterpolatedTableND< Numeric, Axis >::write ( std::ostream &  of) const

Definition at line 479 of file LinInterpolatedTableND.h.

References ntuplemaker::status.

Referenced by npstat::StorableInterpolationFunctor< Numeric, Axis, Converter >::write().

    {
        const bool status = data_.classId().write(of) &&
                            data_.write(of) &&
                            gs::write_obj_vector(of, axes_);
        if (status)
        {
            gs::write_pod_array(of, leftInterpolationLinear_, dim_);
            gs::write_pod_array(of, rightInterpolationLinear_, dim_);
            gs::write_pod(of, functionLabel_);
        }
        return status && !of.fail();
    }

Friends And Related Function Documentation

template<class Numeric, class Axis = UniformAxis>
friend class LinInterpolatedTableND [friend]

Definition at line 34 of file LinInterpolatedTableND.h.


Member Data Documentation

template<class Numeric, class Axis = UniformAxis>
bool npstat::LinInterpolatedTableND< Numeric, Axis >::allConstInterpolated_ [private]
template<class Numeric, class Axis = UniformAxis>
std::vector<Axis> npstat::LinInterpolatedTableND< Numeric, Axis >::axes_ [private]
template<class Numeric, class Axis = UniformAxis>
ArrayND<Numeric> npstat::LinInterpolatedTableND< Numeric, Axis >::data_ [private]
template<class Numeric, class Axis = UniformAxis>
unsigned npstat::LinInterpolatedTableND< Numeric, Axis >::dim_ [private]
template<class Numeric, class Axis = UniformAxis>
std::string npstat::LinInterpolatedTableND< Numeric, Axis >::functionLabel_ [private]
template<class Numeric, class Axis = UniformAxis>
char npstat::LinInterpolatedTableND< Numeric, Axis >::leftInterpolationLinear_[CHAR_BIT *sizeof(unsigned long)] [private]
template<class Numeric, class Axis = UniformAxis>
char npstat::LinInterpolatedTableND< Numeric, Axis >::rightInterpolationLinear_[CHAR_BIT *sizeof(unsigned long)] [private]