28 const double zero_phi_i = 0.0;
29 const double zero_alpha_i = 0.0;
59 FixedBinAxis axis(
"alpha_i",
static_cast<size_t>(nbins), alpha_i_min, alpha_i_max);
66 throw std::runtime_error(
"Error in DepthProbeSimulation::setZSpan: maximum on-axis value "
67 "is less or equal to the minimum one");
68 m_z_axis = std::make_unique<FixedBinAxis>(
"z", n_bins, z_min, z_max);
74 throw std::runtime_error(
"Error in DepthProbeSimulation::getAlphaAxis: incident angle axis "
75 "was not initialized.");
82 throw std::runtime_error(
"Error in DepthProbeSimulation::getZAxis: position axis "
83 "was not initialized.");
90 throw std::runtime_error(
"Error in DepthProbeSimulation::intensityMapSize: attempt to "
91 "access non-initialized data.");
101 :
ISimulation(other), m_sim_elements(other.m_sim_elements), m_cache(other.m_cache)
116 throw std::runtime_error(
117 "Error in DepthProbeSimulation::setBeamParameters: wavelength must be positive.");
119 throw std::runtime_error(
120 "Error in DepthProbeSimulation::setBeamParameters: minimum value on "
121 "angle axis is negative.");
123 throw std::runtime_error(
124 "Error in DepthProbeSimulation::setBeamParameters: maximal value on "
125 "angle axis is less or equal to the minimal one.");
126 if (alpha_axis.
size() == 0)
127 throw std::runtime_error(
128 "Error in DepthProbeSimulation::setBeamParameters: angle axis is empty");
154 std::vector<DepthProbeElement>
result;
160 result.reserve(axis_size);
161 for (
size_t i = 0; i < axis_size; ++i) {
164 if (!alpha_limits.isInRange(result_angle))
165 result.back().setCalculationFlag(
false);
170 std::unique_ptr<IComputation>
174 const auto& begin =
m_sim_elements.begin() +
static_cast<long>(start);
176 begin +
static_cast<long>(n_elements));
183 throw std::runtime_error(
184 "Error in DepthProbeSimulation::validityCheck: no sample found in the simulation.");
188 throw std::runtime_error(
189 "Error in DepthProbeSimulation::validityCheck: length of simulation "
190 "element vector is not equal to the number of inclination angles");
196 throw std::runtime_error(
"Error in DepthProbeSimulation: the sizes of simulation element "
197 "vector and of its cache are different");
207 const std::vector<RealParameter*> names =
209 for (
const auto par : names)
210 if (par->getName().find(
"InclinationAngle") != std::string::npos && !zero_mean)
211 throw std::runtime_error(
"Error in DepthProbeSimulation: parameter distribution of "
212 "beam inclination angle should have zero mean.");
217 setName(
"DepthProbeSimulation");
228 for (
size_t i = start_ind, stop_point = start_ind + n_elements; i < stop_point; ++i) {
230 const double alpha_i = -element.getAlphaI();
232 double intensity_factor = beam_intensity;
233 if (footprint !=
nullptr)
234 intensity_factor = intensity_factor * footprint->
calculate(alpha_i);
235 element.setIntensities(element.getIntensities() * intensity_factor);
242 throw std::runtime_error(
243 "Error: nonzero background is not supported by DepthProbeSimulation");
269 std::unique_ptr<OutputData<double>>
result = std::make_unique<OutputData<double>>();
273 std::vector<double> rawData;
276 const std::valarray<double>& fixed_angle_result =
m_sim_elements[i].getIntensities();
277 rawData.insert(rawData.end(), std::begin(fixed_angle_result), std::end(fixed_angle_result));
279 result->setRawDataVector(rawData);
290 std::vector<double>
result;
291 result.reserve(alpha_size * z_size);
292 for (
size_t i = 0; i < alpha_size; ++i) {
294 throw std::runtime_error(
"Error in DepthProbeSimulation::rawResults: simulation "
295 "element size is not equal to the size of the position axis");
297 result.insert(
result.end(), std::begin(intensities), std::end(intensities));
309 if (raw_results.size() != z_size * alpha_size)
310 throw std::runtime_error(
311 "Error in DepthProbeSimulation::setRawResults: the vector to set is of invalid size");
313 const double* raw_array = raw_results.data();
314 for (
size_t i = 0; i < alpha_size; ++i) {
315 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 interface IBackground.
Defines interface ISampleBuilder.
Defines class ParameterPool.
Defines class RealParameter.
Defines interface UnitConverterSimple and its subclasses.
Defines a detector for specular simulations.
An incident neutron or x-ray beam.
Direction direction() const
double intensity() const
Returns the beam intensity in neutrons/sec.
double wavelength() 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 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 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 upperBound() const =0
Returns value of last point of axis.
virtual size_t size() const =0
retrieve the number of bins
virtual double lowerBound() const =0
Returns value of first 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)
Abstract base class of OffSpecularSimulation, GISASSimulation and SpecularSimulation.
const IBackground * background() const
const MultiLayer * sample() const
const Instrument & instrument() const
ProgressHandler & progress()
const SimulationOptions & options() const
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.
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.
1D detector for specular simulations.