CMS 3D CMS Logo

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

#include <GridAxis.h>

Public Member Functions

gs::ClassId classId () const
 
double coordinate (const unsigned i) const
 
const std::vector< double > & coords () const
 
std::pair< unsigned, double > getInterval (double coordinate) const
 
 GridAxis (const std::vector< double > &coords, bool useLogSpace=false)
 
 GridAxis (const std::vector< double > &coords, const char *label, bool useLogSpace=false)
 
double intervalWidth (const unsigned i=0) const
 
bool isClose (const GridAxis &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 GridAxis &r) const
 
bool operator== (const GridAxis &r) const
 
void setLabel (const char *newlabel)
 
bool usesLogSpace () const
 
bool write (std::ostream &of) const
 

Static Public Member Functions

static const char * classname ()
 
static GridAxisread (const gs::ClassId &id, std::istream &in)
 
static unsigned version ()
 

Private Member Functions

 GridAxis ()
 
void initialize ()
 

Private Attributes

std::vector< double > coords_
 
std::string label_
 
std::vector< double > logs_
 
unsigned npt_
 
bool useLogSpace_
 

Detailed Description

Information needed to define an axis of a rectangular grid. The distance between grid points can change from point to point.

The UniformAxis class will be more efficient in representing equidistant grids.

Definition at line 30 of file GridAxis.h.

Constructor & Destructor Documentation

◆ GridAxis() [1/3]

npstat::GridAxis::GridAxis ( const std::vector< double > &  coords,
bool  useLogSpace = false 
)
explicit

The number of grid coordinates provided must be at least 2. Coordinates will be sorted internally in the increasing order.

Definition at line 38 of file GridAxis.cc.

39  : coords_(coords), npt_(coords_.size()), useLogSpace_(useLogSpace) {
40  initialize();
41  }

References initialize().

◆ GridAxis() [2/3]

npstat::GridAxis::GridAxis ( const std::vector< double > &  coords,
const char *  label,
bool  useLogSpace = false 
)

Definition at line 43 of file GridAxis.cc.

44  : coords_(coords), label_(label ? label : ""), npt_(coords_.size()), useLogSpace_(useLogSpace) {
45  initialize();
46  }

References initialize().

◆ GridAxis() [3/3]

npstat::GridAxis::GridAxis ( )
inlineprivate

Definition at line 125 of file GridAxis.h.

125 : npt_(0), useLogSpace_(false) {}

Referenced by read().

Member Function Documentation

◆ classId()

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

Method related to "geners" I/O

Definition at line 108 of file GridAxis.h.

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

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

◆ classname()

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

Definition at line 112 of file GridAxis.h.

112 { return "npstat::GridAxis"; }

◆ coordinate()

double npstat::GridAxis::coordinate ( const unsigned  i) const
inline

Definition at line 82 of file GridAxis.h.

82 { return coords_.at(i); }

References coords_, and mps_fire::i.

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

◆ coords()

const std::vector<double>& npstat::GridAxis::coords ( ) const
inline

Basic accessor returning a parameter provided in the constructor

Definition at line 43 of file GridAxis.h.

43 { return coords_; }

References coords_.

Referenced by npstat::DualAxis::coords(), and read().

◆ getInterval()

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

This method returns the grid interval number and the weight of the point at the left side of the interval. The weight will be set to 1 if the given coordinate coincides with the grid point and will decay to 0 linearly as the coordinate moves towards the next point on the right.

The coordinates below the leftmost grid point are mapped into the 0th interval with weight 1. The coordinates above the rightmost grid point are mapped into the last interval with weight 0 for the left point (it is expected that weight 1 will then be assigned to the right point).

Definition at line 48 of file GridAxis.cc.

48  {
49  if (useLogSpace_)
50  if (x <= 0.0)
51  throw npstat::NpstatDomainError("In GridAxis::getInterval: argument must be positive");
52  const double* c = &coords_[0];
53  if (x <= c[0])
54  return std::pair<unsigned, double>(0U, 1.0);
55  else if (x >= c[npt_ - 1U])
56  return std::pair<unsigned, double>(npt_ - 2U, 0.0);
57  else {
58  unsigned ibnd = lower_bound(coords_.begin(), coords_.end(), x) - coords_.begin();
59  --ibnd;
60  if (useLogSpace_) {
61  const double* l = &logs_[0];
62  const double w = 1.0 - (log(x) - l[ibnd]) / (l[ibnd + 1U] - l[ibnd]);
63  return std::pair<unsigned, double>(ibnd, w);
64  } else {
65  const double w = 1.0 - (x - c[ibnd]) / (c[ibnd + 1U] - c[ibnd]);
66  return std::pair<unsigned, double>(ibnd, w);
67  }
68  }
69  }

References HltBtagPostValidation_cff::c, coords_, cmsLHEtoEOSManager::l, dqm-mbProfile::log, logs_, pfDeepBoostedJetPreprocessParams_cfi::lower_bound, npt_, mitigatedMETSequence_cff::U, useLogSpace_, and w.

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

◆ initialize()

void npstat::GridAxis::initialize ( void  )
private

