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 - 1U])
34 "In npstat::GridAxis::initialize: "
35 "all coordinates must be distinct");
39 : coords_(coords), npt_(coords_.
size()), useLogSpace_(useLogSpace) {
44 : coords_(coords), label_(label ? label :
""), npt_(coords_.
size()), useLogSpace_(useLogSpace) {
54 return std::pair<unsigned, double>(0U, 1.0);
55 else if (x >= c[
npt_ - 1U])
56 return std::pair<unsigned, double>(
npt_ - 2U, 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>(0U, 1.0 - (
log(x) - l[0]) / bw);
82 const double bw = c[1] - c[0];
83 return std::pair<unsigned, double>(0U, 1.0 - (x - c[0]) / bw);
85 }
else if (x >= c[
npt_ - 1U]) {
87 const double*
l = &
logs_[0];
88 const double bw = l[
npt_ - 1U] - l[
npt_ - 2U];
89 return std::pair<unsigned, double>(
npt_ - 2U, (l[
npt_ - 1U] -
log(x)) / bw);
91 const double bw = c[
npt_ - 1U] - c[
npt_ - 2U];
92 return std::pair<unsigned, double>(
npt_ - 2U, (c[
npt_ - 1U] - x) / bw);
98 const double*
l = &
logs_[0];
99 const double w = 1.0 - (
log(x) - l[ibnd]) / (l[ibnd + 1U] - l[ibnd]);
100 return std::pair<unsigned, double>(ibnd,
w);
102 const double w = 1.0 - (x - c[ibnd]) / (c[ibnd + 1U] - 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)
static std::vector< std::string > checklist log
const edm::EventSetup & c
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_
__host__ __device__ constexpr RandomIt lower_bound(RandomIt first, RandomIt last, const T &value, Compare comp={})
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.