CMS 3D CMS Logo

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

Go to the documentation of this file.
00001 #include <cmath>
00002 #include "JetMETCorrections/InterpolationTables/interface/NpstatException.h"
00003 
00004 #include "JetMETCorrections/InterpolationTables/interface/EquidistantSequence.h"
00005 
00006 namespace npstat {
00007     EquidistantInLinearSpace::EquidistantInLinearSpace(
00008         const double minScale, const double maxScale, const unsigned nScales)
00009         : std::vector<double>()
00010     {
00011         switch (nScales)
00012         {
00013         case 0:
00014         break;
00015 
00016         case 1:
00017         {
00018             this->reserve(nScales);
00019             const double sc = (minScale == maxScale ? minScale :
00020                                (minScale + maxScale)/2.0);
00021             push_back(sc);
00022         }
00023         break;
00024 
00025         default:
00026         {
00027             this->reserve(nScales);
00028             const double step = (maxScale - minScale)/(nScales - 1);
00029             push_back(minScale);
00030             for (unsigned i=1; i<nScales - 1; ++i)
00031                 push_back(minScale + i*step);
00032             push_back(maxScale);
00033         }
00034         break;
00035         }
00036     }
00037 
00038     EquidistantInLogSpace::EquidistantInLogSpace(
00039         const double minScale, const double maxScale, const unsigned nScales)
00040         : std::vector<double>()
00041     {
00042         if (nScales)
00043             if (!(minScale > 0.0 && maxScale > 0.0))
00044                 throw npstat::NpstatInvalidArgument(
00045                     "In npstat::EquidistantInLogSpace constructor: "
00046                     "minimum and maximum scales must be positive");
00047         switch (nScales)
00048         {
00049         case 0:
00050         break;
00051 
00052         case 1:
00053         {
00054             this->reserve(nScales);
00055             const double sc = (minScale == maxScale ? minScale :
00056                                sqrt(minScale*maxScale));
00057             push_back(sc);
00058         }
00059         break;
00060 
00061         default:
00062         {
00063             this->reserve(nScales);
00064             const double logmax = log(maxScale);
00065             const double logmin = log(minScale);
00066             const double logstep = (logmax - logmin)/(nScales - 1);
00067             push_back(minScale);
00068             for (unsigned i=1; i<nScales - 1; ++i)
00069                 push_back(exp(logmin + i*logstep));
00070             push_back(maxScale);
00071         }
00072         break;
00073         }
00074     }
00075 }