BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
SimDataPair.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Sim/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_SIM_FITTING_SIMDATAPAIR_H
21 #define BORNAGAIN_SIM_FITTING_SIMDATAPAIR_H
22 
24 #include "Sim/Fitting/FitTypes.h"
25 
26 class Datafield;
27 
28 //! Holds pair of simulation/experimental data to fit.
29 
30 class SimDataPair {
31 public:
32  SimDataPair(simulation_builder_t builder, const Datafield& raw_data,
33  std::unique_ptr<Datafield>&& raw_stdv, double user_weight = 1.0);
34 
35  SimDataPair(simulation_builder_t builder, const Datafield& raw_data,
36  std::unique_ptr<Datafield>&& raw_stdv, std::unique_ptr<Datafield>&& user_weights);
37 
38  SimDataPair(SimDataPair&& other);
39 
41 
42  void execSimulation(const mumufit::Parameters& params);
43 
44  bool containsUncertainties() 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 validate() const;
83 
84  //! ISimulation builder from the user to construct simulation for given set of parameters.
86 
87  //! Current simulation results. Masked areas are nullified.
89  //! Experimental data cut to the ROI. Masked areas are nullified.
91  //! Weights from experimental data uncertainties. Masked areas are nullified.
93  //! Manually defined (user) weights. Masked areas are nullified.
95 
96  //! Raw experimental data as obtained from the user.
97  std::unique_ptr<Datafield> m_raw_data;
98  //! Data uncertainties as provided by the user
99  std::unique_ptr<Datafield> m_raw_uncertainties;
100  //! User-defined weights
101  std::unique_ptr<Datafield> m_raw_user_weights;
102 };
103 
104 #endif // BORNAGAIN_SIM_FITTING_SIMDATAPAIR_H
105 #endif // USER_API
Defines common types for fitting library.
std::function< std::unique_ptr< ISimulation >(const mumufit::Parameters &)> simulation_builder_t
Definition: FitTypes.h:34
Defines class SimulationResult.
Stores radiation power per bin.
Definition: Datafield.h:30
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:88
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::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. If no uncertainties are availab...
std::vector< double > simulation_array() const
Returns the flattened simulated intensities cut to the ROI area.
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
void validate() const
std::unique_ptr< Datafield > m_raw_data
Raw experimental data as obtained from the user.
Definition: SimDataPair.h:97
std::unique_ptr< Datafield > m_raw_uncertainties
Data uncertainties as provided by the user.
Definition: SimDataPair.h:99
SimDataPair(simulation_builder_t builder, const Datafield &raw_data, std::unique_ptr< Datafield > &&raw_stdv, double user_weight=1.0)
Definition: SimDataPair.cpp:90
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.
std::unique_ptr< Datafield > m_raw_user_weights
User-defined weights.
Definition: SimDataPair.h:101
SimulationResult m_uncertainties
Weights from experimental data uncertainties. Masked areas are nullified.
Definition: SimDataPair.h:92
SimulationResult m_exp_data
Experimental data cut to the ROI. Masked areas are nullified.
Definition: SimDataPair.h:90
SimulationResult m_user_weights
Manually defined (user) weights. Masked areas are nullified.
Definition: SimDataPair.h:94
void execSimulation(const mumufit::Parameters &params)
simulation_builder_t m_simulation_builder
ISimulation builder from the user to construct simulation for given set of parameters.
Definition: SimDataPair.h:85
Wrapper around Datafield that also provides unit conversions.
A collection of fit parameters.
Definition: Parameters.h:26