19 declareProperty(
"WarnOnZeroDivide",
true,
20 "Algorithm usually warns if "
21 "division by 0 occurs. Set this "
22 "value to false if one does not "
23 "want this message appearing ");
32 HistogramData::HistogramY &YOut, HistogramData::HistogramE &EOut) {
33 const auto bins =
static_cast<int>(lhs.e().size());
35 for (
int j = 0; j < bins; ++j) {
37 const double leftY = lhs.y()[j];
38 const double rightY =
rhs.y()[j];
47 EOut[j] = sqrt(pow(lhs.e()[j], 2) + pow(leftY *
rhs.e()[j] / rightY, 2)) /
fabs(rightY);
51 YOut[j] = leftY / rightY;
56 HistogramData::HistogramY &YOut, HistogramData::HistogramE &EOut) {
58 g_log.
warning() <<
"Division by zero: the RHS is a single-valued vector "
63 const double rhsFactor = pow(rhsE / rhsY, 2);
64 const auto bins =
static_cast<int>(lhs.e().size());
65 for (
int j = 0; j < bins; ++j) {
67 const double leftY = lhs.y()[j];
70 EOut[j] = sqrt(pow(lhs.e()[j], 2) + pow(leftY, 2) * rhsFactor) /
fabs(rhsY);
73 YOut[j] = leftY / rhsY;
86 out->setDistribution(
true);
90 if (!lhs->YUnit().empty())
91 out->setYUnit(lhs->YUnit() +
"/" +
rhs->YUnit());
93 out->setYUnit(
"1/" +
rhs->YUnit());
108 rhs.generateHistogram(
rhs.readX(), rhsY, rhsE);
123 lhs.
divide(rhsX, rhsY, rhsE);
182 if (
rhs->size() == 1)
187 if (lhs->size() == 1)
188 return "The left side cannot contain a single value if the right side "
189 "isn't also a single value.";
197 (
m_rhsBlocksize == 1 && lhs->getNumberHistograms() ==
rhs->getNumberHistograms())) {
205 return "X arrays must match when dividing 2D workspaces.";
210 const size_t rhsSpec =
rhs->getNumberHistograms();
220 if (lhs->getNumberHistograms() ==
rhs->getNumberHistograms()) {
223 return "Number of histograms not identical.";
#define DECLARE_ALGORITHM(classname)
const std::vector< double > & rhs
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
size_t m_rhsBlocksize
Cache for RHS workspace's blocksize.
bool m_keepEventWorkspace
Variable set to true if the operation allows the output to stay as an EventWorkspace.
void init() override
Initialisation method.
bool m_AllowDifferentNumberSpectra
The property value.
bool m_useHistogramForRhsEventWorkspace
Are we going to use the histogram representation of the RHS event list when performing the operation?...
bool m_matchXSize
matchXSize set to true if the X sizes of histograms must match.
bool m_flipSides
flipSides set to true if the rhs and lhs operands should be flipped - for commutative binary operatio...
void exec() override
Executes the algorithm.
DataObjects::EventWorkspace_const_sptr m_elhs
Left-hand side EventWorkspace.
Divide performs the division of two input workspaces.
std::string checkSizeCompatibility(const API::MatrixWorkspace_const_sptr lhs, const API::MatrixWorkspace_const_sptr rhs) const override
Performs a simple check to see if the sizes of two workspaces are compatible for a binary operation I...
void exec() override
Executes the algorithm.
void performEventBinaryOperation(DataObjects::EventList &lhs, const DataObjects::EventList &rhs) override
Carries out the binary operation IN-PLACE on a single EventList, with another EventList as the right-...
void setOutputUnits(const API::MatrixWorkspace_const_sptr lhs, const API::MatrixWorkspace_const_sptr rhs, API::MatrixWorkspace_sptr out) override
Should be overridden by operations that need to manipulate the units of the output workspace.
void performBinaryOperation(const HistogramData::Histogram &lhs, const HistogramData::Histogram &rhs, HistogramData::HistogramY &YOut, HistogramData::HistogramE &EOut) override
Carries out the binary operation on a single spectrum, with another spectrum as the right-hand operan...
void checkRequirements() override
Check what operation will be needed in order to apply the operation to these two types of workspaces.
void divide(const double value, const double error=0.0) override
Divide the weights in this event list by a scalar with an (optional) error.
void warning(const std::string &msg)
Logs at warning level.
std::shared_ptr< const MatrixWorkspace > MatrixWorkspace_const_sptr
shared pointer to the matrix workspace base class (const version)
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
std::vector< double > MantidVec
typedef for the data storage used in Mantid matrix workspaces
static bool matchingBins(const MatrixWorkspace &ws1, const MatrixWorkspace &ws2, const bool firstOnly=false)
Checks whether the bins (X values) of two workspace are the same.