From d189a3880a80d4e3d846380a0f9f90e8736dd331 Mon Sep 17 00:00:00 2001 From: Gemma Guest <gemma.guest@stfc.ac.uk> Date: Mon, 1 Oct 2018 17:46:41 +0100 Subject: [PATCH] Add polarization correction type to model Re #22263 --- .../GUI/Experiment/ExperimentPresenter.cpp | 4 ++- .../Experiment/ExperimentPresenterFactory.h | 3 +- .../Reduction/PolarizationCorrections.cpp | 20 ++++++++----- .../Reduction/PolarizationCorrections.h | 30 +++++++++++++++---- .../Experiment/ExperimentPresenterTest.h | 6 ++-- 5 files changed, 47 insertions(+), 16 deletions(-) diff --git a/qt/scientific_interfaces/ISISReflectometry/GUI/Experiment/ExperimentPresenter.cpp b/qt/scientific_interfaces/ISISReflectometry/GUI/Experiment/ExperimentPresenter.cpp index 682f8e9d68a..4e56b2d5ff2 100644 --- a/qt/scientific_interfaces/ISISReflectometry/GUI/Experiment/ExperimentPresenter.cpp +++ b/qt/scientific_interfaces/ISISReflectometry/GUI/Experiment/ExperimentPresenter.cpp @@ -55,11 +55,13 @@ void ExperimentPresenter::onReductionPaused() { m_view->enableAll(); } void ExperimentPresenter::onReductionResumed() { m_view->disableAll(); } PolarizationCorrections ExperimentPresenter::polarizationCorrectionsFromView() { + auto const correctionType = polarizationCorrectionTypeFromString( + m_view->getPolarisationCorrectionType()); auto const cRho = m_view->getCRho(); auto const cAlpha = m_view->getCAlpha(); auto const cAp = m_view->getCAp(); auto const cPp = m_view->getCPp(); - return PolarizationCorrections(cRho, cAlpha, cAp, cPp); + return PolarizationCorrections(correctionType, cRho, cAlpha, cAp, cPp); } boost::optional<RangeInLambda> diff --git a/qt/scientific_interfaces/ISISReflectometry/GUI/Experiment/ExperimentPresenterFactory.h b/qt/scientific_interfaces/ISISReflectometry/GUI/Experiment/ExperimentPresenterFactory.h index 8ee7c1e1ed1..202750c4051 100644 --- a/qt/scientific_interfaces/ISISReflectometry/GUI/Experiment/ExperimentPresenterFactory.h +++ b/qt/scientific_interfaces/ISISReflectometry/GUI/Experiment/ExperimentPresenterFactory.h @@ -25,7 +25,8 @@ private: Experiment makeModel() { // TODO get defaults from algorithm - auto polarizationCorrections = PolarizationCorrections(0.0, 0.0, 0.0, 0.0); + auto polarizationCorrections = PolarizationCorrections( + PolarizationCorrectionType::None, 0.0, 0.0, 0.0, 0.0); auto stitchParameters = std::map<std::string, std::string>(); auto perThetaDefaults = std::vector<PerThetaDefaults>( {PerThetaDefaults(boost::none, std::pair<std::string, std::string>(), diff --git a/qt/scientific_interfaces/ISISReflectometry/Reduction/PolarizationCorrections.cpp b/qt/scientific_interfaces/ISISReflectometry/Reduction/PolarizationCorrections.cpp index b2022c72a86..ff1105dc960 100644 --- a/qt/scientific_interfaces/ISISReflectometry/Reduction/PolarizationCorrections.cpp +++ b/qt/scientific_interfaces/ISISReflectometry/Reduction/PolarizationCorrections.cpp @@ -2,17 +2,23 @@ namespace MantidQt { namespace CustomInterfaces { -PolarizationCorrections::PolarizationCorrections(double CRho, double CAlpha, - double CAp, double CPp) - : CRho(CRho), CAlpha(CAlpha), CAp(CAp), CPp(CPp) {} +PolarizationCorrections::PolarizationCorrections( + PolarizationCorrectionType correctionType, double CRho, double CAlpha, + double CAp, double CPp) + : m_correctionType(correctionType), m_cRho(CRho), m_cAlpha(CAlpha), + m_cAp(CAp), m_cPp(CPp) {} -double PolarizationCorrections::cRho() const { return CRho; } +PolarizationCorrectionType PolarizationCorrections::correctionType() { + return m_correctionType; +} + +double PolarizationCorrections::cRho() const { return m_cRho; } -double PolarizationCorrections::cAlpha() const { return CAlpha; } +double PolarizationCorrections::cAlpha() const { return m_cAlpha; } -double PolarizationCorrections::cAp() const { return CAp; } +double PolarizationCorrections::cAp() const { return m_cAp; } -double PolarizationCorrections::cPp() const { return CPp; } +double PolarizationCorrections::cPp() const { return m_cPp; } bool operator!=(PolarizationCorrections const &lhs, PolarizationCorrections const &rhs) { diff --git a/qt/scientific_interfaces/ISISReflectometry/Reduction/PolarizationCorrections.h b/qt/scientific_interfaces/ISISReflectometry/Reduction/PolarizationCorrections.h index 25fe794e048..4dd72bff879 100644 --- a/qt/scientific_interfaces/ISISReflectometry/Reduction/PolarizationCorrections.h +++ b/qt/scientific_interfaces/ISISReflectometry/Reduction/PolarizationCorrections.h @@ -1,23 +1,43 @@ #ifndef MANTID_CUSTOMINTERFACES_POLARIZATIONCORRECTIONS_H_ #define MANTID_CUSTOMINTERFACES_POLARIZATIONCORRECTIONS_H_ #include "../DllConfig.h" +#include <stdexcept> +#include <string> namespace MantidQt { namespace CustomInterfaces { +enum class PolarizationCorrectionType { None, PA, PNR, ParameterFile }; + +inline PolarizationCorrectionType +polarizationCorrectionTypeFromString(std::string const &correctionType) { + if (correctionType == "None") + return PolarizationCorrectionType::None; + else if (correctionType == "PA") + return PolarizationCorrectionType::PA; + else if (correctionType == "PNR") + return PolarizationCorrectionType::PNR; + else if (correctionType == "ParameterFile") + return PolarizationCorrectionType::ParameterFile; + else + throw std::runtime_error("Unexpected polarization correction type."); +} class MANTIDQT_ISISREFLECTOMETRY_DLL PolarizationCorrections { public: - PolarizationCorrections(double CRho, double CAlpha, double CAp, double CPp); + PolarizationCorrections(PolarizationCorrectionType correctionType, + double CRho, double CAlpha, double CAp, double CPp); + PolarizationCorrectionType correctionType(); double cRho() const; double cAlpha() const; double cAp() const; double cPp() const; private: - double CRho; - double CAlpha; - double CAp; - double CPp; + PolarizationCorrectionType m_correctionType; + double m_cRho; + double m_cAlpha; + double m_cAp; + double m_cPp; }; MANTIDQT_ISISREFLECTOMETRY_DLL bool diff --git a/qt/scientific_interfaces/test/ISISReflectometry/Experiment/ExperimentPresenterTest.h b/qt/scientific_interfaces/test/ISISReflectometry/Experiment/ExperimentPresenterTest.h index bdc44fef6e7..5448bd60282 100644 --- a/qt/scientific_interfaces/test/ISISReflectometry/Experiment/ExperimentPresenterTest.h +++ b/qt/scientific_interfaces/test/ISISReflectometry/Experiment/ExperimentPresenterTest.h @@ -95,7 +95,8 @@ public: void testSetPolarizationCorrections() { auto presenter = makePresenter(); - PolarizationCorrections polCorr(1.2, 1.3, 2.4, 2.5); + PolarizationCorrections polCorr(PolarizationCorrectionType::PA, 1.2, 1.3, + 2.4, 2.5); expectViewReturnsDefaultValues(); EXPECT_CALL(m_view, getCRho()).WillOnce(Return(polCorr.cRho())); @@ -244,7 +245,8 @@ private: NiceMock<MockExperimentView> m_view; Experiment makeModel() { - auto polarizationCorrections = PolarizationCorrections(0.0, 0.0, 0.0, 0.0); + auto polarizationCorrections = PolarizationCorrections( + PolarizationCorrectionType::None, 0.0, 0.0, 0.0, 0.0); auto transmissionRunRange = RangeInLambda(0.0, 0.0); auto stitchParameters = std::map<std::string, std::string>(); auto perThetaDefaults = std::vector<PerThetaDefaults>( -- GitLab