Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

- Added spin state order handling to PolarizationCorrectionFredrikze Correction Algorithm #37672

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#pragma once

#include "MantidAPI/Algorithm.h"
#include "MantidAPI/WorkspaceGroup_fwd.h"
#include "MantidAlgorithms/DllConfig.h"
#include <boost/optional.hpp>
#include <memory>
Expand Down Expand Up @@ -36,11 +37,16 @@ class MANTID_ALGORITHMS_DLL PolarizationCorrectionFredrikze final : public API::
void init() override;
void exec() override;
std::shared_ptr<Mantid::API::MatrixWorkspace> getEfficiencyWorkspace(const std::string &label);
std::shared_ptr<Mantid::API::WorkspaceGroup> execPA(const std::shared_ptr<Mantid::API::WorkspaceGroup> &inWS);
std::shared_ptr<Mantid::API::WorkspaceGroup> execPNR(const std::shared_ptr<Mantid::API::WorkspaceGroup> &inWS);
std::shared_ptr<Mantid::API::MatrixWorkspace> add(std::shared_ptr<Mantid::API::MatrixWorkspace> &lhsWS,
std::shared_ptr<Mantid::API::WorkspaceGroup> execPA(const std::shared_ptr<Mantid::API::WorkspaceGroup> &inWS,
const std::vector<std::string> &inputOrder,
const std::vector<std::string> &outputOrder);

std::shared_ptr<Mantid::API::WorkspaceGroup> execPNR(const std::shared_ptr<Mantid::API::WorkspaceGroup> &inWS,
const std::vector<std::string> &inputOrder,
const std::vector<std::string> &outputOrder);
std::shared_ptr<Mantid::API::MatrixWorkspace> add(const std::shared_ptr<Mantid::API::MatrixWorkspace> &lhsWS,
const double &rhs);
std::shared_ptr<Mantid::API::MatrixWorkspace> multiply(std::shared_ptr<Mantid::API::MatrixWorkspace> &lhsWS,
std::shared_ptr<Mantid::API::MatrixWorkspace> multiply(const std::shared_ptr<Mantid::API::MatrixWorkspace> &lhsWS,
const double &rhs);
};

Expand Down
228 changes: 177 additions & 51 deletions Framework/Algorithms/src/PolarizationCorrectionFredrikze.cpp

Large diffs are not rendered by default.

60 changes: 54 additions & 6 deletions Framework/Algorithms/src/PolarizationEfficiencyCor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "MantidDataObjects/Workspace2D.h"
#include "MantidDataObjects/WorkspaceCreation.h"
#include "MantidKernel/ArrayProperty.h"
#include "MantidKernel/EnabledWhenProperty.h"
#include "MantidKernel/ListValidator.h"
#include "MantidKernel/StringTokenizer.h"

Expand All @@ -26,13 +27,16 @@ namespace {
/// Property names.
namespace Prop {
static const std::string FLIPPERS{"Flippers"};
static const std::string SPIN_STATES{"SpinStates"};
static const std::string OUTPUT_WILDES_SPIN_STATES{"SpinStatesOutWildes"};
static const std::string POLARIZATION_ANALYSIS{"PolarizationAnalysis"};
static const std::string EFFICIENCIES{"Efficiencies"};
static const std::string INPUT_WORKSPACES{"InputWorkspaces"};
static const std::string INPUT_WORKSPACE_GROUP{"InputWorkspaceGroup"};
static const std::string OUTPUT_WORKSPACES{"OutputWorkspace"};
static const std::string CORRECTION_METHOD{"CorrectionMethod"};
static const std::string INPUT_FRED_SPIN_STATES{"SpinStatesInFredrikze"};
static const std::string OUTPUT_FRED_SPIN_STATES{"SpinStatesOutFredrikze"};

} // namespace Prop

namespace CorrectionMethod {
Expand Down Expand Up @@ -107,7 +111,7 @@ void PolarizationEfficiencyCor::init() {

const auto spinStateValidator =
std::make_shared<SpinStateValidator>(std::unordered_set<int>{0, 2, 4}, true, '+', '-', true);
declareProperty(Prop::SPIN_STATES, "", spinStateValidator,
declareProperty(Prop::OUTPUT_WILDES_SPIN_STATES, "", spinStateValidator,
"The order of the spin states in the output workspace. (Wildes method only).");

std::vector<std::string> propOptions{"", "PA", "PNR"};
Expand All @@ -117,9 +121,39 @@ void PolarizationEfficiencyCor::init() {
"PA: Full Polarization Analysis PNR-PA "
"(Fredrikze method only)");

const auto fredrikzeSpinStateValidator =
std::make_shared<SpinStateValidator>(std::unordered_set<int>{2, 4}, true, 'p', 'a', true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should make use of the constants here if we can.


declareProperty(Prop::INPUT_FRED_SPIN_STATES, "", fredrikzeSpinStateValidator,
"The order of spin states in the input workspace group. The possible values are 'pp,pa,ap,aa' or "
"'p,a'. (Fredrikze method only).");

declareProperty(Prop::OUTPUT_FRED_SPIN_STATES, "", fredrikzeSpinStateValidator,
"The order of spin states in the output workspace group. The possible values are 'pp,pa,ap,aa' or "
"'p,a'. (Fredrikze method only).");

declareProperty(
std::make_unique<WorkspaceProperty<WorkspaceGroup>>(Prop::OUTPUT_WORKSPACES, "", Kernel::Direction::Output),
"A group of polarization efficiency corrected workspaces.");

setPropertySettings(
Prop::OUTPUT_WILDES_SPIN_STATES,
std::make_unique<EnabledWhenProperty>(Prop::CORRECTION_METHOD, Kernel::IS_EQUAL_TO, CorrectionMethod::WILDES));

setPropertySettings(Prop::FLIPPERS, std::make_unique<EnabledWhenProperty>(
Prop::CORRECTION_METHOD, Kernel::IS_EQUAL_TO, CorrectionMethod::WILDES));

setPropertySettings(
Prop::INPUT_FRED_SPIN_STATES,
std::make_unique<EnabledWhenProperty>(Prop::CORRECTION_METHOD, Kernel::IS_EQUAL_TO, CorrectionMethod::FREDRIKZE));

setPropertySettings(
Prop::OUTPUT_FRED_SPIN_STATES,
std::make_unique<EnabledWhenProperty>(Prop::CORRECTION_METHOD, Kernel::IS_EQUAL_TO, CorrectionMethod::FREDRIKZE));

setPropertySettings(
"PolarizationAnalysis",
std::make_unique<EnabledWhenProperty>(Prop::CORRECTION_METHOD, Kernel::IS_EQUAL_TO, CorrectionMethod::FREDRIKZE));
}

//----------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -147,8 +181,8 @@ void PolarizationEfficiencyCor::execWildes() {
if (!isDefault(Prop::FLIPPERS)) {
alg->setPropertyValue("Flippers", getPropertyValue(Prop::FLIPPERS));
}
if (!isDefault(Prop::SPIN_STATES)) {
alg->setPropertyValue("SpinStates", getPropertyValue(Prop::SPIN_STATES));
if (!isDefault(Prop::OUTPUT_WILDES_SPIN_STATES)) {
alg->setPropertyValue("SpinStates", getPropertyValue(Prop::OUTPUT_WILDES_SPIN_STATES));
}
auto out = getPropertyValue(Prop::OUTPUT_WORKSPACES);
alg->setPropertyValue("OutputWorkspace", out);
Expand All @@ -169,6 +203,12 @@ void PolarizationEfficiencyCor::execFredrikze() {
if (!isDefault(Prop::POLARIZATION_ANALYSIS)) {
alg->setPropertyValue("PolarizationAnalysis", getPropertyValue(Prop::POLARIZATION_ANALYSIS));
}
if (!isDefault(Prop::INPUT_FRED_SPIN_STATES)) {
alg->setPropertyValue("InputSpinStates", getPropertyValue(Prop::INPUT_FRED_SPIN_STATES));
}
if (!isDefault(Prop::OUTPUT_FRED_SPIN_STATES)) {
alg->setPropertyValue("OutputSpinStates", getPropertyValue(Prop::OUTPUT_FRED_SPIN_STATES));
}
alg->setPropertyValue("OutputWorkspace", getPropertyValue(Prop::OUTPUT_WORKSPACES));
alg->execute();
API::WorkspaceGroup_sptr outWS = alg->getProperty("OutputWorkspace");
Expand Down Expand Up @@ -199,6 +239,14 @@ void PolarizationEfficiencyCor::checkWildesProperties() const {
if (!isDefault(Prop::POLARIZATION_ANALYSIS)) {
throw std::invalid_argument("Property PolarizationAnalysis cannot be used with the Wildes method.");
}

if (!isDefault(Prop::INPUT_FRED_SPIN_STATES)) {
throw std::invalid_argument("Property SpinStatesInFredrikze cannot be used with the Wildes method.");
}

if (!isDefault(Prop::OUTPUT_FRED_SPIN_STATES)) {
throw std::invalid_argument("Property SpinStatesOutFredrikze cannot be used with the Wildes method.");
}
}

//----------------------------------------------------------------------------------------------
Expand All @@ -210,8 +258,8 @@ void PolarizationEfficiencyCor::checkFredrikzeProperties() const {
if (!isDefault(Prop::FLIPPERS)) {
throw std::invalid_argument("Property Flippers cannot be used with the Fredrikze method.");
}
if (!isDefault(Prop::SPIN_STATES)) {
throw std::invalid_argument("Property SpinStates cannot be used with the Fredrikze method.");
if (!isDefault(Prop::OUTPUT_WILDES_SPIN_STATES)) {
throw std::invalid_argument("Property SpinStatesOutWildes cannot be used with the Fredrikze method.");
}
}

Expand Down
Loading
Loading