15using namespace DataObjects;
16using namespace Geometry;
17using namespace Kernel;
36 "An input workspace.");
38 "An output workspace.");
47 if (eventW !=
nullptr) {
48 throw std::runtime_error(
"WeightedMeanOfWorkspace cannot handle EventWorkspaces!");
53 std::size_t numHists = inputWS->getNumberHistograms();
54 double averageValue = 0.0;
55 double weightSum = 0.0;
56 const auto &spectrumInfo = inputWS->spectrumInfo();
57 for (std::size_t i = 0; i < numHists; ++i) {
58 if (spectrumInfo.hasDetectors(i))
59 if (spectrumInfo.isMonitor(i) || spectrumInfo.isMasked(i))
61 auto &
y = inputWS->y(i);
62 auto &e = inputWS->e(i);
64 for (std::size_t j = 0; j <
y.size(); ++j) {
65 if (std::isfinite(
y[j]) && std::isfinite(e[j])) {
66 weight = 1.0 / (e[j] * e[j]);
67 averageValue += (
y[j] * weight);
72 singleValued->mutableX(0)[0] = 0.0;
73 singleValued->mutableY(0)[0] = averageValue / weightSum;
74 singleValued->mutableE(0)[0] = std::sqrt(weightSum);
#define DECLARE_ALGORITHM(classname)
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
A property class for workspaces.
WeightedMeanOfWorkspace This algorithm calculates the weighted mean for a single workspace from all t...
void exec() override
Execute the algorithm.
int version() const override
Algorithm's version for identification.
void init() override
Initialize the algorithm's properties.
const std::string category() const override
Algorithm's category for identification.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
std::shared_ptr< const EventWorkspace > EventWorkspace_const_sptr
shared pointer to a const Workspace2D
Helper class which provides the Collimation Length for SANS instruments.
@ Input
An input workspace.
@ Output
An output workspace.