BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
SimulationElement.h
Go to the documentation of this file.
1 // ************************************************************************** //
2 //
3 // BornAgain: simulate and fit scattering at grazing incidence
4 //
5 //! @file Base/Pixel/SimulationElement.h
6 //! @brief Defines class SimulationElement.
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 
15 #ifndef BORNAGAIN_CORE_PIXEL_SIMULATIONELEMENT_H
16 #define BORNAGAIN_CORE_PIXEL_SIMULATIONELEMENT_H
17 
18 #include "Base/Pixel/IPixel.h"
20 #include "Base/Types/Complex.h"
21 #include <memory>
22 
23 class IPixel;
24 
25 //! Data stucture containing both input and output of a single detector cell.
26 //! @ingroup simulation
27 
29 {
30 public:
31  SimulationElement(double wavelength, double alpha_i, double phi_i,
32  std::unique_ptr<IPixel> pixel);
35 
36  //! Construct SimulationElement from other element and restrict k_f to specific value in
37  //! the original detector pixel
38  SimulationElement(const SimulationElement& other, double x, double y);
39 
40  SimulationElement(SimulationElement&& other) noexcept;
41 
43 
44  //! Sets the polarization density matrix (in spin basis along z-axis)
45  void setPolarization(const Eigen::Matrix2cd& polarization)
46  {
47  m_polarization.setPolarization(polarization);
48  }
49 
50  //! Sets the polarization analyzer operator (in spin basis along z-axis)
51  void setAnalyzerOperator(const Eigen::Matrix2cd& polarization_operator)
52  {
53  m_polarization.setAnalyzerOperator(polarization_operator);
54  }
55 
56  //! Returns assigned PolarizationHandler
58 
59  double getWavelength() const { return m_wavelength; }
60  double getAlphaI() const { return m_alpha_i; }
61  double getPhiI() const { return m_phi_i; }
62  double getAlphaMean() const { return getAlpha(0.5, 0.5); }
63  double getPhiMean() const { return getPhi(0.5, 0.5); }
64  void setIntensity(double intensity) { m_intensity = intensity; }
65  void addIntensity(double intensity) { m_intensity += intensity; }
66  double getIntensity() const { return m_intensity; }
67  kvector_t getKi() const;
68  kvector_t getMeanKf() const;
69  kvector_t getMeanQ() const;
70  kvector_t getQ(double x, double y) const;
71 
72  double getIntegrationFactor(double x, double y) const;
73 
74  double getSolidAngle() const;
75 
76  double getAlpha(double x, double y) const;
77  double getPhi(double x, double y) const;
78 
79  //! Set specularity indication on/off.
80  void setSpecular(bool is_specular) { m_is_specular = is_specular; }
81 
82  //! Tells if simulation element corresponds to a specular peak
83  bool isSpecular() const { return m_is_specular; }
84 
85 private:
86  void swapContent(SimulationElement& other);
87 
88  kvector_t getKf(double x, double y) const;
89 
91  double m_wavelength, m_alpha_i, m_phi_i; //!< wavelength and angles of beam
92  kvector_t m_k_i; //!< cached value of k_i
93  kvector_t m_mean_kf; //!< cached value of mean_kf
94  double m_intensity; //!< simulated intensity for detector cell
95  std::unique_ptr<IPixel> mP_pixel;
97 };
98 
99 #endif // BORNAGAIN_CORE_PIXEL_SIMULATIONELEMENT_H
Defines complex_t, and a few elementary functions.
Defines pure virtual interface IPixel (has no cpp file)
Defines class PolarizationHandler.
Interface for a function that maps [0,1]x[0,1] to the kvectors in a pixel.
Definition: IPixel.h:24
Convenience class for handling polarization density matrix and polarization analyzer operator.
void setPolarization(const Eigen::Matrix2cd &polarization)
Sets the polarization density matrix (in spin basis along z-axis)
void setAnalyzerOperator(const Eigen::Matrix2cd &analyzer)
Sets the polarization analyzer operator (in spin basis along z-axis)
Data stucture containing both input and output of a single detector cell.
PolarizationHandler m_polarization
void setSpecular(bool is_specular)
Set specularity indication on/off.
double getIntensity() const
std::unique_ptr< IPixel > mP_pixel
double getSolidAngle() const
double m_phi_i
wavelength and angles of beam
SimulationElement(double wavelength, double alpha_i, double phi_i, std::unique_ptr< IPixel > pixel)
double getAlphaI() const
double m_intensity
simulated intensity for detector cell
void swapContent(SimulationElement &other)
void addIntensity(double intensity)
kvector_t getMeanKf() const
double getWavelength() const
double getPhiMean() const
void setIntensity(double intensity)
double getIntegrationFactor(double x, double y) const
void setPolarization(const Eigen::Matrix2cd &polarization)
Sets the polarization density matrix (in spin basis along z-axis)
kvector_t getKf(double x, double y) const
Returns outgoing wavevector Kf for in-pixel coordinates x,y.
kvector_t m_mean_kf
cached value of mean_kf
double getPhiI() const
kvector_t getKi() const
kvector_t m_k_i
cached value of k_i
kvector_t getMeanQ() const
void setAnalyzerOperator(const Eigen::Matrix2cd &polarization_operator)
Sets the polarization analyzer operator (in spin basis along z-axis)
kvector_t getQ(double x, double y) const
Returns scattering vector Q, with Kf determined from in-pixel coordinates x,y.
const PolarizationHandler & polarizationHandler() const
Returns assigned PolarizationHandler.
double getAlphaMean() const
double getAlpha(double x, double y) const
bool isSpecular() const
Tells if simulation element corresponds to a specular peak.
SimulationElement & operator=(const SimulationElement &other)
double getPhi(double x, double y) const