Newer
Older
Russell Taylor
committed
#ifndef INSTRUMENTRAYTRACERTEST_H_
#define INSTRUMENTRAYTRACERTEST_H_
#include <cxxtest/TestSuite.h>
#include "MantidAPI/AnalysisDataService.h"
#include "MantidDataObjects/Workspace2D.h"
#include "MantidGeometry/Objects/InstrumentRayTracer.h"
#include "MantidTestHelpers/ComponentCreationHelper.h"
#include "MantidTestHelpers/WorkspaceCreationHelper.h"
Janik Zikovsky
committed
#include "MantidAPI/FrameworkManager.h"
Russell Taylor
committed
using namespace Mantid::Geometry;
using Mantid::DataObjects::Workspace2D_sptr;
using Mantid::API::AnalysisDataService;
using Mantid::Kernel::V3D;
Janik Zikovsky
committed
using Mantid::API::FrameworkManager;
Russell Taylor
committed
//-------------------------------------------------------------
// Fake test suite to keep cxxtest happy
//-------------------------------------------------------------
class InstrumentRayTracerTest : public CxxTest::TestSuite {
Russell Taylor
committed
public:
void testNothing() {}
};
//-------------------------------------------------------------
// Performance test for large rectangular detectors
// TEST IS HERE IN DATAHANDLING BECAUSE IT USES LOADINSTRUMENT
//-------------------------------------------------------------
class InstrumentRayTracerTestPerformance : public CxxTest::TestSuite {
Russell Taylor
committed
public:
/// Test instrument
Instrument_sptr m_inst;
Workspace2D_sptr topazWS;
// This pair of boilerplate methods prevent the suite being created statically
// This means the constructor isn't called when running other tests
static InstrumentRayTracerTestPerformance *createSuite() {
return new InstrumentRayTracerTestPerformance();
}
static void destroySuite(InstrumentRayTracerTestPerformance *suite) {
delete suite;
}
Russell Taylor
committed
InstrumentRayTracerTestPerformance() {
Russell Taylor
committed
m_inst = ComponentCreationHelper::createTestInstrumentRectangular(2, 100);
topazWS = WorkspaceCreationHelper::Create2DWorkspace(1, 2);
AnalysisDataService::Instance().add("TOPAZ_2010", topazWS);
// Load a small test file
FrameworkManager::Instance().exec(
"LoadInstrument", 6, "Filename", "TOPAZ_Definition_2010.xml",
"Workspace", "TOPAZ_2010", "RewriteSpectraMap", "True");
Russell Taylor
committed
}
~InstrumentRayTracerTestPerformance() {
Russell Taylor
committed
AnalysisDataService::Instance().remove("TOPAZ_2010");
}
void test_RectangularDetector() {
Russell Taylor
committed
// Directly in Z+ = towards the detector center
V3D testDir(0.0, 0.0, 1.0);
for (size_t i = 0; i < 100; i++) {
Russell Taylor
committed
InstrumentRayTracer tracker(m_inst);
tracker.traceFromSample(testDir);
Links results = tracker.getResults();
TS_ASSERT_EQUALS(results.size(), 3);
Russell Taylor
committed
}
}
void test_TOPAZ() {
bool verbose = false;
Russell Taylor
committed
Instrument_const_sptr inst = topazWS->getInstrument();
Russell Taylor
committed
// Directly in Z+ = towards the detector center
for (int azimuth = 0; azimuth < 360; azimuth += 3)
for (int elev = -89; elev < 89; elev += 3) {
Russell Taylor
committed
// Make a vector pointing in every direction
V3D testDir;
testDir.spherical(1, double(elev), double(azimuth));
if (verbose)
std::cout << testDir << " : ";
Russell Taylor
committed
// Track it
InstrumentRayTracer tracker(inst);
tracker.traceFromSample(testDir);
Links results = tracker.getResults();
if (verbose)
showResults(results, inst);
}
}
private:
void showResults(Links &results, Instrument_const_sptr inst) {
Russell Taylor
committed
Links::const_iterator resultItr = results.begin();
for (; resultItr != results.end(); resultItr++) {
IComponent_const_sptr component =
inst->getComponentByID(resultItr->componentID);
Russell Taylor
committed
std::cout << component->getName() << ", ";
}
std::cout << "\n";
}
};
#endif // InstrumentRayTracerTEST_H_