19#include <boost/math/special_functions/round.hpp>
26using namespace Kernel;
28using namespace DataObjects;
29using namespace Geometry;
41 std::make_shared<InstrumentValidator>()),
42 "A workspace containing one or more rectangular area "
43 "detectors. Each spectrum needs to correspond to only one "
44 "pixelID (e.g. no grouping or previous calls to "
47 "The name of the workspace that will be created. Can replace "
48 "the input workspace.");
49 declareProperty(
"XMin", -2,
"Minimum of X (col) Range to mask peak relative to peak's center");
50 declareProperty(
"XMax", 2,
"Maximum of X (col) Range to mask peak relative to peak's center");
51 declareProperty(
"YMin", -2,
"Minimum of Y (row) Range to mask peak relative to peak's center");
52 declareProperty(
"YMax", 2,
"Maximum of Y (row) Range to mask peak relative to peak's center");
54 "Optional(all TOF if not specified): "
55 "Minimum TOF relative to peak's "
58 "Optional(all TOF if not specified): "
59 "Maximum TOF relative to peak's "
80 tablews->addColumn(
"double",
"XMin");
81 tablews->addColumn(
"double",
"XMax");
82 tablews->addColumn(
"str",
"SpectraList");
85 const std::vector<Peak> &peaks = peaksW->getPeaks();
87 for (
int i = 0; i < static_cast<int>(peaks.size()); i++) {
89 const Peak &peak = peaks[i];
91 double col = peak.
getCol();
92 double row = peak.getRow();
93 int xPeak = boost::math::iround(col) - 1;
94 int yPeak = boost::math::iround(row) - 1;
95 g_log.
debug() <<
"Generating information for peak at x=" << xPeak <<
" y=" << yPeak <<
"\n";
98 const string &bankName = peak.getBankName();
99 if (bankName ==
"None")
103 g_log.
debug() <<
"Component " + bankName +
" does not exist in instrument\n";
110 bool tofRangeSet(
false);
111 size_t wi = this->
getWkspIndex(pixel_to_wi, comp, xPeak, yPeak);
112 if (wi !=
static_cast<size_t>(
EMPTY_INT())) {
118 std::set<size_t> spectra;
122 size_t wj = this->
getWkspIndex(pixel_to_wi, comp, xPeak + ix, yPeak + iy);
123 if (wj ==
static_cast<size_t>(
EMPTY_INT()))
135 g_log.
warning() <<
"Failed to set time-of-flight range for peak (x=" << xPeak <<
", y=" << yPeak
136 <<
", tof=" << peak.getTOF() <<
")\n";
137 }
else if (spectra.empty()) {
138 g_log.
warning() <<
"Failed to find spectra for peak (x=" << xPeak <<
", y=" << yPeak <<
", tof=" << peak.getTOF()
153 maskbinstb->setProperty(
"InputWorkspace",
m_inputW);
154 maskbinstb->setPropertyValue(
"OutputWorkspace",
m_inputW->getName());
155 maskbinstb->setProperty(
"MaskingInformation", tablews);
156 maskbinstb->execute();
165 throw std::runtime_error(
"Must specify Xmin<Xmax");
170 throw std::runtime_error(
"Must specify Ymin<Ymax");
177 throw std::runtime_error(
"Must specify TOFMin < TOFMax");
180 throw std::runtime_error(
"Must specify both TOFMin and TOFMax or neither");
185 const int x,
const int y) {
190 if (
x >= det->xpixels() || x < 0 || y >= det->ypixels() ||
y < 0) {
197 int pixelID = det->getAtXY(
x,
y)->getID();
200 auto wiEntry = pixel_to_wi.find(pixelID);
201 if (wiEntry == pixel_to_wi.end()) {
202 std::stringstream msg;
203 msg <<
"Failed to find workspace index for x=" <<
x <<
" y=" <<
y;
204 throw std::runtime_error(msg.str());
206 return wiEntry->second;
208 std::vector<Geometry::IComponent_const_sptr> children;
209 std::shared_ptr<const Geometry::ICompAssembly> asmb =
210 std::dynamic_pointer_cast<const Geometry::ICompAssembly>(comp);
211 asmb->getChildren(children,
false);
213 std::shared_ptr<const Geometry::ICompAssembly> asmb2 =
214 std::dynamic_pointer_cast<const Geometry::ICompAssembly>(children[0]);
215 std::vector<Geometry::IComponent_const_sptr> grandchildren;
216 asmb2->getChildren(grandchildren,
false);
218 auto NROWS =
static_cast<int>(grandchildren.size());
219 auto NCOLS =
static_cast<int>(children.size());
221 std::ostringstream msg;
222 if (Iptr->getName().compare(
"CORELLI") == 0) {
223 msg <<
"Instrument is CORELLI\n";
225 std::shared_ptr<const Geometry::ICompAssembly> asmb3 =
226 std::dynamic_pointer_cast<const Geometry::ICompAssembly>(grandchildren[0]);
227 std::vector<Geometry::IComponent_const_sptr> greatgrandchildren;
228 asmb3->getChildren(greatgrandchildren,
false);
230 NCOLS =
static_cast<int>(grandchildren.size());
231 NROWS =
static_cast<int>(greatgrandchildren.size());
233 msg <<
"Instrument is WISH\n";
237 if (
x - 1 >= NCOLS ||
x - 1 < 0 ||
y - 1 >= NROWS ||
y - 1 < 0) {
246 std::string bankName = comp->getName();
248 if (it == pixel_to_wi.end())
262 const HistogramData::HistogramX &tof) {
263 tofMin = tof.front();
264 tofMax = tof.back() - 1;
283 std::shared_ptr<const IComponent> parent = Iptr->getComponentByName(bankName);
285 if (parent->type() ==
"RectangularDetector") {
286 std::shared_ptr<const RectangularDetector> RDet = std::dynamic_pointer_cast<const RectangularDetector>(parent);
288 std::shared_ptr<Detector> pixel = RDet->getAtXY(col, row);
289 return pixel->getID();
290 }
else if (Iptr->getName().compare(
"CORELLI") == 0) {
295 std::ostringstream pixelString;
296 pixelString << parent->getFullName()
300 std::shared_ptr<const Geometry::IComponent> component = Iptr->getComponentByName(pixelString.str());
301 std::shared_ptr<const Detector> pixel = std::dynamic_pointer_cast<const Detector>(component);
303 return pixel->getID();
305 std::string bankName0 = bankName;
307 bankName0.erase(0, 4);
308 std::ostringstream pixelString;
309 pixelString << Iptr->getName() <<
"/" << bankName0 <<
"/" << bankName <<
"/tube" << std::setw(3)
310 << std::setfill(
'0') << col <<
"/pixel" << std::setw(4) << std::setfill(
'0') << row;
311 std::shared_ptr<const Geometry::IComponent> component = Iptr->getComponentByName(pixelString.str());
312 std::shared_ptr<const Detector> pixel = std::dynamic_pointer_cast<const Detector>(component);
313 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.