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
 
double binWidth (const int=0) const
 
gs::ClassId classId () 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)
 
Interval< double > interval () const
 
bool isClose (const HistoAxis &, double tol) const
 
bool isUniform () const
 
CircularMapper1d kernelScanMapper (bool doubleRange) const
 
const std::string & label () const
 
double leftBinEdge (const int binNum) const
 
double length () const
 
double max () const
 
double min () const
 
unsigned nBins () 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)
 
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.

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  }

References bw_, max_, min_, nBins_, std::swap(), and mitigatedMETSequence_cff::U.

◆ HistoAxis() [2/2]

npstat::HistoAxis::HistoAxis ( )
inlineprivate

Definition at line 149 of file HistoAxis.h.

149 : min_(0.0), max_(0.0), bw_(0.0), nBins_(0) {}

Referenced by read(), and rebin().

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.

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

References bw_, and min_.

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

◆ 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.

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

References bw_, and min_.

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

◆ 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.

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  }

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

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

◆ 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.

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  }

References newFWLiteAna::base, bw_, and min_.

◆ binWidth()

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

Definition at line 46 of file HistoAxis.h.

46 { return bw_; }

References bw_.

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

◆ classId()

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

Method related to "geners" I/O

Definition at line 117 of file HistoAxis.h.

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

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

◆ 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.

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  }

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

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

◆ 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.

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

References bw_, and min_.

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

◆ interval()

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

Definition at line 43 of file HistoAxis.h.

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

References max_, and min_.

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

◆ 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.

26  {
27  return closeWithinTolerance(min_, r.min_, tol) && closeWithinTolerance(max_, r.max_, tol) && label_ == r.label_ &&
28  nBins_ == r.nBins_;
29  }

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

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

◆ 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.

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  }

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

◆ label()

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

Definition at line 47 of file HistoAxis.h.

47 { return label_; }

References label_.

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

◆ 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.

55 { return min_ + binNum * bw_; }

References bw_, and min_.

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

◆ length()

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

Definition at line 44 of file HistoAxis.h.

44 { return max_ - min_; }

References max_, and min_.

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

◆ max()

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

Definition at line 42 of file HistoAxis.h.

42 { return max_; }

References max_.

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

◆ min()

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

Examine axis properties

Definition at line 41 of file HistoAxis.h.

41 { return min_; }

References min_.

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

◆ nBins()

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

Definition at line 45 of file HistoAxis.h.

45 { return nBins_; }

References nBins_.

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

◆ operator!=()

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

Definition at line 35 of file HistoAxis.cc.

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

References alignCSCRings::r.

◆ operator==()

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

Definition at line 31 of file HistoAxis.cc.

31  {
32  return min_ == r.min_ && max_ == r.max_ && label_ == r.label_ && nBins_ == r.nBins_;
33  }

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

◆ overflowIndex()

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

Definition at line 136 of file HistoAxis.h.

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  }

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

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

◆ overflowIndexWeighted()

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

Definition at line 87 of file HistoAxis.cc.

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  }

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

◆ read()

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

Definition at line 121 of file HistoAxis.cc.

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  }

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

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

◆ rebin()

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

Return rebinned axis

Definition at line 24 of file HistoAxis.cc.

24 { return HistoAxis(nbins, min_, max_, label_.c_str()); }

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

◆ 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.

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

References bw_, and min_.

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

◆ setLabel()

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

Change the axis label

Definition at line 66 of file HistoAxis.h.

66 { label_ = newlabel ? newlabel : ""; }

References label_.

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

◆ version()

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

Definition at line 122 of file HistoAxis.h.

122 { return 1; }

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

◆ write()

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

Definition at line 113 of file HistoAxis.cc.

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  }

References label_, max_, min_, and nBins_.

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

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
FastTimerService_cff.range
range
Definition: FastTimerService_cff.py:34
npstat::HistoAxis::nBins
unsigned nBins() const
Definition: HistoAxis.h:45
npstat::HistoAxis::min
double min() const
Definition: HistoAxis.h:41
DDAxes::x
std::swap
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
Definition: DataFrameContainer.h:209
LaserClient_cfi.nbins
nbins
Definition: LaserClient_cfi.py:51
npstat::NpstatInvalidArgument
Definition: NpstatException.h:38
npstat::HistoAxis::min_
double min_
Definition: HistoAxis.h:126
npstat::HistoAxis::max
double max() const
Definition: HistoAxis.h:42
npstat::HistoAxis::label_
std::string label_
Definition: HistoAxis.h:129
mitigatedMETSequence_cff.U
U
Definition: mitigatedMETSequence_cff.py:36
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
npstat::HistoAxis::label
const std::string & label() const
Definition: HistoAxis.h:47
npstat::HistoAxis::nBins_
unsigned nBins_
Definition: HistoAxis.h:130
npstat::HistoAxis::max_
double max_
Definition: HistoAxis.h:127
recoMuon::in
Definition: RecoMuonEnumerators.h:6
npstat::NpstatDomainError
Definition: NpstatException.h:54
alignCSCRings.r
r
Definition: alignCSCRings.py:93
newFWLiteAna.bin
bin
Definition: newFWLiteAna.py:161
npstat::HistoAxis::bw_
double bw_
Definition: HistoAxis.h:128
npstat::closeWithinTolerance
bool closeWithinTolerance(const double &a, const double &b, const double &tol)
Definition: closeWithinTolerance.h:25
newFWLiteAna.base
base
Definition: newFWLiteAna.py:92
weight
Definition: weight.py:1
npstat::HistoAxis::HistoAxis
HistoAxis()
Definition: HistoAxis.h:149
npstat::HistoAxis::binNumber
int binNumber(double x) const
Definition: HistoAxis.cc:37