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 {
35 ~RemoveFileAtScopeExit() {
37 auto const path = std::filesystem::path(name);
38 if (std::filesystem::exists(path)) {
39 std::filesystem::remove(path);
47 double min{std::numeric_limits<double>::max()};
48 double max{std::numeric_limits<double>::lowest()};
59 for (
size_t i = 0; i < nHisto; ++i) {
60 auto const &
x = ws.
x(i);
61 mm.min = std::min(mm.min,
x.front());
62 mm.max = std::max(mm.max,
x.back());
73 auto const &
x = ws.
x(0);
82std::string ensureXMLExtension(std::string
const &filename) {
83 std::string
name = filename;
84 auto const path = std::filesystem::path(filename);
85 if (path.extension() !=
".xml") {
108 return "Calculates the intensity as a function of scattering angle and time "
115 auto histogrammedTOF = std::make_shared<Kernel::CompositeValidator>();
116 histogrammedTOF->add(std::make_shared<API::WorkspaceUnitValidator>(
"TOF"));
117 histogrammedTOF->add(std::make_shared<API::HistogramValidator>());
118 histogrammedTOF->add(std::make_shared<API::InstrumentValidator>());
121 "A workspace to be converted.");
123 "A workspace with (2theta, TOF) units.");
124 auto positiveDouble = std::make_shared<Kernel::BoundedValidator<double>>();
125 positiveDouble->setLowerExclusive(0.);
126 declareProperty(Prop::ANGLE_STEP,
EMPTY_DBL(), positiveDouble,
"The angle step for detector grouping, in degrees.");
128 std::vector<std::string>{
".xml"}),
129 "A grouping file that will be created; a corresponding .par "
130 "file wille be created as well.");
142 setProperty(Prop::OUTPUT_WS, ws);
146 if (!isDefault(Prop::ANGLE_STEP)) {
151 throw std::invalid_argument(
"Missing " + Prop::ANGLE_STEP);
154 auto const paramValues = paramMap.
getDouble(instrument->getName(),
"natural-angle-step");
155 if (paramValues.empty()) {
156 throw std::invalid_argument(
"Missing " + Prop::ANGLE_STEP +
157 " or 'natural-angle-step' not defined in "
158 "instrument parameters file.");
160 return paramValues.front();
166 toConstantL2->setProperty(
"InputWorkspace", ws);
167 toConstantL2->setPropertyValue(
"OutputWorkspace",
"out");
168 toConstantL2->execute();
169 return toConstantL2->getProperty(
"OutputWorkspace");
174 convertAxis->setProperty(
"InputWorkspace", ws);
175 convertAxis->setProperty(
"OutputWorkspace",
"out");
176 convertAxis->setProperty(
"Target",
"Theta");
177 convertAxis->execute();
178 return convertAxis->getProperty(
"OutputWorkspace");
182 const std::string GROUP_WS(
"softwothetatof_groupWS");
184 generateGrouping->setProperty(
"InputWorkspace", ws);
185 generateGrouping->setProperty(
"AngleStep", twoThetaStep);
186 generateGrouping->setProperty(
"GroupingWorkspace", GROUP_WS);
187 std::string filename;
188 RemoveFileAtScopeExit deleteThisLater;
189 if (isDefault(Prop::FILENAME)) {
190 const std::string shortname =
"detector-grouping-" + randomString(4) +
"-" + randomString(4) +
"-" +
191 randomString(4) +
"-" + randomString(4) +
".xml";
192 const auto tempPath = std::filesystem::temp_directory_path() / shortname;
193 filename = tempPath.string();
194 generateGrouping->setProperty(
"GenerateParFile",
false);
196 deleteThisLater.name = filename;
198 filename =
static_cast<std::string
>(
getProperty(Prop::FILENAME));
199 filename = ensureXMLExtension(filename);
201 generateGrouping->setProperty(
"GroupingFilename", filename);
202 generateGrouping->execute();
205 groupDetectors->setProperty(
"InputWorkspace", ws);
206 groupDetectors->setProperty(
"OutputWorkspace",
"out");
210 groupDetectors->setProperty(
"MapFile", filename);
211 groupDetectors->setProperty(
"Behaviour",
"Average");
212 groupDetectors->execute();
213 return groupDetectors->getProperty(
"OutputWorkspace");
219 maskNonOverlapping->setProperty(
"InputWorkspace", maskable);
220 maskNonOverlapping->setProperty(
"OutputWorkspace",
"out");
221 maskNonOverlapping->setProperty(
"ComparisonWorkspace", comparison);
222 maskNonOverlapping->setProperty(
"MaskPartiallyOverlapping",
true);
223 maskNonOverlapping->setProperty(
"RaggedInputs",
"Ragged");
224 maskNonOverlapping->setProperty(
"CheckSortedX",
false);
225 maskNonOverlapping->execute();
226 return maskNonOverlapping->getProperty(
"OutputWorkspace");
230 auto const xRange = minMaxX(*ws);
231 std::vector<double>
const rebinParams{xRange.min, binWidth(*ws), xRange.max};
233 rebin->setProperty(
"InputWorkspace", ws);
234 rebin->setProperty(
"OutputWorkspace",
"out");
235 rebin->setProperty(
"Params", rebinParams);
236 rebin->setProperty(
"FullBinsOnly",
true);
238 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.