10#include "MantidBeamline/SpectrumInfo.h"
21#include "MantidTypes/SpectrumDefinition.h"
36 : m_experimentInfo(experimentInfo), m_detectorInfo(detectorInfo), m_spectrumInfo(spectrumInfo),
54 for (
size_t i = 0; i <
size(); ++i)
62 return std::all_of(spectrumDef.cbegin(), spectrumDef.cend(),
63 [
this](
const std::pair<size_t, size_t> &detIndex) { return m_detectorInfo.isMonitor(detIndex); });
69 return std::all_of(spectrumDef.cbegin(), spectrumDef.cend(),
70 [
this](
const std::pair<size_t, size_t> &detIndex) { return m_detectorInfo.isMasked(detIndex); });
80 auto l2 = std::accumulate(
81 spectrumDef.cbegin(), spectrumDef.cend(), 0.0,
82 [
this](
double x,
const std::pair<size_t, size_t> &detIndex) { return x + m_detectorInfo.l2(detIndex); });
83 return l2 /
static_cast<double>(spectrumDef.size());
94 spectrumDef.cbegin(), spectrumDef.cend(), 0.0,
95 [
this](
double x,
const std::pair<size_t, size_t> &detIndex) { return x + m_detectorInfo.twoTheta(detIndex); });
96 return twoTheta /
static_cast<double>(spectrumDef.size());
106 auto signedTwoTheta = std::accumulate(spectrumDef.cbegin(), spectrumDef.cend(), 0.0,
107 [
this](
double x,
const std::pair<size_t, size_t> &detIndex) {
108 return x + m_detectorInfo.signedTwoTheta(detIndex);
120 auto azimuthalSum = std::accumulate(
121 spectrumDef.cbegin(), spectrumDef.cend(), 0.0,
122 [
this](
double x,
const std::pair<size_t, size_t> &detIndex) { return x + m_detectorInfo.azimuthal(detIndex); });
123 return azimuthalSum /
static_cast<double>(spectrumDef.size());
133 auto twoTheta = std::accumulate(spectrumDef.cbegin(), spectrumDef.cend(), 0.0,
134 [&](
double x,
const std::pair<size_t, size_t> &detIndex) {
135 return x + m_detectorInfo.twoTheta(detIndex, observer, axis);
137 return twoTheta /
static_cast<double>(spectrumDef.size());
149 spectrumDef.cbegin(), spectrumDef.cend(), 0.0, [&](
double x,
const std::pair<size_t, size_t> &detIndex) {
150 return x + m_detectorInfo.signedTwoTheta(detIndex, observer, axis, instrumentUp);
160 auto signedTwoTheta = std::accumulate(spectrumDef.cbegin(), spectrumDef.cend(), 0.0,
161 [&](
double x,
const std::pair<size_t, size_t> &detIndex) {
162 return x + m_detectorInfo.signedTwoTheta(detIndex, observer, axis);
175 if (spectrumDef.size() == 1)
177 auto sumPos = std::accumulate(spectrumDef.cbegin(), spectrumDef.cend(),
Kernel::V3D(),
178 [
this](
const auto &
x,
const std::pair<size_t, size_t> &detIndex) {
179 return x + m_detectorInfo.position(detIndex);
187 return std::atan2(sumPos[1], sumPos[0]);
196 return phiValue < 0 ? -(offset + phiValue) : offset - phiValue;
204 double lat{0.0}, lon{0.0};
207 lat += latlong.first;
208 lon += latlong.second;
217 auto newPos = std::accumulate(spectrumDef.cbegin(), spectrumDef.cend(),
Kernel::V3D(),
218 [
this](
const auto &
x,
const std::pair<size_t, size_t> &detIndex) {
219 return x + m_detectorInfo.position(detIndex);
221 return newPos /
static_cast<double>(spectrumDef.size());
235 throw std::runtime_error(
"Retrieval of diffractometer constants not "
236 "implemented for scanning instrument");
239 std::vector<size_t> detectorIndicesOnly;
240 std::vector<detid_t> calibratedDets;
241 std::vector<detid_t> uncalibratedDets;
242 std::transform(spectrumDef.cbegin(), spectrumDef.cend(), std::back_inserter(detectorIndicesOnly),
243 [](
auto const &pair) { return pair.first; });
245 for (
const auto &detIndex : detectorIndicesOnly) {
247 difa += std::get<0>(newDiffConstants);
248 difc += std::get<1>(newDiffConstants);
249 tzero += std::get<2>(newDiffConstants);
252 if (calibratedDets.size() > 0 && uncalibratedDets.size() > 0) {
253 warningDets.insert(warningDets.end(), uncalibratedDets.begin(), uncalibratedDets.end());
257 if (calibratedDets.size() == 0) {
261 return {{UnitParams::difa,
difa / specDefSize},
262 {UnitParams::difc,
difc / specDefSize},
263 {UnitParams::tzero,
tzero / specDefSize}};
273 std::vector<int> warningDets;
306 pmap[UnitParams::l2] =
l2(wsIndex);
315 }
catch (
const std::runtime_error &e) {
322 g_log.
debug() <<
"Detector: " << det->getID() <<
" EFixed: " <<
pmap[UnitParams::efixed] <<
"\n";
323 }
catch (std::runtime_error &) {
329 std::set<std::string> diffConstUnits = {
"dSpacing",
"MomentumTransfer",
"Empty"};
331 (diffConstUnits.count(inputUnit.
unitID()) || diffConstUnits.count(outputUnit.
unitID()))) {
332 std::vector<detid_t> warnDetIds;
334 pmap.insert(diffConstsMap.begin(), diffConstsMap.end());
335 if (warnDetIds.size() > 0) {
341 }
catch (
const std::runtime_error &e) {
345 pmap[UnitParams::twoTheta] = 0.0;
346 pmap[UnitParams::efixed] = std::numeric_limits<double>::min();
348 if (outputUnit.
unitID().find(
"DeltaE") != std::string::npos) {
349 pmap[UnitParams::l2] = 0.0;
351 pmap[UnitParams::difc] = 0;
356 std::string detIDstring;
357 auto iter = detids.begin();
358 auto itEnd = detids.end();
359 for (; iter != itEnd; ++iter) {
363 if (!detIDstring.empty()) {
364 detIDstring.pop_back();
366 g_log.
warning(
"Incomplete set of calibrated diffractometer constants found for "
368 std::to_string(wsIndex) +
". Using uncalibrated values for detectors " + detIDstring);
422 const size_t ndets = specDef.size();
425 const auto detIndex = specDef[0].first;
431 }
else if (ndets == 0) {
433 "detectors for this workspace "
438 std::vector<std::shared_ptr<const Geometry::IDetector>> det_ptrs;
439 for (
const auto &specDefIndex : specDef) {
440 const auto detIndex = specDefIndex.first;
447 m_lastDetector[thread] = std::make_shared<Geometry::DetectorGroup>(det_ptrs);
480 bbox.
grow(componentInfo.boundingBox(detIndex.first));
std::map< DeltaEMode::Type, std::string > index
#define PARALLEL_THREAD_NUMBER
#define PARALLEL_GET_MAX_THREADS
#define GNU_DIAG_OFF(x)
This is a collection of macros for turning compiler warnings off in a controlled manner.
This class is shared by a few Workspace types and holds information related to a particular experimen...
void updateSpectrumDefinitionIfNecessary(const size_t index) const
double getEFixedGivenEMode(const std::shared_ptr< const Geometry::IDetector > &detector, const Kernel::DeltaEMode::Type emode) const
Easy access to the efixed value for this run & detector.
const Geometry::ComponentInfo & componentInfo() const
double signedTwoTheta(const size_t index) const
Returns the signed scattering angle 2 theta in radians (angle w.r.t.
double phiOffset(const size_t index, const double offset) const
Returns phi() reflected about offset (radians): offset - phi for phi >= 0 and -(offset + phi) otherwi...
SpectrumInfoIterator< SpectrumInfo > end()
bool isMonitor(const size_t index) const
Returns true if the detector(s) associated with the spectrum are monitors.
const Kernel::cow_ptr< std::vector< SpectrumDefinition > > & sharedSpectrumDefinitions() const
Kernel::V3D sourcePosition() const
Returns the source position.
const SpectrumInfoIterator< const SpectrumInfo > cbegin() const
Kernel::UnitParametersMap diffractometerConstants(const size_t index, std::vector< detid_t > &uncalibratedDets) const
Calculate average diffractometer constants (DIFA, DIFC, TZERO) of detectors associated with this spec...
void setMasked(const size_t index, bool masked)
Set the mask flag of the spectrum with given index.
size_t firstDetectorIndex(const size_t index) const
Returns the detector index of the first detector of the spectrum with given index.
void createDetectorIdLogMessages(const std::vector< detid_t > &detids, int64_t wsIndex) const
Kernel::V3D samplePosition() const
Returns the sample position.
bool hasDetectors(const size_t index) const
Returns true if the spectrum is associated with detectors in the instrument.
detid_t firstDetectorID(const size_t index) const
Returns the detector ID of the first detector of the spectrum with given index.
double twoTheta(const size_t index) const
Returns the scattering angle 2 theta in radians (angle w.r.t.
double difcUncalibrated(const size_t index) const
Calculate average uncalibrated DIFC value of detectors associated with this spectrum.
Kernel::V3D position(const size_t index) const
Returns the position of the spectrum with given index.
double l2(const size_t index) const
Returns L2 (distance from sample to spectrum).
double azimuthal(const size_t index) const
Returns the out-of-plane angle in radians (angle w.r.t.
bool isMasked(const size_t index) const
Returns true if the detector(s) associated with the spectrum are masked.
const SpectrumDefinition & checkAndGetSpectrumDefinition(const size_t index) const
SpectrumInfo(const Beamline::SpectrumInfo &spectrumInfo, const ExperimentInfo &experimentInfo, Geometry::DetectorInfo &detectorInfo)
bool hasUniqueDetector(const size_t index) const
Returns true if the spectrum is associated with exactly one detector.
const ExperimentInfo & m_experimentInfo
const SpectrumDefinition & spectrumDefinition(const size_t index) const
Returns a const reference to the SpectrumDefinition of the spectrum.
const Geometry::IDetector & detector(const size_t index) const
Return a const reference to the detector or detector group of the spectrum with given index.
double phi(const size_t index) const
Returns the angle of the spectrum position about the lab-frame z axis, atan2(y, x),...
size_t size() const
Returns the size of the SpectrumInfo, i.e., the number of spectra.
double l1() const
Returns L1 (distance from source to sample).
const SpectrumInfoIterator< const SpectrumInfo > cend() const
void getDetectorValues(const Kernel::Unit &inputUnit, const Kernel::Unit &outputUnit, const Kernel::DeltaEMode::Type emode, const bool signedTheta, int64_t wsIndex, Kernel::UnitParametersMap &pmap) const
Get the detector values relevant to unit conversion for a workspace index.
Geometry::DetectorInfo & m_detectorInfo
size_t detectorCount() const
Geometry::BoundingBox boundingBox(const size_t index) const
Returns the bounding box of the detector(s) of the spectrum with given index.
SpectrumInfoIterator< SpectrumInfo > begin()
std::pair< double, double > geographicalAngles(const size_t index) const
Calculate latitude and longitude for given spectrum index.
std::vector< std::shared_ptr< const Geometry::IDetector > > m_lastDetector
std::vector< size_t > m_lastIndex
const Geometry::IDetector & getDetector(const size_t index) const
const Beamline::SpectrumInfo & m_spectrumInfo
A simple structure that defines an axis-aligned cuboid shaped bounding box for a geometrical object.
void grow(const BoundingBox &other)
Grow the bounding box so that it also encompasses the given box.
Geometry::DetectorInfo is an intermediate step towards a DetectorInfo that is part of Instrument-2....
Kernel::V3D samplePosition() const
Returns the sample position.
std::pair< double, double > geographicalAngles(const size_t index) const
void setMasked(const size_t index, bool masked)
Set the mask flag of the detector with given index. Not thread safe.
double l1() const
Returns L1 (distance from source to sample).
double phi(const size_t index) const
Returns the angle of the detector position about the lab-frame z axis, atan2(y, x),...
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
bool isScanning() const
Returns true if the beamline has scanning detectors.
detid_t detid(const size_t index) const
Returns the detector ID for the given logical detector index.
std::shared_ptr< const Geometry::IDetector > getDetectorPtr(const size_t index) const
Helper used by SpectrumInfo.
Interface class for detector objects.
Exception for when an item is not found in a collection.
The Logger class is in charge of the publishing messages from the framework through various channels.
void debug(const std::string &msg)
Logs at debug level.
void warning(const std::string &msg)
Logs at warning level.
The base units (abstract) class.
virtual const std::string unitID() const =0
The name of the unit.
Implements a copy on write data template.
This functor is used as the deleter object of a shared_ptr to effectively erase ownership Raw pointer...
Kernel::Logger g_log("ExperimentInfo")
static logger object
SpectrumInfoIterator< const SpectrumInfo > SpectrumInfoConstIt
SpectrumInfoIterator< SpectrumInfo > SpectrumInfoIt
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.
std::unordered_map< UnitParams, double > UnitParametersMap
constexpr double Tolerance
Standard tolerance value.
int32_t detid_t
Typedef for a detector ID.
Generate a tableworkspace to store the calibration results.
std::string to_string(const wide_integer< Bits, Signed > &n)
Type
Define the available energy transfer modes It is important to assign enums proper numbers,...