CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Friends
npstat::NUHistoAxis Class Reference

#include <NUHistoAxis.h>

Public Member Functions

double binCenter (const int binNum) const
 
Interval< double > binInterval (const int binNum) const
 
int binNumber (double x) const
 
double binWidth (const int binNum) const
 
gs::ClassId classId () const
 
unsigned closestValidBin (double x) const
 
double fltBinNumber (double x, bool mapLeftEdgeTo0=true) const
 
Interval< double > interval () const
 
bool isClose (const NUHistoAxis &, double tol) const
 
bool isUniform () const
 
const std::string & label () const
 
double leftBinEdge (const int binNum) const
 
double length () const
 
double max () const
 
double min () const
 
unsigned nBins () const
 
 NUHistoAxis (const std::vector< double > &binEdges, const char *label=nullptr)
 
bool operator!= (const NUHistoAxis &) const
 
bool operator== (const NUHistoAxis &) const
 
NUHistoAxis 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 NUHistoAxisread (const gs::ClassId &id, std::istream &in)
 
static unsigned version ()
 

Private Member Functions

 NUHistoAxis ()
 
 NUHistoAxis (unsigned nBins, double min, double max, const char *label=nullptr)
 
unsigned overflowIndex (const double x, unsigned *binNum) const
 

Private Attributes

std::vector< double > binEdges_
 
std::string label_
 
double max_
 
double min_
 
unsigned nBins_
 
bool uniform_
 

Friends

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

Detailed Description

This class can be used to create histograms with non-uniform binning

Definition at line 28 of file NUHistoAxis.h.

Constructor & Destructor Documentation

◆ NUHistoAxis() [1/3]

npstat::NUHistoAxis::NUHistoAxis ( const std::vector< double > &  binEdges,
const char *  label = nullptr 
)

The number of bin edges provided must be at least 2. Edge coordinates will be sorted internally in the increasing order. The number of bins will be less by 1 than the number of edges.

Definition at line 15 of file NUHistoAxis.cc.

16  : binEdges_(binEdges), nBins_(binEdges.size() - 1U), uniform_(false) {
17  if (!(binEdges_.size() > 1U && binEdges_.size() < UINT_MAX / 2U))
19  "In npstat::NUHistoAxis constructor: "
20  "number of bin edges is out of range");
21  std::sort(binEdges_.begin(), binEdges_.end());
22  min_ = binEdges_[0];
24  if (label)
26  }

References binEdges_, label(), label_, max_, min_, nBins_, jetUpdater_cfi::sort, AlCaHLTBitMon_QueryRunRegistry::string, and mitigatedMETSequence_cff::U.

◆ NUHistoAxis() [2/3]

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

Definition at line 28 of file NUHistoAxis.cc.

29  : min_(min), max_(max), nBins_(nBins), uniform_(true) {
30  if (!(nBins_ && nBins_ < UINT_MAX / 2U - 1U))
32  "In npstat::NUHistoAxis constructor: "
33  "number of bins is out of range");
34  if (min_ > max_)
36  binEdges_ = EquidistantInLinearSpace(min_, max_, nBins + 1U);
37  if (label)
39  }

References binEdges_, label(), label_, max_, min_, nBins(), nBins_, AlCaHLTBitMon_QueryRunRegistry::string, std::swap(), and mitigatedMETSequence_cff::U.

◆ NUHistoAxis() [3/3]

npstat::NUHistoAxis::NUHistoAxis ( )
inlineprivate

Definition at line 128 of file NUHistoAxis.h.

128 : min_(0.0), max_(0.0), nBins_(0), uniform_(false) {}

Referenced by read(), and rebin().

Member Function Documentation

◆ binCenter()

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

Return the coordinate of the given bin center

Definition at line 56 of file NUHistoAxis.h.

56 { return 0.5 * (binEdges_.at(binNum) + binEdges_.at(binNum + 1)); }

References binEdges_.

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

◆ binInterval()

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

Return the coordinate interval occupied by the given bin

Definition at line 59 of file NUHistoAxis.h.

59  {
60  return Interval<double>(binEdges_.at(binNum), binEdges_.at(binNum + 1));
61  }

References binEdges_.

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

◆ binNumber()

int npstat::NUHistoAxis::binNumber ( double  x) const

