Commit 9a96ad75 authored by Lynch, Vickie's avatar Lynch, Vickie
Browse files

Refs #20355 reviewer suggested changes

parent a22faa07
...@@ -39,7 +39,7 @@ private: ...@@ -39,7 +39,7 @@ private:
void integrateEvent(); void integrateEvent();
int findPixelID(std::string bankName, int col, int row); int findPixelID(std::string bankName, int col, int row);
void removeEdgePeaks(Mantid::DataObjects::PeaksWorkspace &peakWS); void removeEdgePeaks(Mantid::DataObjects::PeaksWorkspace &peakWS);
void sizeBanks(std::string bankName, int &nCols, int &nRows); void sizeBanks(const std::string &bankName, int &nCols, int &nRows);
Geometry::Instrument_const_sptr inst; Geometry::Instrument_const_sptr inst;
/// Input 2D Workspace /// Input 2D Workspace
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#include "MantidKernel/VectorHelper.h" #include "MantidKernel/VectorHelper.h"
#include "MantidGeometry/Crystal/OrientedLattice.h" #include "MantidGeometry/Crystal/OrientedLattice.h"
#include "MantidGeometry/Crystal/EdgePixel.h" #include "MantidGeometry/Crystal/EdgePixel.h"
#include "MantidGeometry/Instrument/ComponentInfo.h"
#include <boost/algorithm/clamp.hpp>
using Mantid::DataObjects::PeaksWorkspace; using Mantid::DataObjects::PeaksWorkspace;
...@@ -24,27 +26,27 @@ using namespace Mantid::Crystal; ...@@ -24,27 +26,27 @@ using namespace Mantid::Crystal;
/** Initialize the algorithm's properties. /** Initialize the algorithm's properties.
*/ */
void CentroidPeaks::init() { void CentroidPeaks::init() {
declareProperty(make_unique<WorkspaceProperty<PeaksWorkspace>>( declareProperty(make_unique<WorkspaceProperty<PeaksWorkspace> >(
"InPeaksWorkspace", "", Direction::Input), "InPeaksWorkspace", "", Direction::Input),
"A PeaksWorkspace containing the peaks to centroid."); "A PeaksWorkspace containing the peaks to centroid.");
declareProperty( declareProperty(
make_unique<WorkspaceProperty<>>("InputWorkspace", "", Direction::Input), make_unique<WorkspaceProperty<> >("InputWorkspace", "", Direction::Input),
"An input 2D Workspace."); "An input 2D Workspace.");
declareProperty( declareProperty(
make_unique<PropertyWithValue<int>>("PeakRadius", 10, Direction::Input), make_unique<PropertyWithValue<int> >("PeakRadius", 10, Direction::Input),
"Fixed radius around each peak position in which to calculate the " "Fixed radius around each peak position in which to calculate the "
"centroid."); "centroid.");
declareProperty( declareProperty(
make_unique<PropertyWithValue<int>>("EdgePixels", 0, Direction::Input), make_unique<PropertyWithValue<int> >("EdgePixels", 0, Direction::Input),
"The number of pixels where peaks are removed at edges. Only " "The number of pixels where peaks are removed at edges. Only "
"for instruments with RectangularDetectors. "); "for instruments with RectangularDetectors. ");
declareProperty( declareProperty(
make_unique<WorkspaceProperty<PeaksWorkspace>>("OutPeaksWorkspace", "", make_unique<WorkspaceProperty<PeaksWorkspace> >("OutPeaksWorkspace", "",
Direction::Output), Direction::Output),
"The output PeaksWorkspace will be a copy of the input PeaksWorkspace " "The output PeaksWorkspace will be a copy of the input PeaksWorkspace "
"with the peaks' positions modified by the new found centroids."); "with the peaks' positions modified by the new found centroids.");
} }
...@@ -142,14 +144,11 @@ void CentroidPeaks::integrate() { ...@@ -142,14 +144,11 @@ void CentroidPeaks::integrate() {
} }
// Set pixelID to change row and col // Set pixelID to change row and col
row = int(rowcentroid / intensity); row = int(rowcentroid / intensity);
row = std::max(0, row); boost::algorithm::clamp(row, 0, nRows - 1);
row = std::min(nRows - 1, row);
col = int(colcentroid / intensity); col = int(colcentroid / intensity);
col = std::max(0, col); boost::algorithm::clamp(col, 0, nCols - 1);
col = std::min(nCols - 1, col);
chan = int(chancentroid / intensity); chan = int(chancentroid / intensity);
chan = std::max(0, chan); boost::algorithm::clamp(chan, 0, static_cast<int>(inWS->blocksize()));
chan = std::min(static_cast<int>(inWS->blocksize()), chan);
// Set wavelength to change tof for peak object // Set wavelength to change tof for peak object
if (!edgePixel(inst, bankName, col, row, Edge)) { if (!edgePixel(inst, bankName, col, row, Edge)) {
...@@ -269,11 +268,9 @@ void CentroidPeaks::integrateEvent() { ...@@ -269,11 +268,9 @@ void CentroidPeaks::integrateEvent() {
} }
// Set pixelID to change row and col // Set pixelID to change row and col
row = int(rowcentroid / intensity); row = int(rowcentroid / intensity);
row = std::max(0, row); boost::algorithm::clamp(row, 0, nRows - 1);
row = std::min(nRows - 1, row);
col = int(colcentroid / intensity); col = int(colcentroid / intensity);
col = std::max(0, col); boost::algorithm::clamp(col, 0, nCols - 1);
col = std::min(nCols - 1, col);
if (!edgePixel(inst, bankName, col, row, Edge)) { if (!edgePixel(inst, bankName, col, row, Edge)) {
peak.setDetectorID(findPixelID(bankName, col, row)); peak.setDetectorID(findPixelID(bankName, col, row));
...@@ -344,8 +341,8 @@ int CentroidPeaks::findPixelID(std::string bankName, int col, int row) { ...@@ -344,8 +341,8 @@ int CentroidPeaks::findPixelID(std::string bankName, int col, int row) {
} }
} }
void CentroidPeaks::removeEdgePeaks( void
Mantid::DataObjects::PeaksWorkspace &peakWS) { CentroidPeaks::removeEdgePeaks(Mantid::DataObjects::PeaksWorkspace &peakWS) {
int Edge = getProperty("EdgePixels"); int Edge = getProperty("EdgePixels");
std::vector<int> badPeaks; std::vector<int> badPeaks;
size_t numPeaks = peakWS.getNumberPeaks(); size_t numPeaks = peakWS.getNumberPeaks();
...@@ -363,31 +360,32 @@ void CentroidPeaks::removeEdgePeaks( ...@@ -363,31 +360,32 @@ void CentroidPeaks::removeEdgePeaks(
peakWS.removePeaks(std::move(badPeaks)); peakWS.removePeaks(std::move(badPeaks));
} }
void CentroidPeaks::sizeBanks(std::string bankName, int &nCols, int &nRows) { void CentroidPeaks::sizeBanks(const std::string &bankName, int &nCols,
int &nRows) {
if (bankName == "None") if (bankName == "None")
return; return;
boost::shared_ptr<const IComponent> parent = ExperimentInfo expInfo;
inst->getComponentByName(bankName); expInfo.setInstrument(inst);
if (!parent) const auto &compInfo = expInfo.componentInfo();
return;
if (parent->type() == "RectangularDetector") { // Get a single bank
boost::shared_ptr<const RectangularDetector> RDet = auto bank = inst->getComponentByName(bankName);
boost::dynamic_pointer_cast<const RectangularDetector>(parent); auto bankID = bank->getComponentID();
auto allBankDetectorIndexes =
nCols = RDet->xpixels(); compInfo.detectorsInSubtree(compInfo.indexOf(bankID));
nRows = RDet->ypixels();
} else { nCols = static_cast<int>(allBankDetectorIndexes.size());
std::vector<Geometry::IComponent_const_sptr> children;
boost::shared_ptr<const Geometry::ICompAssembly> asmb = // Get one of the bank rows
boost::dynamic_pointer_cast<const Geometry::ICompAssembly>(parent); auto bankRowID =
asmb->getChildren(children, false); boost::dynamic_pointer_cast<const Mantid::Geometry::ICompAssembly>(bank)
boost::shared_ptr<const Geometry::ICompAssembly> asmb2 = ->getChild(0)
boost::dynamic_pointer_cast<const Geometry::ICompAssembly>(children[0]); ->getComponentID();
std::vector<Geometry::IComponent_const_sptr> grandchildren; auto allRowDetectorIndexes =
asmb2->getChildren(grandchildren, false); compInfo.detectorsInSubtree(compInfo.indexOf(bankRowID));
nRows = static_cast<int>(grandchildren.size());
nCols = static_cast<int>(children.size()); nRows = static_cast<int>(allRowDetectorIndexes.size());
} std::cout << nCols << " " << nRows << "\n";
} }
} // namespace Mantid } // namespace Mantid
......
...@@ -156,13 +156,18 @@ void PeaksWorkspace::removePeak(const int peakNum) { ...@@ -156,13 +156,18 @@ void PeaksWorkspace::removePeak(const int peakNum) {
void PeaksWorkspace::removePeaks(std::vector<int> badPeaks) { void PeaksWorkspace::removePeaks(std::vector<int> badPeaks) {
if (badPeaks.empty()) if (badPeaks.empty())
return; return;
std::sort(badPeaks.begin(), badPeaks.end());
for (int i = static_cast<int>(peaks.size()) - 1; i >= 0; i--) {
// if index of peak is in badPeaks remove // if index of peak is in badPeaks remove
if (std::binary_search(badPeaks.begin(), badPeaks.end(), i)) { int ip = -1;
removePeak(i); auto it = std::remove_if(
} peaks.begin(), peaks.end(), [&ip, badPeaks] (Peak &pk) {
} (void)pk;
ip++;
for (auto ibp = badPeaks.begin(); ibp != badPeaks.end(); ++ibp) {
if (*ibp == ip) return true;
}
return false;
});
peaks.erase(it, peaks.end());
} }
//--------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment