42 std::map<std::string, std::string> invalidInputs;
47 invalidInputs[propertyName] = propertyName +
" must be set";
52 invalidInputs[
"Sample"] =
"Sample must be set";
57 invalidInputs[
"OverrideSampleThickness"] =
"OverrideSampleThickness value must be greater than 0";
67 auto validOrientation = std::make_shared<Kernel::StringListValidator>(std::set<std::string>{
"X",
"Y",
"Z"});
70 "The name of the workspace to save");
72 "The name to use when saving the file");
85 declareProperty<std::string>(
"Orientation",
"Z", validOrientation,
"Orientation of the instrument");
88 "The sample thickness in mm. If set, this value will be used instead of the thickness from the input "
100 if (ws->getNumberHistograms() != 1) {
101 g_log.
error(
"This algorithm expects a workspace with exactly 1 spectrum");
102 throw std::runtime_error(
"SaveSESANS passed workspace with incorrect "
103 "number of spectra, expected 1");
109 g_log.
error(
"The workspace passed in does not provide the sample thickness. Please use the "
110 "OverrideSampleThickness property to "
111 "provide this value instead");
112 throw std::runtime_error(
"SaveSESANS passed workspace with sample thickness less than "
113 "or equal to 0 and no value provided for OverrideSampleThickness property");
118 std::ofstream outfile(filename, std::ofstream::trunc);
119 if (outfile.fail()) {
120 const std::string
error = strerror(errno);
122 throw std::runtime_error(
"Could not open file at the following path: " + filename);
130 const auto &wavelength = ws->points(0);
131 const auto &yValues = ws->y(0);
132 const auto &eValues = ws->e(0);
138 outfile <<
"SpinEchoLength Depolarisation Depolarisation_error Wavelength\n";
140 for (
size_t i = 0; i < spinEchoLength.size(); ++i) {
141 outfile << spinEchoLength[i] <<
" ";
142 outfile << depolarisation[i] <<
" ";
143 outfile <<
error[i] <<
" ";
144 outfile << wavelength[i] <<
"\n";
157 writeHeader(outfile,
"DataFileTitle", ws->getTitle());
167 writeHeader(outfile,
"Depolarisation_unit",
"A-2 cm-1");
189 std::vector<double> spinEchoLength;
190 const double echoConstant =
getProperty(
"EchoConstant");
193 transform(wavelength.begin(), wavelength.end(), back_inserter(spinEchoLength),
194 [&](
double w) {
return w * w * echoConstant; });
195 return spinEchoLength;
207 const HistogramData::Points &wavelength)
const {
213 transform(yValues.begin(), yValues.end(), wavelength.begin(), back_inserter(depolarisation),
214 [&](
double y,
double w) {
return log(
y) / (w * w) / thickness; });
215 return depolarisation;
227 const HistogramData::HistogramY &yValues,
228 const HistogramData::Points &wavelength)
const {
235 for (
size_t i = 0; i < eValues.size(); i++) {
236 error.emplace_back(eValues[i] / (yValues[i] * wavelength[i] * wavelength[i]) / thickness);
#define DECLARE_ALGORITHM(classname)
double value
The value of the point.
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.
@ Save
to specify a file to write to, the file may or may not exist
A property class for workspaces.
SaveSESANS : Save a workspace in the SESANS file format.
const std::string category() const override
Get the algorithm's category.
std::vector< double > calculateSpinEchoLength(const HistogramData::Points &wavelength) const
Calculate SpinEchoLength column from wavelength ( SEL = wavelength * wavelength * echoConstant)
Mantid::MantidVec calculateError(const HistogramData::HistogramE &eValues, const HistogramData::HistogramY &yValues, const HistogramData::Points &wavelength) const
Calculate the error column from the workspace values (error = e / (y * wavelength^2)) / sample thickn...
std::vector< double > calculateDepolarisation(const HistogramData::HistogramY &yValues, const HistogramData::Points &wavelength) const
Calculate the depolarisation column from wavelength and Y values in the workspace (depol = ln(y) / wa...
int version() const override
Get the version number of the algorithm.
void init() override
Initialise the algorithm.
const std::vector< std::string > fileExtensions
std::map< std::string, std::string > validateInputs() override
Perform validation of ALL the input properties of the algorithm.
const std::string name() const override
Get the algorithm's name.
void writeHeader(std::ofstream &outfile, const std::string &name, const std::string &value)
Write a single header to the output file.
void writeHeaders(std::ofstream &outfile, API::MatrixWorkspace_const_sptr &ws)
Write header values to the output file.
void exec() override
Execute the algorithm.
const std::vector< std::string > mandatoryDoubleProperties
const std::string summary() const override
Get a summary of the algorithm.
void error(const std::string &msg)
Logs at error level.
std::shared_ptr< const MatrixWorkspace > MatrixWorkspace_const_sptr
shared pointer to the matrix workspace base class (const version)
std::vector< double > MantidVec
typedef for the data storage used in Mantid matrix workspaces
constexpr double EMPTY_DBL() noexcept
Returns what we consider an "empty" double within a property.
std::string to_string(const wide_integer< Bits, Signed > &n)
@ Input
An input workspace.