diff --git a/Framework/Algorithms/src/LineProfile.cpp b/Framework/Algorithms/src/LineProfile.cpp index 85cb5cb2ac17a704aa5ec2c1d07a5f0643228001..ef287132a4b78f595553bc9d84353db768e62a07 100644 --- a/Framework/Algorithms/src/LineProfile.cpp +++ b/Framework/Algorithms/src/LineProfile.cpp @@ -414,9 +414,13 @@ void LineProfile::exec() { // specified. Box actualBounds; actualBounds.top = verticalBins[vertInterval.first]; - actualBounds.bottom = verticalBins[vertInterval.second]; + actualBounds.bottom = vertInterval.second < verticalBins.size() + ? verticalBins[vertInterval.second] + : verticalBins.back(); actualBounds.left = horizontalBins[horInterval.first]; - actualBounds.right = horizontalBins[horInterval.second]; + actualBounds.right = horInterval.second < horizontalBins.size() + ? horizontalBins[horInterval.second] + : horizontalBins.back(); setAxesAndUnits(*outWS, *ws, actualBounds, dir); setProperty(PropertyNames::OUTPUT_WORKSPACE, outWS); } diff --git a/Framework/Algorithms/src/PhaseQuadMuon.cpp b/Framework/Algorithms/src/PhaseQuadMuon.cpp index fe76ee5b8187a1f1cc281051efe0615fa5cd23a6..b87f0d41f675e3c572ac21761e609784499a87fc 100644 --- a/Framework/Algorithms/src/PhaseQuadMuon.cpp +++ b/Framework/Algorithms/src/PhaseQuadMuon.cpp @@ -226,16 +226,14 @@ PhaseQuadMuon::squash(const API::MatrixWorkspace_sptr &ws, auto &realE = ows->mutableE(0); auto &imagE = ows->mutableE(1); + const auto &xPointData = ws->histogram(0).points(); // First X value - const double X0 = ws->x(0).front(); + const double X0 = xPointData.front(); // calculate exponential decay outside of the loop - std::vector<double> expDecay(ws->histogram(0).size()); // make a copy - { // limit scope - const auto &X = ws->readX(0); - for (size_t i = 0; i < X.size(); ++i) - expDecay[i] = exp(-(X[i] - X0) / muLife); - } + std::vector<double> expDecay = xPointData.rawData(); + std::transform(expDecay.begin(), expDecay.end(), expDecay.begin(), + [X0, muLife](double x) { return exp(-(x - X0) / muLife); }); for (size_t i = 0; i < npoints; i++) { for (size_t h = 0; h < nspec; h++) { diff --git a/Framework/Algorithms/test/LineProfileTest.h b/Framework/Algorithms/test/LineProfileTest.h index 29aabefeb41a3861c80cf3db11a47736277a13f7..341a432410e675d27e205cb5aad5ff0a0c2734b7 100644 --- a/Framework/Algorithms/test/LineProfileTest.h +++ b/Framework/Algorithms/test/LineProfileTest.h @@ -155,6 +155,40 @@ public: TS_ASSERT_EQUALS(vertAxis->getValue(1), 5.0) } + void test_horizontal_profile_larger_than_workspace() { + const size_t nHist = 1; + const size_t nBins = 1; + MatrixWorkspace_sptr inputWS = create2DWorkspace154(nHist, nBins); + LineProfile alg; + // Don't put output in ADS by default + alg.setChild(true); + alg.setRethrows(true); + TS_ASSERT_THROWS_NOTHING(alg.initialize()) + TS_ASSERT(alg.isInitialized()) + TS_ASSERT_THROWS_NOTHING(alg.setProperty("InputWorkspace", inputWS)) + TS_ASSERT_THROWS_NOTHING( + alg.setPropertyValue("OutputWorkspace", "_unused_for_child")) + TS_ASSERT_THROWS_NOTHING(alg.setProperty("Direction", "Horizontal")) + TS_ASSERT_THROWS_NOTHING( + alg.setProperty("Centre", static_cast<double>(nHist) / 2)) + TS_ASSERT_THROWS_NOTHING(alg.setProperty("HalfWidth", 2.0 * nBins)) + TS_ASSERT_THROWS_NOTHING(alg.execute()) + TS_ASSERT(alg.isExecuted()) + + Workspace2D_sptr outputWS = alg.getProperty("OutputWorkspace"); + TS_ASSERT(outputWS); + TS_ASSERT_EQUALS(outputWS->getNumberHistograms(), 1) + const auto hist = outputWS->histogram(0); + TS_ASSERT_EQUALS(hist.xMode(), Histogram::XMode::Points) + TS_ASSERT_EQUALS(hist.size(), 1) + TS_ASSERT_EQUALS(hist.x().front(), 1.0) + TS_ASSERT_EQUALS(hist.y().front(), 5.0) + TS_ASSERT_EQUALS(hist.e().front(), 4.0) + const auto vertAxis = outputWS->getAxis(1); + TS_ASSERT_EQUALS(vertAxis->getValue(0), 1.0) + TS_ASSERT_EQUALS(vertAxis->getValue(1), 1.0) + } + void test_vertical_profile() { const size_t nHist = 13; const size_t nBins = 23; diff --git a/Framework/Algorithms/test/PhaseQuadMuonTest.h b/Framework/Algorithms/test/PhaseQuadMuonTest.h index 0bef833612188a0b3c22b33381d26448bda8dcda..005d3b233609841b102baf6a82b1fa822371295c 100644 --- a/Framework/Algorithms/test/PhaseQuadMuonTest.h +++ b/Framework/Algorithms/test/PhaseQuadMuonTest.h @@ -87,17 +87,17 @@ public: const auto specImY = outputWs->getSpectrum(1).y(); const auto specImE = outputWs->getSpectrum(1).e(); // Check real Y values - TS_ASSERT_DELTA(specReY[0], -0.9982, 0.0001); - TS_ASSERT_DELTA(specReY[20], -0.0252, 0.0001); - TS_ASSERT_DELTA(specReY[50], 0.0264, 0.0001); + TS_ASSERT_DELTA(specReY[0], -1.0019, 0.0001); + TS_ASSERT_DELTA(specReY[20], -0.0289, 0.0001); + TS_ASSERT_DELTA(specReY[50], 0.0227, 0.0001); // Check real E values TS_ASSERT_DELTA(specReE[0], 0.0010, 0.0001); TS_ASSERT_DELTA(specReE[20], 0.0021, 0.0001); TS_ASSERT_DELTA(specReE[50], 0.0024, 0.0001); // Check imaginary Y values - TS_ASSERT_DELTA(specImY[0], -0.9974, 0.0001); - TS_ASSERT_DELTA(specImY[20], 0.0115, 0.0001); - TS_ASSERT_DELTA(specImY[50], 0.0316, 0.0001); + TS_ASSERT_DELTA(specImY[0], -1.0011, 0.0001); + TS_ASSERT_DELTA(specImY[20], 0.0079, 0.0001); + TS_ASSERT_DELTA(specImY[50], 0.0280, 0.0001); // Check imaginary E values TS_ASSERT_DELTA(specImE[0], 0.0029, 0.0001); TS_ASSERT_DELTA(specImE[20], 0.0031, 0.0001); diff --git a/docs/source/release/v3.11.0/framework.rst b/docs/source/release/v3.11.0/framework.rst index f090c91545bf645f1f6f75dd06c4e16ee379c29c..31ec178d4b5a790250e8b16c7cfb891b2524b229 100644 --- a/docs/source/release/v3.11.0/framework.rst +++ b/docs/source/release/v3.11.0/framework.rst @@ -56,6 +56,7 @@ Improved - :ref:`LoadBBY <algm-LoadBBY-v1>`: Fixed bug where the logManager did not work with sample_name, sample_aperture and source_aperture. Also added more information regarding the sample and the selected choppers. - :ref:`ConvertSpectrumAxis <algm-ConvertSpectrumAxis-v2>`: Added an option to disable the sorting of the resulting axis making it useful especially for scanning workspaces. Also reduced the complexity of the operation for the default (ordered axis) case from *Nˆ2* to *N*. - :ref:`MSDFit <algm-MSDFit>` now supports model selection. Currently has the option of 3 models: MsdGauss, MsdPeters and MsdYi. +- :ref:`algm-LineProfile`: Fixed a bug which could cause crashes when the line extended over the right or bottom edge of a workspace. Deprecated ########## @@ -95,7 +96,7 @@ Bug fixes Improved ######## -- `:ref:`Fit` Outputs a function object containing the optimized parameter values. +- :ref:`Fit <algm-Fit>` outputs a function object containing the optimized parameter values. See the usage examples for more detail. Python ------