BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
RectangularPixel.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Base/Pixel/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/Axis/FixedBinAxis.h"
17 #include "Base/Math/Constants.h"
18 
19 RectangularPixel::RectangularPixel(const R3& corner_pos, const R3& width, const R3& height)
20  : m_corner_pos(corner_pos)
21  , m_width(width)
22  , m_height(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), R3(), R3());
38 }
39 
40 R3 RectangularPixel::getK(double x, double y, double wavelength) const
41 {
42  R3 direction = getPosition(x, y);
43  double length = M_TWOPI / wavelength;
44  return normalizeLength(direction, length);
45 }
46 
47 R3 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  R3 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 R3 RectangularPixel::normalizeLength(const R3 direction, double length) const
67 {
68  return direction.unit() * length;
69 }
70 
72 {
73  R3 position = getPosition(0.5, 0.5);
74  double length = position.mag();
75  return std::abs(position.dot(m_normal)) / std::pow(length, 3);
76 }
77 
79 {
80  const auto k00 = getPosition(0.0, 0.0);
81  const auto k01 = getPosition(0.0, 1.0);
82  const double alpha_f_min = M_PI_2 - R3Util::theta(k00);
83  const double alpha_f_max = M_PI_2 - R3Util::theta(k01);
84 
85  return new FixedBinAxis("alpha_f", alpha_f_min, alpha_f_max, n);
86 }
Defines M_PI and some more mathematical constants.
#define M_TWOPI
Definition: Constants.h:54
#define M_PI_2
Definition: Constants.h:45
Defines class FixedBinAxis.
Defines class RectangularPixel.
Axis with fixed bin size.
Definition: FixedBinAxis.h:23
Abstract base class for one-dimensional axes.
Definition: IAxis.h:27
A pixel in a RectangularDetector.
double solidAngle() const override
double integrationFactor(double x, double y) const override
R3 normalizeLength(R3 direction, double length) const
R3 getPosition(double x, double y) const
IAxis * createAxis(size_t n) const
R3 getK(double x, double y, double wavelength) const override
RectangularPixel * clone() const override
double calculateSolidAngle() const
RectangularPixel * createZeroSizePixel(double x, double y) const override
RectangularPixel(const R3 &corner_pos, const R3 &width, const R3 &height)