13#include "MantidHistogramData/HistogramIterator.h"
23double calculateQ(
const double lambda,
const double twoTheta) {
24 return (4 * M_PI * std::sin(twoTheta * (M_PI / 180) / 2)) / (
lambda);
50 return "Calculates and sets Qmin and Qmax of a SANS workspace";
55 std::map<std::string, std::string> issues;
58 issues[
"InputWorkspace"] =
"The InputWorkspace must be a MatrixWorkspace.";
59 }
else if (
workspace->getAxis(0)->unit()->unitID() !=
"Wavelength" && !
workspace->run().hasProperty(
"wavelength")) {
60 issues[
"InputWorkspace"] =
"If the workspace is not in units of wavelength it must have a sample log wavelength.";
70 "An input workspace.");
73 "List of component names to calculate the q ranges for.");
83 const std::string &compName =
"") {
84 const auto &spectrumInfo =
workspace->spectrumInfo();
85 const auto unit =
workspace->getAxis(0)->unit()->unitID();
86 double constantLambda = 0;
87 if (
workspace->run().hasProperty(
"wavelength"))
88 constantLambda =
workspace->run().getLogAsSingleValue(
"wavelength");
89 double min = std::numeric_limits<double>::max(), max = std::numeric_limits<double>::lowest();
93 for (int64_t
index = 0; index < static_cast<int64_t>(indices.size()); ++
index) {
94 if (spectrumInfo.hasDetectors(indices[
index]) && !spectrumInfo.isMonitor(indices[
index]) &&
95 !spectrumInfo.isMasked(indices[
index])) {
100 if (unit !=
"Wavelength") {
101 const double q = calculateQ(constantLambda, theta);
103 min = std::min(min, q);
104 max = std::max(max, q);
108 const double q1 = calculateQ(spectrum.begin()->center(), theta);
109 const double q2 = calculateQ(std::prev(spectrum.end())->center(), theta);
111 min = std::min(min, std::min(q1, q2));
112 max = std::max(max, std::max(q1, q2));
118 std::string qminLogName =
"qmin";
119 std::string qmaxLogName =
"qmax";
120 if (!compName.empty()) {
121 qminLogName +=
"_" + compName;
122 qmaxLogName +=
"_" + compName;
124 run.addProperty<
double>(qminLogName, min,
true);
125 run.addProperty<
double>(qmaxLogName, max,
true);
133 const size_t nHist =
workspace->getNumberHistograms();
134 std::vector<size_t> allIndices(nHist);
135 for (
size_t i = 0; i < nHist; ++i) {
136 allIndices.emplace_back(i);
139 const std::vector<std::string> componentNames =
getProperty(
"ComponentNames");
140 if (!componentNames.empty()) {
141 const auto instrument =
workspace->getInstrument();
143 g_log.
error() <<
"No instrument in input workspace. Ignoring ComponentList\n";
146 for (
const auto &compName : componentNames) {
147 std::vector<detid_t> detIDs;
148 std::vector<IDetector_const_sptr> dets;
149 instrument->getDetectorsInBank(dets, compName);
151 const auto component = instrument->getComponentByName(compName);
152 const auto det = std::dynamic_pointer_cast<const IDetector>(component);
154 g_log.
error() <<
"No detectors found in component '" << compName <<
"'\n";
157 dets.emplace_back(det);
160 detIDs.reserve(dets.size());
161 std::transform(dets.begin(), dets.end(), std::back_inserter(detIDs),
162 [](
const auto &det) { return det->getID(); });
164 const auto indices =
workspace->getIndicesFromDetectorIDs(detIDs);
#define DECLARE_ALGORITHM(classname)
const std::vector< double > * lambda
IPeaksWorkspace_sptr workspace
std::map< DeltaEMode::Type, std::string > index
#define PARALLEL_FOR_NO_WSP_CHECK()
#define PARALLEL_CRITICAL(name)
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
A property class for workspaces.
CalculateDynamicRange Calculates the Qmin and Qmax of SANS workspace, sets to sample logs.
int version() const override
Algorithm's version for identification.
const std::string summary() const override
Algorithm's summary for use in the GUI and help.
void init() override
Initialize the algorithm's properties.
void calculateQMinMax(const API::MatrixWorkspace_sptr &, const std::vector< size_t > &, const std::string &)
Calculates the max and min Q for given list of workspace indices.
std::map< std::string, std::string > validateInputs() override
Validate inputs.
const std::string category() const override
Algorithm's category for identification.
void exec() override
Execute the algorithm.
Support for a property that holds an array of values.
void error(const std::string &msg)
Logs at error level.
void getSpherical(double &R, double &theta, double &phi) const noexcept
Return the vector's position in spherical coordinates.
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
@ InOut
Both an input & output workspace.