Mantid
Loading...
Searching...
No Matches
ExtractFFTSpectrum.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 +
7//----------------------------------------------------------------------
8// Includes
9//----------------------------------------------------------------------
11#include "MantidAPI/Axis.h"
16#include "MantidKernel/Unit.h"
18
19namespace Mantid::Algorithms {
20
21// Register the algorithm into the AlgorithmFactory
22DECLARE_ALGORITHM(ExtractFFTSpectrum)
23
24using namespace Kernel;
25using namespace API;
26using namespace DataObjects;
27
29 declareProperty(std::make_unique<WorkspaceProperty<>>("InputWorkspace", "", Direction::Input),
30 "The input workspace.");
31 // if desired, provide the imaginary part in a separate workspace.
33 std::make_unique<WorkspaceProperty<>>("InputImagWorkspace", "", Direction::Input, PropertyMode::Optional),
34 "The optional input workspace for the imaginary part.");
35 declareProperty("FFTPart", 2, std::make_shared<BoundedValidator<int>>(0, 5),
36 "Spectrum number, one of the six possible spectra output by "
37 "the FFT algorithm");
38 declareProperty(std::make_unique<WorkspaceProperty<>>("OutputWorkspace", "", Direction::Output),
39 "The output workspace.");
40 declareProperty("Shift", 0.0,
41 "Apply an extra phase equal to this quantity "
42 "times 2*pi to the transform");
43 declareProperty("AutoShift", false,
44 "Automatically calculate and apply phase shift. Zero on the "
45 "X axis is assumed to be in the centre - if it is not, "
46 "setting this property will automatically correct for this.");
47 declareProperty("AcceptXRoundingErrors", false, "Continue to process the data even if X values are not evenly spaced",
49}
50
52 MatrixWorkspace_sptr inputWS = getProperty("InputWorkspace");
53 MatrixWorkspace_sptr inputImagWS = getProperty("InputImagWorkspace");
54 const double shift = getProperty("Shift");
55 const bool autoShift = getProperty("AutoShift");
56 const bool xRoundingErrs = getProperty("AcceptXRoundingErrors");
57 const int fftPart = getProperty("FFTPart");
58 const auto numHists = static_cast<int>(inputWS->getNumberHistograms());
59 MatrixWorkspace_sptr outputWS = create<MatrixWorkspace>(*inputWS);
60
61 Progress prog(this, 0.0, 1.0, numHists);
62
64 for (int i = 0; i < numHists; i++) {
66
67 auto childFFT = createChildAlgorithm("FFT");
68 childFFT->setProperty<MatrixWorkspace_sptr>("InputWorkspace", inputWS);
69 childFFT->setProperty<int>("Real", i);
70 if (inputImagWS) {
71 childFFT->setProperty<MatrixWorkspace_sptr>("InputImagWorkspace", inputImagWS);
72 childFFT->setProperty<int>("Imaginary", i);
73 }
74 childFFT->setProperty<double>("Shift", shift);
75 childFFT->setProperty<bool>("AutoShift", autoShift);
76 childFFT->setProperty<bool>("AcceptXRoundingErrors", xRoundingErrs);
77 childFFT->execute();
78 MatrixWorkspace_const_sptr fftTemp = childFFT->getProperty("OutputWorkspace");
79 if (i == 0) {
80 outputWS->getAxis(0)->unit() = fftTemp->getAxis(0)->unit();
81 }
82 outputWS->setHistogram(i, fftTemp->histogram(fftPart));
83
84 prog.report();
85
87 }
89
90 if (!inputImagWS && fftPart <= 2) {
91 // In this case, trim half of the workspace, as these are just zeros.
92 const double xMax = outputWS->x(0)[(outputWS->x(0).size() / 2) - 1];
93
94 auto extractSpectra = createChildAlgorithm("ExtractSpectra");
95 extractSpectra->setProperty<MatrixWorkspace_sptr>("InputWorkspace", outputWS);
96 extractSpectra->setProperty<MatrixWorkspace_sptr>("OutputWorkspace", outputWS);
97 extractSpectra->setProperty("XMax", xMax);
98 extractSpectra->execute();
99 }
100
101 setProperty("OutputWorkspace", outputWS);
102}
103} // namespace Mantid::Algorithms
#define DECLARE_ALGORITHM(classname)
Definition Algorithm.h:538
#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.
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.
Helper class for reporting progress from algorithms.
Definition Progress.h:25
A property class for workspaces.
void exec() override
Execution code.
void init() override
Initialisation code.
BoundedValidator is a validator that requires the values to be between upper or lower bounds,...
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
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.
@ Input
An input workspace.
Definition Property.h:53
@ Output
An output workspace.
Definition Property.h:54