CMS 3D CMS Logo

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=nullptr)
 
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 31 of file HistoAxis.h.

Constructor & Destructor Documentation

◆ HistoAxis() [1/2]

npstat::HistoAxis::HistoAxis ( unsigned  nBins,
double  min,
double  max,
const char *  label = nullptr 
)

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

14  : min_(min), max_(max), label_(label ? label : ""), nBins_(nbins) {
15  if (!(nBins_ && nBins_ < UINT_MAX / 2U - 1U))
17  "In npstat::HistoAxis constructor: "
18  "number of bins is out of range");
19  if (min_ > max_)
21  bw_ = (max_ - min_) / nBins_;
22  }
const std::string & label() const
Definition: HistoAxis.h:47
std::string label_
Definition: HistoAxis.h:129
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
double min() const
Definition: HistoAxis.h:41
double max() const
Definition: HistoAxis.h:42
unsigned nBins_
Definition: HistoAxis.h:130

◆ HistoAxis() [2/2]

npstat::HistoAxis::HistoAxis ( )
inlineprivate

Definition at line 149 of file HistoAxis.h.

Referenced by read(), and rebin().

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

Member Function Documentation

◆ binCenter()

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

Return the coordinate of the given bin center

Definition at line 52 of file HistoAxis.h.

References bw_, and min_.

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

52 { return min_ + (binNum + 0.5) * bw_; }

◆ binInterval()

Interval<double> npstat::HistoAxis::binInterval ( const int  binNum) const
inline

Return the coordinate interval occupied by the given bin

Definition at line 61 of file HistoAxis.h.

References bw_, and min_.

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

61  {
62  return Interval<double>(min_ + binNum * bw_, min_ + (binNum + 1) * bw_);
63  }

◆ binNumber()

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

References bw_, max_, min_, nBins_, mitigatedMETSequence_cff::U, and x.

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

37  {
38  if (bw_) {
39  int binnum = static_cast<int>(floor((x - min_) / bw_));
40  if (x >= max_) {
41  if (binnum < static_cast<int>(nBins_))
42  binnum = nBins_;
43  } else {
44  if (binnum >= static_cast<int>(nBins_))
45  binnum = nBins_ - 1U;
46  }
47  return binnum;
48  } else {
49  if (x < min_)
50  return -1;
51  else
52  return nBins_;
53  }
54  }
unsigned nBins_
Definition: HistoAxis.h:130

◆ binNumberMapper()

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

References newFWLiteAna::base, bw_, and min_.

67  {
68  if (!bw_)
70  "In npstat::HistoAxis::binNumberMapper: "
71  "bin width is zero. Mapper can not be constructed.");
72  const double base = mapLeftEdgeTo0 ? min_ / bw_ : min_ / bw_ + 0.5;
73  return LinearMapper1d(1.0 / bw_, -base);
74  }
base
Main Program
Definition: newFWLiteAna.py:92

◆ binWidth()

double npstat::HistoAxis::binWidth ( const int  = 0) const
inline

Definition at line 46 of file HistoAxis.h.

References bw_.

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

46 { return bw_; }

◆ classId()

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

Method related to "geners" I/O

Definition at line 117 of file HistoAxis.h.

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

117 { return gs::ClassId(*this); }

◆ classname()

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

Definition at line 121 of file HistoAxis.h.

121 { return "npstat::HistoAxis"; }

◆ closestValidBin()

unsigned npstat::HistoAxis::closestValidBin ( double  x) const

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

Definition at line 56 of file HistoAxis.cc.

References bw_, max_, min_, nBins_, mitigatedMETSequence_cff::U, and x.

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

56  {
57  if (x <= min_)
58  return 0U;
59  else if (bw_ && x < max_) {
60  const unsigned binnum = static_cast<unsigned>(floor((x - min_) / bw_));
61  if (binnum < nBins_)
62  return binnum;
63  }
64  return nBins_ - 1U;
65  }
unsigned nBins_
Definition: HistoAxis.h:130

◆ fltBinNumber()

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 94 of file HistoAxis.h.

References bw_, min_, and x.

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

94  {
95  return (x - min_) / bw_ - (mapLeftEdgeTo0 ? 0.0 : 0.5);
96  }

