CMS 3D CMS Logo

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

npstat::HistoAxis Class Reference

#include <HistoAxis.h>

List of all members.

Public Member Functions

double binCenter (const int binNum) const
Interval< double > binInterval (const int binNum) const
int binNumber (double x) const
LinearMapper1d binNumberMapper (bool mapLeftEdgeTo0=true) const
unsigned closestValidBin (double x) const
double fltBinNumber (const double x, const bool mapLeftEdgeTo0=true) const
 HistoAxis (unsigned nBins, double min, double max, const char *label=0)
bool isClose (const HistoAxis &, double tol) const
CircularMapper1d kernelScanMapper (bool doubleRange) const
double leftBinEdge (const int binNum) const
bool operator!= (const HistoAxis &) const
bool operator== (const HistoAxis &) const
double rightBinEdge (const int binNum) const
void setLabel (const char *newlabel)
double min () const
double max () const
Interval< double > interval () const
double length () const
unsigned nBins () const
double binWidth (const int=0) const
const std::string & label () const
bool isUniform () const
gs::ClassId classId () const
bool write (std::ostream &of) const

Static Public Member Functions

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

Private Member Functions

 HistoAxis ()
unsigned overflowIndex (const double x, unsigned *binNumber) const
unsigned overflowIndexWeighted (double x, unsigned *binNumber, double *weight) const

Private Attributes

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

Friends

class DualHistoAxis
class HistoND

Detailed Description

Class which contain the information needed to define a histogram axis. All bins will have the same width. See NUHistoAxis and DualHistoAxis classes for non-uniform binning.

Definition at line 30 of file HistoAxis.h.


Constructor & Destructor Documentation

npstat::HistoAxis::HistoAxis ( unsigned  nBins,
double  min,
double  max,
const char *  label = 0 
)

Minimum and maximum will be internally swapped if the minimum parameter is larger than the maximum

Definition at line 13 of file HistoAxis.cc.

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

        : min_(min), max_(max), label_(label ? label : ""), nBins_(nbins)
    {
        if (!(nBins_ && nBins_ < UINT_MAX/2U - 1U))
            throw npstat::NpstatInvalidArgument("In npstat::HistoAxis constructor: "
                                        "number of bins is out of range");
        if (min_ > max_)
            std::swap(min_, max_);
        bw_ = (max_ - min_)/nBins_;
    }
npstat::HistoAxis::HistoAxis ( ) [inline, private]

Definition at line 128 of file HistoAxis.h.

Referenced by read().

: min_(0.0), max_(0.0), bw_(0.0), nBins_(0) {}

Member Function Documentation

double npstat::HistoAxis::binCenter ( const int  binNum) const [inline]

Return the coordinate of the given bin center

Definition at line 54 of file HistoAxis.h.

References bw_, and min_.

Referenced by npstat::DualHistoAxis::binCenter(), and npstat::convertToGridAxis().

            {return min_ + (binNum + 0.5)*bw_;}
Interval<double> npstat::HistoAxis::binInterval ( const int  binNum) const [inline]

Return the coordinate interval occupied by the given bin

Definition at line 66 of file HistoAxis.h.

References bw_, and min_.

Referenced by npstat::DualHistoAxis::binInterval().

            {return Interval<double>(min_+binNum*bw_, min_+(binNum+1)*bw_);}
int npstat::HistoAxis::binNumber ( double  x) const

This method returns arbitrary integer bin number, including negative numbers and numbers which can exceed nBins()-1

Definition at line 46 of file HistoAxis.cc.

References bw_, max_, min_, and nBins_.

Referenced by npstat::DualHistoAxis::binNumber(), and overflowIndexWeighted().

    {
        if (bw_)
        {
            int binnum = static_cast<int>(floor((x - min_)/bw_));
            if (x >= max_)
            {
                if (binnum < static_cast<int>(nBins_))
                    binnum = nBins_;
            }
            else
            {
                if (binnum >= static_cast<int>(nBins_))
                    binnum = nBins_ - 1U;
            }
            return binnum;
        }
        else
        {
            if (x < min_)
                return -1;
            else
                return nBins_;
        }
    }
LinearMapper1d npstat::HistoAxis::binNumberMapper ( bool  mapLeftEdgeTo0 = true) const

