Commit 9bc53371 authored by Russell Taylor's avatar Russell Taylor
Browse files

Re #5570. First cut at an algorithm to combine peaks workspaces.

Follows exactly what's written in the ticket. Peaks in the second
workspace that are within the given Q tolerance in all directions
don't make it into the output.
Note that it's quite possible for a given peak in the first workspace
to be matched to multiple peaks in the second, if the tolerance
is large enough/the peaks are close together.
parent 301dd126
...@@ -85,6 +85,13 @@ namespace API ...@@ -85,6 +85,13 @@ namespace API
*/ */
virtual IPeak & getPeak(int peakNum) = 0; virtual IPeak & getPeak(int peakNum) = 0;
//---------------------------------------------------------------------------------------------
/** Return a reference to the Peak (const version)
* @param peakNum :: index of the peak to get.
* @return a reference to a Peak object.
*/
virtual const IPeak & getPeak(int peakNum) const = 0;
//--------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------
/** Return a pointer to the Peak /** Return a pointer to the Peak
* @param peakNum :: index of the peak to get. * @param peakNum :: index of the peak to get.
...@@ -99,7 +106,7 @@ namespace API ...@@ -99,7 +106,7 @@ namespace API
* @param detectorDistance :: distance between the sample and the detector. * @param detectorDistance :: distance between the sample and the detector.
* @return a pointer to a new Peak object. * @return a pointer to a new Peak object.
*/ */
virtual IPeak* createPeak(Mantid::Kernel::V3D QLabFrame, double detectorDistance=1.0) = 0; virtual IPeak* createPeak(Mantid::Kernel::V3D QLabFrame, double detectorDistance=1.0) const = 0;
}; };
......
...@@ -3,20 +3,17 @@ set ( SRC_FILES ...@@ -3,20 +3,17 @@ set ( SRC_FILES
src/AnvredCorrection.cpp src/AnvredCorrection.cpp
src/CalculateUMatrix.cpp src/CalculateUMatrix.cpp
src/CentroidPeaks.cpp src/CentroidPeaks.cpp
src/CombinePeaksWorkspaces.cpp
src/FindSXPeaks.cpp src/FindSXPeaks.cpp
src/FindUBUsingFFT.cpp src/FindUBUsingFFT.cpp
src/FindUBUsingIndexedPeaks.cpp src/FindUBUsingIndexedPeaks.cpp
src/FindUBUsingLatticeParameters.cpp src/FindUBUsingLatticeParameters.cpp
src/FindUBUsingMinMaxD.cpp src/FindUBUsingMinMaxD.cpp
src/IndexPeaks.cpp src/IndexPeaks.cpp
src/TransformHKL.cpp src/IndexSXPeaks.cpp
src/ShowPossibleCells.cpp
src/SelectCellOfType.cpp
src/SelectCellWithForm.cpp
src/IntegratePeakTimeSlices.cpp src/IntegratePeakTimeSlices.cpp
src/LoadHKL.cpp src/LoadHKL.cpp
src/LoadIsawPeaks.cpp src/LoadIsawPeaks.cpp
src/IndexSXPeaks.cpp
src/LoadIsawUB.cpp src/LoadIsawUB.cpp
src/MaskPeaksWorkspace.cpp src/MaskPeaksWorkspace.cpp
src/NormaliseVanadium.cpp src/NormaliseVanadium.cpp
...@@ -24,16 +21,20 @@ set ( SRC_FILES ...@@ -24,16 +21,20 @@ set ( SRC_FILES
src/PeakIntegration.cpp src/PeakIntegration.cpp
src/PeakIntensityVsRadius.cpp src/PeakIntensityVsRadius.cpp
src/PredictPeaks.cpp src/PredictPeaks.cpp
src/SCDCalibratePanels.cpp
src/SCDPanelErrors.cpp
src/SaveHKL.cpp src/SaveHKL.cpp
src/SaveIsawPeaks.cpp src/SaveIsawPeaks.cpp
src/SaveIsawUB.cpp src/SaveIsawUB.cpp
src/SavePeaksFile.cpp src/SavePeaksFile.cpp
src/SCDPanelErrors.cpp src/SelectCellOfType.cpp
src/SCDCalibratePanels.cpp src/SelectCellWithForm.cpp
src/SetGoniometer.cpp src/SetGoniometer.cpp
src/SetUB.cpp src/SetUB.cpp
src/ShowPossibleCells.cpp
src/SortHKL.cpp src/SortHKL.cpp
src/TOFExtinction.cpp src/TOFExtinction.cpp
src/TransformHKL.cpp
) )
set ( SRC_UNITY_IGNORE_FILES ) set ( SRC_UNITY_IGNORE_FILES )
...@@ -41,18 +42,15 @@ set ( INC_FILES ...@@ -41,18 +42,15 @@ set ( INC_FILES
inc/MantidCrystal/AnvredCorrection.h inc/MantidCrystal/AnvredCorrection.h
inc/MantidCrystal/CalculateUMatrix.h inc/MantidCrystal/CalculateUMatrix.h
inc/MantidCrystal/CentroidPeaks.h inc/MantidCrystal/CentroidPeaks.h
inc/MantidCrystal/CombinePeaksWorkspaces.h
inc/MantidCrystal/FindSXPeaks.h inc/MantidCrystal/FindSXPeaks.h
inc/MantidCrystal/FindUBUsingFFT.h inc/MantidCrystal/FindUBUsingFFT.h
inc/MantidCrystal/FindUBUsingIndexedPeaks.h inc/MantidCrystal/FindUBUsingIndexedPeaks.h
inc/MantidCrystal/FindUBUsingLatticeParameters.h inc/MantidCrystal/FindUBUsingLatticeParameters.h
inc/MantidCrystal/FindUBUsingMinMaxD.h inc/MantidCrystal/FindUBUsingMinMaxD.h
inc/MantidCrystal/GSLFunctions.h
inc/MantidCrystal/IndexPeaks.h inc/MantidCrystal/IndexPeaks.h
inc/MantidCrystal/TransformHKL.h inc/MantidCrystal/IndexSXPeaks.h
inc/MantidCrystal/ShowPossibleCells.h
inc/MantidCrystal/SelectCellOfType.h
inc/MantidCrystal/SelectCellWithForm.h
inc/MantidCrystal/IndexSXPeaks.h
inc/MantidCrystal/GSLFunctions.h
inc/MantidCrystal/IntegratePeakTimeSlices.h inc/MantidCrystal/IntegratePeakTimeSlices.h
inc/MantidCrystal/LoadHKL.h inc/MantidCrystal/LoadHKL.h
inc/MantidCrystal/LoadIsawPeaks.h inc/MantidCrystal/LoadIsawPeaks.h
...@@ -63,34 +61,35 @@ set ( INC_FILES ...@@ -63,34 +61,35 @@ set ( INC_FILES
inc/MantidCrystal/PeakIntegration.h inc/MantidCrystal/PeakIntegration.h
inc/MantidCrystal/PeakIntensityVsRadius.h inc/MantidCrystal/PeakIntensityVsRadius.h
inc/MantidCrystal/PredictPeaks.h inc/MantidCrystal/PredictPeaks.h
inc/MantidCrystal/SCDCalibratePanels.h
inc/MantidCrystal/SCDPanelErrors.h
inc/MantidCrystal/SaveHKL.h inc/MantidCrystal/SaveHKL.h
inc/MantidCrystal/SaveIsawPeaks.h inc/MantidCrystal/SaveIsawPeaks.h
inc/MantidCrystal/SaveIsawUB.h inc/MantidCrystal/SaveIsawUB.h
inc/MantidCrystal/SavePeaksFile.h inc/MantidCrystal/SavePeaksFile.h
inc/MantidCrystal/SCDPanelErrors.h inc/MantidCrystal/SelectCellOfType.h
inc/MantidCrystal/SCDCalibratePanels.h inc/MantidCrystal/SelectCellWithForm.h
inc/MantidCrystal/SetGoniometer.h inc/MantidCrystal/SetGoniometer.h
inc/MantidCrystal/SetUB.h inc/MantidCrystal/SetUB.h
inc/MantidCrystal/ShowPossibleCells.h
inc/MantidCrystal/SortHKL.h inc/MantidCrystal/SortHKL.h
inc/MantidCrystal/TOFExtinction.h inc/MantidCrystal/TOFExtinction.h
inc/MantidCrystal/TransformHKL.h
) )
set ( TEST_FILES set ( TEST_FILES
test/AnvredCorrectionTest.h test/AnvredCorrectionTest.h
test/CalculateUMatrixTest.h test/CalculateUMatrixTest.h
test/CentroidPeaksTest.h test/CentroidPeaksTest.h
test/CombinePeaksWorkspacesTest.h
test/FindSXPeaksTest.h test/FindSXPeaksTest.h
test/FindUBUsingFFTTest.h test/FindUBUsingFFTTest.h
test/FindUBUsingIndexedPeaksTest.h test/FindUBUsingIndexedPeaksTest.h
test/FindUBUsingLatticeParametersTest.h test/FindUBUsingLatticeParametersTest.h
test/FindUBUsingMinMaxDTest.h test/FindUBUsingMinMaxDTest.h
test/IndexPeaksTest.h test/IndexPeaksTest.h
test/TransformHKLTest.h test/IndexSXPeaksTest.h
test/ShowPossibleCellsTest.h test/IntegratePeakTimeSlicesTest.h
test/SelectCellOfTypeTest.h
test/SelectCellWithFormTest.h
test/IndexSXPeaksTest.h
test/IntegratePeakTimeSlicesTest.h
test/LoadHKLTest.h test/LoadHKLTest.h
test/LoadIsawPeaksTest.h test/LoadIsawPeaksTest.h
test/LoadIsawUBTest.h test/LoadIsawUBTest.h
...@@ -99,15 +98,19 @@ set ( TEST_FILES ...@@ -99,15 +98,19 @@ set ( TEST_FILES
test/PeakIntegrationTest.h test/PeakIntegrationTest.h
test/PeakIntensityVsRadiusTest.h test/PeakIntensityVsRadiusTest.h
test/PredictPeaksTest.h test/PredictPeaksTest.h
test/SCDCalibratePanelsTest.h
test/SCDPanelErrorsTest.h
test/SaveHKLTest.h test/SaveHKLTest.h
test/SaveIsawPeaksTest.h test/SaveIsawPeaksTest.h
test/SaveIsawUBTest.h test/SaveIsawUBTest.h
test/SavePeaksFileTest.h test/SavePeaksFileTest.h
test/SCDPanelErrorsTest.h test/SelectCellOfTypeTest.h
test/SCDCalibratePanelsTest.h test/SelectCellWithFormTest.h
test/SetGoniometerTest.h test/SetGoniometerTest.h
test/SetUBTest.h test/SetUBTest.h
test/ShowPossibleCellsTest.h
test/SortHKLTest.h test/SortHKLTest.h
test/TransformHKLTest.h
) )
if(UNITY_BUILD) if(UNITY_BUILD)
......
#ifndef MANTID_CRYSTAL_COMBINEPEAKSWORKSPACES_H_
#define MANTID_CRYSTAL_COMBINEPEAKSWORKSPACES_H_
#include "MantidAPI/Algorithm.h"
namespace Mantid
{
namespace Crystal
{
/** An algorithm that combines the sets of peaks in two peaks workspaces.
Optionally, peaks considered 'identical' are combined. Such peaks are those that are within
the given tolerance in all components of Q. The peak from the first/left workspace is kept.
Note that it is possible for multiple peaks in the rhs to be matched to a given lhs peak if
the tolerance is too large/the peaks are close together.
Copyright © 2012 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory
This file is part of Mantid.
Mantid is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
Mantid is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
class DLLExport CombinePeaksWorkspaces : public API::Algorithm
{
public:
CombinePeaksWorkspaces();
virtual ~CombinePeaksWorkspaces();
virtual const std::string name() const;
virtual int version() const;
virtual const std::string category() const;
private:
virtual void initDocs();
void init();
void exec();
};
} // namespace Crystal
} // namespace Mantid
#endif /* MANTID_CRYSTAL_COMBINEPEAKSWORKSPACES_H_ */
/*WIKI*
TODO: Enter a full wiki-markup description of your algorithm here. You can then use the Build/wiki_maker.py script to generate your full wiki page.
*WIKI*/
#include "MantidCrystal/CombinePeaksWorkspaces.h"
#include "MantidKernel/BoundedValidator.h"
#include "MantidKernel/EnabledWhenProperty.h"
#include "MantidDataObjects/PeaksWorkspace.h"
#include "MantidDataObjects/Peak.h"
namespace Mantid
{
namespace Crystal
{
// Register the algorithm into the AlgorithmFactory
DECLARE_ALGORITHM(CombinePeaksWorkspaces)
using namespace Kernel;
using namespace API;
using DataObjects::PeaksWorkspace;
using DataObjects::PeaksWorkspace_const_sptr;
using DataObjects::PeaksWorkspace_sptr;
using DataObjects::Peak;
/** Constructor
*/
CombinePeaksWorkspaces::CombinePeaksWorkspaces()
{
}
/** Destructor
*/
CombinePeaksWorkspaces::~CombinePeaksWorkspaces()
{
}
/// Algorithm's name for identification. @see Algorithm::name
const std::string CombinePeaksWorkspaces::name() const { return "CombinePeaksWorkspaces";};
/// Algorithm's version for identification. @see Algorithm::version
int CombinePeaksWorkspaces::version() const { return 1;};
/// Algorithm's category for identification. @see Algorithm::category
const std::string CombinePeaksWorkspaces::category() const { return "Crystal";}
/// Sets documentation strings for this algorithm
void CombinePeaksWorkspaces::initDocs()
{
this->setWikiSummary("Combines the sets of peaks in two peaks workspaces, optionally omitting duplicates.");
this->setOptionalMessage("Combines the sets of peaks in two peaks workspaces, optionally omitting duplicates.");
}
/** Initialises the algorithm's properties.
*/
void CombinePeaksWorkspaces::init()
{
declareProperty(new WorkspaceProperty<PeaksWorkspace>("LHSWorkspace","",Direction::Input),
"The first set of peaks.");
declareProperty(new WorkspaceProperty<PeaksWorkspace>("RHSWorkspace","",Direction::Input),
"The second set of peaks.");
declareProperty(new WorkspaceProperty<PeaksWorkspace>("OutputWorkspace","",Direction::Output),
"The combined peaks list.");
declareProperty("CombineMatchingPeaks", false,
"Whether to combine peaks that are identical across the two workspaces");
auto mustBePositive = boost::make_shared<BoundedValidator<double>>();
mustBePositive->setLower(0.0);
// N.B. Andrei reckons it should be delta_q/q
declareProperty("Tolerance", EMPTY_DBL(), mustBePositive,
"Maximum difference in each component of Q for which peaks are considered identical");
setPropertySettings("Tolerance", new EnabledWhenProperty("CombineMatchingPeaks", IS_EQUAL_TO, "1"));
}
/** Executes the algorithm.
*/
void CombinePeaksWorkspaces::exec()
{
PeaksWorkspace_const_sptr LHSWorkspace = getProperty("LHSWorkspace");
PeaksWorkspace_const_sptr RHSWorkspace = getProperty("RHSWorkspace");
const bool CombineMatchingPeaks = getProperty("CombineMatchingPeaks");
// Warn if not the same instrument, sample
if ( LHSWorkspace->getInstrument()->getName() != RHSWorkspace->getInstrument()->getName() )
{
g_log.warning("The two input workspaces do not appear to come from data take on the same instrument");
}
if ( LHSWorkspace->sample().getName() != RHSWorkspace->sample().getName() )
{
g_log.warning("The two input workspaces do not appear to relate to the same sample");
}
// Copy the first workspace to our output workspace
PeaksWorkspace_sptr output(LHSWorkspace->clone());
// Get hold of the peaks in the second workspace
auto & rhsPeaks = RHSWorkspace->getPeaks();
Progress progress(this, 0, 1, rhsPeaks.size());
// If not checking for matching peaks, then it's easy...
if ( ! CombineMatchingPeaks )
{
// Loop over the peaks in the second workspace, appending each one to the output
for ( size_t i = 0; i < rhsPeaks.size(); ++i )
{
output->addPeak(rhsPeaks[i]);
progress.report();
}
}
else // Check for matching peaks
{
const double Tolerance = getProperty("Tolerance");
// Get hold of the peaks in the first workspace as we'll need to examine them
auto & lhsPeaks = LHSWorkspace->getPeaks();
// Loop over the peaks in the second workspace, appending ones that don't match any in first workspace
for ( size_t i = 0; i < rhsPeaks.size(); ++i )
{
const Peak& currentPeak = rhsPeaks[i];
// Now have to go through the first workspace checking for matches
// Not doing anything clever as peaks workspace are typically not large - just a linear search
bool match = false;
for ( size_t j = 0; j < lhsPeaks.size(); ++j )
{
const V3D deltaQ = currentPeak.getQSampleFrame() - lhsPeaks[j].getQSampleFrame();
if ( deltaQ.nullVector(Tolerance) ) // Using a V3D method that does the job
{
match = true;
break;
}
}
// Only add the peak if there was no match
if ( ! match ) output->addPeak(currentPeak);
progress.report();
}
}
setProperty("OutputWorkspace", output);
}
} // namespace Crystal
} // namespace Mantid
#ifndef MANTID_CRYSTAL_COMBINEPEAKSWORKSPACESTEST_H_
#define MANTID_CRYSTAL_COMBINEPEAKSWORKSPACESTEST_H_
#include <cxxtest/TestSuite.h>
#include "MantidTestHelpers/WorkspaceCreationHelper.h"
#include "MantidCrystal/CombinePeaksWorkspaces.h"
#include "MantidDataObjects/PeaksWorkspace.h"
using Mantid::Crystal::CombinePeaksWorkspaces;
class CombinePeaksWorkspacesTest : 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 CombinePeaksWorkspacesTest *createSuite() { return new CombinePeaksWorkspacesTest(); }
static void destroySuite( CombinePeaksWorkspacesTest *suite ) { delete suite; }
void test_init()
{
CombinePeaksWorkspaces alg;
TS_ASSERT_THROWS_NOTHING( alg.initialize() )
TS_ASSERT( alg.isInitialized() )
}
void test_invalid_input()
{
CombinePeaksWorkspaces alg;
TS_ASSERT_THROWS_NOTHING( alg.initialize() )
// Tolerance has to be positive. Even if CombineMatchingPeaks is false!
TS_ASSERT_THROWS( alg.setProperty("Tolerance", -1.0), std::invalid_argument )
}
void test_keep_all_peaks()
{
using namespace Mantid::API;
using namespace Mantid::DataObjects;
PeaksWorkspace_sptr lhsWS = WorkspaceCreationHelper::createPeaksWorkspace();
PeaksWorkspace_sptr rhsWS = WorkspaceCreationHelper::createPeaksWorkspace(3);
// Name of the output workspace.
std::string outWSName("CombinePeaksWorkspacesTest_OutputWS");
CombinePeaksWorkspaces alg;
TS_ASSERT_THROWS_NOTHING( alg.initialize() )
TS_ASSERT_THROWS_NOTHING( alg.setProperty("LHSWorkspace", lhsWS) )
TS_ASSERT_THROWS_NOTHING( alg.setProperty("RHSWorkspace", rhsWS) )
TS_ASSERT_THROWS_NOTHING( alg.setPropertyValue("OutputWorkspace", outWSName) )
TS_ASSERT( alg.execute() )
// Retrieve the workspace from data service.
IPeaksWorkspace_const_sptr ws;
TS_ASSERT_THROWS_NOTHING( ws = AnalysisDataService::Instance().retrieveWS<IPeaksWorkspace>(outWSName) );
TS_ASSERT(ws);
if (!ws) return;
TS_ASSERT_EQUALS( ws->getNumberPeaks(), 5 )
TS_ASSERT_EQUALS( ws->getPeak(0).getQLabFrame(), ws->getPeak(2).getQLabFrame() )
TS_ASSERT_EQUALS( ws->getPeak(1).getQLabFrame(), ws->getPeak(3).getQLabFrame() )
TS_ASSERT_DELTA( ws->getPeak(4).getWavelength(), 2.5, 0.001 )
TS_ASSERT_EQUALS( ws->getInstrument()->baseInstrument(), lhsWS->getInstrument()->baseInstrument() )
// Remove workspace from the data service.
AnalysisDataService::Instance().remove(outWSName);
}
void test_match_peaks_identical_workspaces()
{
using namespace Mantid::API;
using namespace Mantid::DataObjects;
PeaksWorkspace_sptr inWS = WorkspaceCreationHelper::createPeaksWorkspace();
// Name of the output workspace.
std::string outWSName("CombinePeaksWorkspacesTest_OutputWS");
CombinePeaksWorkspaces alg;
TS_ASSERT_THROWS_NOTHING( alg.initialize() )
TS_ASSERT_THROWS_NOTHING( alg.setProperty("LHSWorkspace", inWS) )
TS_ASSERT_THROWS_NOTHING( alg.setProperty("RHSWorkspace", inWS) )
TS_ASSERT_THROWS_NOTHING( alg.setProperty("CombineMatchingPeaks", true) )
TS_ASSERT_THROWS_NOTHING( alg.setPropertyValue("OutputWorkspace", outWSName) )
TS_ASSERT( alg.execute() )
// Retrieve the workspace from data service.
IPeaksWorkspace_const_sptr ws;
TS_ASSERT_THROWS_NOTHING( ws = AnalysisDataService::Instance().retrieveWS<IPeaksWorkspace>(outWSName) );
TS_ASSERT(ws);
if (!ws) return;
TS_ASSERT_EQUALS( ws->getNumberPeaks(), 2 )
TS_ASSERT_EQUALS( ws->getPeak(0).getWavelength(), inWS->getPeak(0).getWavelength() )
TS_ASSERT_EQUALS( ws->getPeak(1).getWavelength(), inWS->getPeak(1).getWavelength() )
TS_ASSERT_EQUALS( ws->getInstrument()->baseInstrument(), inWS->getInstrument()->baseInstrument() )
// Remove workspace from the data service.
AnalysisDataService::Instance().remove(outWSName);
}
void test_match_peaks_within_tolerance()
{
using namespace Mantid::API;
using namespace Mantid::DataObjects;
PeaksWorkspace_sptr lhsWS = WorkspaceCreationHelper::createPeaksWorkspace(4);
PeaksWorkspace_sptr rhsWS = WorkspaceCreationHelper::createPeaksWorkspace(4);
// Slightly adjust the peaks in one of the workspaces
auto & rhsPeaks = rhsWS->getPeaks();
auto & lhsPeaks = lhsWS->getPeaks();
// Need to change a couple of detector IDs so that I can get peaks with larger |Q_z| than |Q_x|
lhsPeaks[2].setDetectorID(50);
lhsPeaks[3].setDetectorID(51);
rhsPeaks[2].setDetectorID(50);
rhsPeaks[3].setDetectorID(51);
// And need to shift some peaks in one workspace to test the delta checking
// This one will fails to match in x & z
rhsPeaks[0].setWavelength(rhsPeaks[0].getWavelength()*1.01);
// This one matches in z but not in x
rhsPeaks[1].setWavelength(rhsPeaks[1].getWavelength()*1.02);
// This one matches in x but not z
rhsPeaks[2].setWavelength(rhsPeaks[2].getWavelength()*1.0335);
// This one will be matched (to lhsPeaks[0]) and will not appear in the output
rhsPeaks[3].setWavelength(rhsPeaks[3].getWavelength()*1.04);
// Name of the output workspace.
std::string outWSName("CombinePeaksWorkspacesTest_OutputWS");
CombinePeaksWorkspaces alg;
TS_ASSERT_THROWS_NOTHING( alg.initialize() )
TS_ASSERT_THROWS_NOTHING( alg.setProperty("LHSWorkspace", lhsWS) )
TS_ASSERT_THROWS_NOTHING( alg.setProperty("RHSWorkspace", rhsWS) )
TS_ASSERT_THROWS_NOTHING( alg.setProperty("CombineMatchingPeaks", true) )
TS_ASSERT_THROWS_NOTHING( alg.setProperty("Tolerance", 0.08145) )
TS_ASSERT_THROWS_NOTHING( alg.setPropertyValue("OutputWorkspace", outWSName) )
TS_ASSERT( alg.execute() )
// Retrieve the workspace from data service.
IPeaksWorkspace_const_sptr ws;
TS_ASSERT_THROWS_NOTHING( ws = AnalysisDataService::Instance().retrieveWS<IPeaksWorkspace>(outWSName) );
TS_ASSERT(ws);
if (!ws) return;
TS_ASSERT_EQUALS( ws->getNumberPeaks(), 7 )
TS_ASSERT_EQUALS( ws->getPeak(0).getQLabFrame(), lhsWS->getPeak(0).getQLabFrame() )
TS_ASSERT_EQUALS( ws->getPeak(1).getQLabFrame(), lhsWS->getPeak(1).getQLabFrame() )
TS_ASSERT_EQUALS( ws->getPeak(2).getQLabFrame(), lhsWS->getPeak(2).getQLabFrame() )
TS_ASSERT_EQUALS( ws->getPeak(3).getQLabFrame(), lhsWS->getPeak(3).getQLabFrame() )
TS_ASSERT_EQUALS( ws->getPeak(4).getQLabFrame(), rhsWS->getPeak(0).getQLabFrame() )
TS_ASSERT_EQUALS( ws->getPeak(5).getQLabFrame(), rhsWS->getPeak(1).getQLabFrame() )
TS_ASSERT_EQUALS( ws->getPeak(6).getQLabFrame(), rhsWS->getPeak(2).getQLabFrame() )
TS_ASSERT_EQUALS( ws->getInstrument()->baseInstrument(), lhsWS->getInstrument()->baseInstrument() )
// Remove workspace from the data service.
AnalysisDataService::Instance().remove(outWSName);
}
};
#endif /* MANTID_CRYSTAL_COMBINEPEAKSWORKSPACESTEST_H_ */
...@@ -91,8 +91,10 @@ namespace DataObjects ...@@ -91,8 +91,10 @@ namespace DataObjects
void removePeak(int peakNum); void removePeak(int peakNum);
void addPeak(const API::IPeak& ipeak); void addPeak(const API::IPeak& ipeak);
API::IPeak & getPeak(int peakNum); API::IPeak & getPeak(int peakNum);
API::IPeak* createPeak(Kernel::V3D QLabFrame, double detectorDistance=1.0); const API::IPeak & getPeak(int peakNum) const;
API::IPeak* createPeak(Kernel::V3D QLabFrame, double detectorDistance=1.0) const;
std::vector<Peak> & getPeaks(); std::vector<Peak> & getPeaks();
const std::vector<Peak> & getPeaks() const;
virtual size_t getMemorySize() const; virtual size_t getMemorySi