26std::string
const ANGLE_STEP{
"AngleStep"};
27std::string
const FILENAME{
"GroupingFilename"};
28std::string
const INPUT_WS{
"InputWorkspace"};
29std::string
const OUTPUT_WS{
"OutputWorkspace"};
33struct RemoveFileAtScopeExit {
34 explicit RemoveFileAtScopeExit(std::string filename =
"") :
name(
std::move(filename)) {}
36 ~RemoveFileAtScopeExit() {
38 auto const path = std::filesystem::path(name);
39 if (std::filesystem::exists(path)) {
40 std::filesystem::remove(path);
48 double min{std::numeric_limits<double>::max()};
49 double max{std::numeric_limits<double>::lowest()};
60 for (
size_t i = 0; i < nHisto; ++i) {
61 auto const &
x = ws.
x(i);
62 mm.min = std::min(mm.min,
x.front());
63 mm.max = std::max(mm.max,
x.back());
74 auto const &
x = ws.
x(0);
83std::string ensureXMLExtension(std::string
const &filename) {
84 std::string
name = filename;
85 auto const path = std::filesystem::path(filename);
86 if (path.extension() !=
".xml") {
109 return "Calculates the intensity as a function of scattering angle and time "
116 auto histogrammedTOF = std::make_shared<Kernel::CompositeValidator>();
117 histogrammedTOF->add(std::make_shared<API::WorkspaceUnitValidator>(
"TOF"));
118 histogrammedTOF->add(std::make_shared<API::HistogramValidator>());
119 histogrammedTOF->add(std::make_shared<API::InstrumentValidator>());
122 "A workspace to be converted.");
124 "A workspace with (2theta, TOF) units.");
125 auto positiveDouble = std::make_shared<Kernel::BoundedValidator<double>>();
126 positiveDouble->setLowerExclusive(0.);
127 declareProperty(Prop::ANGLE_STEP,
EMPTY_DBL(), positiveDouble,
"The angle step for detector grouping, in degrees.");
129 std::vector<std::string>{
".xml"}),
130 "A grouping file that will be created; a corresponding .par "
131 "file wille be created as well.");
143 setProperty(Prop::OUTPUT_WS, ws);
147 if (!isDefault(Prop::ANGLE_STEP)) {
152 throw std::invalid_argument(
"Missing " + Prop::ANGLE_STEP);
155 auto const paramValues = paramMap.
getDouble(instrument->getName(),
"natural-angle-step");
156 if (paramValues.empty()) {
157 throw std::invalid_argument(
"Missing " + Prop::ANGLE_STEP +
158 " or 'natural-angle-step' not defined in "
159 "instrument parameters file.");
161 return paramValues.front();
167 toConstantL2->setProperty(
"InputWorkspace", ws);
168 toConstantL2->setPropertyValue(
"OutputWorkspace",
"out");
169 toConstantL2->execute();
170 return toConstantL2->getProperty(
"OutputWorkspace");
175 convertAxis->setProperty(
"InputWorkspace", ws);
176 convertAxis->setProperty(
"OutputWorkspace",
"out");
177 convertAxis->setProperty(
"Target",
"Theta");
178 convertAxis->execute();
179 return convertAxis->getProperty(
"OutputWorkspace");
183 const std::string GROUP_WS(
"softwothetatof_groupWS");
185 generateGrouping->setProperty(
"InputWorkspace", ws);
186 generateGrouping->setProperty(
"AngleStep", twoThetaStep);
187 generateGrouping->setProperty(
"GroupingWorkspace", GROUP_WS);
188 std::string filename;
189 RemoveFileAtScopeExit deleteThisLater;
190 if (isDefault(Prop::FILENAME)) {
191 const std::string shortname =
"detector-grouping-" + randomString(4) +
"-" + randomString(4) +
"-" +
192 randomString(4) +
"-" + randomString(4) +
".xml";
193 const auto tempPath = std::filesystem::temp_directory_path() / shortname;
194 filename = tempPath.string();
195 generateGrouping->setProperty(
"GenerateParFile",
false);
197 deleteThisLater = RemoveFileAtScopeExit(filename);
199 filename =
static_cast<std::string
>(
getProperty(Prop::FILENAME));
200 filename = ensureXMLExtension(filename);
202 generateGrouping->setProperty(
"GroupingFilename", filename);
203 generateGrouping->execute();
206 groupDetectors->setProperty(
"InputWorkspace", ws);
207 groupDetectors->setProperty(
"OutputWorkspace",
"out");
211 groupDetectors->setProperty(
"MapFile", filename);
212 groupDetectors->setProperty(
"Behaviour",
"Average");
213 groupDetectors->execute();
214 return groupDetectors->getProperty(
"OutputWorkspace");
220 maskNonOverlapping->setProperty(
"InputWorkspace", maskable);
221 maskNonOverlapping->setProperty(
"OutputWorkspace",
"out");
222 maskNonOverlapping->setProperty(
"ComparisonWorkspace", comparison);
223 maskNonOverlapping->setProperty(
"MaskPartiallyOverlapping",
true);
224 maskNonOverlapping->setProperty(
"RaggedInputs",
"Ragged");
225 maskNonOverlapping->setProperty(
"CheckSortedX",
false);
226 maskNonOverlapping->execute();
227 return maskNonOverlapping->getProperty(
"OutputWorkspace");
231 auto const xRange = minMaxX(*ws);
232 std::vector<double>
const rebinParams{xRange.min, binWidth(*ws), xRange.max};
234 rebin->setProperty(
"InputWorkspace", ws);
235 rebin->setProperty(
"OutputWorkspace",
"out");
236 rebin->setProperty(
"Params", rebinParams);
237 rebin->setProperty(
"FullBinsOnly",
true);
239 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
const std::string FILENAME("Filename")
MANTID_KERNEL_DLL std::string randomString(const size_t len)
Generates random alpha-numeric string.
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.