Skip to content
Snippets Groups Projects
Commit 7926e251 authored by Pospelov, Gennady's avatar Pospelov, Gennady
Browse files

Introduce DetectorContext as a replacement of DetectorElements

parent aa43bc92
No related branches found
No related tags found
No related merge requests found
// ************************************************************************** //
//
// 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));
}
// ************************************************************************** //
//
// 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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment