21#include <boost/math/special_functions/round.hpp>
28using namespace Kernel;
30using namespace DataObjects;
31using namespace Geometry;
43 std::make_shared<InstrumentValidator>()),
44 "A workspace containing one or more rectangular area "
45 "detectors. Each spectrum needs to correspond to only one "
46 "pixelID (e.g. no grouping or previous calls to "
49 "The name of the workspace that will be created. Can replace "
50 "the input workspace.");
51 declareProperty(
"XMin", -2,
"Minimum of X (col) Range to mask peak relative to peak's center");
52 declareProperty(
"XMax", 2,
"Maximum of X (col) Range to mask peak relative to peak's center");
53 declareProperty(
"YMin", -2,
"Minimum of Y (row) Range to mask peak relative to peak's center");
54 declareProperty(
"YMax", 2,
"Maximum of Y (row) Range to mask peak relative to peak's center");
56 "Optional(all TOF if not specified): "
57 "Minimum TOF relative to peak's "
60 "Optional(all TOF if not specified): "
61 "Maximum TOF relative to peak's "
77 const auto &componentInfo =
m_inputW->componentInfo();
81 tablews->addColumn(
"double",
"XMin");
82 tablews->addColumn(
"double",
"XMax");
83 tablews->addColumn(
"str",
"SpectraList");
86 const std::vector<Peak> &peaks = peaksW->getPeaks();
88 for (
int i = 0; i < static_cast<int>(peaks.size()); i++) {
90 const Peak &peak = peaks[i];
92 double col = peak.
getCol();
93 double row = peak.getRow();
94 int xPeak = boost::math::iround(col) - 1;
95 int yPeak = boost::math::iround(row) - 1;
96 g_log.
debug() <<
"Generating information for peak at x=" << xPeak <<
" y=" << yPeak <<
"\n";
99 const string &bankName = peak.getBankName();
100 if (bankName ==
"None")
104 bankIndex = componentInfo.indexOfAny(bankName);
105 }
catch (std::invalid_argument &) {
106 g_log.
debug() <<
"Component " + bankName +
" does not exist in instrument\n";
113 bool tofRangeSet(
false);
114 size_t wi = this->
getWkspIndex(pixel_to_wi, bankIndex, xPeak, yPeak);
115 if (wi !=
static_cast<size_t>(
EMPTY_INT())) {
121 std::set<size_t> spectra;
125 size_t wj = this->
getWkspIndex(pixel_to_wi, bankIndex, xPeak + ix, yPeak + iy);
126 if (wj ==
static_cast<size_t>(
EMPTY_INT()))
138 g_log.
warning() <<
"Failed to set time-of-flight range for peak (x=" << xPeak <<
", y=" << yPeak
139 <<
", tof=" << peak.getTOF() <<
")\n";
140 }
else if (spectra.empty()) {
141 g_log.
warning() <<
"Failed to find spectra for peak (x=" << xPeak <<
", y=" << yPeak <<
", tof=" << peak.getTOF()
156 maskbinstb->setProperty(
"InputWorkspace",
m_inputW);
157 maskbinstb->setPropertyValue(
"OutputWorkspace",
m_inputW->getName());
158 maskbinstb->setProperty(
"MaskingInformation", tablews);
159 maskbinstb->execute();
168 throw std::runtime_error(
"Must specify Xmin<Xmax");
173 throw std::runtime_error(
"Must specify Ymin<Ymax");
180 throw std::runtime_error(
"Must specify TOFMin < TOFMax");
183 throw std::runtime_error(
"Must specify both TOFMin and TOFMax or neither");
189 const auto &componentInfo =
m_inputW->componentInfo();
191 if (componentInfo.isGridDetector(bankIndex)) {
192 const auto &detectorInfo =
m_inputW->detectorInfo();
193 const auto grid = componentInfo.pixelGridComponent(bankIndex);
194 if (
x >= grid.nX || x < 0 || y >= grid.nY ||
y < 0) {
201 int pixelID = detectorInfo.detid(componentInfo.detectorIndexAtXYZ(bankIndex,
x,
y, 0));
204 auto wiEntry = pixel_to_wi.find(pixelID);
205 if (wiEntry == pixel_to_wi.end()) {
206 std::stringstream msg;
207 msg <<
"Failed to find workspace index for x=" <<
x <<
" y=" <<
y;
208 throw std::runtime_error(msg.str());
210 return wiEntry->second;
212 auto children = componentInfo.children(bankIndex);
214 auto grandchildren = componentInfo.children(children[0]);
216 auto NROWS =
static_cast<int>(grandchildren.size());
217 auto NCOLS =
static_cast<int>(children.size());
219 std::ostringstream msg;
220 if (
m_inputW->getInstrumentName() ==
"CORELLI") {
221 msg <<
"Instrument is CORELLI\n";
223 auto greatgrandchildren = componentInfo.children(grandchildren[0]);
225 NCOLS =
static_cast<int>(grandchildren.size());
226 NROWS =
static_cast<int>(greatgrandchildren.size());
228 msg <<
"Instrument is WISH\n";
232 if (
x - 1 >= NCOLS ||
x - 1 < 0 ||
y - 1 >= NROWS ||
y - 1 < 0) {
241 std::string bankName = componentInfo.name(bankIndex);
243 if (it == pixel_to_wi.end())
257 const HistogramData::HistogramX &tof) {
258 tofMin = tof.front();
259 tofMax = tof.back() - 1;
277 auto const &componentInfo =
m_inputW->componentInfo();
278 size_t const parentIndex = componentInfo.indexOfAny(bankName);
279 if (componentInfo.isGridDetector(parentIndex)) {
280 auto const &detectorInfo =
m_inputW->detectorInfo();
281 return detectorInfo.detid(componentInfo.detectorIndexAtXYZ(parentIndex, col, row, 0));
282 }
else if (
m_inputW->getInstrumentName() ==
"CORELLI") {
287 std::ostringstream pixelString;
288 pixelString << componentInfo.name(parentIndex)
293 std::shared_ptr<const Geometry::IComponent> component = Iptr->getComponentByName(pixelString.str());
294 std::shared_ptr<const Detector> pixel = std::dynamic_pointer_cast<const Detector>(component);
296 return pixel->getID();
298 std::string bankName0 = bankName;
300 bankName0.erase(0, 4);
301 std::ostringstream pixelString;
302 pixelString <<
m_inputW->getInstrumentName() <<
"/" << bankName0 <<
"/" << bankName <<
"/tube" << std::setw(3)
303 << std::setfill(
'0') << col <<
"/pixel" << std::setw(4) << std::setfill(
'0') << row;
305 std::shared_ptr<const Geometry::IComponent> component = Iptr->getComponentByName(pixelString.str());
306 std::shared_ptr<const Detector> pixel = std::dynamic_pointer_cast<const Detector>(component);
307 return pixel->getID();
#define DECLARE_ALGORITHM(classname)
#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.
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.
virtual 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)
Create a Child Algorithm.
static bool isEmpty(const NumT toCheck)
checks that the value was not set by users, uses the value in empty double/int.
TableRow represents a row in a TableWorkspace.
A property class for workspaces.
double m_tofMin
The start of the box around the peak in tof.
int findPixelID(const std::string &bankName, int col, int row)
void init() override
Initialisation method.
int m_xMin
The start of the X range for fitting.
int m_yMax
The end of the Y range for fitting.
std::size_t getWkspIndex(const detid2index_map &pixel_to_wi, const size_t bankIndex, const int x, const int y)
void exec() override
Executes the algorithm.
double m_tofMax
The end of the box around the peak in tof.
void getTofRange(double &tofMin, double &tofMax, const double tofPeak, const HistogramData::HistogramX &tof)
MaskPeaksWorkspace()
Default constructor.
API::MatrixWorkspace_sptr m_inputW
A pointer to the input workspace.
void retrieveProperties()
Read in all the input parameters.
int m_xMax
The end of the X range for fitting.
int m_yMin
The start of the Y range for fitting.
Structure describing a single-crystal peak.
int getCol() const override
For RectangularDetectors only, returns the column (x) of the pixel of the detector or -1 if not found...
void debug(const std::string &msg)
Logs at debug level.
void warning(const std::string &msg)
Logs at warning level.
std::shared_ptr< const PeaksWorkspace > PeaksWorkspace_const_sptr
Typedef for a shared pointer to a const peaks workspace.
std::shared_ptr< TableWorkspace > TableWorkspace_sptr
shared pointer to Mantid::DataObjects::TableWorkspace
std::shared_ptr< const Instrument > Instrument_const_sptr
Shared pointer to an const instrument object.
std::string toString(const T &value)
Convert a number to a string.
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.
std::unordered_map< detid_t, size_t > detid2index_map
Map with key = detector ID, value = workspace index.
constexpr double EMPTY_DBL() noexcept
Returns what we consider an "empty" double within a property.
@ Input
An input workspace.