11#include "MantidHistogramData/Counts.h"
12#include "MantidHistogramData/LinearGenerator.h"
13#include "MantidHistogramData/Points.h"
29std::string
const METHOD_FREDRIKZE(
"Fredrikze");
30std::string
const METHOD_WILDES(
"Wildes");
31std::string
const METHOD_PARAMETER(
"polarization_correction_method");
32std::string
const OPTION_PARAMETER(
"polarization_correction_option");
33std::string
const LAMBDA_PARAMETER(
"efficiency_lambda");
35std::map<std::string, std::vector<std::string>>
const EFFICIENCIES{{METHOD_FREDRIKZE, {
"Pp",
"Ap",
"Rho",
"Alpha"}},
36 {METHOD_WILDES, {
"P1",
"P2",
"F1",
"F2"}}};
38std::vector<double> parseVector(std::string
const &name, std::string
const &
value) {
39 std::istringstream istr(
value);
40 std::vector<double> result;
42 while (istr >> number) {
43 result.emplace_back(number);
47 throw std::invalid_argument(
"Error while parsing instrument vector parameter " + name);
54 std::vector<double>
const &e = std::vector<double>()) {
57 CountStandardDeviations eVals(e.empty() ? std::vector<double>(
y.size()) : e);
58 auto retVal = std::make_shared<Workspace2D>();
59 retVal->initialize(1,
Histogram(xVals, yVals, eVals));
76 return "Extracts polarization efficiencies from instrument's parameter file.";
83 "A workspace with attached instrument whose parameters contain "
84 "polarization efficiencies.");
86 "The workspace with extracted efficiencies.");
87 declareProperty<std::string>(
"CorrectionMethod",
"",
"Correction method: Fredrikze or Wildes.",
89 declareProperty<std::string>(
"CorrectionOption",
"",
"Correction option, eg \"PA\" or \"PNR\" for Fredrikze method.",
98 auto instrument = inputWS->getInstrument();
99 auto const method = instrument->getParameterAsString(METHOD_PARAMETER);
100 if (method.empty()) {
101 throw std::invalid_argument(
"Correction method is undefined");
103 if (method != METHOD_FREDRIKZE && method != METHOD_WILDES) {
104 throw std::invalid_argument(
"Unknown correction method: " + method);
107 auto const lambdaValue = instrument->getParameterAsString(LAMBDA_PARAMETER);
108 if (lambdaValue.empty()) {
109 throw std::invalid_argument(
"Wavelengths are missing from the correction parameters");
111 auto const lambda = parseVector(LAMBDA_PARAMETER, lambdaValue);
113 throw std::runtime_error(
"Instrument vector parameter \"" + LAMBDA_PARAMETER +
118 auto const &efficiencies = EFFICIENCIES.at(method);
119 for (
auto const &
name : efficiencies) {
120 auto propValue = instrument->getParameterAsString(
name);
121 if (propValue.empty()) {
122 throw std::invalid_argument(
"Parameter " +
name +
" is missing from the correction parameters");
124 auto const prop = parseVector(
name, propValue);
125 if (
lambda.size() != prop.size()) {
126 throw std::runtime_error(
"Instrument vector parameter \"" +
name +
"\" is expected to be the same size as \"" +
130 auto const errorName =
name +
"_Errors";
131 propValue = instrument->getParameterAsString(errorName);
132 auto const errorProp = propValue.empty() ? std::vector<double>() : parseVector(errorName, propValue);
134 alg->setProperty(
name, ws);
139 auto const option = instrument->getParameterAsString(OPTION_PARAMETER);
140 if (option.empty()) {
141 throw std::invalid_argument(
"Correction option is undefined");
#define DECLARE_ALGORITHM(classname)
const std::vector< double > * lambda
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.
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.
int version() const override
Algorithm's version for identification.
const std::string category() const override
Algorithm's category for identification.
void init() override
Initialize the algorithm's properties.
const std::string name() const override
Algorithm's name for identification.
void exec() override
Execute the algorithm.
const std::string summary() const override
Algorithm's summary for use in the GUI and help.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
std::shared_ptr< T > createWorkspace(InitArgs... args)
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
std::string to_string(const wide_integer< Bits, Signed > &n)
@ Input
An input workspace.
@ Output
An output workspace.