Skip to content

Commit

Permalink
Add unit test for reduced MAPS instrument re #5797
Browse files Browse the repository at this point in the history
Signed-off-by: Karl Palmen <karl.palmen@stfc.ac.uk>
  • Loading branch information
KarlPalmen committed Mar 15, 2013
1 parent c6b196e commit 7db7d38
Showing 1 changed file with 64 additions and 1 deletion.
65 changes: 64 additions & 1 deletion Code/Mantid/Framework/Algorithms/test/ApplyCalibrationTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "MantidKernel/V3D.h"
#include "MantidGeometry/Instrument.h"
#include "MantidGeometry/Instrument/Component.h"
#include "MantidDataHandling/LoadEmptyInstrument.h"
#include <stdexcept>

using namespace Mantid::Algorithms;
Expand All @@ -39,7 +40,7 @@ class ApplyCalibrationTest : public CxxTest::TestSuite
TS_ASSERT( appCalib.isInitialized() )
}

void testExec()
void testSimple()
{

int ndets = 3;
Expand Down Expand Up @@ -83,6 +84,68 @@ class ApplyCalibrationTest : public CxxTest::TestSuite
TS_ASSERT_DELTA( newPos.Z() , 2.0, 0.0001);
}

void testComplex()
{
/* The purpse of this test is to test the algorithm when the relative positioning and rotation
* of components is complicated. This is the case for the MAPS instrument and so here we
* load the IDF of a MAPS instrument where the number of detectors has been reduced.
*/

int ndets = 3;

// Create workspace with a reduced MAPS instrument (parametrised) and retrieve vfrom data store.
const std::string wsName("ApplyCabrationWs");
Mantid::DataHandling::LoadEmptyInstrument loader;
loader.initialize();
loader.setPropertyValue("Filename", "IDFs_For_UNIT_TESTING/MAPS_Definition_reduced.xml");
loader.setPropertyValue("OutputWorkspace", wsName);
loader.execute();
AnalysisDataServiceImpl & dataStore = AnalysisDataService::Instance();
MatrixWorkspace_sptr ws = dataStore.retrieveWS<MatrixWorkspace>(wsName);

// Create Calibration Table
int firstDetectorID = 34208002;
ITableWorkspace_sptr posTableWs = WorkspaceFactory::Instance().createTable();
posTableWs->addColumn("int","Detector ID");
posTableWs->addColumn("V3D","Detector Position");

for(int i=0; i < ndets; ++i)
{
TableRow row = posTableWs->appendRow();
row << firstDetectorID + 10*i << V3D(1.0,0.01*i,2.0);
}
TS_ASSERT_THROWS_NOTHING(appCalib.setPropertyValue("Workspace", wsName ));
TS_ASSERT_THROWS_NOTHING(appCalib.setProperty<ITableWorkspace_sptr>("PositionTable", posTableWs ));
TS_ASSERT_THROWS_NOTHING(appCalib.execute());

TS_ASSERT( appCalib.isExecuted() );

IDetector_const_sptr det = ws->getDetector(1830);
int id = det->getID();
V3D newPos = det->getPos();
TS_ASSERT_EQUALS( id, firstDetectorID);
TS_ASSERT_DELTA( newPos.X() , 1.0, 0.0001);
TS_ASSERT_DELTA( newPos.Y() , 0.0, 0.0001);
TS_ASSERT_DELTA( newPos.Z() , 2.0, 0.0001);

det = ws->getDetector(1840);
id = det->getID();
newPos = det->getPos();
TS_ASSERT_EQUALS( id, firstDetectorID + 10);
TS_ASSERT_DELTA( newPos.X() , 1.0, 0.0001);
TS_ASSERT_DELTA( newPos.Y() , 0.01, 0.0001);
TS_ASSERT_DELTA( newPos.Z() , 2.0, 0.0001);

det = ws->getDetector(1850);
id = det->getID();
newPos = det->getPos();
TS_ASSERT_EQUALS( id, firstDetectorID + 20);
TS_ASSERT_DELTA( newPos.X() , 1.0, 0.0001);
TS_ASSERT_DELTA( newPos.Y() , 0.02, 0.0001);
TS_ASSERT_DELTA( newPos.Z() , 2.0, 0.0001);
}


private:
ApplyCalibration appCalib;

Expand Down

0 comments on commit 7db7d38

Please sign in to comment.