19using namespace DataObjects;
28 "Name of the input workspace");
30 "The file containing the correction factors");
33 propOptions.emplace_back(
"SpectrumNumber");
34 declareProperty(
"FirstColumnValue",
"Wavelength", std::make_shared<Kernel::StringListValidator>(propOptions),
35 "The units of the first column of the correction file "
36 "(default wavelength)");
38 std::vector<std::string> operations{
"Divide",
"Multiply"};
39 declareProperty(
"WorkspaceOperation",
"Divide", std::make_shared<Kernel::StringListValidator>(operations),
40 "Allowed values: Divide, Multiply (default is divide)");
42 "Name of the output workspace to store the results in");
52 const std::string operation =
getProperty(
"WorkspaceOperation");
64 if (toCorrect->getAxis(0)->unit()->unitID() != rkhInput->getAxis(0)->unit()->unitID()) {
65 g_log.
warning(
"Unit on input workspace is different to that specified in "
66 "'FirstColumnValue' property");
70 auto &Xcor = rkhInput->x(0);
71 auto &Ycor = rkhInput->y(0);
72 auto &Ecor = rkhInput->e(0);
74 const bool divide = operation ==
"Divide";
75 double Yfactor, correctError;
77 const auto nOutSpec =
static_cast<int64_t
>(outputWS->getNumberHistograms());
78 const size_t nbins = outputWS->blocksize();
80 Progress prg(
this, 0 , 1.0, nOutSpec);
82 for (int64_t i = 0; i < nOutSpec; ++i) {
83 const auto xIn = toCorrect->points(i);
84 outputWS->setSharedX(i, toCorrect->sharedX(i));
86 auto &yOut = outputWS->mutableY(i);
87 auto &eOut = outputWS->mutableE(i);
89 auto &yIn = toCorrect->y(i);
90 auto &eIn = toCorrect->e(i);
92 for (
size_t j = 0; j < nbins; ++j) {
93 const double currentX = xIn[j];
95 auto pos = std::lower_bound(Xcor.cbegin(), Xcor.cend(), currentX);
96 const size_t index = pos - Xcor.begin();
97 if (
index == Xcor.size()) {
100 Yfactor = Ycor[
index - 1];
101 correctError = Ecor[
index - 1];
105 const double fraction = (currentX - Xcor[
index - 1]) / (Xcor[
index] - Xcor[
index - 1]);
107 Yfactor = Ycor[
index - 1] + fraction * (Ycor[
index] - Ycor[
index - 1]);
108 correctError = Ecor[
index - 1] + fraction * (Ecor[
index] - Ecor[
index - 1]);
113 correctError = Ecor[0];
118 yOut[j] = yIn[j] / Yfactor;
128 eOut[j] = sqrt(pow(eIn[j], 2) + pow(yIn[j] * correctError / Yfactor, 2)) / Yfactor;
130 yOut[j] = yIn[j] * Yfactor;
137 eOut[j] = sqrt(pow(eIn[j] * Yfactor, 2) + pow(correctError * yIn[j], 2));
140 prg.
report(
"CorrectToFile: applying " + operation);
157 loadRKH->setPropertyValue(
"Filename", rkhfile);
158 loadRKH->setPropertyValue(
"OutputWorkspace",
"rkhout");
159 std::string columnValue =
getProperty(
"FirstColumnValue");
160 loadRKH->setPropertyValue(
"FirstColumnValue", columnValue);
161 loadRKH->executeAsChildAlg();
164 return loadRKH->getProperty(
"OutputWorkspace");
179 algebra->setProperty(
"LHSWorkspace", lhs);
180 algebra->setProperty(
"RHSWorkspace",
rhs);
181 algebra->setProperty(
"OutputWorkspace", result);
185 }
catch (std::runtime_error &) {
186 g_log.
warning() <<
"Error encountered while running algorithm " << algName <<
'\n';
189 g_log.
error() <<
"Mismatched number of spectra?\n";
190 throw std::runtime_error(
"Correct to file failed, see log for details");
193 result = algebra->getProperty(
"OutputWorkspace");
#define DECLARE_ALGORITHM(classname)
const std::vector< double > & rhs
std::map< DeltaEMode::Type, std::string > index
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
std::string getPropertyValue(const std::string &name) const override
Get the value of a property as a string.
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.
@ Load
allowed here which will be passed to the algorithm
Helper class for reporting progress from algorithms.
A property class for workspaces.
void init() override
Initialisation code.
void exec() override
Execution code.
static const double LOAD_TIME
used for the progress bar: the, approximate, fraction of processing time that taken up with loading t...
API::MatrixWorkspace_sptr loadInFile(const std::string &corrFile)
Load in the RKH file for that has the correction information.
void doWkspAlgebra(const API::MatrixWorkspace_sptr &lhs, const API::MatrixWorkspace_sptr &rhs, const std::string &algName, API::MatrixWorkspace_sptr &result)
Multiply or divide the input workspace as specified by the user.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
void debug(const std::string &msg)
Logs at debug level.
void error(const std::string &msg)
Logs at error level.
void warning(const std::string &msg)
Logs at warning level.
void information(const std::string &msg)
Logs at information level.
void report()
Increments the loop counter by 1, then sends the progress notification on behalf of its algorithm.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
@ Input
An input workspace.
@ Output
An output workspace.