13#include "MantidIndexing/IndexInfo.h"
38using namespace Kernel;
43 :
API::
Algorithm(), m_MinRange(DBL_MAX), m_MaxRange(-DBL_MAX), m_MinWsIndex(0), m_MaxWsIndex(0) {}
49 auto wsValidation = std::make_shared<CompositeValidator>();
52 auto unitValidation = std::make_shared<CompositeValidator>(CompositeRelation::OR);
56 wsValidation->add(unitValidation);
59 "The name of the Workspace2D to take as input");
62 auto mustBePositive = std::make_shared<BoundedValidator<int>>();
63 mustBePositive->setLower(0);
64 declareProperty(
"StartWorkspaceIndex", 0, mustBePositive,
"Start workspace index (default 0)");
66 "End workspace index (default to total number of histograms)");
71 auto mustBePositiveDouble = std::make_shared<BoundedValidator<double>>();
72 mustBePositiveDouble->setLower(0.0);
76 std::make_shared<StringListValidator>(peakFindingStrategy),
77 "Different options for peak finding."
78 "1. StrongestPeakOnly: Looks only for the the strongest peak in each "
79 "spectrum (provided there is "
80 "one). This options is more performant than the AllPeaks option.\n"
81 "2. AllPeaks: This strategy will find all peaks in each "
82 "spectrum. This is slower than StrongestPeakOnly. Note that the "
83 "recommended ResolutionStrategy in this mode is AbsoluteResolution.\n");
87 "Multiplication factor for the signal background. Peaks which are"
88 " below the estimated background are discarded. The background is "
90 " to be an average of the first and the last signal and multiplied"
91 " by the SignalBackground property.\n");
94 "Peaks which are below the specified absolute background are discarded."
95 " The background is gloabally specified for all spectra. Inspect your "
96 "data in the InstrumentView to get a good feeling for the background "
98 "Background thresholds which are too low will mistake noise for peaks.");
106 std::make_unique<EnabledWhenProperty>(
110 const std::string peakGroup =
"Peak Finding Settings";
121 std::make_shared<StringListValidator>(resolutionStrategy),
122 "Different options for the resolution."
123 "1. RelativeResolution: This defines a relative tolerance "
124 "needed to avoid peak duplication in number of pixels. "
125 "This selection will enable the Resolution property and "
126 "disable the XResolution, PhiResolution, ThetaResolution.\n"
127 "1. AbsoluteResolution: This defines an absolute tolerance "
128 "needed to avoid peak duplication in number of pixels. "
129 "This selection will disable the Resolution property and "
130 "enable the XResolution, PhiResolution, "
131 "ThetaResolution.\n");
134 "Tolerance needed to avoid peak duplication in number of pixels");
137 "Absolute tolerance in time-of-flight or d-spacing needed to avoid peak "
138 "duplication in number of pixels. The values are specified "
139 "in either microseconds or angstroms.");
142 "Absolute tolerance in the phi "
143 "coordinate needed to avoid peak "
144 "duplication in number of pixels. The "
145 "values are specified in degrees.");
148 "Absolute tolerance of two theta value needed to avoid peak "
149 "duplication in number of pixels. The values are specified "
170 "The name of the PeaksWorkspace in which to store the list "
174 const std::string resolutionGroup =
"Resolution Settings";
192 std::map<std::string, std::string> validationOutput;
193 const std::string resolutionStrategy =
getProperty(
"ResolutionStrategy");
199 validationOutput[
"XResolution"] =
"XResolution must be set to a value greater than 0";
202 return validationOutput;
223 m_peaks->setInstrument(localworkspace->getInstrument());
225 size_t numberOfSpectra = localworkspace->getNumberHistograms();
233 throw std::invalid_argument(
"Cannot have StartWorkspaceIndex > EndWorkspaceIndex");
238 g_log.
warning(
"EndSpectrum out of range! Set to max detector number");
242 g_log.
warning(
"Range_upper is less than Range_lower. Will integrate up to "
250 const auto &spectrumInfo = localworkspace->spectrumInfo();
257 auto peakFindingStrategy =
268 const auto wsIndexSize_t =
static_cast<size_t>(wsIndex);
269 if (!spectrumInfo.hasDetectors(wsIndexSize_t) || spectrumInfo.isMonitor(wsIndexSize_t)) {
274 const auto &
x = localworkspace->x(wsIndex);
275 const auto &
y = localworkspace->y(wsIndex);
278 auto foundPeaks = peakFindingStrategy->findSXPeaks(
x,
y, wsIndex);
283 PARALLEL_CRITICAL(entries) { std::copy(foundPeaks->cbegin(), foundPeaks->cend(), std::back_inserter(entries)); }
304 auto &goniometerMatrix = localworkspace->run().getGoniometer().getR();
307 auto finalv = reductionStrategy->reduce(pcv,
progress);
309 for (
auto &finalPeak : finalv) {
315 peak->setIntensity(finalPeak.getIntensity());
316 peak->setDetectorID(finalPeak.getDetectorId());
317 peak->setGoniometerMatrix(goniometerMatrix);
318 peak->setRunNumber(localworkspace->getRunNumber());
321 }
catch (std::exception &e) {
336 const auto xAxis =
workspace->getAxis(0);
337 const auto unitID = xAxis->unit()->unitID();
339 if (unitID ==
"TOF") {
340 return XAxisUnit::TOF;
342 return XAxisUnit::DSPACING;
347 const std::string peakFindingStrategy =
getProperty(
"PeakFindingStrategy");
349 const double signalBackground =
getProperty(
"SignalBackground");
350 return std::make_unique<PerSpectrumBackgroundStrategy>(signalBackground);
352 const double background =
getProperty(
"AbsoluteBackground");
353 return std::make_unique<AbsoluteBackgroundStrategy>(background);
355 throw std::invalid_argument(
"The selected background strategy has not been implemented yet.");
359std::unique_ptr<FindSXPeaksHelper::PeakFindingStrategy>
363 std::string peakFindingStrategy =
getProperty(
"PeakFindingStrategy");
365 return std::make_unique<StrongestPeaksStrategy>(backgroundStrategy, spectrumInfo,
minValue,
maxValue, tofUnits);
367 return std::make_unique<AllPeaksStrategy>(backgroundStrategy, spectrumInfo,
minValue,
maxValue, tofUnits);
369 throw std::invalid_argument(
"The selected peak finding strategy has not been implemented yet.");
373std::unique_ptr<FindSXPeaksHelper::ReducePeakListStrategy>
375 const std::string peakFindingStrategy =
getProperty(
"PeakFindingStrategy");
377 if (useSimpleReduceStrategy) {
378 return std::make_unique<FindSXPeaksHelper::SimpleReduceStrategy>(compareStrategy);
380 return std::make_unique<FindSXPeaksHelper::FindMaxReduceStrategy>(compareStrategy);
385 const std::string resolutionStrategy =
getProperty(
"ResolutionStrategy");
387 if (useRelativeResolutionStrategy) {
389 return std::make_unique<FindSXPeaksHelper::RelativeCompareStrategy>(resolution);
391 double xUnitResolution =
getProperty(
"XResolution");
392 double phiResolution =
getProperty(
"PhiResolution");
393 double twoThetaResolution =
getProperty(
"TwoThetaResolution");
395 return std::make_unique<FindSXPeaksHelper::AbsoluteCompareStrategy>(xUnitResolution, phiResolution,
396 twoThetaResolution, tofUnits);
#define DECLARE_ALGORITHM(classname)
IPeaksWorkspace_sptr workspace
#define PARALLEL_START_INTERRUPT_REGION
Begins a block to skip processing is the algorithm has been interupted Note the end of the block if n...
#define PARALLEL_CRITICAL(name)
#define PARALLEL_END_INTERRUPT_REGION
Ends a block to skip processing is the algorithm has been interupted Note the start of the block if n...
#define PARALLEL_FOR_IF(condition)
Empty definitions - to enable set your complier to enable openMP.
#define PARALLEL_CHECK_INTERRUPT_REGION
Adds a check after a Parallel region to see if it was interupted.
Base class from which all concrete algorithm classes should be derived.
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
Kernel::Property * getPointerToProperty(const std::string &name) const override
Get a property by name.
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
void progress(double p, const std::string &msg="", double estimatedTime=0.0, int progressPrecision=0)
Sends ProgressNotification.
static bool isEmpty(const NumT toCheck)
checks that the value was not set by users, uses the value in empty double/int.
A validator which checks that a workspace contains histogram data (the default) or point data as requ...
Helper class for reporting progress from algorithms.
API::SpectrumInfo is an intermediate step towards a SpectrumInfo that is part of Instrument-2....
A property class for workspaces.
A validator which checks that the unit of the workspace referred to by a WorkspaceProperty is the exp...
BackgroundStrategy : Abstract class used for identifying elements of a IMDWorkspace that are not cons...
Search detector space for single crystal peaks.
FindSXPeaksHelper::XAxisUnit getWorkspaceXAxisUnit(const Mantid::API::MatrixWorkspace_const_sptr &workspace) const
Check what x units this workspace has.
static const std::string absoluteResolutionPeaksStrategy
Mantid::DataObjects::PeaksWorkspace_sptr m_peaks
size_t m_MaxWsIndex
The spectrum to finish the integration at.
void exec() override
Executes the algorithm.
std::unique_ptr< FindSXPeaksHelper::BackgroundStrategy > getBackgroundStrategy() const
Selects a background strategy.
FindSXPeaks()
Default constructor.
std::unique_ptr< FindSXPeaksHelper::CompareStrategy > getCompareStrategy() const
Selects a comparison strategy.
std::map< std::string, std::string > validateInputs() override
Perform validation of ALL the input properties of the algorithm.
double m_MinRange
The value in X to start the search from.
double m_MaxRange
The value in X to finish the search at.
static const std::string strongestPeakStrategy
static const std::string relativeResolutionStrategy
static const std::string allPeaksStrategy
void init() override
Initialisation method.
void reducePeakList(const peakvector &, Mantid::API::Progress &progress)
Reduce the peak list by removing duplicates then convert SXPeaks objects to PeakObjects and add them ...
size_t m_MinWsIndex
The spectrum to start the integration from.
std::unique_ptr< FindSXPeaksHelper::PeakFindingStrategy > getPeakFindingStrategy(const FindSXPeaksHelper::BackgroundStrategy *backgroundStrategy, const API::SpectrumInfo &spectrumInfo, const double minValue, const double maxValue, const FindSXPeaksHelper::XAxisUnit tofUnits=FindSXPeaksHelper::XAxisUnit::TOF) const
Selects a peak finding strategy.
std::unique_ptr< FindSXPeaksHelper::ReducePeakListStrategy > getReducePeakListStrategy(const FindSXPeaksHelper::CompareStrategy *compareStrategy) const
Selects a peak finding strategy.
Structure describing a single-crystal peak.
The class PeaksWorkspace stores information about a set of SCD peaks.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
void setPropertySettings(const std::string &name, std::unique_ptr< IPropertySettings > settings)
void setPropertyGroup(const std::string &name, const std::string &group)
Set the group for a given property.
void error(const std::string &msg)
Logs at error level.
void warning(const std::string &msg)
Logs at warning level.
std::shared_ptr< const MatrixWorkspace > MatrixWorkspace_const_sptr
shared pointer to the matrix workspace base class (const version)
XAxisUnit
enum to determine the units of the workspaces X axis we are searching in
std::vector< FindSXPeaksHelper::SXPeak > peakvector
std::unique_ptr< Peak > Peak_uptr
std::unique_ptr< IPeak > IPeak_uptr
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.
constexpr int EMPTY_INT() noexcept
Returns what we consider an "empty" integer within a property.
constexpr double EMPTY_DBL() noexcept
Returns what we consider an "empty" double within a property.
@ Input
An input workspace.
@ Output
An output workspace.