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 +
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//----------------------------------------------------------------------------------------------
31 : m_convention(Kernel::ConfigService::Instance().getString("Q.convention")), m_samplePos(V3D(0, 0, 0)), m_H(0),
32 m_K(0), m_L(0), m_intensity(0), m_sigmaIntensity(0), m_binCount(0), m_absorptionWeightedPathLength(0),
33 m_GoniometerMatrix(3, 3, true), m_InverseGoniometerMatrix(3, 3, true), m_runNumber(0), m_monitorCount(0),
34 m_peakNumber(0), m_intHKL(V3D(0, 0, 0)), m_intMNP(V3D(0, 0, 0)), m_peakShape(std::make_shared<NoShape>()) {}
35
36//----------------------------------------------------------------------------------------------
42 : m_convention(Kernel::ConfigService::Instance().getString("Q.convention")), m_H(0), m_K(0), m_L(0), m_intensity(0),
43 m_sigmaIntensity(0), m_binCount(0), m_absorptionWeightedPathLength(0), m_GoniometerMatrix(goniometer),
44 m_InverseGoniometerMatrix(goniometer), m_runNumber(0), m_monitorCount(0), m_peakNumber(0), m_intHKL(V3D(0, 0, 0)),
45 m_intMNP(V3D(0, 0, 0)), m_peakShape(std::make_shared<NoShape>()) {
47 throw std::invalid_argument("BasePeak::ctor(): Goniometer matrix must non-singular.");
48}
49
51 : 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),
52 m_intensity(other.m_intensity), m_sigmaIntensity(other.m_sigmaIntensity), m_binCount(other.m_binCount),
53 m_absorptionWeightedPathLength(other.m_absorptionWeightedPathLength),
54 m_GoniometerMatrix(other.m_GoniometerMatrix), m_InverseGoniometerMatrix(other.m_InverseGoniometerMatrix),
55 m_runNumber(other.m_runNumber), m_monitorCount(other.m_monitorCount), m_peakNumber(other.m_peakNumber),
56 m_intHKL(other.m_intHKL), m_intMNP(other.m_intMNP), m_peakShape(other.m_peakShape->clone()) {}
57
58//----------------------------------------------------------------------------------------------
64 : IPeak(ipeak), m_convention(Kernel::ConfigService::Instance().getString("Q.convention")), m_H(ipeak.getH()),
65 m_K(ipeak.getK()), m_L(ipeak.getL()), m_intensity(ipeak.getIntensity()),
66 m_sigmaIntensity(ipeak.getSigmaIntensity()), m_binCount(ipeak.getBinCount()),
67 m_absorptionWeightedPathLength(ipeak.getAbsorptionWeightedPathLength()),
68 m_GoniometerMatrix(ipeak.getGoniometerMatrix()), m_InverseGoniometerMatrix(ipeak.getGoniometerMatrix()),
69 m_runNumber(ipeak.getRunNumber()), m_monitorCount(ipeak.getMonitorCount()), m_peakNumber(ipeak.getPeakNumber()),
70 m_intHKL(ipeak.getIntHKL()), m_intMNP(ipeak.getIntMNP()), m_peakShape(std::make_shared<NoShape>()) {
72 throw std::invalid_argument("Peak::ctor(): Goniometer matrix must non-singular.");
73}
74
75//----------------------------------------------------------------------------------------------
77int BasePeak::getRunNumber() const { return m_runNumber; }
78
81void BasePeak::setRunNumber(int m_runNumber) { this->m_runNumber = m_runNumber; }
82
83//----------------------------------------------------------------------------------------------
85double BasePeak::getMonitorCount() const { return m_monitorCount; }
86
89void BasePeak::setMonitorCount(double m_monitorCount) { this->m_monitorCount = m_monitorCount; }
90
91//----------------------------------------------------------------------------------------------
93double BasePeak::getH() const { return m_H; }
94
96double BasePeak::getK() const { return m_K; }
97
99double BasePeak::getL() const { return m_L; }
100
103
106 if (m_H == 0. && m_K == 0. && m_L == 0.)
107 return false;
108 return true;
109}
110
113
116
117//----------------------------------------------------------------------------------------------
120void BasePeak::setH(double m_H) { this->m_H = m_H; }
121
124void BasePeak::setK(double m_K) { this->m_K = m_K; }
125
128void BasePeak::setL(double m_L) { this->m_L = m_L; }
129
131void BasePeak::setHKL(double H, double K, double L) {
132 m_H = H;
133 m_K = K;
134 m_L = L;
135}
136
141void BasePeak::setHKL(const Mantid::Kernel::V3D &HKL) { this->setHKL(HKL.X(), HKL.Y(), HKL.Z()); }
142
147void BasePeak::setIntHKL(const V3D &HKL) { m_intHKL = V3D(std::round(HKL[0]), std::round(HKL[1]), std::round(HKL[2])); }
148
152void BasePeak::setIntMNP(const V3D &MNP) { m_intMNP = V3D(std::round(MNP[0]), std::round(MNP[1]), std::round(MNP[2])); }
153
156
161void BasePeak::setSamplePos(double samX, double samY, double samZ) {
162
163 this->m_samplePos[0] = samX;
164 this->m_samplePos[1] = samY;
165 this->m_samplePos[2] = samZ;
166}
167
173
174 this->m_samplePos[0] = XYZ[0];
175 this->m_samplePos[1] = XYZ[1];
176 this->m_samplePos[2] = XYZ[2];
177}
178
179//----------------------------------------------------------------------------------------------
181double BasePeak::getBinCount() const { return m_binCount; }
182
184double BasePeak::getIntensity() const { return m_intensity; }
185
188
191 const auto result = m_intensity / m_sigmaIntensity;
192 return (std::isfinite(result)) ? result : 0.0;
193}
194
197void BasePeak::setIntensity(double m_intensity) { this->m_intensity = m_intensity; }
198
201void BasePeak::setBinCount(double m_binCount) { this->m_binCount = m_binCount; }
202
205void BasePeak::setSigmaIntensity(double m_sigmaIntensity) { this->m_sigmaIntensity = m_sigmaIntensity; }
206
207// -------------------------------------------------------------------------------------
210
211// -------------------------------------------------------------------------------------
214
220 if ((goniometerMatrix.numCols() != 3) || (goniometerMatrix.numRows() != 3))
221 throw std::invalid_argument("BasePeak::setGoniometerMatrix(): Goniometer matrix must be 3x3.");
222 this->m_GoniometerMatrix = goniometerMatrix;
223 // Calc the inverse rotation matrix
226 throw std::invalid_argument("BasePeak::setGoniometerMatrix(): Goniometer "
227 "matrix must be non-singular.");
228}
229
230// -------------------------------------------------------------------------------------
234
235// -------------------------------------------------------------------------------------
238void BasePeak::setPeakNumber(int m_peakNumber) { this->m_peakNumber = m_peakNumber; }
239
240// -------------------------------------------------------------------------------------
249double BasePeak::getValueByColName(std::string name) const {
250 std::transform(name.begin(), name.end(), name.begin(), ::tolower);
251 if (name == "runnumber")
252 return double(this->getRunNumber());
253 else if (name == "h")
254 return this->getH();
255 else if (name == "k")
256 return this->getK();
257 else if (name == "l")
258 return this->getL();
259 else if (name == "wavelength")
260 return this->getWavelength();
261 else if (name == "energy")
262 return this->getInitialEnergy();
263 else if (name == "tof")
264 return this->getTOF();
265 else if (name == "dspacing")
266 return this->getDSpacing();
267 else if (name == "intens")
268 return this->getIntensity();
269 else if (name == "sigint")
270 return this->getSigmaIntensity();
271 else if (name == "intens/sigint")
272 return this->getIntensityOverSigma();
273 else if (name == "bincount")
274 return this->getBinCount();
275 else if (name == "peaknumber")
276 return double(this->getPeakNumber());
277 else if (name == "tbar")
278 return this->getAbsorptionWeightedPathLength();
279 else if (name == "qlab")
280 return this->getQLabFrame().norm2();
281 else if (name == "qsample")
282 return this->getQSampleFrame().norm2();
283 else if (name == "inthkl")
284 return this->getIntHKL().norm2();
285 else if (name == "intmnp")
286 return this->getIntMNP().norm2();
287 else
288 throw std::runtime_error("BasePeak::getValueByColName() unknown column or "
289 "column is not a number: " +
290 name);
291}
292
297const PeakShape &BasePeak::getPeakShape() const { return *this->m_peakShape; }
298
304
310
317 if (&other != this) {
318 m_H = other.m_H;
319 m_K = other.m_K;
320 m_L = other.m_L;
321 m_intensity = other.m_intensity;
322 m_sigmaIntensity = other.m_sigmaIntensity;
323 m_binCount = other.m_binCount;
324 m_GoniometerMatrix = other.m_GoniometerMatrix;
325 m_InverseGoniometerMatrix = other.m_InverseGoniometerMatrix;
326 m_runNumber = other.m_runNumber;
327 m_monitorCount = other.m_monitorCount;
328 m_peakNumber = other.m_peakNumber;
329 m_intHKL = other.m_intHKL;
330 m_intMNP = other.m_intMNP;
331 m_peakShape.reset(other.m_peakShape->clone());
332 m_absorptionWeightedPathLength = other.m_absorptionWeightedPathLength;
333 m_convention = other.m_convention;
334 }
335 return *this;
336}
337
343
348
350 /* The q-vector direction of the peak is = goniometer * ub * hkl_vector
351 * The incident neutron wavevector is along the beam direction, ki = 1/wl
352 * (usually z, but referenceframe is definitive).
353 * In the inelastic convention, q = ki - kf.
354 * The final neutron wavector kf = -qx in x; -qy in y; and (-q.beam_dir+1/wl)
355 * in beam direction.
356 * AND: norm(kf) = norm(ki) = 2*pi/wavelength
357 * THEREFORE: 1/wl = norm(q)^2 / (2*q.beam_dir)
358 */
359 const double norm_q = qLab.norm();
360 if (norm_q == 0.0)
361 throw std::invalid_argument("BasePeak::setQLabFrame(): Q cannot be 0,0,0.");
362
363 std::shared_ptr<const ReferenceFrame> refFrame = getReferenceFrame();
364 V3D refBeamDir(0, 0, 1); // default beam direction +Z
365 if (refFrame)
366 refBeamDir = refFrame->vecPointingAlongBeam();
367
368 // Default for ki-kf has -q
369 const double qSign = (m_convention != "Crystallography") ? 1.0 : -1.0;
370 const double qBeam = qLab.scalar_prod(refBeamDir) * qSign;
371
372 if (qBeam == 0.0)
373 throw std::invalid_argument("BasePeak::setQLabFrame(): Q cannot be 0 in the beam direction.");
374
375 const double one_over_wl = (norm_q * norm_q) / (2.0 * qBeam);
376 const double wl = (2.0 * M_PI) / one_over_wl;
377 if (wl < 0.0) {
378 std::ostringstream mess;
379 mess << "BasePeak::setQLabFrame(): Wavelength found was negative (" << wl << " Ang)! This Q is not physical.";
380 throw std::invalid_argument(mess.str());
381 }
382
383 return wl;
384}
385
387
388} // namespace Mantid::DataObjects
std::string name
Definition Run.cpp:60
#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:115
Mantid::Kernel::Matrix< double > getInverseGoniometerMatrix() const
Get the goniometer rotation matrix at which this peak was measured.
Definition BasePeak.cpp:213
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:105
void setSigmaIntensity(double m_sigmaIntensity) override
Set the error on the integrated peak intensity.
Definition BasePeak.cpp:205
double getL() const override
Get the L index of the peak.
Definition BasePeak.cpp:99
void setIntMNP(const Mantid::Kernel::V3D &MNP) override
Sets the modulated peak structure number.
Definition BasePeak.cpp:152
void setK(double m_K) override
Set the K index of this peak.
Definition BasePeak.cpp:124
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:81
BasePeak()
Default constructor.
Definition BasePeak.cpp:30
void setPeakNumber(int m_peakNumber) override
Sets the unique peak number.
Definition BasePeak.cpp:238
void setMonitorCount(double m_monitorCount) override
Set the monitor count for this peak.
Definition BasePeak.cpp:89
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:184
BasePeak & operator=(BasePeak &&) noexcept=default
Mantid::Kernel::V3D getSamplePos() const override
Return the sample position vector.
Definition BasePeak.cpp:155
double getAbsorptionWeightedPathLength() const override
Gets the absorption weighted path length.
Definition BasePeak.cpp:347
double getSigmaIntensity() const override
Return the error on the integrated peak intensity.
Definition BasePeak.cpp:187
double m_intensity
Integrated peak intensity.
Definition BasePeak.h:135
double getK() const override
Get the K index of the peak.
Definition BasePeak.cpp:96
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:233
void setPeakShape(Mantid::Geometry::PeakShape *shape) override
Set the PeakShape.
Definition BasePeak.cpp:303
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:120
int getRunNumber() const override
Return the run number this peak was measured at.
Definition BasePeak.cpp:77
double getH() const override
Get the H index of the peak.
Definition BasePeak.cpp:93
double calculateWavelengthFromQLab(const Mantid::Kernel::V3D &qLab)
Definition BasePeak.cpp:349
void setIntensity(double m_intensity) override
Set the integrated peak intensity.
Definition BasePeak.cpp:197
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:131
void setL(double m_L) override
Set the L index of this peak.
Definition BasePeak.cpp:128
double m_H
H of the peak.
Definition BasePeak.h:126
Mantid::Kernel::V3D getHKL() const override
Return the HKL vector.
Definition BasePeak.cpp:102
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:147
double getBinCount() const override
Return the # of counts in the bin at its peak.
Definition BasePeak.cpp:181
Mantid::Kernel::Matrix< double > getGoniometerMatrix() const override
Get the goniometer rotation matrix at which this peak was measured.
Definition BasePeak.cpp:209
const Mantid::Geometry::PeakShape & getPeakShape() const override
Get the peak shape.
Definition BasePeak.cpp:297
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:190
double getMonitorCount() const override
Return the monitor count stored in this peak.
Definition BasePeak.cpp:85
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:112
virtual double getValueByColName(std::string colName) const
Helper function for displaying/sorting peaks.
Definition BasePeak.cpp:249
void setAbsorptionWeightedPathLength(double pathLength) override
Set the absorption weighted path length.
Definition BasePeak.cpp:342
void setSamplePos(double samX, double samY, double samZ) override
Set sample position.
Definition BasePeak.cpp:161
void setGoniometerMatrix(const Mantid::Kernel::Matrix< double > &goniometerMatrix) override
Set the goniometer rotation matrix at which this peak was measured.
Definition BasePeak.cpp:219
void setBinCount(double m_binCount) override
Set the # of counts in the bin at its peak.
Definition BasePeak.cpp:201
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:20
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
virtual Mantid::Kernel::V3D getQSampleFrame() const =0
virtual Mantid::Kernel::V3D getQLabFrame() 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:51
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
Class for 3D vectors.
Definition V3D.h:34
constexpr double scalar_prod(const V3D &v) const noexcept
Calculates the cross product.
Definition V3D.h:280
constexpr double X() const noexcept
Get x.
Definition V3D.h:238
double norm() const noexcept
Definition V3D.h:269
constexpr double norm2() const noexcept
Vector length squared.
Definition V3D.h:271
std::shared_ptr< const PeakShape > PeakShape_const_sptr
Definition PeakShape.h:43
Mantid::Kernel::SingletonHolder< ConfigServiceImpl > ConfigService
Helper class which provides the Collimation Length for SANS instruments.
STL namespace.