diff --git a/Framework/Algorithms/inc/MantidAlgorithms/CalculatePolynomialBackground.h b/Framework/Algorithms/inc/MantidAlgorithms/CalculatePolynomialBackground.h index fa1c007f4e81574db5012560ba04fe5a406e7ac7..f43372b4a60104dfe8a34cd0a5f59d39106842a2 100644 --- a/Framework/Algorithms/inc/MantidAlgorithms/CalculatePolynomialBackground.h +++ b/Framework/Algorithms/inc/MantidAlgorithms/CalculatePolynomialBackground.h @@ -30,7 +30,8 @@ namespace Algorithms { File change history is stored at: <https://github.com/mantidproject/mantid> Code Documentation is available at: <http://doxygen.mantidproject.org> */ -class MANTID_ALGORITHMS_DLL CalculatePolynomialBackground : public API::Algorithm { +class MANTID_ALGORITHMS_DLL CalculatePolynomialBackground + : public API::Algorithm { public: const std::string name() const override; int version() const override; diff --git a/Framework/Algorithms/src/CalculatePolynomialBackground.cpp b/Framework/Algorithms/src/CalculatePolynomialBackground.cpp index b1417390504fd5cb78256ef93c8487ca1d402696..0908df42c653c980b6c5b2e2fa76b1920b69bb9e 100644 --- a/Framework/Algorithms/src/CalculatePolynomialBackground.cpp +++ b/Framework/Algorithms/src/CalculatePolynomialBackground.cpp @@ -28,7 +28,9 @@ constexpr char *XRANGES = "XRanges"; * @param wsIndex a workspace index to specify a histogram in ws * @return a ranges-like vector with filtered pairs removed */ -std::vector<double> filterRangesOutsideX(const std::vector<double> &ranges, const Mantid::API::MatrixWorkspace &ws, const size_t wsIndex) { +std::vector<double> filterRangesOutsideX(const std::vector<double> &ranges, + const Mantid::API::MatrixWorkspace &ws, + const size_t wsIndex) { const auto minX = ws.x(wsIndex).front(); const auto maxX = ws.x(wsIndex).back(); std::vector<double> filtered; @@ -49,7 +51,9 @@ std::vector<double> filterRangesOutsideX(const std::vector<double> &ranges, cons * @param totalRange a pair of start-end values to limit the output ranges * @return a ranges-like vector of processed ranges */ -std::vector<double> includedRanges(const std::vector<double> &ranges, const std::pair<double, double> &totalRange) { +std::vector<double> +includedRanges(const std::vector<double> &ranges, + const std::pair<double, double> &totalRange) { if (ranges.empty()) { return {totalRange.first, totalRange.second}; } @@ -61,12 +65,14 @@ std::vector<double> includedRanges(const std::vector<double> &ranges, const std: edges[i].first = ranges[i]; edges[i].second = i % 2 == 0 ? Edge::start : Edge::end; } - std::sort(edges.begin(), edges.end(), [](const std::pair<double, Edge> &p1, const std::pair<double, Edge> &p2) { + std::sort(edges.begin(), edges.end(), [](const std::pair<double, Edge> &p1, + const std::pair<double, Edge> &p2) { if (p1.first == p2.first) return p1.second == Edge::start; return p1.first < p2.first; }); - // If an 'end' edge is followed by a 'start', we have a new range. Everything else + // If an 'end' edge is followed by a 'start', we have a new range. Everything + // else // can be merged. std::vector<double> mergedRanges; mergedRanges.reserve(ranges.size()); @@ -135,7 +141,9 @@ std::string makeFunctionString(const std::vector<double> ¶meters) { * @param wsIndex a workspace index identifying a histogram * @return a pair of values spanning a range */ -std::pair<double, double> totalRange(const std::vector<double> &ranges, const Mantid::API::MatrixWorkspace &ws, const size_t wsIndex) { +std::pair<double, double> totalRange(const std::vector<double> &ranges, + const Mantid::API::MatrixWorkspace &ws, + const size_t wsIndex) { const auto minX = ws.x(wsIndex).front(); const auto maxX = ws.x(wsIndex).back(); if (ranges.empty()) { @@ -144,7 +152,8 @@ std::pair<double, double> totalRange(const std::vector<double> &ranges, const Ma const auto minmaxIt = std::minmax_element(ranges.cbegin(), ranges.cend()); const auto minEdge = *minmaxIt.first; const auto maxEdge = *minmaxIt.second; - return std::pair<double, double>(std::min(minEdge, minX), std::max(maxEdge, maxX)); + return std::pair<double, double>(std::min(minEdge, minX), + std::max(maxEdge, maxX)); } } @@ -157,7 +166,9 @@ DECLARE_ALGORITHM(CalculatePolynomialBackground) //---------------------------------------------------------------------------------------------- /// Algorithms name for identification. @see Algorithm::name -const std::string CalculatePolynomialBackground::name() const { return "CalculatePolynomialBackground"; } +const std::string CalculatePolynomialBackground::name() const { + return "CalculatePolynomialBackground"; +} /// Algorithm's version for identification. @see Algorithm::version int CalculatePolynomialBackground::version() const { return 1; } @@ -179,17 +190,21 @@ void CalculatePolynomialBackground::init() { auto increasingAxis = boost::make_shared<API::IncreasingAxisValidator>(); auto nonnegativeInt = boost::make_shared<Kernel::BoundedValidator<int>>(); nonnegativeInt->setLower(0); - auto orderedPairs = boost::make_shared<Kernel::ArrayOrderedPairsValidator<double>>(); + auto orderedPairs = + boost::make_shared<Kernel::ArrayOrderedPairsValidator<double>>(); declareProperty( - Kernel::make_unique<API::WorkspaceProperty<API::MatrixWorkspace>>(Prop::INPUT_WS, "", - Kernel::Direction::Input, increasingAxis), + Kernel::make_unique<API::WorkspaceProperty<API::MatrixWorkspace>>( + Prop::INPUT_WS, "", Kernel::Direction::Input, increasingAxis), "An input workspace."); declareProperty( - Kernel::make_unique<API::WorkspaceProperty<API::MatrixWorkspace>>(Prop::OUTPUT_WS, "", - Kernel::Direction::Output), + Kernel::make_unique<API::WorkspaceProperty<API::MatrixWorkspace>>( + Prop::OUTPUT_WS, "", Kernel::Direction::Output), "A workspace containing the fitted background."); - declareProperty(Prop::POLY_DEGREE, 0, nonnegativeInt, "Degree of the fitted polynomial."); - declareProperty(Kernel::make_unique<Kernel::ArrayProperty<double>>(Prop::XRANGES, std::vector<double>(), orderedPairs), "A list of fitting ranges given as pairs of X values."); + declareProperty(Prop::POLY_DEGREE, 0, nonnegativeInt, + "Degree of the fitted polynomial."); + declareProperty(Kernel::make_unique<Kernel::ArrayProperty<double>>( + Prop::XRANGES, std::vector<double>(), orderedPairs), + "A list of fitting ranges given as pairs of X values."); } //---------------------------------------------------------------------------------------------- @@ -198,9 +213,11 @@ void CalculatePolynomialBackground::init() { void CalculatePolynomialBackground::exec() { API::MatrixWorkspace_sptr inWS = getProperty(Prop::INPUT_WS); - API::MatrixWorkspace_sptr outWS{DataObjects::create<DataObjects::Workspace2D>(*inWS)}; + API::MatrixWorkspace_sptr outWS{ + DataObjects::create<DataObjects::Workspace2D>(*inWS)}; const std::vector<double> ranges = getProperty(Prop::XRANGES); - const auto polyDegree = static_cast<size_t>(static_cast<int>(getProperty(Prop::POLY_DEGREE))); + const auto polyDegree = + static_cast<size_t>(static_cast<int>(getProperty(Prop::POLY_DEGREE))); const std::vector<double> initialParams(polyDegree + 1, 0.1); const auto fitFunction = makeFunctionString(initialParams); const auto nHistograms = static_cast<int64_t>(inWS->getNumberHistograms()); @@ -211,7 +228,9 @@ void CalculatePolynomialBackground::exec() { PARALLEL_START_INTERUPT_REGION const auto filteredRanges = filterRangesOutsideX(ranges, *inWS, i); if (!ranges.empty() && filteredRanges.empty()) { - throw std::runtime_error("The given XRanges mismatch with the histogram at workspace index " + std::to_string(i)); + throw std::runtime_error( + "The given XRanges mismatch with the histogram at workspace index " + + std::to_string(i)); } const auto fullRange = totalRange(filteredRanges, *inWS, i); const auto includedR = includedRanges(filteredRanges, fullRange); @@ -233,7 +252,8 @@ void CalculatePolynomialBackground::exec() { paramErrors[row] = fitResult->cell<double>(row, 2); } const auto bkgFunction = makeFunctionString(parameters); - auto bkg = boost::dynamic_pointer_cast<API::IFunction1D>(API::FunctionFactory::Instance().createInitialized(bkgFunction)); + auto bkg = boost::dynamic_pointer_cast<API::IFunction1D>( + API::FunctionFactory::Instance().createInitialized(bkgFunction)); // We want bkg to directly write to the output workspace. double *bkgY = const_cast<double *>(outWS->mutableY(i).rawData().data()); bkg->function1D(bkgY, outWS->points(i).rawData().data(), nBins); diff --git a/Framework/Algorithms/test/CalculatePolynomialBackgroundTest.h b/Framework/Algorithms/test/CalculatePolynomialBackgroundTest.h index e65a651225f8417e26219f246d5fdbc1cbba52ba..7891180d25328c47c0c8d357d4fe1a0bb7119d16 100644 --- a/Framework/Algorithms/test/CalculatePolynomialBackgroundTest.h +++ b/Framework/Algorithms/test/CalculatePolynomialBackgroundTest.h @@ -17,9 +17,12 @@ class CalculatePolynomialBackgroundTest : public CxxTest::TestSuite { public: // This pair of boilerplate methods prevent the suite being created statically // This means the constructor isn't called when running other tests - static CalculatePolynomialBackgroundTest *createSuite() { return new CalculatePolynomialBackgroundTest(); } - static void destroySuite( CalculatePolynomialBackgroundTest *suite ) { delete suite; } - + static CalculatePolynomialBackgroundTest *createSuite() { + return new CalculatePolynomialBackgroundTest(); + } + static void destroySuite(CalculatePolynomialBackgroundTest *suite) { + delete suite; + } CalculatePolynomialBackgroundTest() { API::FrameworkManager::Instance(); } @@ -67,7 +70,8 @@ public: const auto &bkgXs = outWS->x(histI); for (size_t binI = 0; binI < nBin; ++binI) { TS_ASSERT_DELTA(bkgYs[binI], ys[binI], 1e-12) - TS_ASSERT_DELTA(bkgEs[binI], es[binI] / std::sqrt(static_cast<double>(nBin)), 1e-12) + TS_ASSERT_DELTA(bkgEs[binI], + es[binI] / std::sqrt(static_cast<double>(nBin)), 1e-12) TS_ASSERT_EQUALS(bkgXs[binI], xs[binI]) } } @@ -110,7 +114,8 @@ public: const auto nBin = edges.size() - 1; const HistogramData::Counts counts{1.0, 2.0, 0.0, 0.0, 5.0, 6.0}; const HistogramData::Histogram h{edges, counts}; - auto ws = API::MatrixWorkspace_sptr(DataObjects::create<DataObjects::Workspace2D>(nHist, h)); + auto ws = API::MatrixWorkspace_sptr( + DataObjects::create<DataObjects::Workspace2D>(nHist, h)); auto alg = makeAlgorithm(); TS_ASSERT_THROWS_NOTHING(alg->setProperty("InputWorkspace", ws)) TS_ASSERT_THROWS_NOTHING(alg->setProperty("OutputWorkspace", "outputWS")) @@ -134,7 +139,8 @@ public: } private: - static boost::shared_ptr<Algorithms::CalculatePolynomialBackground> makeAlgorithm() { + static boost::shared_ptr<Algorithms::CalculatePolynomialBackground> + makeAlgorithm() { auto a = boost::make_shared<Algorithms::CalculatePolynomialBackground>(); a->initialize(); a->setChild(true); @@ -143,5 +149,4 @@ private: } }; - #endif /* MANTID_ALGORITHMS_CALCULATEPOLYNOMIALBACKGROUNDTEST_H_ */ diff --git a/Framework/CurveFitting/test/Functions/ProductFunctionTest.h b/Framework/CurveFitting/test/Functions/ProductFunctionTest.h index 89734c9fdc34bb9a13a3d9fdd3f1a285b553cbae..7000062ccd0d93ca8ba6e2f545376fa4f43ea3c8 100644 --- a/Framework/CurveFitting/test/Functions/ProductFunctionTest.h +++ b/Framework/CurveFitting/test/Functions/ProductFunctionTest.h @@ -10,7 +10,6 @@ #include "MantidCurveFitting/Functions/Gaussian.h" #include "MantidDataObjects/Workspace2D.h" - typedef Mantid::DataObjects::Workspace2D_sptr WS_type; using Mantid::CurveFitting::Functions::ProductFunction; using Mantid::CurveFitting::Functions::Gaussian; diff --git a/Framework/SINQ/test/PoldiSpectrumLinearBackgroundTest.h b/Framework/SINQ/test/PoldiSpectrumLinearBackgroundTest.h index 296768632d7f79a7c8346956435598abb19b341f..536ea7bd12f0681ac4652222b6a23ea7e1b0f583 100644 --- a/Framework/SINQ/test/PoldiSpectrumLinearBackgroundTest.h +++ b/Framework/SINQ/test/PoldiSpectrumLinearBackgroundTest.h @@ -95,8 +95,7 @@ public: function->setParameter("A1", 2.0); FunctionDomain1DSpectrum domainOne(1, m_xValues); - Mantid::API::BasicJacobian jacobian(domainOne.size(), - function->nParams()); + Mantid::API::BasicJacobian jacobian(domainOne.size(), function->nParams()); function->functionDeriv(domainOne, jacobian); for (size_t i = 0; i < domainOne.size(); ++i) {