Skip to content

Commit

Permalink
Refactor Fredrikze Algorithm SpinStates Implementation
Browse files Browse the repository at this point in the history
- Renamed the input and output spin states
- refactored tests to eliminate code duplication
- added an helper function to fix crash which happens when user enter pp, aa as spinstates
- improved code based on PR review suggestions
- updated unit tests to handle crash which happens when user enter pp, aa as spinstates
- updated documentation
  • Loading branch information
yusufjimoh committed Oct 24, 2024
1 parent 2c7eef5 commit b2662b1
Show file tree
Hide file tree
Showing 7 changed files with 373 additions and 353 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class MANTID_ALGORITHMS_DLL PolarizationCorrectionFredrikze final : public API::
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(const std::shared_ptr<Mantid::API::MatrixWorkspace> &lhsWS,
double &rhs);
const double &rhs);
};

} // namespace Algorithms
Expand Down
263 changes: 146 additions & 117 deletions Framework/Algorithms/src/PolarizationCorrectionFredrikze.cpp

Large diffs are not rendered by default.

21 changes: 11 additions & 10 deletions Framework/Algorithms/src/PolarizationEfficiencyCor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace {
/// Property names.
namespace Prop {
static const std::string FLIPPERS{"Flippers"};
static const std::string SPIN_STATES{"SpinStatesOutWildes"};
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"};
Expand Down Expand Up @@ -111,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 @@ -136,8 +136,9 @@ void PolarizationEfficiencyCor::init() {
std::make_unique<WorkspaceProperty<WorkspaceGroup>>(Prop::OUTPUT_WORKSPACES, "", Kernel::Direction::Output),
"A group of polarization efficiency corrected workspaces.");

setPropertySettings(Prop::SPIN_STATES, std::make_unique<EnabledWhenProperty>(
Prop::CORRECTION_METHOD, Kernel::IS_EQUAL_TO, CorrectionMethod::WILDES));
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));
Expand Down Expand Up @@ -180,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 @@ -203,10 +204,10 @@ void PolarizationEfficiencyCor::execFredrikze() {
alg->setPropertyValue("PolarizationAnalysis", getPropertyValue(Prop::POLARIZATION_ANALYSIS));
}
if (!isDefault(Prop::INPUT_FRED_SPIN_STATES)) {
alg->setPropertyValue("InputSpinStateOrder", getPropertyValue(Prop::INPUT_FRED_SPIN_STATES));
alg->setPropertyValue("InputSpinStates", getPropertyValue(Prop::INPUT_FRED_SPIN_STATES));
}
if (!isDefault(Prop::OUTPUT_FRED_SPIN_STATES)) {
alg->setPropertyValue("OutputSpinStateOrder", getPropertyValue(Prop::OUTPUT_FRED_SPIN_STATES));
alg->setPropertyValue("OutputSpinStates", getPropertyValue(Prop::OUTPUT_FRED_SPIN_STATES));
}
alg->setPropertyValue("OutputWorkspace", getPropertyValue(Prop::OUTPUT_WORKSPACES));
alg->execute();
Expand Down Expand Up @@ -257,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

0 comments on commit b2662b1

Please sign in to comment.