Mantid
Loading...
Searching...
No Matches
ComponentInfoBankHelpers.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2020 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#include "MantidBeamline/ComponentType.h"
12
13#include <algorithm>
14
15using Mantid::Beamline::ComponentType;
16
25bool isDetectorFixedInBank(const ComponentInfo &compInfo, const size_t detIndex) {
26 auto parent = compInfo.parent(detIndex);
27 auto grandParent = compInfo.parent(parent);
28 auto grandParentType = compInfo.componentType(grandParent);
29 auto greatGrandParent = compInfo.parent(parent); // bank
30 auto greatGrandParentType = compInfo.componentType(greatGrandParent);
31
32 if (compInfo.isDetector(detIndex) &&
33 (grandParentType == ComponentType::Rectangular || grandParentType == ComponentType::Structured ||
34 greatGrandParentType == ComponentType::Grid)) {
35 return true;
36 }
37
38 return false;
39}
40
52bool isSaveableBank(const ComponentInfo &compInfo, const DetectorInfo &detInfo, const size_t idx) {
53 // return false if is a detector.
54 if (compInfo.isDetector(idx))
55 return false;
56 // needs to ignore if index is the sample
57 if (compInfo.sample() == idx)
58 return false;
59 // needs to ignore if index is the source
60 if (compInfo.source() == idx)
61 return false;
62 if (!compInfo.hasDetectors(idx))
63 return false;
64
65 // banks containing monitors are not considered saveable as are not
66 // NXDetectors
67 auto detectors = compInfo.detectorsInSubtree(idx);
68
69 return std::none_of(detectors.cbegin(), detectors.cend(),
70 [&detInfo](const auto &det) { return detInfo.isMonitor(det); });
71}
72
83bool isAncestorOf(const ComponentInfo &compInfo, const size_t possibleAncestor, const size_t current) {
84 size_t next = current;
85 while (next != compInfo.root()) {
86 if (next == possibleAncestor)
87 return true;
88 next = compInfo.parent(next);
89 }
90 return false;
91}
92
106Eigen::Vector3d offsetFromAncestor(const Mantid::Geometry::ComponentInfo &compInfo, const size_t ancestorIdx,
107 const size_t currentIdx) {
108
109 if ((ancestorIdx <= currentIdx)) {
110 throw std::invalid_argument("Index of ancestor component is not higher than current Index.");
111 }
112
113 if (ancestorIdx == currentIdx) {
114 return Mantid::Kernel::toVector3d(compInfo.position(currentIdx));
115 } else {
116 const auto ancestorPos = Mantid::Kernel::toVector3d(compInfo.position(ancestorIdx));
117 auto transformation = Eigen::Affine3d(
118 Mantid::Kernel::toQuaterniond(compInfo.rotation(ancestorIdx)).conjugate()); // Inverse ancestor rotation
119 transformation.translate(-ancestorPos);
120 return transformation * Mantid::Kernel::toVector3d(compInfo.position(currentIdx));
121 }
122}
123
124} // namespace Mantid::Geometry::ComponentInfoBankHelpers
ComponentInfo : Provides a component centric view on to the instrument.
Definition: ComponentInfo.h:40
bool hasDetectors(const size_t componentIndex) const
size_t parent(const size_t componentIndex) const
Kernel::Quat rotation(const size_t componentIndex) const
Kernel::V3D position(const size_t componentIndex) const
std::vector< size_t > detectorsInSubtree(size_t componentIndex) const
bool isDetector(const size_t componentIndex) const
Beamline::ComponentType componentType(const size_t componentIndex) const
Geometry::DetectorInfo is an intermediate step towards a DetectorInfo that is part of Instrument-2....
Definition: DetectorInfo.h:49
MANTID_GEOMETRY_DLL Eigen::Vector3d offsetFromAncestor(const Mantid::Geometry::ComponentInfo &compInfo, const size_t ancestorIdx, const size_t currentIdx)
Returns the position of the component at the current index relative to the ancestor component at the ...
MANTID_GEOMETRY_DLL bool isAncestorOf(const ComponentInfo &compInfo, const size_t possibleAncestor, const size_t current)
Finds all ancestors up to the root of a component index and returns true if the possible ancestor is ...
MANTID_GEOMETRY_DLL bool isSaveableBank(const ComponentInfo &compInfo, const DetectorInfo &detInfo, const size_t idx)
Function: isSaveableBank.
MANTID_GEOMETRY_DLL bool isDetectorFixedInBank(const ComponentInfo &compInfo, const size_t detIndex)
Tests whether or not the detector is within a fixed bank.
Eigen::Vector3d toVector3d(const Kernel::V3D &vec)
Converts Kernel::V3D to Eigen::Vector3d.
Eigen::Quaterniond toQuaterniond(const Kernel::Quat &quat)
Converts Kernel::Quat to Eigen::Quaterniond.