CMS 3D CMS Logo

Classes | Functions

npstat::Private Namespace Reference

Classes

struct  AbsHelper
struct  AbsHelper< T, 1 >
struct  AbsReturnType
struct  AbsReturnType< const std::complex< T > >
struct  AbsReturnType< const volatile std::complex< T > >
struct  AbsReturnType< std::complex< T > >
struct  AbsReturnType< volatile std::complex< T > >
class  ArrayMapper

Functions

template<class Axis >
std::vector< Axis > addAxis (const std::vector< Axis > &axes, const Axis &newAxis, const unsigned newAxisNumber)
template<class Axis >
std::vector< Axis > axesOfASlice (const std::vector< Axis > &axes, const unsigned *fixedIndices, const unsigned nFixedIndices)
void h_badargs (const char *method)
template<typename Float , class Axis >
void iHND_checkArgs (const HistoND< Float, Axis > &histo, const unsigned xDim, const unsigned interpolationDegree)
double lind_interpolateSimple (const double x0, const double x1, const double y0, const double y1, const double x)
template<typename Numeric , class Axis >
void lind_invert1DSlice (const ArrayND< Numeric > &fromSlice, const Axis &fromAxis, const Axis &toAxis, const bool leftLinear, const bool rightLinear, ArrayND< Numeric > *toSlice)
template<class Axis >
ArrayShape makeHistoShape (const Axis &xAxis, const Axis &yAxis, const Axis &zAxis)
template<class Axis >
ArrayShape makeHistoShape (const Axis &xAxis)
template<class Axis >
ArrayShape makeHistoShape (const Axis &xAxis, const Axis &yAxis, const Axis &zAxis, const Axis &tAxis)
template<class Axis >
ArrayShape makeHistoShape (const std::vector< Axis > &axes)
template<class Axis >
ArrayShape makeHistoShape (const Axis &xAxis, const Axis &yAxis, const Axis &zAxis, const Axis &tAxis, const Axis &vAxis)
template<class Axis >
ArrayShape makeHistoShape (const Axis &xAxis, const Axis &yAxis)
template<class Axis >
ArrayShape makeTableShape (const std::vector< Axis > &axes)
template<class Axis >
ArrayShape makeTableShape (const Axis &xAxis, const Axis &yAxis)
template<class Axis >
ArrayShape makeTableShape (const Axis &xAxis, const Axis &yAxis, const Axis &zAxis, const Axis &tAxis)
template<class Axis >
ArrayShape makeTableShape (const Axis &xAxis, const Axis &yAxis, const Axis &zAxis)
template<class Axis >
ArrayShape makeTableShape (const Axis &xAxis)
template<class Axis >
ArrayShape makeTableShape (const Axis &xAxis, const Axis &yAxis, const Axis &zAxis, const Axis &tAxis, const Axis &vAxis)
template<class Axis >
ArrayShape shapeOfASlice (const std::vector< Axis > &axes, const unsigned *fixedIndices, const unsigned nFixedIndices)
template<class Axis >
ArrayShape shapeWithExtraAxis (const std::vector< Axis > &axes, const Axis &newAxis, const unsigned newAxisNumber)

Function Documentation

template<class Axis >
std::vector<Axis> npstat::Private::addAxis ( const std::vector< Axis > &  axes,
const Axis &  newAxis,
const unsigned  newAxisNumber 
)

Definition at line 1042 of file HistoND.h.

References i.

        {
            const unsigned dim = axes.size();
            std::vector<Axis> newAxes;
            newAxes.reserve(dim + 1U);
            unsigned iadd = 0;
            for (unsigned i=0; i<dim; ++i)
            {
                if (newAxisNumber == i)
                    newAxes.push_back(newAxis);
                else
                    newAxes.push_back(axes[iadd++]);
            }
            if (iadd == dim)
                newAxes.push_back(newAxis);
            else
                newAxes.push_back(axes[iadd]);
            return newAxes;
        }
template<class Axis >
std::vector<Axis> npstat::Private::axesOfASlice ( const std::vector< Axis > &  axes,
const unsigned *  fixedIndices,
const unsigned  nFixedIndices 
)

Definition at line 967 of file HistoND.h.

