10#include "MantidHistogramData/Histogram.h"
11#include "MantidHistogramData/HistogramBuilder.h"
17using Mantid::HistogramData::HistogramX;
18using Mantid::HistogramData::HistogramY;
32 "Input workspace for differentiation");
34 "Workspace with result derivatives");
35 auto mustBePositive = std::make_shared<BoundedValidator<int>>();
36 mustBePositive->setLower(1);
37 declareProperty(
"Order", 1, mustBePositive,
"The order of the derivative");
47 size_t n = inWS->getNumberHistograms();
50 size_t ny = inWS->y(0).size();
51 size_t nx = inWS->x(0).size();
57 HistogramBuilder builder;
58 builder.setX(nx + ny);
59 builder.setY(ny + ny);
60 builder.setDistribution(inWS->isDistribution());
63 for (
size_t spec = 0; spec <
n; ++spec) {
64 symmetriseSpectrum(inWS->histogram(spec), copyWS->mutableX(0), copyWS->mutableY(0), nx, ny);
67 const bool isHisto = copyWS->isHistogramData();
69 fft->setProperty(
"InputWorkspace", copyWS);
70 fft->setProperty(
"Real", 0);
71 fft->setProperty(
"Transform",
"Forward");
76 multiplyTransform(transWS->mutableX(3), transWS->mutableY(3), transWS->mutableY(4));
80 fft->setProperty(
"InputWorkspace", transWS);
81 fft->setProperty(
"Real", 3);
82 fft->setProperty(
"Imaginary", 4);
83 fft->setProperty(
"Transform",
"Backward");
86 transWS = fft->getProperty(
"OutputWorkspace");
91 toHisto->setProperty(
"InputWorkspace", transWS);
93 transWS = toHisto->getProperty(
"OutputWorkspace");
97 outWS = create<MatrixWorkspace>(*inWS);
101 size_t m2 = transWS->y(0).size() / 2;
102 double dx = copyWS->x(0)[m2];
104 outWS->mutableX(spec).assign(transWS->x(0).cbegin() + m2, transWS->x(0).cend());
105 outWS->mutableX(spec) += dx;
106 outWS->mutableY(spec).assign(transWS->y(0).cbegin() + m2, transWS->y(0).cend());
115 HistogramData::HistogramY &symY,
const size_t nx,
const size_t ny) {
116 const auto &inX = in.x();
117 const auto &inY = in.y();
119 const double xx = 2 * inX[0];
124 for (
size_t i = 1; i < ny; ++i) {
127 symX[j1] = xx - inX[i];
129 symY[j1] = symY[j2] = inY[i];
132 symX[0] = 2 * symX[1] - symX[2];
133 symY[0] = inY.back();
135 const bool isHist = (nx != ny);
138 symX[symY.size()] = inX[ny];
152 bool swap_re_im = dn % 2 != 0;
170 for (
size_t j = 0; j < re.size(); ++j) {
171 double w = 2 * M_PI * nu[j];
173 for (
int k = dn; k > 1; --k) {
176 double a = sign_re * re[j] * ww;
177 double b = sign_im * im[j] * ww;
#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.
virtual std::shared_ptr< Algorithm > createChildAlgorithm(const std::string &name, const double startProgress=-1., const double endProgress=-1., const bool enableLogging=true, const int &version=-1)
Create a Child Algorithm.
void progress(double p, const std::string &msg="", double estimatedTime=0.0, int progressPrecision=0)
Sends ProgressNotification.
Helper class for reporting progress from algorithms.
A property class for workspaces.
void symmetriseSpectrum(const HistogramData::Histogram &in, HistogramData::HistogramX &symX, HistogramData::HistogramY &symY, const size_t nx, const size_t ny)
void multiplyTransform(const HistogramData::HistogramX &nu, HistogramData::HistogramY &re, HistogramData::HistogramY &im)
A Fourier transform of a derivative of order n has a factor of i^n where i is the imaginary unit.
void init() override
Initialisation code.
void exec() override
Execution code.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
@ Input
An input workspace.
@ Output
An output workspace.