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