◆ interval()

Interval<double> npstat::HistoAxis::interval ( ) const
inline

Definition at line 43 of file HistoAxis.h.

References max_, and min_.

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

43 { return Interval<double>(min_, max_); }

◆ isClose()

bool npstat::HistoAxis::isClose ( const HistoAxis r,
double  tol 
) const

Comparison of axis coordinates within given tolerance

Definition at line 26 of file HistoAxis.cc.

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

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

26  {
27  return closeWithinTolerance(min_, r.min_, tol) && closeWithinTolerance(max_, r.max_, tol) && label_ == r.label_ &&
28  nBins_ == r.nBins_;
29  }
bool closeWithinTolerance(const double &a, const double &b, const double &tol)
std::string label_
Definition: HistoAxis.h:129
unsigned nBins_
Definition: HistoAxis.h:130

◆ isUniform()

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

Definition at line 48 of file HistoAxis.h.

48 { return true; }

◆ kernelScanMapper()

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

References bw_, max_, min_, and FastTimerService_cff::range.

76  {
77  if (!bw_)
79  "In npstat::HistoAxis::kernelScanMapper: "
80  "bin width is zero. Mapper can not be constructed.");
81  double range = max_ - min_;
82  if (doubleRange)
83  range *= 2.0;
84  return CircularMapper1d(bw_, 0.0, range);
85  }

◆ label()

const std::string& npstat::HistoAxis::label ( ) const
inline

Definition at line 47 of file HistoAxis.h.

References label_.

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

47 { return label_; }
std::string label_
Definition: HistoAxis.h:129

◆ leftBinEdge()

double npstat::HistoAxis::leftBinEdge ( const int  binNum) const
inline

Return the coordinate of the given bin left edge

Definition at line 55 of file HistoAxis.h.

References bw_, and min_.

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

55 { return min_ + binNum * bw_; }

◆ length()

double npstat::HistoAxis::length ( ) const
inline

Definition at line 44 of file HistoAxis.h.

References max_, and min_.

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

44 { return max_ - min_; }

◆ max()

double npstat::HistoAxis::max ( ) const
inline

Definition at line 42 of file HistoAxis.h.

References max_.

Referenced by npstat::DualHistoAxis::max(), and read().

42 { return max_; }

◆ min()

double npstat::HistoAxis::min ( ) const
inline

Examine axis properties

Definition at line 41 of file HistoAxis.h.

References min_.

Referenced by npstat::DualHistoAxis::min(), and read().

41 { return min_; }

◆ nBins()

unsigned npstat::HistoAxis::nBins ( ) const
inline

Definition at line 45 of file HistoAxis.h.

References nBins_.

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

45 { return nBins_; }
unsigned nBins_
Definition: HistoAxis.h:130

◆ operator!=()

bool npstat::HistoAxis::operator!= ( const HistoAxis r) const

Definition at line 35 of file HistoAxis.cc.

References alignCSCRings::r.

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

◆ operator==()

bool npstat::HistoAxis::operator== ( const HistoAxis r) const

Definition at line 31 of file HistoAxis.cc.

References label_, max_, min_, nBins_, and alignCSCRings::r.

31  {
32  return min_ == r.min_ && max_ == r.max_ && label_ == r.label_ && nBins_ == r.nBins_;
33  }
std::string label_
Definition: HistoAxis.h:129
unsigned nBins_
Definition: HistoAxis.h:130

◆ overflowIndex()

unsigned npstat::HistoAxis::overflowIndex ( const double  x,
unsigned *  binNumber 
) const
inlineprivate

Definition at line 136 of file HistoAxis.h.

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

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

136  {
137  if (x < min_)
138  return 0U;
139  else if (x >= max_)
140  return 2U;
141  else {
142  const unsigned bin = static_cast<unsigned>((x - min_) / bw_);
143  *binNumber = bin >= nBins_ ? nBins_ - 1U : bin;
144  return 1U;
145  }
146  }
unsigned nBins_
Definition: HistoAxis.h:130
int binNumber(double x) const
Definition: HistoAxis.cc:37

◆ overflowIndexWeighted()

unsigned npstat::HistoAxis::overflowIndexWeighted ( double  x,
unsigned *  binNumber,
double *  weight 
) const
private

