BornAgain  1.19.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 reflection and scattering
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 #ifdef SWIG
16 #error no need to expose this header to Swig
17 #endif
18 
19 #ifndef USER_API
20 #ifndef BORNAGAIN_CORE_FITTING_SIMDATAPAIR_H
21 #define BORNAGAIN_CORE_FITTING_SIMDATAPAIR_H
22 
23 #include "Core/Fitting/FitTypes.h"
25 
26 template <class T> class OutputData;
27 
28 //! Holds pair of simulation/experimental data to fit.
29 
30 class SimDataPair {
31 public:
33  std::unique_ptr<OutputData<double>> uncertainties, double user_weight = 1.0);
34 
36  std::unique_ptr<OutputData<double>> uncertainties,
37  std::unique_ptr<OutputData<double>> user_weights);
38 
39  SimDataPair(SimDataPair&& other);
40 
42 
43  void runSimulation(const mumufit::Parameters& params);
44 
45  bool containsUncertainties() const;
46 
47  //! Returns the number of elements in the fit area
48  size_t numberOfFitElements() const;
49 
50  //! Returns the result of last computed simulation
52 
53  //! Returns the experimental data cut to the ROI area
55 
56  //! Returns the data uncertainties cut to the ROI area
57  //! If no uncertainties present, returns zero-filled SimulationResult.
59 
60  //! Returns the user uncertainties cut to the ROI area.
62 
63  //! Returns the relative difference between simulated
64  //! and experimental data cut to the ROI area
66 
67  //! Returns the absolute difference between simulated
68  //! and experimental data cut to the ROI area
70 
71  //! Returns the flattened simulated intensities cut to the ROI area
72  std::vector<double> simulation_array() const;
73 
74  //! Returns the flattened experimental data cut to the ROI area
75  std::vector<double> experimental_array() const;
76 
77  //! Returns the flattened experimental uncertainties
78  //! cut to the ROI area. If no uncertainties are available,
79  //! returns a zero-filled array sized to the ROI area.
80  std::vector<double> uncertainties_array() const;
81 
82  //! Returns a flat array of user weights cut to the ROI area.
83  std::vector<double> user_weights_array() const;
84 
85 private:
86  void initResultArrays();
87  void validate() const;
88 
89  //! ISimulation builder from the user to construct simulation for given set of parameters.
91 
92  //! Current simulation for given set of parameters.
93  std::unique_ptr<ISimulation> m_simulation;
94 
95  //! Current simulation results. Masked areas are nullified.
97  //! Experimental data cut to the ROI. Masked areas are nullified.
99  //! Weights from experimental data uncertainties. Masked areas are nullified.
101  //! Manually defined (user) weights. Masked areas are nullified.
103 
104  //! Raw experimental data as obtained from the user.
105  std::unique_ptr<OutputData<double>> m_raw_data;
106  //! Data uncertainties as provided by the user
107  std::unique_ptr<OutputData<double>> m_raw_uncertainties;
108  //! User-defined weights
109  std::unique_ptr<OutputData<double>> m_raw_user_weights;
110 };
111 
112 #endif // BORNAGAIN_CORE_FITTING_SIMDATAPAIR_H
113 #endif // USER_API
Defines common types for fitting library.
std::function< std::unique_ptr< ISimulation >(const mumufit::Parameters &)> simulation_builder_t
Definition: FitTypes.h:33
Defines class SimulationResult.
Templated class to store data of type double or CumulativeValue in multi-dimensional space.
Definition: OutputData.h:32
Holds pair of simulation/experimental data to fit.
Definition: SimDataPair.h:30
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:96
std::vector< double > experimental_array() const
Returns the flattened experimental data cut to the ROI area.
std::unique_ptr< ISimulation > m_simulation
Current simulation for given set of parameters.
Definition: SimDataPair.h:93
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:109
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:38
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.
bool containsUncertainties() const
Definition: SimDataPair.cpp:86
void validate() const
std::unique_ptr< OutputData< double > > m_raw_data
Raw experimental data as obtained from the user.
Definition: SimDataPair.h:105
size_t numberOfFitElements() const
Returns the number of elements in the fit area.
Definition: SimDataPair.cpp:91
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:96
void initResultArrays()
SimulationResult m_uncertainties
Weights from experimental data uncertainties. Masked areas are nullified.
Definition: SimDataPair.h:100
SimulationResult m_exp_data
Experimental data cut to the ROI. Masked areas are nullified.
Definition: SimDataPair.h:98
SimulationResult m_user_weights
Manually defined (user) weights. Masked areas are nullified.
Definition: SimDataPair.h:102
void runSimulation(const mumufit::Parameters &params)
Definition: SimDataPair.cpp:77
std::unique_ptr< OutputData< double > > m_raw_uncertainties
Data uncertainties as provided by the user.
Definition: SimDataPair.h:107
simulation_builder_t m_simulation_builder
ISimulation builder from the user to construct simulation for given set of parameters.
Definition: SimDataPair.h:90
Wrapper around OutputData<double> that also provides unit conversions.
A collection of fit parameters.
Definition: Parameters.h:26