CMS 3D CMS Logo

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