Mantid
Loading...
Searching...
No Matches
BasePeak.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 +
15
16#include "boost/make_shared.hpp"
17
18#include <algorithm>
19#include <cctype>
20#include <string>
21#include <utility>
22
23using namespace Mantid;
24using namespace Mantid::Kernel;
25using namespace Mantid::Geometry;
26
27namespace Mantid::DataObjects {
28
29//----------------------------------------------------------------------------------------------
32 : m_convention(Kernel::ConfigService::Instance().getString("Q.convention")), m_samplePos(V3D(0, 0, 0)), m_H(0),
33 m_K(0), m_L(0), m_intensity(0), m_sigmaIntensity(0), m_binCount(0), m_absorptionWeightedPathLength(0),
34 m_GoniometerMatrix(3, 3, true), m_InverseGoniometerMatrix(3, 3, true), m_runNumber(0), m_monitorCount(0),
35 m_peakNumber(0), m_intHKL(V3D(0, 0, 0)), m_intMNP(V3D(0, 0, 0)), m_peakShape(std::make_shared<NoShape>()) {}
36
37//----------------------------------------------------------------------------------------------
43 : m_convention(Kernel::ConfigService::Instance().getString("Q.convention")), m_H(0), m_K(0), m_L(0), m_intensity(0),
44 m_sigmaIntensity(0), m_binCount(0), m_absorptionWeightedPathLength(0), m_GoniometerMatrix(goniometer),
45 m_InverseGoniometerMatrix(goniometer), m_runNumber(0), m_monitorCount(0), m_peakNumber(0), m_intHKL(V3D(0, 0, 0)),
46 m_intMNP(V3D(0, 0, 0)), m_peakShape(std::make_shared<NoShape>()) {
48 throw std::invalid_argument("BasePeak::ctor(): Goniometer matrix must non-singular.");
49}
50
52 : m_convention(other.m_convention), m_samplePos(other.m_samplePos), m_H(other.m_H), m_K(other.m_K), m_L(other.m_L),
53 m_intensity(other.m_intensity), m_sigmaIntensity(other.m_sigmaIntensity), m_binCount(other.m_binCount),
54 m_absorptionWeightedPathLength(other.m_absorptionWeightedPathLength),
55 m_GoniometerMatrix(other.m_GoniometerMatrix), m_InverseGoniometerMatrix(other.m_InverseGoniometerMatrix),
56 m_runNumber(other.m_runNumber), m_monitorCount(other.m_monitorCount), m_peakNumber(other.m_peakNumber),
57 m_intHKL(other.m_intHKL), m_intMNP(other.m_intMNP), m_peakShape(other.m_peakShape->clone()) {}
58
59//----------------------------------------------------------------------------------------------
65 : IPeak(ipeak), m_convention(Kernel::ConfigService::Instance().getString("Q.convention")), m_H(ipeak.getH()),
66 m_K(ipeak.getK()), m_L(ipeak.getL()), m_intensity(ipeak.getIntensity()),
67 m_sigmaIntensity(ipeak.getSigmaIntensity()), m_binCount(ipeak.getBinCount()),
68 m_absorptionWeightedPathLength(ipeak.getAbsorptionWeightedPathLength()),
69 m_GoniometerMatrix(ipeak.getGoniometerMatrix()), m_InverseGoniometerMatrix(ipeak.getGoniometerMatrix()),
70 m_runNumber(ipeak.getRunNumber()), m_monitorCount(ipeak.getMonitorCount()), m_peakNumber(ipeak.getPeakNumber()),
71 m_intHKL(ipeak.getIntHKL()), m_intMNP(ipeak.getIntMNP()), m_peakShape(std::make_shared<NoShape>()) {
73 throw std::invalid_argument("Peak::ctor(): Goniometer matrix must non-singular.");
74}
75
76//----------------------------------------------------------------------------------------------
78int BasePeak::getRunNumber() const { return m_runNumber; }
79
82void BasePeak::setRunNumber(int m_runNumber) { this->m_runNumber = m_runNumber; }
83
84//----------------------------------------------------------------------------------------------
86double BasePeak::getMonitorCount() const { return m_monitorCount; }
87
90void BasePeak::setMonitorCount(double m_monitorCount) { this->m_monitorCount = m_monitorCount; }
91
92//----------------------------------------------------------------------------------------------
94double BasePeak::getH() const { return m_H; }
95
97double BasePeak::getK() const { return m_K; }
98
100double BasePeak::getL() const { return m_L; }
101
104
107 if (m_H == 0. && m_K == 0. && m_L == 0.)
108 return false;
109 return true;
110}
111
114
117
118//----------------------------------------------------------------------------------------------
121void BasePeak::setH(double m_H) { this->m_H = m_H; }
122
125void BasePeak::setK(double m_K) { this->m_K = m_K; }
126
129void BasePeak::setL(double m_L) { this->m_L = m_L; }
130
132void BasePeak::setHKL(double H, double K, double L) {
133 m_H = H;
134 m_K = K;
135 m_L = L;
136}
137
142void BasePeak::setHKL(const Mantid::Kernel::V3D &HKL) { this->setHKL(HKL.X(), HKL.Y(), HKL.Z()); }
143
148void BasePeak::setIntHKL(const V3D &HKL) { m_intHKL = V3D(std::round(HKL[0]), std::round(HKL[1]), std::round(HKL[2])); }
149
153void BasePeak::setIntMNP(const V3D &MNP) { m_intMNP = V3D(std::round(MNP[0]), std::round(MNP[1]), std::round(MNP[2])); }
154
157
162void BasePeak::setSamplePos(double samX, double samY, double samZ) {
163
164 this->m_samplePos[0] = samX;
165 this->m_samplePos[1] = samY;
166 this->m_samplePos[2] = samZ;
167}
168
174
175 this->m_samplePos[0] = XYZ[0];
176 this->m_samplePos[1] = XYZ[1];
177 this->m_samplePos[2] = XYZ[2];
178}
179
180//----------------------------------------------------------------------------------------------
182double BasePeak::getBinCount() const { return m_binCount; }
183
185double BasePeak::getIntensity() const { return m_intensity; }
186
189
192 const auto result = m_intensity / m_sigmaIntensity;
193 return (std::isfinite(result)) ? result : 0.0;
194}
195
198void BasePeak::setIntensity(double m_intensity) { this->m_intensity = m_intensity; }
199
202void BasePeak::setBinCount(double m_binCount) { this->m_binCount = m_binCount; }
203
206void BasePeak::setSigmaIntensity(double m_sigmaIntensity) { this->m_sigmaIntensity = m_sigmaIntensity; }
207
208// -------------------------------------------------------------------------------------
211
212// -------------------------------------------------------------------------------------
215
221 if ((goniometerMatrix.numCols() != 3) || (goniometerMatrix.numRows() != 3))
222 throw std::invalid_argument("BasePeak::setGoniometerMatrix(): Goniometer matrix must be 3x3.");
223 this->m_GoniometerMatrix = goniometerMatrix;
224 // Calc the inverse rotation matrix
227 throw std::invalid_argument("BasePeak::setGoniometerMatrix(): Goniometer "
228 "matrix must be non-singular.");
229}
230
231// -------------------------------------------------------------------------------------
235
236// -------------------------------------------------------------------------------------
239void BasePeak::setPeakNumber(int m_peakNumber) { this->m_peakNumber = m_peakNumber; }
240
241// -------------------------------------------------------------------------------------
250double BasePeak::getValueByColName(std::string name) const {
251 std::transform(name.begin(), name.end(), name.begin(), ::tolower);
252 if (name == "runnumber")
253 return double(this->getRunNumber());
254 else if (name == "h")
255 return this->getH();
256 else if (name == "k")
257 return this->getK();
258 else if (name == "l")
259 return this->getL();
260 else if (name == "wavelength")
261 return this->getWavelength();
262 else if (name == "energy")
263 return this->getInitialEnergy();
264 else if (name == "tof")
265 return this->getTOF();
266 else if (name == "dspacing")
267 return this->getDSpacing();
268 else if (name == "intens")
269 return this->getIntensity();
270 else if (name == "sigint")
271 return this->getSigmaIntensity();
272 else if (name == "intens/sigint")
273 return this->getIntensityOverSigma();
274 else if (name == "bincount")
275 return this->getBinCount();
276 else if (name == "peaknumber")
277 return double(this->getPeakNumber());
278 else if (name == "tbar")
279 return this->getAbsorptionWeightedPathLength();
280 else
281 throw std::runtime_error("BasePeak::getValueByColName() unknown column or "
282 "column is not a number: " +
283 name);
284}
285
290const PeakShape &BasePeak::getPeakShape() const { return *this->m_peakShape; }
291
297
303
310 if (&other != this) {
311 m_H = other.m_H;
312 m_K = other.m_K;
313 m_L = other.m_L;
314 m_intensity = other.m_intensity;
315 m_sigmaIntensity = other.m_sigmaIntensity;
316 m_binCount = other.m_binCount;
317 m_GoniometerMatrix = other.m_GoniometerMatrix;
318 m_InverseGoniometerMatrix = other.m_InverseGoniometerMatrix;
319 m_runNumber = other.m_runNumber;
320 m_monitorCount = other.m_monitorCount;
321 m_peakNumber = other.m_peakNumber;
322 m_intHKL = other.m_intHKL;
323 m_intMNP = other.m_intMNP;
324 m_peakShape.reset(other.m_peakShape->clone());
325 m_absorptionWeightedPathLength = other.m_absorptionWeightedPathLength;
326 m_convention = other.m_convention;
327 }
328 return *this;
329}
330
336
341
343 /* The q-vector direction of the peak is = goniometer * ub * hkl_vector
344 * The incident neutron wavevector is along the beam direction, ki = 1/wl
345 * (usually z, but referenceframe is definitive).
346 * In the inelastic convention, q = ki - kf.
347 * The final neutron wavector kf = -qx in x; -qy in y; and (-q.beam_dir+1/wl)
348 * in beam direction.
349 * AND: norm(kf) = norm(ki) = 2*pi/wavelength
350 * THEREFORE: 1/wl = norm(q)^2 / (2*q.beam_dir)
351 */
352 const double norm_q = qLab.norm();
353 if (norm_q == 0.0)
354 throw std::invalid_argument("BasePeak::setQLabFrame(): Q cannot be 0,0,0.");
355
356 std::shared_ptr<const ReferenceFrame> refFrame = getReferenceFrame();
357 V3D refBeamDir(0, 0, 1); // default beam direction +Z
358 if (refFrame)
359 refBeamDir = refFrame->vecPointingAlongBeam();
360
361 // Default for ki-kf has -q
362 const double qSign = (m_convention != "Crystallography") ? 1.0 : -1.0;
363 const double qBeam = qLab.scalar_prod(refBeamDir) * qSign;
364
365 if (qBeam == 0.0)
366 throw std::invalid_argument("BasePeak::setQLabFrame(): Q cannot be 0 in the beam direction.");
367
368 const double one_over_wl = (norm_q * norm_q) / (2.0 * qBeam);
369 const double wl = (2.0 * M_PI) / one_over_wl;
370 if (wl < 0.0) {
371 std::ostringstream mess;
372 mess << "BasePeak::setQLabFrame(): Wavelength found was negative (" << wl << " Ang)! This Q is not physical.";
373 throw std::invalid_argument(mess.str());
374 }
375
376 return wl;
377}
378
380
381} // namespace Mantid::DataObjects
#define fabs(x)
Definition: Matrix.cpp:22
Structure describing a single-crystal peak.
Definition: BasePeak.h:33
Mantid::Kernel::V3D getIntMNP() const override
Return the int MNP vector.
Definition: BasePeak.cpp:116
Mantid::Kernel::Matrix< double > getInverseGoniometerMatrix() const
Get the goniometer rotation matrix at which this peak was measured.
Definition: BasePeak.cpp:214
int m_runNumber
Originating run number for this peak.
Definition: BasePeak.h:154
bool isIndexed() const override
Return True if the peak has been indexed.
Definition: BasePeak.cpp:106
void setSigmaIntensity(double m_sigmaIntensity) override
Set the error on the integrated peak intensity.
Definition: BasePeak.cpp:206
double getL() const override
Get the L index of the peak.
Definition: BasePeak.cpp:100
void setIntMNP(const Mantid::Kernel::V3D &MNP) override
Sets the modulated peak structure number.
Definition: BasePeak.cpp:153
void setK(double m_K) override
Set the K index of this peak.
Definition: BasePeak.cpp:125
Mantid::Kernel::Matrix< double > m_GoniometerMatrix
Orientation matrix of the goniometer angles.
Definition: BasePeak.h:147
void setRunNumber(int m_runNumber) override
Set the run number that measured this peak.
Definition: BasePeak.cpp:82
BasePeak()
Default constructor.
Definition: BasePeak.cpp:31
void setPeakNumber(int m_peakNumber) override
Sets the unique peak number.
Definition: BasePeak.cpp:239
void setMonitorCount(double m_monitorCount) override
Set the monitor count for this peak.
Definition: BasePeak.cpp:90
double m_absorptionWeightedPathLength
absorption weighted path length (aka t bar)
Definition: BasePeak.h:144
double getIntensity() const override
Return the integrated peak intensity.
Definition: BasePeak.cpp:185
BasePeak & operator=(BasePeak &&) noexcept=default
Mantid::Kernel::V3D getSamplePos() const override
Return the sample position vector.
Definition: BasePeak.cpp:156
double getAbsorptionWeightedPathLength() const override
Gets the absorption weighted path length.
Definition: BasePeak.cpp:340
double getSigmaIntensity() const override
Return the error on the integrated peak intensity.
Definition: BasePeak.cpp:188
double m_intensity
Integrated peak intensity.
Definition: BasePeak.h:135
double getK() const override
Get the K index of the peak.
Definition: BasePeak.cpp:97
static Mantid::Kernel::Logger g_log
Static logger.
Definition: BasePeak.h:167
int getPeakNumber() const override
Returns the unique peak number Returns -1 if it could not find it.
Definition: BasePeak.cpp:234
void setPeakShape(Mantid::Geometry::PeakShape *shape) override
Set the PeakShape.
Definition: BasePeak.cpp:296
double m_sigmaIntensity
Error (sigma) on peak intensity.
Definition: BasePeak.h:138
Mantid::Kernel::V3D m_samplePos
Cached sample position.
Definition: BasePeak.h:122
void setH(double m_H) override
Set the H index of this peak.
Definition: BasePeak.cpp:121
int getRunNumber() const override
Return the run number this peak was measured at.
Definition: BasePeak.cpp:78
double getH() const override
Get the H index of the peak.
Definition: BasePeak.cpp:94
double calculateWavelengthFromQLab(const Mantid::Kernel::V3D &qLab)
Definition: BasePeak.cpp:342
void setIntensity(double m_intensity) override
Set the integrated peak intensity.
Definition: BasePeak.cpp:198
double m_K
K of the peak.
Definition: BasePeak.h:129
void setHKL(double H, double K, double L) override
Set all three H,K,L indices of the peak.
Definition: BasePeak.cpp:132
void setL(double m_L) override
Set the L index of this peak.
Definition: BasePeak.cpp:129
double m_H
H of the peak.
Definition: BasePeak.h:126
Mantid::Kernel::V3D getHKL() const override
Return the HKL vector.
Definition: BasePeak.cpp:103
double m_binCount
Count in the bin at the peak.
Definition: BasePeak.h:141
Mantid::Kernel::Matrix< double > m_InverseGoniometerMatrix
Inverse of the goniometer rotation matrix; used to go from Q in lab frame to Q in sample frame.
Definition: BasePeak.h:151
Mantid::Kernel::V3D m_intHKL
Definition: BasePeak.h:160
void setIntHKL(const Kernel::V3D &HKL) override
Set int HKL.
Definition: BasePeak.cpp:148
double getBinCount() const override
Return the # of counts in the bin at its peak.
Definition: BasePeak.cpp:182
Mantid::Kernel::Matrix< double > getGoniometerMatrix() const override
Get the goniometer rotation matrix at which this peak was measured.
Definition: BasePeak.cpp:210
const Mantid::Geometry::PeakShape & getPeakShape() const override
Get the peak shape.
Definition: BasePeak.cpp:290
double m_L
L of the peak.
Definition: BasePeak.h:132
double getIntensityOverSigma() const override
Return the peak intensity divided by the error in the intensity.
Definition: BasePeak.cpp:191
double getMonitorCount() const override
Return the monitor count stored in this peak.
Definition: BasePeak.cpp:86
Mantid::Geometry::PeakShape_const_sptr m_peakShape
Peak shape.
Definition: BasePeak.h:164
Mantid::Kernel::V3D m_intMNP
Definition: BasePeak.h:161
Mantid::Kernel::V3D getIntHKL() const override
Return the int HKL vector.
Definition: BasePeak.cpp:113
virtual double getValueByColName(std::string colName) const
Helper function for displaying/sorting peaks.
Definition: BasePeak.cpp:250
void setAbsorptionWeightedPathLength(double pathLength) override
Set the absorption weighted path length.
Definition: BasePeak.cpp:335
void setSamplePos(double samX, double samY, double samZ) override
Set sample position.
Definition: BasePeak.cpp:162
void setGoniometerMatrix(const Mantid::Kernel::Matrix< double > &goniometerMatrix) override
Set the goniometer rotation matrix at which this peak was measured.
Definition: BasePeak.cpp:220
void setBinCount(double m_binCount) override
Set the # of counts in the bin at its peak.
Definition: BasePeak.cpp:202
double m_monitorCount
Integrated monitor count over TOF range for this run.
Definition: BasePeak.h:157
PeakShapeNone : No peak shape.
Definition: NoShape.h:17
HKL : HKL MDFrame.
Definition: HKL.h:21
Structure describing a single-crystal peak.
Definition: IPeak.h:26
virtual double getTOF() const =0
virtual double getWavelength() const =0
virtual double getDSpacing() const =0
virtual double getInitialEnergy() const =0
virtual std::shared_ptr< const Geometry::ReferenceFrame > getReferenceFrame() const =0
PeakShape : Abstract type to describes the shape of a peak.
Definition: PeakShape.h:20
The Logger class is in charge of the publishing messages from the framework through various channels.
Definition: Logger.h:52
Numerical Matrix class.
Definition: Matrix.h:42
T Invert()
LU inversion routine.
Definition: Matrix.cpp:924
size_t numRows() const
Return the number of rows in the matrix.
Definition: Matrix.h:144
size_t numCols() const
Return the number of columns in the matrix.
Definition: Matrix.h:147
Manage the lifetime of a class intended to be a singleton.
Class for 3D vectors.
Definition: V3D.h:34
constexpr double scalar_prod(const V3D &v) const noexcept
Calculates the cross product.
Definition: V3D.h:274
constexpr double X() const noexcept
Get x.
Definition: V3D.h:232
double norm() const noexcept
Definition: V3D.h:263
std::shared_ptr< const PeakShape > PeakShape_const_sptr
Definition: PeakShape.h:43
Helper class which provides the Collimation Length for SANS instruments.
STL namespace.