BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
QSpecScan.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Core/Scan/QSpecScan.h
6 //! @brief Declares QSpecScan 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_SCAN_QSPECSCAN_H
16 #define BORNAGAIN_CORE_SCAN_QSPECSCAN_H
17 
19 #include <memory>
20 
21 class ParameterSample;
23 class ScanResolution;
24 
25 //! Scan type with z-components of scattering vector as coordinate values.
26 //! Wavelength and incident angles are not accessible separately.
27 
28 class QSpecScan : public ISpecularScan {
29 public:
30  //! Accepts qz-value vector (in inverse nm)
31  QSpecScan(std::vector<double> qs_nm);
32  QSpecScan(const IAxis& qs_nm);
33  //! Sets q-defined specular scan. Accepts either numpy array of q-values sorted in ascending
34  //! order or an IAxis object with q-values. Alternatively an axis can be defined in-place, then
35  //! the first passed parameter is the number of bins, second - minimum on-axis q-value,
36  //! third - maximum on-axis q_value.
37  QSpecScan(int nbins, double qz_min, double qz_max);
38 
39  ~QSpecScan() override;
40  QSpecScan* clone() const override;
41 
42  const ScanResolution* resolution() const { return m_resolution.get(); }
43 
44 #ifndef SWIG
45  //! Generates simulation elements for specular simulations
46  std::vector<SpecularSimulationElement>
47  generateSimulationElements(const Instrument& instrument) const override;
48 
49  //! Returns coordinate axis assigned to the data holder
50  virtual const IAxis* coordinateAxis() const override { return m_qs.get(); }
51 
52  //! Returns IFootprintFactor object pointer
53  virtual const IFootprintFactor* footprintFactor() const override { return nullptr; }
54 
55  //! Returns footprint correction factor for a range of simulation elements of size _n_elements_
56  //! and starting from element with index _i_.
57  std::vector<double> footprint(size_t i, size_t n_elements) const override;
58 
59  //! Returns the number of simulation elements
60  size_t numberOfSimulationElements() const override;
61 
62  //! Returns intensity vector corresponding to convolution of given simulation elements
63  std::vector<double>
64  createIntensities(const std::vector<SpecularSimulationElement>& sim_elements) const override;
65 
66 #endif // USER_API
67 
68  //! Sets q resolution values via ScanResolution object.
70 
71  void setRelativeQResolution(const IRangedDistribution& distr, double rel_dev);
72  //! Sets qz resolution values via IRangedDistribution and values of relative deviations
73  //! (that is, _rel_dev_ equals standard deviation divided by the mean value).
74  //! _rel_dev_ can be either single-valued or a numpy array. In the latter case the length of the
75  //! array should coinside with the length of the qz-axis.
77  const std::vector<double>& rel_dev);
78 
79  void setAbsoluteQResolution(const IRangedDistribution& distr, double std_dev);
80  //! Sets qz resolution values via IRangedDistribution and values of standard deviations.
81  //! _std_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 qz-axis.
84  const std::vector<double>& std_dev);
85 
86  void setOffset(double offset) { m_offset = offset; }
87  double offset() const { return m_offset; }
88 
89 private:
90  void checkInitialization();
91  std::vector<double> generateQzVector() const;
92  std::vector<std::vector<ParameterSample>> applyQResolution() const;
93 
94  const std::unique_ptr<IAxis> m_qs;
95  std::unique_ptr<ScanResolution> m_resolution;
96  mutable std::vector<std::vector<ParameterSample>> m_q_res_cache;
97 
98  double m_offset = 0.;
99 };
100 
101 #endif // BORNAGAIN_CORE_SCAN_QSPECSCAN_H
Declares and implements interface ISpecularScan.
Interface for one-dimensional axes.
Definition: IAxis.h:25
Abstract base for classes that calculate the beam footprint factor.
Interface for one-dimensional ranged distributions.
Abstract base class for all types of specular scans.
Definition: ISpecularScan.h:32
Assembles beam, detector and their relative positions with respect to the sample.
Definition: Instrument.h:32
A parameter value with a weight, as obtained when sampling from a distribution.
Scan type with z-components of scattering vector as coordinate values.
Definition: QSpecScan.h:28
std::vector< SpecularSimulationElement > generateSimulationElements(const Instrument &instrument) const override
Generates simulation elements for specular simulations.
Definition: QSpecScan.cpp:54
double m_offset
Definition: QSpecScan.h:98
void setAbsoluteQResolution(const IRangedDistribution &distr, double std_dev)
Definition: QSpecScan.cpp:122
double offset() const
Definition: QSpecScan.h:87
size_t numberOfSimulationElements() const override
Returns the number of simulation elements.
Definition: QSpecScan.cpp:76
void setOffset(double offset)
Definition: QSpecScan.h:86
QSpecScan * clone() const override
Definition: QSpecScan.cpp:44
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...
Definition: QSpecScan.cpp:67
virtual const IAxis * coordinateAxis() const override
Returns coordinate axis assigned to the data holder.
Definition: QSpecScan.h:50
std::vector< std::vector< ParameterSample > > m_q_res_cache
Definition: QSpecScan.h:96
void setRelativeQResolution(const IRangedDistribution &distr, double rel_dev)
Definition: QSpecScan.cpp:107
std::vector< double > createIntensities(const std::vector< SpecularSimulationElement > &sim_elements) const override
Returns intensity vector corresponding to convolution of given simulation elements.
Definition: QSpecScan.cpp:82
QSpecScan(std::vector< double > qs_nm)
Accepts qz-value vector (in inverse nm)
Definition: QSpecScan.cpp:22
virtual const IFootprintFactor * footprintFactor() const override
Returns IFootprintFactor object pointer.
Definition: QSpecScan.h:53
std::unique_ptr< ScanResolution > m_resolution
Definition: QSpecScan.h:95
void setQResolution(const ScanResolution &resolution)
Sets q resolution values via ScanResolution object.
Definition: QSpecScan.cpp:100
void checkInitialization()
Definition: QSpecScan.cpp:137
std::vector< double > generateQzVector() const
Definition: QSpecScan.cpp:149
const ScanResolution * resolution() const
Definition: QSpecScan.h:42
~QSpecScan() override
const std::unique_ptr< IAxis > m_qs
Definition: QSpecScan.h:94
std::vector< std::vector< ParameterSample > > applyQResolution() const
Definition: QSpecScan.cpp:161
Container for reflectivity resolution data.