File indexing completed on 2024-04-06 12:25:22
0001 #include <cmath>
0002 #include <cassert>
0003
0004 #include "RecoJets/FFTJetAlgorithms/interface/LookupTable2d.h"
0005
0006 namespace fftjetcms {
0007 LookupTable2d::LookupTable2d(
0008 unsigned nx, double xmin, double xmax, unsigned ny, double ymin, double ymax, const std::vector<double>& data)
0009 : data_(data),
0010 nx_(nx),
0011 ny_(ny),
0012 xmin_(xmin),
0013 xmax_(xmax),
0014 ymin_(ymin),
0015 ymax_(ymax),
0016 bwx_((xmax - xmin) / nx),
0017 bwy_((ymax - ymin) / ny) {
0018 assert(nx_);
0019 assert(ny_);
0020 assert(xmin_ < xmax_);
0021 assert(ymin_ < ymax_);
0022 assert(data_.size() == nx_ * ny_);
0023 }
0024
0025 double LookupTable2d::closest(const double x, const double y) const {
0026 const unsigned ix = x <= xmin_ ? 0U
0027 : x >= xmax_ - bwx_ / 2.0 ? nx_ - 1U
0028 : static_cast<unsigned>((x - xmin_) / bwx_);
0029 const unsigned iy = y <= ymin_ ? 0U
0030 : y >= ymax_ - bwy_ / 2.0 ? ny_ - 1U
0031 : static_cast<unsigned>((y - ymin_) / bwy_);
0032 return data_[ix * ny_ + iy];
0033 }
0034 }