Skip to content

Commit

Permalink
Fix so integration now works with event workspaces
Browse files Browse the repository at this point in the history
  • Loading branch information
NickDraper committed Feb 15, 2016
1 parent 7b8bf1b commit d3fff0b
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 15 deletions.
12 changes: 6 additions & 6 deletions Framework/Algorithms/inc/MantidAlgorithms/Integration.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
// Includes
//----------------------------------------------------------------------
#include "MantidAPI/Algorithm.h"
#include "MantidDataObjects/EventWorkspace.h"

namespace Mantid {
namespace Algorithms {
Expand Down Expand Up @@ -82,15 +81,16 @@ class DLLExport Integration : public API::Algorithm {
void init();
void exec();

API::MatrixWorkspace_sptr rangeFilterEventWorkspace(
API::MatrixWorkspace_sptr eventWorkspace, double minRange,
double maxRange);

/// Get the input workspace
API::MatrixWorkspace_const_sptr getInputWorkspace();
API::MatrixWorkspace_sptr getInputWorkspace();
/// Create the outputworkspace
API::MatrixWorkspace_sptr
getOutputWorkspace(API::MatrixWorkspace_const_sptr inWS, const int minSpec,
getOutputWorkspace(API::MatrixWorkspace_sptr inWS, const int minSpec,
const int maxSpec);

/// Input event workspace
DataObjects::EventWorkspace_const_sptr inputEventWS;
};

} // namespace Algorithm
Expand Down
45 changes: 42 additions & 3 deletions Framework/Algorithms/src/Integration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void Integration::exec() {
bool incPartBins = getProperty("IncludePartialBins");

// Get the input workspace
MatrixWorkspace_const_sptr localworkspace = this->getInputWorkspace();
MatrixWorkspace_sptr localworkspace = this->getInputWorkspace();

const int numberOfSpectra =
static_cast<int>(localworkspace->getNumberHistograms());
Expand All @@ -105,6 +105,28 @@ void Integration::exec() {
maxRange = 0.0;
}

//---------------------------------------------------------------------------------
// Now, determine if the input workspace is actually an EventWorkspace
EventWorkspace_sptr eventInputWS =
boost::dynamic_pointer_cast<EventWorkspace>(localworkspace);

if (eventInputWS != nullptr) {
//------- EventWorkspace as input -------------------------------------
// Get the eventworkspace rebinned to apply the upper and lowerrange
double evntMinRange =
isEmpty(minRange) ? eventInputWS->getEventXMin() : minRange;
double evntMaxRange =
isEmpty(maxRange) ? eventInputWS->getEventXMax() : maxRange;
localworkspace =
rangeFilterEventWorkspace(eventInputWS, evntMinRange, evntMaxRange);

if ((isEmpty(maxSpec)) && (isEmpty(maxSpec))) {
// Assign it to the output workspace property
setProperty("OutputWorkspace", localworkspace);
return;
}
}

// Create the 2D workspace (with 1 bin) for the output
MatrixWorkspace_sptr outputWorkspace =
this->getOutputWorkspace(localworkspace, minSpec, maxSpec);
Expand Down Expand Up @@ -252,13 +274,30 @@ void Integration::exec() {
return;
}

/**
* Uses rebin to reduce event workspaces to a single bin histogram
*/
API::MatrixWorkspace_sptr
Integration::rangeFilterEventWorkspace(API::MatrixWorkspace_sptr workspace,
double minRange, double maxRange) {
bool childLog = g_log.is(Logger::Priority::PRIO_DEBUG);
auto childAlg = createChildAlgorithm("Rebin", 0, 0.1, childLog);
childAlg->setProperty("InputWorkspace", workspace);
std::ostringstream binParams;
binParams << minRange << "," << maxRange - minRange << "," << maxRange;
childAlg->setPropertyValue("Params", binParams.str());
childAlg->setProperty("PreserveEvents", false);
childAlg->executeAsChildAlg();
return childAlg->getProperty("OutputWorkspace");
}

/**
* This function gets the input workspace. In the case for a RebinnedOutput
* workspace, it must be cleaned before proceeding. Other workspaces are
* untouched.
* @return the input workspace, cleaned if necessary
*/
MatrixWorkspace_const_sptr Integration::getInputWorkspace() {
MatrixWorkspace_sptr Integration::getInputWorkspace() {
MatrixWorkspace_sptr temp = getProperty("InputWorkspace");

if (temp->id() == "RebinnedOutput") {
Expand Down Expand Up @@ -302,7 +341,7 @@ MatrixWorkspace_const_sptr Integration::getInputWorkspace() {
* @return the output workspace
*/
MatrixWorkspace_sptr
Integration::getOutputWorkspace(MatrixWorkspace_const_sptr inWS,
Integration::getOutputWorkspace(MatrixWorkspace_sptr inWS,
const int minSpec, const int maxSpec) {
if (inWS->id() == "RebinnedOutput") {
MatrixWorkspace_sptr outWS = API::WorkspaceFactory::Instance().create(
Expand Down
7 changes: 1 addition & 6 deletions Framework/Algorithms/test/IntegrationTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,7 @@ class IntegrationTest : public CxxTest::TestSuite {
integ.execute();
TS_ASSERT(integ.isExecuted());

// No longer output an EventWorkspace, Rebin should be used instead
// EventWorkspace_sptr output;
// TS_ASSERT_THROWS_NOTHING(output =
// boost::dynamic_pointer_cast<EventWorkspace>(
// AnalysisDataService::Instance().retrieve(outName) ) );

// No longer output an EventWorkspace
Workspace_sptr output;
TS_ASSERT_THROWS_NOTHING(
output = AnalysisDataService::Instance().retrieve(outName));
Expand Down

0 comments on commit d3fff0b

Please sign in to comment.