This method returns -1 for values below the lower limit and "nBins()" for values equal to or above the upper limit

Definition at line 62 of file NUHistoAxis.cc.

62  {
63  const int delta = std::upper_bound(binEdges_.begin(), binEdges_.end(), x) - binEdges_.begin();
64  return delta - 1;
65  }

References binEdges_, dumpMFGeometry_cfg::delta, and pfDeepBoostedJetPreprocessParams_cfi::upper_bound.

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

◆ binWidth()

double npstat::NUHistoAxis::binWidth ( const int  binNum) const
inline

Definition at line 44 of file NUHistoAxis.h.

44 { return binEdges_.at(binNum + 1) - binEdges_.at(binNum); }

References binEdges_.

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

◆ classId()

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

Method related to "geners" I/O

Definition at line 95 of file NUHistoAxis.h.

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

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

◆ classname()

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

Definition at line 99 of file NUHistoAxis.h.

99 { return "npstat::NUHistoAxis"; }

◆ closestValidBin()

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

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

Definition at line 124 of file NUHistoAxis.cc.

124  {
125  const int delta = std::upper_bound(binEdges_.begin(), binEdges_.end(), x) - binEdges_.begin();
126  int binnum = delta - 1;
127  if (binnum < 0)
128  binnum = 0;
129  else if (static_cast<unsigned>(binnum) >= nBins_)
130  binnum = nBins_ - 1U;
131  return binnum;
132  }

References binEdges_, dumpMFGeometry_cfg::delta, nBins_, mitigatedMETSequence_cff::U, and pfDeepBoostedJetPreprocessParams_cfi::upper_bound.

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

◆ fltBinNumber()

double npstat::NUHistoAxis::fltBinNumber ( double  x,
bool  mapLeftEdgeTo0 = true 
) const

Floating point bin number given the coordinate. Useful for interpolation methods and such.

Definition at line 67 of file NUHistoAxis.cc.

67  {
68  const int delta = std::upper_bound(binEdges_.begin(), binEdges_.end(), x) - binEdges_.begin();
69  const int binnum = delta - 1;
70 
71  if (binnum < 0) {
72  const double left = binEdges_[0];
73  const double right = binEdges_[1];
74  double bval = (x - left) / (right - left);
75  if (!mapLeftEdgeTo0)
76  bval -= 0.5;
77  if (bval < -1.0)
78  bval = -1.0;
79  return bval;
80  } else if (static_cast<unsigned>(binnum) >= nBins_) {
81  const double left = binEdges_[nBins_ - 1U];
82  const double right = binEdges_[nBins_];
83  double bval = nBins_ - 1U + (x - left) / (right - left);
84  if (!mapLeftEdgeTo0)
85  bval -= 0.5;
86  if (bval > static_cast<double>(nBins_))
87  bval = nBins_;
88  return bval;
89  } else {
90  const double left = binEdges_[binnum];
91  const double right = binEdges_[delta];
92  if (mapLeftEdgeTo0)
93  return binnum + (x - left) / (right - left);
94  else {
95  // It is not obvious what is best to do here.
96  // The following works to preserve interpolation
97  // of 0th order. The commented out snippet below
98  // would instead connect bin centers by straight
99  // lines during interpolation.
100  return binnum + (x - left) / (right - left) - 0.5;
101 
102  // Bin center is mapped to binnum.
103  // Bin center of the next bin is mapped to binnum + 1.
104  // Bin center of the previous bin is mapped to binnum - 1.
105  //
106  // const double binCenter = (left + right)/2.0;
107  // if ((binnum == 0 && x <= binCenter) ||
108  // (static_cast<unsigned>(binnum) == nBins_ - 1 && x >= binCenter))
109  // return binnum + (x - left)/(right - left) - 0.5;
110  // else if (x <= binCenter)
111  // {
112  // const double otherBinCenter = (left + binEdges_[binnum - 1])/2.0;
113  // return binnum + (x - binCenter)/(binCenter - otherBinCenter);
114  // }
115  // else
116  // {
117  // const double otherBinCenter = (right + binEdges_[binnum + 2])/2.0;
118  // return binnum + (x - binCenter)/(otherBinCenter - binCenter);
119  // }
120  }
121  }
122  }

