BornAgain  1.19.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 reflection and scattering
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 
16 #include "Base/Const/Units.h"
17 #include "Base/Math/Constants.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 
35 SphericalDetector::SphericalDetector(size_t n_bin, double width, double phi, double alpha)
36  : SphericalDetector(n_bin, phi - width / 2, phi + width / 2, n_bin, alpha - width / 2,
37  alpha + width / 2)
38 {
39 }
40 
42 {
43  setName("SphericalDetector");
44 }
45 
47 {
48  return new SphericalDetector(*this);
49 }
50 
52 {
53  return Axes::Units::RADIANS;
54 }
55 
57 {
58  const IAxis& phi_axis = axis(0);
59  const IAxis& alpha_axis = axis(1);
60  const size_t phi_index = axisBinIndex(index, 0);
61  const size_t alpha_index = axisBinIndex(index, 1);
62 
63  const Bin1D alpha_bin = alpha_axis.bin(alpha_index);
64  const Bin1D phi_bin = phi_axis.bin(phi_index);
65  return new SphericalPixel(alpha_bin, phi_bin);
66 }
67 
68 std::string SphericalDetector::axisName(size_t index) const
69 {
70  switch (index) {
71  case 0:
72  return "phi_f";
73  case 1:
74  return "alpha_f";
75  default:
76  throw std::runtime_error(
77  "SphericalDetector::getAxisName(size_t index) -> Error! index > 1");
78  }
79 }
80 
81 size_t SphericalDetector::indexOfSpecular(const Beam& beam) const
82 {
83  if (dimension() != 2)
84  return totalSize();
85  double alpha = beam.direction().alpha();
86  double phi = beam.direction().phi();
87  const IAxis& phi_axis = axis(0);
88  const IAxis& alpha_axis = axis(1);
89  if (phi_axis.contains(phi) && alpha_axis.contains(alpha))
90  return getGlobalIndex(phi_axis.findClosestIndex(phi), alpha_axis.findClosestIndex(alpha));
91  return totalSize();
92 }
Defines class Beam.
Defines M_PI and some more mathematical constants.
Defines interface IDetectorResolution.
Defines class SimulationElement.
Defines class SphericalDetector.
Defines class SphericalPixel.
Defines some unit conversion factors and other constants in namespace Units.
An incident neutron or x-ray beam.
Definition: Beam.h:27
Direction direction() const
Definition: Beam.h:45
double phi() const
Definition: Direction.h:30
double alpha() const
Definition: Direction.h:29
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:37
virtual size_t findClosestIndex(double value) const =0
find bin index which is best match for given value
virtual Bin1D bin(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:92
size_t dimension() const
Returns actual dimensionality of the detector (number of defined axes)
Definition: IDetector.cpp:46
size_t axisBinIndex(size_t index, size_t selected_axis) const
Calculate axis index for given global index.
Definition: IDetector.cpp:63
size_t totalSize() const
Returns total number of pixels.
Definition: IDetector.cpp:88
const IAxis & axis(size_t index) const
Definition: IDetector.cpp:56
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:25
A detector with coordinate axes along angles phi and alpha.
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