Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feature/8104_query_mdworkspace'
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Reuter committed Oct 11, 2013
2 parents 37228df + 85a72aa commit f89701a
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 1 deletion.
9 changes: 9 additions & 0 deletions Code/Mantid/Framework/MDEvents/src/QueryMDWorkspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,15 @@ namespace MDEvents
output->cell<double>(rowCounter, cellIndex++) = it->getNormalizedError();
output->cell<int>(rowCounter, cellIndex++) = int(it->getNumEvents());
VMD center = it->getCenter();
const size_t numberOriginal = input->numOriginalWorkspaces();
if(numberOriginal > 0)
{
const size_t index = numberOriginal -1;
CoordTransform * transform = input->getTransformToOriginal(index);
VMD temp = transform->applyVMD(center);
center = temp;
}

for(size_t index = 0; index < ndims; ++index)
{
output->cell<double>(rowCounter, cellIndex++) = center[index];
Expand Down
60 changes: 59 additions & 1 deletion Code/Mantid/Framework/MDEvents/test/QueryMDWorkspaceTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include "MantidMDEvents/QueryMDWorkspace.h"
#include "MantidAPI/ITableWorkspace.h"
#include "MantidDataObjects/TableWorkspace.h"
#include "MantidAPI/FrameworkManager.h"
#include "MantidAPI/AlgorithmManager.h"

using namespace Mantid;
using namespace Mantid::MDEvents;
Expand All @@ -25,6 +27,10 @@ class QueryMDWorkspaceTest : public CxxTest::TestSuite
static QueryMDWorkspaceTest *createSuite() { return new QueryMDWorkspaceTest(); }
static void destroySuite( QueryMDWorkspaceTest *suite ) { delete suite; }

QueryMDWorkspaceTest()
{
FrameworkManager::Instance();
}

void checkInputs(std::string strNormalisation)
{
Expand Down Expand Up @@ -193,10 +199,62 @@ class QueryMDWorkspaceTest : public CxxTest::TestSuite

TSM_ASSERT("Workspace output is not an ITableWorkspace", table !=NULL);
size_t expectedCount = 3 + in_ws->getNumDims(); //3 fixed columns are Signal, Error, nEvents
TSM_ASSERT_EQUALS("Six columns expected", expectedCount, table->columnCount());
TSM_ASSERT_EQUALS("Five columns expected", expectedCount, table->columnCount());
TSM_ASSERT_EQUALS("Wrong number of rows", 3, table->rowCount());
}

void testOnSlice()
{
auto in_ws = MDEventsTestHelper::makeMDEW<2>(2, -10.0, 10, 3);

// Create a line slice at 45 degrees to the original workspace.
IAlgorithm_sptr binMDAlg = AlgorithmManager::Instance().create("BinMD");
binMDAlg->setRethrows(true);
binMDAlg->initialize();
binMDAlg->setChild(true);
binMDAlg->setProperty("InputWorkspace", in_ws);
binMDAlg->setProperty("AxisAligned", false);
binMDAlg->setPropertyValue("BasisVector0", "X,units,0.7071,0.7071"); // cos 45 to in_ws x-axis (consistent with a 45 degree anti-clockwise rotation)
binMDAlg->setPropertyValue("BasisVector1", "Y,units,-0.7071,0.7071"); // cos 45 to in_ws y-axis (consistent with a 45 degree anti-clockwise rotation)
binMDAlg->setPropertyValue("OutputExtents", "0,28.284,-1,1"); // 0 to sqrt((-10-10)^2 + (-10-10)^2), -1 to 1 (in new coordinate axes)
binMDAlg->setPropertyValue("OutputBins", "10,1");
binMDAlg->setPropertyValue("OutputWorkspace", "temp");
binMDAlg->execute();
Workspace_sptr temp = binMDAlg->getProperty("OutputWorkspace");
auto slice = boost::dynamic_pointer_cast<IMDWorkspace>(temp);

QueryMDWorkspace query;
query.setRethrows(true);
query.setChild(true);
query.initialize();
query.setProperty("InputWorkspace", slice);
query.setPropertyValue("OutputWorkspace", "QueryWS");
query.execute();
ITableWorkspace_sptr table = query.getProperty("OutputWorkspace");

TSM_ASSERT("Workspace output is not an ITableWorkspace", table !=NULL);
size_t expectedCount = 3 + in_ws->getNumDims(); //3 fixed columns are Signal, Error, nEvents
TSM_ASSERT_EQUALS("Six columns expected", expectedCount, table->columnCount());
TSM_ASSERT_EQUALS("Wrong number of rows", 10, table->rowCount());

/*
Note that what we do in the following is to check that the y and x coordinates are the same. They will ONLY be the same in the
original coordinate system owing to the way that they have been rotated. If we were displaying the results in the new coordinate system
then y == 0 and x would increment from 0 to sqrt((-10-10)^2 + (-10-10)^2).
*/
for(size_t i =0; i < table->rowCount(); ++i)
{
auto xColumn = table->getColumn(3);
auto yColumn = table->getColumn(4);
double x = xColumn->toDouble(i);
double y = yColumn->toDouble(i);
std::stringstream messageBuffer;
messageBuffer << "X and Y should be equal at row index: " << i;
TSM_ASSERT_DELTA(messageBuffer.str(), x, y, 1e-3);
}

}


};

Expand Down

0 comments on commit f89701a

Please sign in to comment.