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::NUHistoAxis Class Reference

#include <NUHistoAxis.h>

Public Member Functions

double binCenter (const int binNum) const
 
Interval< double > binInterval (const int binNum) const
 
int binNumber (double x) const
 
unsigned closestValidBin (double x) const
 
double fltBinNumber (double x, bool mapLeftEdgeTo0=true) const
 
bool isClose (const NUHistoAxis &, double tol) const
 
double leftBinEdge (const int binNum) const
 
 NUHistoAxis (const std::vector< double > &binEdges, const char *label=0)
 
bool operator!= (const NUHistoAxis &) const
 
bool operator== (const NUHistoAxis &) 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 binNum) 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 NUHistoAxisread (const gs::ClassId &id, std::istream &in)
 
static unsigned version ()
 

Private Member Functions

 NUHistoAxis ()
 
 NUHistoAxis (unsigned nBins, double min, double max, const char *label=0)
 
unsigned overflowIndex (const double x, unsigned *binNum) const
 

Private Attributes

std::vector< double > binEdges_
 
std::string label_
 
double max_
 
double min_
 
unsigned nBins_
 
bool uniform_
 

Friends

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

Detailed Description

This class can be used to create histograms with non-uniform binning

Definition at line 27 of file NUHistoAxis.h.

Constructor & Destructor Documentation

npstat::NUHistoAxis::NUHistoAxis ( const std::vector< double > &  binEdges,
const char *  label = 0 
)

The number of bin edges provided must be at least 2. Edge coordinates will be sorted internally in the increasing order. The number of bins will be less by 1 than the number of edges.

Definition at line 15 of file NUHistoAxis.cc.

References binEdges_, label_, max_, min_, nBins_, python.multivaluedict::sort(), and AlCaHLTBitMon_QueryRunRegistry::string.

17  : binEdges_(binEdges), nBins_(binEdges.size() - 1U), uniform_(false)
18  {
19  if (!(binEdges_.size() > 1U && binEdges_.size() < UINT_MAX/2U))
20  throw npstat::NpstatInvalidArgument("In npstat::NUHistoAxis constructor: "
21  "number of bin edges is out of range");
22  std::sort(binEdges_.begin(), binEdges_.end());
23  min_ = binEdges_[0];
25  if (label)
27  }
std::vector< double > binEdges_
Definition: NUHistoAxis.h:116
std::string label_
Definition: NUHistoAxis.h:117
const std::string & label() const
Definition: NUHistoAxis.h:48
npstat::NUHistoAxis::NUHistoAxis ( )
inlineprivate

Definition at line 108 of file NUHistoAxis.h.

Referenced by read().

108  : min_(0.0), max_(0.0),
109  nBins_(0), uniform_(false) {}
npstat::NUHistoAxis::NUHistoAxis ( unsigned  nBins,
double  min,
double  max,
const char *  label = 0 
)
private

Definition at line 29 of file NUHistoAxis.cc.

References binEdges_, label_, max_, min_, nBins_, AlCaHLTBitMon_QueryRunRegistry::string, and std::swap().

32  : min_(min), max_(max), nBins_(nBins), uniform_(true)
33  {
34  if (!(nBins_ && nBins_ < UINT_MAX/2U - 1U))
35  throw npstat::NpstatInvalidArgument("In npstat::NUHistoAxis constructor: "
36  "number of bins is out of range");
37  if (min_ > max_)
39  binEdges_ = EquidistantInLinearSpace(min_, max_, nBins+1U);
40  if (label)
42  }
std::vector< double > binEdges_
Definition: NUHistoAxis.h:116
double min() const
Definition: NUHistoAxis.h:40
unsigned nBins() const
Definition: NUHistoAxis.h:45
std::string label_
Definition: NUHistoAxis.h:117
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
double max() const
Definition: NUHistoAxis.h:41
const std::string & label() const
Definition: NUHistoAxis.h:48

Member Function Documentation

double npstat::NUHistoAxis::binCenter ( const int  binNum) const
inline

Return the coordinate of the given bin center

