BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
DetectorContext.cpp
Go to the documentation of this file.
1 // ************************************************************************** //
2 //
3 // BornAgain: simulate and fit scattering at grazing incidence
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 active_indices.size();
26 }
27 
28 //! Creates pixel for given element index. Element index is sequetial index in a vector
29 //! of SimulationElements. 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>(pixels[element_index]->clone());
35 }
36 
37 size_t DetectorContext::detectorIndex(size_t element_index) const
38 {
39  return active_indices[element_index];
40 }
41 
43 {
44  active_indices = detector->active_indices();
46  pixels.reserve(active_indices.size());
47  for (auto detector_index : active_indices)
48  pixels.emplace_back(detector->createPixel(detector_index));
49 }
Define DetectorContext class.
Defines interface IDetector2D.
Eigen::Matrix2cd analyzerOperator() const
Return the polarization density matrix (in spin basis along z-axis)
DetectorContext(const IDetector2D *detector)
std::vector< size_t > active_indices
All unmasked pixels inside ROI.
std::vector< std::unique_ptr< IPixel > > pixels
void setup_context(const IDetector2D *detector)
size_t detectorIndex(size_t element_index) const
std::unique_ptr< IPixel > createPixel(size_t element_index) const
Creates pixel for given element index.
size_t numberOfSimulationElements() const
Eigen::Matrix2cd analyzer_operator
Abstract 2D detector interface.
Definition: IDetector2D.h:31
virtual IPixel * createPixel(size_t index) const =0
Creates an IPixel for the given OutputData object and index.
std::vector< size_t > active_indices() const
Returns vector of unmasked detector indices.
Definition: IDetector2D.cpp:60
const DetectionProperties & detectionProperties() const
Returns detection properties.
Definition: IDetector.h:93