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)");
25 "In npstat::GridAxis::initialize: in log space"
26 "all coordinates must be positive");
34 "In npstat::GridAxis::initialize: "
35 "all coordinates must be distinct");
39 const bool useLogSpace)
42 useLogSpace_(useLogSpace)
49 const bool useLogSpace)
51 label_(label ? label :
""),
53 useLogSpace_(useLogSpace)
62 "In GridAxis::getInterval: argument must be positive");
65 return std::pair<unsigned,double>(0U, 1.0);
66 else if (x >= c[
npt_ - 1U])
67 return std::pair<unsigned,double>(
npt_ - 2U, 0.0);
70 unsigned ibnd = lower_bound
75 const double*
l = &
logs_[0];
76 const double w = 1.0 - (
log(x) - l[ibnd])/
77 (l[ibnd + 1U] - l[ibnd]);
78 return std::pair<unsigned,double>(ibnd,
w);
82 const double w = 1.0 - (x - c[ibnd])/(c[ibnd + 1U] - c[ibnd]);
83 return std::pair<unsigned,double>(ibnd,
w);
92 "In GridAxis::linearInterval: argument must be positive");
98 const double*
l = &
logs_[0];
99 const double bw = l[1] - l[0];
100 return std::pair<unsigned,double>(0U, 1.0 - (
log(x) - l[0])/bw);
104 const double bw = c[1] - c[0];
105 return std::pair<unsigned,double>(0U, 1.0 - (x - c[0])/bw);
108 else if (x >= c[
npt_ - 1U])
112 const double*
l = &
logs_[0];
113 const double bw = l[
npt_ - 1U] - l[
npt_ - 2U];
114 return std::pair<unsigned,double>(
119 const double bw = c[
npt_ - 1U] - c[
npt_ - 2U];
120 return std::pair<unsigned,double>(
126 unsigned ibnd = lower_bound
131 const double*
l = &
logs_[0];
132 const double w = 1.0 - (
log(x) - l[ibnd])/
133 (l[ibnd + 1U] - l[ibnd]);
134 return std::pair<unsigned,double>(ibnd,
w);
138 const double w = 1.0 - (x - c[ibnd])/(c[ibnd + 1U] - c[ibnd]);
139 return std::pair<unsigned,double>(ibnd,
w);
148 gs::write_pod_vector(of,
coords_);
149 gs::write_pod(of,
label_);
156 static const gs::ClassId
current(gs::ClassId::makeId<GridAxis>());
157 current.ensureSameId(
id);
159 std::vector<double>
coords;
160 gs::read_pod_vector(in, &coords);
163 gs::read_pod(in, &label);
166 gs::read_pod(in, &useLogSpace);
169 throw gs::IOReadFailure(
"In npstat::GridAxis::read: "
170 "input stream failure");
171 return new GridAxis(coords, label.c_str(), useLogSpace);
186 const unsigned long n =
coords_.size();
189 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_
tuple size
Write out results.