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 +
13
14#include "boost/make_shared.hpp"
15
16#include <algorithm>
17#include <cctype>
18#include <string>
19#include <utility>
20
21using namespace Mantid;
22using namespace Mantid::Kernel;
23using namespace Mantid::Geometry;
24
25namespace Mantid::DataObjects {
26
27//----------------------------------------------------------------------------------------------
29LeanElasticPeak::LeanElasticPeak() : BasePeak(), m_Qsample(V3D(0, 0, 0)), m_wavelength(0.) {}
30
31//----------------------------------------------------------------------------------------------
40 : BasePeak(), m_Qsample(QSampleFrame), m_wavelength(0.) {}
41
42//----------------------------------------------------------------------------------------------
51 const Mantid::Kernel::Matrix<double> &goniometer,
52 boost::optional<std::shared_ptr<const Geometry::ReferenceFrame>> refFrame)
53 : BasePeak() {
54 if (refFrame.is_initialized())
55 setReferenceFrame(refFrame.get());
56 setQSampleFrame(QSampleFrame, goniometer);
57}
58
59//----------------------------------------------------------------------------------------------
68LeanElasticPeak::LeanElasticPeak(const Mantid::Kernel::V3D &QSampleFrame, double wavelength)
69 : BasePeak(), m_Qsample(QSampleFrame), m_wavelength(wavelength) {}
70
76
77//----------------------------------------------------------------------------------------------
83 : BasePeak(ipeak), m_Qsample(ipeak.getQSampleFrame()), m_wavelength(ipeak.getWavelength()) {}
84
85//----------------------------------------------------------------------------------------------
90void LeanElasticPeak::setWavelength(double wavelength) { m_wavelength = wavelength; }
91
93std::shared_ptr<const Geometry::ReferenceFrame> LeanElasticPeak::getReferenceFrame() const {
94 return (m_refFrame) ? m_refFrame : std::make_shared<const ReferenceFrame>();
95}
96
101void LeanElasticPeak::setReferenceFrame(std::shared_ptr<const ReferenceFrame> frame) { m_refFrame = std::move(frame); }
102
103// -------------------------------------------------------------------------------------
106
107// -------------------------------------------------------------------------------------
112 throw Exception::NotImplementedError("LeanElasticPeak::getTOF(): no detector infomation in LeanElasticPeak");
113}
114
117 throw Exception::NotImplementedError("LeanElasticPeak::getRow(): no detector infomation in LeanElasticPeak");
118}
119
122 throw Exception::NotImplementedError("LeanElasticPeak::getCol(): no detector infomation in LeanElasticPeak");
123}
124
125// -------------------------------------------------------------------------------------
127double LeanElasticPeak::getScattering() const { return asin(getWavelength() / (2 * getDSpacing())) * 2; }
128
129// -------------------------------------------------------------------------------------
132 const V3D qLab = getQLabFrame();
133 std::shared_ptr<const ReferenceFrame> refFrame = getReferenceFrame();
134 const double qSign = (m_convention != "Crystallography") ? 1.0 : -1.0;
135 const V3D detectorDir = -qLab * qSign;
136 if (refFrame)
137 return atan2(detectorDir[refFrame->pointingUp()], detectorDir[refFrame->pointingHorizontal()]);
138 else
139 return atan2(detectorDir[1], detectorDir[0]);
140}
141
142// -------------------------------------------------------------------------------------
144double LeanElasticPeak::getDSpacing() const { return 2 * M_PI / m_Qsample.norm(); }
145
146//----------------------------------------------------------------------------------------------
153
154//----------------------------------------------------------------------------------------------
158
159//----------------------------------------------------------------------------------------------
167void LeanElasticPeak::setQSampleFrame(const Mantid::Kernel::V3D &QSampleFrame, boost::optional<double>) {
168 m_Qsample = QSampleFrame;
169}
170
172 const Mantid::Kernel::Matrix<double> &goniometer) {
173 m_Qsample = QSampleFrame;
174 setGoniometerMatrix(goniometer);
175
176 const V3D qLab = getQLabFrame();
177
178 try {
179 double wl = calculateWavelengthFromQLab(qLab);
180 setWavelength(wl);
181 } catch (std::exception &e) {
182 g_log.information() << "Unable to automatically determine wavelength from q-lab\n"
183 << e.what() << ", goniometer is likely not correct\n";
184 }
185}
186
187//----------------------------------------------------------------------------------------------
196void LeanElasticPeak::setQLabFrame(const Mantid::Kernel::V3D &qLab, boost::optional<double>) {
198}
199
200//----------------------------------------------------------------------------------------------
203 // Velocity of the neutron (non-relativistic)
204 const double velocity = PhysicalConstants::h / (m_wavelength * 1e-10 * PhysicalConstants::NeutronMass);
205 // Energy in J of the neutron
206 const double energy = PhysicalConstants::NeutronMass * velocity * velocity / 2.0;
207 // Convert to meV
209}
210
213
216double LeanElasticPeak::getEnergyTransfer() const { return 0.; }
217
220 throw Exception::NotImplementedError("Use LeanElasticPeak::setWavelength");
221}
222
225 throw Exception::NotImplementedError("Use LeanElasticPeak::setWavelength");
226}
227
228// -------------------------------------------------------------------------------------
231 throw Exception::NotImplementedError("LeanElasticPeak has no detector information");
232}
233
234// -------------------------------------------------------------------------------------
237 throw Exception::NotImplementedError("LeanElasticPeak has no detector information");
238}
239
246 if (&other != this) {
247 BasePeak::operator=(other);
248 m_Qsample = other.m_Qsample;
249 m_wavelength = other.m_wavelength;
250 }
251 return *this;
252}
253
255
256} // 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:342
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.
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.
void setWavelength(double wavelength) override
Set the wavelength of the neutron.
void setFinalEnergy(double m_finalEnergy) override
Set the final energy.
void setQLabFrame(const Mantid::Kernel::V3D &qLab, boost::optional< double >=boost::none) override
Set the peak using the peak's position in reciprocal space, in the lab frame.
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.
double getFinalEnergy() const override
Get the final neutron energy in meV.
Mantid::Kernel::V3D getQLabFrame() const override
Return the Q change (of the lattice, k_i - k_f) for this peak.
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.
void setQSampleFrame(const Mantid::Kernel::V3D &QSampleFrame, boost::optional< double >=boost::none) override
Set the peak using the peak's position in reciprocal space, in the sample frame.
double getL2() const override
Return the L2 flight path length (sample to detector), in meters.
LeanElasticPeak & operator=(LeanElasticPeak &&) noexcept=default
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:52
void information(const std::string &msg)
Logs at information level.
Definition: Logger.cpp:105
Numerical Matrix class.
Definition: Matrix.h:42
Class for 3D vectors.
Definition: V3D.h:34
double norm() const noexcept
Definition: V3D.h:263
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.