CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Friends
npstat::HistoAxis Class Reference

#include <HistoAxis.h>

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
 
template<typename Numeric , class Axis >
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 std::swap().

15  : min_(min), max_(max), label_(label ? label : ""), nBins_(nbins)
16  {
17  if (!(nBins_ && nBins_ < UINT_MAX/2U - 1U))
18  throw npstat::NpstatInvalidArgument("In npstat::HistoAxis constructor: "
19  "number of bins is out of range");
20  if (min_ > max_)
22  bw_ = (max_ - min_)/nBins_;
23  }
const std::string & label() const
Definition: HistoAxis.h:49
std::string label_
Definition: HistoAxis.h:133
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
double max() const
Definition: HistoAxis.h:43
unsigned nBins_
Definition: HistoAxis.h:134
double min() const
Definition: HistoAxis.h:42
npstat::HistoAxis::HistoAxis ( )
inlineprivate

Definition at line 128 of file HistoAxis.h.

Referenced by read().

128 : min_(0.0), max_(0.0), bw_(0.0), nBins_(0) {}
unsigned nBins_
Definition: HistoAxis.h:134

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().

55  {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().

67  {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().

47  {
48  if (bw_)
49  {
50  int binnum = static_cast<int>(floor((x - min_)/bw_));
51  if (x >= max_)
52  {
53  if (binnum < static_cast<int>(nBins_))
54  binnum = nBins_;
55  }
56  else
57  {
58  if (binnum >= static_cast<int>(nBins_))
59  binnum = nBins_ - 1U;
60  }
61  return binnum;
62  }
63  else
64  {
65  if (x < min_)
66  return -1;
67  else
68  return nBins_;
69  }
70  }
unsigned nBins_
Definition: HistoAxis.h:134
Definition: DDAxes.h:10
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 newFWLiteAna::base, bw_, and min_.

86  {
87  if (!bw_) throw npstat::NpstatDomainError(
88  "In npstat::HistoAxis::binNumberMapper: "
89  "bin width is zero. Mapper can not be constructed.");
90  const double base = mapLeftEdgeTo0 ? min_/bw_ : min_/bw_ + 0.5;
91  return LinearMapper1d(1.0/bw_, -base);
92  }
tuple base
Main Program
Definition: newFWLiteAna.py:92
double npstat::HistoAxis::binWidth ( const int  = 0) const
inline

Definition at line 48 of file HistoAxis.h.

References bw_.

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

48 {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().

119 {return gs::ClassId(*this);}
static const char* npstat::HistoAxis::classname ( )
inlinestatic

Definition at line 123 of file HistoAxis.h.

123 {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().

73  {
74  if (x <= min_)
75  return 0U;
76  else if (bw_ && x < max_)
77  {
78  const unsigned binnum = static_cast<unsigned>(floor((x-min_)/bw_));
79  if (binnum < nBins_)
80  return binnum;
81  }
82  return nBins_ - 1U;
83  }
unsigned nBins_
Definition: HistoAxis.h:134
Definition: DDAxes.h:10
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().

101  {return (x - min_)/bw_ - (mapLeftEdgeTo0 ? 0.0 : 0.5);}
Definition: DDAxes.h:10
Interval<double> npstat::HistoAxis::interval ( ) const
inline

Definition at line 44 of file HistoAxis.h.

References max_, and min_.

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

45  {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().

26  {
27  return closeWithinTolerance(min_, r.min_, tol) &&
28  closeWithinTolerance(max_, r.max_, tol) &&
29  label_ == r.label_ &&
30  nBins_ == r.nBins_;
31  }
bool closeWithinTolerance(const double &a, const double &b, const double &tol)
std::string label_
Definition: HistoAxis.h:133
unsigned nBins_
Definition: HistoAxis.h:134
bool npstat::HistoAxis::isUniform ( ) const
inline

Definition at line 50 of file HistoAxis.h.

50 {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_.

95  {
96  if (!bw_) throw npstat::NpstatDomainError(
97  "In npstat::HistoAxis::kernelScanMapper: "
98  "bin width is zero. Mapper can not be constructed.");
99  double range = max_ - min_;
100  if (doubleRange)
101  range *= 2.0;
102  return CircularMapper1d(bw_, 0.0, range);
103  }
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().

49 {return label_;}
std::string label_
Definition: HistoAxis.h:133
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().

59  {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().

46 {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().

43 {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().

42 {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().

47 {return nBins_;}
unsigned nBins_
Definition: HistoAxis.h:134
bool npstat::HistoAxis::operator!= ( const HistoAxis r) const

Definition at line 41 of file HistoAxis.cc.

References alignCSCRings::r.

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

Definition at line 33 of file HistoAxis.cc.

References label_, max_, min_, and nBins_.

34  {
35  return min_ == r.min_ &&
36  max_ == r.max_ &&
37  label_ == r.label_ &&
38  nBins_ == r.nBins_;
39  }
std::string label_
Definition: HistoAxis.h:133
unsigned nBins_
Definition: HistoAxis.h:134
unsigned npstat::HistoAxis::overflowIndex ( const double  x,
unsigned *  binNumber 
) const
inlineprivate

Definition at line 139 of file HistoAxis.h.

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

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

141  {
142  if (x < min_)
143  return 0U;
144  else if (x >= max_)
145  return 2U;
146  else
147  {
148  const unsigned bin = static_cast<unsigned>((x - min_)/bw_);
149  *binNumber = bin >= nBins_ ? nBins_ - 1U : bin;
150  return 1U;
151  }
152  }
int binNumber(double x) const
Definition: HistoAxis.cc:46
unsigned nBins_
Definition: HistoAxis.h:134
Definition: DDAxes.h:10
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_.

107  {
108  if (x < min_)
109  return 0U;
110  else if (x >= max_)
111  return 2U;
112  else
113  {
114  if (nBins_ <= 1U) throw npstat::NpstatInvalidArgument(
115  "In npstat::HistoAxis::overflowIndexWeighted: "
116  "must have more than one bin");
117  const double dbin = (x - min_)/bw_;
118  if (dbin <= 0.5)
119  {
120  *binNumber = 0;
121  *weight = 1.0;
122  }
123  else if (dbin >= nBins_ - 0.5)
124  {
125  *binNumber = nBins_ - 2;
126  *weight = 0.0;
127  }
128  else
129  {
130  const unsigned bin = static_cast<unsigned>(dbin - 0.5);
131  *binNumber = bin >= nBins_ - 1U ? nBins_ - 2U : bin;
132  *weight = 1.0 - (dbin - 0.5 - *binNumber);
133  }
134  return 1U;
135  }
136  }
int binNumber(double x) const
Definition: HistoAxis.cc:46
unsigned nBins_
Definition: HistoAxis.h:134
Definition: DDAxes.h:10
int weight
Definition: histoStyle.py:50
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().

148  {
149  static const gs::ClassId current(gs::ClassId::makeId<HistoAxis>());
150  current.ensureSameId(id);
151 
152  double min = 0.0, max = 0.0;
154  unsigned nBins = 0;
155 
156  gs::read_pod(in, &min);
157  gs::read_pod(in, &max);
158  gs::read_pod(in, &label);
159  gs::read_pod(in, &nBins);
160 
161  if (!in.fail())
162  return new HistoAxis(nBins, min, max, label.c_str());
163  else
164  throw gs::IOReadFailure("In npstat::HistoAxis::read: "
165  "input stream failure");
166  }
const std::string & label() const
Definition: HistoAxis.h:49
unsigned nBins() const
Definition: HistoAxis.h:47
double max() const
Definition: HistoAxis.h:43
double min() const
Definition: HistoAxis.h:42
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().

63  {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().

71  {label_ = newlabel ? newlabel : "";}
std::string label_
Definition: HistoAxis.h:133
static unsigned npstat::HistoAxis::version ( )
inlinestatic

Definition at line 124 of file HistoAxis.h.

124 {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().

139  {
140  gs::write_pod(of, min_);
141  gs::write_pod(of, max_);
142  gs::write_pod(of, label_);
143  gs::write_pod(of, nBins_);
144  return !of.fail();
145  }
std::string label_
Definition: HistoAxis.h:133
unsigned nBins_
Definition: HistoAxis.h:134

Friends And Related Function Documentation

friend class DualHistoAxis
friend

Definition at line 137 of file HistoAxis.h.

template<typename Numeric , class Axis >
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
double npstat::HistoAxis::max_
private
double npstat::HistoAxis::min_
private
unsigned npstat::HistoAxis::nBins_
private