Definition at line 61 of file NUHistoAxis.h.

References binEdges_.

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

62  {return 0.5*(binEdges_.at(binNum) + binEdges_.at(binNum + 1));}
std::vector< double > binEdges_
Definition: NUHistoAxis.h:116
Interval<double> npstat::NUHistoAxis::binInterval ( const int  binNum) const
inline

Return the coordinate interval occupied by the given bin

Definition at line 65 of file NUHistoAxis.h.

References binEdges_.

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

66  {return Interval<double>(binEdges_.at(binNum),
67  binEdges_.at(binNum + 1));}
std::vector< double > binEdges_
Definition: NUHistoAxis.h:116
int npstat::NUHistoAxis::binNumber ( double  x) const

This method returns -1 for values below the lower limit and "nBins()" for values equal to or above the upper limit

Definition at line 73 of file NUHistoAxis.cc.

References binEdges_, delta, and x.

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

74  {
75  const int delta = std::upper_bound(binEdges_.begin(), binEdges_.end(), x) -
76  binEdges_.begin();
77  return delta - 1;
78  }
dbl * delta
Definition: mlp_gen.cc:36
std::vector< double > binEdges_
Definition: NUHistoAxis.h:116
Definition: DDAxes.h:10
double npstat::NUHistoAxis::binWidth ( const int  binNum) const
inline

Definition at line 46 of file NUHistoAxis.h.

References binEdges_.

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

47  {return binEdges_.at(binNum+1) - binEdges_.at(binNum);}
std::vector< double > binEdges_
Definition: NUHistoAxis.h:116
gs::ClassId npstat::NUHistoAxis::classId ( ) const
inline

Method related to "geners" I/O

Definition at line 99 of file NUHistoAxis.h.

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

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

Definition at line 103 of file NUHistoAxis.h.

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

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

Definition at line 137 of file NUHistoAxis.cc.

References binEdges_, delta, nBins_, and x.

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

138  {
139  const int delta = std::upper_bound(binEdges_.begin(), binEdges_.end(), x) -
140  binEdges_.begin();
141  int binnum = delta - 1;
142  if (binnum < 0)
143  binnum = 0;
144  else if (static_cast<unsigned>(binnum) >= nBins_)
145  binnum = nBins_ - 1U;
146  return binnum;
147  }
dbl * delta
Definition: mlp_gen.cc:36
std::vector< double > binEdges_
Definition: NUHistoAxis.h:116
Definition: DDAxes.h:10
double npstat::NUHistoAxis::fltBinNumber ( double  x,
bool  mapLeftEdgeTo0 = true 
) const

Floating point bin number given the coordinate. Useful for interpolation methods and such.

Definition at line 80 of file NUHistoAxis.cc.

References binCenter(), binEdges_, delta, nBins_, and x.

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

81  {
82  const int delta = std::upper_bound(binEdges_.begin(), binEdges_.end(), x) -
83  binEdges_.begin();
84  const int binnum = delta - 1;
85 
86  if (binnum < 0)
87  {
88  const double left = binEdges_[0];
89  const double right = binEdges_[1];
90  double bval = (x - left)/(right - left);
91  if (!mapLeftEdgeTo0)
92  bval -= 0.5;
93  if (bval < -1.0)
94  bval = -1.0;
95  return bval;
96  }
97  else if (static_cast<unsigned>(binnum) >= nBins_)
98  {
99  const double left = binEdges_[nBins_ - 1U];
100  const double right = binEdges_[nBins_];
101  double bval = nBins_ - 1U + (x - left)/(right - left);
102  if (!mapLeftEdgeTo0)
103  bval -= 0.5;
104  if (bval > static_cast<double>(nBins_))
105  bval = nBins_;
106  return bval;
107  }
108  else
109  {
110  const double left = binEdges_[binnum];
111  const double right = binEdges_[delta];
112  if (mapLeftEdgeTo0)
113  return binnum + (x - left)/(right - left);
114  else
115  {
116  // Bin center is mapped to binnum.
117  // Bin center of the next bin is mapped to binnum + 1.
118  // Bin center of the previos bin is mapped to binnum - 1.
119  const double binCenter = (left + right)/2.0;
120  if ((binnum == 0 && x <= binCenter) ||
121  (static_cast<unsigned>(binnum) == nBins_ - 1 && x >= binCenter))
122  return binnum + (x - left)/(right - left) - 0.5;
123  else if (x <= binCenter)
124  {
125  const double otherBinCenter = (left + binEdges_[binnum - 1])/2.0;
126  return binnum + (x - binCenter)/(binCenter - otherBinCenter);
127  }
128  else
129  {
130  const double otherBinCenter = (right + binEdges_[binnum + 1])/2.0;
131  return binnum + (x - binCenter)/(otherBinCenter - binCenter);
132  }
133  }
134  }
135  }
dbl * delta
Definition: mlp_gen.cc:36
std::vector< double > binEdges_
Definition: NUHistoAxis.h:116
double binCenter(const int binNum) const
Definition: NUHistoAxis.h:61
Definition: DDAxes.h:10
Interval<double> npstat::NUHistoAxis::interval ( ) const
inline

