CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Static Private Member Functions | Private Attributes
fftjetcms::LinInterpolatedTable1D Class Reference

#include <LinInterpolatedTable1D.h>

Inheritance diagram for fftjetcms::LinInterpolatedTable1D:

Public Member Functions

const double * data () const
 
std::auto_ptr
< LinInterpolatedTable1D
inverse (unsigned npoints, bool leftExtrapolationLinear, bool rightExtrapolationLinear) const
 
bool isMonotonous () const
 
bool leftExtrapolationLinear () const
 
template<typename RealN >
 LinInterpolatedTable1D (const RealN *data, unsigned npoints, double x_min, double x_max, bool leftExtrapolationLinear, bool rightExtrapolationLinear)
 
template<typename RealN >
 LinInterpolatedTable1D (const std::vector< std::pair< RealN, RealN > > &v, unsigned npoints, bool leftExtrapolationLinear, bool rightExtrapolationLinear)
 
 LinInterpolatedTable1D (double c)
 
unsigned npoints () const
 
bool operator!= (const LinInterpolatedTable1D &r) const
 
virtual double operator() (const double &x) const
 
bool operator== (const LinInterpolatedTable1D &r) const
 
bool rightExtrapolationLinear () const
 
double xmax () const
 
double xmin () const
 
virtual ~LinInterpolatedTable1D ()
 

Static Private Member Functions

static double interpolateSimple (const double x0, const double x1, const double y0, const double y1, const double x)
 

Private Attributes

double binwidth_
 
std::vector< double > data_
 
bool leftExtrapolationLinear_
 
bool monotonicityKnown_
 
bool monotonous_
 
unsigned npoints_
 
bool rightExtrapolationLinear_
 
double xmax_
 
double xmin_
 

Detailed Description

Definition at line 24 of file LinInterpolatedTable1D.h.

Constructor & Destructor Documentation

template<typename RealN >
fftjetcms::LinInterpolatedTable1D::LinInterpolatedTable1D ( const RealN *  data,
unsigned  npoints,
double  x_min,
double  x_max,
bool  leftExtrapolationLinear,
bool  rightExtrapolationLinear 
)
inline

Definition at line 114 of file LinInterpolatedTable1D.h.

References edm::hlt::Exception.

Referenced by inverse().

119  : data_(data, data+npoints),
120  xmin_(x_min),
121  xmax_(x_max),
122  binwidth_((x_max - x_min)/(npoints - 1U)),
123  npoints_(npoints),
126  monotonous_(false),
127  monotonicityKnown_(false)
128  {
129  if (!data)
130  throw cms::Exception("FFTJetBadConfig")
131  << "No data configured" << std::endl;
132  if (npoints <= 1U)
133  throw cms::Exception("FFTJetBadConfig")
134  << "Not enough data points" << std::endl;
135  }
template<typename RealN >
fftjetcms::LinInterpolatedTable1D::LinInterpolatedTable1D ( const std::vector< std::pair< RealN, RealN > > &  v,
unsigned  npoints,
bool  leftExtrapolationLinear,
bool  rightExtrapolationLinear 
)

Definition at line 138 of file LinInterpolatedTable1D.h.

References binwidth_, data_, edm::hlt::Exception, first, i, interpolateSimple(), npoints_, edm::second(), edm::shift, findQualityFiles::v, x, xmax_, and xmin_.

143  : xmin_(v[0].first),
144  xmax_(v[v.size() - 1U].first),
145  binwidth_((xmax_ - xmin_)/(npoints - 1U)),
146  npoints_(npoints),
149  monotonous_(false),
150  monotonicityKnown_(false)
151  {
152  const unsigned len = v.size();
153  if (len <= 1U)
154  throw cms::Exception("FFTJetBadConfig")
155  << "Not enough data for interpolation"
156  << std::endl;
157 
158  if (npoints <= 1U)
159  throw cms::Exception("FFTJetBadConfig")
160  << "Not enough interpolation table entries"
161  << std::endl;
162 
163  const std::pair<RealN,RealN>* vdata = &v[0];
164  for (unsigned i=1; i<len; ++i)
165  if (vdata[i-1U].first >= vdata[i].first)
166  throw cms::Exception("FFTJetBadConfig")
167  << "Input data is not sorted properly"
168  << std::endl;
169 
170  unsigned shift = 0U;
172  {
173  ++npoints_;
174  xmin_ -= binwidth_;
175  shift = 1U;
176  }
178  {
179  ++npoints_;
180  xmax_ += binwidth_;
181  }
182 
183  data_.resize(npoints_);
184 
186  {
188  vdata[0].first, vdata[1].first,
189  vdata[0].second, vdata[1].second, xmin_);
190  }
192  {
194  vdata[len - 2U].first, vdata[len - 1U].first,
195  vdata[len - 2U].second, vdata[len - 1U].second, xmax_);
196  }
197 
198  data_[shift] = vdata[0].second;
199  data_[npoints - 1U + shift] = vdata[len - 1U].second;
200  unsigned ibelow = 0, iabove = 1;
201  for (unsigned i=1; i<npoints-1; ++i)
202  {
203  const double x = xmin_ + (i + shift)*binwidth_;
204  while (static_cast<double>(v[iabove].first) <= x)
205  {
206  ++ibelow;
207  ++iabove;
208  }
209  if (v[ibelow].first == v[iabove].first)
210  data_[i + shift] = (v[ibelow].second + v[iabove].second)/2.0;
211  else
213  v[ibelow].first, v[iabove].first,
214  v[ibelow].second, v[iabove].second, x);
215  }
216  }
int i
Definition: DBlmapReader.cc:9
U second(std::pair< T, U > const &p)
static double interpolateSimple(const double x0, const double x1, const double y0, const double y1, const double x)
bool first
Definition: L1TdeRCT.cc:94
static unsigned int const shift
Definition: DDAxes.h:10
fftjetcms::LinInterpolatedTable1D::LinInterpolatedTable1D ( double  c)
explicit
virtual fftjetcms::LinInterpolatedTable1D::~LinInterpolatedTable1D ( )
inlinevirtual

