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
 
HistoAxis rebin (unsigned newBins) 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:134
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
double max() const
Definition: HistoAxis.h:43
unsigned nBins_
Definition: HistoAxis.h:135
double min() const
Definition: HistoAxis.h:42
npstat::HistoAxis::HistoAxis ( )
inlineprivate

Definition at line 157 of file HistoAxis.h.

Referenced by read(), and rebin().

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

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 51 of file HistoAxis.cc.

References bw_, max_, min_, and nBins_.

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

52  {
53  if (bw_)
54  {
55  int binnum = static_cast<int>(floor((x - min_)/bw_));
56  if (x >= max_)
57  {
58  if (binnum < static_cast<int>(nBins_))
59  binnum = nBins_;
60  }
61  else
62  {
63  if (binnum >= static_cast<int>(nBins_))
64  binnum = nBins_ - 1U;
65  }
66  return binnum;
67  }
68  else
69  {
70  if (x < min_)
71  return -1;
72  else
73  return nBins_;
74  }
75  }
unsigned nBins_
Definition: HistoAxis.h:135
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 90 of file HistoAxis.cc.

References newFWLiteAna::base, bw_, and min_.

91  {
92  if (!bw_) throw npstat::NpstatDomainError(
93  "In npstat::HistoAxis::binNumberMapper: "
94  "bin width is zero. Mapper can not be constructed.");
95  const double base = mapLeftEdgeTo0 ? min_/bw_ : min_/bw_ + 0.5;
96  return LinearMapper1d(1.0/bw_, -base);
97  }
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 122 of file HistoAxis.h.

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

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

Definition at line 126 of file HistoAxis.h.

126 {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 77 of file HistoAxis.cc.

References bw_, max_, min_, and nBins_.

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

78  {
79  if (x <= min_)
80  return 0U;
81  else if (bw_ && x < max_)
82  {
83  const unsigned binnum = static_cast<unsigned>(floor((x-min_)/bw_));
84  if (binnum < nBins_)
85  return binnum;
86  }
87  return nBins_ - 1U;
88  }
unsigned nBins_
Definition: HistoAxis.h:135
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);}
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 30 of file HistoAxis.cc.

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

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

31  {
32  return closeWithinTolerance(min_, r.min_, tol) &&
33  closeWithinTolerance(max_, r.max_, tol) &&
34  label_ == r.label_ &&
35  nBins_ == r.nBins_;
36  }
bool closeWithinTolerance(const double &a, const double &b, const double &tol)
std::string label_
Definition: HistoAxis.h:134
unsigned nBins_
Definition: HistoAxis.h:135
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 99 of file HistoAxis.cc.

References bw_, max_, and min_.

100  {
101  if (!bw_) throw npstat::NpstatDomainError(
102  "In npstat::HistoAxis::kernelScanMapper: "
103  "bin width is zero. Mapper can not be constructed.");
104  double range = max_ - min_;
105  if (doubleRange)
106  range *= 2.0;
107  return CircularMapper1d(bw_, 0.0, range);
108  }
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:134
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:135
bool npstat::HistoAxis::operator!= ( const HistoAxis r) const

Definition at line 46 of file HistoAxis.cc.

References alignCSCRings::r.

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

Definition at line 38 of file HistoAxis.cc.

References label_, max_, min_, and nBins_.

39  {
40  return min_ == r.min_ &&
41  max_ == r.max_ &&
42  label_ == r.label_ &&
43  nBins_ == r.nBins_;
44  }
std::string label_
Definition: HistoAxis.h:134
unsigned nBins_
Definition: HistoAxis.h:135
unsigned npstat::HistoAxis::overflowIndex ( const double  x,
unsigned *  binNumber 
) const
inlineprivate

Definition at line 140 of file HistoAxis.h.

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

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

142  {
143  if (x < min_)
144  return 0U;
145  else if (x >= max_)
146  return 2U;
147  else
148  {
149  const unsigned bin = static_cast<unsigned>((x - min_)/bw_);
150  *binNumber = bin >= nBins_ ? nBins_ - 1U : bin;
151  return 1U;
152  }
153  }
int binNumber(double x) const
Definition: HistoAxis.cc:51
unsigned nBins_
Definition: HistoAxis.h:135
unsigned npstat::HistoAxis::overflowIndexWeighted ( double  x,
unsigned *  binNumber,
double *  weight 
) const
private

Definition at line 110 of file HistoAxis.cc.

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

112  {
113  if (x < min_)
114  return 0U;
115  else if (x >= max_)
116  return 2U;
117  else
118  {
119  if (nBins_ <= 1U) throw npstat::NpstatInvalidArgument(
120  "In npstat::HistoAxis::overflowIndexWeighted: "
121  "must have more than one bin");
122  const double dbin = (x - min_)/bw_;
123  if (dbin <= 0.5)
124  {
125  *binNumber = 0;
126  *weight = 1.0;
127  }
128  else if (dbin >= nBins_ - 0.5)
129  {
130  *binNumber = nBins_ - 2;
131  *weight = 0.0;
132  }
133  else
134  {
135  const unsigned bin = static_cast<unsigned>(dbin - 0.5);
136  *binNumber = bin >= nBins_ - 1U ? nBins_ - 2U : bin;
137  *weight = 1.0 - (dbin - 0.5 - *binNumber);
138  }
139  return 1U;
140  }
141  }
int binNumber(double x) const
Definition: HistoAxis.cc:51
unsigned nBins_
Definition: HistoAxis.h:135
HistoAxis * npstat::HistoAxis::read ( const gs::ClassId &  id,
std::istream &  in 
)
static

Definition at line 152 of file HistoAxis.cc.

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

Referenced by edmIntegrityCheck.PublishToFileSystem::get(), and npstat::DualHistoAxis::read().

153  {
154  static const gs::ClassId current(gs::ClassId::makeId<HistoAxis>());
155  current.ensureSameId(id);
156 
157  double min = 0.0, max = 0.0;
159  unsigned nBins = 0;
160 
161  gs::read_pod(in, &min);
162  gs::read_pod(in, &max);
163  gs::read_pod(in, &label);
164  gs::read_pod(in, &nBins);
165 
166  if (!in.fail())
167  return new HistoAxis(nBins, min, max, label.c_str());
168  else
169  throw gs::IOReadFailure("In npstat::HistoAxis::read: "
170  "input stream failure");
171  }
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
HistoAxis npstat::HistoAxis::rebin ( unsigned  newBins) const

Return rebinned axis

Definition at line 25 of file HistoAxis.cc.

References HistoAxis(), label_, max_, and min_.

26  {
27  return HistoAxis(nbins, min_, max_, label_.c_str());
28  }
std::string label_
Definition: HistoAxis.h:134
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:134
static unsigned npstat::HistoAxis::version ( )
inlinestatic

Definition at line 127 of file HistoAxis.h.

Referenced by validation.Sample::datasetpattern(), and validation.Sample::filename().

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

Definition at line 143 of file HistoAxis.cc.

References label_, max_, min_, and nBins_.

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

144  {
145  gs::write_pod(of, min_);
146  gs::write_pod(of, max_);
147  gs::write_pod(of, label_);
148  gs::write_pod(of, nBins_);
149  return !of.fail();
150  }
std::string label_
Definition: HistoAxis.h:134
unsigned nBins_
Definition: HistoAxis.h:135

Friends And Related Function Documentation

friend class DualHistoAxis
friend

Definition at line 138 of file HistoAxis.h.

template<typename Numeric , class Axis >
friend class HistoND
friend

Definition at line 137 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