Definition at line 12 of file GridAxis.cc.

12  {
13  if (npt_ <= 1U)
15  "In npstat::GridAxis::initialize: insufficient number "
16  "of coordinates (at least 2 are required)");
17  std::sort(coords_.begin(), coords_.end());
18  const double* c = &coords_[0];
19  if (useLogSpace_) {
20  logs_.reserve(npt_);
21  for (unsigned i = 0; i < npt_; ++i) {
22  if (c[i] <= 0.0)
24  "In npstat::GridAxis::initialize: in log space"
25  "all coordinates must be positive");
26  logs_.push_back(log(c[i]));
27  }
28  }
29 
30  // Can't have duplicate coordinates
31  for (unsigned i = 1; i < npt_; ++i)
32  if (c[i] <= c[i - 1U])
34  "In npstat::GridAxis::initialize: "
35  "all coordinates must be distinct");
36  }

References HltBtagPostValidation_cff::c, coords_, mps_fire::i, dqm-mbProfile::log, logs_, npt_, mitigatedMETSequence_cff::U, and useLogSpace_.

Referenced by GridAxis().

◆ intervalWidth()

double npstat::GridAxis::intervalWidth ( const unsigned  i = 0) const
inline

Definition at line 88 of file GridAxis.h.

88 { return coords_.at(i + 1) - coords_.at(i); }

References coords_, and mps_fire::i.

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

◆ isClose()

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

Check for closeness of coordinates with another axis within the given relative tolerance

Definition at line 141 of file GridAxis.cc.

141  {
142  if (!(useLogSpace_ == r.useLogSpace_ && label_ == r.label_))
143  return false;
144  const unsigned long n = coords_.size();
145  if (n != r.coords_.size())
146  return false;
147  for (unsigned long i = 0; i < n; ++i)
148  if (!closeWithinTolerance(coords_[i], r.coords_[i], tol))
149  return false;
150  return true;
151  }

References npstat::closeWithinTolerance(), coords_, mps_fire::i, label_, dqmiodumpmetadata::n, alignCSCRings::r, and useLogSpace_.

◆ isUniform()

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

Definition at line 86 of file GridAxis.h.

86 { return false; }

◆ label()

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

Definition at line 44 of file GridAxis.h.

44 { return label_; }

References label_.

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

◆ length()

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

Definition at line 85 of file GridAxis.h.

85 { return coords_.back() - coords_.front(); }

References coords_.

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

◆ linearInterval()

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

This method returns the grid interval number and the weight of the point at the left side of the interval. The weight will be set to 1 if the given coordinate coincides with the grid point and will decay to 0 linearly as the coordinate moves towards the next point on the right. The weight for the point on the right should be set to one minus the weight on the left.

The coordinates outside of grid boundaries will result in weights which are less than zero or more than one. They will be calculated by linear extrapolation from the closest interval in the grid (i.e., leftmost or rightmost).

Definition at line 71 of file GridAxis.cc.

71  {
72  if (useLogSpace_)
73  if (x <= 0.0)
74  throw npstat::NpstatDomainError("In GridAxis::linearInterval: argument must be positive");
75  const double* c = &coords_[0];
76  if (x <= c[0]) {
77  if (useLogSpace_) {
78  const double* l = &logs_[0];
79  const double bw = l[1] - l[0];
80  return std::pair<unsigned, double>(0U, 1.0 - (log(x) - l[0]) / bw);
81  } else {
82  const double bw = c[1] - c[0];
83  return std::pair<unsigned, double>(0U, 1.0 - (x - c[0]) / bw);
84  }
85  } else if (x >= c[npt_ - 1U]) {
86  if (useLogSpace_) {
87  const double* l = &logs_[0];
88  const double bw = l[npt_ - 1U] - l[npt_ - 2U];
89  return std::pair<unsigned, double>(npt_ - 2U, (l[npt_ - 1U] - log(x)) / bw);
90  } else {
91  const double bw = c[npt_ - 1U] - c[npt_ - 2U];
92  return std::pair<unsigned, double>(npt_ - 2U, (c[npt_ - 1U] - x) / bw);
93  }
94  } else {
95  unsigned ibnd = lower_bound(coords_.begin(), coords_.end(), x) - coords_.begin();
96  --ibnd;
97  if (useLogSpace_) {
98  const double* l = &logs_[0];
99  const double w = 1.0 - (log(x) - l[ibnd]) / (l[ibnd + 1U] - l[ibnd]);
100  return std::pair<unsigned, double>(ibnd, w);
101  } else {
102  const double w = 1.0 - (x - c[ibnd]) / (c[ibnd + 1U] - c[ibnd]);
103  return std::pair<unsigned, double>(ibnd, w);
104  }
105  }
106  }

References HltBtagPostValidation_cff::c, coords_, cmsLHEtoEOSManager::l, dqm-mbProfile::log, logs_, pfDeepBoostedJetPreprocessParams_cfi::lower_bound, npt_, mitigatedMETSequence_cff::U, useLogSpace_, and w.

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

◆ max()

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

Definition at line 84 of file GridAxis.h.

84 { return coords_.back(); }

