Mantid
Loading...
Searching...
No Matches
LeanElasticPeak.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
12#include "MantidKernel/Logger.h"
14
15#include "boost/make_shared.hpp"
16
17#include <algorithm>
18#include <cctype>
19#include <string>
20#include <utility>
21
22using namespace Mantid;
23using namespace Mantid::Kernel;
24using namespace Mantid::Geometry;
25
26namespace Mantid::DataObjects {
27
28//----------------------------------------------------------------------------------------------
30LeanElasticPeak::LeanElasticPeak() : BasePeak(), m_Qsample(V3D(0, 0, 0)), m_wavelength(0.) {}
31
32//----------------------------------------------------------------------------------------------
41 : BasePeak(), m_Qsample(QSampleFrame), m_wavelength(0.) {}
42
43//----------------------------------------------------------------------------------------------
52 const Mantid::Kernel::Matrix<double> &goniometer,
53 std::optional<std::shared_ptr<const Geometry::ReferenceFrame>> refFrame)
54 : BasePeak() {
55 if (refFrame.has_value())
56 setReferenceFrame(refFrame.value());
57 setQSampleFrame(QSampleFrame, goniometer);
58}
59
60//----------------------------------------------------------------------------------------------
69LeanElasticPeak::LeanElasticPeak(const Mantid::Kernel::V3D &QSampleFrame, double wavelength)
70 : BasePeak(), m_Qsample(QSampleFrame), m_wavelength(wavelength) {}
71
77
78//----------------------------------------------------------------------------------------------
84 : BasePeak(ipeak), m_Qsample(ipeak.getQSampleFrame()), m_wavelength(ipeak.getWavelength()) {}
85
86//----------------------------------------------------------------------------------------------
91void LeanElasticPeak::setWavelength(double wavelength) { m_wavelength = wavelength; }
92
94std::shared_ptr<const Geometry::ReferenceFrame> LeanElasticPeak::getReferenceFrame() const {
95 return (m_refFrame) ? m_refFrame : std::make_shared<const ReferenceFrame>();
96}
97
102void LeanElasticPeak::setReferenceFrame(std::shared_ptr<const ReferenceFrame> frame) { m_refFrame = std::move(frame); }
103
104// -------------------------------------------------------------------------------------
107
108// -------------------------------------------------------------------------------------
113 throw Exception::NotImplementedError("LeanElasticPeak::getTOF(): no detector infomation in LeanElasticPeak");
114}
115
116// returns the detectorID of the pixel, throws NotImplementedError for LeanElasticPeak
118 throw Exception::NotImplementedError("LeanElasticPeak::getDetectorID(): no detector infomation in LeanElasticPeak");
119}
120
123 throw Exception::NotImplementedError("LeanElasticPeak::getRow(): no detector infomation in LeanElasticPeak");
124}
125
128 throw Exception::NotImplementedError("LeanElasticPeak::getCol(): no detector infomation in LeanElasticPeak");
129}
130
131// -------------------------------------------------------------------------------------
133double LeanElasticPeak::getScattering() const { return asin(getWavelength() / (2 * getDSpacing())) * 2; }
134
135// -------------------------------------------------------------------------------------
138 const V3D qLab = getQLabFrame();
139 std::shared_ptr<const ReferenceFrame> refFrame = getReferenceFrame();
140 const double qSign = (m_convention != "Crystallography") ? 1.0 : -1.0;
141 const V3D detectorDir = -qLab * qSign;
142 if (refFrame)
143 return atan2(detectorDir[refFrame->pointingUp()], detectorDir[refFrame->pointingHorizontal()]);
144 else
145 return atan2(detectorDir[1], detectorDir[0]);
146}
147
148// -------------------------------------------------------------------------------------
151 const V3D qSample = getQSampleFrame();
152 const double qSign = (m_convention != "Crystallography") ? 1.0 : -1.0;
153 return getSourceDirectionSampleFrame() * -1.0 - qSample * qSign * getWavelength() / (2 * M_PI);
154}
155
156// -------------------------------------------------------------------------------------
159 std::shared_ptr<const ReferenceFrame> refFrame = getReferenceFrame();
160 if (refFrame)
161 return getInverseGoniometerMatrix() * refFrame->vecPointingAlongBeam() * -1.0;
162 else
163 return getInverseGoniometerMatrix() * V3D(0, 0, -1);
164}
165
166// -------------------------------------------------------------------------------------
168double LeanElasticPeak::getDSpacing() const { return 2 * M_PI / m_Qsample.norm(); }
169
170//----------------------------------------------------------------------------------------------
177
178//----------------------------------------------------------------------------------------------
182
183//----------------------------------------------------------------------------------------------
191void LeanElasticPeak::setQSampleFrame(const Mantid::Kernel::V3D &QSampleFrame, std::optional<double>) {
192 m_Qsample = QSampleFrame;
193}
194
196 const Mantid::Kernel::Matrix<double> &goniometer) {
197 m_Qsample = QSampleFrame;
198 setGoniometerMatrix(goniometer);
199
200 const V3D qLab = getQLabFrame();
201
202 try {
203 double wl = calculateWavelengthFromQLab(qLab);
204 setWavelength(wl);
205 } catch (std::exception &e) {
206 g_log.information() << "Unable to automatically determine wavelength from q-lab\n"
207 << e.what() << ", goniometer is likely not correct\n";
208 }
209}
210
211//----------------------------------------------------------------------------------------------
220void LeanElasticPeak::setQLabFrame(const Mantid::Kernel::V3D &qLab, std::optional<double>) {
222}
223
224//----------------------------------------------------------------------------------------------
227 // Velocity of the neutron (non-relativistic)
228 const double velocity = PhysicalConstants::h / (m_wavelength * 1e-10 * PhysicalConstants::NeutronMass);
229 // Energy in J of the neutron
230 const double energy = PhysicalConstants::NeutronMass * velocity * velocity / 2.0;
231 // Convert to meV
233}
234
237
240double LeanElasticPeak::getEnergyTransfer() const { return 0.; }
241
244 throw Exception::NotImplementedError("Use LeanElasticPeak::setWavelength");
245}
246
249 throw Exception::NotImplementedError("Use LeanElasticPeak::setWavelength");
250}
251
252// -------------------------------------------------------------------------------------
255 throw Exception::NotImplementedError("LeanElasticPeak has no detector information");
256}
257
258// -------------------------------------------------------------------------------------
261 throw Exception::NotImplementedError("LeanElasticPeak has no detector information");
262}
263
270 if (&other != this) {
271 BasePeak::operator=(other);
272 m_Qsample = other.m_Qsample;
273 m_wavelength = other.m_wavelength;
274 }
275 return *this;
276}
277
279
280} // namespace Mantid::DataObjects
double energy
Definition GetAllEi.cpp:157
Structure describing a single-crystal peak.
Definition BasePeak.h:33
Mantid::Kernel::Matrix< double > getInverseGoniometerMatrix() const
Get the goniometer rotation matrix at which this peak was measured.
Definition BasePeak.cpp:214
BasePeak & operator=(BasePeak &&) noexcept=default
double calculateWavelengthFromQLab(const Mantid::Kernel::V3D &qLab)
Definition BasePeak.cpp:350
Mantid::Kernel::Matrix< double > getGoniometerMatrix() const override
Get the goniometer rotation matrix at which this peak was measured.
Definition BasePeak.cpp:210
void setGoniometerMatrix(const Mantid::Kernel::Matrix< double > &goniometerMatrix) override
Set the goniometer rotation matrix at which this peak was measured.
Definition BasePeak.cpp:220
Structure describing a single-crystal peak.
void setQSampleFrame(const Mantid::Kernel::V3D &QSampleFrame, std::optional< double >=std::nullopt) override
Set the peak using the peak's position in reciprocal space, in the sample frame.
int getCol() const override
returns the column (x) of the pixel of the detector, throws NotImplementedError for LeanElasticPeak
std::shared_ptr< const Geometry::ReferenceFrame > getReferenceFrame() const override
Return a shared ptr to the reference frame for this peak.
Mantid::Kernel::V3D getDetectorDirectionSampleFrame() const override
Calculate the scattered beam direction in the sample frame
void setWavelength(double wavelength) override
Set the wavelength of the neutron.
void setFinalEnergy(double m_finalEnergy) override
Set the final energy.
double getWavelength() const override
Return the neutron wavelength (in angstroms)
std::shared_ptr< const Geometry::ReferenceFrame > m_refFrame
double getAzimuthal() const override
Calculate the azimuthal angle of the peak
double getEnergyTransfer() const override
Get the difference between the initial and final neutron energy in meV, elastic so always 0.
double getL1() const override
Return the L1 flight path length (source to sample), in meters.
static Mantid::Kernel::Logger g_log
Static logger.
double m_wavelength
Wavelength of neutrons at the peak.
Mantid::Kernel::V3D getQSampleFrame() const override
Return the Q change (of the lattice, k_i - k_f) for this peak.
void setInitialEnergy(double m_initialEnergy) override
Set the initial energy.
Mantid::Kernel::V3D m_Qsample
Q_sample vector.
Mantid::Kernel::V3D getSourceDirectionSampleFrame() const override
Calculate the reverse incident beam direction in the sample frame
double getFinalEnergy() const override
Get the final neutron energy in meV.
double getScattering() const override
Calculate the scattering angle of the peak
double getTOF() const override
Calculate the time of flight (in microseconds) of the neutrons for this peak, using the geometry of t...
double getDSpacing() const override
Calculate the d-spacing of the peak, in 1/Angstroms
int getRow() const override
returns the row (y) of the pixel of the detector, throws NotImplementedError for LeanElasticPeak
double getInitialEnergy() const override
Get the initial (incident) neutron energy in meV.
void setReferenceFrame(std::shared_ptr< const Geometry::ReferenceFrame > frame)
Setter for the reference frame.
double getL2() const override
Return the L2 flight path length (sample to detector), in meters.
Mantid::Kernel::V3D getQLabFrame() const final
Return the Q change (of the lattice, k_i - k_f) for this peak.
LeanElasticPeak & operator=(LeanElasticPeak &&) noexcept=default
void setQLabFrame(const Mantid::Kernel::V3D &qLab, std::optional< double >=std::nullopt) override
Set the peak using the peak's position in reciprocal space, in the lab frame.
Structure describing a single-crystal peak.
Definition IPeak.h:26
Marks code as not implemented yet.
Definition Exception.h:138
The Logger class is in charge of the publishing messages from the framework through various channels.
Definition Logger.h:51
void information(const std::string &msg)
Logs at information level.
Definition Logger.cpp:136
Numerical Matrix class.
Definition Matrix.h:41
Class for 3D vectors.
Definition V3D.h:35
double norm() const noexcept
Definition V3D.h:270
static constexpr double NeutronMass
Mass of the neutron in kg.
static constexpr double h
Planck constant in J*s.
static constexpr double meV
1 meV in Joules.
Helper class which provides the Collimation Length for SANS instruments.