diff --git a/Core/Instrument/RectangularDetector.cpp b/Core/Instrument/RectangularDetector.cpp index ca2f2b7022e7946fb1a87ba31d50c232014dddf3..400205be8456fadae96ecb1058d2687b7c0b4a85 100644 --- a/Core/Instrument/RectangularDetector.cpp +++ b/Core/Instrument/RectangularDetector.cpp @@ -312,7 +312,24 @@ std::string RectangularDetector::getAxisName(size_t index) const size_t RectangularDetector::getIndexOfSpecular(const Beam& beam) const { - (void)beam; + if (getDimension()!=2) return getTotalSize(); + double alpha = beam.getAlpha(); + double phi = beam.getPhi(); + kvector_t k_spec = vecOfLambdaAlphaPhi(beam.getWavelength(), alpha, phi); + kvector_t normal_unit = m_normal_to_detector.unit(); + double kd = k_spec.dot(normal_unit); + if (kd<=0.0) return getTotalSize(); + kvector_t k_orth = (k_spec/kd - normal_unit)*m_distance; + double u = k_orth.dot(m_u_unit) + m_u0; + double v = k_orth.dot(m_v_unit) + m_v0; + const IAxis& u_axis = getAxis(BornAgain::X_AXIS_INDEX); + const IAxis& v_axis = getAxis(BornAgain::Y_AXIS_INDEX); + size_t u_index = u_axis.findClosestIndex(u); + size_t v_index = v_axis.findClosestIndex(v); + if (BinContains(u_axis.getBin(u_index), u) && + BinContains(v_axis.getBin(v_index), v)) { + return getGlobalIndex(u_index, v_index); + } return getTotalSize(); }