Mantid
Loading...
Searching...
No Matches
WorkspaceBoundingBox.cpp
Go to the documentation of this file.
3
4namespace Mantid::Algorithms {
5
6namespace {
7constexpr int HISTOGRAM_INDEX{0};
8}
9
11 if (m_workspace->y(0).size() != 1)
12 throw std::runtime_error("This object only works with integrated workspaces");
13
14 m_spectrumInfo = &workspace->spectrumInfo();
15}
16
18 m_spectrumInfo = nullptr; // certain functionality is not available
19}
20
22
25 if (!m_spectrumInfo)
26 throw std::runtime_error("SpectrumInfo object is not initialized");
27
30 }
31 return m_cachedPosition;
32}
33
34double WorkspaceBoundingBox::yValue(const int index) const {
36 m_cachedYValue = m_workspace->y(index)[HISTOGRAM_INDEX];
38 }
39 return m_cachedYValue;
40}
41
43 this->x = x;
44 this->y = y;
45}
46
47void WorkspaceBoundingBox::setCenter(double x, double y) {
48 this->centerX = x;
49 this->centerY = y;
50}
51
52void WorkspaceBoundingBox::setBounds(double xMin, double xMax, double yMin, double yMax) {
53 this->xMin = xMin;
54 this->xMax = xMax;
55 this->yMin = yMin;
56 this->yMax = yMax;
57}
58
66 if (!m_spectrumInfo)
67 throw std::runtime_error("SpectrumInfo object is not initialized");
69 g_log.warning() << "Workspace index " << index << " has no detector assigned to it - discarding\n";
70 return false;
71 }
72 // Skip if we have a monitor or if the detector is masked.
73 if (this->m_spectrumInfo->isMonitor(index) || this->m_spectrumInfo->isMasked(index))
74 return false;
75
76 // Get the current spectrum
77 const auto YIn = this->yValue(index);
78 // Skip if NaN of inf
79 if (std::isnan(YIn) || std::isinf(YIn))
80 return false;
81 return true;
82}
83
89int WorkspaceBoundingBox::findFirstValidWs(const int numSpec) const {
90 int i;
91 for (i = 0; i < numSpec; ++i) {
92 if (isValidWs(i))
93 break;
94 }
95 return i;
96}
97
105 const auto YIn = this->yValue(index);
106 const auto &position = this->position(index);
107
108 this->x += YIn * position.X();
109 this->y += YIn * position.Y();
110
111 return YIn;
112}
113
120 const auto &position = this->position(index);
121 const double x = position.X();
122 const double y = position.Y();
123
124 this->xMin = std::min(x, this->xMin);
125 this->xMax = std::max(x, this->xMax);
126 this->yMin = std::min(y, this->yMin);
127 this->yMax = std::max(y, this->yMax);
128}
129
137bool WorkspaceBoundingBox::isOutOfBoundsOfNonDirectBeam(const double beamRadius, int index, const bool directBeam) {
138 if (!directBeam) {
139 const auto &position = this->position(index);
140 const double dx = position.X() - this->centerX;
141 const double dy = position.Y() - this->centerY;
142 if (dx * dx + dy * dy < beamRadius * beamRadius)
143 return false;
144 }
145 return true;
146}
147
149 const auto xExtent = (centerX - x);
150 const auto yExtent = (centerY - y);
151 return sqrt(xExtent * xExtent + yExtent * yExtent);
152}
153
154double WorkspaceBoundingBox::calculateRadiusX() const { return std::min((x - xMin), (xMax - x)); }
155
156double WorkspaceBoundingBox::calculateRadiusY() const { return std::min((y - yMin), (yMax - y)); }
157
164 this->x /= std::fabs(x);
165 this->y /= std::fabs(y);
166}
167
175 return (x <= this->xMax && x >= this->xMin && y <= yMax && y >= yMin);
176}
177
178} // namespace Mantid::Algorithms
double position
Definition: GetAllEi.cpp:154
IPeaksWorkspace_sptr workspace
Definition: IndexPeaks.cpp:114
std::map< DeltaEMode::Type, std::string > index
Definition: DeltaEMode.cpp:19
bool isMonitor(const size_t index) const
Returns true if the detector(s) associated with the spectrum are monitors.
bool hasDetectors(const size_t index) const
Returns true if the spectrum is associated with detectors in the instrument.
Kernel::V3D position(const size_t index) const
Returns the position of the spectrum with given index.
bool isValidWs(int index) const
Performs checks on the spectrum located at index to determine if it is acceptable to be operated on.
API::MatrixWorkspace_const_sptr m_workspace
void updateMinMax(int index)
Compare current mins and maxs to the coordinates of the spectrum at index expnd mins and maxs to incl...
bool isOutOfBoundsOfNonDirectBeam(const double beamRadius, int index, const bool directBeam)
Checks to see if spectrum at index is within the diameter of the given beamRadius.
void setBounds(double xMin, double xMax, double yMin, double yMax)
void normalizePosition(double x, double y)
Perform normalization on x/y coords over given values.
double updatePositionAndReturnCount(int index)
Sets member variables x/y to new x/y based on spectrum info and historgram data at the given index.
bool containsPoint(double x, double y)
Checks if a given x/y coord is within the bounding box.
int findFirstValidWs(const int numSpec) const
Searches for the first valid spectrum info in member variable workspace
void warning(const std::string &msg)
Logs at warning level.
Definition: Logger.cpp:86
Class for 3D vectors.
Definition: V3D.h:34
Kernel::Logger g_log("ExperimentInfo")
static logger object
std::shared_ptr< const MatrixWorkspace > MatrixWorkspace_const_sptr
shared pointer to the matrix workspace base class (const version)