CMS 3D CMS Logo

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

◆ UniformAxis() [1/2]

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_, edm::swap(), and mitigatedMETSequence_cff::U.

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  }
void swap(Association< C > &lhs, Association< C > &rhs)
Definition: Association.h:112
double min() const
Definition: UniformAxis.h:34
unsigned nCoords() const
Definition: UniformAxis.h:33
std::string label_
Definition: UniformAxis.h:85
double max() const
Definition: UniformAxis.h:35
const std::string & label() const
Definition: UniformAxis.h:36

◆ UniformAxis() [2/2]

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

◆ classId()

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); }

◆ classname()

static const char* npstat::UniformAxis::classname ( )
inlinestatic

Definition at line 77 of file UniformAxis.h.

77 { return "npstat::UniformAxis"; }

◆ coordinate()

double npstat::UniformAxis::coordinate ( unsigned  i) const

Definition at line 74 of file UniformAxis.cc.

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

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  }

◆ coords()

std::vector< double > npstat::UniformAxis::coords ( ) const

Definition at line 64 of file UniformAxis.cc.

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

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  }

◆ getInterval()

std::pair< unsigned, double > npstat::UniformAxis::getInterval ( double  coordinate) const

Definition at line 28 of file UniformAxis.cc.

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

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  }
T w() const
float x

◆ intervalWidth()

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_; }

◆ isClose()

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

◆ isUniform()

bool npstat::UniformAxis::isUniform ( ) const
inline

Definition at line 60 of file UniformAxis.h.

60 { return true; }

◆ label()

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

◆ length()

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_; }

◆ linearInterval()

std::pair< unsigned, double > npstat::UniformAxis::linearInterval ( double  coordinate) const

Definition at line 46 of file UniformAxis.cc.

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

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  }
T w() const
float x

◆ max()

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_; }

◆ min()

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_; }

◆ nCoords()

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_; }

◆ nIntervals()

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; }

◆ operator!=()

bool npstat::UniformAxis::operator!= ( const UniformAxis r) const
inline

Definition at line 65 of file UniformAxis.h.

65 { return !(*this == r); }

◆ operator==()

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

◆ read()

UniformAxis * npstat::UniformAxis::read ( const gs::ClassId &  id,
std::istream &  in 
)
static

Definition at line 100 of file UniformAxis.cc.

References recoMuon::in, label(), max(), min(), seedmultiplicitymonitor_newtracking_cfi::nBins, 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 min() const
Definition: UniformAxis.h:34
double max() const
Definition: UniformAxis.h:35
const std::string & label() const
Definition: UniformAxis.h:36

◆ setLabel()

void npstat::UniformAxis::setLabel ( const char *  newlabel)
inline

Definition at line 71 of file UniformAxis.h.

References label_.

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

71 { label_ = newlabel ? newlabel : ""; }
std::string label_
Definition: UniformAxis.h:85

◆ usesLogSpace()

bool npstat::UniformAxis::usesLogSpace ( ) const
inline

Definition at line 37 of file UniformAxis.h.

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

37 { return false; }

◆ version()

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; }

◆ write()

bool npstat::UniformAxis::write ( std::ostream &  of) const

Definition at line 92 of file UniformAxis.cc.

References label_, max_, min_, npt_, and haddnano::of.

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  }
std::string label_
Definition: UniformAxis.h:85

Member Data Documentation

◆ bw_

double npstat::UniformAxis::bw_
private

◆ label_

std::string npstat::UniformAxis::label_
private

◆ max_

double npstat::UniformAxis::max_
private

◆ min_

double npstat::UniformAxis::min_
private

◆ npt_

unsigned npstat::UniformAxis::npt_
private