diff --git a/Code/Mantid/Framework/MDAlgorithms/src/CreateMDHistoWorkspace.cpp b/Code/Mantid/Framework/MDAlgorithms/src/CreateMDHistoWorkspace.cpp index a312ee39c8481fe6dc9ac72f824f9c0d99b0eab5..0dfe0a426e7f783f17ab64184f9b034e1806a78c 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<double>("SignalInput"), - "A comma separated list of all the signal values required " - "for the workspace"); + "Signal array for n-dimensional workspace"); declareProperty(new ArrayProperty<double>("ErrorInput"), - "A comma separated list of all the error values required for " - "the workspace"); + "Error array for n-dimensional workspace"); + + declareProperty(new ArrayProperty<double>("NumberOfEvents", std::vector<double>(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<double> signalValues = getProperty("SignalInput"); std::vector<double> errorValues = getProperty("ErrorInput"); + std::vector<double> 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<double>(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 4f71e5fd9bbf2003ed9e1100f0f7dfa7cd06bf2b..b0ae1eebee894d45643ec1b9749f1c0662d7016d 100644 --- a/Code/Mantid/Framework/MDAlgorithms/src/LoadSQW.cpp +++ b/Code/Mantid/Framework/MDAlgorithms/src/LoadSQW.cpp @@ -276,10 +276,10 @@ void interpretAs<float>(Buffer, current_pix + column_size), interpretAs<float>(Buffer, current_pix + column_size_2), interpretAs<float>(Buffer, current_pix + column_size_3)}; - float error = interpretAs<float>(Buffer, current_pix + column_size_8); + const float errorSQ = interpretAs<float>(Buffer, current_pix + column_size_8); ws->addEvent(MDEvent<4>( interpretAs<float>(Buffer, current_pix + column_size_7), // Signal - error * error, // Error sq + errorSQ, // Error sq static_cast<uint16_t>(interpretAs<float>( Buffer, current_pix + column_size_6)), // run Index static_cast<int32_t>(interpretAs<float>( diff --git a/Code/Mantid/Framework/MDAlgorithms/test/CreateMDHistoWorkspaceTest.h b/Code/Mantid/Framework/MDAlgorithms/test/CreateMDHistoWorkspaceTest.h index 3bfe22e06062366607d9a2775b3bb3c2eed3c3d4..66982677d4912764bc477fd3fa796ec0b51f90d5 100644 --- a/Code/Mantid/Framework/MDAlgorithms/test/CreateMDHistoWorkspaceTest.h +++ b/Code/Mantid/Framework/MDAlgorithms/test/CreateMDHistoWorkspaceTest.h @@ -81,6 +81,16 @@ public: 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.