Go to the documentation of this file.00001 #include <cmath>
00002 #include <cassert>
00003
00004 #include "RecoJets/FFTJetAlgorithms/interface/LookupTable2d.h"
00005
00006 namespace fftjetcms {
00007 LookupTable2d::LookupTable2d(unsigned nx, double xmin, double xmax,
00008 unsigned ny, double ymin, double ymax,
00009 const std::vector<double>& data)
00010 : data_(data),
00011 nx_(nx),
00012 ny_(ny),
00013 xmin_(xmin),
00014 xmax_(xmax),
00015 ymin_(ymin),
00016 ymax_(ymax),
00017 bwx_((xmax - xmin)/nx),
00018 bwy_((ymax - ymin)/ny)
00019 {
00020 assert(nx_);
00021 assert(ny_);
00022 assert(xmin_ < xmax_);
00023 assert(ymin_ < ymax_);
00024 assert(data_.size() == nx_*ny_);
00025 }
00026
00027 double LookupTable2d::closest(const double x, const double y) const
00028 {
00029 const unsigned ix = x <= xmin_ ? 0U : x >= xmax_-bwx_/2.0 ? nx_ - 1U :
00030 static_cast<unsigned>((x - xmin_)/bwx_);
00031 const unsigned iy = y <= ymin_ ? 0U : y >= ymax_-bwy_/2.0 ? ny_ - 1U :
00032 static_cast<unsigned>((y - ymin_)/bwy_);
00033 return data_[ix*ny_ + iy];
00034 }
00035 }