BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
HistoUtils.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Device/Histo/HistoUtils.h
6 //! @brief PyObvject forward declaration.
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
15 #ifndef BORNAGAIN_DEVICE_HISTO_HISTOUTILS_H
16 #define BORNAGAIN_DEVICE_HISTO_HISTOUTILS_H
17 
18 #include "Device/Data/OutputData.h"
19 #include <string>
20 #include <vector>
21 
22 class Histogram2D;
23 class IHistogram;
24 class SimulationResult;
25 
26 //! Collection of utils for 1D and 2D image processing (background, peaks, ets).
27 
28 namespace HistoUtils {
29 
30 //! Returns vector of peak center coordinates, for peaks in given histogram.
31 
32 std::vector<std::pair<double, double>> FindPeaks(const Histogram2D& hist, double sigma = 2,
33  const std::string& option = {},
34  double threshold = 0.05);
35 
36 //! Returns sum of relative differences between each pair of elements:
37 //! (a, b) -> 2*abs(a - b)/(a + b) ( and zero if a-b=0 )
38 double RelativeDifference(const SimulationResult& dat, const SimulationResult& ref);
39 
40 double getRelativeDifference(const IHistogram& dat, const IHistogram& ref);
41 
42 //! Returns true if SimulatioResult agrees with data from reference file
43 bool agreesWithReference(const SimulationResult& dat, const std::string& refFileName, double tol);
44 
45 } // namespace HistoUtils
46 
47 #endif // BORNAGAIN_DEVICE_HISTO_HISTOUTILS_H
Defines and implements templated class OutputData.
Two dimensional histogram.
Definition: Histogram2D.h:24
Base class for 1D and 2D histograms holding values of double type.
Definition: IHistogram.h:27
Wrapper around OutputData<double> that also provides unit conversions.
Collection of utils for 1D and 2D image processing (background, peaks, ets).
Definition: HistoUtils.h:28
std::vector< std::pair< double, double > > FindPeaks(const Histogram2D &hist, double sigma=2, const std::string &option={}, double threshold=0.05)
Returns vector of peak center coordinates, for peaks in given histogram.
Definition: HistoUtils.cpp:25
double getRelativeDifference(const IHistogram &dat, const IHistogram &ref)
Definition: HistoUtils.cpp:73
bool agreesWithReference(const SimulationResult &dat, const std::string &refFileName, double tol)
Returns true if SimulatioResult agrees with data from reference file.
Definition: HistoUtils.cpp:80
double RelativeDifference(const SimulationResult &dat, const SimulationResult &ref)
Returns sum of relative differences between each pair of elements: (a, b) -> 2*abs(a - b)/(a + b) ( a...
Definition: HistoUtils.cpp:60