Commit 6578b105 authored by Whitfield, Ross's avatar Whitfield, Ross
Browse files

Add getAzimuthal calculation

parent f86b55cd
......@@ -66,7 +66,6 @@ public:
void setInstrument(const Geometry::Instrument_const_sptr &) override;
Geometry::IDetector_const_sptr getDetector() const override;
Geometry::Instrument_const_sptr getInstrument() const override;
void setReferenceFrame(std::shared_ptr<Geometry::ReferenceFrame> frame);
std::shared_ptr<const Geometry::ReferenceFrame>
getReferenceFrame() const override;
......@@ -110,6 +109,8 @@ public:
LeanElasticPeak &operator=(const LeanElasticPeak &other);
private:
void setReferenceFrame(std::shared_ptr<Geometry::ReferenceFrame> frame);
/// Q_sample vector
Mantid::Kernel::V3D m_Qsample;
......
......@@ -53,7 +53,7 @@ LeanElasticPeak::LeanElasticPeak(const Mantid::Kernel::V3D &QSampleFrame)
LeanElasticPeak::LeanElasticPeak(
const Mantid::Kernel::V3D &QSampleFrame,
const Mantid::Kernel::Matrix<double> &goniometer,
boost::optional<std::shared_ptr<ReferenceFrame>> refFrame)
boost::optional<std::shared_ptr<Geometry::ReferenceFrame>> refFrame)
: BasePeak() {
if (refFrame.is_initialized())
setReferenceFrame(refFrame.get());
......@@ -177,7 +177,15 @@ double LeanElasticPeak::getScattering() const {
// -------------------------------------------------------------------------------------
/** Calculate the azimuthal angle of the peak */
double LeanElasticPeak::getAzimuthal() const {
return std::numeric_limits<double>::quiet_NaN();
const V3D qLab = getQLabFrame();
std::shared_ptr<const ReferenceFrame> refFrame = getReferenceFrame();
const double qSign = (convention != "Crystallography") ? 1.0 : -1.0;
const V3D detectorDir = -qLab * qSign;
if (refFrame)
return atan2(detectorDir[refFrame->pointingUp()],
detectorDir[refFrame->pointingHorizontal()]);
else
return atan2(detectorDir[1], detectorDir[0]);
}
// -------------------------------------------------------------------------------------
......@@ -206,9 +214,6 @@ Mantid::Kernel::V3D LeanElasticPeak::getQSampleFrame() const {
//----------------------------------------------------------------------------------------------
/** Set the peak using the peak's position in reciprocal space, in the sample
*frame.
* The GoniometerMatrix will be used to find the Q in the lab frame, so it
*should
* be set beforehand.
*
* @param QSampleFrame :: Q of the center of the peak, in reciprocal space
* This is in inelastic convention: momentum transfer of the LATTICE!
......@@ -239,10 +244,6 @@ void LeanElasticPeak::setQSampleFrame(
//----------------------------------------------------------------------------------------------
/** Set the peak using the peak's position in reciprocal space, in the lab
*frame.
* The detector position will be determined.
* DetectorID, row and column will be set to -1 since they are not (necessarily)
*found.
* You can call findDetector to look for the detector ID
*
* @param qLab :: Q of the center of the peak, in reciprocal space.
* This is in inelastic convention: momentum transfer of the LATTICE!
......
......@@ -50,7 +50,7 @@ public:
TS_ASSERT_THROWS(p.getSamplePos(), const Exception::NotImplementedError &)
TS_ASSERT(std::isnan(p.getTOF()))
TS_ASSERT_EQUALS(p.getScattering(), 0.)
TS_ASSERT(std::isnan(p.getAzimuthal()))
TS_ASSERT_EQUALS(p.getAzimuthal(), -M_PI)
TS_ASSERT_THROWS(p.getL1(), const Exception::NotImplementedError &)
TS_ASSERT_THROWS(p.getL2(), const Exception::NotImplementedError &)
}
......@@ -90,6 +90,17 @@ public:
TS_ASSERT_DELTA(p.getWavelength(), M_PI * 6 / 7, 1e-9)
TS_ASSERT_DELTA(p.getDSpacing(), 1.679251908362714, 1e-9)
TS_ASSERT_DELTA(p.getScattering(), 1.860548028230944, 1e-9)
TS_ASSERT_DELTA(p.getAzimuthal(), -2.6779450449, 1e-9)
// calculate Q_lab from scattering and azimuthal to check values
const auto k = 2 * M_PI / p.getWavelength();
V3D qLab(-sin(p.getScattering()) * cos(p.getAzimuthal()),
-sin(p.getScattering()) * sin(p.getAzimuthal()),
1 - cos(p.getScattering()));
qLab *= k;
TS_ASSERT_DELTA(qLab.X(), 2, 1e-9)
TS_ASSERT_DELTA(qLab.Y(), 1, 1e-9)
TS_ASSERT_DELTA(qLab.Z(), 3, 1e-9)
}
void test_Qsample_gon_constructor_refFrame() {
......@@ -117,6 +128,16 @@ public:
TS_ASSERT_DELTA(p.getWavelength(), M_PI * 4 / 7, 1e-9)
TS_ASSERT_DELTA(p.getDSpacing(), 1.679251908362714, 1e-9)
TS_ASSERT_DELTA(p.getScattering(), 1.1278852827212578, 1e-9)
// calculate Q_lab from scattering and azimuthal to check values
const auto k = 2 * M_PI / p.getWavelength();
V3D qLab(1 - cos(p.getScattering()),
-sin(p.getScattering()) * sin(p.getAzimuthal()),
-sin(p.getScattering()) * cos(p.getAzimuthal()));
qLab *= k;
TS_ASSERT_DELTA(qLab.X(), 2, 1e-9)
TS_ASSERT_DELTA(qLab.Y(), 1, 1e-9)
TS_ASSERT_DELTA(qLab.Z(), 3, 1e-9)
}
void test_Qsample_gon_constructor_wavelength_fail() {
......@@ -294,6 +315,9 @@ public:
TS_ASSERT_DELTA(leanpeak.getScattering(), peak.getScattering(), 1e-7);
TS_ASSERT_DELTA(leanpeak.getScattering(), 0.2203733065, 1e-7);
TS_ASSERT_DELTA(leanpeak.getAzimuthal(), peak.getAzimuthal(), 1e-7);
TS_ASSERT_DELTA(leanpeak.getAzimuthal(), 0.7853981637, 1e-7);
TS_ASSERT_EQUALS(leanpeak.getRunNumber(), peak.getRunNumber());
TS_ASSERT_EQUALS(leanpeak.getRunNumber(), 1234);
......
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