Commit a6ab43c4 authored by Owen Arnold's avatar Owen Arnold
Browse files

refs #11056. Add regression test.

Prove that this doesn't work yet.
parent 6e4edcc1
...@@ -5,6 +5,11 @@ ...@@ -5,6 +5,11 @@
#include "MockObjects.h" #include "MockObjects.h"
#include "MantidKernel/Timer.h" #include "MantidKernel/Timer.h"
#include "MantidKernel/System.h" #include "MantidKernel/System.h"
#include "MantidKernel/UnitFactory.h"
#include "MantidKernel/Unit.h"
#include "MantidKernel/V3D.h"
#include "MantidKernel/PhysicalConstants.h"
#include "MantidGeometry/Instrument/ReferenceFrame.h"
#include <iostream> #include <iostream>
#include <iomanip> #include <iomanip>
#include <gmock/gmock.h> #include <gmock/gmock.h>
...@@ -18,12 +23,25 @@ using namespace Mantid::Kernel; ...@@ -18,12 +23,25 @@ using namespace Mantid::Kernel;
class PeakTest : public CxxTest::TestSuite class PeakTest : public CxxTest::TestSuite
{ {
private:
/// Common instrument
Instrument_sptr inst;
Instrument_sptr m_minimalInstrument;
public: public:
/// Common instrument
Instrument_sptr inst;
void setUp() // This pair of boilerplate methods prevent the suite being created statically
// This means the constructor isn't called when running other tests
static PeakTest *createSuite() {
return new PeakTest();
}
static void destroySuite(PeakTest *suite) { delete suite; }
// Constructor
PeakTest() : inst(ComponentCreationHelper::createTestInstrumentRectangular(5, 100))
{ {
inst = ComponentCreationHelper::createTestInstrumentRectangular(5, 100);
} }
void test_constructor() void test_constructor()
...@@ -261,6 +279,7 @@ public: ...@@ -261,6 +279,7 @@ public:
/** Compare two peaks, but not the detector IDs etc. */ /** Compare two peaks, but not the detector IDs etc. */
void comparePeaks(Peak & p1, Peak & p2) void comparePeaks(Peak & p1, Peak & p2)
{ {
// TODO. Peak should implement bool operator==(const Peak&) and that should be tested, rather than having external functionality here.
TS_ASSERT_EQUALS( p1.getQLabFrame(), p2.getQLabFrame() ); TS_ASSERT_EQUALS( p1.getQLabFrame(), p2.getQLabFrame() );
TS_ASSERT_EQUALS( p1.getQSampleFrame(), p2.getQSampleFrame() ); TS_ASSERT_EQUALS( p1.getQSampleFrame(), p2.getQSampleFrame() );
TS_ASSERT_EQUALS( p1.getDetPos(), p2.getDetPos() ); TS_ASSERT_EQUALS( p1.getDetPos(), p2.getDetPos() );
...@@ -290,6 +309,60 @@ public: ...@@ -290,6 +309,60 @@ public:
TS_ASSERT_EQUALS( p2.getDetectorID(), -1); TS_ASSERT_EQUALS( p2.getDetectorID(), -1);
} }
void test_setQLabFrame2()
{
// Create fictional instrument
const V3D source(0,0,0);
const V3D sample(15, 0, 0);
const V3D detectorPos(20, 5, 0);
const V3D beam1 = sample - source;
const V3D beam2 = detectorPos - sample;
auto minimalInstrument = ComponentCreationHelper::createMinimalInstrument( source, sample, detectorPos );
// Calculate energy of neutron based on velocity
const double velocity = 1.1 * 10e3; // m/sec
double efixed = 0.5 * Mantid::PhysicalConstants::NeutronMass * velocity * velocity ; // In Joules
efixed = efixed / Mantid::PhysicalConstants::meV;
// Derive distances and angles
const double l1 = beam1.norm();
const double l2 = beam2.norm();
const double scatteringAngle2 = beam2.angle(beam1);
const V3D qLabDir = beam1 - beam2;
// Derive the wavelength
std::vector<double> x;
const double microSecsInSec = 1e6;
x.push_back( ( (l1 + l2) / velocity ) * microSecsInSec ); // Make a TOF
std::vector<double> y;
Unit_sptr unitOfLambda = UnitFactory::Instance().create("Wavelength");
unitOfLambda->fromTOF(x, y, l1, l2, scatteringAngle2, 0, efixed, 0);
// Derive QLab for diffraction
const double wavenumber_in_angstrom_times_tof_in_microsec =
(Mantid::PhysicalConstants::NeutronMass * (l1 + l2) * 1e-10 * microSecsInSec) /
Mantid::PhysicalConstants::h_bar;
V3D qLab = qLabDir * wavenumber_in_angstrom_times_tof_in_microsec;
//Peak peak(minimalInstrument, 1 /* detector id */, x[0] /*wavelength*/);
Peak peak; // Everything will be default
peak.setInstrument(minimalInstrument); // Can't do anything without the instrument
peak.setQLabFrame(qLab);
auto detector = peak.getDetector();
TS_ASSERT_EQUALS(1, detector->getID());
TS_ASSERT_EQUALS(detectorPos, detector->getPos())
// Test that wavelengths aggree firstly.
//TS_ASSERT_EQUALS(x[0], peak.getWavelength());
}
/** Create peaks using Q in sample frame + a goniometer rotation matrix*/ /** Create peaks using Q in sample frame + a goniometer rotation matrix*/
void test_setQSampleFrame() void test_setQSampleFrame()
{ {
......
...@@ -150,6 +150,9 @@ createTestInstrumentRectangular(int num_banks, int pixels, ...@@ -150,6 +150,9 @@ createTestInstrumentRectangular(int num_banks, int pixels,
Mantid::Geometry::Instrument_sptr Mantid::Geometry::Instrument_sptr
createTestInstrumentRectangular2(int num_banks, int pixels, createTestInstrumentRectangular2(int num_banks, int pixels,
double pixelSpacing = 0.008); double pixelSpacing = 0.008);
/// Creates a mimimal valid virtual instrument.
Mantid::Geometry::Instrument_sptr createMinimalInstrument(const Mantid::Kernel::V3D& sourcePos, const Mantid::Kernel::V3D& samplePos, const Mantid::Kernel::V3D& detectorPos );
} }
#endif // COMPONENTCREATIONHELPERS_H_ #endif // COMPONENTCREATIONHELPERS_H_
...@@ -20,9 +20,11 @@ ...@@ -20,9 +20,11 @@
#include "MantidGeometry/Instrument/DetectorGroup.h" #include "MantidGeometry/Instrument/DetectorGroup.h"
#include "MantidGeometry/Instrument/Detector.h" #include "MantidGeometry/Instrument/Detector.h"
#include "MantidGeometry/Instrument/RectangularDetector.h" #include "MantidGeometry/Instrument/RectangularDetector.h"
#include "MantidGeometry/Instrument/ReferenceFrame.h"
#include <Poco/Path.h> #include <Poco/Path.h>
#include <boost/shared_array.hpp> #include <boost/shared_array.hpp>
#include <boost/make_shared.hpp>
#include "MantidGeometry/IDetector.h" #include "MantidGeometry/IDetector.h"
using namespace Mantid::Geometry; using namespace Mantid::Geometry;
...@@ -559,4 +561,42 @@ Instrument_sptr createTestInstrumentRectangular2(int num_banks, int pixels, ...@@ -559,4 +561,42 @@ Instrument_sptr createTestInstrumentRectangular2(int num_banks, int pixels,
return testInst; return testInst;
} }
/**
* createOneDetectorInstrument, creates the most simple possible definition of an instrument in which we can extract a valid L1 and L2 distance for unit calculations.
*
* Beam direction is along X,
* Up direction is Y
*
* @param sourcePos : V3D position
* @param samplePos : V3D sample position
* @param detectorPos : V3D detector position
* @return Instrument generated.
*/
Instrument_sptr createMinimalInstrument(const V3D& sourcePos, const V3D& samplePos, const V3D& detectorPos )
{
Instrument_sptr instrument = boost::make_shared<Instrument>();
instrument->setReferenceFrame(
boost::make_shared<ReferenceFrame>(Mantid::Geometry::Y /*up*/, Mantid::Geometry::X /*along*/, Left, "0,0,0"));
// A source
ObjComponent *source = new ObjComponent("source");
source->setPos(sourcePos);
instrument->add(source);
instrument->markAsSource(source);
// A sample
ObjComponent *sample = new ObjComponent("some-surface-holder");
source->setPos(samplePos);
instrument->add(sample);
instrument->markAsSamplePos(sample);
// A detector
Detector *det = new Detector("point-detector", 1 /*detector id*/, NULL);
det->setPos(detectorPos);
instrument->add(det);
instrument->markAsDetector(det);
return instrument;
}
} }
Supports Markdown
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