12#include "MantidKernel/DllConfig.h"
26namespace VectorHelper {
28 const bool resize_xnew =
true,
const bool full_bins_only =
false,
29 const double xMinHint = std::nan(
""),
30 const double xMaxHint = std::nan(
""),
31 const bool useReverseLogarithmic =
false,
const double power = -1);
33void MANTID_KERNEL_DLL
rebin(
const std::vector<double> &xold,
const std::vector<double> &yold,
34 const std::vector<double> &eold,
const std::vector<double> &xnew,
35 std::vector<double> &ynew, std::vector<double> &enew,
bool distribution,
36 bool addition =
false);
39void MANTID_KERNEL_DLL
rebinHistogram(
const std::vector<double> &xold,
const std::vector<double> &yold,
40 const std::vector<double> &eold,
const std::vector<double> &xnew,
41 std::vector<double> &ynew, std::vector<double> &enew,
bool addition);
44void MANTID_KERNEL_DLL
convertToBinCentre(
const std::vector<double> &bin_edges, std::vector<double> &bin_centres);
47void MANTID_KERNEL_DLL
convertToBinBoundary(
const std::vector<double> &bin_centers, std::vector<double> &bin_edges);
69template <
typename T> std::vector<T>
flattenVector(
const std::vector<std::vector<T>> &v) {
70 std::vector<T> flattened;
72 for (
const auto &subVector : v) {
73 flattened.insert(flattened.end(), subVector.begin(), subVector.end());
79template <
typename NumT> MANTID_KERNEL_DLL std::vector<NumT> splitStringIntoVector(std::string listString);
81MANTID_KERNEL_DLL
int getBinIndex(
const std::vector<double> &bins,
const double value);
86MANTID_KERNEL_DLL
void smoothInRange(
const std::vector<double> &input, std::vector<double> &output,
double avrgInterval,
87 std::vector<double>
const *
const binBndrs =
nullptr,
size_t startIndex = 0,
88 size_t endIndex = 0, std::vector<double> *
const outBins =
nullptr);
99 for (
size_t i = 0; i <
x.size(); i++)
100 total +=
x[i] *
x[i];
106template <
typename T> T
scalar_prod(
const std::vector<T> &v1,
const std::vector<T> &v2) {
107 if (v1.size() != v2.size())
108 throw std::invalid_argument(
" scalar product is defined only for the "
109 "vectors of the equivalent length");
111 for (
size_t i = 0; i < v1.size(); i++)
112 total += v1[i] * v2[i];
118template <
typename T,
typename U>
double scalar_prod(
const std::vector<T> &v1,
const std::vector<U> &v2) {
119 if (v1.size() != v2.size())
120 throw std::invalid_argument(
" scalar product is defined only for the "
121 "vectors of the equivalient length");
123 for (
size_t i = 0; i < v1.size(); i++)
124 total +=
double(v1[i]) * double(v2[i]);
140 std::vector<T> out(
x.size(), 0);
143 for (
size_t i = 0; i <
x.size(); i++)
144 out[i] =
x[i] / length;
153 inline T
operator()(
const T &l,
const T &r)
const {
return sqrt(l * l + r * r); }
180 T
operator()(
const T &l,
const T &r)
const {
return (r * r * l * l); }
191template <
class T>
struct Log {
197 throw std::range_error(
"Attempt to take logarithm of zero or negative number.");
214 if (std::fabs(r) < 1e-12)
224 T
operator()(
const T &
x,
const T &
y)
const {
return static_cast<T
>(0.5) * (
x +
y); }
double value
The value of the point.
MANTID_KERNEL_DLL void smoothInRange(const std::vector< double > &input, std::vector< double > &output, double avrgInterval, std::vector< double > const *const binBndrs=nullptr, size_t startIndex=0, size_t endIndex=0, std::vector< double > *const outBins=nullptr)
Basic running average of input vector within specified range, considering variable bin-boundaries if ...
std::vector< T > flattenVector(const std::vector< std::vector< T > > &v)
A convenience function to "flatten" the given vector of vectors into a single vector.
size_t MANTID_KERNEL_DLL indexOfValueFromCenters(const std::vector< double > &bin_centers, const double value)
Gets the bin of a value from a vector of bin centers and throws exception if out of range.
void MANTID_KERNEL_DLL convertToBinCentre(const std::vector< double > &bin_edges, std::vector< double > &bin_centres)
Convert an array of bin boundaries to bin center values.
std::vector< T > normalizeVector(const std::vector< T > &x)
Normalize a vector of any size to unity, using the sum of the squares of the components.
bool MANTID_KERNEL_DLL isConstantValue(const std::vector< double > &arra)
Assess if all the values in the vector are equal or if there are some different values.
T lengthVector(const std::vector< T > &x)
Return the length of the vector (in the physical sense), the sqrt of the sum of the squares of the co...
MANTID_KERNEL_DLL int getBinIndex(const std::vector< double > &bins, const double value)
Return the index into a vector of bin boundaries for a particular X value.
size_t MANTID_KERNEL_DLL indexOfValueFromEdges(const std::vector< double > &bin_edges, const double value)
Gets the bin of a value from a vector of bin edges.
T scalar_prod(const std::vector< T > &v1, const std::vector< T > &v2)
int MANTID_KERNEL_DLL createAxisFromRebinParams(const std::vector< double > ¶ms, std::vector< double > &xnew, const bool resize_xnew=true, const bool full_bins_only=false, const double xMinHint=std::nan(""), const double xMaxHint=std::nan(""), const bool useReverseLogarithmic=false, const double power=-1)
Creates a new output X array given a 'standard' set of rebinning parameters.
void MANTID_KERNEL_DLL rebin(const std::vector< double > &xold, const std::vector< double > &yold, const std::vector< double > &eold, const std::vector< double > &xnew, std::vector< double > &ynew, std::vector< double > &enew, bool distribution, bool addition=false)
Rebins data according to a new output X array.
void MANTID_KERNEL_DLL rebinHistogram(const std::vector< double > &xold, const std::vector< double > &yold, const std::vector< double > &eold, const std::vector< double > &xnew, std::vector< double > &ynew, std::vector< double > &enew, bool addition)
Rebins histogram data according to a new output X array.
void MANTID_KERNEL_DLL convertToBinBoundary(const std::vector< double > &bin_centers, std::vector< double > &bin_edges)
Convert an array of bin centers to bin boundary values.
int MANTID_KERNEL_DLL indexOfValueFromCentersNoThrow(const std::vector< double > &bin_centers, const double value)
Gets the bin of a value from a vector of bin centers and returns -1 if out of range.
Helper class which provides the Collimation Length for SANS instruments.
Functor to deal with the increase in the error when adding (or subtracting) a number of counts.
T operator()(const T &r, const T &x) const
adds the square of the left-hand argument to the right hand argument and takes the square root
Divide functor with result reset to 0 if the denominator is null.
T operator()(const T &l, const T &r) const
Returns l/r if r is non-zero, otherwise returns l.
T operator()(const T &x) const
T operator()(const T &x) const
Returns the logarithm of the argument.
A binary functor to compute the simple average of 2 numbers.
T operator()(const T &x, const T &y) const
Return the average of the two arguments.
T operator()(const T &x) const
Returns the square of the argument.
Functor used for computing the sum of the square values of a vector, using the accumulate algorithm.
T operator()(const T &l, const T &r) const
Sums the arguments in quadrature.
Functor to accumulate a sum of squares.
T operator()(const T &r, const T &x) const
Adds the square of the right-hand argument to the left hand one.
Functor giving the product of the squares of the arguments.
T operator()(const T &l, const T &r) const
Multiplies the squares of the arguments.