21using namespace Kernel;
26 std::make_shared<WorkspaceUnitValidator>(
"DeltaE")),
27 "The input workspace.");
29 "The name for output workspace with the X axis in units of Q");
31 "The name for output workspace with the X axis in units of Q^2.");
33 "Start Point of Range 1");
35 "End Point of Range 1");
43 double intRangeStart =
getProperty(
"IntegrationRangeStart");
44 double intRangeEnd =
getProperty(
"IntegrationRangeEnd");
45 double bgRangeStart =
getProperty(
"BackgroundRangeStart");
46 double bgRangeEnd =
getProperty(
"BackgroundRangeEnd");
54 const bool childAlgLogging(
true);
55 double startProgress(0.0), endProgress(0.0);
58 const bool axisIsSpectrumNumber = inputWorkspace->getAxis(1)->isSpectra();
59 g_log.
information() <<
"Axis is spectrum number: " << axisIsSpectrumNumber <<
'\n';
62 const bool backgroundSubtraction = !((bgRangeStart == bgRangeEnd) && (bgRangeStart ==
EMPTY_DBL()));
63 g_log.
information() <<
"Use background subtraction: " << backgroundSubtraction <<
'\n';
67 if (backgroundSubtraction)
69 if (axisIsSpectrumNumber)
72 double stepProgress = 1.0 /
static_cast<double>(numSteps);
74 if (backgroundSubtraction) {
76 auto flatBG =
createChildAlgorithm(
"CalculateFlatBackground", startProgress, endProgress, childAlgLogging);
78 flatBG->setProperty<
double>(
"StartX", bgRangeStart);
79 flatBG->setProperty<
double>(
"EndX", bgRangeEnd);
80 flatBG->setPropertyValue(
"Mode",
"Mean");
81 flatBG->setPropertyValue(
"OutputWorkspace",
"flatBG");
83 startProgress += stepProgress;
84 endProgress += stepProgress;
90 integ->setProperty<
double>(
"RangeLower", intRangeStart);
91 integ->setProperty<
double>(
"RangeUpper", intRangeEnd);
92 integ->setPropertyValue(
"OutputWorkspace",
"integ");
95 integWS = integ->getProperty(
"OutputWorkspace");
100 integ->setProperty<
double>(
"RangeLower", intRangeStart);
101 integ->setProperty<
double>(
"RangeUpper", intRangeEnd);
102 integ->setPropertyValue(
"OutputWorkspace",
"integ");
105 integWS = integ->getProperty(
"OutputWorkspace");
107 startProgress += stepProgress;
108 endProgress += stepProgress;
110 if (axisIsSpectrumNumber) {
117 csaQ->setPropertyValue(
"Target",
"ElasticQ");
118 csaQ->setPropertyValue(
"EMode",
"Indirect");
119 csaQ->setPropertyValue(
"OutputWorkspace",
"csaQ");
122 startProgress += stepProgress;
123 endProgress += stepProgress;
128 csaQ2->setPropertyValue(
"Target",
"ElasticQSquared");
129 csaQ2->setPropertyValue(
"EMode",
"Indirect");
130 csaQ2->setPropertyValue(
"OutputWorkspace",
"csaQ2");
133 startProgress += stepProgress;
134 endProgress += stepProgress;
139 tranQ->setPropertyValue(
"OutputWorkspace",
"outQ");
141 outputQ = tranQ->getProperty(
"OutputWorkspace");
142 startProgress += stepProgress;
143 endProgress += stepProgress;
148 tranQ2->setPropertyValue(
"OutputWorkspace",
"outQSquared");
150 outputQSquared = tranQ2->getProperty(
"OutputWorkspace");
155 tranQ->setPropertyValue(
"OutputWorkspace",
"outQ");
157 outputQ = tranQ->getProperty(
"OutputWorkspace");
158 startProgress += stepProgress;
159 endProgress += stepProgress;
162 auto histQ2 =
createChildAlgorithm(
"ConvertToHistogram", startProgress, endProgress, childAlgLogging);
164 histQ2->setPropertyValue(
"OutputWorkspace",
"outQ");
167 startProgress += stepProgress;
168 endProgress += stepProgress;
171 auto convUnitQ2 =
createChildAlgorithm(
"ConvertUnits", startProgress, endProgress, childAlgLogging);
173 convUnitQ2->setPropertyValue(
"Target",
"QSquared");
174 convUnitQ2->setPropertyValue(
"EMode",
"Indirect");
175 convUnitQ2->setPropertyValue(
"OutputWorkspace",
"outQSquared");
176 convUnitQ2->execute();
177 outputQSquared = convUnitQ2->getProperty(
"OutputWorkspace");
179 auto yLabel = outputQSquared->YUnitLabel();
180 outputQSquared->setYUnitLabel(
"ln(" + yLabel +
")");
#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.
A property class for workspaces.
void exec() override
Execution code.
void init() override
Initialisation code.
int version() const override
Algorithm's version.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
void information(const std::string &msg)
Logs at information level.
Validator to check that a property is not left empty.
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
constexpr double EMPTY_DBL() noexcept
Returns what we consider an "empty" double within a property.
@ Input
An input workspace.
@ Output
An output workspace.