Skip to content
Snippets Groups Projects
DetectorContext.cpp 1.66 KiB
//  ************************************************************************************************
//
//  BornAgain: simulate and fit reflection and scattering
//
//! @file      Device/Detector/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 "Device/Detector/DetectorContext.h"
#include "Device/Detector/IDetector2D.h"

DetectorContext::DetectorContext(const IDetector2D* detector)
{
    setup_context(detector);
}

size_t DetectorContext::numberOfElements() const
{
    return m_active_indices.size();
}

//! Creates pixel for given element index. Element index is sequential index in a vector
//! of DiffuseElements. 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>(m_pixels[element_index]->clone());
}

size_t DetectorContext::detectorIndex(size_t element_index) const
{
    return m_active_indices[element_index];
}

void DetectorContext::setup_context(const IDetector2D* detector)
{
    m_active_indices = detector->active_indices();
    m_analyzer_operator = detector->analyzer().matrix();
    m_pixels.reserve(m_active_indices.size());
    for (auto detector_index : m_active_indices)
        m_pixels.emplace_back(detector->createPixel(detector_index));
}