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 +
9
10#include <cmath>
11#include <stdexcept>
12
13namespace Mantid::Algorithms {
14
15//----------------------------------------------------------------------------
16// Weighting Implementations
17//----------------------------------------------------------------------------
18
23WeightingStrategy::WeightingStrategy(const double cutOff) : m_cutOff(cutOff) {}
24
27
28//----------------------------------------------------------------------------
29// Flat Weighting Implementations
30//----------------------------------------------------------------------------
31
36double FlatWeighting::weightAt(const double & /*adjX*/, const double & /*ix*/, const double & /*adjY*/,
37 const double & /*iy*/) {
38 return 1;
39}
40
45double FlatWeighting::weightAt(const Mantid::Kernel::V3D & /*distance*/) { return 1; }
46
47//----------------------------------------------------------------------------
48// Linear Weighting Implementations
49//----------------------------------------------------------------------------
50
55LinearWeighting::LinearWeighting(const double cutOff) : WeightingStrategy(cutOff) {}
56
63double LinearWeighting::weightAt(const Mantid::Kernel::V3D &distance) { return 1 - (distance.norm() / m_cutOff); }
64
73double LinearWeighting::weightAt(const double &adjX, const double &ix, const double &adjY, const double &iy) {
74 return 1 - (std::sqrt(ix * ix + iy * iy) / std::sqrt(adjX * adjX + adjY * adjY));
75}
76
77//----------------------------------------------------------------------------
78// Parabolic Weighting Implementations
79//----------------------------------------------------------------------------
80
85
92 return static_cast<double>(m_cutOff - std::abs(distance.X()) + m_cutOff - std::abs(distance.Y()) + 1);
93}
94
103double ParabolicWeighting::weightAt(const double &adjX, const double &ix, const double &adjY, const double &iy) {
104 return static_cast<double>(adjX - std::abs(ix) + adjY - std::abs(iy) + 1);
105}
106
107//----------------------------------------------------------------------------
108// Null Weighting Implementations
109//----------------------------------------------------------------------------
110
115double NullWeighting::weightAt(const Mantid::Kernel::V3D & /*distance*/) {
116 throw std::runtime_error("NullWeighting strategy cannot be used to evaluate weights.");
117}
118
123double NullWeighting::weightAt(const double & /*adjX*/, const double & /*ix*/, const double & /*adjY*/,
124 const double & /*iy*/) {
125 throw std::runtime_error("NullWeighting strategy cannot be used to evaluate weights.");
126}
127
128//-------------------------------------------------------------------------
129// Gaussian 2D Weighting Implementations
130//-------------------------------------------------------------------------
131
138 if (cutOff < 0) {
139 throw std::invalid_argument("GassianWeighting 1D expects unsigned cutOff input");
140 }
141 if (sigma < 0) {
142 throw std::invalid_argument("GassianWeighting 1D expects unsigned standard deviation input");
143 }
144
146}
147
155 /*
156 distance.norm() = r
157 r/R provides normalisation
158 */
159 double normalisedDistance = distance.norm() / m_cutOff; // Ensures 1 at the edges and zero in the
160 // center no matter what the units are
161 return calculateGaussian(normalisedDistance * normalisedDistance);
162}
163
172double GaussianWeightingnD::weightAt(const double &adjX, const double &ix, const double &adjY, const double &iy) {
173 double normalisedDistanceSq = (ix * ix + iy * iy) / (adjX * adjX + adjY * adjY);
174 return calculateGaussian(normalisedDistanceSq);
175}
176
183inline double GaussianWeightingnD::calculateGaussian(const double normalisedDistanceSq) {
184 return std::exp(-normalisedDistanceSq / m_twiceSigmaSquared);
185}
186
187} // 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:232
constexpr double Y() const noexcept
Get y.
Definition: V3D.h:233
double norm() const noexcept
Definition: V3D.h:263