CMS 3D CMS Logo

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

#include <UniformAxis.h>

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=nullptr)
 
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 = nullptr 
)

Definition at line 13 of file UniformAxis.cc.

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

14  : min_(min), max_(max), label_(label ? label : ""), npt_(nCoords) {
15  if (!(npt_ > 1U && npt_ < UINT_MAX / 2U - 1U))
17  "In npstat::UniformAxis constructor: "
18  "number of points is out of range");
19  if (min_ > max_)
21  bw_ = (max_ - min_) / (npt_ - 1U);
22  if (max_ == min_)
24  "In npstat::UniformAxis constructor: "
25  "minimum and maximum must be distinct");
26  }
unsigned nCoords() const
Definition: UniformAxis.h:33
double max() const
Definition: UniformAxis.h:35
const std::string & label() const
Definition: UniformAxis.h:36
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
std::string label_
Definition: UniformAxis.h:85
double min() const
Definition: UniformAxis.h:34
npstat::UniformAxis::UniformAxis ( )
inlineprivate

Definition at line 88 of file UniformAxis.h.

Referenced by read().

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

Member Function Documentation

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

Definition at line 74 of file UniformAxis.h.

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

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

Definition at line 77 of file UniformAxis.h.

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

Definition at line 74 of file UniformAxis.cc.

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

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

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

Definition at line 64 of file UniformAxis.cc.

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

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

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

Definition at line 28 of file UniformAxis.cc.

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

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

28  {
29  if (x <= min_)
30  return std::pair<unsigned, double>(0U, 1.0);
31  else if (x >= max_)
32  return std::pair<unsigned, double>(npt_ - 2U, 0.0);
33  else {
34  unsigned binnum = static_cast<unsigned>(floor((x - min_) / bw_));
35  if (binnum > npt_ - 2U)
36  binnum = npt_ - 2U;
37  double w = binnum + 1.0 - (x - min_) / bw_;
38  if (w < 0.0)
39  w = 0.0;
40  else if (w > 1.0)
41  w = 1.0;
42  return std::pair<unsigned, double>(binnum, w);
43  }
44  }
const double w
Definition: UKUtility.cc:23
double npstat::UniformAxis::intervalWidth ( unsigned  ) const
inline

Definition at line 62 of file UniformAxis.h.

References bw_.

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

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

Definition at line 83 of file UniformAxis.cc.

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

83  {
84  return closeWithinTolerance(min_, r.min_, tol) && closeWithinTolerance(max_, r.max_, tol) && label_ == r.label_ &&
85  npt_ == r.npt_;
86  }
bool closeWithinTolerance(const double &a, const double &b, const double &tol)
std::string label_
Definition: UniformAxis.h:85
bool npstat::UniformAxis::isUniform ( ) const
inline

Definition at line 60 of file UniformAxis.h.

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

Definition at line 36 of file UniformAxis.h.

References label_.

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

36 { return label_; }
std::string label_
Definition: UniformAxis.h:85
double npstat::UniformAxis::length ( ) const
inline

Definition at line 59 of file UniformAxis.h.

References max_, and min_.

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

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

Definition at line 46 of file UniformAxis.cc.

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

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

46  {
47  if (x <= min_)
48  return std::pair<unsigned, double>(0U, 1.0 - (x - min_) / bw_);
49  else if (x >= max_)
50  return std::pair<unsigned, double>(npt_ - 2U, (max_ - x) / bw_);
51  else {
52  unsigned binnum = static_cast<unsigned>(floor((x - min_) / bw_));
53  if (binnum > npt_ - 2U)
54  binnum = npt_ - 2U;
55  double w = binnum + 1.0 - (x - min_) / bw_;
56  if (w < 0.0)
57  w = 0.0;
58  else if (w > 1.0)
59  w = 1.0;
60  return std::pair<unsigned, double>(binnum, w);
61  }
62  }
const double w
Definition: UKUtility.cc:23
double npstat::UniformAxis::max ( ) const
inline

Definition at line 35 of file UniformAxis.h.

References max_.

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

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

Definition at line 34 of file UniformAxis.h.

References min_.

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

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

Definition at line 33 of file UniformAxis.h.

References npt_.

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

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

Definition at line 61 of file UniformAxis.h.

References npt_.

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

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

Definition at line 65 of file UniformAxis.h.

References alignCSCRings::r.

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

Definition at line 88 of file UniformAxis.cc.

References label_, max_, min_, and npt_.

88  {
89  return min_ == r.min_ && max_ == r.max_ && label_ == r.label_ && npt_ == r.npt_;
90  }
std::string label_
Definition: UniformAxis.h:85
UniformAxis * npstat::UniformAxis::read ( const gs::ClassId &  id,
std::istream &  in 
)
static

Definition at line 100 of file UniformAxis.cc.

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

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

100  {
101  static const gs::ClassId current(gs::ClassId::makeId<UniformAxis>());
102  current.ensureSameId(id);
103 
104  double min = 0.0, max = 0.0;
106  unsigned nBins = 0;
107 
108  gs::read_pod(in, &min);
109  gs::read_pod(in, &max);
110  gs::read_pod(in, &label);
111  gs::read_pod(in, &nBins);
112 
113  if (!in.fail())
114  return new UniformAxis(nBins, min, max, label.c_str());
115  else
116  throw gs::IOReadFailure(
117  "In npstat::UniformAxis::read: "
118  "input stream failure");
119  }
double max() const
Definition: UniformAxis.h:35
const std::string & label() const
Definition: UniformAxis.h:36
double min() const
Definition: UniformAxis.h:34
void npstat::UniformAxis::setLabel ( const char *  newlabel)
inline

Definition at line 71 of file UniformAxis.h.

References label_.

Referenced by SequenceTypes.DummyModule::__init__(), SequenceTypes.DummyBooleanModule::__init__(), and npstat::DualAxis::setLabel().

71 { label_ = newlabel ? newlabel : ""; }
std::string label_
Definition: UniformAxis.h:85
bool npstat::UniformAxis::usesLogSpace ( ) const
inline

Definition at line 37 of file UniformAxis.h.

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

37 { return false; }
static unsigned npstat::UniformAxis::version ( )
inlinestatic

Definition at line 78 of file UniformAxis.h.

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

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

Definition at line 92 of file UniformAxis.cc.

References label_, max_, min_, and npt_.

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

92  {
93  gs::write_pod(of, min_);
94  gs::write_pod(of, max_);
95  gs::write_pod(of, label_);
96  gs::write_pod(of, npt_);
97  return !of.fail();
98  }
tuple of
Definition: haddnano.py:40
std::string label_
Definition: UniformAxis.h:85

Member Data Documentation

double npstat::UniformAxis::bw_
private
std::string npstat::UniformAxis::label_
private
double npstat::UniformAxis::max_
private
double npstat::UniformAxis::min_
private
unsigned npstat::UniformAxis::npt_
private