diff --git a/Code/Mantid/Framework/API/inc/MantidAPI/IPeak.h b/Code/Mantid/Framework/API/inc/MantidAPI/IPeak.h index 0ee7a8d085ff..e85e6be9140d 100644 --- a/Code/Mantid/Framework/API/inc/MantidAPI/IPeak.h +++ b/Code/Mantid/Framework/API/inc/MantidAPI/IPeak.h @@ -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 diff --git a/Code/Mantid/Framework/API/test/MockObjects.h b/Code/Mantid/Framework/API/test/MockObjects.h index 591c063b6e13..d05dfc5746f2 100644 --- a/Code/Mantid/Framework/API/test/MockObjects.h +++ b/Code/Mantid/Framework/API/test/MockObjects.h @@ -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&()); }; diff --git a/Code/Mantid/Framework/DataObjects/inc/MantidDataObjects/Peak.h b/Code/Mantid/Framework/DataObjects/inc/MantidDataObjects/Peak.h index c5c33fbc2a52..428427432828 100644 --- a/Code/Mantid/Framework/DataObjects/inc/MantidDataObjects/Peak.h +++ b/Code/Mantid/Framework/DataObjects/inc/MantidDataObjects/Peak.h @@ -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); diff --git a/Code/Mantid/Framework/DataObjects/src/Peak.cpp b/Code/Mantid/Framework/DataObjects/src/Peak.cpp index 71e958d83617..64ecc81827f7 100644 --- a/Code/Mantid/Framework/DataObjects/src/Peak.cpp +++ b/Code/Mantid/Framework/DataObjects/src/Peak.cpp @@ -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 diff --git a/Code/Mantid/Framework/MDEvents/test/IntegrateEllipsoidsTest.h b/Code/Mantid/Framework/MDEvents/test/IntegrateEllipsoidsTest.h index cd3b1a208c06..f14c9ce1eb2b 100644 --- a/Code/Mantid/Framework/MDEvents/test/IntegrateEllipsoidsTest.h +++ b/Code/Mantid/Framework/MDEvents/test/IntegrateEllipsoidsTest.h @@ -6,7 +6,6 @@ #include "MantidDataObjects/EventWorkspace.h" #include "MantidDataObjects/PeakShapeEllipsoid.h" #include "MantidGeometry/Crystal/OrientedLattice.h" -#include "MantidGeometry/Instrument/NearestNeighbours.h" #include #include @@ -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> 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); @@ -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 neighbourMap = nn.neighbours(detectorId); - - typedef std::map 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)); } } @@ -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(eventWS, peaksWS); @@ -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, peak.getIntensity(), 0); + + std::stringstream stream; + stream << "Wrong shape name for peak " << i; + TSM_ASSERT_EQUALS(stream.str(), PeakShapeEllipsoid::ellipsoidShapeName(), peakShape.shapeName() ); + } } diff --git a/Code/Mantid/MantidQt/SliceViewer/test/MockObjects.h b/Code/Mantid/MantidQt/SliceViewer/test/MockObjects.h index 42cb6aa2ddcf..2d6b3ddc3f1e 100644 --- a/Code/Mantid/MantidQt/SliceViewer/test/MockObjects.h +++ b/Code/Mantid/MantidQt/SliceViewer/test/MockObjects.h @@ -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&()); }; /*------------------------------------------------------------