Commit b9df678a authored by Whitfield, Ross's avatar Whitfield, Ross
Browse files

Add a test

parent 8e154791
......@@ -177,6 +177,7 @@ set(TEST_FILES
PeakShapeSphericalFactoryTest.h
PeakShapeSphericalTest.h
PeakTest.h
LeanPeakTest.h
PeaksWorkspaceTest.h
RebinnedOutputTest.h
RefAxisTest.h
......
......@@ -38,8 +38,7 @@ public:
LeanPeak();
LeanPeak(const Mantid::Kernel::V3D &QLabFrame,
const Mantid::Kernel::Matrix<double> &goniometer);
LeanPeak(const Mantid::Kernel::V3D &QSampleFrame,
boost::optional<const Mantid::Kernel::Matrix<double>> &goniometer);
LeanPeak(const Mantid::Kernel::V3D &QSampleFrame);
/// Copy constructor
LeanPeak(const LeanPeak &other);
......
......@@ -35,8 +35,9 @@ LeanPeak::LeanPeak()
m_binCount(0), m_initialEnergy(0.), m_finalEnergy(0.),
m_absorptionWeightedPathLength(0), m_GoniometerMatrix(3, 3, true),
m_InverseGoniometerMatrix(3, 3, true), m_runNumber(0), m_monitorCount(0),
m_row(-1), m_col(-1), m_peakNumber(0), m_intHKL(V3D(0, 0, 0)),
m_intMNP(V3D(0, 0, 0)), m_peakShape(std::make_shared<NoShape>()) {
m_row(-1), m_col(-1), m_Qsample(V3D(0, 0, 0)), m_peakNumber(0),
m_intHKL(V3D(0, 0, 0)), m_intMNP(V3D(0, 0, 0)),
m_peakShape(std::make_shared<NoShape>()) {
convention = Kernel::ConfigService::Instance().getString("Q.convention");
}
......@@ -50,10 +51,10 @@ LeanPeak::LeanPeak()
LeanPeak::LeanPeak(const Mantid::Kernel::V3D &QLabFrame,
const Mantid::Kernel::Matrix<double> &goniometer)
: m_H(0), m_K(0), m_L(0), m_intensity(0), m_sigmaIntensity(0),
m_binCount(0), m_absorptionWeightedPathLength(0),
m_GoniometerMatrix(goniometer), m_InverseGoniometerMatrix(goniometer),
m_runNumber(0), m_monitorCount(0), m_peakNumber(0),
m_intHKL(V3D(0, 0, 0)), m_intMNP(V3D(0, 0, 0)),
m_binCount(0), m_initialEnergy(0.), m_finalEnergy(0.),
m_absorptionWeightedPathLength(0), m_GoniometerMatrix(goniometer),
m_InverseGoniometerMatrix(goniometer), m_runNumber(0), m_monitorCount(0),
m_peakNumber(0), m_intHKL(V3D(0, 0, 0)), m_intMNP(V3D(0, 0, 0)),
m_peakShape(std::make_shared<NoShape>()) {
convention = Kernel::ConfigService::Instance().getString("Q.convention");
if (fabs(m_InverseGoniometerMatrix.Invert()) < 1e-8)
......@@ -72,18 +73,14 @@ LeanPeak::LeanPeak(const Mantid::Kernel::V3D &QLabFrame,
* @param goniometer :: optional, a 3x3 rotation matrix, to allow convertion to
*QLab
*/
LeanPeak::LeanPeak(
const Mantid::Kernel::V3D &QSampleFrame,
boost::optional<const Mantid::Kernel::Matrix<double>> &goniometer)
LeanPeak::LeanPeak(const Mantid::Kernel::V3D &QSampleFrame)
: m_H(0), m_K(0), m_L(0), m_intensity(0), m_sigmaIntensity(0),
m_binCount(0), m_absorptionWeightedPathLength(0),
m_GoniometerMatrix(3, 3, true), m_InverseGoniometerMatrix(3, 3, true),
m_runNumber(0), m_monitorCount(0), m_peakNumber(0),
m_intHKL(V3D(0, 0, 0)), m_intMNP(V3D(0, 0, 0)),
m_binCount(0), m_initialEnergy(0.0), m_finalEnergy(0.0),
m_absorptionWeightedPathLength(0), m_GoniometerMatrix(3, 3, true),
m_InverseGoniometerMatrix(3, 3, true), m_runNumber(0), m_monitorCount(0),
m_peakNumber(0), m_intHKL(V3D(0, 0, 0)), m_intMNP(V3D(0, 0, 0)),
m_peakShape(std::make_shared<NoShape>()) {
convention = Kernel::ConfigService::Instance().getString("Q.convention");
if (goniometer.is_initialized())
this->setGoniometerMatrix(goniometer.get());
this->setQSampleFrame(QSampleFrame);
}
......@@ -102,10 +99,10 @@ LeanPeak::LeanPeak(const LeanPeak &other)
m_GoniometerMatrix(other.m_GoniometerMatrix),
m_InverseGoniometerMatrix(other.m_InverseGoniometerMatrix),
m_runNumber(other.m_runNumber), m_monitorCount(other.m_monitorCount),
m_row(other.m_row), m_col(other.m_col), m_peakNumber(other.m_peakNumber),
m_intHKL(other.m_intHKL), m_intMNP(other.m_intMNP),
m_peakShape(other.m_peakShape->clone()), convention(other.convention) {}
m_row(other.m_row), m_col(other.m_col), m_Qsample(other.m_Qsample),
m_peakNumber(other.m_peakNumber), m_intHKL(other.m_intHKL),
m_intMNP(other.m_intMNP), m_peakShape(other.m_peakShape->clone()),
convention(other.convention) {}
//----------------------------------------------------------------------------------------------
/** Set the incident wavelength of the neutron. Calculates the energy from this.
* Assumes elastic scattering.
......@@ -617,6 +614,30 @@ LeanPeak &LeanPeak::operator=(const LeanPeak &other) {
return *this;
}
/** After creating a peak using the Q in the lab frame,
* the detPos is set to the direction of the detector (but the detector is
*unknown)
*
* Using the instrument set in the peak, perform ray tracing
* to find the exact detector.
*
* @return true if the detector ID was found.
*/
bool LeanPeak::findDetector() { throw std::runtime_error("not implemented"); }
/**
* Performs the same algorithm as findDetector() but uses a pre-existing
* InstrumentRayTracer object to be able to take adavtange of its caches.
* This method should be preferred if findDetector is to be called many times
* over the same instrument.
* @param tracer A reference to an existing InstrumentRayTracer object.
* @return true if the detector ID was found.
*/
bool LeanPeak::findDetector([
[maybe_unused]] const InstrumentRayTracer &tracer) {
throw std::runtime_error("not implemented");
}
/**
Forwarding function. Exposes the detector position directly.
*/
......
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright &copy; 2018 ISIS Rutherford Appleton Laboratory UKRI,
// NScD Oak Ridge National Laboratory, European Spallation Source,
// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
// SPDX - License - Identifier: GPL - 3.0 +
#pragma once
#include "MantidKernel/V3D.h"
#include <cxxtest/TestSuite.h>
#include "MantidDataObjects/LeanPeak.h"
using namespace Mantid::DataObjects;
using namespace Mantid::Geometry;
using namespace Mantid::Kernel;
class LeanPeakTest : public CxxTest::TestSuite {
public:
// This pair of boilerplate methods prevent the suite being created statically
// This means the constructor isn't called when running other tests
static LeanPeakTest *createSuite() { return new LeanPeakTest(); }
static void destroySuite(LeanPeakTest *suite) { delete suite; }
void test_default_constructor() {
LeanPeak p;
TS_ASSERT_EQUALS(p.getH(), 0.0)
TS_ASSERT_EQUALS(p.getK(), 0.0)
TS_ASSERT_EQUALS(p.getL(), 0.0)
TS_ASSERT_EQUALS(p.getInitialEnergy(), 0.0)
TS_ASSERT_EQUALS(p.getFinalEnergy(), 0.0)
TS_ASSERT_EQUALS(p.getQSampleFrame(), V3D(0, 0, 0))
TS_ASSERT_EQUALS(p.getQLabFrame(), V3D())
TS_ASSERT_THROWS(p.getDetectorID(), const std::runtime_error &)
TS_ASSERT_THROWS(p.getDetector(), const std::runtime_error &)
TS_ASSERT_THROWS(p.getInstrument(), const std::runtime_error &)
TS_ASSERT_THROWS(p.findDetector(), const std::runtime_error &)
TS_ASSERT_THROWS(p.getDetectorPosition(), const std::runtime_error &)
TS_ASSERT_THROWS(p.getDetectorPositionNoCheck(), const std::runtime_error &)
TS_ASSERT_THROWS(p.getScattering(), const std::runtime_error &)
TS_ASSERT_THROWS(p.getAzimuthal(), const std::runtime_error &)
TS_ASSERT_THROWS(p.getTOF(), const std::runtime_error &)
TS_ASSERT_THROWS(p.getDetPos(), const std::runtime_error &)
TS_ASSERT_THROWS(p.getSamplePos(), const std::runtime_error &)
TS_ASSERT_THROWS(p.getL1(), const std::runtime_error &)
TS_ASSERT_THROWS(p.getL2(), const std::runtime_error &)
}
void test_Qsample_constructor() {
LeanPeak p(V3D(1, 2, 3));
p.setWavelength(1.);
// This goniometer should just swap x and y of q
Mantid::Kernel::Matrix<double> gon(3, 3);
gon[0][1] = 1;
gon[1][0] = 1;
gon[2][2] = 1;
p.setGoniometerMatrix(gon);
TS_ASSERT_EQUALS(p.getQSampleFrame(), V3D(1, 2, 3))
TS_ASSERT_EQUALS(p.getQLabFrame(), V3D(2, 1, 3))
TS_ASSERT_DELTA(p.getInitialEnergy(), 81.8042024359, 1e-5)
TS_ASSERT_DELTA(p.getFinalEnergy(), 81.8042024359, 1e-5)
TS_ASSERT_DELTA(p.getWavelength(), 1., 1e-9)
}
};
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment