26 throw std::invalid_argument(this->
name() +
" can only be run on a MDHistoWorkspace.");
34 auto lhs = out->createIterator();
36 auto rhs = operand->createIterator();
39 if (!lhs_it || !rhs_it) {
40 throw std::logic_error(
"Histo iterators have wrong type.");
44 double lhs_s = lhs_it->getSignal();
45 double lhs_err = lhs_it->getError();
46 double rhs_s = rhs_it->getSignal();
47 double rhs_err = rhs_it->getError();
50 if ((lhs_err > 0.0) && (rhs_err > 0.0)) {
51 double rhs_err_sq = rhs_err * rhs_err;
52 double lhs_err_sq = lhs_err * lhs_err;
53 double s = (rhs_s / rhs_err_sq) + (lhs_s / lhs_err_sq);
54 double e = rhs_err_sq * lhs_err_sq / (rhs_err_sq + lhs_err_sq);
57 }
else if ((rhs_err > 0) && (lhs_err == 0)) {
59 error_sq = rhs_err * rhs_err;
60 }
else if ((lhs_err > 0) && (rhs_err == 0)) {
62 error_sq = lhs_err * lhs_err;
65 size_t pos = lhs_it->getLinearIndex();
66 out->setSignalAt(pos, signal);
67 out->setErrorSquaredAt(pos, error_sq);
68 }
while (lhs_it->next() && rhs_it->next());
75 throw std::runtime_error(this->
name() +
" can only be run with two MDHistoWorkspaces as inputs");
#define DECLARE_ALGORITHM(classname)
const std::vector< double > & rhs
An implementation of IMDIterator that iterates through a MDHistoWorkspace.
Mantid::DataObjects::MDHistoWorkspace_sptr m_rhs_histo
Mantid::DataObjects::MDHistoWorkspace_sptr m_lhs_histo
WeightedMeanMD : Find the weighted mean of two MDWorkspaces.
void execHistoScalar(Mantid::DataObjects::MDHistoWorkspace_sptr out, Mantid::DataObjects::WorkspaceSingleValue_const_sptr scalar) override
Run the algorithm with a MDHisotWorkspace as output, scalar and operand.
const std::string name() const override
Algorithm's name for identification.
void checkInputs() override
Check the inputs and throw if the algorithm cannot be run.
void execHistoHisto(Mantid::DataObjects::MDHistoWorkspace_sptr out, Mantid::DataObjects::MDHistoWorkspace_const_sptr operand) override
Run the algorithm with a MDHisotWorkspace as output and operand.
void execEvent() override
Run the algorithm with an MDEventWorkspace as output.
std::shared_ptr< const WorkspaceSingleValue > WorkspaceSingleValue_const_sptr
std::shared_ptr< MDHistoWorkspace > MDHistoWorkspace_sptr
A shared pointer to a MDHistoWorkspace.
std::shared_ptr< const MDHistoWorkspace > MDHistoWorkspace_const_sptr
A shared pointer to a const MDHistoWorkspace.