Skip to content

Commit

Permalink
refs #11348. Apply the fix.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
OwenArnold committed Apr 30, 2015
1 parent 476b8e5 commit ef19a20
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 8 deletions.
28 changes: 22 additions & 6 deletions Code/Mantid/Framework/MDAlgorithms/src/CreateMDHistoWorkspace.cpp
Expand Up @@ -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();
Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions Code/Mantid/Framework/MDAlgorithms/src/LoadSQW.cpp
Expand Up @@ -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>(
Expand Down
Expand Up @@ -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.
Expand Down

0 comments on commit ef19a20

Please sign in to comment.