5 #include "Alignment/Geners/interface/binaryIO.hh" 6 #include "Alignment/Geners/interface/IOException.hh" 15 "In npstat::GridAxis::initialize: insufficient number " 16 "of coordinates (at least 2 are required)");
21 for (
unsigned i = 0;
i <
npt_; ++
i) {
24 "In npstat::GridAxis::initialize: in log space" 25 "all coordinates must be positive");
31 for (
unsigned i = 1;
i <
npt_; ++
i)
32 if (c[
i] <= c[
i - 1
U])
34 "In npstat::GridAxis::initialize: " 35 "all coordinates must be distinct");
54 return std::pair<unsigned, double>(0
U, 1.0);
55 else if (x >= c[
npt_ - 1U])
56 return std::pair<unsigned, double>(
npt_ - 2
U, 0.0);
61 const double*
l = &
logs_[0];
62 const double w = 1.0 - (
log(x) - l[ibnd]) / (l[ibnd + 1U] - l[ibnd]);
63 return std::pair<unsigned, double>(ibnd,
w);
65 const double w = 1.0 - (x - c[ibnd]) / (c[ibnd + 1U] - c[ibnd]);
66 return std::pair<unsigned, double>(ibnd,
w);
78 const double*
l = &
logs_[0];
79 const double bw = l[1] - l[0];
80 return std::pair<unsigned, double>(0
U, 1.0 - (
log(x) - l[0]) / bw);
82 const double bw = c[1] - c[0];
83 return std::pair<unsigned, double>(0
U, 1.0 - (x - c[0]) / bw);
85 }
else if (x >= c[
npt_ - 1
U]) {
87 const double*
l = &
logs_[0];
89 return std::pair<unsigned, double>(
npt_ - 2
U, (l[
npt_ - 1
U] -
log(x)) / bw);
92 return std::pair<unsigned, double>(
npt_ - 2
U, (c[
npt_ - 1
U] - x) / bw);
98 const double*
l = &
logs_[0];
99 const double w = 1.0 - (
log(x) - l[ibnd]) / (l[ibnd + 1
U] - l[ibnd]);
100 return std::pair<unsigned, double>(ibnd,
w);
102 const double w = 1.0 - (x - c[ibnd]) / (c[ibnd + 1
U] - c[ibnd]);
103 return std::pair<unsigned, double>(ibnd,
w);
111 gs::write_pod_vector(of,
coords_);
112 gs::write_pod(of,
label_);
118 static const gs::ClassId current(gs::ClassId::makeId<GridAxis>());
119 current.ensureSameId(
id);
121 std::vector<double>
coords;
122 gs::read_pod_vector(in, &coords);
125 gs::read_pod(in, &label);
128 gs::read_pod(in, &useLogSpace);
131 throw gs::IOReadFailure(
132 "In npstat::GridAxis::read: " 133 "input stream failure");
134 return new GridAxis(coords, label.c_str(), useLogSpace);
144 const unsigned long n =
coords_.size();
147 for (
unsigned long i = 0;
i <
n; ++
i)
std::pair< unsigned, double > getInterval(double coordinate) const
const std::string & label() const
bool closeWithinTolerance(const double &a, const double &b, const double &tol)
bool operator==(const GridAxis &r) const
Exceptions for the npstat namespace.
Non-uniformly spaced coordinate sets for use in constructing rectangular grids.
Determine if two doubles are within requested relative tolerance of each other.
bool isClose(const GridAxis &r, double tol) const
std::vector< double > logs_
static GridAxis * read(const gs::ClassId &id, std::istream &in)
const std::vector< double > & coords() const
bool write(std::ostream &of) const
std::pair< unsigned, double > linearInterval(double coordinate) const
std::vector< double > coords_