BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
SimulationElement.cpp
Go to the documentation of this file.
1 // ************************************************************************** //
2 //
3 // BornAgain: simulate and fit scattering at grazing incidence
4 //
5 //! @file Base/Pixel/SimulationElement.cpp
6 //! @brief Implements class SimulationElement.
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 
16 
17 SimulationElement::SimulationElement(double wavelength, double alpha_i, double phi_i,
18  std::unique_ptr<IPixel> pixel)
19  : m_wavelength(wavelength), m_alpha_i(alpha_i), m_phi_i(phi_i),
20  m_k_i(vecOfLambdaAlphaPhi(m_wavelength, m_alpha_i, m_phi_i)),
21  m_mean_kf(pixel->getK(0.5, 0.5, m_wavelength)), m_intensity(0.0), mP_pixel(std::move(pixel)),
22  m_is_specular(false)
23 {
24 }
25 
27  : m_polarization(other.m_polarization), m_wavelength(other.m_wavelength),
28  m_alpha_i(other.m_alpha_i), m_phi_i(other.m_phi_i), m_k_i(other.m_k_i),
29  m_mean_kf(other.m_mean_kf), m_intensity(other.m_intensity), m_is_specular(other.isSpecular())
30 {
31  mP_pixel.reset(other.mP_pixel->clone());
32 }
33 
35  : m_polarization(other.m_polarization), m_wavelength(other.m_wavelength),
36  m_alpha_i(other.m_alpha_i), m_phi_i(other.m_phi_i), m_k_i(other.m_k_i),
37  m_mean_kf(other.m_mean_kf), m_intensity(other.m_intensity), m_is_specular(other.isSpecular())
38 {
39  mP_pixel.reset(other.mP_pixel->createZeroSizePixel(x, y));
40  m_mean_kf = mP_pixel->getK(0.5, 0.5, m_wavelength);
41 }
42 
44  : m_polarization(std::move(other.m_polarization)), m_wavelength(other.m_wavelength),
45  m_alpha_i(other.m_alpha_i), m_phi_i(other.m_phi_i), m_k_i(std::move(other.m_k_i)),
46  m_mean_kf(other.m_mean_kf), m_intensity(other.m_intensity),
47  mP_pixel(std::move(other.mP_pixel)), m_is_specular(other.isSpecular())
48 {
49 }
50 
51 SimulationElement::~SimulationElement() = default; // here because of forward declared members
52 
54 {
55  if (this != &other) {
56  SimulationElement tmp(other);
57  tmp.swapContent(*this);
58  }
59  return *this;
60 }
61 
63 {
64  return m_k_i;
65 }
66 
68 {
69  return m_mean_kf;
70 }
71 
72 //! Returns outgoing wavevector Kf for in-pixel coordinates x,y.
73 //! In-pixel coordinates take values from 0 to 1.
74 kvector_t SimulationElement::getKf(double x, double y) const
75 {
76  return mP_pixel->getK(x, y, m_wavelength);
77 }
78 
80 {
81  return getKi() - getMeanKf();
82 }
83 
84 //! Returns scattering vector Q, with Kf determined from in-pixel coordinates x,y.
85 //! In-pixel coordinates take values from 0 to 1.
86 kvector_t SimulationElement::getQ(double x, double y) const
87 {
88  return getKi() - mP_pixel->getK(x, y, m_wavelength);
89 }
90 
92 {
96  std::swap(m_phi_i, other.m_phi_i);
97  std::swap(m_k_i, other.m_k_i);
100  std::swap(mP_pixel, other.mP_pixel);
102 }
103 
104 double SimulationElement::getAlpha(double x, double y) const
105 {
106  return M_PI_2 - getKf(x, y).theta();
107 }
108 
109 double SimulationElement::getPhi(double x, double y) const
110 {
111  return getKf(x, y).phi();
112 }
113 
114 double SimulationElement::getIntegrationFactor(double x, double y) const
115 {
116  return mP_pixel->getIntegrationFactor(x, y);
117 }
118 
120 {
121  return mP_pixel->getSolidAngle();
122 }
BasicVector3D< double > vecOfLambdaAlphaPhi(double _lambda, double _alpha, double _phi)
Creates a vector<double> as a wavevector with given wavelength and angles.
#define M_PI_2
Definition: MathConstants.h:40
void swap(OutputDataIterator< TValue, TContainer > &left, OutputDataIterator< TValue, TContainer > &right)
make Swappable
Defines class SimulationElement.
double theta() const
Returns polar angle.
double phi() const
Returns azimuth angle.
void swapContent(PolarizationHandler &other)
Data stucture containing both input and output of a single detector cell.
PolarizationHandler m_polarization
std::unique_ptr< IPixel > mP_pixel
double getSolidAngle() const
double m_phi_i
wavelength and angles of beam
SimulationElement(double wavelength, double alpha_i, double phi_i, std::unique_ptr< IPixel > pixel)
double m_intensity
simulated intensity for detector cell
void swapContent(SimulationElement &other)
kvector_t getMeanKf() const
double getIntegrationFactor(double x, double y) const
kvector_t getKf(double x, double y) const
Returns outgoing wavevector Kf for in-pixel coordinates x,y.
kvector_t m_mean_kf
cached value of mean_kf
kvector_t getKi() const
kvector_t m_k_i
cached value of k_i
kvector_t getMeanQ() const
kvector_t getQ(double x, double y) const
Returns scattering vector Q, with Kf determined from in-pixel coordinates x,y.
double getAlpha(double x, double y) const
SimulationElement & operator=(const SimulationElement &other)
double getPhi(double x, double y) const