CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_1/src/JetMETCorrections/InterpolationTables/src/convertAxis.cc

Go to the documentation of this file.
00001 #include "JetMETCorrections/InterpolationTables/interface/NpstatException.h"
00002 
00003 #include "JetMETCorrections/InterpolationTables/interface/convertAxis.h"
00004 
00005 namespace npstat {
00006     HistoAxis convertToHistoAxis(const UniformAxis& gridAxis)
00007     {
00008         const unsigned nBins = gridAxis.nCoords();
00009         const double xmin = gridAxis.min();
00010         const double xmax = gridAxis.max();
00011         const double hbw = 0.5*(xmax - xmin)/(nBins - 1U);
00012         HistoAxis ax(nBins, xmin-hbw, xmax+hbw, gridAxis.label().c_str());
00013         return ax;
00014     }
00015  
00016     UniformAxis convertToGridAxis(const HistoAxis& histoAxis)
00017     {
00018         const unsigned nBins = histoAxis.nBins();
00019         const double xmin = histoAxis.binCenter(0);
00020         const double xmax = histoAxis.binCenter(nBins - 1);
00021         UniformAxis ax(nBins, xmin, xmax, histoAxis.label().c_str());
00022         return ax;
00023     }
00024 
00025     NUHistoAxis convertToHistoAxis(const GridAxis& gridAxis, double xMin)
00026     {
00027         const unsigned nCoords = gridAxis.nCoords();
00028         std::vector<double> binEdges;
00029         binEdges.reserve(nCoords + 1U);
00030         binEdges.push_back(xMin);
00031         for (unsigned i=0; i<nCoords; ++i)
00032         {
00033             const double x = gridAxis.coordinate(i);
00034             if (x <= xMin)
00035                 throw npstat::NpstatInvalidArgument("In npstat::convertToHistoAxis: "
00036                                             "conversion is impossible");
00037             const double halfbin = x - xMin;
00038             xMin = x + halfbin;
00039             binEdges.push_back(xMin);
00040         }
00041         NUHistoAxis ax(binEdges, gridAxis.label().c_str());
00042         return ax;
00043     }
00044 
00045     GridAxis convertToGridAxis(const NUHistoAxis& histoAxis)
00046     {
00047         const unsigned nBins = histoAxis.nBins();
00048         std::vector<double> coords;
00049         coords.reserve(nBins);
00050         for (unsigned i=0; i<nBins; ++i)
00051             coords.push_back(histoAxis.binCenter(i));
00052         GridAxis ax(coords, histoAxis.label().c_str());
00053         return ax;
00054     }
00055 }