From 27759248154995ab10e014c361fab2f53bf2e2c3 Mon Sep 17 00:00:00 2001 From: Owen Arnold Date: Thu, 26 Feb 2015 13:35:55 +0000 Subject: [PATCH] refs #11056. Check principle axis I've added some peak by peak checks using the PeakShape to determine what the principle axis used for integration has been. Since I artifically construct the ellipsoids in the test, I know that they have a principle axis directly along the TOF, and there is only one detector involved. We should therefore expect that the principle axis of the ellipsoid is exactly the same as the scattering qDir. Normalising both before comparison takes out the wavenumber dependency. I've also started adding in the regression tests needed for the Histogram workspace cases. --- .../MDEvents/test/IntegrateEllipsoidsTest.h | 63 ++++++++++++++++++- 1 file changed, 61 insertions(+), 2 deletions(-) diff --git a/Code/Mantid/Framework/MDEvents/test/IntegrateEllipsoidsTest.h b/Code/Mantid/Framework/MDEvents/test/IntegrateEllipsoidsTest.h index f14c9ce1eb2b..8cbd50218a73 100644 --- a/Code/Mantid/Framework/MDEvents/test/IntegrateEllipsoidsTest.h +++ b/Code/Mantid/Framework/MDEvents/test/IntegrateEllipsoidsTest.h @@ -1,6 +1,7 @@ #include #include "MantidMDEvents/IntegrateEllipsoids.h" #include "MantidAPI/FrameworkManager.h" +#include "MantidAPI/AlgorithmManager.h" #include "MantidTestHelpers/ComponentCreationHelper.h" #include "MantidDataObjects/PeaksWorkspace.h" #include "MantidDataObjects/EventWorkspace.h" @@ -113,8 +114,15 @@ class IntegrateEllipsoidsTest : public CxxTest::TestSuite { PeaksWorkspace_sptr integratedPeaksWS = alg.getProperty("OutputWorkspace"); TSM_ASSERT_EQUALS("Wrong number of peaks in output workspace", integratedPeaksWS->getNumberPeaks(), peaksWS->getNumberPeaks()); - for(int i = 0; i < integratedPeaksWS->getNumberPeaks(); ++i) { - const Peak& peak = integratedPeaksWS->getPeak(0); + auto instrument = eventWS->getInstrument(); + const V3D samplePos = instrument->getComponentByName("sample")->getPos(); + const V3D sourcePos = instrument->getComponentByName("source")->getPos(); + V3D beamDir = samplePos - sourcePos; + beamDir.normalize(); + + // Just test the first few peaks + for(int i = 0; i < 3; ++i) { + const Peak& peak = integratedPeaksWS->getPeak(i); const PeakShape& peakShape = peak.getPeakShape(); TSM_ASSERT_RELATION("Peak should be integrated", std::greater, peak.getIntensity(), 0); @@ -122,10 +130,61 @@ class IntegrateEllipsoidsTest : public CxxTest::TestSuite { std::stringstream stream; stream << "Wrong shape name for peak " << i; TSM_ASSERT_EQUALS(stream.str(), PeakShapeEllipsoid::ellipsoidShapeName(), peakShape.shapeName() ); + + // Calculate the q direction based on geometry + const V3D detPos = peak.getDetectorPosition(); + V3D detDir = detPos - samplePos; + detDir.normalize(); + V3D qDir = detDir - beamDir ; + qDir.normalize(); + + // Get the q-direction off the ellipsoid + PeakShapeEllipsoid const * const ellipsoid = dynamic_cast(&peakShape); + auto dirs = ellipsoid->directions(); + + /* We have set the fake ellipsoids up to be lines along a single detectors TOF (see setup). + * We therefore expect the principle axis of the ellipsoid to be the same as the q-dir! + */ + TS_ASSERT_EQUALS(qDir, dirs[0]); + } } + void test_execution_histograms() + { + auto out = createDiffractionData(); + EventWorkspace_sptr eventWS = out.get<0>(); + PeaksWorkspace_sptr peaksWS = out.get<1>(); + + /* + Simply rebin the event workspace to a histo workspace to create the input we need. + */ + auto rebinAlg = Mantid::API::AlgorithmManager::Instance().createUnmanaged("Rebin"); + rebinAlg->setChild(true); + rebinAlg->initialize(); + rebinAlg->setProperty("InputWorkspace", eventWS); + rebinAlg->setProperty("Params", std::vector(1,100) ); + rebinAlg->setProperty("PreserveEvents", false); // Make a histo workspace + rebinAlg->setPropertyValue("OutputWorkspace", "dummy"); + rebinAlg->execute(); + Mantid::API::MatrixWorkspace_sptr histoWS = rebinAlg->getProperty("OutputWorkspace"); + + /* + IntegrateEllipsoids alg; + alg.setChild(true); + alg.setRethrows(true); + alg.initialize(); + alg.setProperty("InputWorkspace", histoWS); + alg.setProperty("PeaksWorkspace", peaksWS); + alg.setPropertyValue("OutputWorkspace", "dummy"); + alg.execute(); + PeaksWorkspace_sptr integratedPeaksWS = alg.getProperty("OutputWorkspace"); + TSM_ASSERT_EQUALS("Wrong number of peaks in output workspace", integratedPeaksWS->getNumberPeaks(), peaksWS->getNumberPeaks()); + */ + + } +