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 
18 DetectorContext::DetectorContext(const IDetector2D* detector)
19 {
20  setup_context(detector);
21 }
22 
23 size_t DetectorContext::numberOfSimulationElements() const
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 
42 void DetectorContext::setup_context(const IDetector2D* detector)
43 {
44  active_indices = detector->active_indices();
45  analyzer_operator = detector->detectionProperties().analyzerOperator();
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)
std::unique_ptr< IPixel > createPixel(size_t element_index) const
Creates pixel for given element index.
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