Definition at line 50 of file LinInterpolatedTable1D.h.

50 {}

Member Function Documentation

const double* fftjetcms::LinInterpolatedTable1D::data ( ) const
inline

Definition at line 68 of file LinInterpolatedTable1D.h.

References data_.

Referenced by cuy.FindIssue::__init__().

68 {return &data_[0];}
static double fftjetcms::LinInterpolatedTable1D::interpolateSimple ( const double  x0,
const double  x1,
const double  y0,
const double  y1,
const double  x 
)
inlinestaticprivate

Definition at line 90 of file LinInterpolatedTable1D.h.

Referenced by LinInterpolatedTable1D().

94  {
95  return y0 + (y1 - y0)*((x - x0)/(x1 - x0));
96  }
Definition: DDAxes.h:10
std::auto_ptr< LinInterpolatedTable1D > fftjetcms::LinInterpolatedTable1D::inverse ( unsigned  npoints,
bool  leftExtrapolationLinear,
bool  rightExtrapolationLinear 
) const

Definition at line 46 of file LinInterpolatedTable1D.cc.

References binwidth_, data_, i, isMonotonous(), LinInterpolatedTable1D(), npoints_, NULL, xmax_, and xmin_.

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,
75  }
int i
Definition: DBlmapReader.cc:9
#define NULL
Definition: scimark2.h:8
LinInterpolatedTable1D(const RealN *data, unsigned npoints, double x_min, double x_max, bool leftExtrapolationLinear, bool rightExtrapolationLinear)
bool fftjetcms::LinInterpolatedTable1D::isMonotonous ( ) const

Definition at line 29 of file LinInterpolatedTable1D.cc.

References data_, delta, i, monotonicityKnown_, monotonous_, and npoints_.

Referenced by inverse().

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  }
dbl * delta
Definition: mlp_gen.cc:36
int i
Definition: DBlmapReader.cc:9
bool fftjetcms::LinInterpolatedTable1D::leftExtrapolationLinear ( ) const
inline
unsigned fftjetcms::LinInterpolatedTable1D::npoints ( ) const
inline

Definition at line 63 of file LinInterpolatedTable1D.h.

References npoints_.

bool fftjetcms::LinInterpolatedTable1D::operator!= ( const LinInterpolatedTable1D r) const
inline

Definition at line 57 of file LinInterpolatedTable1D.h.

References alignCSCRings::r.

58  {return !(*this == r);}
double fftjetcms::LinInterpolatedTable1D::operator() ( const double &  x) const
virtual

Definition at line 77 of file LinInterpolatedTable1D.cc.

References binwidth_, data_, delta, leftExtrapolationLinear_, npoints_, rightExtrapolationLinear_, xmax_, and xmin_.

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] - (
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  }
dbl * delta
Definition: mlp_gen.cc:36
Definition: DDAxes.h:10
bool fftjetcms::LinInterpolatedTable1D::operator== ( const LinInterpolatedTable1D r) const

Definition at line 17 of file LinInterpolatedTable1D.cc.

References binwidth_, data_, leftExtrapolationLinear_, npoints_, rightExtrapolationLinear_, xmax_, and xmin_.

19  {
20  return xmin_ == r.xmin_ &&
21  xmax_ == r.xmax_ &&
22  binwidth_ == r.binwidth_ &&
23  npoints_ == r.npoints_ &&
24  leftExtrapolationLinear_ == r.leftExtrapolationLinear_ &&
25  rightExtrapolationLinear_ == r.rightExtrapolationLinear_ &&
26  data_ == r.data_;
27  }
bool fftjetcms::LinInterpolatedTable1D::rightExtrapolationLinear ( ) const
inline
double fftjetcms::LinInterpolatedTable1D::xmax ( ) const
inline

Definition at line 62 of file LinInterpolatedTable1D.h.

References xmax_.

Referenced by svgfig.XAxis::__repr__().

double fftjetcms::LinInterpolatedTable1D::xmin ( ) const
inline

Member Data Documentation

double fftjetcms::LinInterpolatedTable1D::binwidth_
private

Definition at line 101 of file LinInterpolatedTable1D.h.

Referenced by inverse(), LinInterpolatedTable1D(), operator()(), and operator==().

std::vector<double> fftjetcms::LinInterpolatedTable1D::data_
private
bool fftjetcms::LinInterpolatedTable1D::leftExtrapolationLinear_
private

Definition at line 103 of file LinInterpolatedTable1D.h.

Referenced by leftExtrapolationLinear(), operator()(), and operator==().

bool fftjetcms::LinInterpolatedTable1D::monotonicityKnown_
mutableprivate

Definition at line 106 of file LinInterpolatedTable1D.h.

Referenced by isMonotonous().

bool fftjetcms::LinInterpolatedTable1D::monotonous_
mutableprivate

Definition at line 105 of file LinInterpolatedTable1D.h.

Referenced by isMonotonous().

unsigned fftjetcms::LinInterpolatedTable1D::npoints_
private
bool fftjetcms::LinInterpolatedTable1D::rightExtrapolationLinear_
private

Definition at line 104 of file LinInterpolatedTable1D.h.

Referenced by operator()(), operator==(), and rightExtrapolationLinear().

double fftjetcms::LinInterpolatedTable1D::xmax_
private
double fftjetcms::LinInterpolatedTable1D::xmin_
private