diff --git a/Code/Mantid/Framework/MDAlgorithms/src/CreateMDHistoWorkspace.cpp b/Code/Mantid/Framework/MDAlgorithms/src/CreateMDHistoWorkspace.cpp index a312ee39c848..0dfe0a426e7f 100644 --- a/Code/Mantid/Framework/MDAlgorithms/src/CreateMDHistoWorkspace.cpp +++ b/Code/Mantid/Framework/MDAlgorithms/src/CreateMDHistoWorkspace.cpp @@ -49,12 +49,13 @@ const std::string CreateMDHistoWorkspace::category() const { */ void CreateMDHistoWorkspace::init() { declareProperty(new ArrayProperty("SignalInput"), - "A comma separated list of all the signal values required " - "for the workspace"); + "Signal array for n-dimensional workspace"); declareProperty(new ArrayProperty("ErrorInput"), - "A comma separated list of all the error values required for " - "the workspace"); + "Error array for n-dimensional workspace"); + + declareProperty(new ArrayProperty("NumberOfEvents", std::vector(0)), + "Number of pixels array for n-dimensional workspace. Optional, defaults to 1 per bin."); // Declare all the generic properties required. this->initGenericImportProps(); @@ -65,11 +66,13 @@ void CreateMDHistoWorkspace::init() { */ void CreateMDHistoWorkspace::exec() { MDHistoWorkspace_sptr ws = this->createEmptyOutputWorkspace(); - double *signals = ws->getSignalArray(); - double *errors = ws->getErrorSquaredArray(); + Mantid::signal_t *signals = ws->getSignalArray(); + Mantid::signal_t *errors = ws->getErrorSquaredArray(); + Mantid::signal_t *nEvents = ws->getNumEventsArray(); std::vector signalValues = getProperty("SignalInput"); std::vector errorValues = getProperty("ErrorInput"); + std::vector numberOfEvents = getProperty("NumberOfEvents"); size_t binProduct = this->getBinProduct(); std::stringstream stream; @@ -82,6 +85,15 @@ void CreateMDHistoWorkspace::exec() { throw std::invalid_argument("Expected size of the ErrorInput is: " + stream.str()); } + if (!numberOfEvents.empty() && binProduct != numberOfEvents.size()) { + throw std::invalid_argument("Expected size of the NumberOfEvents is: " + + stream.str() + ". Leave empty to auto fill with 1.0"); + } + + // Auto fill number of events. + if(numberOfEvents.empty()) { + numberOfEvents = std::vector(binProduct, 1.0); + } // Copy from property std::copy(signalValues.begin(), signalValues.end(), signals); @@ -93,6 +105,10 @@ void CreateMDHistoWorkspace::exec() { std::copy(errorValues.begin(), errorValues.end(), errors); // Clean up errorValues.swap(empty); + // Copy from property + std::copy(numberOfEvents.begin(), numberOfEvents.end(), nEvents); + // Clean up + numberOfEvents.swap(empty); setProperty("OutputWorkspace", ws); } diff --git a/Code/Mantid/Framework/MDAlgorithms/src/LoadSQW.cpp b/Code/Mantid/Framework/MDAlgorithms/src/LoadSQW.cpp index 4f71e5fd9bbf..b0ae1eebee89 100644 --- a/Code/Mantid/Framework/MDAlgorithms/src/LoadSQW.cpp +++ b/Code/Mantid/Framework/MDAlgorithms/src/LoadSQW.cpp @@ -276,10 +276,10 @@ void interpretAs(Buffer, current_pix + column_size), interpretAs(Buffer, current_pix + column_size_2), interpretAs(Buffer, current_pix + column_size_3)}; - float error = interpretAs(Buffer, current_pix + column_size_8); + const float errorSQ = interpretAs(Buffer, current_pix + column_size_8); ws->addEvent(MDEvent<4>( interpretAs(Buffer, current_pix + column_size_7), // Signal - error * error, // Error sq + errorSQ, // Error sq static_cast(interpretAs( Buffer, current_pix + column_size_6)), // run Index static_cast(interpretAs( diff --git a/Code/Mantid/Framework/MDAlgorithms/test/CreateMDHistoWorkspaceTest.h b/Code/Mantid/Framework/MDAlgorithms/test/CreateMDHistoWorkspaceTest.h index 3bfe22e06062..66982677d491 100644 --- a/Code/Mantid/Framework/MDAlgorithms/test/CreateMDHistoWorkspaceTest.h +++ b/Code/Mantid/Framework/MDAlgorithms/test/CreateMDHistoWorkspaceTest.h @@ -81,6 +81,16 @@ class CreateMDHistoWorkspaceTest : public CxxTest::TestSuite AnalysisDataService::Instance().remove(outWSName); } + void test_throws_if_wrong_number_of_nevents() + { + std::string outWSName = "test_ws"; + IAlgorithm_sptr alg = make_standard_algorithm(outWSName); + alg->setProperty("NumberOfEvents", "1"); //Only one number of events value provided, but NumberOfBins set to 5! + TS_ASSERT_THROWS(alg->execute(), std::invalid_argument); + AnalysisDataService::Instance().remove(outWSName); + } + + void test_exec_1D() { // Name of the output workspace.