Mantid
Loading...
Searching...
No Matches
FindPeaks.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2008 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
12#include "MantidAlgorithms/DllConfig.h"
14#include "MantidIndexing/SpectrumIndexSet.h"
16
17namespace Mantid {
18
19namespace HistogramData {
20class Histogram;
21class HistogramX;
22class HistogramY;
23} // namespace HistogramData
24
25namespace Algorithms {
50class MANTID_ALGORITHMS_DLL FindPeaks : public API::ParallelAlgorithm {
51public:
53 FindPeaks();
55 ~FindPeaks() override = default;
57 const std::string name() const override { return "FindPeaks"; }
59 const std::string summary() const override { return "Searches for peaks in a dataset."; }
60
62 int version() const override { return (1); }
63 const std::vector<std::string> seeAlso() const override { return {"MatchPeaks", "FindPeaksMD", "GeneratePeaks"}; }
65 const std::string category() const override { return "Optimization\\PeakFinding"; }
67 int getIndex(const HistogramData::HistogramX &vecX, double x);
68
69private:
70 void init() override;
71 void exec() override;
72
74 void processAlgorithmProperties();
75
77 void findPeaksUsingMariscotti();
78
80 void findPeaksGivenStartingPoints(const std::vector<double> &peakcentres, const std::vector<double> &fitwindows);
81
83 std::vector<HistogramData::Histogram> calculateSecondDifference(const API::MatrixWorkspace_const_sptr &input);
84 void smoothData(std::vector<HistogramData::Histogram> &histograms, const int w, const int g_z);
85 void calculateStandardDeviation(const API::MatrixWorkspace_const_sptr &input,
86 std::vector<HistogramData::Histogram> &smoothed, const int &w);
87 long long computePhi(const int &w) const;
88
90 void fitPeakInWindow(const API::MatrixWorkspace_sptr &input, const int spectrum, const double centre_guess,
91 const double xmin, const double xmax);
92
94 void fitPeakGivenFWHM(const API::MatrixWorkspace_sptr &input, const int spectrum, const double center_guess,
95 const int fitWidth, const bool hasleftpeak, const double leftpeakcentre,
96 const bool hasrightpeak, const double rightpeakcentre);
97
100 void fitSinglePeak(const API::MatrixWorkspace_sptr &input, const int spectrum, const int i_min, const int i_max,
101 const int i_centre);
102
103 void fitPeakHighBackground(const API::MatrixWorkspace_sptr &input, const size_t spectrum, int i_centre, int i_min,
104 int i_max, double &in_bg0, double &in_bg1, double &in_bg2, int i_peakmin, int i_peakmax);
105
106 void fitPeakOneStep(const API::MatrixWorkspace_sptr &input, const int spectrum, const int &i0, const int &i2,
107 const int &i4, const double &in_bg0, const double &in_bg1, const double &in_bg2);
108
111 void addInfoRow(const size_t spectrum, const API::IPeakFunction_const_sptr &peakfunction,
112 const API::IBackgroundFunction_sptr &bkgdfunction, const bool isoutputraw, const double mincost);
113
115 void addNonFitRecord(const size_t spectrum, const double centre);
116
118 void createFunctions();
119
121 int findPeakBackground(const API::MatrixWorkspace_sptr &input, int spectrum, size_t i_min, size_t i_max,
122 std::vector<double> &vecBkgdParamValues, std::vector<double> &vecpeakrange);
123
125 void estimateBackground(const HistogramData::HistogramX &X, const HistogramData::HistogramY &Y, const size_t i_min,
126 const size_t i_max, std::vector<double> &vecbkgdparvalues);
127
129 void estimatePeakRange(const HistogramData::HistogramX &vecX, size_t i_centre, size_t i_min, size_t i_max,
130 const double &leftfwhm, const double &rightfwhm, std::vector<double> &vecpeakrange);
131
133 std::string estimatePeakParameters(const HistogramData::HistogramX &vecX, const HistogramData::HistogramY &vecY,
134 size_t i_min, size_t i_max, const std::vector<double> &vecbkgdparvalues,
135 size_t &iobscentre, double &height, double &fwhm, double &leftfwhm,
136 double &rightfwhm);
137
139 void generateOutputPeakParameterTable();
140
141 std::vector<double> getStartingPeakValues();
142 std::vector<double> getStartingBkgdValues();
143
145 double callFitPeak(const API::MatrixWorkspace_sptr &dataws, int wsindex, const API::IPeakFunction_sptr &peakfunction,
146 const API::IBackgroundFunction_sptr &backgroundfunction, const std::vector<double> &vec_fitwindow,
147 const std::vector<double> &vec_peakrange, int minGuessFWHM, int maxGuessFWHM, int guessedFWHMStep,
148 int estBackResult = 0);
149
150 std::vector<std::string> m_peakParameterNames;
151 std::vector<std::string> m_bkgdParameterNames;
153
156 static const int g_z = 5;
157
161 std::unique_ptr<API::Progress> m_progress = nullptr;
162
163 // Properties saved in the algo.
166 Indexing::SpectrumIndexSet m_indexSet;
172 std::size_t m_numTableParams; //<Number of parameters in the output table workspace
173 std::size_t m_centreIndex; //< Column in output table of peak centre
174 std::string m_peakFuncType; //< The name of the peak function to fit
175 std::string m_backgroundType; //< The type of background to fit
176
177 // Peaks positions
178 std::vector<double> m_vecPeakCentre;
179 std::vector<double> m_vecFitWindows;
180
181 // Functions for reused
184
188
191
192 std::vector<API::IFunction_sptr> m_fitFunctions;
193 std::vector<size_t> m_peakLeftIndexes;
194 std::vector<size_t> m_peakRightIndexes;
195
196 std::string m_minimizer;
197 std::string m_costFunction;
198
203
206};
207
208} // namespace Algorithms
209} // namespace Mantid
double height
Definition: GetAllEi.cpp:155
Base class for algorithms that can run in parallel on all MPI ranks but not in a distributed fashion.
This algorithm searches for peaks in a dataset.
Definition: FindPeaks.h:50
const std::vector< std::string > seeAlso() const override
Function to return all of the seeAlso algorithms related to this algorithm.
Definition: FindPeaks.h:63
Indexing::SpectrumIndexSet m_indexSet
list of workspace indicies to check
Definition: FindPeaks.h:166
API::ITableWorkspace_sptr m_outPeakTableWS
Storage of the peak data.
Definition: FindPeaks.h:159
std::vector< size_t > m_peakRightIndexes
Definition: FindPeaks.h:194
const std::string category() const override
Algorithm's category for identification.
Definition: FindPeaks.h:65
const std::string summary() const override
Summary of algorithms purpose.
Definition: FindPeaks.h:59
API::IBackgroundFunction_sptr m_backgroundFunction
Definition: FindPeaks.h:182
bool m_useObsCentre
Start values.
Definition: FindPeaks.h:205
std::vector< double > m_vecPeakCentre
Definition: FindPeaks.h:178
const std::string name() const override
Algorithm's name.
Definition: FindPeaks.h:57
void fitPeakOneStep(const API::MatrixWorkspace_sptr &input, const int spectrum, const int &i0, const int &i2, const int &i4, const double &in_bg0, const double &in_bg1, const double &in_bg2)
API::MatrixWorkspace_sptr m_dataWS
workspace to check for peaks
Definition: FindPeaks.h:164
double m_leastMaxObsY
Minimum value of peak's observed maximum Y value.
Definition: FindPeaks.h:202
double m_minHeight
Minimum peak height.
Definition: FindPeaks.h:200
API::IPeakFunction_sptr m_peakFunction
Definition: FindPeaks.h:183
void fitPeakHighBackground(const API::MatrixWorkspace_sptr &input, const size_t spectrum, int i_centre, int i_min, int i_max, double &in_bg0, double &in_bg1, double &in_bg2, int i_peakmin, int i_peakmax)
std::size_t m_numTableParams
parameters or effective (centre, width, height)
Definition: FindPeaks.h:172
~FindPeaks() override=default
Virtual destructor.
std::vector< double > m_vecFitWindows
Definition: FindPeaks.h:179
std::vector< API::IFunction_sptr > m_fitFunctions
Definition: FindPeaks.h:192
std::vector< double > getStartingBkgdValues()
bool m_highBackground
flag for find relatively weak peak in high
Definition: FindPeaks.h:168
int version() const override
Algorithm's version.
Definition: FindPeaks.h:62
std::vector< std::string > m_bkgdParameterNames
Definition: FindPeaks.h:151
std::vector< std::string > m_peakParameterNames
Definition: FindPeaks.h:150
bool m_rawPeaksTable
background
Definition: FindPeaks.h:170
std::vector< size_t > m_peakLeftIndexes
Definition: FindPeaks.h:193
int m_inputPeakFWHM
holder for the requested peak FWHM
Definition: FindPeaks.h:165
std::shared_ptr< IBackgroundFunction > IBackgroundFunction_sptr
std::shared_ptr< IPeakFunction > IPeakFunction_sptr
std::shared_ptr< ITableWorkspace > ITableWorkspace_sptr
shared pointer to Mantid::API::ITableWorkspace
std::shared_ptr< const IPeakFunction > IPeakFunction_const_sptr
std::shared_ptr< const MatrixWorkspace > MatrixWorkspace_const_sptr
shared pointer to the matrix workspace base class (const version)
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
MANTID_ALGORITHMS_DLL int estimatePeakParameters(const HistogramData::Histogram &histogram, const std::pair< size_t, size_t > &peak_window, const API::IPeakFunction_sptr &peakfunction, const API::IBackgroundFunction_sptr &bkgdfunction, bool observe_peak_width, const EstimatePeakWidth peakWidthEstimateApproach, const double peakWidthPercentage, const double minPeakHeight)
Estimate peak parameters by 'observation'.
size_t getIndex(const HistogramData::HistogramX &vecx, double x)
Get an index of a value in a sorted vector.
Helper class which provides the Collimation Length for SANS instruments.