Commit f158ff0f authored by Jose Borreguero's avatar Jose Borreguero
Browse files

Refs #30887 clean getDetPos



Signed-off-by: default avatarJose Borreguero <borreguero@gmail.com>
parent 3e4e39c7
......@@ -11,6 +11,7 @@
#include "MantidGeometry/Crystal/IPeak.h"
#include "MantidKernel/ListValidator.h"
#include <variant>
#include <boost/function.hpp>
using namespace Mantid::API;
......@@ -79,14 +80,15 @@ void PeaksIntersection::executePeaksIntersection(const bool checkPeakExtents) {
m_peakRadius = this->getProperty("PeakRadius");
// Find the coordinate frame to use an set up boost function for this.
boost::function<V3D(IPeak *)> coordFrameFunc = &IPeak::getHKL;
boost::function<V3D(Peak *)> coordFrameFunc;
coordFrameFunc = &Peak::getHKL;
if (coordinateFrame == detectorSpaceFrame()) {
coordFrameFunc = &Peak::getDetectorPosition;
} else if (coordinateFrame == qLabFrame()) {
coordFrameFunc = &IPeak::getQLabFrame;
coordFrameFunc = &Peak::getQLabFrame;
} else if (coordinateFrame == qSampleFrame()) {
coordFrameFunc = &IPeak::getQSampleFrame;
coordFrameFunc = &Peak::getQSampleFrame;
}
// Create the faces.
......
......@@ -86,7 +86,6 @@ public:
void setInitialEnergy(double m_initialEnergy) override;
void setFinalEnergy(double m_finalEnergy) override;
virtual Mantid::Kernel::V3D getDetPos() const override;
virtual Mantid::Kernel::V3D getSamplePos() const override;
double getL1() const override;
double getL2() const override;
......
......@@ -121,7 +121,7 @@ public:
void setInitialEnergy(double m_initialEnergy) override;
void setFinalEnergy(double m_finalEnergy) override;
virtual Mantid::Kernel::V3D getDetPos() const override;
virtual Mantid::Kernel::V3D getDetPos() const;
virtual Mantid::Kernel::V3D getSamplePos() const override;
double getL1() const override;
double getL2() const override;
......
......@@ -256,13 +256,6 @@ void LeanElasticPeak::setInitialEnergy(double) {
throw Exception::NotImplementedError("Use LeanElasticPeak::setWavelength");
}
// -------------------------------------------------------------------------------------
/** Return the detector position vector */
Mantid::Kernel::V3D LeanElasticPeak::getDetPos() const {
throw Exception::NotImplementedError(
"LeanElasticPeak has no detector information");
}
// -------------------------------------------------------------------------------------
/** Return the sample position vector */
Mantid::Kernel::V3D LeanElasticPeak::getSamplePos() const {
......
......@@ -37,8 +37,6 @@ public:
TS_ASSERT(std::isinf(p.getFinalEnergy()))
TS_ASSERT_EQUALS(p.getQSampleFrame(), V3D(0, 0, 0))
TS_ASSERT_EQUALS(p.getQLabFrame(), V3D())
TS_ASSERT_THROWS(p.getDetPos(), const Exception::NotImplementedError &)
TS_ASSERT_THROWS(p.getSamplePos(), const Exception::NotImplementedError &)
TS_ASSERT_THROWS(p.getTOF(), const Exception::NotImplementedError &)
TS_ASSERT_EQUALS(p.getScattering(), 0.)
......
......@@ -94,7 +94,6 @@ public:
virtual int getRow() const = 0;
virtual int getCol() const = 0;
virtual Mantid::Kernel::V3D getDetPos() const = 0;
virtual double getL1() const = 0;
virtual double getL2() const = 0;
......
......@@ -122,7 +122,6 @@ public:
MOCK_CONST_METHOD0(getBankName, std::string());
MOCK_CONST_METHOD0(getRow, int());
MOCK_CONST_METHOD0(getCol, int());
MOCK_CONST_METHOD0(getDetPos, Mantid::Kernel::V3D());
MOCK_CONST_METHOD0(getL1, double());
MOCK_CONST_METHOD0(getL2, double());
MOCK_CONST_METHOD0(getPeakShape, const Mantid::Geometry::PeakShape &());
......
......@@ -209,8 +209,6 @@ void export_IPeak() {
"For :class:`~mantid.geometry.RectangularDetector` s only, returns "
"the column (x) of the pixel of the "
":class:`~mantid.geometry.Detector`.")
.def("getDetPos", &IPeak::getDetPos, arg("self"),
"Return the :class:`~mantid.geometry.Detector` position vector")
.def("getL1", &IPeak::getL1, arg("self"),
"Return the L1 flight path length (source to "
":class:`~mantid.api.Sample`), in meters. ")
......
......@@ -71,17 +71,17 @@ class SaveHKLCW(PythonAlgorithm):
if directionCosines:
U = peak_ws.sample().getOrientedLattice().getU()
sample_pos = peak_ws.getInstrument().getSample().getPos()
q_reverse_incident = peak_ws.getInstrument().getSource().getPos() - sample_pos
q_reverse_incident = np.array(q_reverse_incident) / q_reverse_incident.norm()
source_pos = peak_ws.getInstrument().getSource().getPos()
ki_n = (sample_pos - source_pos).norm() # direction of incident wavevector
for p in peak_ws:
if directionCosines:
R = p.getGoniometerMatrix()
RU = np.dot(R, U)
q_diffracted = p.getDetPos() - sample_pos
q_diffracted = np.array(q_diffracted) / q_diffracted.norm()
dir_cos_1 = np.dot(RU.T, q_reverse_incident)
dir_cos_2 = np.dot(RU.T, q_diffracted)
ki = ki_n * (2 * np.pi / p.getWavelength())
kf_n = (ki + p.getQLabFrame()).norm() # direction of scattered wavevector
dir_cos_1 = np.dot(RU.T, -ki_n) # notice ki direction is reversed
dir_cos_2 = np.dot(RU.T, kf_n)
f.write(
"{:4.0f}{:4.0f}{:4.0f}{:8.2f}{:8.2f}{:4d}{:8.5f}{:8.5f}{:8.5f}{:8.5f}{:8.5f}{:8.5f}\n"
.format(p.getH(), p.getK(), p.getL(), p.getIntensity(),
......
......@@ -152,10 +152,6 @@ class IPeakTest(unittest.TestCase):
self.assertEqual(self._peak.getRow(), row)
self.assertEqual(self._peak.getCol(), col)
def test_get_det_pos(self):
expected_det_pos = np.array([0.05962, -0.09450, -0.23786])
npt.assert_allclose(self._peak.getDetPos(), expected_det_pos, atol=1e-5)
def test_get_l1(self):
expected_l1 = 8.3
self.assertEqual(self._peak.getL1(), expected_l1)
......
......@@ -7,6 +7,7 @@
#include "MantidQtWidgets/InstrumentView/PeakOverlay.h"
#include "MantidAPI/AlgorithmManager.h"
#include "MantidAPI/IPeaksWorkspace.h"
#include "MantidDataObjects/Peak.h"
#include "MantidQtWidgets/InstrumentView/UnwrappedSurface.h"
#include <QList>
......@@ -15,6 +16,10 @@
#include <cmath>
#include <stdexcept>
namespace {
Mantid::Kernel::Logger g_log("PeakOverlay");
}
namespace MantidQt {
namespace MantidWidgets {
......@@ -243,7 +248,15 @@ void PeakOverlay::createMarkers(const PeakMarker2D::Style &style) {
this->clear();
for (int i = 0; i < nPeaks; ++i) {
Mantid::Geometry::IPeak &peak = getPeak(i);
const Mantid::Kernel::V3D &pos = peak.getDetPos();
Mantid::Kernel::V3D pos;
try {
auto peakFull = dynamic_cast<Mantid::DataObjects::Peak &>(peak);
pos = peakFull.getDetPos();
}
catch(std::bad_cast) {
g_log.error("Cannot create markers for this type of peak");
return;
}
// Project the peak (detector) position onto u,v coords
double u, v, uscale, vscale;
m_surface->project(pos, u, v, uscale, vscale);
......
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