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#include "MantidKernel/V3D.h"
18
19namespace Mantid {
20namespace Algorithms {
21using SpectraDistanceMap = std::map<specnum_t, Mantid::Kernel::V3D>;
22
23/*
24Filters spectra detector list by radius.
25*/
26class MANTID_ALGORITHMS_DLL RadiusFilter {
27public:
32 RadiusFilter(double cutoff) : m_cutoff(cutoff) {
33 if (cutoff < 0) {
34 throw std::invalid_argument("RadiusFilter - Cannot have a negative cutoff.");
35 }
36 }
43 SpectraDistanceMap neighbSpectra;
44 double cutoff{m_cutoff};
45 std::copy_if(unfiltered.begin(), unfiltered.end(), std::inserter(neighbSpectra, neighbSpectra.end()),
46 [cutoff](const std::pair<specnum_t, Mantid::Kernel::V3D> &spectraDistance) {
47 return spectraDistance.second.norm() <= cutoff;
48 });
49 return neighbSpectra;
50 }
51
52private:
54 double m_cutoff;
55};
56
62class MANTID_ALGORITHMS_DLL SmoothNeighbours final : public API::Algorithm {
63public:
67 const std::string name() const override { return "SmoothNeighbours"; }
69 const std::string summary() const override {
70 return "Perform a moving-average smoothing by summing spectra of nearest "
71 "neighbours over the face of detectors.";
72 }
73
75 int version() const override { return (1); }
76 const std::vector<std::string> seeAlso() const override { return {"SmoothData"}; }
78 const std::string category() const override { return "Transforms\\Smoothing"; }
79
80private:
81 // Overridden Algorithm methods
82 void init() override;
83 void exec() override;
84
85 void execWorkspace2D();
87 void findNeighboursRectangular();
88 void findNeighboursUbiquitous();
89
91 void setWeightingStrategy(const std::string &strategyName, double &cutOff);
93 double translateToMeters(const std::string &radiusUnits, const double &enteredRadius) const;
94
96 void setupNewInstrument(API::MatrixWorkspace &outWS) const;
97
99 void spreadPixels(const API::MatrixWorkspace_sptr &outWS);
100
102 int m_adjX = 0;
104 int m_adjY = 0;
106 int m_edge = 0;
108 double m_radius = 0.0;
110 int m_nNeighbours = 0;
112 std::unique_ptr<WeightingStrategy> m_weightedSum;
114 bool m_preserveEvents = false;
116 bool m_expandSumAllPixels = false;
118 size_t m_outWI = 0;
122 using weightedNeighbour = std::pair<size_t, double>;
124 std::vector<std::vector<weightedNeighbour>> m_neighbours;
126 std::unique_ptr<Mantid::API::Progress> m_progress = nullptr;
127};
128
129} // namespace Algorithms
130} // namespace Mantid
Base class from which all concrete algorithm classes should be derived.
Definition Algorithm.h:76
Base MatrixWorkspace Abstract Class.
SpectraDistanceMap apply(SpectraDistanceMap &unfiltered) const
Apply the filtering based on radius.
RadiusFilter(double cutoff)
Constructor.
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.