Skip to content

Commit

Permalink
refs #11056. Simplify test setup
Browse files Browse the repository at this point in the history
Also changed the getPeakShape public method to be const, as this is the right sort of behaviour as the PeakShape should be immutable and should not cause internal change to Peak.
  • Loading branch information
OwenArnold committed Feb 26, 2015
1 parent 333433e commit 5542c3b
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 46 deletions.
2 changes: 1 addition & 1 deletion Code/Mantid/Framework/API/inc/MantidAPI/IPeak.h
Expand Up @@ -87,7 +87,7 @@ class MANTID_API_DLL IPeak {
virtual double getL1() const = 0;
virtual double getL2() const = 0;

virtual const Mantid::Geometry::PeakShape& getPeakShape() = 0;
virtual const Mantid::Geometry::PeakShape& getPeakShape() const = 0;
};

} // namespace Mantid
Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/Framework/API/test/MockObjects.h
Expand Up @@ -156,7 +156,7 @@ namespace
Mantid::Kernel::V3D());
MOCK_CONST_METHOD0(getDetectorPositionNoCheck,
Mantid::Kernel::V3D());
MOCK_METHOD0(getPeakShape, const Mantid::Geometry::PeakShape&());
MOCK_CONST_METHOD0(getPeakShape, const Mantid::Geometry::PeakShape&());
};


