diff --git a/Code/Mantid/Framework/MDEvents/CMakeLists.txt b/Code/Mantid/Framework/MDEvents/CMakeLists.txt index a5d5dff82ccc19de449650737a9aaf8b0a097fcb..c841512a44cfa7e1ea3ccec77e4305c5447945eb 100644 --- a/Code/Mantid/Framework/MDEvents/CMakeLists.txt +++ b/Code/Mantid/Framework/MDEvents/CMakeLists.txt @@ -162,6 +162,7 @@ set ( TEST_FILES QueryMDWorkspaceTest.h ReflectometryTransformQxQzTest.h Integrate3DEventsTest.h +# IntegrateEllipsoidsTest.h SaveIsawQvectorTest.h SkippingPolicyTest.h UnitsConversionHelperTest.h diff --git a/Code/Mantid/Framework/MDEvents/src/Integrate3DEvents.cpp b/Code/Mantid/Framework/MDEvents/src/Integrate3DEvents.cpp index aafa49771813d75ed87ea055dae9debeb0cf5370..161d9564137cd4b3c57255c60cd64bcacb50b7d4 100644 --- a/Code/Mantid/Framework/MDEvents/src/Integrate3DEvents.cpp +++ b/Code/Mantid/Framework/MDEvents/src/Integrate3DEvents.cpp @@ -130,7 +130,6 @@ void Integrate3DEvents::ellipseIntegrateEvents( long hkl_key = getHklKey( peak_q ); if ( hkl_key == 0 ) { - std::cout << "HKL KEY IS 0 " << std::endl; return; } @@ -138,7 +137,6 @@ void Integrate3DEvents::ellipseIntegrateEvents( if ( some_events.size() < 3 ) // if there are not enough events to { // find covariance matrix, return - std::cout << "TOO FEW EVENTS: " << some_events.size() << std::endl; return; } @@ -159,31 +157,23 @@ void Integrate3DEvents::ellipseIntegrateEvents( { if ( (boost::math::isnan)( sigmas[i]) ) { - std::cout << " SIGMA isNaN "; invalid_peak = true; } else if ( sigmas[i] <= 0 ) { - std::cout << " SIGMA <= 0 "; invalid_peak = true; } } if ( invalid_peak ) // if data collapses to a line or { // to a plane, the volume of the - inti = 0.0; // ellipsoids will be zero. - sigi = 0.0; + return; // ellipsoids will be zero. } - else - { - ellipseIntegrateEvents(some_events, eigen_vectors, sigmas, - specify_size, peak_radius, - back_inner_radius, back_outer_radius, - inti, sigi); - } - - if ( invalid_peak ) - std::cout << "INVALID_PEAK " << inti << ", " << sigi << std::endl; + + ellipseIntegrateEvents(some_events, eigen_vectors, sigmas, + specify_size, peak_radius, + back_inner_radius, back_outer_radius, + inti, sigi); } diff --git a/Code/Mantid/Framework/MDEvents/test/IntegrateEllipsoidsTest.h b/Code/Mantid/Framework/MDEvents/test/IntegrateEllipsoidsTest.h new file mode 100644 index 0000000000000000000000000000000000000000..428507d97498142324fd9814ece52f9d1c605540 --- /dev/null +++ b/Code/Mantid/Framework/MDEvents/test/IntegrateEllipsoidsTest.h @@ -0,0 +1,138 @@ +#ifndef MANTID_MDEVENTS_INTEGRATE_ELLIPSOIDS_TEST_H_ +#define MANTID_MDEVENTS_INTEGRATE_ELLIPSOIDS_TEST_H_ + +#include <iostream> +#include <fstream> + + +#include <cxxtest/TestSuite.h> +#include <Poco/File.h> +#include "MantidAPI/AnalysisDataService.h" +#include "MantidDataObjects/EventWorkspace.h" +#include "MantidDataObjects/PeaksWorkspace.h" +#include "MantidMDEvents/IntegrateEllipsoids.h" +#include "MantidTestHelpers/MDEventsTestHelper.h" + + +#include "MantidAPI/FrameworkManager.h" +#include "MantidAPI/AlgorithmFactory.h" + +#include "MantidDataHandling/LoadNexus.h" +#include "MantidDataObjects/WorkspaceSingleValue.h" +#include "MantidDataHandling/LoadInstrument.h" + +using Mantid::API::AnalysisDataService; +using Mantid::MDEvents::IntegrateEllipsoids; +using namespace Mantid::API; +using namespace Mantid::Kernel; +using namespace Mantid::DataHandling; +using namespace Mantid::DataObjects; + + +class IntegrateEllipsoidsTest : 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 IntegrateEllipsoidsTest *createSuite() { return new IntegrateEllipsoidsTest(); } + static void destroySuite( IntegrateEllipsoidsTest *suite ) { delete suite; } + + + void test_Init() + { + IntegrateEllipsoids alg; + TS_ASSERT_THROWS_NOTHING( alg.initialize() ) + TS_ASSERT( alg.isInitialized() ) + } + + void test_exec() + { // expected results with size determined + // automatically from projected event sigmas + double inti_auto[] = { 88, 99, 23, 33, 8, 8, 4 }; + double sigi_auto[] = { 13.784, 18.1384, 13.1529, 9.94987, 5.83095, 10.2956, 10.2956 }; + // expected results with fixed size + // ellipsoids + double inti_fixed[] = { 87.541, 95.3934, 21.3607, 33.4262, 7.36066, 9.68852, 3.54098 }; + double sigi_fixed[] = { 13.9656, 18.4523, 13.4335, 10.1106, 5.94223, 10.5231, 10.5375 }; + + // first, load peaks into a peaks workspace + + Mantid::API::FrameworkManager::Instance(); // needed for LoadIsawPeaks + // to be found (i.e. registered) + + std::string peaks_file("TOPAZ_3007.peaks"); + std::string peaks_ws_name("TOPAZ_3007_peaks"); + + boost::shared_ptr<Mantid::API::Algorithm> peaks_loader = + Mantid::API::AlgorithmFactory::Instance().create(std::string("LoadIsawPeaks"), -1); + peaks_loader->initialize(); + peaks_loader->setPropertyValue( "Filename", peaks_file ); + peaks_loader->setPropertyValue( "OutputWorkspace", peaks_ws_name ); + peaks_loader->execute(); + + // next, load events into an event workspace + std::string event_file("TOPAZ_3007_bank_37_20_sec.nxs"); + std::string event_ws_name("TOPAZ_3007_events"); + + boost::shared_ptr<Mantid::API::Algorithm> event_loader = + Mantid::API::AlgorithmFactory::Instance().create(std::string("LoadNexus"), -1); + event_loader->initialize(); + + event_loader->setPropertyValue( "FileName", event_file ); + event_loader->setPropertyValue( "OutputWorkspace", event_ws_name ); + event_loader->execute(); + // configure and test the algorithm + // using automatically determined + // ellipsoid sizes + IntegrateEllipsoids integrator; + TS_ASSERT_THROWS_NOTHING( integrator.initialize() ); + TS_ASSERT_THROWS_NOTHING( integrator.setPropertyValue( "InputWorkspace", event_ws_name ) ); + TS_ASSERT_THROWS_NOTHING( integrator.setPropertyValue( "PeaksWorkspace", peaks_ws_name ) ); + TS_ASSERT_THROWS_NOTHING( integrator.setPropertyValue( "RegionRadius", ".25" ) ); + TS_ASSERT_THROWS_NOTHING( integrator.setPropertyValue( "SpecifySize", "0" ) ); + TS_ASSERT_THROWS_NOTHING( integrator.setPropertyValue( "PeakSize", ".2" ) ); + TS_ASSERT_THROWS_NOTHING( integrator.setPropertyValue( "BackgroundInnerSize", ".2" ) ); + TS_ASSERT_THROWS_NOTHING( integrator.setPropertyValue( "BackgroundOuterSize", ".25" ) ); + TS_ASSERT_THROWS_NOTHING( integrator.setPropertyValue( "OutputWorkspace", peaks_ws_name ) ); + TS_ASSERT_THROWS_NOTHING( integrator.execute() ); + + PeaksWorkspace_sptr peaks_ws; + TS_ASSERT_THROWS_NOTHING( peaks_ws = boost::dynamic_pointer_cast<PeaksWorkspace>( + AnalysisDataService::Instance().retrieve(peaks_ws_name)); ); + TS_ASSERT(peaks_ws); + + std::vector<Peak> & peaks = peaks_ws->getPeaks(); + for (size_t i = 13; i <= 19; i++ ) + { + TS_ASSERT_DELTA( peaks[i].getIntensity(), inti_auto[i-13], 0.1 ); + TS_ASSERT_DELTA( peaks[i].getSigmaIntensity(), sigi_auto[i-13], 0.1 ); + } + // configure and test the algorithm + // using fixed ellipsoid sizes + TS_ASSERT_THROWS_NOTHING( integrator.initialize() ); + TS_ASSERT_THROWS_NOTHING( integrator.setPropertyValue( "InputWorkspace", event_ws_name ) ); + TS_ASSERT_THROWS_NOTHING( integrator.setPropertyValue( "PeaksWorkspace", peaks_ws_name + ) ); + TS_ASSERT_THROWS_NOTHING( integrator.setPropertyValue( "RegionRadius", ".25" ) ); + TS_ASSERT_THROWS_NOTHING( integrator.setPropertyValue( "SpecifySize", "1" ) ); + TS_ASSERT_THROWS_NOTHING( integrator.setPropertyValue( "PeakSize", ".2" ) ); + TS_ASSERT_THROWS_NOTHING( integrator.setPropertyValue( "BackgroundInnerSize", ".2" ) ); + TS_ASSERT_THROWS_NOTHING( integrator.setPropertyValue( "BackgroundOuterSize", ".25" ) ); + TS_ASSERT_THROWS_NOTHING( integrator.setPropertyValue( "OutputWorkspace", peaks_ws_name ) ); + TS_ASSERT_THROWS_NOTHING( integrator.execute() ); + + peaks = peaks_ws->getPeaks(); + for (size_t i = 13; i <= 19; i++ ) + { + TS_ASSERT_DELTA( peaks[i].getIntensity(), inti_fixed[i-13], 0.1 ); + TS_ASSERT_DELTA( peaks[i].getSigmaIntensity(), sigi_fixed[i-13], 0.1 ); + } + + AnalysisDataService::Instance().remove( event_ws_name ); + AnalysisDataService::Instance().remove(peaks_ws_name); + } + +}; + + +#endif /* MANTID_MDEVENTS_INTEGRATE_ELLIPSOIDS_TEST_H_ */