diff --git a/Core/Instrument/DetectorContext.cpp b/Core/Instrument/DetectorContext.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f9fc7ce37324256f8a0ef6413863bdbb3aba7a9b --- /dev/null +++ b/Core/Instrument/DetectorContext.cpp @@ -0,0 +1,49 @@ +// ************************************************************************** // +// +// BornAgain: simulate and fit scattering at grazing incidence +// +//! @file Core/Instrument/DetectorContext.cpp +//! @brief Implements DetectorContext class. +//! +//! @homepage http://www.bornagainproject.org +//! @license GNU General Public License v3 or higher (see COPYING) +//! @copyright Forschungszentrum Jülich GmbH 2018 +//! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS) +// +// ************************************************************************** // + +#include "DetectorContext.h" +#include "IDetector2D.h" + +DetectorContext::DetectorContext(const IDetector2D *detector) +{ + setup_context(detector); +} + +size_t DetectorContext::numberOfSimulationElements() const +{ + return active_indices.size(); +} + +//! Creates pixel for given element index. Element index is sequetial index in a vector +//! of SimulationElements. Corresponds to sequence of detector bins inside ROI and outside +//! of masked areas. + +std::unique_ptr<IPixel> DetectorContext::createPixel(size_t element_index) const +{ + return std::unique_ptr<IPixel>(pixels[element_index]->clone()); +} + +size_t DetectorContext::detectorIndex(size_t element_index) const +{ + return active_indices[element_index]; +} + +void DetectorContext::setup_context(const IDetector2D *detector) +{ + active_indices = detector->active_indices(); + analyzer_operator = detector->detectionProperties().analyzerOperator(); + pixels.reserve(active_indices.size()); + for (auto detector_index : active_indices) + pixels.emplace_back(detector->createPixel(detector_index)); +} diff --git a/Core/Instrument/DetectorContext.h b/Core/Instrument/DetectorContext.h new file mode 100644 index 0000000000000000000000000000000000000000..fcbc2513aec1860627b69c9bb79f97dcd9215400 --- /dev/null +++ b/Core/Instrument/DetectorContext.h @@ -0,0 +1,47 @@ +// ************************************************************************** // +// +// BornAgain: simulate and fit scattering at grazing incidence +// +//! @file Core/Instrument/DetectorContext.h +//! @brief Define DetectorContext class. +//! +//! @homepage http://www.bornagainproject.org +//! @license GNU General Public License v3 or higher (see COPYING) +//! @copyright Forschungszentrum Jülich GmbH 2018 +//! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS) +// +// ************************************************************************** // + +#ifndef DETECTORCONTEXT_H +#define DETECTORCONTEXT_H + +#include "EigenCore.h" +#include "IPixel.h" +#include "WinDllMacros.h" +#include <memory> +#include <vector> + +class IDetector2D; + +//! Holds precalculated information for faster SimulationElement generation. +//! @ingroup simulation + +class BA_CORE_API_ DetectorContext +{ +public: + DetectorContext(const IDetector2D* detector); + size_t numberOfSimulationElements() const; + + std::unique_ptr<IPixel> createPixel(size_t element_index) const; + + size_t detectorIndex(size_t element_index) const; + +private: + void setup_context(const IDetector2D* detector); + + Eigen::Matrix2cd analyzer_operator; + std::vector<std::unique_ptr<IPixel>> pixels; //! All unmasked pixels inside ROI. + std::vector<size_t> active_indices; //! The sequence of detector bin indices (unmasked, in ROI) +}; + +#endif // DETECTORCONTEXT_H