CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
LinInterpolatedTable1D.cc
Go to the documentation of this file.
2 
3 namespace fftjetcms {
5  : data_(2, c),
6  xmin_(0.0),
7  xmax_(1.0),
8  binwidth_(1.0),
9  npoints_(2U),
10  leftExtrapolationLinear_(false),
11  rightExtrapolationLinear_(false),
12  monotonous_(false),
13  monotonicityKnown_(true)
14  {
15  }
16 
18  const LinInterpolatedTable1D& r) const
19  {
20  return xmin_ == r.xmin_ &&
21  xmax_ == r.xmax_ &&
22  binwidth_ == r.binwidth_ &&
23  npoints_ == r.npoints_ &&
26  data_ == r.data_;
27  }
28 
30  {
31  if (!monotonicityKnown_)
32  {
33  monotonous_ = true;
34  const double delta = data_[npoints_ - 1U] - data_[0];
35  if (delta == 0.0)
36  monotonous_ = false;
37  const double sg = delta > 0.0 ? 1.0 : -1.0;
38  for (unsigned i=1; i<npoints_ && monotonous_; ++i)
39  if ((data_[i] - data_[i-1])*sg <= 0.0)
40  monotonous_ = false;
41  monotonicityKnown_ = true;
42  }
43  return monotonous_;
44  }
45 
46  std::auto_ptr<LinInterpolatedTable1D> LinInterpolatedTable1D::inverse(
47  const unsigned npoints, const bool leftExtrapolationLinear,
48  const bool rightExtrapolationLinear) const
49  {
50  if (!isMonotonous())
51  return std::auto_ptr<LinInterpolatedTable1D>(NULL);
52 
53  std::vector<std::pair<double,double> > points;
54  points.reserve(npoints_);
55 
56  if (data_[npoints_ - 1U] > data_[0])
57  {
58  points.push_back(std::pair<double,double>(data_[0], xmin_));
59  for (unsigned i=1; i<npoints_ - 1U; ++i)
60  points.push_back(std::pair<double,double>(data_[i], xmin_+i*binwidth_));
61  points.push_back(std::pair<double,double>(data_[npoints_ - 1U], xmax_));
62  }
63  else
64  {
65  points.push_back(std::pair<double,double>(data_[npoints_ - 1U], xmax_));
66  for (unsigned i=npoints_ - 2U; i>0; --i)
67  points.push_back(std::pair<double,double>(data_[i], xmin_+i*binwidth_));
68  points.push_back(std::pair<double,double>(data_[0], xmin_));
69  }
70 
71  return std::auto_ptr<LinInterpolatedTable1D>(
72  new LinInterpolatedTable1D(points, npoints,
73  leftExtrapolationLinear,
74  rightExtrapolationLinear));
75  }
76 
77  double LinInterpolatedTable1D::operator()(const double& x) const
78  {
79  if (x <= xmin_)
80  {
82  return data_[0] + (data_[1]-data_[0])*((x-xmin_)/binwidth_);
83  else
84  return data_[0];
85  }
86  else if (x >= xmax_)
87  {
89  return data_[npoints_ - 1U] - (
90  data_[npoints_-2U]-data_[npoints_-1U])*((x-xmax_)/binwidth_);
91  else
92  return data_[npoints_ - 1U];
93  }
94  else
95  {
96  const unsigned ux = static_cast<unsigned>((x - xmin_)/binwidth_);
97  if (ux >= npoints_ - 1U)
98  return data_[npoints_ - 1U];
99  const double delta = x - (ux*binwidth_ + xmin_);
100  return data_[ux] + (data_[ux+1U]-data_[ux])*delta/binwidth_;
101  }
102  }
103 }
dbl * delta
Definition: mlp_gen.cc:36
int i
Definition: DBlmapReader.cc:9
bool operator==(const LinInterpolatedTable1D &r) const
#define NULL
Definition: scimark2.h:8
virtual double operator()(const double &x) const
std::auto_ptr< LinInterpolatedTable1D > inverse(unsigned npoints, bool leftExtrapolationLinear, bool rightExtrapolationLinear) const
Definition: DDAxes.h:10
LinInterpolatedTable1D(const RealN *data, unsigned npoints, double x_min, double x_max, bool leftExtrapolationLinear, bool rightExtrapolationLinear)