diff --git a/Framework/Algorithms/inc/MantidAlgorithms/SofQCommon.h b/Framework/Algorithms/inc/MantidAlgorithms/SofQCommon.h index 60248ddf8ea22992f11d68f63c222e7f7f13e2b5..75145054146004df2b3717294c0faf3674ebd115 100644 --- a/Framework/Algorithms/inc/MantidAlgorithms/SofQCommon.h +++ b/Framework/Algorithms/inc/MantidAlgorithms/SofQCommon.h @@ -30,11 +30,17 @@ struct DLLExport SofQCommon { /// Get global minimum and maximum X from given ws. std::pair<double, double> eBinHints(const API::MatrixWorkspace &ws) const; /// Estimate minimum and maximum momentum transfer. - std::pair<double, double> qBinHints(const API::MatrixWorkspace &ws, const double minE, const double maxE) const; + std::pair<double, double> qBinHints(const API::MatrixWorkspace &ws, + const double minE, + const double maxE) const; private: - std::pair<double, double> qBinHintsDirect(const API::MatrixWorkspace &ws, const double minE, const double maxE) const; - std::pair<double, double> qBinHintsIndirect(const API::MatrixWorkspace &ws, const double minE, const double maxE) const; + std::pair<double, double> qBinHintsDirect(const API::MatrixWorkspace &ws, + const double minE, + const double maxE) const; + std::pair<double, double> qBinHintsIndirect(const API::MatrixWorkspace &ws, + const double minE, + const double maxE) const; }; } } diff --git a/Framework/Algorithms/inc/MantidAlgorithms/SofQW.h b/Framework/Algorithms/inc/MantidAlgorithms/SofQW.h index d1a3426f363a885cf70f0f671f6cfc33b7510f00..0622a72f6210a170aad533004b768aa4e95626c7 100644 --- a/Framework/Algorithms/inc/MantidAlgorithms/SofQW.h +++ b/Framework/Algorithms/inc/MantidAlgorithms/SofQW.h @@ -65,12 +65,10 @@ public: /// Algorithm's category for identification const std::string category() const override { return "Inelastic\\SofQW"; } /// Create the output workspace - static API::MatrixWorkspace_sptr - setUpOutputWorkspace(const API::MatrixWorkspace_const_sptr &inputWorkspace, - const std::vector<double> &qbinParams, - std::vector<double> &qAxis, - const std::vector<double> &ebinParams, - const SofQCommon &emodeProperties); + static API::MatrixWorkspace_sptr setUpOutputWorkspace( + const API::MatrixWorkspace_const_sptr &inputWorkspace, + const std::vector<double> &qbinParams, std::vector<double> &qAxis, + const std::vector<double> &ebinParams, const SofQCommon &emodeProperties); /// Create the input properties on the given algorithm object static void createCommonInputProperties(API::Algorithm &alg); diff --git a/Framework/Algorithms/src/SofQCommon.cpp b/Framework/Algorithms/src/SofQCommon.cpp index 9dd16ab244cebdeb64843905b16f7edf16ef0b54..9cd2f56aaa5a78b60fce87f528fe82a7cfc037e4 100644 --- a/Framework/Algorithms/src/SofQCommon.cpp +++ b/Framework/Algorithms/src/SofQCommon.cpp @@ -91,7 +91,8 @@ double SofQCommon::getEFixed(const Geometry::IDetector &det) const { * @param ws a workspace * @return a pair containing the global minimum and maximum X */ -std::pair<double, double> SofQCommon::eBinHints(const API::MatrixWorkspace &ws) const { +std::pair<double, double> +SofQCommon::eBinHints(const API::MatrixWorkspace &ws) const { auto min = std::numeric_limits<double>::max(); auto max = std::numeric_limits<double>::lowest(); for (size_t i = 0; i < ws.getNumberHistograms(); ++i) { @@ -113,7 +114,9 @@ std::pair<double, double> SofQCommon::eBinHints(const API::MatrixWorkspace &ws) * @param maxE maximum energy transfer in ws * @return a pair containing global minimun and maximum Q */ -std::pair<double, double> SofQCommon::qBinHints(const API::MatrixWorkspace &ws, const double minE, const double maxE) const { +std::pair<double, double> SofQCommon::qBinHints(const API::MatrixWorkspace &ws, + const double minE, + const double maxE) const { if (m_emode == 1) { return qBinHintsDirect(ws, minE, maxE); } @@ -128,7 +131,9 @@ std::pair<double, double> SofQCommon::qBinHints(const API::MatrixWorkspace &ws, * @param maxE maximum energy transfer in ws * @return a pair containing global minimun and maximum Q */ -std::pair<double, double> SofQCommon::qBinHintsDirect(const API::MatrixWorkspace &ws, const double minE, const double maxE) const { +std::pair<double, double> +SofQCommon::qBinHintsDirect(const API::MatrixWorkspace &ws, const double minE, + const double maxE) const { using namespace Mantid::PhysicalConstants; auto minTheta = std::numeric_limits<double>::max(); auto maxTheta = std::numeric_limits<double>::lowest(); @@ -146,7 +151,8 @@ std::pair<double, double> SofQCommon::qBinHintsDirect(const API::MatrixWorkspace } } if (minTheta == std::numeric_limits<double>::max()) { - throw std::runtime_error("Could not determine Q binning: workspace does not contain usable spectra."); + throw std::runtime_error("Could not determine Q binning: workspace does " + "not contain usable spectra."); } const auto incidentKSq = m_efixed / E_mev_toNeutronWavenumberSq; const auto incidentK = std::sqrt(incidentKSq); @@ -157,10 +163,14 @@ std::pair<double, double> SofQCommon::qBinHintsDirect(const API::MatrixWorkspace const auto maxKSq = maxEnergy / E_mev_toNeutronWavenumberSq; const auto maxK = std::sqrt(maxKSq); std::array<double, 4> q; - q[0] = std::sqrt(incidentKSq + minKSq - 2. * incidentK * minK * std::cos(minTheta)); - q[1] = std::sqrt(incidentKSq + minKSq - 2. * incidentK * minK * std::cos(maxTheta)); - q[2] = std::sqrt(incidentKSq + maxKSq - 2. * incidentK * maxK * std::cos(minTheta)); - q[4] = std::sqrt(incidentKSq + maxKSq - 2. * incidentK * maxK * std::cos(maxTheta)); + q[0] = std::sqrt(incidentKSq + minKSq - + 2. * incidentK * minK * std::cos(minTheta)); + q[1] = std::sqrt(incidentKSq + minKSq - + 2. * incidentK * minK * std::cos(maxTheta)); + q[2] = std::sqrt(incidentKSq + maxKSq - + 2. * incidentK * maxK * std::cos(minTheta)); + q[4] = std::sqrt(incidentKSq + maxKSq - + 2. * incidentK * maxK * std::cos(maxTheta)); const auto minmaxQ = std::minmax_element(q.cbegin(), q.cend()); return std::make_pair(*minmaxQ.first, *minmaxQ.second); } @@ -175,7 +185,9 @@ std::pair<double, double> SofQCommon::qBinHintsDirect(const API::MatrixWorkspace * @param maxE maximum energy transfer in ws * @return a pair containing global minimun and maximum Q */ -std::pair<double, double> SofQCommon::qBinHintsIndirect(const API::MatrixWorkspace &ws, const double minE, const double maxE) const { +std::pair<double, double> +SofQCommon::qBinHintsIndirect(const API::MatrixWorkspace &ws, const double minE, + const double maxE) const { using namespace Mantid::PhysicalConstants; auto minQSq = std::numeric_limits<double>::max(); auto maxQSq = std::numeric_limits<double>::lowest(); @@ -205,10 +217,10 @@ std::pair<double, double> SofQCommon::qBinHintsIndirect(const API::MatrixWorkspa } } if (minQSq == std::numeric_limits<double>::max()) { - throw std::runtime_error("Could not determine Q binning: workspace does not contain usable spectra."); + throw std::runtime_error("Could not determine Q binning: workspace does " + "not contain usable spectra."); } return std::make_pair(std::sqrt(minQSq), std::sqrt(maxQSq)); } - } } diff --git a/Framework/Algorithms/src/SofQW.cpp b/Framework/Algorithms/src/SofQW.cpp index af5a52fc79fb612dde76730826c2653223d67663..57cd4f72d2ac369a23d8ba0c2eae9a5fd9957b2b 100644 --- a/Framework/Algorithms/src/SofQW.cpp +++ b/Framework/Algorithms/src/SofQW.cpp @@ -142,8 +142,7 @@ void SofQW::exec() { API::MatrixWorkspace_sptr SofQW::setUpOutputWorkspace( const API::MatrixWorkspace_const_sptr &inputWorkspace, const std::vector<double> &qbinParams, std::vector<double> &qAxis, - const std::vector<double> &ebinParams, - const SofQCommon &emodeProperties) { + const std::vector<double> &ebinParams, const SofQCommon &emodeProperties) { using Kernel::VectorHelper::createAxisFromRebinParams; // Create vector to hold the new X axis values HistogramData::BinEdges xAxis(0); @@ -154,10 +153,11 @@ API::MatrixWorkspace_sptr SofQW::setUpOutputWorkspace( xLength = static_cast<int>(xAxis.size()); } else if (ebinParams.size() == 1) { eHints = emodeProperties.eBinHints(*inputWorkspace); - xLength = createAxisFromRebinParams(ebinParams, xAxis.mutableRawData(), true, true, eHints.first, eHints.second); + xLength = + createAxisFromRebinParams(ebinParams, xAxis.mutableRawData(), true, + true, eHints.first, eHints.second); } else { - xLength = createAxisFromRebinParams( - ebinParams, xAxis.mutableRawData()); + xLength = createAxisFromRebinParams(ebinParams, xAxis.mutableRawData()); } // Create a vector to temporarily hold the vertical ('y') axis and populate // that @@ -166,8 +166,10 @@ API::MatrixWorkspace_sptr SofQW::setUpOutputWorkspace( if (std::isnan(eHints.first)) { eHints = emodeProperties.eBinHints(*inputWorkspace); } - const auto qHints = emodeProperties.qBinHints(*inputWorkspace, eHints.first, eHints.second); - yLength = createAxisFromRebinParams(qbinParams, qAxis, true, true, qHints.first, qHints.second); + const auto qHints = + emodeProperties.qBinHints(*inputWorkspace, eHints.first, eHints.second); + yLength = createAxisFromRebinParams(qbinParams, qAxis, true, true, + qHints.first, qHints.second); } else { yLength = createAxisFromRebinParams(qbinParams, qAxis); } @@ -197,6 +199,5 @@ API::MatrixWorkspace_sptr SofQW::setUpOutputWorkspace( return outputWorkspace; } - } // namespace Algorithms } // namespace Mantid diff --git a/Framework/Algorithms/src/SofQWCentre.cpp b/Framework/Algorithms/src/SofQWCentre.cpp index 9e1ccbf9fbae90ee5e880ea35ababd05fee15744..5fdf2e361bf20351d767ac59945b66da06a57f35 100644 --- a/Framework/Algorithms/src/SofQWCentre.cpp +++ b/Framework/Algorithms/src/SofQWCentre.cpp @@ -65,9 +65,9 @@ void SofQWCentre::exec() { const int emode = m_EmodeProperties.m_emode; std::vector<double> verticalAxis; - MatrixWorkspace_sptr outputWorkspace = - SofQW::setUpOutputWorkspace(inputWorkspace, getProperty("QAxisBinning"), - verticalAxis, getProperty("EAxisBinning"), m_EmodeProperties); + MatrixWorkspace_sptr outputWorkspace = SofQW::setUpOutputWorkspace( + inputWorkspace, getProperty("QAxisBinning"), verticalAxis, + getProperty("EAxisBinning"), m_EmodeProperties); setProperty("OutputWorkspace", outputWorkspace); const auto &xAxis = outputWorkspace->binEdges(0).rawData(); @@ -75,7 +75,6 @@ void SofQWCentre::exec() { std::vector<specnum_t> specNumberMapping; std::vector<detid_t> detIDMapping; - const auto &detectorInfo = inputWorkspace->detectorInfo(); const auto &spectrumInfo = inputWorkspace->spectrumInfo(); V3D beamDir = detectorInfo.samplePosition() - detectorInfo.sourcePosition(); diff --git a/Framework/Algorithms/src/SofQWNormalisedPolygon.cpp b/Framework/Algorithms/src/SofQWNormalisedPolygon.cpp index 406bf59d4d675b0a9e5f8fa7208cf88a22d350c1..71f012343fb1421002eef41e6f6c5d06e19f0146 100644 --- a/Framework/Algorithms/src/SofQWNormalisedPolygon.cpp +++ b/Framework/Algorithms/src/SofQWNormalisedPolygon.cpp @@ -419,7 +419,8 @@ RebinnedOutput_sptr SofQWNormalisedPolygon::setUpOutputWorkspace( xAxis = inputWorkspace.binEdges(0); } else if (ebinParams.size() == 1) { eHints = m_EmodeProperties.eBinHints(inputWorkspace); - createAxisFromRebinParams(ebinParams, xAxis.mutableRawData(), true, true, eHints.first, eHints.second); + createAxisFromRebinParams(ebinParams, xAxis.mutableRawData(), true, true, + eHints.first, eHints.second); } else { createAxisFromRebinParams(ebinParams, xAxis.mutableRawData()); } @@ -431,8 +432,10 @@ RebinnedOutput_sptr SofQWNormalisedPolygon::setUpOutputWorkspace( if (std::isnan(eHints.first)) { eHints = m_EmodeProperties.eBinHints(inputWorkspace); } - const auto qHints = m_EmodeProperties.qBinHints(inputWorkspace, eHints.first, eHints.second); - yLength = createAxisFromRebinParams(qbinParams, qAxis, true, true, qHints.first, qHints.second); + const auto qHints = m_EmodeProperties.qBinHints( + inputWorkspace, eHints.first, eHints.second); + yLength = createAxisFromRebinParams(qbinParams, qAxis, true, true, + qHints.first, qHints.second); } else { yLength = createAxisFromRebinParams(qbinParams, qAxis); } diff --git a/Framework/Algorithms/src/SofQWPolygon.cpp b/Framework/Algorithms/src/SofQWPolygon.cpp index 1ca461af7f9d9270d96e26e698215591da16c06b..40a31e22b243e445c1b95394e7df0c0613bcbe7a 100644 --- a/Framework/Algorithms/src/SofQWPolygon.cpp +++ b/Framework/Algorithms/src/SofQWPolygon.cpp @@ -42,9 +42,9 @@ void SofQWPolygon::exec() { m_EmodeProperties.initCachedValues(*inputWS, this); - MatrixWorkspace_sptr outputWS = - SofQW::setUpOutputWorkspace(inputWS, getProperty("QAxisBinning"), m_Qout, - getProperty("EAxisBinning"), m_EmodeProperties); + MatrixWorkspace_sptr outputWS = SofQW::setUpOutputWorkspace( + inputWS, getProperty("QAxisBinning"), m_Qout, getProperty("EAxisBinning"), + m_EmodeProperties); setProperty("OutputWorkspace", outputWS); const size_t nenergyBins = inputWS->blocksize(); diff --git a/Framework/Algorithms/test/SofQCommonTest.h b/Framework/Algorithms/test/SofQCommonTest.h index 79f3d656147f4c136804a1edb23444b40460b226..249df2c56d317cd14644f79c6d121cffa5e67136 100644 --- a/Framework/Algorithms/test/SofQCommonTest.h +++ b/Framework/Algorithms/test/SofQCommonTest.h @@ -86,8 +86,8 @@ public: Algorithms::SofQW alg; alg.initialize(); alg.setProperty("EMode", "Indirect"); - //const double Ei{2.3}; - //alg.setProperty("EFixed", Ei); + // const double Ei{2.3}; + // alg.setProperty("EFixed", Ei); Algorithms::SofQCommon s; const size_t nHist{13}; auto ws = create2DWorkspaceWithFullInstrument(nHist, 1); @@ -185,8 +185,10 @@ public: setEFixed(ws, "pixel-1)", eFixed1); const auto minDeltaE = ws->x(0).front(); const auto maxDeltaE = ws->x(0).back(); - const auto minQ = std::min(indirectQ(eFixed0, minDeltaE, twoTheta0), indirectQ(eFixed1, minDeltaE, twoTheta1)); - const auto maxQ = std::max(indirectQ(eFixed0, maxDeltaE, twoTheta1), indirectQ(eFixed1, maxDeltaE, twoTheta1)); + const auto minQ = std::min(indirectQ(eFixed0, minDeltaE, twoTheta0), + indirectQ(eFixed1, minDeltaE, twoTheta1)); + const auto maxQ = std::max(indirectQ(eFixed0, maxDeltaE, twoTheta1), + indirectQ(eFixed1, maxDeltaE, twoTheta1)); s.initCachedValues(*ws, &alg); const auto minmaxE = s.eBinHints(*ws); const auto minmaxQ = s.qBinHints(*ws, minmaxE.first, minmaxE.second); @@ -195,7 +197,6 @@ public: } private: - static double k(const double E) { using namespace Mantid; using PhysicalConstants::h_bar; @@ -204,23 +205,27 @@ private: return std::sqrt(2 * NeutronMass * E * meV) / h_bar * 1e-10; } - static double indirectQ(const double Ef, const double DeltaE, const double twoTheta = 0.) { + static double indirectQ(const double Ef, const double DeltaE, + const double twoTheta = 0.) { const auto kf = k(Ef); const auto Ei = Ef + DeltaE; const auto ki = k(Ei); return std::sqrt(ki * ki + kf * kf - 2. * ki * kf * std::cos(twoTheta)); } - static double directQ(const double Ei, const double DeltaE, const double twoTheta = 0.) { + static double directQ(const double Ei, const double DeltaE, + const double twoTheta = 0.) { const auto ki = k(Ei); const auto Ef = Ei - DeltaE; const auto kf = k(Ef); return std::sqrt(ki * ki + kf * kf - 2. * ki * kf * std::cos(twoTheta)); } - static void setEFixed(Mantid::API::MatrixWorkspace_sptr ws, const std::string &component, const double eFixed) { + static void setEFixed(Mantid::API::MatrixWorkspace_sptr ws, + const std::string &component, const double eFixed) { using namespace Mantid; - auto alg = API::AlgorithmManager::Instance().createUnmanaged("SetInstrumentParameter"); + auto alg = API::AlgorithmManager::Instance().createUnmanaged( + "SetInstrumentParameter"); alg->initialize(); alg->setChild(true); alg->setProperty("Workspace", ws); diff --git a/Framework/Algorithms/test/SofQWNormalisedPolygonTest.h b/Framework/Algorithms/test/SofQWNormalisedPolygonTest.h index 0bfc1c8a5c27774438f13a05d41e07db3dcca0e8..1cdb86180f20448cd3dada8eaea5f9ddcf9f4a3b 100644 --- a/Framework/Algorithms/test/SofQWNormalisedPolygonTest.h +++ b/Framework/Algorithms/test/SofQWNormalisedPolygonTest.h @@ -99,14 +99,17 @@ public: TS_ASSERT_THROWS_NOTHING(alg.setProperty("EMode", "Indirect")) TS_ASSERT_THROWS_NOTHING(alg.setProperty("EFixed", 1.84)) const std::vector<double> eBinParams{-0.5, 0.1, -0.1, 0.2, 0.4}; - const std::vector<double> expectedEBinEdges{-0.5, -0.4, -0.3, -0.2, -0.1, 0.1, 0.3, 0.4}; + const std::vector<double> expectedEBinEdges{-0.5, -0.4, -0.3, -0.2, + -0.1, 0.1, 0.3, 0.4}; TS_ASSERT_THROWS_NOTHING(alg.setProperty("EAxisBinning", eBinParams)) const std::vector<double> qBinParams{0.5, 0.1, 1.0, 0.2, 2.}; - const std::vector<double> expectedQBinEdges{0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.2, 1.4, 1.6, 1.8, 2.}; + const std::vector<double> expectedQBinEdges{0.5, 0.6, 0.7, 0.8, 0.9, 1.0, + 1.2, 1.4, 1.6, 1.8, 2.}; TS_ASSERT_THROWS_NOTHING(alg.setProperty("QAxisBinning", qBinParams)) TS_ASSERT_THROWS_NOTHING(alg.execute()) TS_ASSERT(alg.isExecuted()) - Mantid::API::MatrixWorkspace_sptr outWS = alg.getProperty("OutputWorkspace"); + Mantid::API::MatrixWorkspace_sptr outWS = + alg.getProperty("OutputWorkspace"); TS_ASSERT_EQUALS(outWS->getNumberHistograms(), expectedQBinEdges.size() - 1) for (size_t i = 0; i < outWS->getNumberHistograms(); ++i) { const auto &x = outWS->x(i); @@ -146,11 +149,13 @@ public: expectedEBinEdges.emplace_back(lastEdge); TS_ASSERT_THROWS_NOTHING(alg.setProperty("EAxisBinning", eBinParams)) const std::vector<double> qBinParams{0.5, 0.1, 1.0, 0.2, 2.}; - const std::vector<double> expectedQBinEdges{0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.2, 1.4, 1.6, 1.8, 2.}; + const std::vector<double> expectedQBinEdges{0.5, 0.6, 0.7, 0.8, 0.9, 1.0, + 1.2, 1.4, 1.6, 1.8, 2.}; TS_ASSERT_THROWS_NOTHING(alg.setProperty("QAxisBinning", qBinParams)) TS_ASSERT_THROWS_NOTHING(alg.execute()) TS_ASSERT(alg.isExecuted()) - Mantid::API::MatrixWorkspace_sptr outWS = alg.getProperty("OutputWorkspace"); + Mantid::API::MatrixWorkspace_sptr outWS = + alg.getProperty("OutputWorkspace"); TS_ASSERT_EQUALS(outWS->getNumberHistograms(), expectedQBinEdges.size() - 1) for (size_t i = 0; i < outWS->getNumberHistograms(); ++i) { const auto &x = outWS->x(i); @@ -182,7 +187,8 @@ public: TS_ASSERT_THROWS_NOTHING(alg.setProperty("QAxisBinning", qBinParams)) TS_ASSERT_THROWS_NOTHING(alg.execute()) TS_ASSERT(alg.isExecuted()) - Mantid::API::MatrixWorkspace_sptr outWS = alg.getProperty("OutputWorkspace"); + Mantid::API::MatrixWorkspace_sptr outWS = + alg.getProperty("OutputWorkspace"); const auto axis = outWS->getAxis(1); // Test only the Q bin width, not the actual edges. for (size_t i = 0; i < axis->length() - 1; ++i) { diff --git a/Framework/Algorithms/test/SofQWTest.h b/Framework/Algorithms/test/SofQWTest.h index da4b304a6bff0b0c36cee6755270cad5a0195ece..adefabecbe8dd39db5ae99850d122b6ea242797a 100644 --- a/Framework/Algorithms/test/SofQWTest.h +++ b/Framework/Algorithms/test/SofQWTest.h @@ -17,7 +17,6 @@ using namespace Mantid::API; class SofQWTest : public CxxTest::TestSuite { public: - static Mantid::API::MatrixWorkspace_sptr loadTestFile() { Mantid::DataHandling::LoadNexusProcessed loader; loader.initialize(); @@ -45,8 +44,7 @@ public: // Cannot be marked as child or history is not recorded TS_ASSERT_THROWS_NOTHING(sqw.setProperty("InputWorkspace", inWS)); const std::string wsname{"_tmp_"}; - TS_ASSERT_THROWS_NOTHING( - sqw.setPropertyValue("OutputWorkspace", wsname)); + TS_ASSERT_THROWS_NOTHING(sqw.setPropertyValue("OutputWorkspace", wsname)); TS_ASSERT_THROWS_NOTHING( sqw.setPropertyValue("QAxisBinning", "0.5,0.25,2")); TS_ASSERT_THROWS_NOTHING(sqw.setPropertyValue("EMode", "Indirect")); @@ -58,8 +56,7 @@ public: TS_ASSERT(sqw.isExecuted()); auto &dataStore = Mantid::API::AnalysisDataService::Instance(); - auto result = - dataStore.retrieveWS<Mantid::API::MatrixWorkspace>(wsname); + auto result = dataStore.retrieveWS<Mantid::API::MatrixWorkspace>(wsname); dataStore.remove(wsname); return result; @@ -146,11 +143,14 @@ public: Mantid::Algorithms::SofQCommon emodeProperties; emodeProperties.initCachedValues(*inWS, &alg); const std::vector<double> eBinParams{-0.5, 0.1, -0.1, 0.2, 0.4}; - const std::vector<double> expectedEBinEdges{-0.5, -0.4, -0.3, -0.2, -0.1, 0.1, 0.3, 0.4}; + const std::vector<double> expectedEBinEdges{-0.5, -0.4, -0.3, -0.2, + -0.1, 0.1, 0.3, 0.4}; const std::vector<double> qBinParams{0.5, 0.1, 1.0, 0.2, 2.}; - const std::vector<double> expectedQBinEdges{0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.2, 1.4, 1.6, 1.8, 2.}; + const std::vector<double> expectedQBinEdges{0.5, 0.6, 0.7, 0.8, 0.9, 1.0, + 1.2, 1.4, 1.6, 1.8, 2.}; std::vector<double> qAxis; - auto outWS = Mantid::Algorithms::SofQW::setUpOutputWorkspace(inWS, qBinParams, qAxis, eBinParams, emodeProperties); + auto outWS = Mantid::Algorithms::SofQW::setUpOutputWorkspace( + inWS, qBinParams, qAxis, eBinParams, emodeProperties); TS_ASSERT_EQUALS(outWS->getNumberHistograms(), expectedQBinEdges.size() - 1) for (size_t i = 0; i < outWS->getNumberHistograms(); ++i) { const auto &x = outWS->x(i); @@ -188,9 +188,11 @@ public: } expectedEBinEdges.emplace_back(lastEdge); const std::vector<double> qBinParams{0.5, 0.25, 2.}; - const std::vector<double> expectedQBinEdges{0.5, 0.75, 1., 1.25, 1.5, 1.75, 2.}; + const std::vector<double> expectedQBinEdges{0.5, 0.75, 1., 1.25, + 1.5, 1.75, 2.}; std::vector<double> qAxis; - auto outWS = Mantid::Algorithms::SofQW::setUpOutputWorkspace(inWS, qBinParams, qAxis, eBinParams, emodeProperties); + auto outWS = Mantid::Algorithms::SofQW::setUpOutputWorkspace( + inWS, qBinParams, qAxis, eBinParams, emodeProperties); TS_ASSERT_EQUALS(outWS->getNumberHistograms(), expectedQBinEdges.size() - 1) for (size_t i = 0; i < outWS->getNumberHistograms(); ++i) { const auto &x = outWS->x(i); @@ -221,7 +223,8 @@ public: const double dQ{0.023}; const std::vector<double> qBinParams{dQ}; std::vector<double> qAxis; - auto outWS = Mantid::Algorithms::SofQW::setUpOutputWorkspace(inWS, qBinParams, qAxis, eBinParams, emodeProperties); + auto outWS = Mantid::Algorithms::SofQW::setUpOutputWorkspace( + inWS, qBinParams, qAxis, eBinParams, emodeProperties); for (size_t i = 0; i < outWS->getNumberHistograms(); ++i) { const auto &x = outWS->x(i); for (size_t j = 0; j < x.size(); ++j) { @@ -242,7 +245,7 @@ public: private: static bool isAlgorithmInHistory(const Mantid::API::MatrixWorkspace &result, - const std::string &name) { + const std::string &name) { // Loaded nexus file has 13 other entries const auto &wsHistory = result.getHistory(); const auto &lastAlg = wsHistory.getAlgorithmHistory(wsHistory.size() - 1); diff --git a/Framework/Kernel/inc/MantidKernel/VectorHelper.h b/Framework/Kernel/inc/MantidKernel/VectorHelper.h index ecfe4b64a09b50e7626cb64ff182bfdff99c864c..45bd4aaa115ea26113a476fc3d0a37b87ce245f2 100644 --- a/Framework/Kernel/inc/MantidKernel/VectorHelper.h +++ b/Framework/Kernel/inc/MantidKernel/VectorHelper.h @@ -40,13 +40,10 @@ namespace Kernel { Code Documentation is available at: <http://doxygen.mantidproject.org> */ namespace VectorHelper { -int MANTID_KERNEL_DLL -createAxisFromRebinParams(const std::vector<double> ¶ms, - std::vector<double> &xnew, - const bool resize_xnew = true, - const bool full_bins_only = false, - const double xMinHint = std::nan(""), - const double xMaxHint = std::nan("")); +int MANTID_KERNEL_DLL createAxisFromRebinParams( + const std::vector<double> ¶ms, std::vector<double> &xnew, + const bool resize_xnew = true, const bool full_bins_only = false, + const double xMinHint = std::nan(""), const double xMaxHint = std::nan("")); void MANTID_KERNEL_DLL rebin(const std::vector<double> &xold, const std::vector<double> &yold, diff --git a/Framework/Kernel/src/VectorHelper.cpp b/Framework/Kernel/src/VectorHelper.cpp index 3280d190a43b1e7344acfef6e0b215fc6377c873..f4f9a68b23a953bab2731a6552ee54a0648650b7 100644 --- a/Framework/Kernel/src/VectorHelper.cpp +++ b/Framework/Kernel/src/VectorHelper.cpp @@ -25,28 +25,31 @@ namespace VectorHelper { * @param[in] xMaxHint x_2 if params contains only delta_1. * @return The number of bin boundaries in the new axis **/ -int DLLExport createAxisFromRebinParams(const std::vector<double> ¶ms, - std::vector<double> &xnew, - const bool resize_xnew, - const bool full_bins_only, - const double xMinHint, - const double xMaxHint) { +int DLLExport +createAxisFromRebinParams(const std::vector<double> ¶ms, + std::vector<double> &xnew, const bool resize_xnew, + const bool full_bins_only, const double xMinHint, + const double xMaxHint) { std::vector<double> tmp; - const std::vector<double> &fullParams = [¶ms, &tmp, xMinHint, xMaxHint]() { - if (params.size() == 1) { - if (std::isnan(xMinHint) || std::isnan(xMaxHint)) { - throw std::runtime_error("createAxisFromRebinParams: xMinHint and xMaxHint must be supplied if params contains only the bin width."); - } - tmp.resize(3); - tmp = {xMinHint, params.front(), xMaxHint}; - return tmp; - } - return params; - }(); + const std::vector<double> &fullParams = + [¶ms, &tmp, xMinHint, xMaxHint]() { + if (params.size() == 1) { + if (std::isnan(xMinHint) || std::isnan(xMaxHint)) { + throw std::runtime_error("createAxisFromRebinParams: xMinHint and " + "xMaxHint must be supplied if params " + "contains only the bin width."); + } + tmp.resize(3); + tmp = {xMinHint, params.front(), xMaxHint}; + return tmp; + } + return params; + }(); double xs; int ibound(2), istep(1), inew(1); int ibounds = static_cast<int>( - fullParams.size()); // highest index in params array containing a bin boundary + fullParams + .size()); // highest index in params array containing a bin boundary int isteps = ibounds - 1; // highest index in params array containing a step xnew.clear(); diff --git a/Framework/Kernel/test/VectorHelperTest.h b/Framework/Kernel/test/VectorHelperTest.h index 1d0313ab9eef9f52a97b359899aeff2f097d2710..c9cae618898da04822f14631c967caaf28fe2b4e 100644 --- a/Framework/Kernel/test/VectorHelperTest.h +++ b/Framework/Kernel/test/VectorHelperTest.h @@ -170,7 +170,8 @@ public: void test_CreateAxisFromRebinParams_xMinXMaxHints() { const std::vector<double> rbParams = {1.0}; std::vector<double> axis; - TS_ASSERT_THROWS_NOTHING(VectorHelper::createAxisFromRebinParams(rbParams, axis, true, true, -5., 3.)) + TS_ASSERT_THROWS_NOTHING(VectorHelper::createAxisFromRebinParams( + rbParams, axis, true, true, -5., 3.)) const std::vector<double> expectedAxis = {-5, -4, -3, -2, -1, 0, 1, 2, 3}; TS_ASSERT_EQUALS(axis, expectedAxis); }