BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
DetectorContext.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Device/Detector/DetectorContext.cpp
6 //! @brief Implements DetectorContext class.
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 
19 {
20  setup_context(detector);
21 }
22 
24 {
25  return m_active_indices.size();
26 }
27 
28 //! Creates pixel for given element index. Element index is sequential index in a vector
29 //! of DiffuseElements. Corresponds to sequence of detector bins inside ROI and outside
30 //! of masked areas.
31 
32 std::unique_ptr<IPixel> DetectorContext::createPixel(size_t element_index) const
33 {
34  return std::unique_ptr<IPixel>(m_pixels[element_index]->clone());
35 }
36 
37 size_t DetectorContext::detectorIndex(size_t element_index) const
38 {
39  return m_active_indices[element_index];
40 }
41 
43 {
44  m_active_indices = detector->active_indices();
45  m_analyzer_operator = detector->analyzer().matrix();
46  m_pixels.reserve(m_active_indices.size());
47  for (auto detector_index : m_active_indices)
48  m_pixels.emplace_back(detector->createPixel(detector_index));
49 }
Define DetectorContext class.
Defines common detector interface.
size_t numberOfElements() const
void setup_context(const IDetector *detector)
std::vector< size_t > m_active_indices
All unmasked pixels inside ROI.
DetectorContext(const IDetector *detector)
size_t detectorIndex(size_t element_index) const
std::vector< std::unique_ptr< IPixel > > m_pixels
std::unique_ptr< IPixel > createPixel(size_t element_index) const
Creates pixel for given element index. Element index is sequential index in a vector of DiffuseElemen...
SpinMatrix m_analyzer_operator
Abstract detector interface.
Definition: IDetector.h:57
const PolFilter & analyzer() const
Returns detection properties.
Definition: IDetector.h:204
std::vector< size_t > active_indices() const
Returns vector of unmasked detector indices.
Definition: IDetector.cpp:346
virtual IPixel * createPixel(size_t index) const =0
Creates an IPixel for the given Datafield object and index.
SpinMatrix matrix() const
Return the polarization density matrix (in spin basis along z-axis)
Definition: PolFilter.cpp:40