Definition at line 87 of file HistoAxis.cc.

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

87  {
88  if (x < min_)
89  return 0U;
90  else if (x >= max_)
91  return 2U;
92  else {
93  if (nBins_ <= 1U)
95  "In npstat::HistoAxis::overflowIndexWeighted: "
96  "must have more than one bin");
97  const double dbin = (x - min_) / bw_;
98  if (dbin <= 0.5) {
99  *binNumber = 0;
100  *weight = 1.0;
101  } else if (dbin >= nBins_ - 0.5) {
102  *binNumber = nBins_ - 2;
103  *weight = 0.0;
104  } else {
105  const unsigned bin = static_cast<unsigned>(dbin - 0.5);
106  *binNumber = bin >= nBins_ - 1U ? nBins_ - 2U : bin;
107  *weight = 1.0 - (dbin - 0.5 - *binNumber);
108  }
109  return 1U;
110  }
111  }
Definition: weight.py:1
unsigned nBins_
Definition: HistoAxis.h:130
int binNumber(double x) const
Definition: HistoAxis.cc:37

◆ read()

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

Definition at line 121 of file HistoAxis.cc.

References HistoAxis(), recoMuon::in, label(), max(), min(), nBins(), and AlCaHLTBitMon_QueryRunRegistry::string.

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

121  {
122  static const gs::ClassId current(gs::ClassId::makeId<HistoAxis>());
123  current.ensureSameId(id);
124 
125  double min = 0.0, max = 0.0;
127  unsigned nBins = 0;
128 
129  gs::read_pod(in, &min);
130  gs::read_pod(in, &max);
131  gs::read_pod(in, &label);
132  gs::read_pod(in, &nBins);
133 
134  if (!in.fail())
135  return new HistoAxis(nBins, min, max, label.c_str());
136  else
137  throw gs::IOReadFailure(
138  "In npstat::HistoAxis::read: "
139  "input stream failure");
140  }
const std::string & label() const
Definition: HistoAxis.h:47
double min() const
Definition: HistoAxis.h:41
unsigned nBins() const
Definition: HistoAxis.h:45
double max() const
Definition: HistoAxis.h:42

◆ rebin()

HistoAxis npstat::HistoAxis::rebin ( unsigned  newBins) const

Return rebinned axis

Definition at line 24 of file HistoAxis.cc.

References HistoAxis(), label_, max_, min_, and LaserClient_cfi::nbins.

24 { return HistoAxis(nbins, min_, max_, label_.c_str()); }
std::string label_
Definition: HistoAxis.h:129

◆ rightBinEdge()

double npstat::HistoAxis::rightBinEdge ( const int  binNum) const
inline

Return the coordinate of the given bin right edge

Definition at line 58 of file HistoAxis.h.

References bw_, and min_.

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

58 { return min_ + (binNum + 1) * bw_; }

◆ setLabel()

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

Change the axis label

Definition at line 66 of file HistoAxis.h.

References label_.

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

66 { label_ = newlabel ? newlabel : ""; }
std::string label_
Definition: HistoAxis.h:129

◆ version()

static unsigned npstat::HistoAxis::version ( )
inlinestatic

Definition at line 122 of file HistoAxis.h.

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

122 { return 1; }

◆ write()

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

Definition at line 113 of file HistoAxis.cc.

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

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

113  {
114  gs::write_pod(of, min_);
115  gs::write_pod(of, max_);
116  gs::write_pod(of, label_);
117  gs::write_pod(of, nBins_);
118  return !of.fail();
119  }
std::string label_
Definition: HistoAxis.h:129
unsigned nBins_
Definition: HistoAxis.h:130

Friends And Related Function Documentation

◆ DualHistoAxis

friend class DualHistoAxis
friend

Definition at line 134 of file HistoAxis.h.

◆ HistoND

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

Definition at line 133 of file HistoAxis.h.

Member Data Documentation

◆ bw_

double npstat::HistoAxis::bw_
private

◆ label_

std::string npstat::HistoAxis::label_
private

◆ max_

double npstat::HistoAxis::max_
private

◆ min_

double npstat::HistoAxis::min_
private

◆ nBins_

unsigned npstat::HistoAxis::nBins_
private