herwig is hosted by Hepforge, IPPP Durham
Herwig  7.2.1
linear_interpolator.h
1 // -*- C++ -*-
2 //
3 // linear_interpolator.h is part of ExSample -- A Library for Sampling Sudakov-Type Distributions
4 //
5 // Copyright (C) 2008-2019 Simon Platzer -- simon.plaetzer@desy.de, The Herwig Collaboration
6 //
7 // ExSample is licenced under version 3 of the GPL, see COPYING for details.
8 // Please respect the MCnet academic guidelines, see GUIDELINES for details.
9 //
10 //
11 #ifndef EXSAMPLE_linear_interpolator_h_included
12 #define EXSAMPLE_linear_interpolator_h_included
13 
14 #include "utility.h"
15 
16 namespace exsample {
17 
21 
25 
28  double xhigh,
29  double h)
30  : range(xlow,xhigh), value(h) {}
31 
33  std::pair<double,double> range;
34 
36  double value;
37 
38  };
39 
43 
44  public:
45 
48 
51  explicit linear_interpolator(const std::map<double,double>& points);
52 
53  public:
54 
56  double operator()(double x) const;
57 
59  std::pair<double,double> range() const { return range_; }
60 
61  public:
62 
65  bool invertible(double f) const {
66  return (range_.first <= f &&
67  range_.second >= f);
68  }
69 
72  double unique_inverse(double f) const;
73 
75  std::map<double,double>& interpolation() {
76  return interpolation_;
77  }
78 
80  void set_interpolation(double point, double value);
81 
83  void reset();
84 
85  public:
86 
88  template<class OStream>
89  void put(OStream& os) const;
90 
92  template<class IStream>
93  void get(IStream& is);
94 
95  private:
96 
98  std::map<double, double> interpolation_;
99 
101  std::pair<double,double> range_;
102 
103  };
104 
106  template<class OStream>
107  inline OStream& operator<<(OStream& os, const linear_interpolator& ip) {
108  ip.put(os);
109  return os;
110  }
111 
113  template<class IStream>
114  inline IStream& operator>>(IStream& is, linear_interpolator& ip) {
115  ip.get(is);
116  return is;
117  }
118 
119 }
120 
121 #include "linear_interpolator.icc"
122 
123 #endif // EXSAMPLE_linear_interpolator_h_included
A linear interpolation allowing for inversion of the linear interpolation.
void get(IStream &is)
get from istream
std::map< double, double > interpolation_
map points to values
Exception thrown, if inversion of the interpolation has no solution.
IteratorRange< typename Container::iterator > range(Container &c)
std::pair< double, double > range_
the range of the interpolation
vector< T > & operator>>(vector< T > &tv, U &u)
std::pair< double, double > range() const
return the range of the interpolation
std::pair< double, double > range
The range in which the interpolation is constant.
double value
The value of the interpolation in the range.
void put(OStream &os) const
put to ostream
bool invertible(double f) const
return true, if an inverse exists for the given value
vector< T > & operator<<(vector< T > &tv, const U &u)
constant_interpolation(double xlow, double xhigh, double h)
standard constructor
std::map< double, double > & interpolation()
access the interpolation map
Exception thrown, if a constant piece of the interpolation has been hit.