11#include "MantidIndexing/Extract.h"
12#include "MantidIndexing/IndexInfo.h"
24using namespace Kernel;
32 "Name of the input workspace");
34 "The name of the workspace to be created as the output of the algorithm");
36 auto mustBePositive = std::make_shared<BoundedValidator<int>>();
37 mustBePositive->setLower(0);
39 "The number of points for averaging, i.e. summing will be done in the\n"
40 "range [y(i-m),y(i+m)]");
41 declareProperty(
"Z", 0, mustBePositive,
"The number of iteration steps in the averaging procedure");
42 declareProperty(
"WorkspaceIndexMin", 0, mustBePositive,
"Lower bound of the spectrum range (default 0)");
43 declareProperty(
"WorkspaceIndexMax", 0, mustBePositive,
"Upper bound of the spectrum range (default workspace max)");
52 std::ostringstream message;
58 auto n_hists =
static_cast<int>(inputWS->getNumberHistograms());
60 if (spec_min == 0 && spec_max == 0)
61 spec_max = n_hists - 1;
63 if (spec_min > spec_max)
64 std::swap(spec_min, spec_max);
66 if (spec_max > n_hists) {
67 message <<
"WorkspaceIndexMax " << spec_max <<
" > number of histograms, WorkspaceIndexMax reset to "
71 spec_max = n_hists - 1;
77 const int n_av =
m_z *
m_m + 1;
82 const int n_points =
static_cast<int>(inputWS->y(0).size()) - 2 * n_av;
84 throw std::invalid_argument(
"Invalid (M,Z) values");
87 auto out = DataObjects::create<HistoWorkspace>(*inputWS, Indexing::extract(inputWS->indexInfo(), spec_min, spec_max),
88 HistogramData::BinEdges(n_points + 1));
90 const int nsteps = 2 * n_av + 1;
92 std::shared_ptr<API::Progress>
progress = std::make_shared<API::Progress>(
this, 0.0, 1.0, (spec_max - spec_min));
93 for (
int i = spec_min; i <= spec_max; i++) {
94 int out_index = i - spec_min;
95 const auto &refX = inputWS->x(i);
96 const auto &refY = inputWS->y(i);
97 const auto &refE = inputWS->e(i);
98 auto &outX = out->mutableX(out_index);
99 auto &outY = out->mutableY(out_index);
100 auto &outE = out->mutableE(out_index);
102 std::copy(refX.begin() + n_av, refX.end() - n_av, outX.begin());
104 auto itInY = refY.cbegin();
105 auto itOutY = outY.begin();
106 auto itInE = refE.cbegin();
107 auto itOutE = outE.begin();
108 for (; itOutY != outY.end(); ++itOutY, ++itInY, ++itOutE, ++itInE) {
110 (*itOutY) = std::inner_product(itInY, itInY + nsteps,
m_Cij.begin(), 0.0);
112 double err2 = std::inner_product(itInE, itInE + nsteps,
m_Cij2.cbegin(), 0.0);
113 (*itOutE) = sqrt(err2);
124 int max_index_prev = 1;
126 std::vector<double> previous(n_el_prev);
134 m_Cij.assign(previous.begin(), previous.end());
139 std::vector<double> next;
143 int max_index = zz *
m_m + 1;
144 int n_el = 2 * max_index + 1;
146 std::fill(next.begin(), next.end(), 0.0);
147 for (
int i = 0; i < n_el; ++i) {
148 int delta = -max_index + i;
150 int index = l + max_index_prev;
152 next[i] += previous[
index];
156 max_index_prev = max_index;
161 m_Cij.assign(previous.begin(), previous.end());
#define DECLARE_ALGORITHM(classname)
std::map< DeltaEMode::Type, std::string > index
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.
void progress(double p, const std::string &msg="", double estimatedTime=0.0, int progressPrecision=0)
Sends ProgressNotification.
A property class for workspaces.
int m_z
Contains the value of the property z.
std::vector< double > m_Cij2
Vector that contains the prefactor coefficients Cij^2 in the range [-zm-1,zm+1].
void init() override
Initialisation code.
std::vector< double > m_Cij
Vector that contains the prefactor coefficients Cij in the range [-zm-1,zm+1].
int m_m
Contains the value of the property m.
void exec() override
Execution code.
void computePrefactors()
Compute the Cij.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
void information(const std::string &msg)
Logs at information level.
std::shared_ptr< const MatrixWorkspace > MatrixWorkspace_const_sptr
shared pointer to the matrix workspace base class (const version)
@ Input
An input workspace.
@ Output
An output workspace.