herwig is hosted by Hepforge, IPPP Durham
Herwig 7.3.0
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
16namespace 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.
linear_interpolator()
default constructor
std::map< double, double > interpolation_
map points to values
linear_interpolator(const std::map< double, double > &points)
construct a linear interpolator given the map of interpolation points and values
void set_interpolation(double point, double value)
set the value at the given point
bool invertible(double f) const
return true, if an inverse exists for the given value
std::map< double, double > & interpolation()
access the interpolation map
void put(OStream &os) const
put to ostream
void reset()
reset after interpolation points have been changed
double operator()(double x) const
return the interpolations value at the given point
void get(IStream &is)
get from istream
std::pair< double, double > range_
the range of the interpolation
std::pair< double, double > range() const
return the range of the interpolation
double unique_inverse(double f) const
return the inverse, assuming the inverse is unique
vector< T > & operator>>(vector< T > &tv, U &u)
vector< T > & operator<<(vector< T > &tv, const U &u)
Exception thrown, if a constant piece of the interpolation has been hit.
double value
The value of the interpolation in the range.
constant_interpolation(double xlow, double xhigh, double h)
standard constructor
std::pair< double, double > range
The range in which the interpolation is constant.
Exception thrown, if inversion of the interpolation has no solution.