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//----------------------------------------------------------------------
19
20#include <boost/algorithm/string.hpp>
21
22namespace Mantid::Algorithms {
23
24// Register the class into the algorithm factory
25DECLARE_ALGORITHM(SumNeighbours)
26
27using namespace Kernel;
28using namespace Geometry;
29using namespace API;
30using namespace DataObjects;
31
37 "InputWorkspace", "", Direction::Input, std::make_shared<InstrumentValidator>()),
38 "A workspace containing one or more rectangular area "
39 "detectors. Each spectrum needs to correspond to only one "
40 "pixelID (e.g. no grouping or previous calls to "
41 "SumNeighbours).");
42
43 declareProperty(std::make_unique<WorkspaceProperty<MatrixWorkspace>>("OutputWorkspace", "", Direction::Output),
44 "The name of the workspace to be created as the output of "
45 "the algorithm.");
46
47 auto mustBePositive = std::make_shared<BoundedValidator<int>>();
48 mustBePositive->setLower(1);
49
50 declareProperty("SumX", 4, mustBePositive,
51 "The number of X (horizontal) pixels to sum together. This "
52 "must evenly divide the number of X pixels in a detector.");
53
54 declareProperty("SumY", 4, mustBePositive,
55 "The number of Y (vertical) pixels to sum together. This "
56 "must evenly divide the number of Y pixels in a detector");
57}
58
63 // Try and retrieve the optional properties
64 int SumX = getProperty("SumX");
65 int SumY = getProperty("SumY");
66
67 // Get the input workspace
68 Mantid::API::MatrixWorkspace_sptr inWS = getProperty("InputWorkspace");
69 const auto &spectrumInfo = inWS->spectrumInfo();
70 const auto &det = spectrumInfo.detector(0);
71 // Check if grandparent is rectangular detector
72 std::shared_ptr<const Geometry::IComponent> parent = det.getParent();
73 std::shared_ptr<const RectangularDetector> rect;
74
75 if (parent) {
76 rect = std::dynamic_pointer_cast<const RectangularDetector>(parent->getParent());
77 }
78
80
81 Progress progress(this, 0.0, 1.0, 2);
82
83 progress.report("Smoothing Neighbours...");
84
85 auto smooth = createChildAlgorithm("SmoothNeighbours");
86 smooth->setProperty("InputWorkspace", inWS);
87 if (rect) {
88 smooth->setProperty("SumPixelsX", SumX);
89 smooth->setProperty("SumPixelsY", SumY);
90 } else {
91 smooth->setProperty<std::string>("RadiusUnits", "NumberOfPixels");
92 smooth->setProperty("Radius", static_cast<double>(SumX * SumY * SumX * SumY));
93 smooth->setProperty("NumberOfNeighbours", SumX * SumY * SumX * SumY * 4);
94 smooth->setProperty("SumNumberOfNeighbours", SumX * SumY);
95 }
96 smooth->executeAsChildAlg();
97
98 progress.report();
99 // Get back the result
100 outWS = smooth->getProperty("OutputWorkspace");
101 // Cast to the matrixOutputWS and save it
102 this->setProperty("OutputWorkspace", outWS);
103}
104
105} // namespace Mantid::Algorithms
#define DECLARE_ALGORITHM(classname)
Definition: Algorithm.h:576
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
Definition: Algorithm.cpp:1913
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
Definition: Algorithm.cpp:2076
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.
Definition: Algorithm.cpp:842
void progress(double p, const std::string &msg="", double estimatedTime=0.0, int progressPrecision=0)
Sends ProgressNotification.
Definition: Algorithm.cpp:231
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, int npts)
@ Input
An input workspace.
Definition: Property.h:53
@ Output
An output workspace.
Definition: Property.h:54