BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
AngularSpecScan.h
Go to the documentation of this file.
1 // ************************************************************************** //
2 //
3 // BornAgain: simulate and fit scattering at grazing incidence
4 //
5 //! @file Core/Scan/AngularSpecScan.h
6 //! @brief Declares AngularSpecScan class.
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_INSTRUMENT_ANGULARSPECSCAN_H
16 #define BORNAGAIN_CORE_INSTRUMENT_ANGULARSPECSCAN_H
17 
19 #include <memory>
20 
21 class ParameterSample;
22 class RangedDistribution;
23 class ScanResolution;
24 
25 //! Scan type with inclination angles as coordinate values and a unique wavelength.
26 //! Features footprint correction.
28 {
29 public:
30  AngularSpecScan(double wl, std::vector<double> inc_angle);
31  AngularSpecScan(double wl, const IAxis& inc_angle);
32  //! Sets angle-defined specular scan. The first parameter is always a wavelength in nm.
33  //! Second parameter is either a numpy array of incident angles in radians or an IAxis object
34  //! with angle values. Alternatively an axis can be defined in-place, then
35  //! the second passed parameter is the number of bins, third - minimum on-axis angle value,
36  //! fourth - maximum on-axis angle value.
37  AngularSpecScan(double wl, int nbins, double alpha_i_min, double alpha_i_max);
38  ~AngularSpecScan() override;
39  AngularSpecScan* clone() const override;
40 
41 #ifndef SWIG
42  //! Generates simulation elements for specular simulations
43  std::vector<SpecularSimulationElement> generateSimulationElements() const override;
44 
45  //! Returns coordinate axis assigned to the data holder
46  virtual const IAxis* coordinateAxis() const override { return m_inc_angle.get(); }
47 
48  //! Returns IFootprintFactor object pointer
49  virtual const IFootprintFactor* footprintFactor() const override { return m_footprint.get(); }
50 
51  //! Returns footprint correction factor for a range of simulation elements of size _n_elements_
52  //! and starting from element with index _i_.
53  std::vector<double> footprint(size_t i, size_t n_elements) const override;
54 
55  //! Returns the number of simulation elements
56  size_t numberOfSimulationElements() const override;
57 
58  //! Returns intensity vector corresponding to convolution of given simulation elements
59  std::vector<double>
60  createIntensities(const std::vector<SpecularSimulationElement>& sim_elements) const override;
61 
62  //! Print scan definition in python format
63  std::string print() const override;
64 
65  double wavelength() const { return m_wl; }
66 
67  // TODO: remove these getters after transition to the new resolution machinery is finished
68  const ScanResolution* wavelengthResolution() const { return m_wl_resolution.get(); }
69  const ScanResolution* angleResolution() const { return m_inc_resolution.get(); }
70 #endif // SWIG
71 
72  //! Sets footprint correction factor
73  void setFootprintFactor(const IFootprintFactor* f_factor);
74 
75  //! Sets wavelength resolution values via ScanResolution object.
76  void setWavelengthResolution(const ScanResolution& resolution);
77 
78  void setRelativeWavelengthResolution(const RangedDistribution& distr, double rel_dev);
79  //! Sets wavelength resolution values via RangedDistribution and values of relative deviations
80  //! (that is, _rel_dev_ equals standard deviation divided by the mean value).
81  //! _rel_dev_ can be either single-valued or a numpy array. In the latter case the length of the
82  //! array should coinside with the length of the inclination angle axis.
84  const std::vector<double>& rel_dev);
85 
86  void setAbsoluteWavelengthResolution(const RangedDistribution& distr, double std_dev);
87  //! Sets wavelength resolution values via RangedDistribution and values of standard deviations.
88  //! _std_dev_ can be either single-valued or a numpy array. In the latter case the length of the
89  //! array should coinside with the length of the inclination angle axis.
91  const std::vector<double>& std_dev);
92 
93  //! Sets angle resolution values via ScanResolution object.
94  void setAngleResolution(const ScanResolution& resolution);
95 
96  void setRelativeAngularResolution(const RangedDistribution& distr, double rel_dev);
97  //! Sets angular resolution values via RangedDistribution and values of relative deviations
98  //! (that is, _rel_dev_ equals standard deviation divided by the mean value).
99  //! _rel_dev_ can be either single-valued or a numpy array. In the latter case the length of the
100  //! array should coinside with the length of the inclination angle axis.
102  const std::vector<double>& rel_dev);
103 
104  void setAbsoluteAngularResolution(const RangedDistribution& distr, double std_dev);
105  //! Sets angular resolution values via RangedDistribution and values of standard deviations.
106  //! _std_dev_ can be either single-valued or a numpy array. In the latter case the length of the
107  //! array should coinside with the length of the inclination angle axis.
109  const std::vector<double>& std_dev);
110 
111 private:
112  using DistrOutput = std::vector<std::vector<ParameterSample>>;
113 
114  void checkInitialization();
117 
118  double m_wl;
119  std::unique_ptr<IAxis> m_inc_angle;
120  std::unique_ptr<IFootprintFactor> m_footprint;
121 
122  std::unique_ptr<ScanResolution> m_wl_resolution;
124 
125  std::unique_ptr<ScanResolution> m_inc_resolution;
127 };
128 
129 #endif // BORNAGAIN_CORE_INSTRUMENT_ANGULARSPECSCAN_H
Declares and implements pure virtual class ISpecularScan.
Scan type with inclination angles as coordinate values and a unique wavelength.
void setAngleResolution(const ScanResolution &resolution)
Sets angle resolution values via ScanResolution object.
void setAbsoluteAngularResolution(const RangedDistribution &distr, double std_dev)
virtual const IFootprintFactor * footprintFactor() const override
Returns IFootprintFactor object pointer.
DistrOutput m_wl_res_cache
std::vector< std::vector< ParameterSample > > DistrOutput
std::vector< double > footprint(size_t i, size_t n_elements) const override
Returns footprint correction factor for a range of simulation elements of size n_elements and startin...
size_t numberOfSimulationElements() const override
Returns the number of simulation elements.
std::unique_ptr< IAxis > m_inc_angle
AngularSpecScan(double wl, std::vector< double > inc_angle)
const ScanResolution * wavelengthResolution() const
const ScanResolution * angleResolution() const
virtual const IAxis * coordinateAxis() const override
Returns coordinate axis assigned to the data holder.
AngularSpecScan * clone() const override
std::unique_ptr< ScanResolution > m_inc_resolution
std::unique_ptr< ScanResolution > m_wl_resolution
std::vector< double > createIntensities(const std::vector< SpecularSimulationElement > &sim_elements) const override
Returns intensity vector corresponding to convolution of given simulation elements.
DistrOutput m_inc_res_cache
void setAbsoluteWavelengthResolution(const RangedDistribution &distr, double std_dev)
void setFootprintFactor(const IFootprintFactor *f_factor)
Sets footprint correction factor.
void setRelativeWavelengthResolution(const RangedDistribution &distr, double rel_dev)
double wavelength() const
DistrOutput applyIncResolution() const
std::unique_ptr< IFootprintFactor > m_footprint
DistrOutput applyWlResolution() const
void setWavelengthResolution(const ScanResolution &resolution)
Sets wavelength resolution values via ScanResolution object.
std::string print() const override
Print scan definition in python format.
std::vector< SpecularSimulationElement > generateSimulationElements() const override
Generates simulation elements for specular simulations.
~AngularSpecScan() override
void setRelativeAngularResolution(const RangedDistribution &distr, double rel_dev)
Interface for one-dimensional axes.
Definition: IAxis.h:25
Abstract base for classes that calculate the beam footprint factor.
Pure virtual base class for all types of specular scans.
Definition: ISpecularScan.h:31
A parameter value with a weight, as obtained when sampling from a distribution.
Interface for one-dimensional ranged distributions.
Container for reflectivity resolution data.