BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
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/Axis/Bin.h"
17 #include "Base/Axis/IAxis.h"
18 #include "Base/Const/Units.h"
19 #include "Base/Math/Constants.h"
21 #include "Base/Util/Assert.h"
22 #include "Device/Beam/Beam.h"
26 
27 SphericalDetector::SphericalDetector(size_t n_phi, double phi_min, double phi_max, size_t n_alpha,
28  double alpha_min, double alpha_max)
29 {
30  setDetectorParameters(n_phi, phi_min, phi_max, n_alpha, alpha_min, alpha_max);
31 }
32 
33 SphericalDetector::SphericalDetector(size_t n_bin, double width, double phi, double alpha)
34  : SphericalDetector(n_bin, phi - width / 2, phi + width / 2, n_bin, alpha - width / 2,
35  alpha + width / 2)
36 {
37 }
38 
40 
42 {
43  return new SphericalDetector(*this);
44 }
45 
47 {
48  const IAxis& phi_axis = axis(0);
49  const IAxis& alpha_axis = axis(1);
50  const size_t phi_index = axisBinIndex(index, 0);
51  const size_t alpha_index = axisBinIndex(index, 1);
52 
53  const Bin1D alpha_bin = alpha_axis.bin(alpha_index);
54  const Bin1D phi_bin = phi_axis.bin(phi_index);
55  return new SphericalPixel(alpha_bin, phi_bin);
56 }
57 
58 std::string SphericalDetector::axisName(size_t index) const
59 {
60  switch (index) {
61  case 0:
62  return "phi_f";
63  case 1:
64  return "alpha_f";
65  default:
66  throw std::runtime_error(
67  "SphericalDetector::getAxisName(size_t index) -> Error! index > 1");
68  }
69 }
70 
71 size_t SphericalDetector::indexOfSpecular(const Beam& beam) const
72 {
73  if (rank() != 2)
74  return totalSize();
75  double alpha = beam.direction().alpha();
76  double phi = beam.direction().phi();
77  const IAxis& phi_axis = axis(0);
78  const IAxis& alpha_axis = axis(1);
79  if (phi_axis.contains(phi) && alpha_axis.contains(alpha))
80  return getGlobalIndex(phi_axis.findClosestIndex(phi), alpha_axis.findClosestIndex(alpha));
81  return totalSize();
82 }
83 
85  const Direction& beamDirection) const
86 {
87  const auto axes = axesClippedToRegionOfInterest();
88  ASSERT(axes.size() == 2);
89  const IAxis& yAxis = *axes[1];
90 
91  OwningVector<IAxis> axes2({beamAxis, yAxis.clone()});
92  return new OffspecCoordinates(axes2, beamDirection);
93 }
94 
96 {
98  beam.wavelength());
99 }
Defines the macro ASSERT.
#define ASSERT(condition)
Definition: Assert.h:45
Defines class Beam.
Defines structs Bin1D, Bin1DCVector.
Defines M_PI and some more mathematical constants.
Defines interface CoordSystem2D and its subclasses.
Defines class DiffuseElement.
Defines interface IAxis.
Defines interface IDetectorResolution.
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:28
Direction direction() const
Definition: Beam.h:46
double wavelength() const
Definition: Beam.h:44
Definition: Bin.h:20
Interface for objects that provide axis translations to different units for IDetector objects.
Definition: CoordSystem2D.h:32
A direction in three-dimensional space.
Definition: Direction.h:24
double phi() const
Definition: Direction.h:37
double alpha() const
Definition: Direction.h:36
Abstract base class for one-dimensional axes.
Definition: IAxis.h:27
virtual bool contains(double value) const
Returns true if axis contains given point.
Definition: IAxis.cpp:45
virtual size_t findClosestIndex(double value) const =0
find bin index which is best match for given value
virtual IAxis * clone() const =0
virtual Bin1D bin(size_t index) const =0
retrieve a 1d bin for the given index
Interface to provide axis translations to different units for simulation output.
Definition: ICoordSystem.h:40
size_t axisBinIndex(size_t index, size_t selected_axis) const
Calculate axis index for given global index.
Definition: IDetector.cpp:80
size_t totalSize() const
Returns total number of pixels. Any region of interest is not taken into account.
Definition: IDetector.cpp:114
void setDetectorParameters(size_t n_x, double x_min, double x_max, size_t n_y, double y_min, double y_max)
Sets equidistant axes.
Definition: IDetector.cpp:329
const IAxis & axis(size_t index) const
One axis of the complete detector. Any region of interest is not taken into account.
Definition: IDetector.cpp:74
OwningVector< IAxis > axesClippedToRegionOfInterest() const
Returns the axes clipped to the region of interest. If no region of interest is explicitly defined,...
Definition: IDetector.cpp:136
size_t getGlobalIndex(size_t x, size_t y) const
Calculate global index from two axis indices.
Definition: IDetector.cpp:377
size_t rank() const
Returns number of defined axes.
Definition: IDetector.cpp:64
Interface for a function that maps [0,1]x[0,1] to the kvectors in a pixel. Abstract base class for Sp...
Definition: IPixel.h:29
ICoordSystem class that handles the unit translations for off-specular simulations with a spherical d...
ICoordSystem class that handles the unit translations for spherical detectors Its default units are r...
Definition: CoordSystem2D.h:69
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. If no pixel contains this specular wave...
IPixel * createPixel(size_t index) const override
Creates an IPixel for the given Datafield object and index.
SphericalDetector()=default
SphericalDetector * clone() const override
ICoordSystem * offspecCoords(IAxis *beamAxis, const Direction &beamDirection) const override
CoordSystem2D * scatteringCoords(const Beam &beam) const override
A pixel in a SphericalDetector.