Mantid
Loading...
Searching...
No Matches
SassenaFFT.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
12#include "MantidAPI/Axis.h"
20
21namespace Mantid::Algorithms {
22
23// Register the class into the algorithm factory
24DECLARE_ALGORITHM(SassenaFFT)
25
26
27bool SassenaFFT::checkGroups() { return false; }
28
31 const std::string errMessg = "processGroups must not be called from SassenaFFT";
32 this->g_log.error(errMessg);
33 throw std::logic_error(errMessg);
34}
35
42 this->declareProperty(
43 std::make_unique<API::WorkspaceProperty<API::WorkspaceGroup>>("InputWorkspace", "", Kernel::Direction::InOut),
44 "The name of the input group workspace");
45 // properties for the detailed balance condition
46 this->declareProperty(
47 std::make_unique<Kernel::PropertyWithValue<bool>>("FFTonlyRealPart", false, Kernel::Direction::Input),
48 "Do we FFT only the real part of I(Q,t)? (optional, default is False)");
49 this->declareProperty(
50 std::make_unique<Kernel::PropertyWithValue<bool>>("DetailedBalance", false, Kernel::Direction::Input),
51 "Do we apply detailed balance condition? (optional, default is False)");
52 this->declareProperty("Temp", 300.0, "Multiply structure factor by exp(E/(2*kT)");
53 this->setPropertySettings("Temp",
54 std::make_unique<Kernel::EnabledWhenProperty>("DetailedBalance", Kernel::IS_EQUAL_TO, "1"));
55}
56
59 const std::string gwsName = this->getPropertyValue("InputWorkspace");
60 API::WorkspaceGroup_sptr gws = this->getProperty("InputWorkspace");
61
62 const std::string ftqReName = gwsName + "_fqt.Re";
63 const std::string ftqImName = gwsName + "_fqt.Im";
64
65 // Make sure the intermediate structure factor is there
66 if (!gws->contains(ftqReName)) {
67 const std::string errMessg = "workspace " + gwsName + " does not contain an intermediate structure factor";
68 this->g_log.error(errMessg);
69 throw Kernel::Exception::NotFoundError("group workspace does not contain", ftqReName);
70 }
71
72 // Retrieve the real and imaginary parts of the intermediate scattering
73 // function
74 DataObjects::Workspace2D_sptr fqtRe = std::dynamic_pointer_cast<DataObjects::Workspace2D>(gws->getItem(ftqReName));
75 DataObjects::Workspace2D_sptr fqtIm = std::dynamic_pointer_cast<DataObjects::Workspace2D>(gws->getItem(ftqImName));
76
77 // Calculate the FFT for all spectra, retaining only the real part since
78 // F(q,-t) = F*(q,t)
79 int part = 3; // extract the real part of the transform, assuming I(Q,t) is real
80 const std::string sqwName = gwsName + "_sqw";
81 auto fft = createChildAlgorithm("ExtractFFTSpectrum");
82 fft->setProperty<DataObjects::Workspace2D_sptr>("InputWorkspace", fqtRe);
83 if (!this->getProperty("FFTonlyRealPart")) {
84 part = 0; // extract the real part of the transform, assuming I(Q,t) is complex
85 fft->setProperty<DataObjects::Workspace2D_sptr>("InputImagWorkspace", fqtIm);
86 }
87 fft->setPropertyValue("OutputWorkspace", sqwName);
88 fft->setProperty<int>("FFTPart", part); // extract the real part
89 fft->executeAsChildAlg();
90 API::MatrixWorkspace_sptr sqw0 = fft->getProperty("OutputWorkspace");
91 DataObjects::Workspace2D_sptr sqw = std::dynamic_pointer_cast<DataObjects::Workspace2D>(sqw0);
92 API::AnalysisDataService::Instance().addOrReplace(sqwName, sqw);
93
94 // Transform the X-axis to appropriate dimensions
95 // We assume the units of the intermediate scattering function are in
96 // picoseconds
97 // The resulting frequency unit is in mili-eV, thus use m_ps2meV
98 auto scaleX = createChildAlgorithm("ScaleX");
99 scaleX->setProperty<DataObjects::Workspace2D_sptr>("InputWorkspace", sqw);
100 scaleX->setProperty<double>("Factor", m_ps2meV);
101 scaleX->setProperty<DataObjects::Workspace2D_sptr>("OutputWorkspace", sqw);
102 scaleX->executeAsChildAlg();
103
104 // Do we apply the detailed balance condition exp(E/(2*kT)) ?
105 if (this->getProperty("DetailedBalance")) {
106 double T = this->getProperty("Temp");
107 // The ExponentialCorrection algorithm assumes the form C0*exp(-C1*x). Note
108 // the explicit minus in the exponent
109 auto ec = createChildAlgorithm("ExponentialCorrection");
110 ec->setProperty<DataObjects::Workspace2D_sptr>("InputWorkspace", sqw);
111 ec->setProperty<DataObjects::Workspace2D_sptr>("OutputWorkspace", sqw);
112 ec->setProperty<double>("C0", 1.0);
113 ec->setProperty<double>("C1", -1.0 / (2.0 * T * m_T2ueV)); // Temperature in units of ueV
114 ec->setPropertyValue("Operation", "Multiply");
115 ec->executeAsChildAlg();
116 }
117
118 // Set the Energy unit for the X-axis
119 sqw->getAxis(0)->unit() = Kernel::UnitFactory::Instance().create("DeltaE");
120
121 // Add to group workspace, except if we are replacing the workspace. In this
122 // case, the group workspace
123 // is already notified of the changes by the analysis data service.
124 if (!gws->contains(sqwName)) {
125 gws->add(sqwName);
126 } else {
127 this->g_log.information("Workspace " + sqwName + " replaced with new contents");
128 }
129}
130
131} // namespace Mantid::Algorithms
#define DECLARE_ALGORITHM(classname)
Definition: Algorithm.h:576
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
std::string getPropertyValue(const std::string &name) const override
Get the value of a property as a string.
Definition: Algorithm.cpp:2026
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
Kernel::Logger & g_log
Definition: Algorithm.h:451
A property class for workspaces.
Perform Fourier Transform of the Sassena Intermediate Scattering Function.
Definition: SassenaFFT.h:26
void init() override
Initialise the algorithm.
Definition: SassenaFFT.cpp:41
static constexpr double m_T2ueV
Definition: SassenaFFT.h:53
void exec() override
Execute the algorithm.
Definition: SassenaFFT.cpp:58
bool processGroups() override
processGroups must not be called
Definition: SassenaFFT.cpp:30
Exception for when an item is not found in a collection.
Definition: Exception.h:145
void setPropertySettings(const std::string &name, std::unique_ptr< IPropertySettings > settings)
void error(const std::string &msg)
Logs at error level.
Definition: Logger.cpp:77
void information(const std::string &msg)
Logs at information level.
Definition: Logger.cpp:105
The concrete, templated class for properties.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
std::shared_ptr< WorkspaceGroup > WorkspaceGroup_sptr
shared pointer to Mantid::API::WorkspaceGroup
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
std::shared_ptr< Workspace2D > Workspace2D_sptr
shared pointer to Mantid::DataObjects::Workspace2D
@ InOut
Both an input & output workspace.
Definition: Property.h:55
@ Input
An input workspace.
Definition: Property.h:53