References binEdges_, dumpMFGeometry_cfg::delta, nBins_, mitigatedMETSequence_cff::U, and pfDeepBoostedJetPreprocessParams_cfi::upper_bound.

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

◆ interval()

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

Definition at line 41 of file NUHistoAxis.h.

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

References max_, and min_.

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

◆ isClose()

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

Comparison of axis coordinates within given tolerance

Definition at line 45 of file NUHistoAxis.cc.

45  {
46  if (!(closeWithinTolerance(min_, r.min_, tol) && closeWithinTolerance(max_, r.max_, tol) && label_ == r.label_ &&
47  nBins_ == r.nBins_ && uniform_ == r.uniform_))
48  return false;
49  for (unsigned i = 0; i < nBins_; ++i)
50  if (!closeWithinTolerance(binEdges_[i], r.binEdges_[i], tol))
51  return false;
52  return true;
53  }

References binEdges_, npstat::closeWithinTolerance(), mps_fire::i, label_, max_, min_, nBins_, alignCSCRings::r, and uniform_.

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

◆ isUniform()

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

Definition at line 46 of file NUHistoAxis.h.

46 { return uniform_; }

References uniform_.

◆ label()

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

Definition at line 45 of file NUHistoAxis.h.

45 { return label_; }

References label_.

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

◆ leftBinEdge()

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

Return the coordinate of the given bin left edge

Definition at line 50 of file NUHistoAxis.h.

50 { return binEdges_.at(binNum); }

References binEdges_.

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

◆ length()

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

Definition at line 42 of file NUHistoAxis.h.

42 { return max_ - min_; }

References max_, and min_.

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

◆ max()

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

Definition at line 40 of file NUHistoAxis.h.

40 { return max_; }

References max_.

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

◆ min()

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

Examine axis properties

Definition at line 39 of file NUHistoAxis.h.

39 { return min_; }

References min_.

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

◆ nBins()

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

Definition at line 43 of file NUHistoAxis.h.

43 { return nBins_; }

References nBins_.

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

◆ operator!=()

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

Definition at line 60 of file NUHistoAxis.cc.

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

References alignCSCRings::r.

◆ operator==()

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

Definition at line 55 of file NUHistoAxis.cc.

55  {
56  return min_ == r.min_ && max_ == r.max_ && label_ == r.label_ && nBins_ == r.nBins_ && binEdges_ == r.binEdges_ &&
57  uniform_ == r.uniform_;
58  }

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

◆ overflowIndex()

unsigned npstat::NUHistoAxis::overflowIndex ( const double  x,
unsigned *  binNum 
) const
inlineprivate

Definition at line 117 of file NUHistoAxis.h.

117  {
118  if (x < min_)
119  return 0U;
120  else if (x >= max_)
121  return 2U;
122  else {
123  *binNum = binNumber(x);
124  return 1U;
125  }
126  }

References binNumber(), max_, min_, mitigatedMETSequence_cff::U, and x.

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

◆ read()

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

Definition at line 142 of file NUHistoAxis.cc.

142  {
143  static const gs::ClassId current(gs::ClassId::makeId<NUHistoAxis>());
144  current.ensureSameId(id);
145 
146  std::vector<double> binEdges;
148  unsigned char unif;
149  gs::read_pod_vector(in, &binEdges);
150  gs::read_pod(in, &label);
151  gs::read_pod(in, &unif);
152  if (in.fail())
153  throw gs::IOReadFailure(
154  "In npstat::UHistoAxis::read: "
155  "input stream failure");
156  NUHistoAxis* result = new NUHistoAxis(binEdges, label.c_str());
157  result->uniform_ = unif;
158  return result;
159  }

References recoMuon::in, label(), NUHistoAxis(), mps_fire::result, and AlCaHLTBitMon_QueryRunRegistry::string.

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

◆ rebin()

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

Return uniformly rebinned axis

Definition at line 41 of file NUHistoAxis.cc.

41  {
42  return NUHistoAxis(newBins, min_, max_, label_.c_str());
43  }

References label_, max_, min_, and NUHistoAxis().

◆ rightBinEdge()

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

Return the coordinate of the given bin right edge

Definition at line 53 of file NUHistoAxis.h.

53 { return binEdges_.at(binNum + 1); }

References binEdges_.

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

◆ setLabel()

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

Change the axis label

