CMS 3D CMS Logo

Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes

npstat::UniformAxis Class Reference

#include <UniformAxis.h>

List of all members.

Public Member Functions

gs::ClassId classId () const
double coordinate (unsigned i) const
std::vector< double > coords () const
std::pair< unsigned, double > getInterval (double coordinate) const
double intervalWidth (unsigned) const
bool isClose (const UniformAxis &r, double tol) const
bool isUniform () const
const std::string & label () const
double length () const
std::pair< unsigned, double > linearInterval (double coordinate) const
double max () const
double min () const
unsigned nCoords () const
unsigned nIntervals () const
bool operator!= (const UniformAxis &r) const
bool operator== (const UniformAxis &r) const
void setLabel (const char *newlabel)
 UniformAxis (unsigned nCoords, double min, double max, const char *label=0)
bool usesLogSpace () const
bool write (std::ostream &of) const

Static Public Member Functions

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

Private Member Functions

 UniformAxis ()

Private Attributes

double bw_
std::string label_
double max_
double min_
unsigned npt_

Detailed Description

This class contains the info needed to define an axis of a rectangular grid. The distance between grid points is uniform.

Definition at line 27 of file UniformAxis.h.


Constructor & Destructor Documentation

npstat::UniformAxis::UniformAxis ( unsigned  nCoords,
double  min,
double  max,
const char *  label = 0 
)

Definition at line 13 of file UniformAxis.cc.

References bw_, max_, min_, npt_, and swap().

        : min_(min), max_(max), label_(label ? label : ""), npt_(nCoords)
    {
        if (!(npt_ > 1U && npt_ < UINT_MAX/2U - 1U))
            throw npstat::NpstatInvalidArgument("In npstat::UniformAxis constructor: "
                                        "number of points is out of range");
        if (min_ > max_)
            std::swap(min_, max_);
        bw_ = (max_ - min_)/(npt_ - 1U);
        if (max_ == min_)
            throw npstat::NpstatInvalidArgument(
                "In npstat::UniformAxis constructor: "
                "minimum and maximum must be distinct");
    }
npstat::UniformAxis::UniformAxis ( ) [inline, private]

Definition at line 86 of file UniformAxis.h.

Referenced by read().

: min_(0.), max_(0.), bw_(0.), npt_(0) {}

Member Function Documentation

gs::ClassId npstat::UniformAxis::classId ( ) const [inline]

Definition at line 78 of file UniformAxis.h.

Referenced by npstat::DualAxis::write().

{return gs::ClassId(*this);}
static const char* npstat::UniformAxis::classname ( ) [inline, static]

Definition at line 81 of file UniformAxis.h.

{return "npstat::UniformAxis";}
double npstat::UniformAxis::coordinate ( unsigned  i) const

Definition at line 81 of file UniformAxis.cc.

References bw_, i, max_, min_, and npt_.

Referenced by npstat::DualAxis::coordinate().

    {
        if (i >= npt_)
            throw npstat::NpstatOutOfRange(
                "In npstat::UniformAxis::coordinate: index out of range");
        if (i == npt_ - 1U)
            return max_;
        else
            return min_ + bw_*i;
    }
std::vector< double > npstat::UniformAxis::coords ( ) const

Definition at line 70 of file UniformAxis.cc.

References bw_, i, max_, min_, and npt_.

Referenced by npstat::DualAxis::coords().

    {
        std::vector<double> vec;
        vec.reserve(npt_);
        const unsigned nptm1 = npt_ - 1U;
        for (unsigned i=0; i<nptm1; ++i)
            vec.push_back(min_ + bw_*i);
        vec.push_back(max_);
        return vec;
    }
std::pair< unsigned, double > npstat::UniformAxis::getInterval ( double  coordinate) const

Definition at line 30 of file UniformAxis.cc.

References bw_, max_, min_, npt_, and w().

Referenced by npstat::DualAxis::getInterval().

    {
        if (x <= min_)
            return std::pair<unsigned,double>(0U, 1.0);
        else if (x >= max_)
            return std::pair<unsigned,double>(npt_ - 2U, 0.0);
        else
        {
            unsigned binnum = static_cast<unsigned>(floor((x - min_)/bw_));
            if (binnum > npt_ - 2U)
                binnum = npt_ - 2U;
            double w = binnum + 1.0 - (x - min_)/bw_;
            if (w < 0.0)
                w = 0.0;
            else if (w > 1.0)
                w = 1.0;
            return std::pair<unsigned,double>(binnum, w);
        }
    }
double npstat::UniformAxis::intervalWidth ( unsigned  ) const [inline]

Definition at line 64 of file UniformAxis.h.

References bw_.

Referenced by npstat::DualAxis::intervalWidth().

{return bw_;}
bool npstat::UniformAxis::isClose ( const UniformAxis r,
double  tol 
) const

Definition at line 92 of file UniformAxis.cc.

References npstat::closeWithinTolerance(), label_, max_, min_, and npt_.

    {
        return closeWithinTolerance(min_, r.min_, tol) &&
               closeWithinTolerance(max_, r.max_, tol) &&
               label_ == r.label_ &&
               npt_ == r.npt_;
    }
bool npstat::UniformAxis::isUniform ( ) const [inline]

