31 "The name of the workspace to take as input.");
34 "If left empty then all workspace indices are used.");
35 setPropertySettings(
"WorkspaceIndices",
38 declareProperty(
"IncludeData",
false,
"Include the first value from each spectrum.");
39 setPropertySettings(
"IncludeData",
42 declareProperty<bool>(
"IncludeDetectorPosition",
false,
43 "Include the absolute position of the detector group for each spectrum.",
Direction::Input);
44 setPropertySettings(
"IncludeDetectorPosition",
47 declareProperty<bool>(
"PickOneDetectorID",
false,
"Populate the Detector ID column with only the first of the set.",
49 setPropertySettings(
"PickOneDetectorID",
54 "The name of the outputted detector table workspace, if left empty then "
55 "the input workspace name + \"-Detectors\" is used.");
65 if (
auto peaks = std::dynamic_pointer_cast<IPeaksWorkspace>(inputWs)) {
66 table = peaks->createDetectorTable();
71 if ((
ws = std::dynamic_pointer_cast<MatrixWorkspace>(inputWs))) {
72 if (
ws->getInstrument()->getSample() ==
nullptr) {
73 throw std::runtime_error(
"Matrix workspace has no instrument information");
82 throw std::runtime_error(
"Detector table can only be created for matrix and peaks workspaces.");
86 if (
table ==
nullptr) {
87 throw std::runtime_error(
"Unknown error while creating detector table workspace");
91 setPropertyValue(
"DetectorTableWorkspace", inputWs->getName() +
"-Detectors");
103 std::map<std::string, std::string> validationOutput;
106 const auto matrix = std::dynamic_pointer_cast<MatrixWorkspace>(inputWS);
109 const int numSpectra =
static_cast<int>(matrix->getNumberHistograms());
110 const std::vector<int> indices =
getProperty(
"WorkspaceIndices");
112 if (std::any_of(indices.cbegin(), indices.cend(),
113 [numSpectra](
const auto index) { return (index >= numSpectra) || (index < 0); })) {
114 validationOutput[
"WorkspaceIndices"] =
"One or more indices out of range of available spectra.";
118 return validationOutput;
132 ws->getEFixed(detector);
133 }
catch (std::invalid_argument &) {
135 }
catch (std::runtime_error &) {
148 beamAxisIndex =
ws->getInstrument()->getReferenceFrame()->pointingAlongBeam();
158 std::vector<std::pair<std::string, std::string>> colNames;
159 colNames.emplace_back(
"int",
"Index");
160 colNames.emplace_back(
"int",
"Spectrum No");
162 colNames.emplace_back(
"int",
"Detector ID(s)");
164 colNames.emplace_back(
"str",
"Detector ID(s)");
167 colNames.emplace_back(
"str",
"Time Indexes");
169 colNames.emplace_back(
"double",
"Data Value");
170 colNames.emplace_back(
"double",
"Data Error");
173 colNames.emplace_back(
"double",
"R");
174 colNames.emplace_back(
"double",
"Theta");
176 colNames.emplace_back(
"double",
"Q elastic");
178 colNames.emplace_back(
"double",
"Phi");
179 colNames.emplace_back(
"str",
"Monitor");
181 colNames.emplace_back(
"double",
"DIFA");
182 colNames.emplace_back(
"double",
"DIFC");
183 colNames.emplace_back(
"double",
"DIFC - Uncalibrated");
184 colNames.emplace_back(
"double",
"TZERO");
187 colNames.emplace_back(
"V3D",
"Position");
191 for (
size_t col = 0; col < colNames.size(); ++col) {
192 auto column =
table->addColumn(colNames.at(col).first, colNames.at(col).second);
193 column->setPlotType(0);
200 for (
int row = 0; row <
nrows; ++row) {
203 colValues << static_cast<int>(wsIndex);
204 const double dataY0{
ws->y(wsIndex)[0]}, dataE0{
ws->e(wsIndex)[0]};
206 auto &spectrum =
ws->getSpectrum(wsIndex);
211 throw std::runtime_error(
"No detectors found.");
213 const std::vector<std::string> ¶meters =
216 (!parameters.empty() && find(parameters.begin(), parameters.end(),
"Always") != parameters.end());
220 double R{0.0}, theta{0.0}, phi{0.0};
235 theta *= 180.0 / M_PI;
236 }
catch (
const std::exception &ex) {
244 const std::string isMonitorDisplay = isMonitor ?
"yes" :
"no";
246 colValues << static_cast<int>(specNo);
248 const auto &ids =
dynamic_cast<const std::set<int> &
>(spectrum.getDetectorIDs());
251 colValues << static_cast<int>(*ids.begin());
257 std::set<int> timeIndexSet;
259 timeIndexSet.insert(
int(def.second));
263 colValues << timeIndexes;
267 colValues << dataY0 << dataE0;
274 colValues << R << theta;
279 colValues << std::nan(
"");
290 }
catch (std::runtime_error &) {
292 colValues << std::nan(
"");
302 colValues << 0. << 0. << 0. << 0.;
307 colValues << diffConsts[UnitParams::difa] << diffConsts[UnitParams::difc] << difcValueUncalibrated
308 << diffConsts[UnitParams::tzero];
313 colValues << detectorPosition;
315 }
catch (
const std::exception &) {
317 colValues << static_cast<int>(wsIndex);
327 colValues << dataY0 << dataE0;
329 colValues << 0.0 << 0.0;
336 colValues << 0.0 << 0.0 << 0.0 << 0.0;
339 colValues <<
V3D(0.0, 0.0, 0.0);
355 std::string truncated;
356 size_t ndets = elements.size();
357 auto iter = elements.begin();
358 auto itEnd = elements.end();
362 auto revIter = elements.rbegin();
366 for (; iter != itEnd; ++iter) {
370 if (!truncated.empty()) {
371 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.
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.
API::MatrixWorkspace_sptr ws
void setup()
Creates table workspace of detector information from a given workspace.
void exec() override
Execution code.
Geometry::PointingAlong beamAxisIndex
bool includeDetectorPosition
std::map< std::string, std::string > validateInputs() override
Method checking errors on ALL the inputs, before execution.
const API::SpectrumInfo * spectrumInfo
API::ITableWorkspace_sptr table
bool signedThetaParamRetrieved
std::vector< int > workspaceIndices
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.
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< Workspace > Workspace_sptr
shared pointer to Mantid::API::Workspace
std::string createTruncatedList(const std::set< int > &elements)
Converts a list to a string, shortened if necessary.
std::shared_ptr< const Mantid::Geometry::IDetector > IDetector_const_sptr
Shared pointer to IDetector (const version)
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.