Return the mapper which calculates floating point bin number given the coordinate. The resulting bin number can go above and below the axis range. If "mapLeftEdgeTo0" is specified as "false", it is the center of the first bin which gets mapped to 0.

Definition at line 85 of file HistoAxis.cc.

References bw_, and min_.

    {
        if (!bw_) throw npstat::NpstatDomainError(
            "In npstat::HistoAxis::binNumberMapper: "
            "bin width is zero. Mapper can not be constructed.");
        const double base = mapLeftEdgeTo0 ? min_/bw_ : min_/bw_ + 0.5;
        return LinearMapper1d(1.0/bw_, -base);
    }
double npstat::HistoAxis::binWidth ( const int  = 0) const [inline]

Definition at line 48 of file HistoAxis.h.

References bw_.

Referenced by npstat::DualHistoAxis::binWidth().

{return bw_;}
gs::ClassId npstat::HistoAxis::classId ( ) const [inline]

Method related to "geners" I/O

Definition at line 119 of file HistoAxis.h.

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

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

Definition at line 123 of file HistoAxis.h.

{return "npstat::HistoAxis";}
unsigned npstat::HistoAxis::closestValidBin ( double  x) const

This method returns the closest valid bin number (above 0 and below nBins() )

Definition at line 72 of file HistoAxis.cc.

References bw_, max_, min_, and nBins_.

Referenced by npstat::DualHistoAxis::closestValidBin().

    {
        if (x <= min_)
            return 0U;
        else if (bw_ && x < max_)
        {
            const unsigned binnum = static_cast<unsigned>(floor((x-min_)/bw_));
            if (binnum < nBins_)
                return binnum;
        }
        return nBins_ - 1U;
    }
double npstat::HistoAxis::fltBinNumber ( const double  x,
const bool  mapLeftEdgeTo0 = true 
) const [inline]

Floating point bin number given the coordinate (no bin number truncation of any kind is performed). Works in exactly the same way as the mapper returned by the previous method.

Definition at line 99 of file HistoAxis.h.

References bw_, and min_.

Referenced by npstat::DualHistoAxis::fltBinNumber().

            {return (x - min_)/bw_ - (mapLeftEdgeTo0 ? 0.0 : 0.5);}
Interval<double> npstat::HistoAxis::interval ( ) const [inline]

Definition at line 44 of file HistoAxis.h.

References max_, and min_.

Referenced by npstat::DualHistoAxis::interval().

            {return Interval<double>(min_, max_);}
bool npstat::HistoAxis::isClose ( const HistoAxis r,
double  tol 
) const

Comparison of axis coordinates within given tolerance

Definition at line 25 of file HistoAxis.cc.

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

Referenced by npstat::DualHistoAxis::isClose().

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

Definition at line 50 of file HistoAxis.h.

{return true;}
CircularMapper1d npstat::HistoAxis::kernelScanMapper ( bool  doubleRange) const

The following function returns a mapper that can be helpful in scanning a kernel (a density function) for subsequent convolution with the histogram which contains this axis.

Definition at line 94 of file HistoAxis.cc.

References bw_, max_, and min_.

    {
        if (!bw_) throw npstat::NpstatDomainError(
            "In npstat::HistoAxis::kernelScanMapper: "
            "bin width is zero. Mapper can not be constructed.");
        double range = max_ - min_;
        if (doubleRange)
            range *= 2.0;
        return CircularMapper1d(bw_, 0.0, range);
    }
const std::string& npstat::HistoAxis::label ( ) const [inline]

Definition at line 49 of file HistoAxis.h.

References label_.

Referenced by npstat::convertToGridAxis(), npstat::DualHistoAxis::label(), and read().

{return label_;}
double npstat::HistoAxis::leftBinEdge ( const int  binNum) const [inline]

Return the coordinate of the given bin left edge

Definition at line 58 of file HistoAxis.h.

References bw_, and min_.

Referenced by npstat::DualHistoAxis::leftBinEdge().

            {return min_ + binNum*bw_;}
double npstat::HistoAxis::length ( ) const [inline]

Definition at line 46 of file HistoAxis.h.

References max_, and min_.

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

{return max_ - min_;}
double npstat::HistoAxis::max ( ) const [inline]

Definition at line 43 of file HistoAxis.h.

References max_.

Referenced by npstat::DualHistoAxis::max(), and read().

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

