BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
RectangularPixel.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Device/Detector/RectangularPixel.cpp
6 //! @brief Implements class RectangularPixel.
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 #include "Base/Math/Constants.h"
17 
18 RectangularPixel::RectangularPixel(const kvector_t& corner_pos, const kvector_t& width,
19  const kvector_t& height)
20  : m_corner_pos(std::move(corner_pos))
21  , m_width(std::move(width))
22  , m_height(std::move(height))
23  , m_normal(width.cross(height))
24 {
25  // TODO URGENT: why allow solid angle <=0 ??
26  auto solid_angle_value = calculateSolidAngle();
27  m_solid_angle = solid_angle_value <= 0.0 ? 1.0 : solid_angle_value;
28 }
29 
31 {
33 }
34 
36 {
37  return new RectangularPixel(getPosition(x, y), kvector_t(), kvector_t());
38 }
39 
40 kvector_t RectangularPixel::getK(double x, double y, double wavelength) const
41 {
42  kvector_t direction = getPosition(x, y);
43  double length = M_TWOPI / wavelength;
44  return normalizeLength(direction, length);
45 }
46 
47 kvector_t RectangularPixel::getPosition(double x, double y) const
48 {
49  return m_corner_pos + x * m_width + y * m_height;
50 }
51 
52 double RectangularPixel::integrationFactor(double x, double y) const
53 {
54  if (m_solid_angle == 0.0)
55  return 1.0;
56  kvector_t position = getPosition(x, y);
57  double length = position.mag();
58  return std::abs(position.dot(m_normal)) / std::pow(length, 3) / m_solid_angle;
59 }
60 
62 {
63  return m_solid_angle;
64 }
65 
66 kvector_t RectangularPixel::normalizeLength(const kvector_t direction, double length) const
67 {
68  return direction.unit() * length;
69 }
70 
72 {
73  kvector_t position = getPosition(0.5, 0.5);
74  double length = position.mag();
75  return std::abs(position.dot(m_normal)) / std::pow(length, 3);
76 }
Defines M_PI and some more mathematical constants.
#define M_TWOPI
Definition: Constants.h:54
Defines class RectangularPixel.
BasicVector3D< double > kvector_t
Definition: Vectors3D.h:21
auto dot(const BasicVector3D< U > &v) const
Returns dot product of vectors (antilinear in the first [=self] argument).
BasicVector3D< T > unit() const
Returns unit vector in direction of this. Throws for null vector.
double mag() const
Returns magnitude of the vector.
A pixel in a RectangularDetector.
kvector_t getK(double x, double y, double wavelength) const override
double solidAngle() const override
double integrationFactor(double x, double y) const override
kvector_t getPosition(double x, double y) const
const kvector_t m_corner_pos
const kvector_t m_width
kvector_t normalizeLength(const kvector_t direction, double length) const
RectangularPixel(const kvector_t &corner_pos, const kvector_t &width, const kvector_t &height)
RectangularPixel * clone() const override
double calculateSolidAngle() const
const kvector_t m_normal
RectangularPixel * createZeroSizePixel(double x, double y) const override
const kvector_t m_height
Vector3D cross(const Vector3D &v1, const Vector3D &v2)
Definition: def.cpp:54
Definition: filesystem.h:81