Skip to content
Snippets Groups Projects
Commit ef19a200 authored by Owen Arnold's avatar Owen Arnold
Browse files

refs #11348. Apply the fix.

The algorithm documentation for this algorithm is actually up-to-date
correctly pointing out that the file stores the variance. The fix
brings the implementation in-line.
parent 476b8e5d
Branches mr_peak_fitting
No related tags found
No related merge requests found
......@@ -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);
}
......
......@@ -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>(
......
......@@ -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.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment