BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
SimDataPair.h
Go to the documentation of this file.
1 // ************************************************************************** //
2 //
3 // BornAgain: simulate and fit scattering at grazing incidence
4 //
5 //! @file Core/Fitting/SimDataPair.h
6 //! @brief Defines class SimDataPair.
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_FITTING_SIMDATAPAIR_H
16 #define BORNAGAIN_CORE_FITTING_SIMDATAPAIR_H
17 
18 #include "Core/Fitting/FitTypes.h"
20 
21 template <class T> class OutputData;
22 
23 //! Holds pair of simulation/experimental data to fit.
24 
26 {
27 public:
29  std::unique_ptr<OutputData<double>> uncertainties, double user_weight = 1.0);
30 
32  std::unique_ptr<OutputData<double>> uncertainties,
33  std::unique_ptr<OutputData<double>> user_weights);
34 
35  SimDataPair(SimDataPair&& other);
36 
38 
39  void runSimulation(const Fit::Parameters& params);
40 
41  bool containsUncertainties() const;
42 
43  //! Returns the number of elements in the fit area
44  size_t numberOfFitElements() const;
45 
46  //! Returns the result of last computed simulation
48 
49  //! Returns the experimental data cut to the ROI area
51 
52  //! Returns the data uncertainties cut to the ROI area
53  //! If no uncertainties present, returns zero-filled SimulationResult.
55 
56  //! Returns the user uncertainties cut to the ROI area.
58 
59  //! Returns the relative difference between simulated
60  //! and experimental data cut to the ROI area
62 
63  //! Returns the absolute difference between simulated
64  //! and experimental data cut to the ROI area
66 
67  //! Returns the flattened simulated intensities cut to the ROI area
68  std::vector<double> simulation_array() const;
69 
70  //! Returns the flattened experimental data cut to the ROI area
71  std::vector<double> experimental_array() const;
72 
73  //! Returns the flattened experimental uncertainties
74  //! cut to the ROI area. If no uncertainties are available,
75  //! returns a zero-filled array sized to the ROI area.
76  std::vector<double> uncertainties_array() const;
77 
78  //! Returns a flat array of user weights cut to the ROI area.
79  std::vector<double> user_weights_array() const;
80 
81 private:
82  void initResultArrays();
83  void validate() const;
84 
85  //! Simulation builder from the user to construct simulation for given set of parameters.
87 
88  //! Current simulation for given set of parameters.
89  std::unique_ptr<Simulation> m_simulation;
90 
91  //! Current simulation results. Masked areas are nullified.
93  //! Experimental data cut to the ROI. Masked areas are nullified.
95  //! Weights from experimental data uncertainties. Masked areas are nullified.
97  //! Manually defined (user) weights. Masked areas are nullified.
99 
100  //! Raw experimental data as obtained from the user.
101  std::unique_ptr<OutputData<double>> m_raw_data;
102  //! Data uncertainties as provided by the user
103  std::unique_ptr<OutputData<double>> m_raw_uncertainties;
104  //! User-defined weights
105  std::unique_ptr<OutputData<double>> m_raw_user_weights;
106 };
107 
108 #endif // BORNAGAIN_CORE_FITTING_SIMDATAPAIR_H
Defines common types for fitting library.
std::function< std::unique_ptr< Simulation >(const Fit::Parameters &)> simulation_builder_t
Definition: FitTypes.h:28
Defines class SimulationResult.
A collection of fit parameters.
Definition: Parameters.h:28
Template class to store data of any type in multi-dimensional space.
Definition: OutputData.h:33
Holds pair of simulation/experimental data to fit.
Definition: SimDataPair.h:26
SimulationResult userWeights() const
Returns the user uncertainties cut to the ROI area.
SimulationResult m_sim_data
Current simulation results. Masked areas are nullified.
Definition: SimDataPair.h:92
std::vector< double > experimental_array() const
Returns the flattened experimental data cut to the ROI area.
SimulationResult absoluteDifference() const
Returns the absolute difference between simulated and experimental data cut to the ROI area.
std::unique_ptr< OutputData< double > > m_raw_user_weights
User-defined weights.
Definition: SimDataPair.h:105
std::vector< double > user_weights_array() const
Returns a flat array of user weights cut to the ROI area.
std::vector< double > uncertainties_array() const
Returns the flattened experimental uncertainties cut to the ROI area.
std::vector< double > simulation_array() const
Returns the flattened simulated intensities cut to the ROI area.
SimDataPair(simulation_builder_t builder, const OutputData< double > &data, std::unique_ptr< OutputData< double >> uncertainties, double user_weight=1.0)
Definition: SimDataPair.cpp:39
SimulationResult uncertainties() const
Returns the data uncertainties cut to the ROI area If no uncertainties present, returns zero-filled S...
SimulationResult experimentalData() const
Returns the experimental data cut to the ROI area.
Definition: SimDataPair.cpp:98
bool containsUncertainties() const
Definition: SimDataPair.cpp:81
void validate() const
std::unique_ptr< OutputData< double > > m_raw_data
Raw experimental data as obtained from the user.
Definition: SimDataPair.h:101
void runSimulation(const Fit::Parameters &params)
Definition: SimDataPair.cpp:72
std::unique_ptr< Simulation > m_simulation
Current simulation for given set of parameters.
Definition: SimDataPair.h:89
size_t numberOfFitElements() const
Returns the number of elements in the fit area.
Definition: SimDataPair.cpp:86
SimulationResult relativeDifference() const
Returns the relative difference between simulated and experimental data cut to the ROI area.
SimulationResult simulationResult() const
Returns the result of last computed simulation.
Definition: SimDataPair.cpp:91
void initResultArrays()
SimulationResult m_uncertainties
Weights from experimental data uncertainties. Masked areas are nullified.
Definition: SimDataPair.h:96
SimulationResult m_exp_data
Experimental data cut to the ROI. Masked areas are nullified.
Definition: SimDataPair.h:94
SimulationResult m_user_weights
Manually defined (user) weights. Masked areas are nullified.
Definition: SimDataPair.h:98
std::unique_ptr< OutputData< double > > m_raw_uncertainties
Data uncertainties as provided by the user.
Definition: SimDataPair.h:103
simulation_builder_t m_simulation_builder
Simulation builder from the user to construct simulation for given set of parameters.
Definition: SimDataPair.h:86
Wrapper around OutputData<double> that also provides unit conversions.