BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
DepthProbeSimulation.h
Go to the documentation of this file.
1 // ************************************************************************** //
2 //
3 // BornAgain: simulate and fit scattering at grazing incidence
4 //
5 //! @file Core/Simulation/DepthProbeSimulation.h
6 //! @brief Defines class DepthProbeSimulation
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_SIMULATION_DEPTHPROBESIMULATION_H
16 #define BORNAGAIN_CORE_SIMULATION_DEPTHPROBESIMULATION_H
17 
21 
22 #include <vector>
23 
24 class IAxis;
25 class IComputation;
26 class IFootprintFactor;
27 class ISample;
28 class ISampleBuilder;
29 class MultiLayer;
30 class Histogram1D;
31 class IUnitConverter;
32 
34 {
35 public:
38 
39  DepthProbeSimulation* clone() const override;
40 
41  void accept(INodeVisitor* visitor) const override final { visitor->visit(this); }
42 
43  //! Returns the results of the simulation in a format that supports unit conversion and export
44  //! to numpy arrays
45  SimulationResult result() const override;
46 
47  //! Sets beam parameters with alpha_i of the beam defined in the range.
48  void setBeamParameters(double lambda, int nbins, double alpha_i_min, double alpha_i_max,
49  const IFootprintFactor* beam_shape = nullptr);
50 
51  //! Set z positions for intensity calculations. Negative z's correspond to the area
52  //! under sample surface. The more negative z is, the deeper layer corresponds to it.
53  void setZSpan(size_t n_bins, double z_min, double z_max);
54 
55  //! Returns a pointer to incident angle axis.
56  const IAxis* getAlphaAxis() const;
57 
58  //! Returns a pointer to z-position axis.
59  const IAxis* getZAxis() const;
60 
61  //! Returns the total number of the intensity values in the simulation result
62  size_t intensityMapSize() const override;
63 
64 #ifndef SWIG
65  std::unique_ptr<IUnitConverter> createUnitConverter() const;
66 #endif
67 
68 private:
70 
71  //! Sets beam parameters with alpha_i of the beam defined in the range.
72  void setBeamParameters(double lambda, const IAxis& alpha_axis,
73  const IFootprintFactor* beam_shape);
74 
75  //! Initializes the vector of Simulation elements
76  void initSimulationElementVector() override;
77 
78  //! Gets the number of elements this simulation needs to calculate
79  size_t numberOfSimulationElements() const override;
80 
81  //! Generate simulation elements for given beam
82  std::vector<DepthProbeElement> generateSimulationElements(const Beam& beam);
83 
84  //! Generate a single threaded computation for a given range of simulation elements
85  //! @param start Index of the first element to include into computation
86  //! @param n_elements Number of elements to process
87  std::unique_ptr<IComputation> generateSingleThreadedComputation(size_t start,
88  size_t n_elements) override;
89 
90  //! Checks if simulation data is ready for retrieval.
91  void validityCheck() const;
92 
93  void checkCache() const;
94 
95  //! Checks the distribution validity for simulation.
96  void validateParametrization(const ParameterDistribution& par_distr) const override;
97 
98  //! Initializes simulation
99  void initialize();
100 
101  //! Normalize the detector counts to beam intensity, to solid angle, and to exposure angle.
102  //! @param start_ind Index of the first element to operate on
103  //! @param n_elements Number of elements to process
104  void normalize(size_t start_ind, size_t n_elements) override;
105 
106  void addBackgroundIntensity(size_t start_ind, size_t n_elements) override;
107 
108  void addDataToCache(double weight) override;
109 
110  void moveDataFromCache() override;
111 
112  double incidentAngle(size_t index) const;
113 
114  //! Creates intensity data from simulation elements
115  std::unique_ptr<OutputData<double>> createIntensityData() const;
116 
117  std::vector<double> rawResults() const override;
118  void setRawResults(const std::vector<double>& raw_data) override;
119 
120  std::unique_ptr<IAxis> m_alpha_axis;
121  std::unique_ptr<IAxis> m_z_axis;
122  std::vector<DepthProbeElement> m_sim_elements;
123  std::vector<std::valarray<double>> m_cache;
124 };
125 
126 #endif // BORNAGAIN_CORE_SIMULATION_DEPTHPROBESIMULATION_H
Defines class DepthProbeElement.
Defines and implements class ILayerRTCoefficients.
Defines class Simulation.
Beam defined by wavelength, direction and intensity.
Definition: Beam.h:27
std::unique_ptr< IUnitConverter > createUnitConverter() const
void initSimulationElementVector() override
Initializes the vector of Simulation elements.
std::unique_ptr< IAxis > m_z_axis
const IAxis * getAlphaAxis() const
Returns a pointer to incident angle axis.
SimulationResult result() const override
Returns the results of the simulation in a format that supports unit conversion and export to numpy a...
DepthProbeSimulation * clone() const override
void setBeamParameters(double lambda, int nbins, double alpha_i_min, double alpha_i_max, const IFootprintFactor *beam_shape=nullptr)
Sets beam parameters with alpha_i of the beam defined in the range.
std::unique_ptr< IComputation > generateSingleThreadedComputation(size_t start, size_t n_elements) override
Generate a single threaded computation for a given range of simulation elements.
void moveDataFromCache() override
void addDataToCache(double weight) override
void initialize()
Initializes simulation.
std::unique_ptr< OutputData< double > > createIntensityData() const
Creates intensity data from simulation elements.
void setZSpan(size_t n_bins, double z_min, double z_max)
Set z positions for intensity calculations.
void addBackgroundIntensity(size_t start_ind, size_t n_elements) override
std::vector< double > rawResults() const override
~DepthProbeSimulation() override
double incidentAngle(size_t index) const
void validateParametrization(const ParameterDistribution &par_distr) const override
Checks the distribution validity for simulation.
void validityCheck() const
Checks if simulation data is ready for retrieval.
void normalize(size_t start_ind, size_t n_elements) override
Normalize the detector counts to beam intensity, to solid angle, and to exposure angle.
std::vector< DepthProbeElement > generateSimulationElements(const Beam &beam)
Generate simulation elements for given beam.
const IAxis * getZAxis() const
Returns a pointer to z-position axis.
std::vector< std::valarray< double > > m_cache
std::unique_ptr< IAxis > m_alpha_axis
void setRawResults(const std::vector< double > &raw_data) override
size_t numberOfSimulationElements() const override
Gets the number of elements this simulation needs to calculate.
size_t intensityMapSize() const override
Returns the total number of the intensity values in the simulation result.
std::vector< DepthProbeElement > m_sim_elements
void accept(INodeVisitor *visitor) const override final
Calls the INodeVisitor's visit method.
One dimensional histogram.
Definition: Histogram1D.h:24
Interface for one-dimensional axes.
Definition: IAxis.h:25
Interface for a single-threaded computation with given range of SimulationElements and ProgressHandle...
Definition: IComputation.h:35
Abstract base for classes that calculate the beam footprint factor.
Visitor interface to visit ISample objects.
Definition: INodeVisitor.h:149
Interface to the class capable to build samples to simulate.
Pure virtual base class for sample components and properties related to scattering.
Definition: ISample.h:28
Interface to provide axis translations to different units for simulation output.
Our sample model: a stack of layers one below the other.
Definition: MultiLayer.h:42
A parametric distribution function, for use with any model parameter.
Wrapper around OutputData<double> that also provides unit conversions.
Pure virtual base class of OffSpecularSimulation, GISASSimulation and SpecularSimulation.
Definition: Simulation.h:38