References i, and j.

        {
            const unsigned dim = axes.size();
            std::vector<Axis> newAxes;
            if (nFixedIndices == 0U) throw npstat::NpstatInvalidArgument(
                "In npstat::Private::axesOfASlice: "
                "at least one fixed index must be specified");
            if (nFixedIndices > dim) throw npstat::NpstatInvalidArgument(
                "In npstat::Private::axesOfASlice: too many fixed indices");
            assert(fixedIndices);
            for (unsigned i=0; i<nFixedIndices; ++i)
               if (fixedIndices[i] >= dim) throw npstat::NpstatInvalidArgument(
                  "In npstat::Private::axesOfASlice: fixed index out of range");
            newAxes.reserve(dim - nFixedIndices);
            for (unsigned i=0; i<dim; ++i)
            {
                bool fixed = false;
                for (unsigned j=0; j<nFixedIndices; ++j)
                    if (fixedIndices[j] == i)
                    {
                        fixed = true;
                        break;
                    }
                if (!fixed)
                    newAxes.push_back(axes[i]);
            }
            if (newAxes.size() != dim - nFixedIndices)
                throw npstat::NpstatInvalidArgument(
                    "In npstat::Private::axesOfASlice: duplicate fixed index");
            return newAxes;
        }
void npstat::Private::h_badargs ( const char *  method) [inline]

Definition at line 1087 of file HistoND.h.

Referenced by npstat::HistoND< Numeric, Axis >::closestBin(), npstat::HistoND< Numeric, Axis >::dispatch(), npstat::HistoND< Numeric, Axis >::examine(), npstat::HistoND< Numeric, Axis >::fill(), and npstat::HistoND< Numeric, Axis >::fillC().

        {
            std::ostringstream os;
            os << "In npstat::HistoND::" << method << ": number of arguments"
               << " is incompatible with histogram dimensionality";
            throw npstat::NpstatInvalidArgument(os.str());
        }
template<typename Float , class Axis >
void npstat::Private::iHND_checkArgs ( const HistoND< Float, Axis > &  histo,
const unsigned  xDim,
const unsigned  interpolationDegree 
)

Definition at line 106 of file interpolateHistoND.h.

References npstat::HistoND< Numeric, Axis >::dim(), and npstat::HistoND< Numeric, Axis >::isUniformlyBinned().

Referenced by npstat::interpolateHistoND().

        {
            if (xDim != histo.dim()) throw npstat::NpstatInvalidArgument(
                "In npstat::interpolateHistoND: incompatible "
                "dimensionality of input coordinates");
            if (xDim == 0U) throw npstat::NpstatInvalidArgument(
                "In npstat::interpolateHistoND: can not interpolate "
                "zero-dimensional histograms");
            if (!(interpolationDegree == 0U ||
                  interpolationDegree == 1U ||
                  interpolationDegree == 3U)) throw npstat::NpstatInvalidArgument(
                "In npstat::interpolateHistoND: "
                "unsupported interpolation degree");
            if (interpolationDegree == 3U && !histo.isUniformlyBinned())
                throw npstat::NpstatInvalidArgument(
                    "In npstat::interpolateHistoND: unsupported "
                    "interpolation degree for non-uniform binning");
        }
double npstat::Private::lind_interpolateSimple ( const double  x0,
const double  x1,
const double  y0,
const double  y1,
const double  x 
) [inline]

Definition at line 334 of file LinInterpolatedTableND.h.

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

        {
            return y0 + (y1 - y0)*((x - x0)/(x1 - x0));
        }
template<typename Numeric , class Axis >
void npstat::Private::lind_invert1DSlice ( const ArrayND< Numeric > &  fromSlice,
const Axis &  fromAxis,
const Axis &  toAxis,
const bool  leftLinear,
const bool  rightLinear,
ArrayND< Numeric > *  toSlice 
)

