Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:19:22

0001 #include "JetMETCorrections/InterpolationTables/interface/NpstatException.h"
0002 
0003 #include "JetMETCorrections/InterpolationTables/interface/convertAxis.h"
0004 
0005 namespace npstat {
0006   HistoAxis convertToHistoAxis(const UniformAxis& gridAxis) {
0007     const unsigned nBins = gridAxis.nCoords();
0008     const double xmin = gridAxis.min();
0009     const double xmax = gridAxis.max();
0010     const double hbw = 0.5 * (xmax - xmin) / (nBins - 1U);
0011     HistoAxis ax(nBins, xmin - hbw, xmax + hbw, gridAxis.label().c_str());
0012     return ax;
0013   }
0014 
0015   UniformAxis convertToGridAxis(const HistoAxis& histoAxis) {
0016     const unsigned nBins = histoAxis.nBins();
0017     const double xmin = histoAxis.binCenter(0);
0018     const double xmax = histoAxis.binCenter(nBins - 1);
0019     UniformAxis ax(nBins, xmin, xmax, histoAxis.label().c_str());
0020     return ax;
0021   }
0022 
0023   NUHistoAxis convertToHistoAxis(const GridAxis& gridAxis, double xMin) {
0024     const unsigned nCoords = gridAxis.nCoords();
0025     std::vector<double> binEdges;
0026     binEdges.reserve(nCoords + 1U);
0027     binEdges.push_back(xMin);
0028     for (unsigned i = 0; i < nCoords; ++i) {
0029       const double x = gridAxis.coordinate(i);
0030       if (x <= xMin)
0031         throw npstat::NpstatInvalidArgument(
0032             "In npstat::convertToHistoAxis: "
0033             "conversion is impossible");
0034       const double halfbin = x - xMin;
0035       xMin = x + halfbin;
0036       binEdges.push_back(xMin);
0037     }
0038     NUHistoAxis ax(binEdges, gridAxis.label().c_str());
0039     return ax;
0040   }
0041 
0042   GridAxis convertToGridAxis(const NUHistoAxis& histoAxis) {
0043     const unsigned nBins = histoAxis.nBins();
0044     std::vector<double> coords;
0045     coords.reserve(nBins);
0046     for (unsigned i = 0; i < nBins; ++i)
0047       coords.push_back(histoAxis.binCenter(i));
0048     GridAxis ax(coords, histoAxis.label().c_str());
0049     return ax;
0050   }
0051 }  // namespace npstat