Mantid
Loading...
Searching...
No Matches
SumNeighbours.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7//----------------------------------------------------------------------
8// Includes
9//----------------------------------------------------------------------
18
19#include <boost/algorithm/string.hpp>
20
21namespace Mantid::Algorithms {
22
23// Register the class into the algorithm factory
24DECLARE_ALGORITHM(SumNeighbours)
25
26using namespace Kernel;
27using namespace Geometry;
28using namespace API;
29using namespace DataObjects;
30
36 "InputWorkspace", "", Direction::Input, std::make_shared<InstrumentValidator>()),
37 "A workspace containing one or more rectangular area "
38 "detectors. Each spectrum needs to correspond to only one "
39 "pixelID (e.g. no grouping or previous calls to "
40 "SumNeighbours).");
41
42 declareProperty(std::make_unique<WorkspaceProperty<MatrixWorkspace>>("OutputWorkspace", "", Direction::Output),
43 "The name of the workspace to be created as the output of "
44 "the algorithm.");
45
46 auto mustBePositive = std::make_shared<BoundedValidator<int>>();
47 mustBePositive->setLower(1);
48
49 declareProperty("SumX", 4, mustBePositive,
50 "The number of X (horizontal) pixels to sum together. This "
51 "must evenly divide the number of X pixels in a detector.");
52
53 declareProperty("SumY", 4, mustBePositive,
54 "The number of Y (vertical) pixels to sum together. This "
55 "must evenly divide the number of Y pixels in a detector");
56}
57
62 // Try and retrieve the optional properties
63 int SumX = getProperty("SumX");
64 int SumY = getProperty("SumY");
65
66 // Get the input workspace
67 Mantid::API::MatrixWorkspace_sptr inWS = getProperty("InputWorkspace");
68 const auto &componentInfo = inWS->componentInfo();
69 const auto &spectrumInfo = inWS->spectrumInfo();
70 const auto &det = spectrumInfo.detector(0);
71 // Check if grandparent is a Rectangular/Grid detector
72 const size_t detIndex = componentInfo.indexOf(det.getComponentID());
73 const size_t parentIndex = componentInfo.parent(detIndex);
74 const size_t grandparentIndex = componentInfo.parent(parentIndex);
75 const bool rect = componentInfo.isGridDetector(grandparentIndex);
76
78
79 Progress progress(this, 0.0, 1.0, 2);
80
81 progress.report("Smoothing Neighbours...");
82
83 auto smooth = createChildAlgorithm("SmoothNeighbours");
84 smooth->setProperty("InputWorkspace", inWS);
85 if (rect) {
86 smooth->setProperty("SumPixelsX", SumX);
87 smooth->setProperty("SumPixelsY", SumY);
88 } else {
89 smooth->setProperty<std::string>("RadiusUnits", "NumberOfPixels");
90 smooth->setProperty("Radius", static_cast<double>(SumX * SumY * SumX * SumY));
91 smooth->setProperty("NumberOfNeighbours", SumX * SumY * SumX * SumY * 4);
92 smooth->setProperty("SumNumberOfNeighbours", SumX * SumY);
93 }
94 smooth->executeAsChildAlg();
95
96 progress.report();
97 // Get back the result
98 outWS = smooth->getProperty("OutputWorkspace");
99 // Cast to the matrixOutputWS and save it
100 this->setProperty("OutputWorkspace", outWS);
101}
102
103} // namespace Mantid::Algorithms
#define DECLARE_ALGORITHM(classname)
Definition Algorithm.h:542
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.
void progress(double p, const std::string &msg="", double estimatedTime=0.0, int progressPrecision=0)
Sends ProgressNotification.
Helper class for reporting progress from algorithms.
Definition Progress.h:25
A property class for workspaces.
void exec() override
Executes the algorithm.
void init() override
Initialisation method.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
HistogramData::Histogram smooth(const HistogramData::Histogram &histogram, unsigned int const npts)
@ Input
An input workspace.
Definition Property.h:53
@ Output
An output workspace.
Definition Property.h:54