14#include "MantidHistogramData/BinEdges.h"
15#include "MantidHistogramData/Histogram.h"
16#include "MantidHistogramData/LinearGenerator.h"
17#include "MantidHistogramData/Points.h"
18#include "MantidTypes/SpectrumDefinition.h"
36 const size_t nTimeIndexes,
const size_t nBins,
37 const bool isPointData)
38 : m_nDetectors(instrument->getNumberDetectors()), m_nTimeIndexes(nTimeIndexes), m_nBins(nBins),
39 m_instrument(instrument), m_histogram(BinEdges(nBins + 1, LinearGenerator(1.0, 1.0)), Counts(nBins, 0.0)),
42 m_histogram = HistogramData::Histogram(Points(nBins), Counts(nBins, 0.0));
53 if (histogram.size() !=
m_nBins)
54 throw std::logic_error(
"Histogram supplied does not have the correct size.");
66 std::vector<std::pair<Types::Core::DateAndTime, Types::Core::DateAndTime>> timeRanges) {
79 const std::vector<double> &durations) {
82 std::vector<std::pair<Types::Core::DateAndTime, Types::Core::DateAndTime>> timeRanges = {
83 std::pair<Types::Core::DateAndTime, Types::Core::DateAndTime>(startTime, startTime + durations[0])};
86 const auto newStartTime = timeRanges[i - 1].second;
87 const auto endTime = newStartTime + durations[i];
88 timeRanges.emplace_back(std::pair<Types::Core::DateAndTime, Types::Core::DateAndTime>(newStartTime, endTime));
104 throw std::logic_error(
"Can not set positions, as positions or instrument "
105 "angles have already been set.");
107 for (
const auto &vector : positions) {
125 throw std::logic_error(
"Can not set rotations, as rotations or instrument "
126 "angles have already been set.");
128 for (
const auto &vector : rotations) {
157 throw std::logic_error(
"Can not set instrument angles, as positions and/or "
158 "rotations have already been set.");
173 throw std::logic_error(
"Indexing type has been set already.");
188 auto &outputComponentInfo = outputWorkspace->mutableComponentInfo();
193 auto &outputDetectorInfo = outputWorkspace->mutableDetectorInfo();
216 return std::shared_ptr<MatrixWorkspace>(std::move(outputWorkspace));
222 auto &mergeComponentInfo = mergeWorkspace->mutableComponentInfo();
224 outputComponentInfo.
merge(mergeComponentInfo);
245 for (
size_t i = 0; i < outputDetectorInfo.
size(); ++i) {
246 for (
size_t j = 0; j < outputDetectorInfo.
scanCount(); ++j) {
247 if (outputDetectorInfo.
isMonitor({i, j}))
255 const auto &oldRotation = outputDetectorInfo.
rotation({i, j});
265 for (
size_t detIndex = 0; detIndex <
m_nDetectors; ++detIndex) {
266 for (
size_t timeIndex = 0; timeIndex <
m_nTimeIndexes; ++timeIndex) {
267 spectrumDefinitions[detIndex *
m_nTimeIndexes + timeIndex].add(detIndex, timeIndex);
271 indexInfo.setSpectrumDefinitions(spectrumDefinitions);
279 for (
size_t timeIndex = 0; timeIndex <
m_nTimeIndexes; ++timeIndex) {
280 for (
size_t detIndex = 0; detIndex <
m_nDetectors; ++detIndex) {
281 spectrumDefinitions[timeIndex *
m_nDetectors + detIndex].add(detIndex, timeIndex);
285 indexInfo.setSpectrumDefinitions(spectrumDefinitions);
291 throw std::logic_error(
"Number of " + description +
" supplied does not match the number of time indexes.");
297 throw std::logic_error(
"Number of " + description +
" supplied does not match the number of detectors.");
303 throw std::logic_error(
"Can not build workspace - time ranges have not "
304 "been set. Please call setTimeRanges() before "
Mantid::Kernel::Quat(ComponentInfo::* rotation)(const size_t) const
Base MatrixWorkspace Abstract Class.
const Indexing::IndexInfo & indexInfo() const
Returns a const reference to the IndexInfo object of the workspace.
void setIndexInfo(const Indexing::IndexInfo &indexInfo)
Sets the IndexInfo object of the workspace.
API::MatrixWorkspace_sptr buildWorkspace() const
Verify everything has been set that is required and return the workspace.
std::vector< std::pair< Types::Core::DateAndTime, Types::Core::DateAndTime > > m_timeRanges
void setTimeRanges(std::vector< std::pair< Types::Core::DateAndTime, Types::Core::DateAndTime > > timeRanges)
Set time ranges from a vector of start time, end time pairs.
void verifyDetectorSize(const size_t detectorSize, const std::string &description) const
void createDetectorOrientedIndexInfo(API::MatrixWorkspace &ws) const
void validateInputs() const
void setHistogram(HistogramData::Histogram histogram)
Set a histogram to be used for all the workspace spectra.
void setRelativeRotationsForScans(const std::vector< double > &relativeRotations, const Kernel::V3D &rotationPosition, const Kernel::V3D &rotationAxis)
Set a vector of rotations corresponding to each time index.
std::vector< double > m_instrumentAngles
Kernel::V3D m_rotationPosition
void buildOutputComponentInfo(Geometry::ComponentInfo &outputComponentInfo) const
std::shared_ptr< const Geometry::Instrument > m_instrument
void verifyTimeIndexSize(const size_t timeIndexSize, const std::string &description) const
void buildRelativeRotationsForScans(Geometry::DetectorInfo &outputDetectorInfo) const
void buildPositions(Geometry::DetectorInfo &outputDetectorInfo) const
void setIndexingType(const IndexingType indexingType)
Set the indexing type, either to time or detector oriented indexing.
void buildRotations(Geometry::DetectorInfo &outputDetectorInfo) const
HistogramData::Histogram m_histogram
std::vector< std::vector< Kernel::V3D > > m_positions
IndexingType m_indexingType
void createTimeOrientedIndexInfo(API::MatrixWorkspace &ws) const
ScanningWorkspaceBuilder(const std::shared_ptr< const Geometry::Instrument > &instrument, const size_t nTimeIndexes, const size_t nBins, const bool isPointData=false)
Create the scanning workspace builder.
std::vector< std::vector< Kernel::Quat > > m_rotations
Kernel::V3D m_rotationAxis
void setPositions(std::vector< std::vector< Kernel::V3D > > positions)
Supply a vector of vectors which contain positions.
void setRotations(std::vector< std::vector< Kernel::Quat > > rotations)
Supply a vector of vectors which contain rotations.
ComponentInfo : Provides a component centric view on to the instrument.
void merge(const ComponentInfo &other)
Geometry::DetectorInfo is an intermediate step towards a DetectorInfo that is part of Instrument-2....
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.
Kernel::Quat rotation(const size_t index) const
Returns the rotation of the detector with given index.
Kernel::V3D position(const size_t index) const
Returns the position of the detector with given index.
void setRotation(const size_t index, const Kernel::Quat &rotation)
Set the absolute rotation of the detector with given index. Not thread safe.
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.
void rotate(V3D &) const
Rotate a vector.
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class