30 inline size_t xcoord(
size_t index,
size_t sizeX,
size_t sizeY)
32 return index / sizeY % sizeX;
35 inline size_t ycoord(
size_t index,
size_t sizeY)
46 , m_explicitROI(other.m_explicitROI)
47 , m_axes(other.m_axes)
48 , m_polAnalyzer(other.m_polAnalyzer)
49 , m_detector_mask(other.m_detector_mask)
82 const size_t dim =
rank();
83 size_t remainder(index);
85 for (
size_t i = 0; i < dim; ++i) {
87 if (selected_axis == i_axis)
101 s *= roiOfAxis.roiSize;
116 const size_t dim =
rank();
120 for (
size_t i_axis = 0; i_axis < dim; ++i_axis)
121 result *=
m_axes[i_axis]->size();
128 return (explicitSize != 0) ? explicitSize :
totalSize();
139 for (
size_t iAxis = 0; iAxis <
m_axes.
size(); ++iAxis) {
181 p_intensity_map->
setVector(buff->flatVector());
192 const std::vector<std::unique_ptr<DiffuseElement>>& elements)
const
196 size_t elementIndex = 0;
198 (*detectorMap)[it.roiIndex()] = elements[elementIndex++]->intensity();
202 return detectorMap.release();
207 const size_t dim =
rank();
210 std::vector<IAxis*> axes;
211 for (
size_t iAxis = 0; iAxis < dim; ++iAxis) {
214 axes.emplace_back(tmp);
217 return std::make_unique<Datafield>(axes);
232 if (explicitBounds.first != 0 || explicitBounds.second != 0)
233 return explicitBounds;
235 return m_axes[iAxis]->bounds();
245 if (this->
rank() == 0)
254 if (this->
rank() == 0)
284 return regionOfInterestIndex;
289 const size_t globalIndex0 = y.lowerIndex + x.lowerIndex * y.detectorSize;
290 return globalIndex0 + ycoord(regionOfInterestIndex, y.roiSize)
291 + xcoord(regionOfInterestIndex, x.roiSize, y.roiSize) * y.detectorSize;
297 return detectorIndex;
302 const size_t ny = ycoord(detectorIndex, y.detectorSize);
303 if (ny < y.lowerIndex || ny > y.upperIndex)
304 throw std::runtime_error(
"IDetector::detectorIndexToRegionOfInterestIndex() -> Error.");
306 const size_t nx = xcoord(detectorIndex, x.detectorSize, y.detectorSize);
307 if (nx < x.lowerIndex || nx > x.upperIndex)
308 throw std::runtime_error(
"IDetector::detectorIndexToRegionOfInterestIndex() -> Error.");
310 return ny - y.lowerIndex + (nx - x.lowerIndex) * y.roiSize;
330 double y_min,
double y_max)
348 std::vector<size_t> result;
357 return std::make_unique<DetectorContext>(
this);
Defines the macro ASSERT.
#define ASSERT(condition)
Defines class ConvolutionDetectorResolution.
Define DetectorContext class.
Defines class DetectorMask.
Defines class DiffuseElement.
Defines class FixedBinAxis.
Defines and implements templated class Frame.
Defines common detector interface.
Defines class InfinitePlane.
Defines some unit conversion factors and other constants in namespace Units.
Convolutes the intensity in 1 or 2 dimensions with a resolution function.
Stores radiation power per bin.
void setVector(const std::vector< double > &data_vector)
Sets new values to raw data vector.
const Frame & frame() const
Collection of detector masks.
Axis with fixed bin size.
std::vector< IAxis * > cloned_axes() const
Returns cloned axes.
Abstract base class for one-dimensional axes.
virtual size_t findClosestIndex(double value) const =0
find bin index which is best match for given value
virtual IAxis * clone() const =0
virtual size_t size() const =0
Returns the number of bins.
virtual void clip(double lower, double upper)
Clips this axis to the given values.
Interface for detector resolution algorithms.
IDetectorResolution * clone() const override=0
Abstract detector interface.
virtual std::pair< double, double > boundsOfExplicitRegionOfInterest(size_t iAxis) const
Lower and upper bound of one axis of an explicitly set ROI. Return 0/0 if no ROI has been explicitly ...
size_t sizeOfRegionOfInterest() const
The size of the "Region of Interest". Same as totalSize() if no region of interest has been explicitl...
void iterateOverRegionOfInterest(std::function< void(const_iterator)> func) const
Iterate over all points within "region of interest", no matter whether they are masked or not....
OwningVector< IAxis > m_axes
void addDetAxis(const IAxis &axis)
virtual size_t sizeOfExplicitRegionOfInterest() const
Return 0 if no ROI has been explicitly set. Size means number of data points.
virtual std::string axisName(size_t index) const =0
Returns the name for the axis with given index.
size_t numberOfElements() const
Returns number of simulation elements.
SimulationAreaIterator beginRegionOfInterestPoints() const
Create begin-iterator to iterate over all points which lay within the "Region of Interest"....
void setRegionOfInterest(double xlow, double ylow, double xup, double yup)
Sets rectangular region of interest with lower left and upper right corners defined.
std::pair< double, double > regionOfInterestBounds(size_t iAxis) const
The lower and upper bound of the region of interest. If no region of interest is explicitly defined,...
void maskAll()
Put the mask for all detector channels (i.e. exclude whole detector from the analysis)
void iterateOverNonMaskedPoints(std::function< void(const_iterator)> func) const
Iterate over all non-masked points within "region of interest". If no region of interest is explicitl...
std::vector< const INode * > nodeChildren() const override
Returns all children.
SimulationAreaIterator beginNonMaskedPoints() const
Create begin-iterator to iterate over all points which are not masked and lay within the "Region of I...
size_t axisBinIndex(size_t index, size_t selected_axis) const
Calculate axis index for given global index.
size_t regionOfInterestIndexToDetectorIndex(size_t regionOfInterestIndex) const
Convert an index of the region of interest to an index of the detector. If no region of interest is s...
size_t totalSize() const
Returns total number of pixels. Any region of interest is not taken into account.
void setDetectorParameters(size_t n_x, double x_min, double x_max, size_t n_y, double y_min, double y_max)
Sets equidistant axes.
std::unique_ptr< Datafield > createDetectorMap() const
Returns empty detector map in given axes units. This map is a data array limited to the size of the "...
std::unique_ptr< IDetectorResolution > m_detector_resolution
size_t detectorIndexToRegionOfInterestIndex(size_t detectorIndex) const
const IAxis & axis(size_t index) const
One axis of the complete detector. Any region of interest is not taken into account.
void addMask(const IShape2D &shape, bool mask_value=true)
Adds mask of given shape to the stack of detector masks. The mask value 'true' means that the channel...
bool hasExplicitRegionOfInterest() const
True if a region of interest is explicitly set.
void setResolutionFunction(const IResolutionFunction2D &resFunc)
std::vector< size_t > active_indices() const
Returns vector of unmasked detector indices.
OwningVector< IAxis > axesClippedToRegionOfInterest() const
Returns the axes clipped to the region of interest. If no region of interest is explicitly defined,...
void setAnalyzer(R3 direction, double efficiency, double total_transmission)
Sets the polarization analyzer characteristics of the detector.
SimulationAreaIterator endNonMaskedPoints() const
Create end-iterator to iterate over all points which are not masked and lay within the "Region of Int...
std::unique_ptr< DetectorContext > createContext() const
size_t getGlobalIndex(size_t x, size_t y) const
Calculate global index from two axis indices.
void setDetectorResolution(const IDetectorResolution &p_detector_resolution)
Sets the detector resolution.
std::vector< RoiOfAxis > m_explicitROI
an explicitly defined region of interest. Empty if no ROI has been defined. Vector index corresponds ...
const IDetectorResolution * detectorResolution() const
Returns a pointer to detector resolution object.
SimulationAreaIterator endRegionOfInterestPoints() const
Create end-iterator to iterate over all points which lay within the "Region of Interest"....
void resetRegionOfInterest()
Resets region of interest making whole detector plane available for the simulation.
size_t rank() const
Returns number of defined axes.
const DetectorMask * detectorMask() const
Datafield * createDetectorIntensity(const std::vector< std::unique_ptr< DiffuseElement >> &elements) const
Returns new intensity map with resolution applied, and cropped to ROI if applicable.
void applyDetectorResolution(Datafield *p_intensity_map) const
Applies the detector resolution to the given intensity maps.
std::shared_ptr< DetectorMask > m_detector_mask
Base class for tree-like structures containing parameterized objects.
Interface providing two-dimensional resolution function.
Basic class for all shapes in 2D.
The infinite plane is used for masking the entire detector.
Detector properties (efficiency, transmission).
An iterator for SimulationArea.
size_t detectorIndex() const
SimulationAreaIterator createEnd() const
Convenience function to create an end-iterator matching to this iterator.
@ notMasked
iterate over all points in "region of interest" and not masked
@ regionOfInterest
iterate over all points in "region of interest", no matter whether masked
static SimulationAreaIterator createBegin(const IDetector *detector, Mode mode)
Create begin-iterator to iterate over all points according to the given mode.
size_t roiSize
number of bins on axis of ROI
size_t upperIndex
index corresponding to 'upper'
RoiOfAxis(const IAxis &axis, double lower, double upper)
size_t detectorSize
number of bins on axis of detector
size_t lowerIndex
index corresponding to 'lower'