Examine axis properties

Definition at line 42 of file HistoAxis.h.

References min_.

Referenced by npstat::DualHistoAxis::min(), and read().

{return min_;}
unsigned npstat::HistoAxis::nBins ( ) const [inline]

Definition at line 47 of file HistoAxis.h.

References nBins_.

Referenced by npstat::convertToGridAxis(), npstat::DualHistoAxis::nBins(), and read().

{return nBins_;}
bool npstat::HistoAxis::operator!= ( const HistoAxis r) const

Definition at line 41 of file HistoAxis.cc.

References alignCSCRings::r.

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

Definition at line 33 of file HistoAxis.cc.

References label_, max_, min_, and nBins_.

    {
        return min_ == r.min_ &&
               max_ == r.max_ &&
               label_ == r.label_ &&
               nBins_ == r.nBins_;
    }
unsigned npstat::HistoAxis::overflowIndex ( const double  x,
unsigned *  binNumber 
) const [inline, private]

Definition at line 139 of file HistoAxis.h.

References newFWLiteAna::bin, bw_, max_, min_, and nBins_.

Referenced by npstat::DualHistoAxis::overflowIndex().

        {
            if (x < min_)
                return 0U;
            else if (x >= max_)
                return 2U;
            else
            {
                const unsigned bin = static_cast<unsigned>((x - min_)/bw_);
                *binNumber = bin >= nBins_ ? nBins_ - 1U : bin;
                return 1U;
            }
        }
unsigned npstat::HistoAxis::overflowIndexWeighted ( double  x,
unsigned *  binNumber,
double *  weight 
) const [private]

Definition at line 105 of file HistoAxis.cc.

References newFWLiteAna::bin, binNumber(), bw_, max_, min_, and nBins_.

    {
        if (x < min_)
            return 0U;
        else if (x >= max_)
            return 2U;
        else
        {
            if (nBins_ <= 1U) throw npstat::NpstatInvalidArgument(
                "In npstat::HistoAxis::overflowIndexWeighted: "
                "must have more than one bin");
            const double dbin = (x - min_)/bw_;
            if (dbin <= 0.5)
            {
                *binNumber = 0;
                *weight = 1.0;
            }
            else if (dbin >= nBins_ - 0.5)
            {
                *binNumber = nBins_ - 2;
                *weight = 0.0;
            }
            else
            {
                const unsigned bin = static_cast<unsigned>(dbin - 0.5);
                *binNumber = bin >= nBins_ - 1U ? nBins_ - 2U : bin;
                *weight = 1.0 - (dbin - 0.5 - *binNumber);
            }
            return 1U;
        }
    }
HistoAxis * npstat::HistoAxis::read ( const gs::ClassId &  id,
std::istream &  in 
) [static]

Definition at line 147 of file HistoAxis.cc.

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

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

    {
        static const gs::ClassId current(gs::ClassId::makeId<HistoAxis>());
        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 HistoAxis(nBins, min, max, label.c_str());
        else
            throw gs::IOReadFailure("In npstat::HistoAxis::read: "
                                    "input stream failure");
    }
double npstat::HistoAxis::rightBinEdge ( const int  binNum) const [inline]

Return the coordinate of the given bin right edge

Definition at line 62 of file HistoAxis.h.

References bw_, and min_.

Referenced by npstat::DualHistoAxis::rightBinEdge().

            {return min_ + (binNum + 1)*bw_;}
void npstat::HistoAxis::setLabel ( const char *  newlabel) [inline]

Change the axis label

Definition at line 70 of file HistoAxis.h.

References label_.

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

            {label_ = newlabel ? newlabel : "";}
static unsigned npstat::HistoAxis::version ( ) [inline, static]

Definition at line 124 of file HistoAxis.h.

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

Definition at line 138 of file HistoAxis.cc.

References label_, max_, min_, and nBins_.

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

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

Friends And Related Function Documentation

friend class DualHistoAxis [friend]

Definition at line 137 of file HistoAxis.h.

friend class HistoND [friend]

Definition at line 136 of file HistoAxis.h.


Member Data Documentation

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

Definition at line 133 of file HistoAxis.h.

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

double npstat::HistoAxis::max_ [private]
double npstat::HistoAxis::min_ [private]
unsigned npstat::HistoAxis::nBins_ [private]