References coords_.

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

◆ min()

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

Definition at line 83 of file GridAxis.h.

83 { return coords_.front(); }

References coords_.

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

◆ nCoords()

unsigned npstat::GridAxis::nCoords ( ) const
inline

Convenience accessor

Definition at line 81 of file GridAxis.h.

81 { return npt_; }

References npt_.

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

◆ nIntervals()

unsigned npstat::GridAxis::nIntervals ( ) const
inline

Definition at line 87 of file GridAxis.h.

87 { return coords_.size() - 1; }

References coords_.

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

◆ operator!=()

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

Logical negation of operator==

Definition at line 95 of file GridAxis.h.

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

References alignCSCRings::r.

◆ operator==()

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

Compare two grids for equality

Definition at line 137 of file GridAxis.cc.

137  {
138  return useLogSpace_ == r.useLogSpace_ && coords_ == r.coords_ && label_ == r.label_;
139  }

References coords_, label_, alignCSCRings::r, and useLogSpace_.

◆ read()

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

Definition at line 117 of file GridAxis.cc.

117  {
118  static const gs::ClassId current(gs::ClassId::makeId<GridAxis>());
119  current.ensureSameId(id);
120 
121  std::vector<double> coords;
122  gs::read_pod_vector(in, &coords);
123 
125  gs::read_pod(in, &label);
126 
127  bool useLogSpace;
128  gs::read_pod(in, &useLogSpace);
129 
130  if (in.fail())
131  throw gs::IOReadFailure(
132  "In npstat::GridAxis::read: "
133  "input stream failure");
134  return new GridAxis(coords, label.c_str(), useLogSpace);
135  }

References coords(), GridAxis(), recoMuon::in, label(), and AlCaHLTBitMon_QueryRunRegistry::string.

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

◆ setLabel()

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

Modify the axis label

Definition at line 104 of file GridAxis.h.

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

References label_.

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

◆ usesLogSpace()

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

Definition at line 45 of file GridAxis.h.

45 { return useLogSpace_; }

References useLogSpace_.

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

◆ version()

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

Definition at line 113 of file GridAxis.h.

113 { return 2; }

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

◆ write()

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

Definition at line 108 of file GridAxis.cc.

108  {
109  // It is unlikely that this object will be written in isolation.
110  // So, do not bother with too many checks.
111  gs::write_pod_vector(of, coords_);
112  gs::write_pod(of, label_);
113  gs::write_pod(of, useLogSpace_);
114  return !of.fail();
115  }

References coords_, label_, and useLogSpace_.

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

Member Data Documentation

◆ coords_

std::vector<double> npstat::GridAxis::coords_
private

◆ label_

std::string npstat::GridAxis::label_
private

◆ logs_

std::vector<double> npstat::GridAxis::logs_
private

Definition at line 120 of file GridAxis.h.

Referenced by getInterval(), initialize(), and linearInterval().

◆ npt_

unsigned npstat::GridAxis::npt_
private

Definition at line 122 of file GridAxis.h.

Referenced by getInterval(), initialize(), linearInterval(), and nCoords().

◆ useLogSpace_

bool npstat::GridAxis::useLogSpace_
private
mps_fire.i
i
Definition: mps_fire.py:428
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
npstat::GridAxis::npt_
unsigned npt_
Definition: GridAxis.h:122
npstat::GridAxis::coords
const std::vector< double > & coords() const
Definition: GridAxis.h:43
npstat::GridAxis::initialize
void initialize()
Definition: GridAxis.cc:12
DDAxes::x
w
const double w
Definition: UKUtility.cc:23
npstat::NpstatInvalidArgument
Definition: NpstatException.h:38
mitigatedMETSequence_cff.U
U
Definition: mitigatedMETSequence_cff.py:36
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
pfDeepBoostedJetPreprocessParams_cfi.lower_bound
lower_bound
Definition: pfDeepBoostedJetPreprocessParams_cfi.py:15
npstat::GridAxis::useLogSpace_
bool useLogSpace_
Definition: GridAxis.h:123
recoMuon::in
Definition: RecoMuonEnumerators.h:6
npstat::GridAxis::label_
std::string label_
Definition: GridAxis.h:121
HltBtagPostValidation_cff.c
c
Definition: HltBtagPostValidation_cff.py:31
npstat::NpstatDomainError
Definition: NpstatException.h:54
cmsLHEtoEOSManager.l
l
Definition: cmsLHEtoEOSManager.py:204
alignCSCRings.r
r
Definition: alignCSCRings.py:93
dqm-mbProfile.log
log
Definition: dqm-mbProfile.py:17
npstat::GridAxis::coords_
std::vector< double > coords_
Definition: GridAxis.h:119
npstat::closeWithinTolerance
bool closeWithinTolerance(const double &a, const double &b, const double &tol)
Definition: closeWithinTolerance.h:25
npstat::GridAxis::GridAxis
GridAxis()
Definition: GridAxis.h:125
npstat::GridAxis::logs_
std::vector< double > logs_
Definition: GridAxis.h:120
npstat::GridAxis::label
const std::string & label() const
Definition: GridAxis.h:44