Definition at line 62 of file UniformAxis.h.

{return true;}
const std::string& npstat::UniformAxis::label ( ) const [inline]

Definition at line 38 of file UniformAxis.h.

References label_.

Referenced by npstat::convertToHistoAxis(), npstat::DualAxis::label(), and read().

{return label_;}
double npstat::UniformAxis::length ( ) const [inline]

Definition at line 61 of file UniformAxis.h.

References max_, and min_.

Referenced by npstat::DualAxis::length().

{return max_ - min_;}
std::pair< unsigned, double > npstat::UniformAxis::linearInterval ( double  coordinate) const

Definition at line 50 of file UniformAxis.cc.

References bw_, max_, min_, npt_, w(), and x.

Referenced by npstat::DualAxis::linearInterval().

    {
        if (x <= min_)
            return std::pair<unsigned,double>(0U, 1.0 - (x - min_)/bw_);
        else if (x >= max_)
            return std::pair<unsigned,double>(npt_ - 2U, (max_ - x)/bw_);
        else
        {
            unsigned binnum = static_cast<unsigned>(floor((x - min_)/bw_));
            if (binnum > npt_ - 2U)
                binnum = npt_ - 2U;
            double w = binnum + 1.0 - (x - min_)/bw_;
            if (w < 0.0)
                w = 0.0;
            else if (w > 1.0)
                w = 1.0;
            return std::pair<unsigned,double>(binnum, w);
        }
    }
double npstat::UniformAxis::max ( ) const [inline]

Definition at line 37 of file UniformAxis.h.

References max_.

Referenced by npstat::convertToHistoAxis(), npstat::DualAxis::max(), and read().

{return max_;}
double npstat::UniformAxis::min ( ) const [inline]

Definition at line 36 of file UniformAxis.h.

References min_.

Referenced by npstat::convertToHistoAxis(), npstat::DualAxis::min(), and read().

{return min_;}
unsigned npstat::UniformAxis::nCoords ( ) const [inline]

Definition at line 35 of file UniformAxis.h.

References npt_.

Referenced by npstat::convertToHistoAxis(), and npstat::DualAxis::nCoords().

{return npt_;}
unsigned npstat::UniformAxis::nIntervals ( ) const [inline]

Definition at line 63 of file UniformAxis.h.

References npt_.

Referenced by npstat::DualAxis::nIntervals().

{return npt_ - 1;}
bool npstat::UniformAxis::operator!= ( const UniformAxis r) const [inline]

Definition at line 67 of file UniformAxis.h.

References alignCSCRings::r.

            {return !(*this == r);}
bool npstat::UniformAxis::operator== ( const UniformAxis r) const

Definition at line 100 of file UniformAxis.cc.

References label_, max_, min_, and npt_.

    {
        return min_ == r.min_ &&
               max_ == r.max_ &&
               label_ == r.label_ &&
               npt_ == r.npt_;
    }
UniformAxis * npstat::UniformAxis::read ( const gs::ClassId &  id,
std::istream &  in 
) [static]

Definition at line 117 of file UniformAxis.cc.

References cond::rpcobimon::current, label(), max(), min(), AlCaHLTBitMon_QueryRunRegistry::string, and UniformAxis().

Referenced by npstat::DualAxis::read().

    {
        static const gs::ClassId current(gs::ClassId::makeId<UniformAxis>());
        current.ensureSameId(id);

        double min = 0.0, max = 0.0;
        std::string label;
        unsigned nBins = 0;

        gs::read_pod(in, &min);
        gs::read_pod(in, &max);
        gs::read_pod(in, &label);
        gs::read_pod(in, &nBins);

        if (!in.fail())
            return new UniformAxis(nBins, min, max, label.c_str());
        else
            throw gs::IOReadFailure("In npstat::UniformAxis::read: "
                                    "input stream failure");
    }
void npstat::UniformAxis::setLabel ( const char *  newlabel) [inline]

Definition at line 74 of file UniformAxis.h.

References label_.

Referenced by npstat::DualAxis::setLabel().

            {label_ = newlabel ? newlabel : "";}
bool npstat::UniformAxis::usesLogSpace ( ) const [inline]

Definition at line 39 of file UniformAxis.h.

Referenced by npstat::DualAxis::usesLogSpace().

{return false;}
static unsigned npstat::UniformAxis::version ( ) [inline, static]

Definition at line 82 of file UniformAxis.h.

{return 1;}
bool npstat::UniformAxis::write ( std::ostream &  of) const

Definition at line 108 of file UniformAxis.cc.

References label_, max_, min_, and npt_.

Referenced by npstat::DualAxis::write().

    {
        gs::write_pod(of, min_);
        gs::write_pod(of, max_);
        gs::write_pod(of, label_);
        gs::write_pod(of, npt_);
        return !of.fail();
    }

Member Data Documentation

double npstat::UniformAxis::bw_ [private]
std::string npstat::UniformAxis::label_ [private]

Definition at line 91 of file UniformAxis.h.

Referenced by isClose(), label(), operator==(), setLabel(), and write().

double npstat::UniformAxis::max_ [private]
double npstat::UniformAxis::min_ [private]
unsigned npstat::UniformAxis::npt_ [private]