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

Definition at line 13 of file UniformAxis.cc.

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

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

Definition at line 86 of file UniformAxis.h.

Referenced by read().

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

Member Function Documentation

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

Definition at line 78 of file UniformAxis.h.

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

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

Definition at line 81 of file UniformAxis.h.

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

Definition at line 81 of file UniformAxis.cc.

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

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

82  {
83  if (i >= npt_)
85  "In npstat::UniformAxis::coordinate: index out of range");
86  if (i == npt_ - 1U)
87  return max_;
88  else
89  return min_ + bw_*i;
90  }
int i
Definition: DBlmapReader.cc:9
std::vector< double > npstat::UniformAxis::coords ( ) const

Definition at line 70 of file UniformAxis.cc.

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

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

71  {
72  std::vector<double> vec;
73  vec.reserve(npt_);
74  const unsigned nptm1 = npt_ - 1U;
75  for (unsigned i=0; i<nptm1; ++i)
76  vec.push_back(min_ + bw_*i);
77  vec.push_back(max_);
78  return vec;
79  }
int i
Definition: DBlmapReader.cc:9
std::pair< unsigned, double > npstat::UniformAxis::getInterval ( double  coordinate) const

Definition at line 30 of file UniformAxis.cc.

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

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

31  {
32  if (x <= min_)
33  return std::pair<unsigned,double>(0U, 1.0);
34  else if (x >= max_)
35  return std::pair<unsigned,double>(npt_ - 2U, 0.0);
36  else
37  {
38  unsigned binnum = static_cast<unsigned>(floor((x - min_)/bw_));
39  if (binnum > npt_ - 2U)
40  binnum = npt_ - 2U;
41  double w = binnum + 1.0 - (x - min_)/bw_;
42  if (w < 0.0)
43  w = 0.0;
44  else if (w > 1.0)
45  w = 1.0;
46  return std::pair<unsigned,double>(binnum, w);
47  }
48  }
T w() const
Definition: DDAxes.h:10
double npstat::UniformAxis::intervalWidth ( unsigned  ) const
inline

Definition at line 64 of file UniformAxis.h.

References bw_.

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

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

Definition at line 92 of file UniformAxis.cc.

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

93  {
94  return closeWithinTolerance(min_, r.min_, tol) &&
95  closeWithinTolerance(max_, r.max_, tol) &&
96  label_ == r.label_ &&
97  npt_ == r.npt_;
98  }
bool closeWithinTolerance(const double &a, const double &b, const double &tol)
std::string label_
Definition: UniformAxis.h:91
bool npstat::UniformAxis::isUniform ( ) const
inline

Definition at line 62 of file UniformAxis.h.

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

Definition at line 38 of file UniformAxis.h.

References label_.

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

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

Definition at line 61 of file UniformAxis.h.

References max_, and min_.

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

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

Definition at line 50 of file UniformAxis.cc.

References bw_, max_, min_, npt_, w(), and x.

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

51  {
52  if (x <= min_)
53  return std::pair<unsigned,double>(0U, 1.0 - (x - min_)/bw_);
54  else if (x >= max_)
55  return std::pair<unsigned,double>(npt_ - 2U, (max_ - x)/bw_);
56  else
57  {
58  unsigned binnum = static_cast<unsigned>(floor((x - min_)/bw_));
59  if (binnum > npt_ - 2U)
60  binnum = npt_ - 2U;
61  double w = binnum + 1.0 - (x - min_)/bw_;
62  if (w < 0.0)
63  w = 0.0;
64  else if (w > 1.0)
65  w = 1.0;
66  return std::pair<unsigned,double>(binnum, w);
67  }
68  }
T w() const
Definition: DDAxes.h:10
double npstat::UniformAxis::max ( ) const
inline

Definition at line 37 of file UniformAxis.h.

References max_.

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

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

Definition at line 36 of file UniformAxis.h.

References min_.

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

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

Definition at line 35 of file UniformAxis.h.

References npt_.

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

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

Definition at line 63 of file UniformAxis.h.

References npt_.

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

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

Definition at line 67 of file UniformAxis.h.

References alignCSCRings::r.

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

Definition at line 100 of file UniformAxis.cc.

References label_, max_, min_, and npt_.

101  {
102  return min_ == r.min_ &&
103  max_ == r.max_ &&
104  label_ == r.label_ &&
105  npt_ == r.npt_;
106  }
std::string label_
Definition: UniformAxis.h:91
UniformAxis * npstat::UniformAxis::read ( const gs::ClassId &  id,
std::istream &  in 
)
static

Definition at line 117 of file UniformAxis.cc.

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

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

118  {
119  static const gs::ClassId current(gs::ClassId::makeId<UniformAxis>());
120  current.ensureSameId(id);
121 
122  double min = 0.0, max = 0.0;
124  unsigned nBins = 0;
125 
126  gs::read_pod(in, &min);
127  gs::read_pod(in, &max);
128  gs::read_pod(in, &label);
129  gs::read_pod(in, &nBins);
130 
131  if (!in.fail())
132  return new UniformAxis(nBins, min, max, label.c_str());
133  else
134  throw gs::IOReadFailure("In npstat::UniformAxis::read: "
135  "input stream failure");
136  }
double max() const
Definition: UniformAxis.h:37
const std::string & label() const
Definition: UniformAxis.h:38
double min() const
Definition: UniformAxis.h:36
void npstat::UniformAxis::setLabel ( const char *  newlabel)
inline

Definition at line 74 of file UniformAxis.h.

References label_.

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

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

Definition at line 39 of file UniformAxis.h.

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

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

Definition at line 82 of file UniformAxis.h.

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

Definition at line 108 of file UniformAxis.cc.

References label_, max_, min_, and npt_.

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

109  {
110  gs::write_pod(of, min_);
111  gs::write_pod(of, max_);
112  gs::write_pod(of, label_);
113  gs::write_pod(of, npt_);
114  return !of.fail();
115  }
std::string label_
Definition: UniformAxis.h:91

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