BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
IntensityDataFunctions.h
Go to the documentation of this file.
1 // ************************************************************************** //
2 //
3 // BornAgain: simulate and fit scattering at grazing incidence
4 //
5 //! @file Device/Instrument/IntensityDataFunctions.h
6 //! @brief Defines class IntensityDataFunctions.
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_CORE_INTENSITY_INTENSITYDATAFUNCTIONS_H
16 #define BORNAGAIN_CORE_INTENSITY_INTENSITYDATAFUNCTIONS_H
17 
18 #include "Device/Data/OutputData.h"
19 #include <memory>
20 
21 class IHistogram;
22 class SimulationResult;
23 class Simulation;
24 
25 //! Functions to work with intensity data.
26 //! @ingroup tools
27 
29 {
30 //! Returns sum of relative differences between each pair of elements:
31 //! (a, b) -> 2*abs(a - b)/(a + b) ( and zero if a-b=0 )
32 double RelativeDifference(const SimulationResult& dat, const SimulationResult& ref);
33 
34 //! Returns relative difference between two data sets sum(dat[i] - ref[i])/ref[i]).
35 double getRelativeDifference(const OutputData<double>& dat, const OutputData<double>& ref);
36 
37 //! Returns true is relative difference is below threshold; prints informative output
39  const double threshold);
40 
41 double getRelativeDifference(const IHistogram& dat, const IHistogram& ref);
42 
43 //! Transforms coordinate on axis into the bin-fraction-coordinate.
44 double coordinateToBinf(double coordinate, const IAxis& axis);
45 
46 //! Transforms bin-fraction-coordinate into axis coordinate.
47 double coordinateFromBinf(double value, const IAxis& axis);
48 
49 //! Transforms x,y coordinate from OutputData axes coordinates to bin-fraction-coordinates.
50 void coordinateToBinf(double& x, double& y, const OutputData<double>& data);
51 
52 //! Transforms x,y coordinate from bin-fraction-coordinates to OutputData's axes coordinates.
53 void coordinateFromBinf(double& x, double& y, const OutputData<double>& data);
54 
55 //! Creates a vector of vectors of double (2D Array) from OutputData.
56 std::vector<std::vector<double>> create2DArrayfromOutputData(const OutputData<double>& data);
57 
58 //! Creates a Fourier Transform of a 2D Array (vector of vectors).
59 std::vector<std::vector<double>> FT2DArray(const std::vector<std::vector<double>>& signal);
60 
61 #ifndef SWIG
62 
63 std::unique_ptr<OutputData<double>>
65 
66 //! Returns new object with input data rotated by
67 //! n*90 deg counterclockwise (n > 0) or clockwise (n < 0)
68 //! Axes are swapped if the data is effectively rotated by 90 or 270 degrees
69 //! Applicable to 2D arrays only
70 std::unique_ptr<OutputData<double>> createRearrangedDataSet(const OutputData<double>& data, int n);
71 
72 //! Returns new IntensityData objects which axes clipped to represent the specified rectangle.
73 std::unique_ptr<OutputData<double>>
74 createClippedDataSet(const OutputData<double>& origin, double x1, double y1, double x2, double y2);
75 
76 //! Creates OutputData from a 2D Array.
77 std::unique_ptr<OutputData<double>>
78 createOutputDatafrom2DArray(const std::vector<std::vector<double>>& array_2d);
79 
80 //! Creates Fourier Transform (OutputData format) of intensity map (OutputData format).
81 std::unique_ptr<OutputData<double>> createFFT(const OutputData<double>& data);
82 
83 #endif // SWIG
84 
85 }; // namespace IntensityDataFunctions
86 
87 #endif // BORNAGAIN_CORE_INTENSITY_INTENSITYDATAFUNCTIONS_H
Defines and implements template class OutputData.
Interface for one-dimensional axes.
Definition: IAxis.h:25
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.
Pure virtual base class of OffSpecularSimulation, GISASSimulation and SpecularSimulation.
Definition: Simulation.h:38
Functions to work with intensity data.
double getRelativeDifference(const OutputData< double > &dat, const OutputData< double > &ref)
Returns relative difference between two data sets sum(dat[i] - ref[i])/ref[i]).
std::unique_ptr< OutputData< double > > createFFT(const OutputData< double > &data)
Creates Fourier Transform (OutputData format) of intensity map (OutputData format).
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...
std::unique_ptr< OutputData< double > > createClippedDataSet(const OutputData< double > &origin, double x1, double y1, double x2, double y2)
Returns new IntensityData objects which axes clipped to represent the specified rectangle.
std::unique_ptr< OutputData< double > > createRelativeDifferenceData(const OutputData< double > &data, const OutputData< double > &reference)
double coordinateToBinf(double coordinate, const IAxis &axis)
Transforms coordinate on axis into the bin-fraction-coordinate.
std::unique_ptr< OutputData< double > > createRearrangedDataSet(const OutputData< double > &data, int n)
Returns new object with input data rotated by n*90 deg counterclockwise (n > 0) or clockwise (n < 0) ...
bool checkRelativeDifference(const OutputData< double > &dat, const OutputData< double > &ref, const double threshold)
Returns true is relative difference is below threshold; prints informative output.
std::vector< std::vector< double > > create2DArrayfromOutputData(const OutputData< double > &data)
Creates a vector of vectors of double (2D Array) from OutputData.
double coordinateFromBinf(double value, const IAxis &axis)
Transforms bin-fraction-coordinate into axis coordinate.
std::unique_ptr< OutputData< double > > createOutputDatafrom2DArray(const std::vector< std::vector< double >> &array_2d)
Creates OutputData from a 2D Array.
std::vector< std::vector< double > > FT2DArray(const std::vector< std::vector< double >> &signal)
Creates a Fourier Transform of a 2D Array (vector of vectors).