20#include <boost/math/special_functions/round.hpp>
27using namespace Kernel;
29using namespace DataObjects;
30using namespace Geometry;
42 std::make_shared<InstrumentValidator>()),
43 "A workspace containing one or more rectangular area "
44 "detectors. Each spectrum needs to correspond to only one "
45 "pixelID (e.g. no grouping or previous calls to "
48 "The name of the workspace that will be created. Can replace "
49 "the input workspace.");
50 declareProperty(
"XMin", -2,
"Minimum of X (col) Range to mask peak relative to peak's center");
51 declareProperty(
"XMax", 2,
"Maximum of X (col) Range to mask peak relative to peak's center");
52 declareProperty(
"YMin", -2,
"Minimum of Y (row) Range to mask peak relative to peak's center");
53 declareProperty(
"YMax", 2,
"Maximum of Y (row) Range to mask peak relative to peak's center");
55 "Optional(all TOF if not specified): "
56 "Minimum TOF relative to peak's "
59 "Optional(all TOF if not specified): "
60 "Maximum TOF relative to peak's "
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 g_log.
debug() <<
"Component " + bankName +
" does not exist in instrument\n";
111 bool tofRangeSet(
false);
112 size_t wi = this->
getWkspIndex(pixel_to_wi, comp, xPeak, yPeak);
113 if (wi !=
static_cast<size_t>(
EMPTY_INT())) {
119 std::set<size_t> spectra;
123 size_t wj = this->
getWkspIndex(pixel_to_wi, comp, xPeak + ix, yPeak + iy);
124 if (wj ==
static_cast<size_t>(
EMPTY_INT()))
136 g_log.
warning() <<
"Failed to set time-of-flight range for peak (x=" << xPeak <<
", y=" << yPeak
137 <<
", tof=" << peak.getTOF() <<
")\n";
138 }
else if (spectra.empty()) {
139 g_log.
warning() <<
"Failed to find spectra for peak (x=" << xPeak <<
", y=" << yPeak <<
", tof=" << peak.getTOF()
154 maskbinstb->setProperty(
"InputWorkspace",
m_inputW);
155 maskbinstb->setPropertyValue(
"OutputWorkspace",
m_inputW->getName());
156 maskbinstb->setProperty(
"MaskingInformation", tablews);
157 maskbinstb->execute();
166 throw std::runtime_error(
"Must specify Xmin<Xmax");
171 throw std::runtime_error(
"Must specify Ymin<Ymax");
178 throw std::runtime_error(
"Must specify TOFMin < TOFMax");
181 throw std::runtime_error(
"Must specify both TOFMin and TOFMax or neither");
186 const int x,
const int y) {
191 if (
x >= det->xpixels() || x < 0 || y >= det->ypixels() ||
y < 0) {
198 int pixelID = det->getAtXY(
x,
y)->getID();
201 auto wiEntry = pixel_to_wi.find(pixelID);
202 if (wiEntry == pixel_to_wi.end()) {
203 std::stringstream msg;
204 msg <<
"Failed to find workspace index for x=" <<
x <<
" y=" <<
y;
205 throw std::runtime_error(msg.str());
207 return wiEntry->second;
209 const auto &componentInfo =
m_inputW->componentInfo();
210 const size_t compIndex = componentInfo.indexOfAny(comp->getName());
211 auto children = componentInfo.children(compIndex);
213 auto grandchildren = componentInfo.children(children[0]);
215 auto NROWS =
static_cast<int>(grandchildren.size());
216 auto NCOLS =
static_cast<int>(children.size());
218 std::ostringstream msg;
219 if (Iptr->getName().compare(
"CORELLI") == 0) {
220 msg <<
"Instrument is CORELLI\n";
222 auto greatgrandchildren = componentInfo.children(grandchildren[0]);
224 NCOLS =
static_cast<int>(grandchildren.size());
225 NROWS =
static_cast<int>(greatgrandchildren.size());
227 msg <<
"Instrument is WISH\n";
231 if (
x - 1 >= NCOLS ||
x - 1 < 0 ||
y - 1 >= NROWS ||
y - 1 < 0) {
240 std::string bankName = comp->getName();
242 if (it == pixel_to_wi.end())
256 const HistogramData::HistogramX &tof) {
257 tofMin = tof.front();
258 tofMax = tof.back() - 1;
277 std::shared_ptr<const IComponent> parent = Iptr->getComponentByName(bankName);
279 if (parent->type() ==
"RectangularDetector") {
280 std::shared_ptr<const RectangularDetector> RDet = std::dynamic_pointer_cast<const RectangularDetector>(parent);
282 std::shared_ptr<Detector> pixel = RDet->getAtXY(col, row);
283 return pixel->getID();
284 }
else if (Iptr->getName().compare(
"CORELLI") == 0) {
289 std::ostringstream pixelString;
290 pixelString << parent->getFullName()
294 std::shared_ptr<const Geometry::IComponent> component = Iptr->getComponentByName(pixelString.str());
295 std::shared_ptr<const Detector> pixel = std::dynamic_pointer_cast<const Detector>(component);
297 return pixel->getID();
299 std::string bankName0 = bankName;
301 bankName0.erase(0, 4);
302 std::ostringstream pixelString;
303 pixelString << Iptr->getName() <<
"/" << bankName0 <<
"/" << bankName <<
"/tube" << std::setw(3)
304 << 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)
std::size_t getWkspIndex(const detid2index_map &pixel_to_wi, const Geometry::IComponent_const_sptr &comp, const int x, const int y)
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.
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 IComponent > IComponent_const_sptr
Typdef of a shared pointer to a const IComponent.
std::shared_ptr< const RectangularDetector > RectangularDetector_const_sptr
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.