Mantid
Loading...
Searching...
No Matches
FilterPeaks.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2012 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
11#include "MantidCrystal/DllConfig.h"
12
13namespace Mantid {
14namespace Crystal {
15
19class MANTID_CRYSTAL_DLL FilterPeaks final : public API::Algorithm {
20public:
21 const std::string name() const override;
23 const std::string summary() const override {
24 return "Filters the peaks in a peaks workspace based upon the valur of a "
25 "chosen variable.";
26 }
27
28 int version() const override;
29 const std::vector<std::string> seeAlso() const override { return {"CreatePeaksWorkspace"}; }
30 const std::string category() const override;
31
32private:
34 using FilterFunction = std::function<double(const Geometry::IPeak &)>;
35 using FilterFunctionStr = std::function<std::string(const Geometry::IPeak &)>;
36
38 void init() override;
40 void exec() override;
41
43 FilterFunction getFilterVariableFunction(const std::string &filterVariable) const;
44
58 template <typename Comparator>
60 const FilterFunction &filterFunction, const double filterValue) {
61 Comparator operatorFunc;
62 for (int i = 0; i < inputWS.getNumberPeaks(); ++i) {
63 const Geometry::IPeak &currentPeak = inputWS.getPeak(i);
64 const auto currentValue = filterFunction(currentPeak);
65
66 if (operatorFunc(currentValue, filterValue))
67 filteredWS.addPeak(currentPeak);
68 }
69 }
70
83 template <typename Comparator>
85 const FilterFunctionStr &filterFunction, const std::string &filterValue) {
86 Comparator operatorFunc;
87 for (int i = 0; i < inputWS.getNumberPeaks(); ++i) {
88 const Geometry::IPeak &currentPeak = inputWS.getPeak(i);
89 const auto currentValue = filterFunction(currentPeak);
90
91 if (operatorFunc(currentValue, filterValue))
92 filteredWS.addPeak(currentPeak);
93 }
94 }
95};
96
97} // namespace Crystal
98} // namespace Mantid
Base class from which all concrete algorithm classes should be derived.
Definition: Algorithm.h:85
Interface to the class Mantid::DataObjects::PeaksWorkspace.
virtual Mantid::Geometry::IPeak & getPeak(int peakNum)=0
Return a reference to the Peak.
virtual void addPeak(const Mantid::Geometry::IPeak &ipeak)=0
Add a peak to the list.
virtual int getNumberPeaks() const =0
FilterPeaks : Filter a peaks workspace based on a set number of queries to provide a new,...
Definition: FilterPeaks.h:19
void filterPeaks(const Mantid::API::IPeaksWorkspace &inputWS, Mantid::API::IPeaksWorkspace &filteredWS, const FilterFunction &filterFunction, const double filterValue)
Filter the input peaks workspace using a comparator and a value selection function.
Definition: FilterPeaks.h:59
const std::vector< std::string > seeAlso() const override
Function to return all of the seeAlso (these are not validated) algorithms related to this algorithm....
Definition: FilterPeaks.h:29
std::function< double(const Geometry::IPeak &)> FilterFunction
Typedef for the function to get the variable we're filtering against.
Definition: FilterPeaks.h:34
const std::string summary() const override
Summary of algorithms purpose.
Definition: FilterPeaks.h:23
std::function< std::string(const Geometry::IPeak &)> FilterFunctionStr
Definition: FilterPeaks.h:35
void filterPeaksStr(const Mantid::API::IPeaksWorkspace &inputWS, Mantid::API::IPeaksWorkspace &filteredWS, const FilterFunctionStr &filterFunction, const std::string &filterValue)
Select peaks from the input peak workspace by checking a string value.
Definition: FilterPeaks.h:84
Structure describing a single-crystal peak.
Definition: IPeak.h:26
Helper class which provides the Collimation Length for SANS instruments.