Definition at line 343 of file LinInterpolatedTableND.h.

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

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

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

            const Numeric* fromData = fromSlice.data();
            const unsigned fromLen = fromSlice.length();
            assert(fromLen > 1U);
            assert(fromLen == fromAxis.nCoords());
            const Numeric* fromDataEnd = fromData + fromLen;
            if (!isStrictlyMonotonous(fromData, fromDataEnd))
                throw npstat::NpstatInvalidArgument(
                    "In npstat::Private::lind_invert1DSlice: "
                    "slice data is not monotonous and can not be inverted");

            const Numeric yfirst = fromData[0];
            const Numeric ylast = fromData[fromLen - 1U];
            const bool increasing = yfirst < ylast;

            Numeric* toD = const_cast<Numeric*>(toSlice->data());
            const unsigned nAxisPoints = toAxis.nCoords();
            assert(toSlice->length() == nAxisPoints);

            for (unsigned ipt=0; ipt<nAxisPoints; ++ipt)
            {
                const Numeric y = static_cast<Numeric>(toAxis.coordinate(ipt));
                if (increasing)
                {
                    if (y <= yfirst)
                    {
                        if (leftLinear)
                            toD[ipt] = Private::lind_interpolateSimple(
                                yfirst, fromData[1], fromAxis.coordinate(0),
                                fromAxis.coordinate(1), y);
                        else
                            toD[ipt] = fromAxis.coordinate(0);
                    }
                    else if (y >= ylast)
                    {
                        if (rightLinear)
                            toD[ipt] = Private::lind_interpolateSimple(
                                ylast, fromData[fromLen - 2U],
                                fromAxis.coordinate(fromLen - 1U),
                                fromAxis.coordinate(fromLen - 2U), y);
                        else
                            toD[ipt] = fromAxis.coordinate(fromLen - 1U);
                    }
                    else
                    {
                        const unsigned i = std::lower_bound(fromData,fromDataEnd,y)-
                            fromData;
                        toD[ipt] = Private::lind_interpolateSimple(
                            fromData[i-1U], fromData[i],
                            fromAxis.coordinate(i-1U),
                            fromAxis.coordinate(i), y);
                    }
                }
                else
                {
                    // The role of left and right are exchanged
                    // with respect to first and last point
                    if (y <= ylast)
                    {
                        if (leftLinear)
                            toD[ipt] = Private::lind_interpolateSimple(
                                ylast, fromData[fromLen - 2U],
                                fromAxis.coordinate(fromLen - 1U),
                                fromAxis.coordinate(fromLen - 2U), y);
                        else
                            toD[ipt] = fromAxis.coordinate(fromLen - 1U);
                    }
                    else if (y >= yfirst)
                    {
                        if (rightLinear)
                            toD[ipt] = Private::lind_interpolateSimple(
                                yfirst, fromData[1],
                                fromAxis.coordinate(0),
                                fromAxis.coordinate(1), y);
                        else
                            toD[ipt] = fromAxis.coordinate(0);
                    }
                    else
                    {
                        const unsigned i = std::lower_bound(fromData,fromDataEnd,
                                             y,std::greater<Numeric>())-fromData;
                        toD[ipt] = Private::lind_interpolateSimple(
                            fromData[i-1U], fromData[i],
                            fromAxis.coordinate(i-1U),
                            fromAxis.coordinate(i), y);
                    }
                }
            }
        }
template<class Axis >
ArrayShape npstat::Private::makeHistoShape ( const Axis &  xAxis,
const Axis &  yAxis,
const Axis &  zAxis 
)

Definition at line 926 of file HistoND.h.

References query::result.

        {
            ArrayShape result;
            result.reserve(3U);
            result.push_back(xAxis.nBins());
            result.push_back(yAxis.nBins());
            result.push_back(zAxis.nBins());
            return result;
        }
template<class Axis >
ArrayShape npstat::Private::makeHistoShape ( const Axis &  xAxis)

Definition at line 907 of file HistoND.h.

References query::result.

        {
            ArrayShape result;
            result.reserve(1U);
            result.push_back(xAxis.nBins());
            return result;
        }
template<class Axis >
ArrayShape npstat::Private::makeHistoShape ( const Axis &  xAxis,
const Axis &  yAxis,
const Axis &  zAxis,
const Axis &  tAxis 
)

Definition at line 939 of file HistoND.h.

References query::result.

        {
            ArrayShape result;
            result.reserve(4U);
            result.push_back(xAxis.nBins());
            result.push_back(yAxis.nBins());
            result.push_back(zAxis.nBins());
            result.push_back(tAxis.nBins());
            return result;
        }
template<class Axis >
ArrayShape npstat::Private::makeHistoShape ( const std::vector< Axis > &  axes)

Definition at line 896 of file HistoND.h.

References i, n, and query::result.

        {
            const unsigned n = axes.size();
            ArrayShape result;
            result.reserve(n);
            for (unsigned i=0; i<n; ++i)
                result.push_back(axes[i].nBins());
            return result;
        }
template<class Axis >
ArrayShape npstat::Private::makeHistoShape ( const Axis &  xAxis,
const Axis &  yAxis,
const Axis &  zAxis,
const Axis &  tAxis,
const Axis &  vAxis 
)

Definition at line 952 of file HistoND.h.

References query::result.

        {
            ArrayShape result;
            result.reserve(5U);
            result.push_back(xAxis.nBins());
            result.push_back(yAxis.nBins());
            result.push_back(zAxis.nBins());
            result.push_back(tAxis.nBins());
            result.push_back(vAxis.nBins());
            return result;
        }
template<class Axis >
ArrayShape npstat::Private::makeHistoShape ( const Axis &  xAxis,
const Axis &  yAxis 
)

Definition at line 916 of file HistoND.h.

References query::result.

        {
            ArrayShape result;
            result.reserve(2U);
            result.push_back(xAxis.nBins());
            result.push_back(yAxis.nBins());
            return result;
        }
template<class Axis >
ArrayShape npstat::Private::makeTableShape ( const std::vector< Axis > &  axes)

Definition at line 264 of file LinInterpolatedTableND.h.

References i, n, and query::result.

        {
            const unsigned n = axes.size();
            ArrayShape result;
            result.reserve(n);
            for (unsigned i=0; i<n; ++i)
                result.push_back(axes[i].nCoords());
            return result;
        }
