CMS 3D CMS Logo

convertAxis.cc
Go to the documentation of this file.
2 
4 
5 namespace npstat {
7  const unsigned nBins = gridAxis.nCoords();
8  const double xmin = gridAxis.min();
9  const double xmax = gridAxis.max();
10  const double hbw = 0.5 * (xmax - xmin) / (nBins - 1U);
11  HistoAxis ax(nBins, xmin - hbw, xmax + hbw, gridAxis.label().c_str());
12  return ax;
13  }
14 
16  const unsigned nBins = histoAxis.nBins();
17  const double xmin = histoAxis.binCenter(0);
18  const double xmax = histoAxis.binCenter(nBins - 1);
19  UniformAxis ax(nBins, xmin, xmax, histoAxis.label().c_str());
20  return ax;
21  }
22 
23  NUHistoAxis convertToHistoAxis(const GridAxis& gridAxis, double xMin) {
24  const unsigned nCoords = gridAxis.nCoords();
25  std::vector<double> binEdges;
26  binEdges.reserve(nCoords + 1U);
27  binEdges.push_back(xMin);
28  for (unsigned i = 0; i < nCoords; ++i) {
29  const double x = gridAxis.coordinate(i);
30  if (x <= xMin)
32  "In npstat::convertToHistoAxis: "
33  "conversion is impossible");
34  const double halfbin = x - xMin;
35  xMin = x + halfbin;
36  binEdges.push_back(xMin);
37  }
38  NUHistoAxis ax(binEdges, gridAxis.label().c_str());
39  return ax;
40  }
41 
43  const unsigned nBins = histoAxis.nBins();
44  std::vector<double> coords;
45  coords.reserve(nBins);
46  for (unsigned i = 0; i < nBins; ++i)
47  coords.push_back(histoAxis.binCenter(i));
48  GridAxis ax(coords, histoAxis.label().c_str());
49  return ax;
50  }
51 } // namespace npstat
const std::string & label() const
Definition: HistoAxis.h:47
double binCenter(const int binNum) const
Definition: NUHistoAxis.h:56
unsigned nBins() const
Definition: NUHistoAxis.h:43
unsigned nCoords() const
Definition: GridAxis.h:81
Functions for converting between grid and histogram axes.
double min() const
Definition: UniformAxis.h:34
unsigned nCoords() const
Definition: UniformAxis.h:33
Exceptions for the npstat namespace.
const std::string & label() const
Definition: GridAxis.h:44
UniformAxis convertToGridAxis(const HistoAxis &histoAxis)
Definition: convertAxis.cc:15
double coordinate(const unsigned i) const
Definition: GridAxis.h:82
HistoAxis convertToHistoAxis(const UniformAxis &gridAxis)
Definition: convertAxis.cc:6
double binCenter(const int binNum) const
Definition: HistoAxis.h:52
unsigned nBins() const
Definition: HistoAxis.h:45
const std::string & label() const
Definition: NUHistoAxis.h:45
float x
double max() const
Definition: UniformAxis.h:35
const std::string & label() const
Definition: UniformAxis.h:36