Definition at line 42 of file NUHistoAxis.h.

References max_, and min_.

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

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

Comparison of axis coordinates within given tolerance

Definition at line 44 of file NUHistoAxis.cc.

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

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

45  {
46  if (!(closeWithinTolerance(min_, r.min_, tol) &&
47  closeWithinTolerance(max_, r.max_, tol) &&
48  label_ == r.label_ &&
49  nBins_ == r.nBins_ &&
50  uniform_ == r.uniform_))
51  return false;
52  for (unsigned i=0; i<nBins_; ++i)
53  if (!closeWithinTolerance(binEdges_[i], r.binEdges_[i], tol))
54  return false;
55  return true;
56  }
std::vector< double > binEdges_
Definition: NUHistoAxis.h:116
int i
Definition: DBlmapReader.cc:9
bool closeWithinTolerance(const double &a, const double &b, const double &tol)
std::string label_
Definition: NUHistoAxis.h:117
bool npstat::NUHistoAxis::isUniform ( ) const
inline

Definition at line 49 of file NUHistoAxis.h.

References uniform_.

49 {return uniform_;}
const std::string& npstat::NUHistoAxis::label ( ) const
inline

Definition at line 48 of file NUHistoAxis.h.

References label_.

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

48 {return label_;}
std::string label_
Definition: NUHistoAxis.h:117
double npstat::NUHistoAxis::leftBinEdge ( const int  binNum) const
inline

Return the coordinate of the given bin left edge

Definition at line 53 of file NUHistoAxis.h.

References binEdges_.

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

54  {return binEdges_.at(binNum);}
std::vector< double > binEdges_
Definition: NUHistoAxis.h:116
double npstat::NUHistoAxis::length ( ) const
inline

Definition at line 44 of file NUHistoAxis.h.

References max_, and min_.

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

44 {return max_ - min_;}
double npstat::NUHistoAxis::max ( ) const
inline

Definition at line 41 of file NUHistoAxis.h.

References max_.

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

41 {return max_;}
double npstat::NUHistoAxis::min ( ) const
inline

Examine axis propoerties

Definition at line 40 of file NUHistoAxis.h.

References min_.

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

40 {return min_;}
unsigned npstat::NUHistoAxis::nBins ( ) const
inline

Definition at line 45 of file NUHistoAxis.h.

References nBins_.

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

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

Definition at line 68 of file NUHistoAxis.cc.

References alignCSCRings::r.

69  {
70  return !(*this == r);
71  }
bool npstat::NUHistoAxis::operator== ( const NUHistoAxis r) const

Definition at line 58 of file NUHistoAxis.cc.

References binEdges_, label_, max_, min_, nBins_, and uniform_.