template<class Axis >
ArrayShape npstat::Private::makeTableShape ( const Axis &  xAxis,
const Axis &  yAxis 
)

Definition at line 284 of file LinInterpolatedTableND.h.

References query::result.

        {
            ArrayShape result;
            result.reserve(2U);
            result.push_back(xAxis.nCoords());
            result.push_back(yAxis.nCoords());
            return result;
        }
template<class Axis >
ArrayShape npstat::Private::makeTableShape ( const Axis &  xAxis,
const Axis &  yAxis,
const Axis &  zAxis,
const Axis &  tAxis 
)

Definition at line 307 of file LinInterpolatedTableND.h.

References query::result.

        {
            ArrayShape result;
            result.reserve(4U);
            result.push_back(xAxis.nCoords());
            result.push_back(yAxis.nCoords());
            result.push_back(zAxis.nCoords());
            result.push_back(tAxis.nCoords());
            return result;
        }
template<class Axis >
ArrayShape npstat::Private::makeTableShape ( const Axis &  xAxis,
const Axis &  yAxis,
const Axis &  zAxis 
)

Definition at line 294 of file LinInterpolatedTableND.h.

References query::result.

        {
            ArrayShape result;
            result.reserve(3U);
            result.push_back(xAxis.nCoords());
            result.push_back(yAxis.nCoords());
            result.push_back(zAxis.nCoords());
            return result;
        }
template<class Axis >
ArrayShape npstat::Private::makeTableShape ( const Axis &  xAxis)

Definition at line 275 of file LinInterpolatedTableND.h.

References query::result.

        {
            ArrayShape result;
            result.reserve(1U);
            result.push_back(xAxis.nCoords());
            return result;
        }
template<class Axis >
ArrayShape npstat::Private::makeTableShape ( const Axis &  xAxis,
const Axis &  yAxis,
const Axis &  zAxis,
const Axis &  tAxis,
const Axis &  vAxis 
)

Definition at line 320 of file LinInterpolatedTableND.h.

References query::result.

        {
            ArrayShape result;
            result.reserve(5U);
            result.push_back(xAxis.nCoords());
            result.push_back(yAxis.nCoords());
            result.push_back(zAxis.nCoords());
            result.push_back(tAxis.nCoords());
            result.push_back(vAxis.nCoords());
            return result;
        }
template<class Axis >
ArrayShape npstat::Private::shapeOfASlice ( const std::vector< Axis > &  axes,
const unsigned *  fixedIndices,
const unsigned  nFixedIndices 
)

Definition at line 1002 of file HistoND.h.

References i, and j.

        {
            const unsigned dim = axes.size();
            if (nFixedIndices == 0U) throw npstat::NpstatInvalidArgument(
                "In npstat::Private::shapeOfASlice: "
                "at least one fixed index must be specified");
            if (nFixedIndices > dim) throw npstat::NpstatInvalidArgument(
                "In npstat::Private::shapeOfASlice: too many fixed indices");
            assert(fixedIndices);

            // Check that the fixed indices are within range
            for (unsigned j=0; j<nFixedIndices; ++j)
              if (fixedIndices[j] >= dim) throw npstat::NpstatInvalidArgument(
                "In npstat::Private::shapeOfASlice: fixed index out of range");

            // Build the shape for the slice
            ArrayShape sh;
            if (nFixedIndices < dim)
                sh.reserve(dim - nFixedIndices);
            for (unsigned i=0; i<dim; ++i)
            {
                bool fixed = false;
                for (unsigned j=0; j<nFixedIndices; ++j)
                    if (fixedIndices[j] == i)
                    {
                        fixed = true;
                        break;
                    }
                if (!fixed)
                    sh.push_back(axes[i].nBins());
            }
            if (sh.size() != dim - nFixedIndices)
                throw npstat::NpstatInvalidArgument(
                    "In npstat::Private::shapeOfASlice: duplicate fixed index");
            return sh;
        }
template<class Axis >
ArrayShape npstat::Private::shapeWithExtraAxis ( const std::vector< Axis > &  axes,
const Axis &  newAxis,
const unsigned  newAxisNumber 
)

Definition at line 1065 of file HistoND.h.

References i, and query::result.

        {
            const unsigned dim = axes.size();
            ArrayShape result;
            result.reserve(dim + 1U);
            unsigned iadd = 0;
            for (unsigned i=0; i<dim; ++i)
            {
                if (newAxisNumber == i)
                    result.push_back(newAxis.nBins());
                else
                    result.push_back(axes[iadd++].nBins());
            }
            if (iadd == dim)
                result.push_back(newAxis.nBins());
            else
                result.push_back(axes[iadd].nBins());
            return result;
        }