diff --git a/Core/Instrument/SpecularDetector1D.cpp b/Core/Instrument/SpecularDetector1D.cpp index 9f19a157463d9e67a98e1a7fc1f36cfb3ed32f94..0d822ed696954453051a0c6cf175a7d5794fded5 100644 --- a/Core/Instrument/SpecularDetector1D.cpp +++ b/Core/Instrument/SpecularDetector1D.cpp @@ -15,6 +15,7 @@ #include "Beam.h" #include "DetectorElement.h" #include "IPixel.h" +#include "OutputData.h" #include "SimulationArea.h" #include "SimulationElement.h" #include "SpecularDetector1D.h" @@ -143,6 +144,33 @@ std::vector<DetectorElement> SpecularDetector1D::createDetectorElements(const Be return result; } +OutputData<double>* +SpecularDetector1D::createDetectorIntensity(const std::vector<SpecularSimulationElement>& elements, + const Beam& beam, AxesUnits units_type) const +{ + std::unique_ptr<OutputData<double>> detectorMap(createDetectorMap(beam, units_type)); + if (!detectorMap) + throw std::runtime_error("Instrument::createDetectorIntensity:" + "can't create detector map."); + + if (detectorResolution()) { + if (units_type != AxesUnits::DEFAULT) { + std::unique_ptr<OutputData<double>> defaultMap( + createDetectorMap(beam, AxesUnits::DEFAULT)); + setDataToDetectorMap(*defaultMap, elements); + applyDetectorResolution(defaultMap.get()); + detectorMap->setRawDataVector(defaultMap->getRawDataVector()); + } else { + setDataToDetectorMap(*detectorMap, elements); + applyDetectorResolution(detectorMap.get()); + } + } else { + setDataToDetectorMap(*detectorMap, elements); + } + + return detectorMap.release(); +} + std::string SpecularDetector1D::axisName(size_t index) const { if (index == 0) { @@ -165,3 +193,14 @@ void SpecularDetector1D::calculateAxisRange(size_t axis_index, const Beam& beam, IDetector::calculateAxisRange(axis_index, beam, units, amin, amax); } } + +void SpecularDetector1D::setDataToDetectorMap( + OutputData<double>& detectorMap, const std::vector<SpecularSimulationElement>& elements) const +{ + if(elements.empty()) + return; + SimulationArea area(this); + for(SimulationArea::iterator it = area.begin(); it!=area.end(); ++it) + detectorMap[it.roiIndex()] = elements[it.elementIndex()].getIntensity(); + +} diff --git a/Core/Instrument/SpecularDetector1D.h b/Core/Instrument/SpecularDetector1D.h index 3cb78efd43ccb483ae29171987cd8ae5393dacfe..0c0fd34e87d3bf9b19c2e32000f720b1200f19db 100644 --- a/Core/Instrument/SpecularDetector1D.h +++ b/Core/Instrument/SpecularDetector1D.h @@ -45,6 +45,12 @@ public: std::vector<DetectorElement> createDetectorElements(const Beam& beam) override; #endif // SWIG + using IDetector::createDetectorIntensity; + //! Returns new intensity map with detector resolution applied and axes in requested units + OutputData<double>* + createDetectorIntensity(const std::vector<SpecularSimulationElement>& elements, + const Beam& beam, AxesUnits units_type) const; + //! Returns region of interest if exists. const RegionOfInterest* regionOfInterest() const override { return nullptr; } @@ -67,6 +73,9 @@ protected: double& amin, double& amax) const override; private: + void setDataToDetectorMap(OutputData<double>& detectorMap, + const std::vector<SpecularSimulationElement>& elements) const; + double alphaI(size_t index) const; };