BornAgain  1.18.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 scattering at grazing incidence
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 
17 #include "Base/Const/Units.h"
19 #include "Device/Beam/Beam.h"
22 
24  : m_corner_pos(std::move(corner_pos)), m_width(std::move(width)), m_height(std::move(height))
25 {
27  auto solid_angle_value = calculateSolidAngle();
28  m_solid_angle = solid_angle_value <= 0.0 ? 1.0 : solid_angle_value;
29 }
30 
32 {
34 }
35 
37 {
38  return new RectangularPixel(getPosition(x, y), kvector_t(), kvector_t());
39 }
40 
41 kvector_t RectangularPixel::getK(double x, double y, double wavelength) const
42 {
43  kvector_t direction = getPosition(x, y);
44  double length = M_TWOPI / wavelength;
45  return normalizeLength(direction, length);
46 }
47 
48 kvector_t RectangularPixel::getPosition(double x, double y) const
49 {
50  return m_corner_pos + x * m_width + y * m_height;
51 }
52 
53 double RectangularPixel::getIntegrationFactor(double x, double y) const
54 {
55  if (m_solid_angle == 0.0)
56  return 1.0;
57  kvector_t position = getPosition(x, y);
58  double length = position.mag();
59  return std::abs(position.dot(m_normal)) / std::pow(length, 3) / m_solid_angle;
60 }
61 
63 {
64  return m_solid_angle;
65 }
66 
68 {
69  return direction.unit() * length;
70 }
71 
73 {
74  kvector_t position = getPosition(0.5, 0.5);
75  double length = position.mag();
76  return std::abs(position.dot(m_normal)) / std::pow(length, 3);
77 }
Defines class Beam.
Defines class IDetectorResolution.
Defines M_PI and some more mathematical constants.
#define M_TWOPI
Definition: MathConstants.h:49
Defines class RectangularPixel.
Defines class RegionOfInterest.
Defines class SimulationElement.
Defines some unit conversion factors and other constants in namespace Units.
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.
auto cross(const BasicVector3D< U > &v) const
Returns cross product of vectors (linear in both arguments).
A pixel in a RectangularDetector.
kvector_t getK(double x, double y, double wavelength) const override
kvector_t getPosition(double x, double y) const
double getSolidAngle() const override
kvector_t normalizeLength(const kvector_t direction, double length) const
RectangularPixel * clone() const override
double calculateSolidAngle() const
RectangularPixel(kvector_t corner_pos, kvector_t width, kvector_t height)
double getIntegrationFactor(double x, double y) const override
kvector_t m_corner_pos
RectangularPixel * createZeroSizePixel(double x, double y) const override