19#include "MantidHistogramData/Histogram.h"
31using namespace Kernel;
32using namespace DataObjects;
33using namespace HistogramData;
46 "The name of the input 2D workspace.");
49 "The name of the output 2D workspace.");
51 "ApodizationFunction",
"None",
52 std::make_shared<Mantid::Kernel::StringListValidator>(std::vector<std::string>{
"None",
"Lorentz",
"Gaussian"}),
53 "The apodization function to apply to the data");
54 declareProperty(
"DecayConstant", 1.5,
"The decay constant for the apodization function.");
55 auto mustBePositive = std::make_shared<Kernel::BoundedValidator<int>>();
56 mustBePositive->setLower(0);
57 declareProperty(
"Padding", 0, mustBePositive,
58 "The amount of padding to add to the data,"
59 "it is the number of multiples of the data set."
60 "i.e 0 means no padding and 1 will double the number of data points.");
61 declareProperty(
"NegativePadding",
false,
62 "If true padding is added to "
63 "both sides of the original data. Both sides "
73 auto numSpectra = inputWS->getNumberHistograms();
76 if (inputWS != outputWS) {
77 outputWS = create<API::MatrixWorkspace>(*inputWS);
81 for (
size_t i = 0; i < static_cast<size_t>(numSpectra); ++i) {
82 outputWS->setSharedX(i, inputWS->sharedX(i));
85 std::vector<int> spectra;
86 spectra = std::vector<int>(numSpectra);
87 std::iota(spectra.begin(), spectra.end(), 0);
89 Progress prog(
this, 0.0, 1.0, numSpectra + spectra.size());
90 if (inputWS != outputWS) {
94 for (int64_t i = 0; i < int64_t(numSpectra); ++i) {
97 if (std::find(spectra.begin(), spectra.end(), i) != spectra.end()) {
98 const auto index =
static_cast<size_t>(i);
99 outputWS->setSharedY(
index, inputWS->sharedY(
index));
100 outputWS->setSharedE(
index, inputWS->sharedE(
index));
107 const std::string method =
getProperty(
"ApodizationFunction");
108 const double decayConstant =
getProperty(
"DecayConstant");
112 auto specLength =
static_cast<int>(spectra.size());
114 for (
int i = 0; i < specLength; ++i) {
116 const auto specNum =
static_cast<size_t>(spectra[i]);
118 if (spectra[i] >
static_cast<int>(numSpectra)) {
119 throw std::invalid_argument(
"The spectral index " +
std::to_string(spectra[i]) +
120 " is greater than the number of spectra!");
124 decayConstant, apodizationFunction));
132using fptr = double (*)(
const double,
const double);
140 if (method ==
"None") {
142 }
else if (method ==
"Lorentz") {
144 }
else if (method ==
"Gaussian") {
147 throw std::invalid_argument(
"The apodization function selected " + method +
" is not a valid option");
157 const double decayConstant,
fptr function) {
158 HistogramData::Histogram result(histogram);
160 auto &xData = result.mutableX();
161 auto &yData = result.mutableY();
162 auto &eData = result.mutableE();
164 for (
size_t i = 0; i < yData.size(); ++i) {
165 yData[i] *= function(xData[i], decayConstant);
166 eData[i] *= function(xData[i], decayConstant);
186 auto &xData = histogram.x();
187 auto &yData = histogram.y();
188 auto &eData = histogram.e();
189 auto incEData = eData.size() > 0 ? true :
false;
191 if (xData.size() < 2) {
192 throw std::invalid_argument(
"The xData does not contain "
193 "enought data points to add padding"
196 const double dx = xData[1] - xData[0];
197 const auto dataSize = yData.size() * (1 + padding);
200 HistogramData::Histogram result(histogram);
202 result.resize(dataSize);
203 auto &newXData = result.mutableX();
204 auto &newYData = result.mutableY();
205 auto &newEData = result.mutableE();
209 double x = xData.front() - dx;
211 bool negativePadding =
getProperty(
"NegativePadding");
212 if (negativePadding) {
214 offset = padding * yData.size() / 2;
215 x -= dx * double(offset);
219 std::generate(newXData.begin(), newXData.end(), [&
x, &dx] {
226 std::fill(newYData.begin(), newYData.end(), 0.0);
228 std::copy(yData.begin(), yData.end(), newYData.begin() + offset);
232 std::fill(newEData.begin(), newEData.end(), 0.0);
233 std::copy(eData.begin(), eData.end(), newEData.begin() + offset);
#define DECLARE_ALGORITHM(classname)
std::map< DeltaEMode::Type, std::string > index
#define PARALLEL_START_INTERRUPT_REGION
Begins a block to skip processing is the algorithm has been interupted Note the end of the block if n...
#define PARALLEL_END_INTERRUPT_REGION
Ends a block to skip processing is the algorithm has been interupted Note the start of the block if n...
#define PARALLEL_FOR_IF(condition)
Empty definitions - to enable set your complier to enable openMP.
#define PARALLEL_CHECK_INTERRUPT_REGION
Adds a check after a Parallel region to see if it was interupted.
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
Helper class for reporting progress from algorithms.
A property class for workspaces.
Takes a workspace as input and applies a apodization function and/or padding.
void exec() override
Executes the algorithm.
HistogramData::Histogram addPadding(const HistogramData::Histogram &histogram, const int padding)
Adds padding to the data.
double(*)(const double, const double) fptr
HistogramData::Histogram applyApodizationFunction(const HistogramData::Histogram &histogram, const double decayConstant, fptr function)
Applies the appodization function to the data.
fptr getApodizationFunction(const std::string &method)
Gets a pointer to the relevant apodization function.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
void report()
Increments the loop counter by 1, then sends the progress notification on behalf of its algorithm.
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
double none(const double, const double)
Returns no apodization function.
double lorentz(double time, double decayConstant)
Returns the evaluation of the Lorentz (an exponential decay) apodization function at a time (t) and d...
double gaussian(const double time, const double decayConstant)
Returns the evaluation of the Gaussian apodization function at a time (t) and decay constant tau: f =...
double(*)(const double, const double) fptr
std::enable_if< std::is_pointer< Arg >::value, bool >::type threadSafe(Arg workspace)
Thread-safety check Checks the workspace to ensure it is suitable for multithreaded access.
std::string to_string(const wide_integer< Bits, Signed > &n)
@ Input
An input workspace.
@ Output
An output workspace.