Expand Down
Expand Up @@ -124,7 +124,7 @@ class DLLExport Peak : public API::IPeak {
double getValueByColName(const std::string &name) const;

/// Get the peak shape.
const Mantid::Geometry::PeakShape& getPeakShape();
const Mantid::Geometry::PeakShape& getPeakShape() const;

/// Set the PeakShape
void setPeakShape(Mantid::Geometry::PeakShape* shape);
Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/Framework/DataObjects/src/Peak.cpp
Expand Up @@ -857,7 +857,7 @@ double Peak::getValueByColName(const std::string &name_in) const {
* @brief Get the peak shape
* @return : const ref to current peak shape.
*/
const PeakShape &Peak::getPeakShape() { return *this->m_peakShape; }
const PeakShape &Peak::getPeakShape() const { return *this->m_peakShape; }

/**
* @brief Set the peak shape
Expand Down
64 changes: 23 additions & 41 deletions Code/Mantid/Framework/MDEvents/test/IntegrateEllipsoidsTest.h
Expand Up @@ -6,7 +6,6 @@
#include "MantidDataObjects/EventWorkspace.h"
#include "MantidDataObjects/PeakShapeEllipsoid.h"
#include "MantidGeometry/Crystal/OrientedLattice.h"
#include "MantidGeometry/Instrument/NearestNeighbours.h"
#include <boost/make_shared.hpp>
#include <boost/tuple/tuple.hpp>

Expand All @@ -32,17 +31,8 @@ class IntegrateEllipsoidsTest : public CxxTest::TestSuite {

static void destroySuite(IntegrateEllipsoidsTest *suite) { delete suite; }

static ISpectrumDetectorMapping buildSpectrumDetectorMapping(const specid_t start, const specid_t end)
{
boost::unordered_map<specid_t, std::set<detid_t>> map;
for ( specid_t i = start; i <= end; ++i )
{
map[i].insert(i);
}
return map;
}

void addFakeEllipsoid(const V3D& peakHKL, const int& totalNPixels, const int& nEvents, const NearestNeighbours& nn, EventWorkspace_sptr& eventWS, PeaksWorkspace_sptr& peaksWS)
void addFakeEllipsoid(const V3D& peakHKL, const int& totalNPixels, const int& nEvents, EventWorkspace_sptr& eventWS, PeaksWorkspace_sptr& peaksWS)
{
// Create the peak and add it to the peaks ws
Peak* peak = peaksWS->createPeakHKL(peakHKL);
Expand All @@ -52,25 +42,11 @@ class IntegrateEllipsoidsTest : public CxxTest::TestSuite {
delete peak;

EventList& el = eventWS->getEventList(detectorId - totalNPixels);
el.setDetectorID(detectorId);
el.addEventQuickly(TofEvent(tofExact));

// Find some neighbours,
std::map<specid_t, Mantid::Kernel::V3D> neighbourMap = nn.neighbours(detectorId);

typedef std::map<specid_t, Mantid::Kernel::V3D> NeighbourMap;
typedef NeighbourMap::iterator NeighbourMapIterator;
for(NeighbourMapIterator it = neighbourMap.begin(); it != neighbourMap.end(); ++it)
{
const specid_t neighbourDet = (*it).first;
const double distanceFromCentre = (*it).second.norm2(); // gives TOF delta
EventList neighbourEventList = eventWS->getEventList(neighbourDet - totalNPixels);
neighbourEventList.setDetectorID(neighbourDet);
for(int i = 0; i < nEvents; ++i) {

const double tof = (tofExact - (distanceFromCentre/2) ) + ( distanceFromCentre * double(i)/double(nEvents) );
neighbourEventList.addEventQuickly(TofEvent(tof));
}

// Add more events to the event list corresponding to the peak centre
for (int i = -nEvents/2; i < nEvents/2; ++i) {
const double tof = tofExact + i ;
el.addEventQuickly(TofEvent(tof));
}
}

Expand Down Expand Up @@ -102,16 +78,13 @@ class IntegrateEllipsoidsTest : public CxxTest::TestSuite {
el.setDetectorID(i + nPixelsTotal);
}

// Make a nn map, so that we can add counts in the vicinity of the actual peak centre.
NearestNeighbours nn(inst, buildSpectrumDetectorMapping(nPixelsTotal, nPixelsTotal+inst->getNumberDetectors() - 1));

// Add some peaks which should correspond to real reflections (could calculate these). Same function also adds a fake ellipsoid
addFakeEllipsoid(V3D(1, -5, -3), nPixelsTotal, 10, nn, eventWS, peaksWS);
addFakeEllipsoid(V3D(1, -4, -4), nPixelsTotal, 10, nn, eventWS, peaksWS);
addFakeEllipsoid(V3D(1, -3, -5), nPixelsTotal, 10, nn, eventWS, peaksWS);
addFakeEllipsoid(V3D(1, -4, -1), nPixelsTotal, 10, nn, eventWS, peaksWS);
addFakeEllipsoid(V3D(1, -4, 0), nPixelsTotal, 10, nn, eventWS, peaksWS);
addFakeEllipsoid(V3D(2, -3, -4), nPixelsTotal, 10, nn, eventWS, peaksWS);
addFakeEllipsoid(V3D(1, -5, -3), nPixelsTotal, 10, eventWS, peaksWS);
addFakeEllipsoid(V3D(1, -4, -4), nPixelsTotal, 10, eventWS, peaksWS);
addFakeEllipsoid(V3D(1, -3, -5), nPixelsTotal, 10, eventWS, peaksWS);
addFakeEllipsoid(V3D(1, -4, -1), nPixelsTotal, 10, eventWS, peaksWS);
addFakeEllipsoid(V3D(1, -4, 0), nPixelsTotal, 10, eventWS, peaksWS);
addFakeEllipsoid(V3D(2, -3, -4), nPixelsTotal, 10, eventWS, peaksWS);

// Return test data.
return boost::tuple<EventWorkspace_sptr, PeaksWorkspace_sptr>(eventWS, peaksWS);
Expand Down Expand Up @@ -139,8 +112,17 @@ class IntegrateEllipsoidsTest : public CxxTest::TestSuite {
alg.execute();
PeaksWorkspace_sptr integratedPeaksWS = alg.getProperty("OutputWorkspace");
TSM_ASSERT_EQUALS("Wrong number of peaks in output workspace", integratedPeaksWS->getNumberPeaks(), peaksWS->getNumberPeaks());
const Peak& firstPeak = integratedPeaksWS->getPeak(0);
TSM_ASSERT_EQUALS("Wrong shape name", PeakShapeEllipsoid::ellipsoidShapeName(), firstPeak.getPeakShape().shapeName() );

for(int i = 0; i < integratedPeaksWS->getNumberPeaks(); ++i) {
const Peak& peak = integratedPeaksWS->getPeak(0);
const PeakShape& peakShape = peak.getPeakShape();

TSM_ASSERT_RELATION("Peak should be integrated", std::greater<double>, peak.getIntensity(), 0);

std::stringstream stream;
stream << "Wrong shape name for peak " << i;
TSM_ASSERT_EQUALS(stream.str(), PeakShapeEllipsoid::ellipsoidShapeName(), peakShape.shapeName() );
}

}

Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/MantidQt/SliceViewer/test/MockObjects.h
Expand Up @@ -253,7 +253,7 @@ class MockPeakTransformFactory : public PeakTransformFactory
Mantid::Kernel::V3D());
MOCK_CONST_METHOD0(getDetectorPositionNoCheck,
Mantid::Kernel::V3D());
MOCK_METHOD0(getPeakShape, const Mantid::Geometry::PeakShape&());
MOCK_CONST_METHOD0(getPeakShape, const Mantid::Geometry::PeakShape&());
};

/*------------------------------------------------------------
Expand Down

0 comments on commit 5542c3b

Please sign in to comment.