26 return (convention ==
"Crystallography") ? -1.0 : 1.0;
39 : m_usingFullRayTrace(instrument->containsRectDetectors() == Geometry::
Instrument::ContainsState::Full),
40 m_crystallography_convention(
getQSign()), m_detInfo(detInfo), m_instrument(instrument) {
55 m_rayTracer = std::make_unique<InstrumentRayTracer>(instrument);
62 std::vector<Eigen::Vector3d> points;
67 auto beam = frame->vecPointingAlongBeam();
68 auto up = frame->vecPointingUp();
70 for (
size_t pointNo = 0; pointNo <
m_detInfo.
size(); ++pointNo) {
78 const auto norm =
E1.norm();
85 Eigen::Vector3d point(
E1[0],
E1[1],
E1[2]);
88 if (point.hasNaN() || up.coLinear(beam, pos))
91 points.emplace_back(point);
109 return std::make_tuple(
false, 0);
133 return std::make_tuple(
false, 0);
138 return std::make_tuple(
false, 0);
140 return std::make_tuple(
true, detIndex);
158 if (neighbours.empty()) {
160 return std::make_tuple(
false, 0);
164 const auto hitDetector = std::get<0>(result);
165 const auto index = std::get<1>(result);
174 return std::make_tuple(
false, 0);
189 std::vector<double> gaps =
m_instrument->getNumberParameter(
"tube-gap",
true);
191 const auto gap =
static_cast<double>(gaps.front());
194 for (
int i = 0; i < 3; i++) {
195 auto gapDir =
V3D(0., 0., 0.);
198 auto beam1 =
normalize(detectorDir + gapDir);
200 const auto hit1 = std::get<0>(result1);
202 const auto beam2 =
normalize(detectorDir - gapDir);
204 const auto hit2 = std::get<0>(result2);
208 return std::make_tuple(
true,
m_indexMap[std::get<1>(result1)]);
213 return std::make_tuple(
false, 0);
227 for (
const auto &neighbour : neighbours) {
228 const auto index = std::get<1>(neighbour);
235 const auto hitDetector = det.interceptSurface(track) > 0;
237 return std::make_tuple(hitDetector,
index);
242 return std::make_tuple(
false, 0);
251 const auto norm_q = q.
norm();
252 const auto refFrame =
m_instrument->getReferenceFrame();
253 const V3D refBeamDir = refFrame->vecPointingAlongBeam();
256 double one_over_wl = (norm_q * norm_q) / (2.0 * qBeam);
259 detectorDir[refFrame->pointingAlongBeam()] = one_over_wl - qBeam;
260 detectorDir.normalize();
std::map< DeltaEMode::Type, std::string > index
DetectorSearchResult searchUsingNearestNeighbours(const Kernel::V3D &q)
Attempt to find a detector using a nearest neighbours search strategy.
Geometry::Instrument_const_sptr m_instrument
handle to the instrument to search for detectors in
DetectorSearchResult handleTubeGap(const Kernel::V3D &detectorDir, const Kernel::NearestNeighbours< 3 >::NearestNeighbourResults &neighbours)
Helper function to handle the tube gap parameter in tube instruments.
DetectorSearchResult findDetectorIndex(const Kernel::V3D &q)
Find a detector that intsects with the given Qlab vector.
std::tuple< bool, size_t > DetectorSearchResult
Search result type representing whether a detector was found and if so which detector index it was.
const double m_crystallography_convention
flag for whether the crystallography convention is to be used
std::unique_ptr< Geometry::InstrumentRayTracer > m_rayTracer
instrument ray tracer object for searching in rectangular detectors
DetectorSearchResult searchUsingInstrumentRayTracing(const Kernel::V3D &q)
Attempt to find a detector using a full instrument ray tracing strategy.
std::unique_ptr< Kernel::NearestNeighbours< 3 > > m_detectorCacheSearch
Detector search cache for fast look-up of detectors.
std::vector< size_t > m_indexMap
vector of detector indicies used in the search
Kernel::V3D convertQtoDirection(const Kernel::V3D &q) const
Helper function to convert a Qlab vector to a direction in detector space.
std::tuple< bool, size_t > checkInteceptWithNeighbours(const Kernel::V3D &direction, const Kernel::NearestNeighbours< 3 >::NearestNeighbourResults &neighbours) const
Check whether the given direction in detector space intercepts with a detector.
DetectorSearcher(const Geometry::Instrument_const_sptr &instrument, const Geometry::DetectorInfo &detInfo)
Create a new DetectorSearcher with the given instrument & detectors.
const bool m_usingFullRayTrace
flag for whether to use InstrumentRayTracer or NearestNeighbours
const Geometry::DetectorInfo & m_detInfo
detector info for the instrument
void createDetectorCache()
Helper function to build the nearest neighbour tree.
A simple structure that defines an axis-aligned cuboid shaped bounding box for a geometrical object.
bool doesLineIntersect(const Track &track) const
Does a specified track intersect the bounding box.
Geometry::DetectorInfo is an intermediate step towards a DetectorInfo that is part of Instrument-2....
Kernel::V3D samplePosition() const
Returns the sample position.
bool isMasked(const size_t index) const
Returns true if the detector is masked.
Kernel::V3D position(const size_t index) const
Returns the position of the detector with given index.
const Geometry::IDetector & detector(const size_t index) const
Return a const reference to the detector with given index.
size_t indexOf(const detid_t id) const
Returns the index of the detector with the given detector ID.
size_t size() const
Returns the size of the DetectorInfo, i.e., the number of detectors in the instrument.
bool isMonitor(const size_t index) const
Returns true if the detector is a monitor.
This class is responsible for tracking rays and accumulating a list of objects that are intersected a...
Defines a track as a start point and a direction.
void reset(const Kernel::V3D &startPoint, const Kernel::V3D &direction)
Set a starting point and direction.
The Logger class is in charge of the publishing messages from the framework through various channels.
void information(const std::string &msg)
Logs at information level.
std::vector< std::tuple< VectorType, size_t, double > > NearestNeighbourResults
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
constexpr double scalar_prod(const V3D &v) const noexcept
Calculates the cross product.
double norm() const noexcept
bool nullVector(const double tolerance=1e-3) const noexcept
Determine if the point is null.
std::complex< double > MANTID_API_DLL E1(std::complex< double > z)
Integral for Gamma.
Kernel::Logger g_log("ExperimentInfo")
static logger object
std::shared_ptr< const Instrument > Instrument_const_sptr
Shared pointer to an const instrument object.
MANTID_KERNEL_DLL V3D normalize(V3D v)
Normalizes a V3D.
Helper class which provides the Collimation Length for SANS instruments.