Mantid
Loading...
Searching...
No Matches
SmoothNeighbours.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2007 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#pragma once
8
9//----------------------------------------------------------------------
10// Includes
11//----------------------------------------------------------------------
12#include "MantidAPI/Algorithm.h"
13#include "MantidAlgorithms/DllConfig.h"
17
18namespace Mantid {
19namespace Algorithms {
20using SpectraDistanceMap = std::map<specnum_t, Mantid::Kernel::V3D>;
21
22/*
23Filters spectra detector list by radius.
24*/
25class MANTID_ALGORITHMS_DLL RadiusFilter {
26public:
31 RadiusFilter(double cutoff) : m_cutoff(cutoff) {
32 if (cutoff < 0) {
33 throw std::invalid_argument("RadiusFilter - Cannot have a negative cutoff.");
34 }
35 }
42 SpectraDistanceMap neighbSpectra;
43 double cutoff{m_cutoff};
44 std::copy_if(unfiltered.begin(), unfiltered.end(), std::inserter(neighbSpectra, neighbSpectra.end()),
45 [cutoff](const std::pair<specnum_t, Mantid::Kernel::V3D> &spectraDistance) {
46 return spectraDistance.second.norm() <= cutoff;
47 });
48 return neighbSpectra;
49 }
50
51private:
53 double m_cutoff;
54};
55
61class MANTID_ALGORITHMS_DLL SmoothNeighbours final : public API::Algorithm {
62public:
66 const std::string name() const override { return "SmoothNeighbours"; }
68 const std::string summary() const override {
69 return "Perform a moving-average smoothing by summing spectra of nearest "
70 "neighbours over the face of detectors.";
71 }
72
74 int version() const override { return (1); }
75 const std::vector<std::string> seeAlso() const override { return {"SmoothData"}; }
77 const std::string category() const override { return "Transforms\\Smoothing"; }
78
79private:
80 // Overridden Algorithm methods
81 void init() override;
82 void exec() override;
83
84 void execWorkspace2D();
86 void findNeighboursRectangular();
87 void findNeighboursUbiquitous();
88
90 void setWeightingStrategy(const std::string &strategyName, double &cutOff);
92 double translateToMeters(const std::string &radiusUnits, const double &enteredRadius) const;
93
95 void setupNewInstrument(API::MatrixWorkspace &outWS) const;
96
98 void spreadPixels(const API::MatrixWorkspace_sptr &outWS);
99
101 int m_adjX = 0;
103 int m_adjY = 0;
105 int m_edge = 0;
107 double m_radius = 0.0;
109 int m_nNeighbours = 0;
111 std::unique_ptr<WeightingStrategy> m_weightedSum;
113 bool m_preserveEvents = false;
115 bool m_expandSumAllPixels = false;
117 size_t m_outWI = 0;
121 using weightedNeighbour = std::pair<size_t, double>;
123 std::vector<std::vector<weightedNeighbour>> m_neighbours;
125 std::unique_ptr<Mantid::API::Progress> m_progress = nullptr;
126};
127
128} // namespace Algorithms
129} // namespace Mantid
Base class from which all concrete algorithm classes should be derived.
Definition: Algorithm.h:85
Base MatrixWorkspace Abstract Class.
SpectraDistanceMap apply(SpectraDistanceMap &unfiltered) const
Apply the filtering based on radius.
RadiusFilter(double cutoff)
Constructor.
Smooth neighboring pixels.
std::vector< std::vector< weightedNeighbour > > m_neighbours
Vector of list of neighbours (with weight) for each workspace index.
std::unique_ptr< WeightingStrategy > m_weightedSum
Weight the neighbours during summing.
const std::vector< std::string > seeAlso() const override
Function to return all of the seeAlso algorithms related to this algorithm.
const std::string name() const override
Algorithm's name for identification overriding a virtual method.
std::pair< size_t, double > weightedNeighbour
Each neighbours is specified as a pair with workspace index, weight.
Mantid::API::MatrixWorkspace_sptr m_inWS
Input workspace.
const std::string category() const override
Algorithm's category for identification overriding a virtual method.
int version() const override
Algorithm's version for identification overriding a virtual method.
const std::string summary() const override
Summary of algorithms purpose.
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
std::map< specnum_t, Mantid::Kernel::V3D > SpectraDistanceMap
std::shared_ptr< EventWorkspace > EventWorkspace_sptr
shared pointer to the EventWorkspace class
Helper class which provides the Collimation Length for SANS instruments.