9#include "MantidBeamline/DetectorInfo.h"
27 std::shared_ptr<const Geometry::Instrument> instrument,
28 std::shared_ptr<
const std::vector<detid_t>> detectorIds,
29 std::shared_ptr<
const std::unordered_map<detid_t, size_t>> detIdToIndexMap)
30 : m_detectorInfo(
std::move(detectorInfo)), m_instrument(
std::move(instrument)),
31 m_detectorIDs(
std::move(detectorIds)), m_detIDToIndex(
std::move(detIdToIndexMap)),
37 throw std::invalid_argument(
"DetectorInfo::DetectorInfo Workspace does not contain an instrument!");
40 throw std::invalid_argument(
"DetectorInfo::DetectorInfo: ID and ID->index map do not match");
49 : m_detectorInfo(
std::make_unique<Beamline::
DetectorInfo>(*other.m_detectorInfo)), m_instrument(other.m_instrument),
50 m_detectorIDs(other.m_detectorIDs), m_detIDToIndex(other.m_detIDToIndex),
56 throw std::runtime_error(
"DetectorInfo::operator=: Detector IDs in "
57 "assignment do not match. Assignment not "
130 throw std::logic_error(
"Two theta (scattering angle) is not defined for monitors.");
135 if (beamLine.nullVector()) {
140 return sampleDetVec.angle(beamLine);
146 throw std::logic_error(
"Two theta (scattering angle) is not defined for monitors.");
151 if (beamLine.nullVector()) {
156 return sampleDetVec.angle(beamLine);
162 throw std::logic_error(
"Two theta (scattering angle) is not defined for monitors.");
167 if (beamLine.nullVector()) {
171 const auto &instrumentUpAxis =
m_instrument->getReferenceFrame()->vecThetaSign();
174 double angle = sampleDetVec.angle(beamLine);
176 const auto cross = beamLine.cross_prod(sampleDetVec);
177 const auto normToSurface = beamLine.cross_prod(instrumentUpAxis);
178 if (normToSurface.scalar_prod(cross) < 0) {
187 throw std::logic_error(
"Two theta (scattering angle) is not defined for monitors.");
192 if (beamLine.nullVector()) {
196 const auto &instrumentUpAxis =
m_instrument->getReferenceFrame()->vecThetaSign();
199 double angle = sampleDetVec.angle(beamLine);
201 const auto cross = beamLine.cross_prod(sampleDetVec);
202 const auto normToSurface = beamLine.cross_prod(instrumentUpAxis);
203 if (normToSurface.scalar_prod(cross) < 0) {
211 throw std::logic_error(
"Azimuthal angle is not defined for monitors");
216 if (beamLine.nullVector()) {
224 const auto origHorizontal =
m_instrument->getReferenceFrame()->vecPointingHorizontal();
225 const auto vertical = beamLineNormalized.cross_prod(origHorizontal);
226 if (vertical.scalar_prod(
m_instrument->getReferenceFrame()->vecPointingUp()) <= 0.)
227 throw std::runtime_error(
"Failed to create up axis orthogonal to the beam direction");
230 const auto horizontal = vertical.cross_prod(beamLineNormalized);
231 if (origHorizontal.scalar_prod(horizontal) <= 0.)
232 throw std::runtime_error(
"Failed to create horizontal axis orthogonal to the beam direction");
234 const double dotHorizontal = sampleDetVec.scalar_prod(horizontal);
235 const double dotVertical = sampleDetVec.scalar_prod(vertical);
237 return atan2(dotVertical, dotHorizontal);
242 throw std::logic_error(
"Azimuthal angle is not defined for monitors");
247 if (beamLine.nullVector()) {
255 const auto origHorizontal =
m_instrument->getReferenceFrame()->vecPointingHorizontal();
256 const auto vertical = beamLineNormalized.cross_prod(origHorizontal);
257 if (vertical.scalar_prod(
m_instrument->getReferenceFrame()->vecPointingUp()) <= 0.)
258 throw std::runtime_error(
"Failed to create up axis orthogonal to the beam direction");
261 const auto horizontal = vertical.cross_prod(beamLineNormalized);
262 if (origHorizontal.scalar_prod(horizontal) <= 0.)
263 throw std::runtime_error(
"Failed to create horizontal axis orthogonal to the beam direction");
265 const double dotHorizontal = sampleDetVec.scalar_prod(horizontal);
266 const double dotVertical = sampleDetVec.scalar_prod(vertical);
268 return atan2(dotVertical, dotHorizontal);
272 std::vector<detid_t> &calibratedDets,
273 std::vector<detid_t> &uncalibratedDets)
const {
276 auto par =
pmap->get(det.get(),
"DIFC");
278 double difc = par->value<
double>();
281 par =
pmap->get(det.get(),
"DIFA");
283 difa = par->value<
double>();
284 par =
pmap->get(det.get(),
"TZERO");
286 tzero = par->value<
double>();
293 return {0.,
difc, 0.};
304 const double upCoord = sampleDetVec[
m_instrument->getReferenceFrame()->pointingUp()];
305 const double beamCoord = sampleDetVec[
m_instrument->getReferenceFrame()->pointingAlongBeam()];
306 const double leftoverCoord = sampleDetVec[
m_instrument->getReferenceFrame()->pointingHorizontal()];
307 const double lat = std::atan2(upCoord, std::hypot(leftoverCoord, beamCoord));
308 const double lon = std::atan2(leftoverCoord, beamCoord);
309 return std::pair<double, double>(lat, lon);
315 const double upCoord = sampleDetVec[
m_instrument->getReferenceFrame()->pointingUp()];
316 const double beamCoord = sampleDetVec[
m_instrument->getReferenceFrame()->pointingAlongBeam()];
317 const double leftoverCoord = sampleDetVec[
m_instrument->getReferenceFrame()->pointingHorizontal()];
318 const double lat = std::atan2(upCoord, std::hypot(leftoverCoord, beamCoord));
319 const double lon = std::atan2(leftoverCoord, beamCoord);
320 return std::pair<double, double>(lat, lon);
354 for (
size_t i = 0; i <
size(); ++i)
376 pmap->clearParametersByName(
"DIFA", det.get());
377 pmap->clearParametersByName(
"DIFC", det.get());
378 pmap->clearParametersByName(
"TZERO", det.get());
409 }
catch (
const std::out_of_range &) {
411 std::stringstream msg;
412 msg <<
"Failed to find detector with id=" << id;
413 throw std::out_of_range(msg.str());
426 return {intervals.begin(), intervals.end()};
const std::vector< double > & rhs
std::map< DeltaEMode::Type, std::string > index
#define PARALLEL_THREAD_NUMBER
#define PARALLEL_GET_MAX_THREADS
Mantid::Kernel::Quat(ComponentInfo::* rotation)(const size_t) const
DetectorInfoIterator for random access iteration over DetectorInfo.
Geometry::DetectorInfo is an intermediate step towards a DetectorInfo that is part of Instrument-2....
void clearPositionDependentParameters(const size_t index)
double twoTheta(const size_t index) const
Returns 2 theta (scattering angle w.r.t. to beam direction).
size_t scanCount() const
Returns the scan count of the detector with given detector index.
void setPosition(const size_t index, const Kernel::V3D &position)
Set the absolute position of the detector with given index. Not thread safe.
std::shared_ptr< const Geometry::Instrument > m_instrument
double l2(const size_t index) const
Returns L2 (distance from sample to spectrum).
std::shared_ptr< const std::unordered_map< detid_t, size_t > > m_detIDToIndex
const Geometry::IDetector & getDetector(const size_t index) const
Kernel::V3D samplePosition() const
Returns the sample position.
std::pair< double, double > geographicalAngles(const size_t index) const
DetectorInfoIterator< DetectorInfo > end()
bool hasMaskedDetectors() const
Returns true if there are masked detectors.
Kernel::Quat rotation(const size_t index) const
Returns the rotation of the detector with given index.
bool isMasked(const size_t index) const
Returns true if the detector is masked.
void setMasked(const size_t index, bool masked)
Set the mask flag of the detector with given index. Not thread safe.
const std::vector< detid_t > & detectorIDs() const
Returns a sorted vector of all detector IDs.
Kernel::V3D position(const size_t index) const
Returns the position of the detector with given index.
void clearMaskFlags()
Sets all mask flags to false (unmasked).
bool isEquivalent(const DetectorInfo &other) const
Returns true if the content of this is equivalent to the content of other.
const DetectorInfoIterator< const DetectorInfo > cend() const
std::vector< std::shared_ptr< const Geometry::IDetector > > m_lastDetector
double signedTwoTheta(const size_t index) const
Returns signed 2 theta (signed scattering angle w.r.t. to beam direction).
double l1() const
Returns L1 (distance from source to sample).
void setRotation(const size_t index, const Kernel::Quat &rotation)
Set the absolute rotation of the detector with given index. Not thread safe.
std::vector< size_t > m_lastIndex
Kernel::V3D sourcePosition() const
Returns the source position.
std::tuple< double, double, double > diffractometerConstants(const size_t index, std::vector< detid_t > &calibratedDets, std::vector< detid_t > &uncalibratedDets) const
const Geometry::IDetector & detector(const size_t index) const
Return a const reference to the detector with given index.
DetectorInfo(std::unique_ptr< Beamline::DetectorInfo > detectorInfo, std::shared_ptr< const Geometry::Instrument > instrument, std::shared_ptr< const std::vector< detid_t > > detectorIds, std::shared_ptr< const std::unordered_map< detid_t, size_t > > detIdToIndexMap)
Construct DetectorInfo based on an Instrument.
const DetectorInfoIterator< const DetectorInfo > cbegin() const
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.
DetectorInfoIterator< DetectorInfo > begin()
std::unique_ptr< Beamline::DetectorInfo > m_detectorInfo
Pointer to the actual DetectorInfo object (non-wrapping part).
bool isMonitor(const size_t index) const
Returns true if the detector is a monitor.
bool isScanning() const
Returns true if the beamline has scanning detectors.
std::shared_ptr< const std::vector< detid_t > > m_detectorIDs
double azimuthal(const size_t index) const
DetectorInfo & operator=(const DetectorInfo &rhs)
Assigns the contents of the non-wrapping part of rhs to this.
double difcUncalibrated(const size_t index) const
const std::vector< std::pair< Types::Core::DateAndTime, Types::Core::DateAndTime > > scanIntervals() const
Returns the scan interval of the detector with given index.
std::shared_ptr< const Geometry::IDetector > getDetectorPtr(const size_t index) const
Helper used by SpectrumInfo.
Interface class for detector objects.
Exception for errors associated with the instrument definition.
DetectorInfoIterator< DetectorInfo > DetectorInfoIt
DetectorInfoIterator< const DetectorInfo > DetectorInfoConstIt
MANTID_KERNEL_DLL double tofToDSpacingFactor(const double l1, const double l2, const double twoTheta, const double offset)
Calculate and return conversion factor from tof to d-spacing.
Kernel::Quat toQuat(const Eigen::Quaterniond &quat)
Converts Eigen::Quaterniond to Kernel::Quat.
Eigen::Vector3d toVector3d(const Kernel::V3D &vec)
Converts Kernel::V3D to Eigen::Vector3d.
Kernel::V3D toV3D(const Eigen::Vector3d &vec)
This header provides conversion helpers between vector and rotation types in MantidKernel and equival...
MANTID_KERNEL_DLL V3D normalize(V3D v)
Normalizes a V3D.
Eigen::Quaterniond toQuaterniond(const Kernel::Quat &quat)
Converts Kernel::Quat to Eigen::Quaterniond.
int32_t detid_t
Typedef for a detector ID.
Generate a tableworkspace to store the calibration results.