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

Unit test for SphericalDetector::createDetectorMap

parent 4cbc733c
Branches
Tags
No related merge requests found
...@@ -116,21 +116,24 @@ OutputData<double>* IDetector2D::createDetectorMap(const Beam&, EAxesUnits) cons ...@@ -116,21 +116,24 @@ OutputData<double>* IDetector2D::createDetectorMap(const Beam&, EAxesUnits) cons
//! //!
void IDetector2D::initOutputData(OutputData<double>& data) const void IDetector2D::initOutputData(OutputData<double> &data) const {
{ data.clear();
data.clear();
if(m_region_of_interest) {
std::unique_ptr<IAxis> axis0(getAxis(0).createClippedAxis(m_region_of_interest->getXlow(), m_region_of_interest->getXup()));
std::unique_ptr<IAxis> axis1(getAxis(1).createClippedAxis(m_region_of_interest->getYlow(), m_region_of_interest->getYup()));
data.addAxis(*axis0);
data.addAxis(*axis1);
} else { if (m_region_of_interest) {
for(size_t i=0; i<getDimension(); ++i) std::unique_ptr<IAxis> axis0(getAxis(0).createClippedAxis(
data.addAxis(getAxis(i)); m_region_of_interest->getXlow(), m_region_of_interest->getXup()));
} data.addAxis(*axis0);
std::unique_ptr<IAxis> axis1(getAxis(1).createClippedAxis(
m_region_of_interest->getYlow(), m_region_of_interest->getYup()));
data.addAxis(*axis1);
} else {
for (size_t i = 0; i < getDimension(); ++i)
data.addAxis(getAxis(i));
}
data.setAllTo(0.); data.setAllTo(0.);
} }
std::vector<IDetector2D::EAxesUnits> IDetector2D::getValidAxesUnits() const std::vector<IDetector2D::EAxesUnits> IDetector2D::getValidAxesUnits() const
......
...@@ -10,6 +10,8 @@ ...@@ -10,6 +10,8 @@
#include "Polygon.h" #include "Polygon.h"
#include "BornAgainNamespace.h" #include "BornAgainNamespace.h"
#include "Rectangle.h" #include "Rectangle.h"
#include "Units.h"
#include "Beam.h"
#include <memory> #include <memory>
class SphericalDetectorTest : public ::testing::Test class SphericalDetectorTest : public ::testing::Test
...@@ -109,7 +111,7 @@ TEST_F(SphericalDetectorTest, constructionWithParameters) ...@@ -109,7 +111,7 @@ TEST_F(SphericalDetectorTest, constructionWithParameters)
EXPECT_EQ(BornAgain::ALPHA_AXIS_NAME, detector.getAxis(1).getName()); EXPECT_EQ(BornAgain::ALPHA_AXIS_NAME, detector.getAxis(1).getName());
} }
//! Init external data with detector axes //! Init external data with detector axes.
TEST_F(SphericalDetectorTest, initOutputData) TEST_F(SphericalDetectorTest, initOutputData)
{ {
...@@ -129,6 +131,45 @@ TEST_F(SphericalDetectorTest, initOutputData) ...@@ -129,6 +131,45 @@ TEST_F(SphericalDetectorTest, initOutputData)
EXPECT_EQ(BornAgain::ALPHA_AXIS_NAME, data.getAxis(1)->getName()); EXPECT_EQ(BornAgain::ALPHA_AXIS_NAME, data.getAxis(1)->getName());
} }
//! Creation of the detector map with axes in given units
TEST_F(SphericalDetectorTest, createDetectorMap)
{
SphericalDetector detector(10, -1.0*Units::deg, 1.0*Units::deg,
20, 0.0*Units::deg, 2.0*Units::deg);
Beam beam;
beam.setCentralK(1.0*Units::angstrom, 0.4*Units::deg, 0.0);
// creating map in default units, which are radians and checking axes
std::unique_ptr<OutputData<double>> data(
detector.createDetectorMap(beam, IDetector2D::DEFAULT));
EXPECT_EQ(data->getAxis(0)->getSize(), 10);
EXPECT_EQ(data->getAxis(0)->getMin(), -1.0*Units::deg);
EXPECT_EQ(data->getAxis(0)->getMax(), 1.0*Units::deg);
EXPECT_EQ(data->getAxis(1)->getSize(), 20);
EXPECT_EQ(data->getAxis(1)->getMin(), 0.0*Units::deg);
EXPECT_EQ(data->getAxis(1)->getMax(), 2.0*Units::deg);
// creating map in degrees and checking axes
data.reset(detector.createDetectorMap(beam, IDetector2D::DEGREES));
EXPECT_EQ(data->getAxis(0)->getSize(), 10);
EXPECT_FLOAT_EQ(data->getAxis(0)->getMin(), -1.0);
EXPECT_FLOAT_EQ(data->getAxis(0)->getMax(), 1.0);
EXPECT_EQ(data->getAxis(1)->getSize(), 20);
EXPECT_FLOAT_EQ(data->getAxis(1)->getMin(), 0.0);
EXPECT_FLOAT_EQ(data->getAxis(1)->getMax(), 2.0);
// creating map in nbins and checking axes
data.reset(detector.createDetectorMap(beam, IDetector2D::NBINS));
EXPECT_EQ(data->getAxis(0)->getSize(), 10);
EXPECT_FLOAT_EQ(data->getAxis(0)->getMin(), 0.0);
EXPECT_FLOAT_EQ(data->getAxis(0)->getMax(), 10.0);
EXPECT_EQ(data->getAxis(1)->getSize(), 20);
EXPECT_FLOAT_EQ(data->getAxis(1)->getMin(), 0.0);
EXPECT_FLOAT_EQ(data->getAxis(1)->getMax(), 20.0);
}
//! Testing region of interest. //! Testing region of interest.
TEST_F(SphericalDetectorTest, regionOfInterest) TEST_F(SphericalDetectorTest, regionOfInterest)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment