diff --git a/Code/Mantid/Framework/DataHandling/CMakeLists.txt b/Code/Mantid/Framework/DataHandling/CMakeLists.txt index 24f39e04ac69..a6d2877b0070 100644 --- a/Code/Mantid/Framework/DataHandling/CMakeLists.txt +++ b/Code/Mantid/Framework/DataHandling/CMakeLists.txt @@ -1,6 +1,5 @@ set ( SRC_FILES src/AppendGeometryToSNSNexus.cpp - src/ApplyGroupingFromMuonNexus.cpp src/CompressEvents.cpp src/ConvertFullprofToXML.cpp src/CreateChopperModel.cpp @@ -131,7 +130,6 @@ set ( SRC_FILES set ( INC_FILES inc/MantidDataHandling/AppendGeometryToSNSNexus.h - inc/MantidDataHandling/ApplyGroupingFromMuonNexus.h inc/MantidDataHandling/CompressEvents.h inc/MantidDataHandling/ConvertFullprofToXML.h inc/MantidDataHandling/CreateChopperModel.h @@ -262,7 +260,6 @@ set ( INC_FILES set ( TEST_FILES AppendGeometryToSNSNexusTest.h - ApplyGroupingFromMuonNexusTest.h CompressEventsTest.h ConvertFullprofToXMLTest.h CreateChopperModelTest.h @@ -279,8 +276,8 @@ set ( TEST_FILES GroupDetectorsTest.h ISISDataArchiveTest.h InstrumentRayTracerTest.h - LoadAsciiTest.h LoadAscii2Test.h + LoadAsciiTest.h LoadCalFileTest.h LoadCanSAS1dTest.h LoadDaveGrpTest.h @@ -304,8 +301,8 @@ set ( TEST_FILES LoadLogTest.h LoadMappingTableTest.h LoadMaskTest.h - LoadMcStasTest.h LoadMcStasNexusTest.h + LoadMcStasTest.h LoadMuonLogTest.h LoadMuonNexus1Test.h LoadMuonNexus2Test.h @@ -348,8 +345,8 @@ set ( TEST_FILES RotateInstrumentComponentTest.h SNSDataArchiveICAT2Test.h SNSDataArchiveTest.h - SaveAsciiTest.h SaveAscii2Test.h + SaveAsciiTest.h SaveCSVTest.h SaveCalFileTest.h SaveCanSAS1dTest.h diff --git a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/ApplyGroupingFromMuonNexus.h b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/ApplyGroupingFromMuonNexus.h deleted file mode 100644 index 4022af0d42df..000000000000 --- a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/ApplyGroupingFromMuonNexus.h +++ /dev/null @@ -1,62 +0,0 @@ -#ifndef MANTID_DATAHANDLING_APPLYGROUPINGFROMMUONNEXUS_H_ -#define MANTID_DATAHANDLING_APPLYGROUPINGFROMMUONNEXUS_H_ - -#include "MantidKernel/System.h" -#include "MantidAPI/Algorithm.h" -#include "MantidDataObjects/Workspace2D.h" - -namespace Mantid -{ -namespace DataHandling -{ - using namespace DataObjects; - /** - Applies grouping information from Muon Nexus file to the workspace. - - @author Arturs Bekasovs - @date 10/10/2013 - - Copyright © 2013 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 . - - File change history is stored at: - Code Documentation is available at: - */ - class DLLExport ApplyGroupingFromMuonNexus : public API::Algorithm - { - public: - virtual const std::string name() const; - virtual int version() const; - virtual const std::string category() const; - - private: - virtual void initDocs(); - void init(); - void exec(); - - bool checkGroups(); - bool processGroups(); - - /// Applies grouping to a given workspace - Workspace2D_sptr applyGrouping(const std::vector& detectorGrouping, Workspace2D_const_sptr inputWs); - }; - - -} // namespace DataHandling -} // namespace Mantid - -#endif /* MANTID_DATAHANDLING_APPLYGROUPINGFROMMUONNEXUS_H_ */ \ No newline at end of file diff --git a/Code/Mantid/Framework/DataHandling/src/ApplyGroupingFromMuonNexus.cpp b/Code/Mantid/Framework/DataHandling/src/ApplyGroupingFromMuonNexus.cpp deleted file mode 100644 index 56dd105da425..000000000000 --- a/Code/Mantid/Framework/DataHandling/src/ApplyGroupingFromMuonNexus.cpp +++ /dev/null @@ -1,211 +0,0 @@ -/*WIKI* -Given a workspace or workspace group and Muon Nexus file, retrieves grouping information stored in the file and groups input workspace accordingly. -*WIKI*/ - -#include "MantidAPI/FileProperty.h" -#include "MantidDataHandling/ApplyGroupingFromMuonNexus.h" -#include "MantidDataObjects/Workspace2D.h" - -#include -#include - -namespace Mantid -{ -namespace DataHandling -{ - using namespace Kernel; - using namespace API; - using namespace DataObjects; - - // Register the algorithm into the AlgorithmFactory - DECLARE_ALGORITHM(ApplyGroupingFromMuonNexus) - - //---------------------------------------------------------------------------------------------- - /// Algorithm's name for identification. @see Algorithm::name - const std::string ApplyGroupingFromMuonNexus::name() const { return "ApplyGroupingFromMuonNexus";}; - - /// Algorithm's version for identification. @see Algorithm::version - int ApplyGroupingFromMuonNexus::version() const { return 1;}; - - /// Algorithm's category for identification. @see Algorithm::category - const std::string ApplyGroupingFromMuonNexus::category() const { return "DataHandling\\Nexus;Muon";} - - //---------------------------------------------------------------------------------------------- - /// Sets documentation strings for this algorithm - void ApplyGroupingFromMuonNexus::initDocs() - { - this->setWikiSummary("Applies grouping information from Muon Nexus file to the [[workspace]]."); - this->setOptionalMessage("Applies grouping information from Muon Nexus file to the workspace."); - } - - //---------------------------------------------------------------------------------------------- - /** Initialize the algorithm's properties. - */ - void ApplyGroupingFromMuonNexus::init() - { - declareProperty(new WorkspaceProperty("InputWorkspace","",Direction::Input), - "Workspace to group."); - - declareProperty(new FileProperty("Filename", "", FileProperty::Load, ".nxs"), - "Nexus file to load grouping information from." ); - - declareProperty(new WorkspaceProperty("OutputWorkspace","",Direction::Output), - "Workspace with grouping applied."); - } - - //---------------------------------------------------------------------------------------------- - /** Execute the algorithm. - */ - void ApplyGroupingFromMuonNexus::exec() - { - // Load grouping information from the Nexus file - std::string filename = getPropertyValue("Filename"); - - NeXus::File handle(filename, NXACC_READ); - - handle.openData("grouping"); // TODO: what if no? - size_t numDetectors = static_cast(handle.getInfo().dims[0]); - - boost::scoped_array detectorGrouping(new int[numDetectors]); - - handle.getData(detectorGrouping.get()); - handle.closeData(); - - Workspace_sptr inputWs = getProperty("InputWorkspace"); - - std::string outputWsName = getPropertyValue("OutputWorkspace"); - - if(Workspace2D_const_sptr inputWs2D = boost::dynamic_pointer_cast(inputWs)) - { - std::vector grouping(detectorGrouping.get(), detectorGrouping.get() + numDetectors); - - Workspace2D_sptr outputWs = applyGrouping(grouping, inputWs2D); - setProperty("OutputWorkspace", outputWs); - } - else if(WorkspaceGroup_const_sptr inputGroup = boost::dynamic_pointer_cast(inputWs)) - { - WorkspaceGroup_sptr outputWsGroup = WorkspaceGroup_sptr(new WorkspaceGroup); - - int currentOffset = 0; - - for(size_t i = 0; i < inputGroup->size(); i++) - { - Workspace2D_const_sptr memberWs2D = boost::dynamic_pointer_cast(inputGroup->getItem(i)); - - if(!memberWs2D) - throw std::invalid_argument("Specified group contains a workspace which is not a Workspace2D"); - - int* from = detectorGrouping.get() + currentOffset; - int* to = from + memberWs2D->getNumberHistograms(); - - std::vector grouping(from, to); - - Workspace2D_sptr outputWs = applyGrouping(grouping, memberWs2D); - outputWsGroup->addWorkspace(outputWs); - - std::string suffix = "_" + boost::lexical_cast(i + 1); - std::string outWsPropName = "OutputWorkspace" + suffix; - - declareProperty(new WorkspaceProperty(outWsPropName, outputWsName + suffix, Direction::Output)); - setProperty(outWsPropName, boost::dynamic_pointer_cast(outputWs)); - } - - setProperty("OutputWorkspace",boost::dynamic_pointer_cast(outputWsGroup)); - } - else - { - throw std::invalid_argument("Should be whether a Workspace2D or WorkspaceGroup"); - } - } - - bool ApplyGroupingFromMuonNexus::checkGroups() - { - return false; - } - - bool ApplyGroupingFromMuonNexus::processGroups() - { - return true; - } - - /** - * Applies grouping to a given workspace. - * - * @param detectorGrouping :: Grouping info, where index is detector id and value is group number - * @param inputWs :: Workspace to group - * @return Workspace with grouped detectors. All the unrelated parameters are left as in inputWs. - */ - Workspace2D_sptr ApplyGroupingFromMuonNexus::applyGrouping(const std::vector& detectorGrouping, - Workspace2D_const_sptr inputWs) - { - if(inputWs->getNumberHistograms() != detectorGrouping.size()) - throw std::invalid_argument("Invalid number of detectors."); - - std::map< int, std::vector > groups; - std::vector ungrouped; - - for (size_t i = 0; i < detectorGrouping.size(); ++i) - { - int group = detectorGrouping[i]; - - if(group == 0) - ungrouped.push_back(static_cast(i)); - else - groups[group].push_back(static_cast(i)); - } - - if(groups.empty()) - throw std::invalid_argument("No groups specified in the input file"); - - // Number of the last group we've met - int lastGroup = groups.rbegin()->first; - - // Add ungrouped detectors to separate groups - for(size_t i = 0; i < ungrouped.size(); i++) - groups[++lastGroup].push_back(ungrouped[i]); - - Workspace2D_sptr groupedWs = boost::dynamic_pointer_cast( - WorkspaceFactory::Instance().create(inputWs, groups.size(), inputWs->dataX(0).size(), inputWs->blocksize())); - - // Compile the groups - int groupIndex = 0; - for (auto groupIt = groups.begin(); groupIt != groups.end(); groupIt++) - { - std::vector& detectors = groupIt->second; - - for(auto detIt = detectors.begin(); detIt != detectors.end(); detIt++) - { - for(size_t j = 0; j < inputWs->blocksize(); j++) - { - // Sum the y values - groupedWs->dataY(groupIndex)[j] += inputWs->dataY(*detIt)[j]; - - // Sum the errors in quadrature - groupedWs->dataE(groupIndex)[j] = - sqrt(pow(groupedWs->dataE(groupIndex)[j], 2) + pow(inputWs->dataE(*detIt)[j], 2)); - } - - groupedWs->getSpectrum(groupIndex)->addDetectorID(static_cast(*detIt)); - } - - // Using the last detector X values for consistency with LoadMuonNexus1 AutoGroup behavior - groupedWs->dataX(groupIndex) = inputWs->dataX(detectors.back()); - - groupedWs->getSpectrum(groupIndex)->setSpectrumNo(groupIndex+1); - - g_log.information() << "Group " << groupIt->first << ": " - << Kernel::Strings::join(detectors.begin(), detectors.end(), ", ") - << std::endl; - - groupIndex++; - } - - // Set Y axis values - for(size_t i = 0; i < groupedWs->getNumberHistograms(); i++) - groupedWs->getAxis(1)->setValue(i, static_cast(i + 1)); - - return groupedWs; - } - -} // namespace DataHandling -} // namespace Mantid \ No newline at end of file diff --git a/Code/Mantid/Framework/DataHandling/test/ApplyGroupingFromMuonNexusTest.h b/Code/Mantid/Framework/DataHandling/test/ApplyGroupingFromMuonNexusTest.h deleted file mode 100644 index 813db4e3ac01..000000000000 --- a/Code/Mantid/Framework/DataHandling/test/ApplyGroupingFromMuonNexusTest.h +++ /dev/null @@ -1,152 +0,0 @@ -#ifndef MANTID_DATAHANDLING_ApplyGroupingFromMuonNexusTEST_H_ -#define MANTID_DATAHANDLING_ApplyGroupingFromMuonNexusTEST_H_ - -#include - -#include "MantidAPI/AnalysisDataService.h" -#include "MantidDataHandling/ApplyGroupingFromMuonNexus.h" -#include "MantidDataHandling/LoadMuonNexus1.h" -#include "MantidDataObjects/Workspace2D.h" -#include - -#include // std::accumulate - -using namespace Mantid::API; -using namespace Mantid::Kernel; -using namespace Mantid::DataHandling; -using namespace Mantid::DataObjects; - -class ApplyGroupingFromMuonNexusTest : 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 ApplyGroupingFromMuonNexusTest *createSuite() { return new ApplyGroupingFromMuonNexusTest(); } - static void destroySuite( ApplyGroupingFromMuonNexusTest *suite ) { delete suite; } - - - void test_init() - { - ApplyGroupingFromMuonNexus alg; - TS_ASSERT_THROWS_NOTHING( alg.initialize() ) - TS_ASSERT( alg.isInitialized() ) - } - - void test_execSingle() - { - AnalysisDataService::Instance().clear(); - - // Name of the output workspace. - std::string loadedWsName("ApplyGroupingFromMuonNexusTest_LoadedWS"); - std::string outWsName("ApplyGroupingFromMuonNexusTest_OutputWS"); - std::string dataFileName("emu00006473.nxs"); - - // Load the data we will group - LoadMuonNexus1 loadAlg; - loadAlg.initialize(); - loadAlg.setPropertyValue("Filename", dataFileName); - loadAlg.setPropertyValue("OutputWorkspace", loadedWsName); - loadAlg.execute(); - - ApplyGroupingFromMuonNexus alg; - alg.initialize(); - - TS_ASSERT_THROWS_NOTHING( alg.setPropertyValue("InputWorkspace", loadedWsName) ); - TS_ASSERT_THROWS_NOTHING( alg.setPropertyValue("Filename", dataFileName) ); - TS_ASSERT_THROWS_NOTHING( alg.setPropertyValue("OutputWorkspace", outWsName) ); - TS_ASSERT_THROWS_NOTHING( alg.execute(); ); - TS_ASSERT( alg.isExecuted() ); - - // Retrieve the workspace from data service. - Workspace2D_sptr ws; - TS_ASSERT_THROWS_NOTHING( ws = AnalysisDataService::Instance().retrieveWS(outWsName) ); - TS_ASSERT(ws); - - TS_ASSERT_EQUALS(ws->getNumberHistograms(), 2); - TS_ASSERT_EQUALS(ws->readY(0).size(), 2000); - - TS_ASSERT_EQUALS(ws->readX(0), ws->readX(1)); - TS_ASSERT_DELTA(std::accumulate(ws->readX(0).begin(), ws->readX(0).end(), 0.0), 31507.736, 0.001); - - TS_ASSERT_EQUALS(std::accumulate(ws->readY(0).begin(), ws->readY(0).end(), 0), 32571161); - TS_ASSERT_EQUALS(std::accumulate(ws->readY(1).begin(), ws->readY(1).end(), 0), 18184711); - - TS_ASSERT_DELTA(std::accumulate(ws->readE(0).begin(), ws->readE(0).end(), 0.0), 133292.1, 0.1); - TS_ASSERT_DELTA(std::accumulate(ws->readE(1).begin(), ws->readE(1).end(), 0.0), 101157.1, 0.1); - - AnalysisDataService::Instance().clear(); - } - - void test_execGroup() - { - AnalysisDataService::Instance().clear(); - - // Name of the output workspace. - std::string loadedWsName("ApplyGroupingFromMuonNexusTest_LoadedWS"); - std::string outWsName("ApplyGroupingFromMuonNexusTest_OutputWS"); - std::string dataFileName("MUSR00015189.nxs"); - - // Load the data we will group - LoadMuonNexus1 loadAlg; - loadAlg.initialize(); - loadAlg.setPropertyValue("Filename", dataFileName); - loadAlg.setPropertyValue("OutputWorkspace", loadedWsName); - loadAlg.execute(); - - ApplyGroupingFromMuonNexus alg; - alg.initialize(); - - TS_ASSERT_THROWS_NOTHING( alg.setPropertyValue("InputWorkspace", loadedWsName) ); - TS_ASSERT_THROWS_NOTHING( alg.setPropertyValue("Filename", dataFileName) ); - TS_ASSERT_THROWS_NOTHING( alg.setPropertyValue("OutputWorkspace", outWsName) ); - TS_ASSERT_THROWS_NOTHING( alg.execute(); ); - TS_ASSERT( alg.isExecuted() ); - - // Retrieve the workspace from data service. - WorkspaceGroup_sptr ws; - TS_ASSERT_THROWS_NOTHING( ws = AnalysisDataService::Instance().retrieveWS(outWsName) ); - TS_ASSERT(ws); - - TS_ASSERT_EQUALS(ws->size(), 2); - - // Check the first workspace in group ---------------------------------------------------------- - - Workspace2D_sptr ws1 = boost::dynamic_pointer_cast(ws->getItem(0)); - TS_ASSERT(ws1); - - TS_ASSERT_EQUALS(ws1->getNumberHistograms(), 2); - TS_ASSERT_EQUALS(ws1->readY(0).size(), 2000); - - TS_ASSERT_EQUALS(ws1->readX(0), ws1->readX(1)); - TS_ASSERT_DELTA(std::accumulate(ws1->readX(0).begin(), ws1->readX(0).end(), 0.0), 30915.451, 0.001); - - TS_ASSERT_EQUALS(std::accumulate(ws1->readY(0).begin(), ws1->readY(0).end(), 0), 355655); - TS_ASSERT_EQUALS(std::accumulate(ws1->readY(1).begin(), ws1->readY(1).end(), 0), 262852); - - TS_ASSERT_DELTA(std::accumulate(ws1->readE(0).begin(), ws1->readE(0).end(), 0.0), 14046.9, 0.1); - TS_ASSERT_DELTA(std::accumulate(ws1->readE(1).begin(), ws1->readE(1).end(), 0.0), 12079.8, 0.1); - - // Check the second workspace in group --------------------------------------------------------- - - Workspace2D_sptr ws2 = boost::dynamic_pointer_cast(ws->getItem(1)); - TS_ASSERT(ws2); - - TS_ASSERT_EQUALS(ws2->getNumberHistograms(), 2); - TS_ASSERT_EQUALS(ws2->readY(0).size(), 2000); - - TS_ASSERT_EQUALS(ws1->readX(0), ws2->readX(0)); - TS_ASSERT_EQUALS(ws2->readX(0), ws2->readX(1)); - - TS_ASSERT_EQUALS(std::accumulate(ws2->readY(0).begin(), ws2->readY(0).end(), 0), 359076); - TS_ASSERT_EQUALS(std::accumulate(ws2->readY(1).begin(), ws2->readY(1).end(), 0), 258629); - - TS_ASSERT_DELTA(std::accumulate(ws2->readE(0).begin(), ws2->readE(0).end(), 0.0), 14054.2, 0.1); - TS_ASSERT_DELTA(std::accumulate(ws2->readE(1).begin(), ws2->readE(1).end(), 0.0), 11976.0, 0.1); - - AnalysisDataService::Instance().clear(); - } - -}; - - -#endif /* MANTID_DATAHANDLING_ApplyGroupingFromMuonNexusTEST_H_ */