Skip to content
Snippets Groups Projects
Commit f54a855c authored by Jose Borreguero's avatar Jose Borreguero
Browse files

Refs #27876 unit test with RAW file


Signed-off-by: default avatarJose Borreguero <borreguero@gmail.com>
parent 7b0b7bcb
No related branches found
No related tags found
No related merge requests found
...@@ -19,10 +19,12 @@ ...@@ -19,10 +19,12 @@
#include "MantidAlgorithms/ApplyCalibration.h" #include "MantidAlgorithms/ApplyCalibration.h"
#include "MantidDataHandling/LoadEmptyInstrument.h" #include "MantidDataHandling/LoadEmptyInstrument.h"
#include "MantidDataHandling/LoadInstrument.h" #include "MantidDataHandling/LoadInstrument.h"
#include "MantidDataHandling/LoadRaw3.h"
#include "MantidDataObjects/Workspace2D.h" #include "MantidDataObjects/Workspace2D.h"
#include "MantidGeometry/Instrument.h" #include "MantidGeometry/Instrument.h"
#include "MantidGeometry/Instrument/Component.h" #include "MantidGeometry/Instrument/Component.h"
#include "MantidGeometry/Instrument/ComponentInfo.h" #include "MantidGeometry/Instrument/ComponentInfo.h"
#include "MantidGeometry/Instrument/DetectorInfo.h"
#include "MantidKernel/V3D.h" #include "MantidKernel/V3D.h"
#include "MantidTestHelpers/WorkspaceCreationHelper.h" #include "MantidTestHelpers/WorkspaceCreationHelper.h"
...@@ -104,6 +106,75 @@ public: ...@@ -104,6 +106,75 @@ public:
dataStore.remove(wsName); dataStore.remove(wsName);
} }
/**
* Load a *.raw file and reset the detector position, width, and height for the first two spectra
*/
void testCalibrateRawFile() {
// Create a calibration table
ITableWorkspace_sptr calTableWs =
WorkspaceFactory::Instance().createTable();
calTableWs->addColumn("int", "Detector ID");
calTableWs->addColumn("V3D", "Detector Position");
calTableWs->addColumn("double", "Detector Y Coordinate");
calTableWs->addColumn("double", "Detector Width");
calTableWs->addColumn("double", "Detector Height");
// Load the first two spectra from a *.raw data file into a workspace
const int nSpectra = 2;
const std::string wsName("applyCalibrationToRaw");
Mantid::DataHandling::LoadRaw3 loader;
loader.initialize();
loader.setPropertyValue("Filename", "HRP39180.RAW");
loader.setPropertyValue("OutputWorkspace", wsName);
loader.setPropertyValue("SpectrumMin", "1"); // Spectrum number, not workspace index
loader.setPropertyValue("SpectrumMax", "9");//std::to_string(nSpectra));
loader.execute();
AnalysisDataServiceImpl &dataStore = AnalysisDataService::Instance();
MatrixWorkspace_sptr workspace = dataStore.retrieveWS<MatrixWorkspace>(wsName);
const auto &detectorInfo = workspace->detectorInfo();
const auto &componentInfo = workspace->componentInfo();
// Populate the calibration table with some final detector positions, widths, and heights
const std::vector<V3D> positions{V3D(0.20, 0.0, 0.42), V3D(0.53, 0.0, 0.75)};
const std::vector<double> yCoords{0.31, 0.64};
const std::vector<double> widths{0.008, 0.007};
const std::vector<double> heights{0.041, 0.039};
for(size_t i=0; i < nSpectra; i++) {
IDetector_const_sptr detector = workspace->getDetector(i);
const auto detectorID = detector->getID();
TableRow row = calTableWs->appendRow();
// insert data in the same order in which table columns were declared
// detector-ID position Y-coordinate Width Height
row << detectorID << positions[i] << yCoords[i] << widths[i] << heights[i];
}
// Apply the calibration to the workspace
ApplyCalibration calibrationAlgorithm;
calibrationAlgorithm.initialize();
TS_ASSERT(calibrationAlgorithm.isInitialized())
TS_ASSERT_THROWS_NOTHING(calibrationAlgorithm.setPropertyValue("Workspace", wsName));
TS_ASSERT_THROWS_NOTHING(calibrationAlgorithm.setProperty<ITableWorkspace_sptr>("CalibrationTable", calTableWs));
TS_ASSERT_THROWS_NOTHING(calibrationAlgorithm.execute());
TS_ASSERT(calibrationAlgorithm.isExecuted());
// Assert the calibration
for(size_t i=0; i < nSpectra; i++) {
// assert detector position
IDetector_const_sptr detector = workspace->getDetector(i);
const auto detectorID = detector->getID();
const auto &newPosition = detector->getPos();
TS_ASSERT_DELTA(newPosition.X(), positions[i].X(), 0.0001);
TS_ASSERT_DELTA(newPosition.Y(), yCoords[i], 0.0001);
TS_ASSERT_DELTA(newPosition.Z(), positions[i].Z(), 0.0001);
// assert detector width and height
const auto detectorIndex = detectorInfo.indexOf(detectorID);
const auto &scaleFactor = componentInfo.scaleFactor(detectorIndex);
const auto &box = componentInfo.shape(detectorIndex).getBoundingBox().width();
TS_ASSERT_DELTA(scaleFactor.X() * box.X(), widths[i], 0.0001);
TS_ASSERT_DELTA(scaleFactor.Y() * box.Y(), heights[i], 0.0001);
}
}
void testComplex() { void testComplex() {
/* The purpse of this test is to test the algorithm when the relative /* The purpse of this test is to test the algorithm when the relative
* positioning and rotation * positioning and rotation
......
7d19937fbfb68e962c190454a128fde6
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment