64 FixedBinAxis axis(
"alpha_i",
static_cast<size_t>(nbins), alpha_i_min, alpha_i_max);
71 throw std::runtime_error(
"Error in DepthProbeSimulation::setZSpan: maximum on-axis value "
72 "is less or equal to the minimum one");
73 m_z_axis = std::make_unique<FixedBinAxis>(
"z", n_bins, z_min, z_max);
79 throw std::runtime_error(
"Error in DepthProbeSimulation::getAlphaAxis: incident angle axis "
80 "was not initialized.");
87 throw std::runtime_error(
"Error in DepthProbeSimulation::getZAxis: position axis "
88 "was not initialized.");
95 throw std::runtime_error(
"Error in DepthProbeSimulation::intensityMapSize: attempt to "
96 "access non-initialized data.");
106 :
Simulation(other), m_sim_elements(other.m_sim_elements), m_cache(other.m_cache)
121 throw std::runtime_error(
122 "Error in DepthProbeSimulation::setBeamParameters: wavelength must be positive.");
123 if (alpha_axis.
getMin() < 0.0)
124 throw std::runtime_error(
125 "Error in DepthProbeSimulation::setBeamParameters: minimum value on "
126 "angle axis is negative.");
128 throw std::runtime_error(
129 "Error in DepthProbeSimulation::setBeamParameters: maximal value on "
130 "angle axis is less or equal to the minimal one.");
131 if (alpha_axis.
size() == 0)
132 throw std::runtime_error(
133 "Error in DepthProbeSimulation::setBeamParameters: angle axis is empty");
160 std::vector<DepthProbeElement>
result;
163 const double angle_shift = beam.
getAlpha();
166 result.reserve(axis_size);
167 for (
size_t i = 0; i < axis_size; ++i) {
171 result.back().setCalculationFlag(
false);
176 std::unique_ptr<IComputation>
180 const auto& begin =
m_sim_elements.begin() +
static_cast<long>(start);
182 begin +
static_cast<long>(n_elements));
189 throw std::runtime_error(
190 "Error in DepthProbeSimulation::validityCheck: no sample found in the simulation.");
194 throw std::runtime_error(
195 "Error in DepthProbeSimulation::validityCheck: length of simulation "
196 "element vector is not equal to the number of inclination angles");
202 throw std::runtime_error(
"Error in DepthProbeSimulation: the sizes of simulation element "
203 "vector and of its cache are different");
213 const std::vector<RealParameter*> names =
215 for (
const auto par : names)
216 if (par->getName().find(
"InclinationAngle") != std::string::npos && !zero_mean)
217 throw std::runtime_error(
"Error in DepthProbeSimulation: parameter distribution of "
218 "beam inclination angle should have zero mean.");
223 setName(
"DepthProbeSimulation");
234 if (beam_intensity == 0.0)
236 for (
size_t i = start_ind, stop_point = start_ind + n_elements; i < stop_point; ++i) {
238 const double alpha_i = -element.getAlphaI();
240 double intensity_factor = beam_intensity;
241 if (footprint !=
nullptr)
242 intensity_factor = intensity_factor * footprint->
calculate(alpha_i);
243 element.setIntensities(element.getIntensities() * intensity_factor);
250 throw std::runtime_error(
251 "Error: nonzero background is not supported by DepthProbeSimulation");
277 std::unique_ptr<OutputData<double>>
result = std::make_unique<OutputData<double>>();
281 std::vector<double> rawData;
284 const std::valarray<double>& fixed_angle_result =
m_sim_elements[i].getIntensities();
285 rawData.insert(rawData.end(), std::begin(fixed_angle_result), std::end(fixed_angle_result));
287 result->setRawDataVector(rawData);
298 std::vector<double>
result;
299 result.reserve(alpha_size * z_size);
300 for (
size_t i = 0; i < alpha_size; ++i) {
302 throw std::runtime_error(
"Error in DepthProbeSimulation::rawResults: simulation "
303 "element size is not equal to the size of the position axis");
305 result.insert(
result.end(), std::begin(intensities), std::end(intensities));
317 if (raw_results.size() != z_size * alpha_size)
318 throw std::runtime_error(
319 "Error in DepthProbeSimulation::setRawResults: the vector to set is of invalid size");
321 const double* raw_array = raw_results.data();
322 for (
size_t i = 0; i < alpha_size; ++i) {
323 std::valarray<double> fixed_angle_result(raw_array, z_size);
#define ASSERT(condition)
Declares class DepthProbeComputation.
Defines class DepthProbeSimulation.
Defines classes representing one-dimensional distributions.
Defines class Histogram1D.
Defines interface IBackground.
Defines pure virtual base class ISampleBuilder.
Declares functions in namespace MaterialUtils.
Defines M_PI and some more mathematical constants.
Defines class MultiLayer.
Defines class ParameterPool.
Defines class RealParameter.
Defines interface UnitConverterSimple and its subclasses.
Defines a detector for specular simulations.
Beam defined by wavelength, direction and intensity.
double getWavelength() const
const IFootprintFactor * footprintFactor() const
Returns footprint factor.
void setFootprintFactor(const IFootprintFactor &shape_factor)
Sets footprint factor to the beam.
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
Axis with fixed bin size.
Interface for one-dimensional axes.
virtual IAxis * clone() const =0
clone function
virtual double getMin() const =0
Returns value of first point of axis.
virtual size_t size() const =0
retrieve the number of bins
virtual double getMax() const =0
Returns value of last point of axis.
virtual double getMean() const =0
Returns the distribution-specific mean.
ParameterPool * createParameterTree() const
Creates new parameter pool, with all local parameters and those of its children.
RealParameter * parameter(const std::string &name) const
Returns parameter with given 'name'.
void setName(const std::string &name)
void setBeamParameters(double wavelength, double alpha_i, double phi_i)
Sets the beam wavelength and incoming angles.
void setDetector(const IDetector &detector)
Sets the detector (axes can be overwritten later)
Our sample model: a stack of layers one below the other.
A parametric distribution function, for use with any model parameter.
const IDistribution1D * getDistribution() const
std::string getMainParameterName() const
get the main parameter's name
Limits for a real fit parameter.
bool isInRange(double value) const
returns true if proposed value is in limits range
static RealLimits limited(double left_bound_value, double right_bound_value)
Creates an object bounded from the left and right.
RealParameter & setLimits(const RealLimits &limits)
Wrapper around OutputData<double> that also provides unit conversions.
Pure virtual base class of OffSpecularSimulation, GISASSimulation and SpecularSimulation.
const Instrument & instrument() const
ProgressHandler & progress()
const IBackground * background() const
const MultiLayer * sample() const
double getBeamIntensity() const
const SimulationOptions & options() const
1D detector for specular simulations.
const double zero_alpha_i
const RealLimits alpha_limits
const double wavelength(0.154)