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

Yet another convenience function for OutputData, and tests

parent e951e224
No related branches found
No related tags found
No related merge requests found
......@@ -101,6 +101,9 @@ public:
//! returns wavelength
virtual double getWavelength() const;
void setMask(bool mask);
void setRectangularMask(double xlow, double ylow, double xup, double yup, bool mask = true);
protected:
GISASSimulation(const GISASSimulation& other);
......@@ -120,6 +123,7 @@ protected:
// extra components describing a GISAS experiment and its simulation:
Instrument m_instrument;
OutputData<double> m_intensity_map;
OutputData<bool > m_detector_mask;
};
#endif /* GISASSIMULATION_H_ */
......@@ -100,12 +100,12 @@ int GISASSimulation::getNumberOfSimulationElements() const
throw RuntimeErrorException("GISASSimulation::getNumberOfSimulationElements: "
"detector is not two-dimensional");
}
const IAxis &phi_axis = m_instrument.getDetectorAxis(0);
const IAxis &phi_axis = m_instrument.getDetectorAxis(BornAgain::PHI_AXIS_INDEX);
if (phi_axis.getName()!=BornAgain::PHI_AXIS_NAME) {
throw RuntimeErrorException("GISASSimulation::getNumberOfSimulationElements: "
"phi-axis is not correct");
}
const IAxis &alpha_axis = m_instrument.getDetectorAxis(1);
const IAxis &alpha_axis = m_instrument.getDetectorAxis(BornAgain::ALPHA_AXIS_INDEX);
if (alpha_axis.getName()!=BornAgain::ALPHA_AXIS_NAME) {
throw RuntimeErrorException("GISASSimulation::getNumberOfSimulationElements: "
"alpha-axis is not correct");
......@@ -210,6 +210,28 @@ double GISASSimulation::getWavelength() const
return m_instrument.getBeam().getWavelength();
}
void GISASSimulation::setMask(bool mask)
{
// if(!m_detector_mask.hasSameShape(m_intensity_map)) {
// m_detector_mask.copyShapeFrom(m_intensity_map);
// }
m_detector_mask.setAllTo(mask);
}
void GISASSimulation::setRectangularMask(double xlow, double ylow, double xup, double yup, bool mask)
{
// if(!m_detector_mask.hasSameShape(m_intensity_map)) {
// m_detector_mask.copyShapeFrom(m_intensity_map);
// }
for(size_t index=0; index<m_detector_mask.getAllocatedSize(); ++index) {
double x = m_detector_mask.getAxisValue(index, BornAgain::PHI_AXIS_INDEX);
double y = m_detector_mask.getAxisValue(index, BornAgain::PHI_AXIS_INDEX);
}
}
GISASSimulation::GISASSimulation(const GISASSimulation& other)
: Simulation(other)
, m_instrument(other.m_instrument)
......
......@@ -22,6 +22,8 @@ namespace BornAgain
{
static const std::string PHI_AXIS_NAME = "phi_f";
static const std::string ALPHA_AXIS_NAME = "alpha_f";
static const size_t PHI_AXIS_INDEX = 0;
static const size_t ALPHA_AXIS_INDEX = 1;
const std::string FTDistribution2DCauchyType = "FTDistribution2DCauchy";
const std::string FTDistribution2DGaussType = "FTDistribution2DGauss";
......
......@@ -169,6 +169,11 @@ public:
//! @return corresponding bin center of selected axis
double getAxisValue(size_t global_index, const std::string& axis_name) const;
//! Returns values on all defined axes for given globalbin number
//! @param global_index The global index of this data structure.
//! @return Vector of corresponding bin centers
std::vector<double > getAxesValues(size_t global_index) const;
//! Returns bin of selected axis for given global_index.
//! @param global_index The global index of this data structure.
//! @param axis_name The name of selected axis.
......@@ -543,6 +548,17 @@ double OutputData<T>::getAxisValue(size_t global_index, const std::string& axis_
return getAxisValue(global_index, getAxisSerialNumber(axis_name));
}
template <class T>
std::vector<double> OutputData<T>::getAxesValues(size_t global_index) const
{
std::vector<int> indices = getAxesBinIndices(global_index);
std::vector<double > result;
for(size_t i_axis=0; i_axis<indices.size(); ++i_axis) {
result.push_back((*m_value_axes[i_axis])[indices[i_axis]]);
}
return result;
}
template <class T>
Bin1D OutputData<T>::getAxisBin(size_t global_index, const std::string& axis_name) const
{
......
......@@ -193,6 +193,10 @@ TEST_F(OutputDataTest, ValueOfAxis)
EXPECT_EQ( 2.5, data.getAxisValue(18, "axis2"));
EXPECT_EQ( 7.5, data.getAxisValue(19, "axis2"));
std::vector<double > coordinates = data.getAxesValues(18);
EXPECT_EQ(9.5, coordinates[0]);
EXPECT_EQ(2.5, coordinates[1]);
OutputData<Eigen::Matrix2d > mdata;
mdata.addAxis("axis1", 10, 0., 10.);
mdata.addAxis("axis2", 2, 0., 10.);
......
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