Mantid
Loading...
Searching...
No Matches
WeightingStrategy.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 +
8
9#include <cmath>
10#include <stdexcept>
11
12namespace Mantid::Algorithms {
13
14//----------------------------------------------------------------------------
15// Weighting Implementations
16//----------------------------------------------------------------------------
17
22WeightingStrategy::WeightingStrategy(const double cutOff) : m_cutOff(cutOff) {}
23
26
27//----------------------------------------------------------------------------
28// Flat Weighting Implementations
29//----------------------------------------------------------------------------
30
35double FlatWeighting::weightAt(const double & /*adjX*/, const double & /*ix*/, const double & /*adjY*/,
36 const double & /*iy*/) {
37 return 1;
38}
39
44double FlatWeighting::weightAt(const Mantid::Kernel::V3D & /*distance*/) { return 1; }
45
46//----------------------------------------------------------------------------
47// Linear Weighting Implementations
48//----------------------------------------------------------------------------
49
54LinearWeighting::LinearWeighting(const double cutOff) : WeightingStrategy(cutOff) {}
55
62double LinearWeighting::weightAt(const Mantid::Kernel::V3D &distance) { return 1 - (distance.norm() / m_cutOff); }
63
72double LinearWeighting::weightAt(const double &adjX, const double &ix, const double &adjY, const double &iy) {
73 return 1 - (std::sqrt(ix * ix + iy * iy) / std::sqrt(adjX * adjX + adjY * adjY));
74}
75
76//----------------------------------------------------------------------------
77// Parabolic Weighting Implementations
78//----------------------------------------------------------------------------
79
84
91 return static_cast<double>(m_cutOff - std::abs(distance.X()) + m_cutOff - std::abs(distance.Y()) + 1);
92}
93
102double ParabolicWeighting::weightAt(const double &adjX, const double &ix, const double &adjY, const double &iy) {
103 return static_cast<double>(adjX - std::abs(ix) + adjY - std::abs(iy) + 1);
104}
105
106//----------------------------------------------------------------------------
107// Null Weighting Implementations
108//----------------------------------------------------------------------------
109
114double NullWeighting::weightAt(const Mantid::Kernel::V3D & /*distance*/) {
115 throw std::runtime_error("NullWeighting strategy cannot be used to evaluate weights.");
116}
117
122double NullWeighting::weightAt(const double & /*adjX*/, const double & /*ix*/, const double & /*adjY*/,
123 const double & /*iy*/) {
124 throw std::runtime_error("NullWeighting strategy cannot be used to evaluate weights.");
125}
126
127//-------------------------------------------------------------------------
128// Gaussian 2D Weighting Implementations
129//-------------------------------------------------------------------------
130
137 if (cutOff < 0) {
138 throw std::invalid_argument("GassianWeighting 1D expects unsigned cutOff input");
139 }
140 if (sigma < 0) {
141 throw std::invalid_argument("GassianWeighting 1D expects unsigned standard deviation input");
142 }
143
145}
146
154 /*
155 distance.norm() = r
156 r/R provides normalisation
157 */
158 double normalisedDistance = distance.norm() / m_cutOff; // Ensures 1 at the edges and zero in the
159 // center no matter what the units are
160 return calculateGaussian(normalisedDistance * normalisedDistance);
161}
162
171double GaussianWeightingnD::weightAt(const double &adjX, const double &ix, const double &adjY, const double &iy) {
172 double normalisedDistanceSq = (ix * ix + iy * iy) / (adjX * adjX + adjY * adjY);
173 return calculateGaussian(normalisedDistanceSq);
174}
175
182inline double GaussianWeightingnD::calculateGaussian(const double normalisedDistanceSq) {
183 return std::exp(-normalisedDistanceSq / m_twiceSigmaSquared);
184}
185
186} // namespace Mantid::Algorithms
double sigma
Definition GetAllEi.cpp:156
double weightAt(const double &, const double &, const double &, const double &) override
Calculate the weight at distance from epicenter.
double calculateGaussian(const double normalisedDistanceSq)
calculateGaussian method so that same gaussian calculation can be run by different consuming methods.
double weightAt(const Mantid::Kernel::V3D &) override
Calculate the weight at distance from epicenter.
GaussianWeightingnD(double cutOff, double sigma)
Constructor.
double weightAt(const Mantid::Kernel::V3D &) override
Calculate the weight at distance from epicenter.
LinearWeighting(const double cutOff)
Constructor.
double weightAt(const Mantid::Kernel::V3D &) override
Calculate the weight at distance from epicenter.
ParabolicWeighting(const double cutOff)
Constructor.
double weightAt(const Mantid::Kernel::V3D &) override
Implementation doesn't make sense on this type.
Class for 3D vectors.
Definition V3D.h:34
constexpr double X() const noexcept
Get x.
Definition V3D.h:238
constexpr double Y() const noexcept
Get y.
Definition V3D.h:239
double norm() const noexcept
Definition V3D.h:269