20#include <boost/math/special_functions/pow.hpp>
26static const std::string FLIPPERS{
"Flippers"};
27static const std::string POLARIZATION_ANALYSIS{
"PolarizationAnalysis"};
28static const std::string EFFICIENCIES{
"Efficiencies"};
29static const std::string INPUT_WORKSPACES{
"InputWorkspaces"};
30static const std::string INPUT_WORKSPACE_GROUP{
"InputWorkspaceGroup"};
31static const std::string OUTPUT_WORKSPACES{
"OutputWorkspace"};
32static const std::string CORRECTION_METHOD{
"CorrectionMethod"};
37static const std::string Off{
"0"};
38static const std::string OffOff{
"00"};
39static const std::string OffOn{
"01"};
40static const std::string On{
"1"};
41static const std::string OnOff{
"10"};
42static const std::string OnOn{
"11"};
46static const std::string WILDES{
"Wildes"};
47static const std::string FREDRIKZE{
"Fredrikze"};
55using namespace Kernel;
73 return "Corrects a group of polarization analysis workspaces for polarizer "
74 "and analyzer efficiencies.";
81 bool const allowMultiSelection =
true;
82 bool const isOptional =
true;
84 Prop::INPUT_WORKSPACES,
"", std::make_shared<ADSValidator>(allowMultiSelection, isOptional),
86 "A list of names of workspaces to be corrected.");
90 "A group of workspaces to be corrected.");
92 const std::vector<std::string> methods{CorrectionMethod::WILDES, CorrectionMethod::FREDRIKZE};
98 "A workspace containing the efficiency factors as "
99 "histograms: P1, P2, F1 and F2 in the Wildes method and Pp, "
100 "Ap, Rho and Alpha for Fredrikze.");
102 const std::string full = Flippers::OffOff +
", " + Flippers::OffOn +
", " + Flippers::OnOff +
", " + Flippers::OnOn;
103 const std::string missing01 = Flippers::OffOff +
", " + Flippers::OnOff +
", " + Flippers::OnOn;
104 const std::string missing10 = Flippers::OffOff +
", " + Flippers::OffOn +
", " + Flippers::OnOn;
105 const std::string missing0110 = Flippers::OffOff +
", " + Flippers::OnOn;
106 const std::string noAnalyzer = Flippers::Off +
", " + Flippers::On;
107 const std::string directBeam = Flippers::Off;
108 const std::vector<std::string> setups{{
"", full, missing01, missing10, missing0110, noAnalyzer, directBeam}};
110 "Flipper configurations of the input workspaces (Wildes method only)");
112 std::vector<std::string> propOptions{
"",
"PA",
"PNR"};
113 declareProperty(
"PolarizationAnalysis",
"", std::make_shared<StringListValidator>(propOptions),
114 "What Polarization mode will be used?\n"
115 "PNR: Polarized Neutron Reflectivity mode\n"
116 "PA: Full Polarization Analysis PNR-PA "
117 "(Fredrikze method only)");
121 "A group of polarization efficiency corrected workspaces.");
128 std::string
const method =
getProperty(Prop::CORRECTION_METHOD);
129 if (method == CorrectionMethod::WILDES) {
144 alg->setProperty(
"InputWorkspaces", workspaces);
145 alg->setProperty(
"Efficiencies", efficiencies);
150 alg->setPropertyValue(
"OutputWorkspace", out);
163 alg->setProperty(
"InputWorkspace", group);
164 alg->setProperty(
"Efficiencies", efficiencies);
165 if (!
isDefault(Prop::POLARIZATION_ANALYSIS)) {
166 alg->setPropertyValue(
"PolarizationAnalysis",
getPropertyValue(Prop::POLARIZATION_ANALYSIS));
168 alg->setPropertyValue(
"OutputWorkspace",
getPropertyValue(Prop::OUTPUT_WORKSPACES));
179 throw std::invalid_argument(
"Input workspaces are missing. Either a "
180 "workspace group or a list of workspace names "
184 throw std::invalid_argument(
"Input workspaces must be given either as a "
185 "workspace group or a list of names.");
195 if (!
isDefault(Prop::POLARIZATION_ANALYSIS)) {
196 throw std::invalid_argument(
"Property PolarizationAnalysis cannot be used with the Wildes method.");
207 throw std::invalid_argument(
"Property Flippers cannot be used with the Fredrikze method.");
215 std::vector<std::string> names;
216 if (!
isDefault(Prop::INPUT_WORKSPACES)) {
220 auto const n = group->size();
221 for (
size_t i = 0; i <
n; ++i) {
222 auto ws = group->getItem(i);
223 auto const name = ws->getName();
225 throw std::invalid_argument(
"Workspace from the input workspace group is not stored in the "
226 "Analysis Data Service which is required by the Wildes method.");
228 names.emplace_back(
name);
239 if (!
isDefault(Prop::INPUT_WORKSPACE_GROUP)) {
242 throw std::invalid_argument(
"Input workspaces are required to be in a workspace group.");
258 auto const &
x = inWS.
x(0);
260 if (efficiencies.
x(i).rawData() !=
x.rawData())
269 if (efficiencies->isHistogramData()) {
274 alg->setProperty(
"InputWorkspace", efficiencies);
275 alg->setProperty(
"OutputWorkspace",
"dummy");
286 efficiencies->setDistribution(
true);
289 alg->setProperty(
"WorkspaceToRebin", efficiencies);
290 alg->setProperty(
"WorkspaceToMatch", inWS);
291 alg->setProperty(
"OutputWorkspace",
"dummy");
302 if (!
isDefault(Prop::INPUT_WORKSPACES)) {
303 std::vector<std::string>
const names =
getProperty(Prop::INPUT_WORKSPACES);
307 inWS = std::dynamic_pointer_cast<MatrixWorkspace>(group->getItem(0));
#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.
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.
bool isDefault(const std::string &name) const
Base MatrixWorkspace Abstract Class.
virtual std::size_t blocksize() const =0
Returns the size of each block of data returned by the dataY accessors.
virtual std::size_t getNumberHistograms() const =0
Returns the number of histograms in the workspace.
const HistogramData::HistogramX & x(const size_t index) const
virtual bool isHistogramData() const
Returns true if the workspace contains data in histogram form (as opposed to point-like)
A property class for workspaces.
PolarizationEfficiencyCor: a generalised polarization correction algorithm.
API::MatrixWorkspace_sptr getEfficiencies()
Prepare and return the efficiencies.
const std::string category() const override
Algorithm's category for identification.
void checkWildesProperties() const
Check that the inputs for the Wildes are correct and consistent.
std::vector< std::string > getWorkspaceNameList() const
Get the input workspaces as a list of names.
API::MatrixWorkspace_sptr convertToHistogram(API::MatrixWorkspace_sptr efficiencies)
Convert the efficiencies to histogram.
API::MatrixWorkspace_sptr interpolate(const API::MatrixWorkspace_sptr &efficiencies, const API::MatrixWorkspace_sptr &inWS)
Convert the efficiencies to histogram.
void checkWorkspaces() const
Check that the inputs workspaces are set.
void init() override
Initialize the algorithm's properties.
API::WorkspaceGroup_sptr getWorkspaceGroup() const
Get the input workspaces as a workspace group.
const std::string name() const override
Algorithms name for identification.
const std::string summary() const override
Algorithm's summary for use in the GUI and help.
void checkFredrikzeProperties() const
Check that the inputs for the Fredrikze method are correct and consistent.
int version() const override
Algorithm's version for identification.
bool needInterpolation(API::MatrixWorkspace const &efficiencies, API::MatrixWorkspace const &inWS) const
Check if efficiencies workspace needs interpolation.
void exec() override
Execute the algorithm.
Support for a property that holds an array of values.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
ListValidator is a validator that requires the value of a property to be one of a defined list of pos...
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
String constants for algorithm's properties.
@ Input
An input workspace.
@ Output
An output workspace.