20 "The name of the workspace to take as input.");
23 "If left empty then all workspace indices are used.");
24 setPropertySettings(
"WorkspaceIndices",
27 declareProperty(
"IncludeData",
false,
"Include the first value from each spectrum.");
28 setPropertySettings(
"IncludeData",
33 "The name of the outputted detector table workspace, if left empty then "
34 "the input workspace name + \"-Detectors\" is used.");
40 std::vector<int> indices =
getProperty(
"WorkspaceIndices");
44 auto matrix = std::dynamic_pointer_cast<MatrixWorkspace>(inputWS);
48 if (detectorTable ==
nullptr) {
49 throw std::runtime_error(
"The instrument has no sample.");
52 auto peaks = std::dynamic_pointer_cast<IPeaksWorkspace>(inputWS);
54 detectorTable = peaks->createDetectorTable();
58 if (detectorTable ==
nullptr) {
59 throw std::runtime_error(
"Detector table can only be created for matrix and peaks workspaces.");
63 setPropertyValue(
"DetectorTableWorkspace", inputWS->getName() +
"-Detectors");
66 setProperty(
"DetectorTableWorkspace", detectorTable);
76 std::map<std::string, std::string> validationOutput;
79 const auto matrix = std::dynamic_pointer_cast<MatrixWorkspace>(inputWS);
82 const int numSpectra =
static_cast<int>(matrix->getNumberHistograms());
83 const std::vector<int> indices =
getProperty(
"WorkspaceIndices");
85 if (std::any_of(indices.cbegin(), indices.cend(),
86 [numSpectra](
const auto index) { return (index >= numSpectra) || (index < 0); })) {
87 validationOutput[
"WorkspaceIndices"] =
"One or more indices out of range of available spectra.";
91 return validationOutput;
105 const bool includeData,
Logger &logger) {
116 const bool isScanning = ws->detectorInfo().isScanning();
118 const auto &spectrumInfo = ws->spectrumInfo();
119 if (spectrumInfo.hasDetectors(0)) {
121 std::shared_ptr<const IDetector> detector(&spectrumInfo.detector(0),
Mantid::NoDeleting());
122 ws->getEFixed(detector);
123 }
catch (std::runtime_error &) {
131 bool hasDiffConstants{
false};
132 auto emode = ws->getEMode();
134 hasDiffConstants =
true;
138 auto colNames =
createColumns(isScanning, includeData, calcQ, hasDiffConstants);
140 const int ncols =
static_cast<int>(colNames.size());
141 const int nrows = indices.empty() ?
static_cast<int>(ws->getNumberHistograms()) :
static_cast<int>(indices.size());
146 for (
int col = 0; col <
ncols; ++col) {
147 auto column = t->addColumn(colNames.at(col).first, colNames.at(col).second);
148 column->setPlotType(0);
151 t->setRowCount(
nrows);
154 const auto beamAxisIndex = ws->getInstrument()->getReferenceFrame()->pointingAlongBeam();
155 const auto sampleDist = sample->getPos()[beamAxisIndex];
156 bool signedThetaParamRetrieved{
false}, showSignedTwoTheta{
false};
159 populateTable(t, ws,
nrows, indices, spectrumInfo, signedThetaParamRetrieved, showSignedTwoTheta, beamAxisIndex,
160 sampleDist, isScanning, includeData, calcQ, hasDiffConstants, logger);
165std::vector<std::pair<std::string, std::string>>
createColumns(
const bool isScanning,
const bool includeData,
166 const bool calcQ,
const bool hasDiffConstants) {
167 std::vector<std::pair<std::string, std::string>> colNames;
168 colNames.emplace_back(
"double",
"Index");
169 colNames.emplace_back(
"int",
"Spectrum No");
170 colNames.emplace_back(
"str",
"Detector ID(s)");
172 colNames.emplace_back(
"str",
"Time Indexes");
174 colNames.emplace_back(
"double",
"Data Value");
175 colNames.emplace_back(
"double",
"Data Error");
178 colNames.emplace_back(
"double",
"R");
179 colNames.emplace_back(
"double",
"Theta");
181 colNames.emplace_back(
"double",
"Q elastic");
183 colNames.emplace_back(
"double",
"Phi");
184 colNames.emplace_back(
"str",
"Monitor");
185 if (hasDiffConstants) {
186 colNames.emplace_back(
"double",
"DIFA");
187 colNames.emplace_back(
"double",
"DIFC");
188 colNames.emplace_back(
"double",
"DIFC - Uncalibrated");
189 colNames.emplace_back(
"double",
"TZERO");
195 const std::vector<int> &indices,
const SpectrumInfo &spectrumInfo,
bool signedThetaParamRetrieved,
196 bool showSignedTwoTheta,
const PointingAlong &beamAxisIndex,
const double sampleDist,
197 const bool isScanning,
const bool includeData,
const bool calcQ,
const bool includeDiffConstants,
200 for (
int row = 0; row <
nrows; ++row) {
201 TableRow colValues = t->getRow(row);
202 size_t wsIndex = indices.empty() ?
static_cast<size_t>(row) : indices[row];
203 colValues << static_cast<double>(wsIndex);
204 const double dataY0{ws->y(wsIndex)[0]}, dataE0{ws->e(wsIndex)[0]};
206 auto &spectrum = ws->getSpectrum(wsIndex);
208 const auto &ids =
dynamic_cast<const std::set<int> &
>(spectrum.getDetectorIDs());
213 throw std::runtime_error(
"No detectors found.");
214 if (!signedThetaParamRetrieved) {
215 const std::vector<std::string> ¶meters =
218 (!parameters.empty() && find(parameters.begin(), parameters.end(),
"Always") != parameters.end());
219 signedThetaParamRetrieved =
true;
222 double R{0.0}, theta{0.0}, phi{0.0};
228 R = spectrumInfo.
l2(wsIndex);
233 const bool isMonitor = spectrumInfo.
isMonitor(wsIndex);
237 theta *= 180.0 / M_PI;
238 }
catch (
const std::exception &ex) {
240 logger.
error(ex.what());
243 const auto dist = spectrumInfo.
position(wsIndex)[beamAxisIndex];
244 theta = sampleDist > dist ? 180.0 : 0.0;
246 const std::string isMonitorDisplay = isMonitor ?
"yes" :
"no";
247 colValues << static_cast<int>(specNo) << detIds;
249 std::set<int> timeIndexSet;
251 timeIndexSet.insert(
int(def.second));
255 colValues << timeIndexes;
259 colValues << dataY0 << dataE0;
266 colValues << R << theta;
271 colValues << std::nan(
"");
277 double efixed = ws->getEFixed(det);
278 double usignTheta = spectrumInfo.
twoTheta(wsIndex) * 0.5;
282 }
catch (std::runtime_error &) {
284 colValues << std::nan(
"");
292 if (includeDiffConstants) {
294 colValues << 0. << 0. << 0. << 0.;
299 colValues << diffConsts[UnitParams::difa] << diffConsts[UnitParams::difc] << difcValueUncalibrated
300 << diffConsts[UnitParams::tzero];
303 }
catch (
const std::exception &) {
305 colValues << static_cast<double>(wsIndex);
307 colValues << -1 <<
"0";
310 colValues << dataY0 << dataE0;
312 colValues << 0.0 << 0.0;
318 if (includeDiffConstants) {
319 colValues << 0.0 << 0.0 << 0.0 << 0.0;
335 std::string truncated;
336 size_t ndets = elements.size();
337 auto iter = elements.begin();
338 auto itEnd = elements.end();
342 auto revIter = elements.rbegin();
346 for (; iter != itEnd; ++iter) {
350 if (!truncated.empty()) {
351 truncated.pop_back();
#define DECLARE_ALGORITHM(classname)
std::map< DeltaEMode::Type, std::string > index
#define PARALLEL_FOR_IF(condition)
Empty definitions - to enable set your complier to enable openMP.
std::string getPropertyValue(const std::string &name) const override
Get the value of a property as a string.
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
void setPropertyValue(const std::string &name, const std::string &value) override
Set the value of a property by string N.B.
Show a property as enabled when the workspace pointed to by another is of a given type.
API::SpectrumInfo is an intermediate step towards a SpectrumInfo that is part of Instrument-2....
double signedTwoTheta(const size_t index) const
Returns the signed scattering angle 2 theta in radians (angle w.r.t.
bool isMonitor(const size_t index) const
Returns true if the detector(s) associated with the spectrum are monitors.
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...
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).
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.
TableRow represents a row in a TableWorkspace.
size_t row() const
Returns the row number of the TableRow.
A property class for workspaces.
void exec() override
Execution code.
std::map< std::string, std::string > validateInputs() override
Method checking errors on ALL the inputs, before execution.
virtual std::vector< std::string > getStringParameter(const std::string &pname, bool recursive=true) const =0
Get a parameter defined as a string.
Support for a property that holds an array of values.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
The Logger class is in charge of the publishing messages from the framework through various channels.
void error(const std::string &msg)
Logs at error level.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
static double convertToElasticQ(const double theta, const double efixed)
Convert to ElasticQ from Energy.
void getSpherical(double &R, double &theta, double &phi) const noexcept
Return the vector's position in spherical coordinates.
An object for constructing a shared_ptr that won't ever delete its pointee.
std::shared_ptr< ITableWorkspace > ITableWorkspace_sptr
shared pointer to Mantid::API::ITableWorkspace
std::shared_ptr< Workspace > Workspace_sptr
shared pointer to Mantid::API::Workspace
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
std::string createTruncatedList(const std::set< int > &elements)
Converts a list to a string, shortened if necessary.
API::ITableWorkspace_sptr createDetectorTableWorkspace(const API::MatrixWorkspace_sptr &ws, const std::vector< int > &indices, const bool includeData, Kernel::Logger &logger)
Creates table workspace of detector information from a given workspace.
std::vector< std::pair< std::string, std::string > > createColumns(const bool isScanning, const bool includeData, const bool calcQ, const bool hasDiffConstants)
void populateTable(Mantid::API::ITableWorkspace_sptr &t, const Mantid::API::MatrixWorkspace_sptr &ws, const int nrows, const std::vector< int > &indices, const Mantid::API::SpectrumInfo &spectrumInfo, bool signedThetaParamRetrieved, bool showSignedTwoTheta, const Mantid::Geometry::PointingAlong &beamAxisIndex, const double sampleDist, const bool isScanning, const bool include_data, const bool calcQ, const bool includeDiffConstants, Kernel::Logger &logger)
std::shared_ptr< const IComponent > IComponent_const_sptr
Typdef of a shared pointer to a const IComponent.
std::shared_ptr< const Mantid::Geometry::IDetector > IDetector_const_sptr
Shared pointer to IDetector (const version)
PointingAlong
Type to describe pointing along options.
std::enable_if< std::is_pointer< Arg >::value, bool >::type threadSafe(Arg workspace)
Thread-safety check Checks the workspace to ensure it is suitable for multithreaded access.
int32_t detid_t
Typedef for a detector ID.
int32_t specnum_t
Typedef for a spectrum Number.
std::string to_string(const wide_integer< Bits, Signed > &n)
@ Input
An input workspace.
@ Output
An output workspace.