Definition at line 64 of file NUHistoAxis.h.

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

References label_.

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

◆ version()

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

Definition at line 100 of file NUHistoAxis.h.

100 { return 1; }

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

◆ write()

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

Definition at line 134 of file NUHistoAxis.cc.

134  {
135  gs::write_pod_vector(of, binEdges_);
136  gs::write_pod(of, label_);
137  unsigned char c = uniform_;
138  gs::write_pod(of, c);
139  return !of.fail();
140  }

References binEdges_, c, label_, and uniform_.

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

Friends And Related Function Documentation

◆ DualHistoAxis

friend class DualHistoAxis
friend

Definition at line 115 of file NUHistoAxis.h.

◆ HistoND

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

Definition at line 114 of file NUHistoAxis.h.

Member Data Documentation

◆ binEdges_

std::vector<double> npstat::NUHistoAxis::binEdges_
private

◆ label_

std::string npstat::NUHistoAxis::label_
private

◆ max_

double npstat::NUHistoAxis::max_
private

Definition at line 107 of file NUHistoAxis.h.

Referenced by interval(), isClose(), length(), max(), NUHistoAxis(), operator==(), overflowIndex(), and rebin().

◆ min_

double npstat::NUHistoAxis::min_
private

Definition at line 106 of file NUHistoAxis.h.

Referenced by interval(), isClose(), length(), min(), NUHistoAxis(), operator==(), overflowIndex(), and rebin().

◆ nBins_

unsigned npstat::NUHistoAxis::nBins_
private

Definition at line 110 of file NUHistoAxis.h.

Referenced by closestValidBin(), fltBinNumber(), isClose(), nBins(), NUHistoAxis(), and operator==().

◆ uniform_

bool npstat::NUHistoAxis::uniform_
private

Definition at line 111 of file NUHistoAxis.h.

Referenced by isClose(), isUniform(), operator==(), and write().

pfDeepBoostedJetPreprocessParams_cfi.upper_bound
upper_bound
Definition: pfDeepBoostedJetPreprocessParams_cfi.py:16
mps_fire.i
i
Definition: mps_fire.py:428
npstat::NUHistoAxis::binNumber
int binNumber(double x) const
Definition: NUHistoAxis.cc:62
npstat::NUHistoAxis::nBins_
unsigned nBins_
Definition: NUHistoAxis.h:110
npstat::NUHistoAxis::nBins
unsigned nBins() const
Definition: NUHistoAxis.h:43
DDAxes::x
npstat::NUHistoAxis::binEdges_
std::vector< double > binEdges_
Definition: NUHistoAxis.h:108
std::swap
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
Definition: DataFrameContainer.h:209
npstat::NUHistoAxis::NUHistoAxis
NUHistoAxis()
Definition: NUHistoAxis.h:128
npstat::NpstatInvalidArgument
Definition: NpstatException.h:38
mitigatedMETSequence_cff.U
U
Definition: mitigatedMETSequence_cff.py:36
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
npstat::NUHistoAxis::uniform_
bool uniform_
Definition: NUHistoAxis.h:111
npstat::NUHistoAxis::label
const std::string & label() const
Definition: NUHistoAxis.h:45
npstat::NUHistoAxis::max
double max() const
Definition: NUHistoAxis.h:40
npstat::NUHistoAxis::label_
std::string label_
Definition: NUHistoAxis.h:109
npstat::NUHistoAxis::min
double min() const
Definition: NUHistoAxis.h:39
jetUpdater_cfi.sort
sort
Definition: jetUpdater_cfi.py:29
recoMuon::in
Definition: RecoMuonEnumerators.h:6
dumpMFGeometry_cfg.delta
delta
Definition: dumpMFGeometry_cfg.py:25
npstat::NUHistoAxis::max_
double max_
Definition: NUHistoAxis.h:107
npstat::NUHistoAxis::min_
double min_
Definition: NUHistoAxis.h:106
alignCSCRings.r
r
Definition: alignCSCRings.py:93
mps_fire.result
result
Definition: mps_fire.py:311
npstat::closeWithinTolerance
bool closeWithinTolerance(const double &a, const double &b, const double &tol)
Definition: closeWithinTolerance.h:25
c
auto & c
Definition: CAHitNtupletGeneratorKernelsImpl.h:46