BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
SphericalDetector.cpp
Go to the documentation of this file.
1 // ************************************************************************** //
2 //
3 // BornAgain: simulate and fit scattering at grazing incidence
4 //
5 //! @file Device/Detector/SphericalDetector.cpp
6 //! @brief Implements class SphericalDetector.
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 {
25  setName("SphericalDetector");
26 }
27 
28 SphericalDetector::SphericalDetector(size_t n_phi, double phi_min, double phi_max, size_t n_alpha,
29  double alpha_min, double alpha_max)
30 {
31  setName("SphericalDetector");
32  setDetectorParameters(n_phi, phi_min, phi_max, n_alpha, alpha_min, alpha_max);
33 }
34 
36 {
37  setName("SphericalDetector");
38 }
39 
41 {
42  return new SphericalDetector(*this);
43 }
44 
46 {
47  return Axes::Units::RADIANS;
48 }
49 
51 {
52  const IAxis& phi_axis = getAxis(0);
53  const IAxis& alpha_axis = getAxis(1);
54  const size_t phi_index = axisBinIndex(index, 0);
55  const size_t alpha_index = axisBinIndex(index, 1);
56 
57  const Bin1D alpha_bin = alpha_axis.getBin(alpha_index);
58  const Bin1D phi_bin = phi_axis.getBin(phi_index);
59  return new SphericalPixel(alpha_bin, phi_bin);
60 }
61 
62 std::string SphericalDetector::axisName(size_t index) const
63 {
64  switch (index) {
65  case 0:
66  return "phi_f";
67  case 1:
68  return "alpha_f";
69  default:
71  "SphericalDetector::getAxisName(size_t index) -> Error! index > 1");
72  }
73 }
74 
75 size_t SphericalDetector::indexOfSpecular(const Beam& beam) const
76 {
77  if (dimension() != 2)
78  return totalSize();
79  double alpha = beam.getAlpha();
80  double phi = beam.getPhi();
81  const IAxis& phi_axis = getAxis(0);
82  const IAxis& alpha_axis = getAxis(1);
83  if (phi_axis.contains(phi) && alpha_axis.contains(alpha))
84  return getGlobalIndex(phi_axis.findClosestIndex(phi), alpha_axis.findClosestIndex(alpha));
85  return totalSize();
86 }
Defines class Beam.
Defines class IDetectorResolution.
Defines M_PI and some more mathematical constants.
Defines class SimulationElement.
Defines class SphericalDetector.
Defines class SphericalPixel.
Defines some unit conversion factors and other constants in namespace Units.
Beam defined by wavelength, direction and intensity.
Definition: Beam.h:27
double getAlpha() const
Definition: Beam.h:70
double getPhi() const
Definition: Beam.h:71
Interface for one-dimensional axes.
Definition: IAxis.h:25
virtual bool contains(double value) const
Returns true if axis contains given point.
Definition: IAxis.cpp:40
virtual size_t findClosestIndex(double value) const =0
find bin index which is best match for given value
virtual Bin1D getBin(size_t index) const =0
retrieve a 1d bin for the given index
Abstract 2D detector interface.
Definition: IDetector2D.h:31
void setDetectorParameters(size_t n_x, double x_min, double x_max, size_t n_y, double y_min, double y_max)
Sets detector parameters using angle ranges.
Definition: IDetector2D.cpp:35
size_t getGlobalIndex(size_t x, size_t y) const
Calculate global index from two axis indices.
Definition: IDetector2D.cpp:98
size_t dimension() const
Returns actual dimensionality of the detector (number of defined axes)
Definition: IDetector.cpp:44
size_t axisBinIndex(size_t index, size_t selected_axis) const
Calculate axis index for given global index.
Definition: IDetector.cpp:61
size_t totalSize() const
Returns total number of pixels.
Definition: IDetector.cpp:87
const IAxis & getAxis(size_t index) const
Definition: IDetector.cpp:54
void setName(const std::string &name)
Interface for a function that maps [0,1]x[0,1] to the kvectors in a pixel.
Definition: IPixel.h:24
A spherical detector with axes and resolution function.
std::string axisName(size_t index) const override
Returns the name for the axis with given index.
size_t indexOfSpecular(const Beam &beam) const override
Returns index of pixel that contains the specular wavevector.
IPixel * createPixel(size_t index) const override
Creates an IPixel for the given OutputData object and index.
Axes::Units defaultAxesUnits() const override
return default axes units
SphericalDetector * clone() const override
A pixel in a SphericalDetector.
Definition: Bin.h:20