Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef NPSTAT_COORDINATESELECTOR_HH_
0002 #define NPSTAT_COORDINATESELECTOR_HH_
0003 
0004 /*!
0005 // \file CoordinateSelector.h
0006 //
0007 // \brief Multidimensional functor which picks one of the elements
0008 //        from an array of doubles
0009 //
0010 // Author: I. Volobouev
0011 //
0012 // August 2012
0013 */
0014 
0015 #include <climits>
0016 #include "JetMETCorrections/InterpolationTables/interface/NpstatException.h"
0017 
0018 #include "JetMETCorrections/InterpolationTables/interface/AbsMultivariateFunctor.h"
0019 
0020 namespace npstat {
0021   /**
0022     // A trivial implementation of AbsMultivariateFunctor which selects
0023     // an element with a certain index from the input array
0024     */
0025   class CoordinateSelector : public AbsMultivariateFunctor {
0026   public:
0027     inline explicit CoordinateSelector(const unsigned i) : index_(i) {}
0028 
0029     CoordinateSelector() = delete;
0030 
0031     inline ~CoordinateSelector() override {}
0032 
0033     inline double operator()(const double* point, const unsigned dim) const override {
0034       if (dim <= index_)
0035         throw npstat::NpstatInvalidArgument(
0036             "In npstat::CoordinateSelector::operator(): "
0037             "input array dimensionality is too small");
0038       return point[index_];
0039     }
0040     inline unsigned minDim() const override { return index_ + 1U; }
0041     inline unsigned maxDim() const override { return UINT_MAX; }
0042 
0043   private:
0044     unsigned index_;
0045   };
0046 }  // namespace npstat
0047 
0048 #endif  // NPSTAT_COORDINATESELECTOR_HH_