18#include "boost/filesystem.hpp"
23std::string
const ANGLE_STEP{
"AngleStep"};
24std::string
const FILENAME{
"GroupingFilename"};
25std::string
const INPUT_WS{
"InputWorkspace"};
26std::string
const OUTPUT_WS{
"OutputWorkspace"};
30struct RemoveFileAtScopeExit {
32 ~RemoveFileAtScopeExit() {
34 auto const path = boost::filesystem::path(name);
35 if (boost::filesystem::exists(path)) {
36 boost::filesystem::remove(path);
44 double min{std::numeric_limits<double>::max()};
45 double max{std::numeric_limits<double>::lowest()};
56 for (
size_t i = 0; i < nHisto; ++i) {
57 auto const &
x = ws.
x(i);
58 mm.min = std::min(mm.min,
x.front());
59 mm.max = std::max(mm.max,
x.back());
70 auto const &
x = ws.
x(0);
79std::string ensureXMLExtension(std::string
const &filename) {
80 std::string name = filename;
81 auto const path = boost::filesystem::path(filename);
82 if (path.extension() !=
".xml") {
105 return "Calculates the intensity as a function of scattering angle and time "
112 auto histogrammedTOF = std::make_shared<Kernel::CompositeValidator>();
113 histogrammedTOF->add(std::make_shared<API::WorkspaceUnitValidator>(
"TOF"));
114 histogrammedTOF->add(std::make_shared<API::HistogramValidator>());
115 histogrammedTOF->add(std::make_shared<API::InstrumentValidator>());
118 "A workspace to be converted.");
120 "A workspace with (2theta, TOF) units.");
121 auto positiveDouble = std::make_shared<Kernel::BoundedValidator<double>>();
122 positiveDouble->setLowerExclusive(0.);
123 declareProperty(Prop::ANGLE_STEP,
EMPTY_DBL(), positiveDouble,
"The angle step for detector grouping, in degrees.");
125 std::vector<std::string>{
".xml"}),
126 "A grouping file that will be created; a corresponding .par "
127 "file wille be created as well.");
139 setProperty(Prop::OUTPUT_WS, ws);
143 if (!isDefault(Prop::ANGLE_STEP)) {
148 throw std::invalid_argument(
"Missing " + Prop::ANGLE_STEP);
151 auto const paramValues = paramMap.
getDouble(instrument->getName(),
"natural-angle-step");
152 if (paramValues.empty()) {
153 throw std::invalid_argument(
"Missing " + Prop::ANGLE_STEP +
154 " or 'natural-angle-step' not defined in "
155 "instrument parameters file.");
157 return paramValues.front();
163 toConstantL2->setProperty(
"InputWorkspace", ws);
164 toConstantL2->setPropertyValue(
"OutputWorkspace",
"out");
165 toConstantL2->execute();
166 return toConstantL2->getProperty(
"OutputWorkspace");
171 convertAxis->setProperty(
"InputWorkspace", ws);
172 convertAxis->setProperty(
"OutputWorkspace",
"out");
173 convertAxis->setProperty(
"Target",
"Theta");
174 convertAxis->execute();
175 return convertAxis->getProperty(
"OutputWorkspace");
180 generateGrouping->setProperty(
"InputWorkspace", ws);
181 generateGrouping->setProperty(
"AngleStep", twoThetaStep);
182 std::string filename;
183 RemoveFileAtScopeExit deleteThisLater;
184 if (isDefault(Prop::FILENAME)) {
185 auto tempPath = boost::filesystem::temp_directory_path();
186 tempPath /= boost::filesystem::unique_path(
"detector-grouping-%%%%-%%%%-%%%%-%%%%.xml");
187 filename = tempPath.string();
188 generateGrouping->setProperty(
"GenerateParFile",
false);
191 deleteThisLater.name = filename;
193 filename =
static_cast<std::string
>(
getProperty(Prop::FILENAME));
194 filename = ensureXMLExtension(filename);
196 generateGrouping->setProperty(
"GroupingFilename", filename);
197 generateGrouping->execute();
199 groupDetectors->setProperty(
"InputWorkspace", ws);
200 groupDetectors->setProperty(
"OutputWorkspace",
"out");
201 groupDetectors->setProperty(
"MapFile", filename);
202 groupDetectors->setProperty(
"Behaviour",
"Average");
203 groupDetectors->execute();
204 return groupDetectors->getProperty(
"OutputWorkspace");
210 maskNonOverlapping->setProperty(
"InputWorkspace", maskable);
211 maskNonOverlapping->setProperty(
"OutputWorkspace",
"out");
212 maskNonOverlapping->setProperty(
"ComparisonWorkspace", comparison);
213 maskNonOverlapping->setProperty(
"MaskPartiallyOverlapping",
true);
214 maskNonOverlapping->setProperty(
"RaggedInputs",
"Ragged");
215 maskNonOverlapping->setProperty(
"CheckSortedX",
false);
216 maskNonOverlapping->execute();
217 return maskNonOverlapping->getProperty(
"OutputWorkspace");
221 auto const xRange = minMaxX(*ws);
222 std::vector<double>
const rebinParams{xRange.min, binWidth(*ws), xRange.max};
224 rebin->setProperty(
"InputWorkspace", ws);
225 rebin->setProperty(
"OutputWorkspace",
"out");
226 rebin->setProperty(
"Params", rebinParams);
227 rebin->setProperty(
"FullBinsOnly",
true);
229 return rebin->getProperty(
"OutputWorkspace");
#define DECLARE_ALGORITHM(classname)
const Geometry::ParameterMap & constInstrumentParameters() const
Const version.
Geometry::Instrument_const_sptr getInstrument() const
Returns the parameterized instrument.
@ OptionalSave
to specify a file to write to but an empty string is
std::shared_ptr< Algorithm > createChildAlgorithm(const std::string &name, const double startProgress=-1., const double endProgress=-1., const bool enableLogging=true, const int &version=-1) override
Create a Child Algorithm.
Kernel::IPropertyManager::TypedValue getProperty(const std::string &name) const override
Get the property held by this object.
Base MatrixWorkspace Abstract Class.
virtual std::size_t getNumberHistograms() const =0
Returns the number of histograms in the workspace.
const HistogramData::HistogramX & x(const size_t index) const
A property class for workspaces.
std::vector< double > getDouble(const std::string &compName, const std::string &name) const
Returns a double parameter as vector's first element if exists and an empty vector if it doesn't.
SofTwoThetaTOF : Convert a S(spectrum number, TOF) workspace to S(twoTheta, TOF) workspace.
API::MatrixWorkspace_sptr convertToTwoTheta(API::MatrixWorkspace_sptr &ws)
const std::string category() const override
Algorithm's category for identification.
API::MatrixWorkspace_sptr maskEmptyBins(API::MatrixWorkspace_sptr &maskable, API::MatrixWorkspace_sptr &comparison)
void init() override
Initialize the algorithm's properties.
int version() const override
Algorithm's version for identification.
void exec() override
Execute the algorithm.
API::MatrixWorkspace_sptr groupByTwoTheta(API::MatrixWorkspace_sptr &ws, double const twoThetaStep)
const std::string summary() const override
Algorithm's summary for use in the GUI and help.
API::MatrixWorkspace_sptr rebinToNonRagged(API::MatrixWorkspace_sptr &ws)
API::MatrixWorkspace_sptr convertToConstantL2(API::MatrixWorkspace_sptr &ws)
double clarifyAngleStep(API::MatrixWorkspace const &ws)
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
constexpr double EMPTY_DBL() noexcept
Returns what we consider an "empty" double within a property.
String constants for algorithm's properties.
@ Input
An input workspace.
@ Output
An output workspace.