Skip to content

Commit

Permalink
refs #11056. Add regression test.
Browse files Browse the repository at this point in the history
Prove that this doesn't work yet.
  • Loading branch information
OwenArnold committed Feb 11, 2015
1 parent 6e4edcc commit a6ab43c
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 4 deletions.
81 changes: 77 additions & 4 deletions Code/Mantid/Framework/DataObjects/test/PeakTest.h
Expand Up @@ -5,6 +5,11 @@
#include "MockObjects.h"
#include "MantidKernel/Timer.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 <iomanip>
#include <gmock/gmock.h>
Expand All @@ -18,12 +23,25 @@ using namespace Mantid::Kernel;

class PeakTest : public CxxTest::TestSuite
{
private:
/// Common instrument
Instrument_sptr inst;
Instrument_sptr m_minimalInstrument;
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()
Expand Down Expand Up @@ -261,6 +279,7 @@ class PeakTest : public CxxTest::TestSuite
/** Compare two peaks, but not the detector IDs etc. */
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.getQSampleFrame(), p2.getQSampleFrame() );
TS_ASSERT_EQUALS( p1.getDetPos(), p2.getDetPos() );
Expand Down Expand Up @@ -290,6 +309,60 @@ class PeakTest : public CxxTest::TestSuite
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*/
void test_setQSampleFrame()
{
Expand Down
Expand Up @@ -150,6 +150,9 @@ createTestInstrumentRectangular(int num_banks, int pixels,
Mantid::Geometry::Instrument_sptr
createTestInstrumentRectangular2(int num_banks, int pixels,
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_
40 changes: 40 additions & 0 deletions Code/Mantid/Framework/TestHelpers/src/ComponentCreationHelper.cpp
Expand Up @@ -20,9 +20,11 @@
#include "MantidGeometry/Instrument/DetectorGroup.h"
#include "MantidGeometry/Instrument/Detector.h"
#include "MantidGeometry/Instrument/RectangularDetector.h"
#include "MantidGeometry/Instrument/ReferenceFrame.h"

#include <Poco/Path.h>
#include <boost/shared_array.hpp>
#include <boost/make_shared.hpp>
#include "MantidGeometry/IDetector.h"

using namespace Mantid::Geometry;
Expand Down Expand Up @@ -559,4 +561,42 @@ Instrument_sptr createTestInstrumentRectangular2(int num_banks, int pixels,

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;
}
}

0 comments on commit a6ab43c

Please sign in to comment.