59  {
60  return min_ == r.min_ &&
61  max_ == r.max_ &&
62  label_ == r.label_ &&
63  nBins_ == r.nBins_ &&
64  binEdges_ == r.binEdges_ &&
65  uniform_ == r.uniform_;
66  }
std::vector< double > binEdges_
Definition: NUHistoAxis.h:116
std::string label_
Definition: NUHistoAxis.h:117
unsigned npstat::NUHistoAxis::overflowIndex ( const double  x,
unsigned *  binNum 
) const
inlineprivate

Definition at line 124 of file NUHistoAxis.h.

References binNumber(), max_, and min_.

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

126  {
127  if (x < min_)
128  return 0U;
129  else if (x >= max_)
130  return 2U;
131  else
132  {
133  *binNum = binNumber(x);
134  return 1U;
135  }
136  }
int binNumber(double x) const
Definition: NUHistoAxis.cc:73
Definition: DDAxes.h:10
NUHistoAxis * npstat::NUHistoAxis::read ( const gs::ClassId &  id,
std::istream &  in 
)
static

Definition at line 158 of file NUHistoAxis.cc.

References cond::rpcobimon::current, label(), NUHistoAxis(), query::result, AlCaHLTBitMon_QueryRunRegistry::string, and uniform_.

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

159  {
160  static const gs::ClassId current(gs::ClassId::makeId<NUHistoAxis>());
161  current.ensureSameId(id);
162 
163  std::vector<double> binEdges;
165  unsigned char unif;
166  gs::read_pod_vector(in, &binEdges);
167  gs::read_pod(in, &label);
168  gs::read_pod(in, &unif);
169  if (in.fail())
170  throw gs::IOReadFailure("In npstat::UHistoAxis::read: "
171  "input stream failure");
172  NUHistoAxis* result = new NUHistoAxis(binEdges, label.c_str());
173  result->uniform_ = unif;
174  return result;
175  }
tuple result
Definition: query.py:137
const std::string & label() const
Definition: NUHistoAxis.h:48
double npstat::NUHistoAxis::rightBinEdge ( const int  binNum) const
inline

Return the coordinate of the given bin right edge

Definition at line 57 of file NUHistoAxis.h.

References binEdges_.

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

58  {return binEdges_.at(binNum + 1);}
std::vector< double > binEdges_
Definition: NUHistoAxis.h:116
void npstat::NUHistoAxis::setLabel ( const char *  newlabel)
inline

Change the axis label

Definition at line 70 of file NUHistoAxis.h.

References label_.

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

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

Definition at line 104 of file NUHistoAxis.h.

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

Definition at line 149 of file NUHistoAxis.cc.

References binEdges_, trackerHits::c, label_, and uniform_.

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

150  {
151  gs::write_pod_vector(of, binEdges_);
152  gs::write_pod(of, label_);
153  unsigned char c = uniform_;
154  gs::write_pod(of, c);
155  return !of.fail();
156  }
std::vector< double > binEdges_
Definition: NUHistoAxis.h:116
std::string label_
Definition: NUHistoAxis.h:117

Friends And Related Function Documentation

friend class DualHistoAxis
friend

Definition at line 122 of file NUHistoAxis.h.

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

Definition at line 121 of file NUHistoAxis.h.

Member Data Documentation

std::vector<double> npstat::NUHistoAxis::binEdges_
private
std::string npstat::NUHistoAxis::label_
private
double npstat::NUHistoAxis::max_
private

Definition at line 115 of file NUHistoAxis.h.

Referenced by interval(), isClose(), length(), max(), NUHistoAxis(), operator==(), and overflowIndex().

double npstat::NUHistoAxis::min_
private

Definition at line 114 of file NUHistoAxis.h.

Referenced by interval(), isClose(), length(), min(), NUHistoAxis(), operator==(), and overflowIndex().

unsigned npstat::NUHistoAxis::nBins_
private

Definition at line 118 of file NUHistoAxis.h.

Referenced by closestValidBin(), fltBinNumber(), isClose(), nBins(), NUHistoAxis(), and operator==().

bool npstat::NUHistoAxis::uniform_
private

Definition at line 119 of file NUHistoAxis.h.

Referenced by isClose(), isUniform(), operator==(), read(), and write().