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"
14#include "MantidHistogramData/Slice.h"
17#include "MantidKernel/Unit.h"
19
20namespace Mantid::Algorithms {
21
22// Register the algorithm into the AlgorithmFactory
23DECLARE_ALGORITHM(ExtractFFTSpectrum)
24
25using namespace Kernel;
26using namespace API;
27using namespace DataObjects;
28
30 declareProperty(std::make_unique<WorkspaceProperty<>>("InputWorkspace", "", Direction::Input),
31 "The input workspace.");
32 // if desired, provide the imaginary part in a separate workspace.
34 std::make_unique<WorkspaceProperty<>>("InputImagWorkspace", "", Direction::Input, PropertyMode::Optional),
35 "The optional input workspace for the imaginary part.");
36 declareProperty("FFTPart", 2, std::make_shared<BoundedValidator<int>>(0, 5),
37 "Spectrum number, one of the six possible spectra output by "
38 "the FFT algorithm");
39 declareProperty(std::make_unique<WorkspaceProperty<>>("OutputWorkspace", "", Direction::Output),
40 "The output workspace.");
41 declareProperty("Shift", 0.0,
42 "Apply an extra phase equal to this quantity "
43 "times 2*pi to the transform");
44 declareProperty("AutoShift", false,
45 "Automatically calculate and apply phase shift. Zero on the "
46 "X axis is assumed to be in the centre - if it is not, "
47 "setting this property will automatically correct for this.");
48 declareProperty("AcceptXRoundingErrors", false, "Continue to process the data even if X values are not evenly spaced",
50}
51
53 MatrixWorkspace_sptr inputWS = getProperty("InputWorkspace");
54 MatrixWorkspace_sptr inputImagWS = getProperty("InputImagWorkspace");
55 const double shift = getProperty("Shift");
56 const bool autoShift = getProperty("AutoShift");
57 const bool xRoundingErrs = getProperty("AcceptXRoundingErrors");
58 const int fftPart = getProperty("FFTPart");
59 const auto numHists = static_cast<int>(inputWS->getNumberHistograms());
60 MatrixWorkspace_sptr outputWS = create<MatrixWorkspace>(*inputWS);
61
62 Progress prog(this, 0.0, 1.0, numHists);
63
64 Mantid::Kernel::Unit_sptr unit; // must retrieve this from the child FFT
66 for (int i = 0; i < numHists; i++) {
68
69 auto childFFT = createChildAlgorithm("FFT");
70 childFFT->setProperty<MatrixWorkspace_sptr>("InputWorkspace", inputWS);
71 childFFT->setProperty<int>("Real", i);
72 if (inputImagWS) {
73 childFFT->setProperty<MatrixWorkspace_sptr>("InputImagWorkspace", inputImagWS);
74 childFFT->setProperty<int>("Imaginary", i);
75 }
76 childFFT->setProperty<double>("Shift", shift);
77 childFFT->setProperty<bool>("AutoShift", autoShift);
78 childFFT->setProperty<bool>("AcceptXRoundingErrors", xRoundingErrs);
79 childFFT->execute();
80 MatrixWorkspace_const_sptr fftTemp = childFFT->getProperty("OutputWorkspace");
81 unit = fftTemp->getAxis(0)->unit();
82 outputWS->setHistogram(i, fftTemp->histogram(fftPart));
83
84 prog.report();
85
87 }
89
90 outputWS->getAxis(0)->unit() = unit;
91
92 if (!inputImagWS && fftPart <= 2) {
93 // In this case, trim half of the workspace, as these are just zeros.
94 const double xMax = outputWS->x(0)[(outputWS->x(0).size() / 2) - 1];
95
96 auto extractSpectra = createChildAlgorithm("ExtractSpectra");
97 extractSpectra->setProperty<MatrixWorkspace_sptr>("InputWorkspace", outputWS);
98 extractSpectra->setProperty<MatrixWorkspace_sptr>("OutputWorkspace", outputWS);
99 extractSpectra->setProperty("XMax", xMax);
100 extractSpectra->execute();
101 }
102
103 setProperty("OutputWorkspace", outputWS);
104}
105} // namespace Mantid::Algorithms
#define DECLARE_ALGORITHM(classname)
Definition: Algorithm.h:576
#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...
Definition: MultiThreaded.h:94
#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.
Definition: Algorithm.cpp:1913
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
Definition: Algorithm.cpp:2076
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.
Definition: Algorithm.cpp:842
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.
Definition: ProgressBase.h:51
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::shared_ptr< Unit > Unit_sptr
Shared pointer to the Unit base class.
Definition: Unit.h:229
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.
Definition: MultiThreaded.h:22
@ Input
An input workspace.
Definition: Property.h:53
@ Output
An output workspace.
Definition: Property.h:54