Mantid
Loading...
Searching...
No Matches
PoissonErrors.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
8
9using namespace Mantid::API;
10using namespace Mantid::Kernel;
11
12namespace Mantid::Algorithms {
13// Register the class into the algorithm factory
14DECLARE_ALGORITHM(PoissonErrors)
15
16
24std::string PoissonErrors::checkSizeCompatibility(const API::MatrixWorkspace_const_sptr lhs,
25 const API::MatrixWorkspace_const_sptr rhs) const {
26 // in order to be size compatible then the workspaces must be identically
27 // sized
28 if (lhs->size() == rhs->size()) {
29 return "";
30 } else {
31 return "Workspaces not identically sized.";
32 }
33}
34
35void PoissonErrors::performBinaryOperation(const HistogramData::Histogram &lhs, const HistogramData::Histogram &rhs,
36 HistogramData::HistogramY &YOut, HistogramData::HistogramE &EOut) {
37 // Just copy over the lhs data
38 YOut = lhs.y();
39 // Now make the fractional error the same as it was on the rhs
40 const auto bins = static_cast<int>(lhs.e().size());
41 for (int j = 0; j < bins; ++j) {
42 if (rhs.y()[j] != 0.0)
43 EOut[j] = rhs.e()[j] / rhs.y()[j] * lhs.y()[j];
44 else
45 EOut[j] = 0.0;
46 }
47}
48
49void PoissonErrors::performBinaryOperation(const HistogramData::Histogram &lhs, const double rhsY, const double rhsE,
50 HistogramData::HistogramY &YOut, HistogramData::HistogramE &EOut) {
51
52 assert(lhs.x().size() == 1);
53 // If we get here we've got two single column workspaces so it's easy.
54 YOut[0] = lhs.y()[0];
55
56 if (rhsY != 0.0)
57 EOut[0] = rhsE / rhsY * lhs.y()[0];
58 else
59 EOut[0] = 0.0;
60}
61} // namespace Mantid::Algorithms
#define DECLARE_ALGORITHM(classname)
Definition: Algorithm.h:576
const std::vector< double > & rhs
Takes a Data workspace and an original counts workspace input and updates the error values in the dat...
Definition: PoissonErrors.h:32
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...
std::shared_ptr< const MatrixWorkspace > MatrixWorkspace_const_sptr
shared pointer to the matrix workspace base class (const version)
STL namespace.