10#include "MantidBeamline/SpectrumInfo.h"
17#include "MantidTypes/SpectrumDefinition.h"
31 : m_experimentInfo(experimentInfo), m_detectorInfo(detectorInfo), m_spectrumInfo(spectrumInfo),
49 for (
size_t i = 0; i <
size(); ++i)
58 [
this](
const std::pair<size_t, size_t> &detIndex) { return m_detectorInfo.isMonitor(detIndex); });
65 [
this](
const std::pair<size_t, size_t> &detIndex) { return m_detectorInfo.isMasked(detIndex); });
75 auto l2 = std::accumulate(
77 [
this](
double x,
const std::pair<size_t, size_t> &detIndex) { return x + m_detectorInfo.l2(detIndex); });
90 [
this](
double x,
const std::pair<size_t, size_t> &detIndex) { return x + m_detectorInfo.twoTheta(detIndex); });
102 [
this](
double x,
const std::pair<size_t, size_t> &detIndex) {
103 return x + m_detectorInfo.signedTwoTheta(detIndex);
115 auto phi = std::accumulate(
117 [
this](
double x,
const std::pair<size_t, size_t> &detIndex) { return x + m_detectorInfo.azimuthal(detIndex); });
126 double lat{0.0}, lon{0.0};
129 lat += latlong.first;
130 lon += latlong.second;
140 [
this](
const auto &
x,
const std::pair<size_t, size_t> &detIndex) {
141 return x + m_detectorInfo.position(detIndex);
157 throw std::runtime_error(
"Retrieval of diffractometer constants not "
158 "implemented for scanning instrument");
161 std::vector<size_t> detectorIndicesOnly;
162 std::vector<detid_t> calibratedDets;
163 std::vector<detid_t> uncalibratedDets;
164 std::transform(spectrumDef.begin(), spectrumDef.end(), std::back_inserter(detectorIndicesOnly),
165 [](
auto const &pair) { return pair.first; });
167 for (
const auto &detIndex : detectorIndicesOnly) {
169 difa += std::get<0>(newDiffConstants);
170 difc += std::get<1>(newDiffConstants);
171 tzero += std::get<2>(newDiffConstants);
174 if (calibratedDets.size() > 0 && uncalibratedDets.size() > 0) {
175 warningDets.insert(warningDets.end(), uncalibratedDets.begin(), uncalibratedDets.end());
179 if (calibratedDets.size() == 0) {
194 std::vector<int> warningDets;
227 pmap[UnitParams::l2] =
l2(wsIndex);
236 }
catch (
const std::runtime_error &e) {
243 g_log.
debug() <<
"Detector: " << det->getID() <<
" EFixed: " <<
pmap[UnitParams::efixed] <<
"\n";
244 }
catch (std::runtime_error &) {
249 std::vector<detid_t> warnDetIds;
251 std::set<std::string> diffConstUnits = {
"dSpacing",
"MomentumTransfer",
"Empty"};
253 (diffConstUnits.count(inputUnit.
unitID()) || diffConstUnits.count(outputUnit.
unitID()))) {
255 pmap.insert(diffConstsMap.begin(), diffConstsMap.end());
256 if (warnDetIds.size() > 0) {
262 }
catch (
const std::runtime_error &e) {
266 pmap[UnitParams::twoTheta] = 0.0;
267 pmap[UnitParams::efixed] = std::numeric_limits<double>::min();
269 if (outputUnit.
unitID().find(
"DeltaE") != std::string::npos) {
270 pmap[UnitParams::l2] = 0.0;
272 pmap[UnitParams::difc] = 0;
277 std::string detIDstring;
278 auto iter = detids.begin();
279 auto itEnd = detids.end();
280 for (; iter != itEnd; ++iter) {
284 if (!detIDstring.empty()) {
285 detIDstring.pop_back();
287 g_log.
warning(
"Incomplete set of calibrated diffractometer constants found for "
289 std::to_string(wsIndex) +
". Using uncalibrated values for detectors " + detIDstring);
337 const size_t ndets = specDef.size();
340 const auto detIndex = specDef[0].first;
342 }
else if (ndets == 0) {
344 "detectors for this workspace "
349 std::vector<std::shared_ptr<const Geometry::IDetector>> det_ptrs;
350 for (
const auto &specDefIndex : specDef) {
351 const auto detIndex = specDefIndex.first;
354 m_lastDetector[thread] = std::make_shared<Geometry::DetectorGroup>(det_ptrs);
std::map< DeltaEMode::Type, std::string > index
#define PARALLEL_THREAD_NUMBER
#define PARALLEL_GET_MAX_THREADS
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.
double signedTwoTheta(const size_t index) const
Returns the signed scattering angle 2 theta in radians (angle w.r.t.
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.
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.
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.
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
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
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).
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.
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.
An object for constructing a shared_ptr that won't ever delete its pointee.
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
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,...