diff --git a/Core/Algorithms/inc/Beam.h b/Core/Algorithms/inc/Beam.h index 52d815825e10a14c151d7d27634cc4e8ef74ba0d..69657f505001adee2d5b5c6c20437748c3cac832 100644 --- a/Core/Algorithms/inc/Beam.h +++ b/Core/Algorithms/inc/Beam.h @@ -34,7 +34,7 @@ public: virtual ~Beam() {} //! Get the value of the wavevector - cvector_t getCentralK() const; + kvector_t getCentralK() const; //! Sets the value of the incoming wavevector in terms of wavelength //! and incoming angles diff --git a/Core/Algorithms/inc/GISASSimulation.h b/Core/Algorithms/inc/GISASSimulation.h index 8d975f028296477ce7428d3bbef6e9e7ffe45718..5577f679d419b75e0ab8ab937d1db779c749a50b 100644 --- a/Core/Algorithms/inc/GISASSimulation.h +++ b/Core/Algorithms/inc/GISASSimulation.h @@ -73,7 +73,8 @@ public: void setInstrument(const Instrument& instrument); //! Returns the instrument containing beam and detector information - const Instrument& getInstrument() const; + const Instrument& getInstrument() const { return m_instrument; } + Instrument& getInstrument() { return m_instrument; } //! Sets beam parameters from here (forwarded to Instrument) void setBeamParameters(double wavelength, double alpha_i, double phi_i); @@ -91,9 +92,15 @@ public: void setDetectorParameters(const OutputData<double> &output_data); void setDetectorParameters(const IHistogram &hisotgram); - //! Sets detector parameters using angle ranges - void setDetectorParameters(size_t n_x, double x_min, double x_max, - size_t n_y, double y_min, double y_max); + //! Sets spherical detector parameters using angle ranges + //! @param n_phi number of phi-axis bins + //! @param phi_min low edge of first phi-bin + //! @param phi_max upper edge of last phi-bin + //! @param n_alpha number of alpha-axis bins + //! @param alpha_min low edge of first alpha-bin + //! @param alpha_max upper edge of last alpha-bin + void setDetectorParameters(size_t n_phi, double phi_min, double phi_max, + size_t n_alpha, double alpha_min, double alpha_max); //! Define resolution function for detector void setDetectorResolutionFunction(const IResolutionFunction2D &resolution_function); diff --git a/Core/Algorithms/inc/IDetector2D.h b/Core/Algorithms/inc/IDetector2D.h index d1fda15e3283ad1dfe97ab24959d3a5f48927348..72b7f177f7726fc52b42d06285b31e79f2303ca2 100644 --- a/Core/Algorithms/inc/IDetector2D.h +++ b/Core/Algorithms/inc/IDetector2D.h @@ -27,6 +27,8 @@ #include <boost/scoped_ptr.hpp> +class GISASSimulation; + //! @class IDetector //! @ingroup simulation //! @brief The detector interface. @@ -41,6 +43,9 @@ public: virtual ~IDetector2D() {} + //! Inits detector using simulation settings (e.g. beam position) if necessary + virtual void init(const GISASSimulation *simulation); + void addAxis(const IAxis &axis); const IAxis &getAxis(size_t index) const; diff --git a/Core/Algorithms/inc/IsGISAXSDetector.h b/Core/Algorithms/inc/IsGISAXSDetector.h index 2a79eee0ec14fc9404cd6f2406e6776de135b5b5..4afca2e6af6e1bb1172310acdda16658bbb50616 100644 --- a/Core/Algorithms/inc/IsGISAXSDetector.h +++ b/Core/Algorithms/inc/IsGISAXSDetector.h @@ -26,6 +26,9 @@ class BA_CORE_API_ IsGISAXSDetector : public SphericalDetector { public: IsGISAXSDetector(); + IsGISAXSDetector(size_t n_phi, double phi_min, double phi_max, + size_t n_alpha, double alpha_min, double alpha_max); + IsGISAXSDetector(const IsGISAXSDetector &other); IsGISAXSDetector &operator=(const IsGISAXSDetector &other); diff --git a/Core/Algorithms/inc/RectangularDetector.h b/Core/Algorithms/inc/RectangularDetector.h index 7a32069c5f7148393ab206f59e23c665bca3e9dd..381da48820a641723978b9910807c07c6373ae85 100644 --- a/Core/Algorithms/inc/RectangularDetector.h +++ b/Core/Algorithms/inc/RectangularDetector.h @@ -34,7 +34,22 @@ class RectPixelMap; class BA_CORE_API_ RectangularDetector : public IDetector2D { public: - RectangularDetector(kvector_t normal_to_detector, kvector_t u_direction); + + enum EDetectorArrangement { + GENERIC, + PERPENDICULAR_TO_SAMPLE, + PERPENDICULAR_TO_DIRECT_BEAM, + PERPENDICULAR_TO_REFLECTED_BEAM, + PERPENDICULAR_TO_REFLECTED_BEAM_DPOS + }; + + //! Rectangular detector constructor + //! @param nxbins Number of bins (pixels) in x-direction + //! @param width Width of the detector in mm along x-direction + //! @param nybins Number of bins (pixels) in y-direction + //! @param height Height of the detector in mm along y-direction + RectangularDetector(int nxbins, double width, int nybins, double height); + RectangularDetector(const RectangularDetector &other); RectangularDetector &operator=(const RectangularDetector &other); @@ -42,10 +57,34 @@ public: virtual ~RectangularDetector() {} + void init(const GISASSimulation *simulation); + + void setPosition(const kvector_t &normal_to_detector, double u0, double v0, + const kvector_t &direction = kvector_t(0.0, -1.0, 0.0)); + + void setPerpendicularToSampleX(double distance, double u0, double v0); + + void setPerpendicularToDirectBeam(double distance, double u0, double v0); + void setPerpendicularToReflectedBeam(double distance, double u0 = 0.0, double v0 = 0.0); + void setDirectBeamPosition(double u0, double v0); + //! Adds parameters from local pool to external pool and recursively calls its direct children. virtual std::string addParametersToExternalPool(std::string path, ParameterPool *external_pool, int copy_number = -1) const; + double getWidth() const; + double getHeight() const; + size_t getNbinsX() const; + size_t getNbinsY() const; + kvector_t getNormalVector() const; + double getU0() const; + double getV0() const; + kvector_t getDirectionVector() const; + double getDistance() const; + double getDirectBeamU0() const; + double getDirectBeamV0() const; + EDetectorArrangement getDetectorArrangment() const; + protected: //! Create an IPixelMap for the given OutputData object and index virtual IPixelMap* createPixelMap(size_t index) const; @@ -64,8 +103,17 @@ protected: //! swap function void swapContent(RectangularDetector &other); private: + void setDistanceAndOffset(double distance, double u0, double v0); kvector_t normalizeToUnitLength(const kvector_t& direction) const; + void initNormalVector(const kvector_t ¢ral_k); + void initUandV(double alpha_i); + kvector_t m_normal_to_detector; + double m_u0, m_v0; //!< position of normal vector hitting point in detector coordinates + kvector_t m_direction; //!< direction vector of detector coordinate system + double m_distance; //!< distance from sample origin to the detector plane + double m_dbeam_u0, m_dbeam_v0; //!< position of direct beam in detector coordinates + EDetectorArrangement m_detector_arrangement; kvector_t m_u_unit; kvector_t m_v_unit; }; diff --git a/Core/Algorithms/inc/SphericalDetector.h b/Core/Algorithms/inc/SphericalDetector.h index 638d162e2d3da9456d0417279e88c5842a0e48ba..4b07fc942996053741399e7a7ab2b0432d377905 100644 --- a/Core/Algorithms/inc/SphericalDetector.h +++ b/Core/Algorithms/inc/SphericalDetector.h @@ -35,6 +35,17 @@ class BA_CORE_API_ SphericalDetector : public IDetector2D { public: SphericalDetector(); + + //! Spherical detector constructor using angle ranges + //! @param n_phi number of phi-axis bins + //! @param phi_min low edge of first phi-bin + //! @param phi_max upper edge of last phi-bin + //! @param n_alpha number of alpha-axis bins + //! @param alpha_min low edge of first alpha-bin + //! @param alpha_max upper edge of last alpha-bin + SphericalDetector(size_t n_phi, double phi_min, double phi_max, + size_t n_alpha, double alpha_min, double alpha_max); + SphericalDetector(const SphericalDetector &other); SphericalDetector &operator=(const SphericalDetector &other); diff --git a/Core/Algorithms/src/Beam.cpp b/Core/Algorithms/src/Beam.cpp index bae22047f80cb8177c1b4eae05d9cff3c2f05c00..9cb792b63bba91fbd758ee33b022b9ea0a58e8c0 100644 --- a/Core/Algorithms/src/Beam.cpp +++ b/Core/Algorithms/src/Beam.cpp @@ -45,9 +45,9 @@ Beam &Beam::operator=(const Beam &other) return *this; } -cvector_t Beam::getCentralK() const +kvector_t Beam::getCentralK() const { - cvector_t k; + kvector_t k; k.setLambdaAlphaPhi(m_wavelength, -1.0 * m_alpha, m_phi); return k; } diff --git a/Core/Algorithms/src/GISASSimulation.cpp b/Core/Algorithms/src/GISASSimulation.cpp index c15ae95ce60a80286d02e22e8fb10e7c6139ac1a..7b382fb151f386d1203ec634a8b82e2de6208bfd 100644 --- a/Core/Algorithms/src/GISASSimulation.cpp +++ b/Core/Algorithms/src/GISASSimulation.cpp @@ -78,6 +78,9 @@ void GISASSimulation::prepareSimulation() "GISASSimulation::prepareSimulation() " "-> Error. Incoming wavelength <= 0."); } + + getInstrument().getDetector()->init(this); + Simulation::prepareSimulation(); } @@ -154,10 +157,10 @@ void GISASSimulation::setDetectorParameters(const IHistogram &hisotgram) setDetectorParameters(*data); } -void GISASSimulation::setDetectorParameters(size_t n_x, double x_min, double x_max, - size_t n_y, double y_min, double y_max) +void GISASSimulation::setDetectorParameters(size_t n_phi, double phi_min, double phi_max, + size_t n_alpha, double alpha_min, double alpha_max) { - m_instrument.setDetectorParameters(n_x, x_min, x_max, n_y, y_min, y_max); + m_instrument.setDetectorParameters(n_phi, phi_min, phi_max, n_alpha, alpha_min, alpha_max); updateIntensityMap(); } diff --git a/Core/Algorithms/src/IDetector2D.cpp b/Core/Algorithms/src/IDetector2D.cpp index c9ff75e1f165aca744c7b35898f09388fd05a150..c10bc147b342a5636072c942d931dda761778d8c 100644 --- a/Core/Algorithms/src/IDetector2D.cpp +++ b/Core/Algorithms/src/IDetector2D.cpp @@ -39,6 +39,11 @@ IDetector2D::IDetector2D(const IDetector2D &other) init_parameters(); } +void IDetector2D::init(const GISASSimulation *simulation) +{ + (void)simulation; +} + const IAxis &IDetector2D::getAxis(size_t index) const { if (isCorrectAxisIndex(index)) { diff --git a/Core/Algorithms/src/IsGISAXSDetector.cpp b/Core/Algorithms/src/IsGISAXSDetector.cpp index 53d8fed3154f322eee178f78cd82473321ca5f52..a0ba129124267cdfb30724baf315cd4567adfe81 100644 --- a/Core/Algorithms/src/IsGISAXSDetector.cpp +++ b/Core/Algorithms/src/IsGISAXSDetector.cpp @@ -24,6 +24,14 @@ IsGISAXSDetector::IsGISAXSDetector() init_parameters(); } +IsGISAXSDetector::IsGISAXSDetector(size_t n_phi, double phi_min, double phi_max, size_t n_alpha, + double alpha_min, double alpha_max) +{ + setName(BornAgain::IsGISAXSDetectorType); + init_parameters(); + setDetectorParameters(n_phi, phi_min, phi_max, n_alpha, alpha_min, alpha_max); +} + IsGISAXSDetector::IsGISAXSDetector(const IsGISAXSDetector &other) : SphericalDetector(other) { diff --git a/Core/Algorithms/src/RectangularDetector.cpp b/Core/Algorithms/src/RectangularDetector.cpp index bfd809a9a3bacc03290091575273c1132aef175e..eab8b51ca89e565b8195b893bb2957c7944a922b 100644 --- a/Core/Algorithms/src/RectangularDetector.cpp +++ b/Core/Algorithms/src/RectangularDetector.cpp @@ -21,16 +21,22 @@ #include "CustomBinAxis.h" #include "Beam.h" #include "Rectangle.h" +#include "GISASSimulation.h" +#include "Instrument.h" +#include "Beam.h" #include <iostream> -RectangularDetector::RectangularDetector(kvector_t normal_to_detector, kvector_t u_direction) - : m_normal_to_detector(normal_to_detector) +RectangularDetector::RectangularDetector(int nxbins, double width, int nybins, double height) + : m_u0(0.0) + , m_v0(0.0) + , m_direction(kvector_t(0.0, -1.0, 0.0)) + , m_distance(0.0) + , m_dbeam_u0(0.0) + , m_dbeam_v0(0.0) + , m_detector_arrangement(GENERIC) { - double d2 = m_normal_to_detector.dot(m_normal_to_detector); - m_u_unit = normalizeToUnitLength( - d2 * u_direction - u_direction.dot(m_normal_to_detector) * m_normal_to_detector); - m_v_unit = normalizeToUnitLength(m_u_unit.cross(m_normal_to_detector)); + setDetectorParameters(nxbins, 0.0, width, nybins, 0.0, height); setName(BornAgain::RectangularDetectorType); init_parameters(); } @@ -38,7 +44,15 @@ RectangularDetector::RectangularDetector(kvector_t normal_to_detector, kvector_t RectangularDetector::RectangularDetector(const RectangularDetector &other) : IDetector2D(other) , m_normal_to_detector(other.m_normal_to_detector) - , m_u_unit(other.m_u_unit), m_v_unit(other.m_v_unit) + , m_u0(other.m_u0) + , m_v0(other.m_v0) + , m_direction(other.m_direction) + , m_distance(other.m_distance) + , m_dbeam_u0(other.m_dbeam_u0) + , m_dbeam_v0(other.m_dbeam_v0) + , m_detector_arrangement(other.m_detector_arrangement) + , m_u_unit(other.m_u_unit) + , m_v_unit(other.m_v_unit) { setName(BornAgain::RectangularDetectorType); init_parameters(); @@ -58,6 +72,49 @@ RectangularDetector *RectangularDetector::clone() const return new RectangularDetector(*this); } +void RectangularDetector::init(const GISASSimulation *simulation) +{ + double alpha_i = simulation->getInstrument().getBeam().getAlpha(); + kvector_t central_k = simulation->getInstrument().getBeam().getCentralK(); + initNormalVector(central_k); + initUandV(alpha_i); +} + +void RectangularDetector::setPosition(const kvector_t &normal_to_detector, + double u0, double v0, const kvector_t &direction) +{ + m_detector_arrangement = GENERIC; + m_normal_to_detector = normal_to_detector; + m_u0 = u0; + m_v0 = v0; + m_direction = direction; +} + +void RectangularDetector::setPerpendicularToSampleX(double distance, double u0, double v0) +{ + m_detector_arrangement = PERPENDICULAR_TO_SAMPLE; + setDistanceAndOffset(distance, u0, v0); +} + +void RectangularDetector::setPerpendicularToDirectBeam(double distance, double u0, double v0) +{ + m_detector_arrangement = PERPENDICULAR_TO_DIRECT_BEAM; + setDistanceAndOffset(distance, u0, v0); +} + +void RectangularDetector::setPerpendicularToReflectedBeam(double distance, double u0, double v0) +{ + m_detector_arrangement = PERPENDICULAR_TO_REFLECTED_BEAM; + setDistanceAndOffset(distance, u0, v0); +} + +void RectangularDetector::setDirectBeamPosition(double u0, double v0) +{ + m_detector_arrangement = PERPENDICULAR_TO_REFLECTED_BEAM_DPOS; + m_dbeam_u0 = u0; + m_dbeam_v0 = v0; +} + IPixelMap *RectangularDetector::createPixelMap(size_t index) const { const IAxis &u_axis = getAxis(BornAgain::X_AXIS_INDEX); @@ -68,14 +125,15 @@ IPixelMap *RectangularDetector::createPixelMap(size_t index) const Bin1D u_bin = u_axis.getBin(u_index); Bin1D v_bin = v_axis.getBin(v_index); kvector_t corner_position = m_normal_to_detector - + u_bin.m_lower*m_u_unit + v_bin.m_lower*m_v_unit; + + (u_bin.m_lower - m_u0)*m_u_unit + (v_bin.m_lower - m_v0)*m_v_unit; kvector_t width = u_bin.getBinSize()*m_u_unit; kvector_t height = v_bin.getBinSize()*m_v_unit; return new RectPixelMap(corner_position, width, height); } -std::string RectangularDetector::addParametersToExternalPool(std::string path, ParameterPool *external_pool, - int copy_number) const +std::string RectangularDetector::addParametersToExternalPool(std::string path, + ParameterPool *external_pool, + int copy_number) const { // add own parameters std::string new_path @@ -88,6 +146,68 @@ std::string RectangularDetector::addParametersToExternalPool(std::string path, P return new_path; } +double RectangularDetector::getWidth() const +{ + const IAxis &axis = getAxis(BornAgain::X_AXIS_INDEX); + return axis.getMax() - axis.getMin(); +} + +double RectangularDetector::getHeight() const +{ + const IAxis &axis = getAxis(BornAgain::Y_AXIS_INDEX); + return axis.getMax() - axis.getMin(); +} + +size_t RectangularDetector::getNbinsX() const +{ + return getAxis(BornAgain::X_AXIS_INDEX).getSize(); +} + +size_t RectangularDetector::getNbinsY() const +{ + return getAxis(BornAgain::Y_AXIS_INDEX).getSize(); +} + +kvector_t RectangularDetector::getNormalVector() const +{ + return m_normal_to_detector; +} + +double RectangularDetector::getU0() const +{ + return m_u0; +} + +double RectangularDetector::getV0() const +{ + return m_v0; +} + +kvector_t RectangularDetector::getDirectionVector() const +{ + return m_direction; +} + +double RectangularDetector::getDistance() const +{ + return m_distance; +} + +double RectangularDetector::getDirectBeamU0() const +{ + return m_dbeam_u0; +} + +double RectangularDetector::getDirectBeamV0() const +{ + return m_dbeam_v0; +} + +RectangularDetector::EDetectorArrangement RectangularDetector::getDetectorArrangment() const +{ + return m_detector_arrangement; +} + void RectangularDetector::print(std::ostream &ostr) const { ostr << "RectangularDetector: '" << getName() << "' " << m_parameters; @@ -131,6 +251,19 @@ void RectangularDetector::swapContent(RectangularDetector &other) std::swap(this->m_v_unit, other.m_v_unit); } +void RectangularDetector::setDistanceAndOffset(double distance, double u0, double v0) +{ + if(distance <= 0.0) { + std::ostringstream message; + message << "RectangularDetector::setPerpendicularToSample() -> Error. " + << "Distance to sample can't be negative or zero"; + throw Exceptions::LogicErrorException(message.str()); + } + m_distance = distance; + m_u0 = u0; + m_v0 = v0; +} + kvector_t RectangularDetector::normalizeToUnitLength(const kvector_t &direction) const { double old_length = direction.mag(); @@ -138,6 +271,57 @@ kvector_t RectangularDetector::normalizeToUnitLength(const kvector_t &direction) return direction/old_length; } +void RectangularDetector::initNormalVector(const kvector_t ¢ral_k) +{ + kvector_t central_k_unit = central_k.normalize(); + + if (m_detector_arrangement == GENERIC) { + // do nothing + } + + else if(m_detector_arrangement == PERPENDICULAR_TO_SAMPLE) { + m_normal_to_detector = kvector_t(m_distance, 0.0, 0.0); + } + + else if(m_detector_arrangement == PERPENDICULAR_TO_DIRECT_BEAM) { + m_normal_to_detector = m_distance*central_k_unit; + } + + else if(m_detector_arrangement == PERPENDICULAR_TO_REFLECTED_BEAM) { + m_normal_to_detector = m_distance*central_k_unit; + m_normal_to_detector.setZ(-m_normal_to_detector.z()); + } + + else if(m_detector_arrangement == PERPENDICULAR_TO_REFLECTED_BEAM_DPOS) { + m_normal_to_detector = m_distance*central_k_unit; + m_normal_to_detector.setZ(-m_normal_to_detector.z()); + + } + + else { + throw LogicErrorException("RectangularDetector::init() -> Unknown detector arrangement"); + } + +} + +void RectangularDetector::initUandV(double alpha_i) +{ + double d2 = m_normal_to_detector.dot(m_normal_to_detector); + m_u_unit = normalizeToUnitLength( + d2 * m_direction - m_direction.dot(m_normal_to_detector) * m_normal_to_detector); + m_v_unit = normalizeToUnitLength(m_u_unit.cross(m_normal_to_detector)); + + if(m_detector_arrangement == PERPENDICULAR_TO_REFLECTED_BEAM_DPOS) { + kvector_t z(0.0, 0.0, 1.0); + kvector_t normal_unit = m_normal_to_detector.normalize(); + kvector_t zp = z - z.dot(normal_unit)*normal_unit; + double uz = zp.dot(m_u_unit)/zp.mag(); + double vz = zp.dot(m_v_unit)/zp.mag(); + m_u0 = m_dbeam_u0 + m_distance*std::tan(2*alpha_i)*uz; + m_v0 = m_dbeam_v0 + m_distance*std::tan(2*alpha_i)*vz; + } +} + RectPixelMap::RectPixelMap(kvector_t corner_pos, kvector_t width, kvector_t height) : m_corner_pos(corner_pos), m_width(width), m_height(height) { diff --git a/Core/Algorithms/src/SphericalDetector.cpp b/Core/Algorithms/src/SphericalDetector.cpp index 43d2cc0507ddd5689a5f19b7ebdaa8da9ba593f5..be78192803ff5ab5857c7f3af3ba87fbcc8523a1 100644 --- a/Core/Algorithms/src/SphericalDetector.cpp +++ b/Core/Algorithms/src/SphericalDetector.cpp @@ -30,6 +30,14 @@ SphericalDetector::SphericalDetector() init_parameters(); } +SphericalDetector::SphericalDetector(size_t n_phi, double phi_min, double phi_max, size_t n_alpha, + double alpha_min, double alpha_max) +{ + setName(BornAgain::SphericalDetectorType); + init_parameters(); + setDetectorParameters(n_phi, phi_min, phi_max, n_alpha, alpha_min, alpha_max); +} + SphericalDetector::SphericalDetector(const SphericalDetector &other) : IDetector2D(other) { diff --git a/Core/Geometry/inc/BasicVector3D.h b/Core/Geometry/inc/BasicVector3D.h index 353b593436e3e7c8341f9fe826432babe49c711f..52c6bf30020fc656f6be035729bdf7206612d6ff 100644 --- a/Core/Geometry/inc/BasicVector3D.h +++ b/Core/Geometry/inc/BasicVector3D.h @@ -154,6 +154,9 @@ public: //! Returns cross product of vectors. BasicVector3D<T> cross(const BasicVector3D<T>& v ) const; + //! Returns normalized vector + BasicVector3D<T> normalize() const; + //! Returns square of transverse component with respect to given axis. double perp2(const BasicVector3D<T>& v) const; @@ -324,6 +327,7 @@ template<> BA_CORE_API_ double BasicVector3D<double>::dot( template<> BA_CORE_API_ BasicVector3D<double> BasicVector3D<double>::cross( const BasicVector3D<double>& v) const; +template<> BA_CORE_API_ BasicVector3D<double> BasicVector3D<double>::normalize() const; template<> BA_CORE_API_ double BasicVector3D<double>::phi() const; diff --git a/Core/Geometry/src/BasicVector3D.cpp b/Core/Geometry/src/BasicVector3D.cpp index be239ab9d86b0a679a6cc183a8e5216c05b23f8a..38ccf433082fe7e2c87bf70b7c3431d9ba7615d1 100644 --- a/Core/Geometry/src/BasicVector3D.cpp +++ b/Core/Geometry/src/BasicVector3D.cpp @@ -142,6 +142,18 @@ BasicVector3D<double> BasicVector3D<double>::cross( x()*v.y()-v.x()*y()); } + +//! Returns normalized vector +template<> +BasicVector3D<double> BasicVector3D<double>::normalize() const +{ + if(mag()) { + return BasicVector3D<double>(x()/mag(), y()/mag(), z()/mag()); + } else { + return BasicVector3D<double>(); + } +} + //! Returns square of transverse component with respect to given axis. template<> double BasicVector3D<double>::perp2(const BasicVector3D<double>& v) const diff --git a/Core/PythonAPI/src/Beam.pypp.cpp b/Core/PythonAPI/src/Beam.pypp.cpp index 2adc7392c4b24039e4c4ad3175561a18225e896a..1dbeba18955a7d427542266e3827d27ee2404454 100644 --- a/Core/PythonAPI/src/Beam.pypp.cpp +++ b/Core/PythonAPI/src/Beam.pypp.cpp @@ -44,7 +44,7 @@ void register_Beam_class(){ } { //::Beam::getCentralK - typedef ::cvector_t ( ::Beam::*getCentralK_function_type)( ) const; + typedef ::kvector_t ( ::Beam::*getCentralK_function_type)( ) const; Beam_exposer.def( "getCentralK" diff --git a/Core/PythonAPI/src/GISASSimulation.pypp.cpp b/Core/PythonAPI/src/GISASSimulation.pypp.cpp index c1f9c39deb8736eff105d5884cc6d828ae19295e..37943ddc3cb5932ae1d8d7cef37e531bc77c898b 100644 --- a/Core/PythonAPI/src/GISASSimulation.pypp.cpp +++ b/Core/PythonAPI/src/GISASSimulation.pypp.cpp @@ -173,6 +173,17 @@ void register_GISASSimulation_class(){ , getInstrument_function_type( &::GISASSimulation::getInstrument ) , bp::return_value_policy< bp::copy_const_reference >() ); + } + { //::GISASSimulation::getInstrument + + typedef ::Instrument & ( ::GISASSimulation::*getInstrument_function_type)( ) ; + + GISASSimulation_exposer.def( + "getInstrument" + , getInstrument_function_type( &::GISASSimulation::getInstrument ) + , bp::return_value_policy< bp::reference_existing_object >() + , "Returns the instrument containing beam and detector information." ); + } { //::GISASSimulation::getIntensityData @@ -332,8 +343,8 @@ void register_GISASSimulation_class(){ GISASSimulation_exposer.def( "setDetectorParameters" , setDetectorParameters_function_type( &::GISASSimulation::setDetectorParameters ) - , ( bp::arg("n_x"), bp::arg("x_min"), bp::arg("x_max"), bp::arg("n_y"), bp::arg("y_min"), bp::arg("y_max") ) - , "Sets detector parameters using angle ranges." ); + , ( bp::arg("n_phi"), bp::arg("phi_min"), bp::arg("phi_max"), bp::arg("n_alpha"), bp::arg("alpha_min"), bp::arg("alpha_max") ) + , "Sets spherical detector parameters using angle ranges @param n_phi number of phi-axis bins @param phi_min low edge of first phi-bin @param phi_max upper edge of last phi-bin @param n_alpha number of alpha-axis bins @param alpha_min low edge of first alpha-bin @param alpha_max upper edge of last alpha-bin \n\n:Parameters:\n - 'n_phi' - number of phi-axis bins\n - 'phi_min' - low edge of first phi-bin\n - 'phi_max' - upper edge of last phi-bin\n - 'n_alpha' - number of alpha-axis bins\n - 'alpha_min' - low edge of first alpha-bin\n - 'alpha_max' - upper edge of last alpha-bin\n" ); } { //::GISASSimulation::setDetectorResolutionFunction diff --git a/Core/PythonAPI/src/IDetector2D.pypp.cpp b/Core/PythonAPI/src/IDetector2D.pypp.cpp index 539685174647f103318bb1065df48a0541ba2513..56370784eb507e470c785275fc56e821745e19ed 100644 --- a/Core/PythonAPI/src/IDetector2D.pypp.cpp +++ b/Core/PythonAPI/src/IDetector2D.pypp.cpp @@ -21,6 +21,8 @@ GCC_DIAG_OFF(missing-field-initializers) #include "boost/python.hpp" GCC_DIAG_ON(unused-parameter) GCC_DIAG_ON(missing-field-initializers) +#include "__call_policies.pypp.hpp" +#include "__convenience.pypp.hpp" #include "PythonCoreList.h" #include "IDetector2D.pypp.h" @@ -62,6 +64,97 @@ struct IDetector2D_wrapper : IDetector2D, bp::wrapper< IDetector2D > { return func_getAxisName( index ); } + virtual bool areParametersChanged( ) { + if( bp::override func_areParametersChanged = this->get_override( "areParametersChanged" ) ) + return func_areParametersChanged( ); + else{ + return this->IParameterized::areParametersChanged( ); + } + } + + bool default_areParametersChanged( ) { + return IParameterized::areParametersChanged( ); + } + + virtual void clearParameterPool( ) { + if( bp::override func_clearParameterPool = this->get_override( "clearParameterPool" ) ) + func_clearParameterPool( ); + else{ + this->IParameterized::clearParameterPool( ); + } + } + + void default_clearParameterPool( ) { + IParameterized::clearParameterPool( ); + } + + virtual ::ParameterPool * createParameterTree( ) const { + if( bp::override func_createParameterTree = this->get_override( "createParameterTree" ) ) + return func_createParameterTree( ); + else{ + return this->IParameterized::createParameterTree( ); + } + } + + ::ParameterPool * default_createParameterTree( ) const { + return IParameterized::createParameterTree( ); + } + + virtual void printParameters( ) const { + if( bp::override func_printParameters = this->get_override( "printParameters" ) ) + func_printParameters( ); + else{ + this->IParameterized::printParameters( ); + } + } + + void default_printParameters( ) const { + IParameterized::printParameters( ); + } + + virtual void registerParameter( ::std::string const & name, double * parpointer, ::AttLimits const & limits=AttLimits::limitless( ) ) { + namespace bpl = boost::python; + if( bpl::override func_registerParameter = this->get_override( "registerParameter" ) ){ + bpl::object py_result = bpl::call<bpl::object>( func_registerParameter.ptr(), name, parpointer, limits ); + } + else{ + IParameterized::registerParameter( name, parpointer, boost::ref(limits) ); + } + } + + static void default_registerParameter( ::IParameterized & inst, ::std::string const & name, long unsigned int parpointer, ::AttLimits const & limits=AttLimits::limitless( ) ){ + if( dynamic_cast< IDetector2D_wrapper * >( boost::addressof( inst ) ) ){ + inst.::IParameterized::registerParameter(name, reinterpret_cast< double * >( parpointer ), limits); + } + else{ + inst.registerParameter(name, reinterpret_cast< double * >( parpointer ), limits); + } + } + + virtual bool setParameterValue( ::std::string const & name, double value ) { + if( bp::override func_setParameterValue = this->get_override( "setParameterValue" ) ) + return func_setParameterValue( name, value ); + else{ + return this->IParameterized::setParameterValue( name, value ); + } + } + + bool default_setParameterValue( ::std::string const & name, double value ) { + return IParameterized::setParameterValue( name, value ); + } + + virtual void setParametersAreChanged( ) { + if( bp::override func_setParametersAreChanged = this->get_override( "setParametersAreChanged" ) ) + func_setParametersAreChanged( ); + else{ + this->IParameterized::setParametersAreChanged( ); + } + } + + void default_setParametersAreChanged( ) { + IParameterized::setParametersAreChanged( ); + } + PyObject* m_pyobj; }; @@ -262,15 +355,83 @@ void register_IDetector2D_class(){ , "Sets detector parameters using axes." ); } - { //::IDetector2D::setDetectorParameters + { //::IParameterized::areParametersChanged + + typedef bool ( ::IParameterized::*areParametersChanged_function_type)( ) ; + typedef bool ( IDetector2D_wrapper::*default_areParametersChanged_function_type)( ) ; + + IDetector2D_exposer.def( + "areParametersChanged" + , areParametersChanged_function_type(&::IParameterized::areParametersChanged) + , default_areParametersChanged_function_type(&IDetector2D_wrapper::default_areParametersChanged) ); + + } + { //::IParameterized::clearParameterPool + + typedef void ( ::IParameterized::*clearParameterPool_function_type)( ) ; + typedef void ( IDetector2D_wrapper::*default_clearParameterPool_function_type)( ) ; + + IDetector2D_exposer.def( + "clearParameterPool" + , clearParameterPool_function_type(&::IParameterized::clearParameterPool) + , default_clearParameterPool_function_type(&IDetector2D_wrapper::default_clearParameterPool) ); + + } + { //::IParameterized::createParameterTree + + typedef ::ParameterPool * ( ::IParameterized::*createParameterTree_function_type)( ) const; + typedef ::ParameterPool * ( IDetector2D_wrapper::*default_createParameterTree_function_type)( ) const; + + IDetector2D_exposer.def( + "createParameterTree" + , createParameterTree_function_type(&::IParameterized::createParameterTree) + , default_createParameterTree_function_type(&IDetector2D_wrapper::default_createParameterTree) + , bp::return_value_policy< bp::manage_new_object >() ); + + } + { //::IParameterized::printParameters + + typedef void ( ::IParameterized::*printParameters_function_type)( ) const; + typedef void ( IDetector2D_wrapper::*default_printParameters_function_type)( ) const; + + IDetector2D_exposer.def( + "printParameters" + , printParameters_function_type(&::IParameterized::printParameters) + , default_printParameters_function_type(&IDetector2D_wrapper::default_printParameters) ); + + } + { //::IParameterized::registerParameter + + typedef void ( *default_registerParameter_function_type )( ::IParameterized &,::std::string const &,long unsigned int,::AttLimits const & ); + + IDetector2D_exposer.def( + "registerParameter" + , default_registerParameter_function_type( &IDetector2D_wrapper::default_registerParameter ) + , ( bp::arg("inst"), bp::arg("name"), bp::arg("parpointer"), bp::arg("limits")=AttLimits::limitless( ) ) + , "main method to register data address in the pool." ); + + } + { //::IParameterized::setParameterValue + + typedef bool ( ::IParameterized::*setParameterValue_function_type)( ::std::string const &,double ) ; + typedef bool ( IDetector2D_wrapper::*default_setParameterValue_function_type)( ::std::string const &,double ) ; + + IDetector2D_exposer.def( + "setParameterValue" + , setParameterValue_function_type(&::IParameterized::setParameterValue) + , default_setParameterValue_function_type(&IDetector2D_wrapper::default_setParameterValue) + , ( bp::arg("name"), bp::arg("value") ) ); + + } + { //::IParameterized::setParametersAreChanged - typedef void ( ::IDetector2D::*setDetectorParameters_function_type)( ::std::size_t,double,double,::std::size_t,double,double ) ; + typedef void ( ::IParameterized::*setParametersAreChanged_function_type)( ) ; + typedef void ( IDetector2D_wrapper::*default_setParametersAreChanged_function_type)( ) ; IDetector2D_exposer.def( - "setDetectorParameters" - , setDetectorParameters_function_type( &::IDetector2D::setDetectorParameters ) - , ( bp::arg("n_x"), bp::arg("x_min"), bp::arg("x_max"), bp::arg("n_y"), bp::arg("y_min"), bp::arg("y_max") ) - , "Sets detector parameters using angle ranges." ); + "setParametersAreChanged" + , setParametersAreChanged_function_type(&::IParameterized::setParametersAreChanged) + , default_setParametersAreChanged_function_type(&IDetector2D_wrapper::default_setParametersAreChanged) ); } } diff --git a/Core/PythonAPI/src/IsGISAXSDetector.pypp.cpp b/Core/PythonAPI/src/IsGISAXSDetector.pypp.cpp index 477a33d70f1a5988b2bedf4d989abb08c0324a84..3c2ee785f2a57d397a36d872a391f454b30d6766 100644 --- a/Core/PythonAPI/src/IsGISAXSDetector.pypp.cpp +++ b/Core/PythonAPI/src/IsGISAXSDetector.pypp.cpp @@ -35,6 +35,13 @@ struct IsGISAXSDetector_wrapper : IsGISAXSDetector, bp::wrapper< IsGISAXSDetecto m_pyobj = 0; } + IsGISAXSDetector_wrapper(::std::size_t n_phi, double phi_min, double phi_max, ::std::size_t n_alpha, double alpha_min, double alpha_max ) + : IsGISAXSDetector( n_phi, phi_min, phi_max, n_alpha, alpha_min, alpha_max ) + , bp::wrapper< IsGISAXSDetector >(){ + // constructor + m_pyobj = 0; + } + IsGISAXSDetector_wrapper(::IsGISAXSDetector const & other ) : IsGISAXSDetector( boost::ref(other) ) , bp::wrapper< IsGISAXSDetector >(){ @@ -64,6 +71,7 @@ void register_IsGISAXSDetector_class(){ typedef bp::class_< IsGISAXSDetector_wrapper, bp::bases< SphericalDetector >, std::auto_ptr< IsGISAXSDetector_wrapper > > IsGISAXSDetector_exposer_t; IsGISAXSDetector_exposer_t IsGISAXSDetector_exposer = IsGISAXSDetector_exposer_t( "IsGISAXSDetector", "A spherical detector used for validation with IsGISAXS results.", bp::init< >() ); bp::scope IsGISAXSDetector_scope( IsGISAXSDetector_exposer ); + IsGISAXSDetector_exposer.def( bp::init< std::size_t, double, double, std::size_t, double, double >(( bp::arg("n_phi"), bp::arg("phi_min"), bp::arg("phi_max"), bp::arg("n_alpha"), bp::arg("alpha_min"), bp::arg("alpha_max") )) ); IsGISAXSDetector_exposer.def( bp::init< IsGISAXSDetector const & >(( bp::arg("other") )) ); { //::IsGISAXSDetector::clone diff --git a/Core/PythonAPI/src/PythonModule.cpp b/Core/PythonAPI/src/PythonModule.cpp index d29d3e4f8543aeb3b1b72ea915a135f1c19fdf6d..63c2998ddf4d503d9b817f5abb8bff9cb97ffdf0 100644 --- a/Core/PythonAPI/src/PythonModule.cpp +++ b/Core/PythonAPI/src/PythonModule.cpp @@ -10,150 +10,150 @@ GCC_DIAG_ON(missing-field-initializers) #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION #define PY_ARRAY_UNIQUE_SYMBOL BORNAGAIN_PYTHONAPI_ARRAY #include "numpy/arrayobject.h" -#include "FormFactorFullSpheroid.pypp.h" -#include "DistributionGate.pypp.h" -#include "SimpleSelectionRule.pypp.h" -#include "RealParameterWrapper.pypp.h" -#include "vdouble1d_t.pypp.h" -#include "SimulationParameters.pypp.h" -#include "ThreadInfo.pypp.h" -#include "InterferenceFunction2DLattice.pypp.h" -#include "LayerInterface.pypp.h" #include "ILayout.pypp.h" -#include "FormFactorCone6.pypp.h" -#include "FormFactorTetrahedron.pypp.h" -#include "FTDistribution1DCosine.pypp.h" -#include "VerticalLine.pypp.h" -#include "FTDistribution1DTriangle.pypp.h" +#include "RotationZ.pypp.h" +#include "FTDistribution1DCauchy.pypp.h" +#include "ISampleBuilder.pypp.h" +#include "Beam.pypp.h" #include "FormFactorWeighted.pypp.h" -#include "InterferenceFunctionRadialParaCrystal.pypp.h" -#include "DistributionGaussian.pypp.h" -#include "IDetectorResolution.pypp.h" -#include "FormFactorCylinder.pypp.h" +#include "HomogeneousMagneticMaterial.pypp.h" +#include "DistributionLorentz.pypp.h" +#include "RotationX.pypp.h" #include "Crystal.pypp.h" -#include "FTDistribution1DCauchy.pypp.h" -#include "IFormFactorBorn.pypp.h" -#include "FormFactorEllipsoidalCylinder.pypp.h" #include "InterferenceFunctionNone.pypp.h" -#include "Histogram1D.pypp.h" -#include "vector_less__const_ISample_ptr___greater_.pypp.h" -#include "WavevectorInfo.pypp.h" -#include "HorizontalLine.pypp.h" #include "FTDistribution2DGate.pypp.h" -#include "vector_kvector_t.pypp.h" -#include "FormFactorTruncatedSpheroid.pypp.h" -#include "IShape2D.pypp.h" -#include "Particle.pypp.h" -#include "vector_string_t.pypp.h" -#include "FormFactorTrivial.pypp.h" +#include "FormFactorPrism6.pypp.h" +#include "vdouble2d_t.pypp.h" +#include "FormFactorTruncatedCube.pypp.h" +#include "VerticalLine.pypp.h" +#include "IFTDistribution2D.pypp.h" +#include "FormFactorLorentz.pypp.h" +#include "FixedBinAxis.pypp.h" +#include "ISample.pypp.h" #include "ConstKBinAxis.pypp.h" +#include "LayerInterface.pypp.h" +#include "IDetectorResolution.pypp.h" +#include "Lattice2DIFParameters.pypp.h" +#include "HorizontalLine.pypp.h" +#include "IntensityData.pypp.h" +#include "LayerRoughness.pypp.h" +#include "vector_integer_t.pypp.h" +#include "FormFactorTruncatedSphere.pypp.h" +#include "FormFactorCylinder.pypp.h" +#include "FormFactorFullSphere.pypp.h" +#include "IAxis.pypp.h" +#include "Simulation.pypp.h" +#include "IDetector2D.pypp.h" +#include "InterferenceFunction2DParaCrystal.pypp.h" +#include "DistributionLogNormal.pypp.h" +#include "FTDistribution1DCosine.pypp.h" +#include "OffSpecSimulation.pypp.h" +#include "RotationEuler.pypp.h" +#include "FTDistribution1DTriangle.pypp.h" +#include "FormFactorSphereUniformRadius.pypp.h" +#include "IntensityDataFunctions.pypp.h" +#include "Instrument.pypp.h" +#include "FormFactorTrivial.pypp.h" +#include "FormFactorSphereLogNormalRadius.pypp.h" +#include "RotationY.pypp.h" +#include "vector_realparameter_t.pypp.h" +#include "IInterferenceFunction.pypp.h" #include "FTDistribution2DCauchy.pypp.h" -#include "FormFactorCrystal.pypp.h" -#include "ParticleDistribution.pypp.h" +#include "IFormFactor.pypp.h" +#include "IObserver.pypp.h" +#include "ParticleComposition.pypp.h" +#include "Particle.pypp.h" +#include "MultiLayer.pypp.h" +#include "ParameterPool.pypp.h" +#include "FormFactorTetrahedron.pypp.h" +#include "FormFactorFullSpheroid.pypp.h" +#include "IParameterized.pypp.h" +#include "FormFactorAnisoPyramid.pypp.h" +#include "IObservable.pypp.h" +#include "ParticleCoreShell.pypp.h" +#include "Histogram2D.pypp.h" +#include "IShape2D.pypp.h" +#include "FormFactorCone.pypp.h" +#include "vector_string_t.pypp.h" +#include "Polygon.pypp.h" +#include "RectangularDetector.pypp.h" +#include "IDistribution1D.pypp.h" +#include "MesoCrystal.pypp.h" +#include "FTDistribution2DVoigt.pypp.h" +#include "InterferenceFunctionRadialParaCrystal.pypp.h" +#include "IMaterial.pypp.h" +#include "IsGISAXSDetector.pypp.h" +#include "SimulationParameters.pypp.h" +#include "IResolutionFunction2D.pypp.h" +#include "FormFactorTruncatedSpheroid.pypp.h" +#include "FormFactorCone6.pypp.h" +#include "FormFactorSphereGaussianRadius.pypp.h" +#include "VariableBinAxis.pypp.h" #include "vector_longinteger_t.pypp.h" #include "ResolutionFunction2DGaussian.pypp.h" -#include "RectangularDetector.pypp.h" +#include "cvector_t.pypp.h" +#include "FormFactorDecoratorDebyeWaller.pypp.h" +#include "IClusteredParticles.pypp.h" +#include "FTDistribution1DVoigt.pypp.h" +#include "vector_complex_t.pypp.h" +#include "FTDistribution2DCone.pypp.h" +#include "ParticleDistribution.pypp.h" +#include "vector_kvector_t.pypp.h" +#include "FormFactorRipple1.pypp.h" +#include "Bin1D.pypp.h" +#include "FormFactorRipple2.pypp.h" +#include "InterferenceFunction2DLattice.pypp.h" +#include "ThreadInfo.pypp.h" +#include "DistributionCosine.pypp.h" #include "FTDistribution1DGauss.pypp.h" #include "FTDistribution1DGate.pypp.h" -#include "FormFactorAnisoPyramid.pypp.h" -#include "FixedBinAxis.pypp.h" -#include "MultiLayer.pypp.h" -#include "IFormFactor.pypp.h" -#include "kvector_t.pypp.h" -#include "Ellipse.pypp.h" -#include "FormFactorSphereUniformRadius.pypp.h" -#include "IHistogram.pypp.h" -#include "Polygon.pypp.h" -#include "OffSpecSimulation.pypp.h" -#include "FormFactorRipple1.pypp.h" -#include "Simulation.pypp.h" -#include "IObservable.pypp.h" -#include "FormFactorLorentz.pypp.h" +#include "FormFactorCuboctahedron.pypp.h" +#include "Layer.pypp.h" +#include "RealParameterWrapper.pypp.h" +#include "Histogram1D.pypp.h" #include "SpecularSimulation.pypp.h" -#include "GISASSimulation.pypp.h" -#include "ISelectionRule.pypp.h" -#include "FormFactorRipple2.pypp.h" -#include "RotationZ.pypp.h" -#include "LayerRoughness.pypp.h" -#include "Bin1DCVector.pypp.h" -#include "FormFactorSphereGaussianRadius.pypp.h" -#include "ParameterPool.pypp.h" -#include "IsGISAXSDetector.pypp.h" +#include "FormFactorCrystal.pypp.h" #include "FormFactorPrism3.pypp.h" -#include "IMaterial.pypp.h" -#include "FTDistribution1DVoigt.pypp.h" -#include "IntensityDataFunctions.pypp.h" -#include "FormFactorPrism6.pypp.h" -#include "IClusteredParticles.pypp.h" -#include "VariableBinAxis.pypp.h" -#include "IParticle.pypp.h" -#include "DistributionCosine.pypp.h" +#include "PythonInterface_global_variables.pypp.h" +#include "FTDistribution2DGauss.pypp.h" +#include "Line.pypp.h" +#include "FormFactorGauss.pypp.h" +#include "vector_less__const_ISample_ptr___greater_.pypp.h" #include "FormFactorHemiEllipsoid.pypp.h" -#include "IAxis.pypp.h" -#include "vector_integer_t.pypp.h" -#include "IntensityDataIOFactory.pypp.h" -#include "ParameterDistribution.pypp.h" -#include "Layer.pypp.h" +#include "PythonInterface_free_functions.pypp.h" +#include "IParticle.pypp.h" +#include "vdouble1d_t.pypp.h" +#include "AttLimits.pypp.h" +#include "DistributionGaussian.pypp.h" +#include "FormFactorBox.pypp.h" #include "FormFactorPyramid.pypp.h" -#include "RotationY.pypp.h" -#include "CustomBinAxis.pypp.h" -#include "FTDistribution2DCone.pypp.h" +#include "Lattice.pypp.h" #include "IFTDistribution1D.pypp.h" -#include "DistributionLorentz.pypp.h" -#include "IDistribution1D.pypp.h" -#include "vdouble2d_t.pypp.h" -#include "Line.pypp.h" -#include "HomogeneousMagneticMaterial.pypp.h" -#include "vector_realparameter_t.pypp.h" -#include "IAbstractParticle.pypp.h" -#include "FormFactorTruncatedCube.pypp.h" -#include "FormFactorCuboctahedron.pypp.h" -#include "IDetector2D.pypp.h" -#include "cvector_t.pypp.h" -#include "PythonInterface_free_functions.pypp.h" -#include "FormFactorSphereLogNormalRadius.pypp.h" -#include "IResolutionFunction2D.pypp.h" -#include "FormFactorFullSphere.pypp.h" +#include "IFormFactorBorn.pypp.h" +#include "FormFactorEllipsoidalCylinder.pypp.h" #include "ParticleLayout.pypp.h" -#include "FormFactorBox.pypp.h" -#include "IParameterized.pypp.h" -#include "Lattice2DIFParameters.pypp.h" +#include "WavevectorInfo.pypp.h" #include "IFormFactorDecorator.pypp.h" -#include "InterferenceFunction1DLattice.pypp.h" -#include "RotationEuler.pypp.h" -#include "ISample.pypp.h" -#include "ISampleBuilder.pypp.h" -#include "IRotation.pypp.h" -#include "PythonInterface_global_variables.pypp.h" -#include "Beam.pypp.h" #include "HomogeneousMaterial.pypp.h" +#include "DistributionGate.pypp.h" +#include "kvector_t.pypp.h" +#include "IAbstractParticle.pypp.h" +#include "ISelectionRule.pypp.h" +#include "IntensityDataIOFactory.pypp.h" +#include "IHistogram.pypp.h" +#include "ParameterDistribution.pypp.h" +#include "SimpleSelectionRule.pypp.h" +#include "InterferenceFunction1DLattice.pypp.h" +#include "Ellipse.pypp.h" #include "Rectangle.pypp.h" +#include "Bin1DCVector.pypp.h" +#include "CustomBinAxis.pypp.h" #include "ICloneable.pypp.h" -#include "Histogram2D.pypp.h" -#include "ParticleCoreShell.pypp.h" -#include "FormFactorDecoratorDebyeWaller.pypp.h" -#include "MesoCrystal.pypp.h" +#include "IRotation.pypp.h" #include "Lattice1DIFParameters.pypp.h" -#include "IObserver.pypp.h" -#include "IntensityData.pypp.h" -#include "Lattice.pypp.h" -#include "AttLimits.pypp.h" -#include "IInterferenceFunction.pypp.h" -#include "Instrument.pypp.h" -#include "FormFactorCone.pypp.h" -#include "ParticleComposition.pypp.h" -#include "RotationX.pypp.h" -#include "FTDistribution2DGauss.pypp.h" -#include "FormFactorTruncatedSphere.pypp.h" -#include "FTDistribution2DVoigt.pypp.h" -#include "FormFactorGauss.pypp.h" -#include "InterferenceFunction2DParaCrystal.pypp.h" -#include "SphericalDetector.pypp.h" #include "ICompositeSample.pypp.h" -#include "Bin1D.pypp.h" -#include "vector_complex_t.pypp.h" -#include "DistributionLogNormal.pypp.h" -#include "IFTDistribution2D.pypp.h" +#include "GISASSimulation.pypp.h" +#include "SphericalDetector.pypp.h" #include "__call_policies.pypp.hpp" #include "__call_policies.pypp.hpp" diff --git a/Core/PythonAPI/src/RectangularDetector.pypp.cpp b/Core/PythonAPI/src/RectangularDetector.pypp.cpp index 5a1a03783e27a971ebfb733d56865e9e88cb94a6..07f169d6253e747abdaede967a336cb4f73cef28 100644 --- a/Core/PythonAPI/src/RectangularDetector.pypp.cpp +++ b/Core/PythonAPI/src/RectangularDetector.pypp.cpp @@ -21,6 +21,8 @@ GCC_DIAG_OFF(missing-field-initializers) #include "boost/python.hpp" GCC_DIAG_ON(unused-parameter) GCC_DIAG_ON(missing-field-initializers) +#include "__call_policies.pypp.hpp" +#include "__convenience.pypp.hpp" #include "PythonCoreList.h" #include "RectangularDetector.pypp.h" @@ -28,8 +30,8 @@ namespace bp = boost::python; struct RectangularDetector_wrapper : RectangularDetector, bp::wrapper< RectangularDetector > { - RectangularDetector_wrapper(::kvector_t normal_to_detector, ::kvector_t u_direction ) - : RectangularDetector( normal_to_detector, u_direction ) + RectangularDetector_wrapper(int nxbins, double width, int nybins, double height ) + : RectangularDetector( nxbins, width, nybins, height ) , bp::wrapper< RectangularDetector >(){ // constructor m_pyobj = 0; @@ -54,6 +56,97 @@ struct RectangularDetector_wrapper : RectangularDetector, bp::wrapper< Rectangul return RectangularDetector::clone( ); } + virtual bool areParametersChanged( ) { + if( bp::override func_areParametersChanged = this->get_override( "areParametersChanged" ) ) + return func_areParametersChanged( ); + else{ + return this->IParameterized::areParametersChanged( ); + } + } + + bool default_areParametersChanged( ) { + return IParameterized::areParametersChanged( ); + } + + virtual void clearParameterPool( ) { + if( bp::override func_clearParameterPool = this->get_override( "clearParameterPool" ) ) + func_clearParameterPool( ); + else{ + this->IParameterized::clearParameterPool( ); + } + } + + void default_clearParameterPool( ) { + IParameterized::clearParameterPool( ); + } + + virtual ::ParameterPool * createParameterTree( ) const { + if( bp::override func_createParameterTree = this->get_override( "createParameterTree" ) ) + return func_createParameterTree( ); + else{ + return this->IParameterized::createParameterTree( ); + } + } + + ::ParameterPool * default_createParameterTree( ) const { + return IParameterized::createParameterTree( ); + } + + virtual void printParameters( ) const { + if( bp::override func_printParameters = this->get_override( "printParameters" ) ) + func_printParameters( ); + else{ + this->IParameterized::printParameters( ); + } + } + + void default_printParameters( ) const { + IParameterized::printParameters( ); + } + + virtual void registerParameter( ::std::string const & name, double * parpointer, ::AttLimits const & limits=AttLimits::limitless( ) ) { + namespace bpl = boost::python; + if( bpl::override func_registerParameter = this->get_override( "registerParameter" ) ){ + bpl::object py_result = bpl::call<bpl::object>( func_registerParameter.ptr(), name, parpointer, limits ); + } + else{ + IParameterized::registerParameter( name, parpointer, boost::ref(limits) ); + } + } + + static void default_registerParameter( ::IParameterized & inst, ::std::string const & name, long unsigned int parpointer, ::AttLimits const & limits=AttLimits::limitless( ) ){ + if( dynamic_cast< RectangularDetector_wrapper * >( boost::addressof( inst ) ) ){ + inst.::IParameterized::registerParameter(name, reinterpret_cast< double * >( parpointer ), limits); + } + else{ + inst.registerParameter(name, reinterpret_cast< double * >( parpointer ), limits); + } + } + + virtual bool setParameterValue( ::std::string const & name, double value ) { + if( bp::override func_setParameterValue = this->get_override( "setParameterValue" ) ) + return func_setParameterValue( name, value ); + else{ + return this->IParameterized::setParameterValue( name, value ); + } + } + + bool default_setParameterValue( ::std::string const & name, double value ) { + return IParameterized::setParameterValue( name, value ); + } + + virtual void setParametersAreChanged( ) { + if( bp::override func_setParametersAreChanged = this->get_override( "setParametersAreChanged" ) ) + func_setParametersAreChanged( ); + else{ + this->IParameterized::setParametersAreChanged( ); + } + } + + void default_setParametersAreChanged( ) { + IParameterized::setParametersAreChanged( ); + } + PyObject* m_pyobj; }; @@ -62,9 +155,17 @@ void register_RectangularDetector_class(){ { //::RectangularDetector typedef bp::class_< RectangularDetector_wrapper, bp::bases< IDetector2D >, std::auto_ptr< RectangularDetector_wrapper > > RectangularDetector_exposer_t; - RectangularDetector_exposer_t RectangularDetector_exposer = RectangularDetector_exposer_t( "RectangularDetector", "A rectangular plane detector with axes and resolution function.", bp::init< kvector_t, kvector_t >(( bp::arg("normal_to_detector"), bp::arg("u_direction") )) ); + RectangularDetector_exposer_t RectangularDetector_exposer = RectangularDetector_exposer_t( "RectangularDetector", "A rectangular plane detector with axes and resolution function.", bp::init< int, double, int, double >(( bp::arg("nxbins"), bp::arg("width"), bp::arg("nybins"), bp::arg("height") ), "Rectangular detector constructor @param nxbins Number of bins (pixels) in x-direction @param width Width of the detector in mm along x-direction @param nybins Number of bins (pixels) in y-direction @param height Height of the detector in mm along y-direction \n\n:Parameters:\n - 'nxbins' - Number of bins (pixels) in x-direction\n - 'width' - Width of the detector in mm along x-direction\n - 'nybins' - Number of bins (pixels) in y-direction\n - 'height' - Height of the detector in mm along y-direction\n") ); bp::scope RectangularDetector_scope( RectangularDetector_exposer ); - RectangularDetector_exposer.def( bp::init< RectangularDetector const & >(( bp::arg("other") )) ); + bp::enum_< RectangularDetector::EDetectorArrangement>("EDetectorArrangement") + .value("GENERIC", RectangularDetector::GENERIC) + .value("PERPENDICULAR_TO_SAMPLE", RectangularDetector::PERPENDICULAR_TO_SAMPLE) + .value("PERPENDICULAR_TO_DIRECT_BEAM", RectangularDetector::PERPENDICULAR_TO_DIRECT_BEAM) + .value("PERPENDICULAR_TO_REFLECTED_BEAM", RectangularDetector::PERPENDICULAR_TO_REFLECTED_BEAM) + .value("PERPENDICULAR_TO_REFLECTED_BEAM_DPOS", RectangularDetector::PERPENDICULAR_TO_REFLECTED_BEAM_DPOS) + .export_values() + ; + RectangularDetector_exposer.def( bp::init< RectangularDetector const & >(( bp::arg("other") ), "Rectangular detector constructor @param nxbins Number of bins (pixels) in x-direction @param width Width of the detector in mm along x-direction @param nybins Number of bins (pixels) in y-direction @param height Height of the detector in mm along y-direction \n\n:Parameters:\n - 'nxbins' - Number of bins (pixels) in x-direction\n - 'width' - Width of the detector in mm along x-direction\n - 'nybins' - Number of bins (pixels) in y-direction\n - 'height' - Height of the detector in mm along y-direction\n") ); { //::RectangularDetector::clone typedef ::RectangularDetector * ( ::RectangularDetector::*clone_function_type)( ) const; @@ -76,6 +177,114 @@ void register_RectangularDetector_class(){ , default_clone_function_type(&RectangularDetector_wrapper::default_clone) , bp::return_value_policy< bp::manage_new_object >() ); + } + { //::RectangularDetector::getDetectorArrangment + + typedef ::RectangularDetector::EDetectorArrangement ( ::RectangularDetector::*getDetectorArrangment_function_type)( ) const; + + RectangularDetector_exposer.def( + "getDetectorArrangment" + , getDetectorArrangment_function_type( &::RectangularDetector::getDetectorArrangment ) ); + + } + { //::RectangularDetector::getDirectBeamU0 + + typedef double ( ::RectangularDetector::*getDirectBeamU0_function_type)( ) const; + + RectangularDetector_exposer.def( + "getDirectBeamU0" + , getDirectBeamU0_function_type( &::RectangularDetector::getDirectBeamU0 ) ); + + } + { //::RectangularDetector::getDirectBeamV0 + + typedef double ( ::RectangularDetector::*getDirectBeamV0_function_type)( ) const; + + RectangularDetector_exposer.def( + "getDirectBeamV0" + , getDirectBeamV0_function_type( &::RectangularDetector::getDirectBeamV0 ) ); + + } + { //::RectangularDetector::getDirectionVector + + typedef ::kvector_t ( ::RectangularDetector::*getDirectionVector_function_type)( ) const; + + RectangularDetector_exposer.def( + "getDirectionVector" + , getDirectionVector_function_type( &::RectangularDetector::getDirectionVector ) ); + + } + { //::RectangularDetector::getDistance + + typedef double ( ::RectangularDetector::*getDistance_function_type)( ) const; + + RectangularDetector_exposer.def( + "getDistance" + , getDistance_function_type( &::RectangularDetector::getDistance ) ); + + } + { //::RectangularDetector::getHeight + + typedef double ( ::RectangularDetector::*getHeight_function_type)( ) const; + + RectangularDetector_exposer.def( + "getHeight" + , getHeight_function_type( &::RectangularDetector::getHeight ) ); + + } + { //::RectangularDetector::getNbinsX + + typedef ::std::size_t ( ::RectangularDetector::*getNbinsX_function_type)( ) const; + + RectangularDetector_exposer.def( + "getNbinsX" + , getNbinsX_function_type( &::RectangularDetector::getNbinsX ) ); + + } + { //::RectangularDetector::getNbinsY + + typedef ::std::size_t ( ::RectangularDetector::*getNbinsY_function_type)( ) const; + + RectangularDetector_exposer.def( + "getNbinsY" + , getNbinsY_function_type( &::RectangularDetector::getNbinsY ) ); + + } + { //::RectangularDetector::getNormalVector + + typedef ::kvector_t ( ::RectangularDetector::*getNormalVector_function_type)( ) const; + + RectangularDetector_exposer.def( + "getNormalVector" + , getNormalVector_function_type( &::RectangularDetector::getNormalVector ) ); + + } + { //::RectangularDetector::getU0 + + typedef double ( ::RectangularDetector::*getU0_function_type)( ) const; + + RectangularDetector_exposer.def( + "getU0" + , getU0_function_type( &::RectangularDetector::getU0 ) ); + + } + { //::RectangularDetector::getV0 + + typedef double ( ::RectangularDetector::*getV0_function_type)( ) const; + + RectangularDetector_exposer.def( + "getV0" + , getV0_function_type( &::RectangularDetector::getV0 ) ); + + } + { //::RectangularDetector::getWidth + + typedef double ( ::RectangularDetector::*getWidth_function_type)( ) const; + + RectangularDetector_exposer.def( + "getWidth" + , getWidth_function_type( &::RectangularDetector::getWidth ) ); + } { //::RectangularDetector::operator= @@ -88,6 +297,135 @@ void register_RectangularDetector_class(){ , bp::return_self< >() ); } + { //::RectangularDetector::setDirectBeamPosition + + typedef void ( ::RectangularDetector::*setDirectBeamPosition_function_type)( double,double ) ; + + RectangularDetector_exposer.def( + "setDirectBeamPosition" + , setDirectBeamPosition_function_type( &::RectangularDetector::setDirectBeamPosition ) + , ( bp::arg("u0"), bp::arg("v0") ) ); + + } + { //::RectangularDetector::setPerpendicularToDirectBeam + + typedef void ( ::RectangularDetector::*setPerpendicularToDirectBeam_function_type)( double,double,double ) ; + + RectangularDetector_exposer.def( + "setPerpendicularToDirectBeam" + , setPerpendicularToDirectBeam_function_type( &::RectangularDetector::setPerpendicularToDirectBeam ) + , ( bp::arg("distance"), bp::arg("u0"), bp::arg("v0") ) ); + + } + { //::RectangularDetector::setPerpendicularToReflectedBeam + + typedef void ( ::RectangularDetector::*setPerpendicularToReflectedBeam_function_type)( double,double,double ) ; + + RectangularDetector_exposer.def( + "setPerpendicularToReflectedBeam" + , setPerpendicularToReflectedBeam_function_type( &::RectangularDetector::setPerpendicularToReflectedBeam ) + , ( bp::arg("distance"), bp::arg("u0")=0.0, bp::arg("v0")=0.0 ) ); + + } + { //::RectangularDetector::setPerpendicularToSampleX + + typedef void ( ::RectangularDetector::*setPerpendicularToSampleX_function_type)( double,double,double ) ; + + RectangularDetector_exposer.def( + "setPerpendicularToSampleX" + , setPerpendicularToSampleX_function_type( &::RectangularDetector::setPerpendicularToSampleX ) + , ( bp::arg("distance"), bp::arg("u0"), bp::arg("v0") ) ); + + } + { //::RectangularDetector::setPosition + + typedef void ( ::RectangularDetector::*setPosition_function_type)( ::kvector_t const &,double,double,::kvector_t const & ) ; + + RectangularDetector_exposer.def( + "setPosition" + , setPosition_function_type( &::RectangularDetector::setPosition ) + , ( bp::arg("normal_to_detector"), bp::arg("u0"), bp::arg("v0"), bp::arg("direction")=Geometry::BasicVector3D<double>(0.0, -1.0e+0, 0.0) ) ); + + } + { //::IParameterized::areParametersChanged + + typedef bool ( ::IParameterized::*areParametersChanged_function_type)( ) ; + typedef bool ( RectangularDetector_wrapper::*default_areParametersChanged_function_type)( ) ; + + RectangularDetector_exposer.def( + "areParametersChanged" + , areParametersChanged_function_type(&::IParameterized::areParametersChanged) + , default_areParametersChanged_function_type(&RectangularDetector_wrapper::default_areParametersChanged) ); + + } + { //::IParameterized::clearParameterPool + + typedef void ( ::IParameterized::*clearParameterPool_function_type)( ) ; + typedef void ( RectangularDetector_wrapper::*default_clearParameterPool_function_type)( ) ; + + RectangularDetector_exposer.def( + "clearParameterPool" + , clearParameterPool_function_type(&::IParameterized::clearParameterPool) + , default_clearParameterPool_function_type(&RectangularDetector_wrapper::default_clearParameterPool) ); + + } + { //::IParameterized::createParameterTree + + typedef ::ParameterPool * ( ::IParameterized::*createParameterTree_function_type)( ) const; + typedef ::ParameterPool * ( RectangularDetector_wrapper::*default_createParameterTree_function_type)( ) const; + + RectangularDetector_exposer.def( + "createParameterTree" + , createParameterTree_function_type(&::IParameterized::createParameterTree) + , default_createParameterTree_function_type(&RectangularDetector_wrapper::default_createParameterTree) + , bp::return_value_policy< bp::manage_new_object >() ); + + } + { //::IParameterized::printParameters + + typedef void ( ::IParameterized::*printParameters_function_type)( ) const; + typedef void ( RectangularDetector_wrapper::*default_printParameters_function_type)( ) const; + + RectangularDetector_exposer.def( + "printParameters" + , printParameters_function_type(&::IParameterized::printParameters) + , default_printParameters_function_type(&RectangularDetector_wrapper::default_printParameters) ); + + } + { //::IParameterized::registerParameter + + typedef void ( *default_registerParameter_function_type )( ::IParameterized &,::std::string const &,long unsigned int,::AttLimits const & ); + + RectangularDetector_exposer.def( + "registerParameter" + , default_registerParameter_function_type( &RectangularDetector_wrapper::default_registerParameter ) + , ( bp::arg("inst"), bp::arg("name"), bp::arg("parpointer"), bp::arg("limits")=AttLimits::limitless( ) ) + , "main method to register data address in the pool." ); + + } + { //::IParameterized::setParameterValue + + typedef bool ( ::IParameterized::*setParameterValue_function_type)( ::std::string const &,double ) ; + typedef bool ( RectangularDetector_wrapper::*default_setParameterValue_function_type)( ::std::string const &,double ) ; + + RectangularDetector_exposer.def( + "setParameterValue" + , setParameterValue_function_type(&::IParameterized::setParameterValue) + , default_setParameterValue_function_type(&RectangularDetector_wrapper::default_setParameterValue) + , ( bp::arg("name"), bp::arg("value") ) ); + + } + { //::IParameterized::setParametersAreChanged + + typedef void ( ::IParameterized::*setParametersAreChanged_function_type)( ) ; + typedef void ( RectangularDetector_wrapper::*default_setParametersAreChanged_function_type)( ) ; + + RectangularDetector_exposer.def( + "setParametersAreChanged" + , setParametersAreChanged_function_type(&::IParameterized::setParametersAreChanged) + , default_setParametersAreChanged_function_type(&RectangularDetector_wrapper::default_setParametersAreChanged) ); + + } } } diff --git a/Core/PythonAPI/src/SphericalDetector.pypp.cpp b/Core/PythonAPI/src/SphericalDetector.pypp.cpp index f11e4bc7b658cb8d7dd4d3b4767b339210c3705d..52f80c48cd7017266805032519f125f77e36afa1 100644 --- a/Core/PythonAPI/src/SphericalDetector.pypp.cpp +++ b/Core/PythonAPI/src/SphericalDetector.pypp.cpp @@ -35,6 +35,13 @@ struct SphericalDetector_wrapper : SphericalDetector, bp::wrapper< SphericalDete m_pyobj = 0; } + SphericalDetector_wrapper(::std::size_t n_phi, double phi_min, double phi_max, ::std::size_t n_alpha, double alpha_min, double alpha_max ) + : SphericalDetector( n_phi, phi_min, phi_max, n_alpha, alpha_min, alpha_max ) + , bp::wrapper< SphericalDetector >(){ + // constructor + m_pyobj = 0; + } + SphericalDetector_wrapper(::SphericalDetector const & other ) : SphericalDetector( boost::ref(other) ) , bp::wrapper< SphericalDetector >(){ @@ -64,6 +71,7 @@ void register_SphericalDetector_class(){ typedef bp::class_< SphericalDetector_wrapper, bp::bases< IDetector2D >, std::auto_ptr< SphericalDetector_wrapper > > SphericalDetector_exposer_t; SphericalDetector_exposer_t SphericalDetector_exposer = SphericalDetector_exposer_t( "SphericalDetector", "A spherical detector with axes and resolution function.", bp::init< >() ); bp::scope SphericalDetector_scope( SphericalDetector_exposer ); + SphericalDetector_exposer.def( bp::init< std::size_t, double, double, std::size_t, double, double >(( bp::arg("n_phi"), bp::arg("phi_min"), bp::arg("phi_max"), bp::arg("n_alpha"), bp::arg("alpha_min"), bp::arg("alpha_max") ), "Spherical detector constructor using angle ranges @param n_phi number of phi-axis bins @param phi_min low edge of first phi-bin @param phi_max upper edge of last phi-bin @param n_alpha number of alpha-axis bins @param alpha_min low edge of first alpha-bin @param alpha_max upper edge of last alpha-bin \n\n:Parameters:\n - 'n_phi' - number of phi-axis bins\n - 'phi_min' - low edge of first phi-bin\n - 'phi_max' - upper edge of last phi-bin\n - 'n_alpha' - number of alpha-axis bins\n - 'alpha_min' - low edge of first alpha-bin\n - 'alpha_max' - upper edge of last alpha-bin\n") ); SphericalDetector_exposer.def( bp::init< SphericalDetector const & >(( bp::arg("other") )) ); { //::SphericalDetector::clone diff --git a/Fit/PythonAPI/src/PythonModule.cpp b/Fit/PythonAPI/src/PythonModule.cpp index 0d99cdbbf0c226613998dda37d347a9fac4d9a5a..66bc390ea18998677001da76287e98579670f1e4 100644 --- a/Fit/PythonAPI/src/PythonModule.cpp +++ b/Fit/PythonAPI/src/PythonModule.cpp @@ -5,37 +5,37 @@ GCC_DIAG_OFF(missing-field-initializers) #include "boost/python.hpp" GCC_DIAG_ON(unused-parameter) GCC_DIAG_ON(missing-field-initializers) -#include "IntensityFunctionSqrt.pypp.h" +#include "FitSuiteObjects.pypp.h" +#include "IChiSquaredModule.pypp.h" +#include "FitStrategyDefault.pypp.h" +#include "IntensityFunctionLog.pypp.h" +#include "IntensityNormalizer.pypp.h" +#include "FitStrategyFixParameters.pypp.h" +#include "FitStrategyAdjustParameters.pypp.h" +#include "SquaredFunctionGaussianError.pypp.h" +#include "IFitStrategy.pypp.h" #include "MinimizerFactory.pypp.h" +#include "FitSuite.pypp.h" #include "IMinimizer.pypp.h" -#include "SquaredFunctionSystematicError.pypp.h" -#include "IntensityNormalizer.pypp.h" -#include "IIntensityFunction.pypp.h" -#include "INamed.pypp.h" -#include "IntensityFunctionLog.pypp.h" -#include "FitSuiteParameters.pypp.h" -#include "AttFitting.pypp.h" -#include "FitParameter.pypp.h" #include "IntensityScaleAndShiftNormalizer.pypp.h" -#include "IChiSquaredModule.pypp.h" +#include "ISquaredFunction.pypp.h" +#include "SquaredFunctionSimError.pypp.h" #include "FitStrategyAdjustMinimizer.pypp.h" -#include "IFitStrategy.pypp.h" -#include "FitStrategyFixParameters.pypp.h" -#include "SquaredFunctionGaussianError.pypp.h" +#include "FitParameter.pypp.h" #include "IFitObserver.pypp.h" -#include "IIntensityNormalizer.pypp.h" -#include "FitSuite.pypp.h" -#include "FitStrategyAdjustParameters.pypp.h" -#include "ChiSquaredModule.pypp.h" -#include "MinimizerOptions.pypp.h" #include "SquaredFunctionDefault.pypp.h" +#include "ChiSquaredModule.pypp.h" #include "SquaredFunctionMeanSquaredError.pypp.h" -#include "ISquaredFunction.pypp.h" -#include "FitStrategyDefault.pypp.h" -#include "FitObject.pypp.h" -#include "FitSuiteObjects.pypp.h" -#include "SquaredFunctionSimError.pypp.h" +#include "IIntensityNormalizer.pypp.h" +#include "FitSuiteParameters.pypp.h" #include "FitStrategyReleaseParameters.pypp.h" +#include "MinimizerOptions.pypp.h" +#include "IIntensityFunction.pypp.h" +#include "IntensityFunctionSqrt.pypp.h" +#include "FitObject.pypp.h" +#include "SquaredFunctionSystematicError.pypp.h" +#include "AttFitting.pypp.h" +#include "INamed.pypp.h" BOOST_PYTHON_MODULE(libBornAgainFit){ boost::python::docstring_options doc_options(true, true, false); diff --git a/Tests/FunctionalTests/TestPyCore/cylinders_ba_dwba_size.py b/Tests/FunctionalTests/TestPyCore/cylinders_ba_dwba_size.py index 9b037a94dc56152357261b3402afd017359a2dfc..90b892333825e3f974ea82c5205de82b86d15bde 100644 --- a/Tests/FunctionalTests/TestPyCore/cylinders_ba_dwba_size.py +++ b/Tests/FunctionalTests/TestPyCore/cylinders_ba_dwba_size.py @@ -37,8 +37,7 @@ def RunSimulationDWBA(): # build and run experiment simulation = GISASSimulation() - detector = IsGISAXSDetector() - detector.setDetectorParameters(100, 0.0*degree, 2.0*degree, 100, 0.0*degree, 2.0*degree) + detector = IsGISAXSDetector(100, 0.0*degree, 2.0*degree, 100, 0.0*degree, 2.0*degree) simulation.setDetector(detector) simulation.setBeamParameters(1.0*angstrom, 0.2*degree, 0.0*degree) simulation.setSample(multi_layer) @@ -73,8 +72,7 @@ def RunSimulationBA(): # build and run experiment simulation = GISASSimulation() - detector = IsGISAXSDetector() - detector.setDetectorParameters(100, 0.0*degree, 2.0*degree, 100, 0.0*degree, 2.0*degree) + detector = IsGISAXSDetector(100, 0.0*degree, 2.0*degree, 100, 0.0*degree, 2.0*degree) simulation.setDetector(detector) simulation.setBeamParameters(1.0*angstrom, 0.2*degree, 0.0*degree) simulation.setSample(multi_layer) @@ -118,8 +116,7 @@ def RunSimulationBA_Size(): # build and run experiment simulation = GISASSimulation() - detector = IsGISAXSDetector() - detector.setDetectorParameters(100, 0.0*degree, 2.0*degree, 100, 0.0*degree, 2.0*degree) + detector = IsGISAXSDetector(100, 0.0*degree, 2.0*degree, 100, 0.0*degree, 2.0*degree) simulation.setDetector(detector) simulation.setBeamParameters(1.0*angstrom, 0.2*degree, 0.0*degree) simulation.setSample(multi_layer) diff --git a/Tests/FunctionalTests/TestPyCore/isgisaxs01.py b/Tests/FunctionalTests/TestPyCore/isgisaxs01.py index e698f68ecb29c364ceaa3a1245189bf79705dc2c..b3eda99476b7e113b0aa47da3519e3eb20622536 100644 --- a/Tests/FunctionalTests/TestPyCore/isgisaxs01.py +++ b/Tests/FunctionalTests/TestPyCore/isgisaxs01.py @@ -42,8 +42,7 @@ def RunSimulation(): # build and run experiment simulation = GISASSimulation() - detector = IsGISAXSDetector() - detector.setDetectorParameters(100, -1.0*degree, 1.0*degree, 100, 0.0*degree, 2.0*degree) + detector = IsGISAXSDetector(100, -1.0*degree, 1.0*degree, 100, 0.0*degree, 2.0*degree) simulation.setDetector(detector) simulation.setBeamParameters(1.0*angstrom, 0.2*degree, 0.0*degree) simulation.setSample(multi_layer) diff --git a/Tests/FunctionalTests/TestPyCore/isgisaxs02.py b/Tests/FunctionalTests/TestPyCore/isgisaxs02.py index 52a5636fe73ff7135428e08ed26e39b0ba383f64..bdcdf31d7442b7cda4dd30674ebc8f8ec5398898 100644 --- a/Tests/FunctionalTests/TestPyCore/isgisaxs02.py +++ b/Tests/FunctionalTests/TestPyCore/isgisaxs02.py @@ -56,8 +56,7 @@ def RunSimulation(): # build and run experiment simulation = GISASSimulation() - detector = IsGISAXSDetector() - detector.setDetectorParameters(100, 0.0*degree, 2.0*degree, 100, 0.0*degree, 2.0*degree) + detector = IsGISAXSDetector(100, 0.0*degree, 2.0*degree, 100, 0.0*degree, 2.0*degree) simulation.setDetector(detector) simulation.setBeamParameters(1.0*angstrom, 0.2*degree, 0.0*degree) diff --git a/Tests/FunctionalTests/TestPyCore/isgisaxs04.py b/Tests/FunctionalTests/TestPyCore/isgisaxs04.py index 84d4d0c78cadb7df1cac25082197850f018f297c..7d03316acddc5484b16f147d24a10fe50dc935e4 100644 --- a/Tests/FunctionalTests/TestPyCore/isgisaxs04.py +++ b/Tests/FunctionalTests/TestPyCore/isgisaxs04.py @@ -40,8 +40,7 @@ def RunSimulation1(): multi_layer.addLayer(substrate_layer) # build and run experiment simulation = GISASSimulation() - detector = IsGISAXSDetector() - detector.setDetectorParameters(100, 0.0*degree, 2.0*degree, 100, 0.0*degree, 2.0*degree) + detector = IsGISAXSDetector(100, 0.0*degree, 2.0*degree, 100, 0.0*degree, 2.0*degree) simulation.setDetector(detector) simulation.setBeamParameters(1.0 * angstrom, 0.2 * degree, 0.0 * degree) simulation.setSample(multi_layer) @@ -83,8 +82,7 @@ def RunSimulation2(): # build and run experiment #gsl_set_error_handler_off() simulation = GISASSimulation() - detector = IsGISAXSDetector() - detector.setDetectorParameters(100, 0.0*degree, 2.0*degree, 100, 0.0*degree, 2.0*degree) + detector = IsGISAXSDetector(100, 0.0*degree, 2.0*degree, 100, 0.0*degree, 2.0*degree) simulation.setDetector(detector) simulation.setBeamParameters(1.0 * angstrom, 0.2 * degree, 0.0 * degree) simulation.setSample(multi_layer) diff --git a/Tests/FunctionalTests/TestPyCore/isgisaxs06.py b/Tests/FunctionalTests/TestPyCore/isgisaxs06.py index 962949be8da213975b62eac3986381c008f60ba4..4e323fa135487cc61dae81a9d5104353479ff393 100644 --- a/Tests/FunctionalTests/TestPyCore/isgisaxs06.py +++ b/Tests/FunctionalTests/TestPyCore/isgisaxs06.py @@ -41,8 +41,7 @@ def run_simulation_lattice(): multi_layer.addLayer(substrate_layer) # build and run experiment simulation = GISASSimulation() - detector = IsGISAXSDetector() - detector.setDetectorParameters(100, 0.0*degree, 2.0*degree, 100, 0.0*degree, 2.0*degree) + detector = IsGISAXSDetector(100, 0.0*degree, 2.0*degree, 100, 0.0*degree, 2.0*degree) simulation.setDetector(detector) simulation.setBeamParameters(1.0*angstrom, 0.2*degree, 0.0*degree) @@ -86,8 +85,7 @@ def run_simulation_centered(): multi_layer.addLayer(substrate_layer) # build and run experiment simulation = GISASSimulation() - detector = IsGISAXSDetector() - detector.setDetectorParameters(100, 0.0*degree, 2.0*degree, 100, 0.0*degree, 2.0*degree) + detector = IsGISAXSDetector(100, 0.0*degree, 2.0*degree, 100, 0.0*degree, 2.0*degree) simulation.setDetector(detector) simulation.setBeamParameters(1.0*angstrom, 0.2*degree, 0.0*degree) @@ -124,8 +122,7 @@ def run_simulation_rotated(): multi_layer.addLayer(substrate_layer) # build and run experiment simulation = GISASSimulation() - detector = IsGISAXSDetector() - detector.setDetectorParameters(100, 0.0*degree, 2.0*degree, 100, 0.0*degree, 2.0*degree) + detector = IsGISAXSDetector(100, 0.0*degree, 2.0*degree, 100, 0.0*degree, 2.0*degree) simulation.setDetector(detector) simulation.setBeamParameters(1.0*angstrom, 0.2*degree, 0.0*degree) @@ -141,8 +138,7 @@ def run_simulation_variants(): # building simulation simulation = GISASSimulation() - detector = IsGISAXSDetector() - detector.setDetectorParameters(100, 0.0*degree, 2.0*degree, 100, 0.0*degree, 2.0*degree) + detector = IsGISAXSDetector(100, 0.0*degree, 2.0*degree, 100, 0.0*degree, 2.0*degree) simulation.setDetector(detector) simulation.setBeamParameters(1.0*angstrom, 0.2*degree, 0.0*degree) diff --git a/Tests/FunctionalTests/TestPyCore/isgisaxs07.py b/Tests/FunctionalTests/TestPyCore/isgisaxs07.py index 6b068a739245060ec5ff8e7d27c478e7a08b9735..ab14cbac891ce4c0ab378c83664ecaf777dbd1bc 100644 --- a/Tests/FunctionalTests/TestPyCore/isgisaxs07.py +++ b/Tests/FunctionalTests/TestPyCore/isgisaxs07.py @@ -102,8 +102,7 @@ def RunSimulation(): #build and run experiment simulation = GISASSimulation() - detector = IsGISAXSDetector() - detector.setDetectorParameters(100, 0.0*degree, 1.0*degree, 100, 0.0*degree, 1.0*degree) + detector = IsGISAXSDetector(100, 0.0*degree, 1.0*degree, 100, 0.0*degree, 1.0*degree) simulation.setDetector(detector) simulation.setBeamParameters(1.0*angstrom, 0.0*degree, 0.0*degree) diff --git a/Tests/FunctionalTests/TestPyCore/isgisaxs08.py b/Tests/FunctionalTests/TestPyCore/isgisaxs08.py index 13b38e7cb0d296738398d127884951f125946316..0f8b3a866279cf2ab6b3148c15143080e6cca19a 100644 --- a/Tests/FunctionalTests/TestPyCore/isgisaxs08.py +++ b/Tests/FunctionalTests/TestPyCore/isgisaxs08.py @@ -42,8 +42,7 @@ def RunSimulation1(): # build and run experiment simulation = GISASSimulation() - detector = IsGISAXSDetector() - detector.setDetectorParameters(100, 0.0*degree, 2.0*degree, 100, 0.0*degree, 2.0*degree) + detector = IsGISAXSDetector(100, 0.0*degree, 2.0*degree, 100, 0.0*degree, 2.0*degree) simulation.setDetector(detector) simulation.setBeamParameters(1.0*angstrom, 0.2*degree, 0.0*degree) simulation.setSample(multi_layer) @@ -83,8 +82,7 @@ def RunSimulation2(): # build and run experiment simulation = GISASSimulation() - detector = IsGISAXSDetector() - detector.setDetectorParameters(100, 0.0*degree, 2.0*degree, 100, 0.0*degree, 2.0*degree) + detector = IsGISAXSDetector(100, 0.0*degree, 2.0*degree, 100, 0.0*degree, 2.0*degree) simulation.setDetector(detector) simulation.setBeamParameters(1.0*angstrom, 0.2*degree, 0.0*degree) simulation.setSample(multi_layer) diff --git a/Tests/FunctionalTests/TestPyCore/isgisaxs09.py b/Tests/FunctionalTests/TestPyCore/isgisaxs09.py index c2f53d7705ea80496f7895e8b136420ebe9a22a8..7272a0ade1e461e4ba1f03f2293ca2206daf446c 100644 --- a/Tests/FunctionalTests/TestPyCore/isgisaxs09.py +++ b/Tests/FunctionalTests/TestPyCore/isgisaxs09.py @@ -39,8 +39,7 @@ def RunSimulation1(): multi_layer.addLayer(substrate_layer) # build and run experiment simulation = GISASSimulation() - detector = IsGISAXSDetector() - detector.setDetectorParameters(100, 0.0*degree, 2.0*degree, 100, 0.0*degree, 2.0*degree) + detector = IsGISAXSDetector(100, 0.0*degree, 2.0*degree, 100, 0.0*degree, 2.0*degree) simulation.setDetector(detector) simulation.setBeamParameters(1.0*angstrom, 0.2*degree, 0.0*degree) simulation.setSample(multi_layer) @@ -79,8 +78,7 @@ def RunSimulation2(): multi_layer.addLayer(substrate_layer) # build and run experiment simulation = GISASSimulation() - detector = IsGISAXSDetector() - detector.setDetectorParameters(100, 0.0*degree, 2.0*degree, 100, 0.0*degree, 2.0*degree) + detector = IsGISAXSDetector(100, 0.0*degree, 2.0*degree, 100, 0.0*degree, 2.0*degree) simulation.setDetector(detector) simulation.setBeamParameters(1.0*angstrom, 0.2*degree, 0.0*degree) simulation.setSample(multi_layer) diff --git a/Tests/FunctionalTests/TestPyCore/isgisaxs10.py b/Tests/FunctionalTests/TestPyCore/isgisaxs10.py index 431fdfe92d31c004d11f30f5687e461d2c9a5809..4390567023cefbbb633d3b2cacefeee4b4bd9a9f 100644 --- a/Tests/FunctionalTests/TestPyCore/isgisaxs10.py +++ b/Tests/FunctionalTests/TestPyCore/isgisaxs10.py @@ -37,8 +37,7 @@ def RunSimulation(): multi_layer.addLayer(substrate_layer) # build and run experiment simulation = GISASSimulation() - detector = IsGISAXSDetector() - detector.setDetectorParameters(100, 0.0*degree, 2.0*degree, 100, 0.0*degree, 2.0*degree) + detector = IsGISAXSDetector(100, 0.0*degree, 2.0*degree, 100, 0.0*degree, 2.0*degree) simulation.setDetector(detector) simulation.setBeamParameters(1.0 * angstrom, 0.2 * degree, 0.0 * degree) simulation.setSample(multi_layer) diff --git a/Tests/FunctionalTests/TestPyCore/isgisaxs11.py b/Tests/FunctionalTests/TestPyCore/isgisaxs11.py index bd8ccaa47392521484c9499e12a57b68ba6091c4..aa2c1cbc90368b46177720f4f1b551a20c94dbed 100644 --- a/Tests/FunctionalTests/TestPyCore/isgisaxs11.py +++ b/Tests/FunctionalTests/TestPyCore/isgisaxs11.py @@ -41,8 +41,7 @@ def RunSimulation(): # build and run experiment simulation = GISASSimulation() - detector = IsGISAXSDetector() - detector.setDetectorParameters(100, 0.0*degree, 2.0*degree, 100, 0.0*degree, 2.0*degree) + detector = IsGISAXSDetector(100, 0.0*degree, 2.0*degree, 100, 0.0*degree, 2.0*degree) simulation.setDetector(detector) simulation.setBeamParameters(1.0*angstrom, 0.2*degree, 0.0*degree) simulation.setSample(multi_layer) diff --git a/Tests/FunctionalTests/TestPyCore/isgisaxs15.py b/Tests/FunctionalTests/TestPyCore/isgisaxs15.py index 01d0200fb3bce3db512cf8f4a65cf173d05073a3..859c46bc32a3cb3191ff311d12a4f71d8376c851 100644 --- a/Tests/FunctionalTests/TestPyCore/isgisaxs15.py +++ b/Tests/FunctionalTests/TestPyCore/isgisaxs15.py @@ -44,8 +44,7 @@ def RunSimulation(): # build and run experiment simulation = GISASSimulation() - detector = IsGISAXSDetector() - detector.setDetectorParameters(150, 0.05*degree, 1.5*degree, 150, 0.05*degree, 1.5*degree) + detector = IsGISAXSDetector(150, 0.05*degree, 1.5*degree, 150, 0.05*degree, 1.5*degree) simulation.setDetector(detector) simulation.setBeamParameters(1.0 * angstrom, 0.2 * degree, 0.0 * degree) diff --git a/Tests/UnitTests/TestCore/BeamTest.h b/Tests/UnitTests/TestCore/BeamTest.h index f358367eb0a8e38f6652960da6a960d8af621e21..b21be3e6ffc633a6c0876c43aa4fe7b62a74686f 100644 --- a/Tests/UnitTests/TestCore/BeamTest.h +++ b/Tests/UnitTests/TestCore/BeamTest.h @@ -20,10 +20,9 @@ protected: TEST_F(BeamTest, BeamInitialState) { - EXPECT_DOUBLE_EQ(2.0 * Units::PI, m_empty_beam.getCentralK()[0].real()); - EXPECT_DOUBLE_EQ(0.0, m_empty_beam.getCentralK()[0].imag()); - EXPECT_EQ(complex_t(0.0, 0.0), m_empty_beam.getCentralK()[1]); - EXPECT_EQ(complex_t(0.0, 0.0), m_empty_beam.getCentralK()[2]); + EXPECT_DOUBLE_EQ(2.0 * Units::PI, m_empty_beam.getCentralK()[0]); + EXPECT_EQ(0.0, m_empty_beam.getCentralK()[1]); + EXPECT_EQ(0.0, m_empty_beam.getCentralK()[2]); EXPECT_EQ(0.0, m_empty_beam.getIntensity()); EXPECT_EQ(size_t(4), m_empty_beam.getParameterPool()->size()); EXPECT_EQ(0.0, m_empty_beam.getParameterPool()->getParameter(BornAgain::Intensity).getValue()); @@ -45,9 +44,9 @@ TEST_F(BeamTest, BeamAssignment) P_beam->setPolarization(polarization); Beam beam_copy = *P_beam; - EXPECT_NEAR(1.83423, beam_copy.getCentralK()[0].real(), 0.00001); - EXPECT_NEAR(2.85664, beam_copy.getCentralK()[1].real(), 0.00001); - EXPECT_NEAR(-5.28712, beam_copy.getCentralK()[2].real(), 0.00001); + EXPECT_NEAR(1.83423, beam_copy.getCentralK()[0], 0.00001); + EXPECT_NEAR(2.85664, beam_copy.getCentralK()[1], 0.00001); + EXPECT_NEAR(-5.28712, beam_copy.getCentralK()[2], 0.00001); EXPECT_EQ(double(2.0), beam_copy.getIntensity()); EXPECT_EQ(size_t(4), beam_copy.getParameterPool()->size()); EXPECT_EQ(double(2.0), diff --git a/Tests/UnitTests/TestCore/InstrumentTest.h b/Tests/UnitTests/TestCore/InstrumentTest.h index 8ff7194532a2a32974e2c6d5cdc0bd404ce9be60..af09bbab314e2bc7ac3586c925a719b8f6a602ce 100644 --- a/Tests/UnitTests/TestCore/InstrumentTest.h +++ b/Tests/UnitTests/TestCore/InstrumentTest.h @@ -40,12 +40,9 @@ TEST_F(InstrumentTest, BeamManipulation) double y = k*std::cos(alpha) * std::sin(phi); double z = k*std::sin(alpha); m_instrument.setBeamParameters(lambda, -1.0*alpha, phi); - EXPECT_DOUBLE_EQ(x, m_instrument.getBeam().getCentralK().x().real() ); - EXPECT_DOUBLE_EQ(0, m_instrument.getBeam().getCentralK().x().imag() ); - EXPECT_DOUBLE_EQ(y, m_instrument.getBeam().getCentralK().y().real() ); - EXPECT_DOUBLE_EQ(0, m_instrument.getBeam().getCentralK().y().imag() ); - EXPECT_DOUBLE_EQ(z, m_instrument.getBeam().getCentralK().z().real() ); - EXPECT_DOUBLE_EQ(0, m_instrument.getBeam().getCentralK().z().imag() ); + EXPECT_DOUBLE_EQ(x, m_instrument.getBeam().getCentralK().x() ); + EXPECT_DOUBLE_EQ(y, m_instrument.getBeam().getCentralK().y() ); + EXPECT_DOUBLE_EQ(z, m_instrument.getBeam().getCentralK().z() ); EXPECT_FALSE( m_instrument.getDetectorDimension()==2 ); m_instrument.matchDetectorAxes(m_data); diff --git a/Tests/UnitTests/TestCore/RectangularDetectorTest.h b/Tests/UnitTests/TestCore/RectangularDetectorTest.h new file mode 100644 index 0000000000000000000000000000000000000000..913eef49ffd45936d20dd8e1961a5572636dbd88 --- /dev/null +++ b/Tests/UnitTests/TestCore/RectangularDetectorTest.h @@ -0,0 +1,268 @@ +#ifndef RECTANGULARDETECTORTEST_H +#define RECTANGULARDETECTORTEST_H + +#include "RectangularDetector.h" +#include "GISASSimulation.h" +#include "SimulationElement.h" +#include "Numeric.h" +#include "gtest/gtest.h" +#include <boost/scoped_ptr.hpp> +#include <iostream> + + +class RectangularDetectorTest : public ::testing::Test +{ + protected: + RectangularDetectorTest(){} + virtual ~RectangularDetectorTest(){} + + double phi(SimulationElement &element) {return element.getPhiMean()/Units::degree; } + double alpha(SimulationElement &element) {return element.getAlphaMean()/Units::degree; } + double phi(kvector_t &k) {return k.phi()/Units::degree; } + double alpha(kvector_t &k) {return 90.0 - k.theta()/Units::degree; } + + bool isEqual(const kvector_t &lhs, const kvector_t &rhs) { + bool is_equal = Numeric::areAlmostEqual(lhs.x(), rhs.x()) && + Numeric::areAlmostEqual(lhs.y(), rhs.y()) && + Numeric::areAlmostEqual(lhs.z(), rhs.z()); + if(!is_equal) { + std::cout << "lhs:" << lhs << " rhs:" << rhs << " diff:" << (lhs-rhs) << std::endl; + } + return is_equal; + } +}; + +TEST_F(RectangularDetectorTest, InitialState) +{ + RectangularDetector det(50, 10.0, 60, 20.0); + EXPECT_EQ(50, det.getNbinsX()); + EXPECT_EQ(10.0, det.getWidth()); + EXPECT_EQ(60, det.getNbinsY()); + EXPECT_EQ(20.0, det.getHeight()); + + EXPECT_EQ(0.0, det.getU0()); + EXPECT_EQ(0.0, det.getV0()); + EXPECT_EQ(0.0, det.getDistance()); + + EXPECT_TRUE(kvector_t() == det.getNormalVector()); + EXPECT_TRUE(kvector_t(0.0, -1.0, 0.0) == det.getDirectionVector()); + + EXPECT_EQ(RectangularDetector::GENERIC, det.getDetectorArrangment()); +} + +TEST_F(RectangularDetectorTest, Clone) +{ + RectangularDetector det(50, 10.0, 60, 20.0); + kvector_t normal(10.0, 20.0, 30.0); + kvector_t direction(1.0, 2.0, 3.0); + double u0(88.0), v0(99.0); + det.setPosition(normal, u0, v0, direction); + + boost::scoped_ptr<RectangularDetector> clone(det.clone()); + EXPECT_EQ(u0, clone->getU0()); + EXPECT_EQ(v0, clone->getV0()); + EXPECT_TRUE(normal == clone->getNormalVector()); + EXPECT_TRUE(direction == clone->getDirectionVector()); + EXPECT_EQ(RectangularDetector::GENERIC, clone->getDetectorArrangment()); +} + +TEST_F(RectangularDetectorTest, PerpToSample) +{ + int nbinsx(5), nbinsy(4); + double width(50.0), height(40.0); + double distance(100.0), u0(20.0), v0(10.0); + double dx = width/nbinsx; + double dy = height/nbinsy; + + RectangularDetector det(nbinsx, width, nbinsy, height); + + // detector perpendicular to sample + det.setPerpendicularToSampleX(distance, u0, v0); + EXPECT_EQ(distance, det.getDistance()); + EXPECT_EQ(u0, det.getU0()); + EXPECT_EQ(v0, det.getV0()); + EXPECT_TRUE(kvector_t() == det.getNormalVector()); + EXPECT_TRUE(kvector_t(0.0, -1.0, 0.0) == det.getDirectionVector()); + EXPECT_EQ(RectangularDetector::PERPENDICULAR_TO_SAMPLE, det.getDetectorArrangment()); + + // initializing with the simulation + GISASSimulation simulation; + simulation.setBeamParameters(1.0, 10.0*Units::degree, 0.0); + det.init(&simulation); + EXPECT_TRUE(kvector_t(distance, 0, 0) == det.getNormalVector()); + EXPECT_TRUE(kvector_t(0.0, -1.0, 0.0) == det.getDirectionVector()); + + std::vector<SimulationElement> elements = det.createSimulationElements(simulation.getInstrument().getBeam()); + EXPECT_EQ(elements.size(), nbinsx*nbinsy); + + // lower left bin + kvector_t k(distance, u0-dx/2., (-v0+dy/2.)); + SimulationElement element = elements[0]; + EXPECT_FLOAT_EQ(phi(k), phi(element)); + EXPECT_FLOAT_EQ(alpha(k), alpha(element)); + + // upper left bin + k = kvector_t(distance, u0-dx/2., (height - v0 - dy/2.)); + element = elements[3]; + EXPECT_FLOAT_EQ(phi(k), phi(element)); + EXPECT_FLOAT_EQ(alpha(k), alpha(element)); + + // lower right bin + k = kvector_t(distance, -(width-u0-dx/2.), (-v0+dy/2.)); + element = elements[16]; + EXPECT_FLOAT_EQ(phi(k), phi(element)); + EXPECT_FLOAT_EQ(alpha(k), alpha(element)); + + // upper right bin + k = kvector_t(distance, -(width-u0-dx/2.), (height - v0 - dy/2.)); + element = elements[19]; + EXPECT_FLOAT_EQ(phi(k), phi(element)); + EXPECT_FLOAT_EQ(alpha(k), alpha(element)); +} + + +TEST_F(RectangularDetectorTest, PerpToDirectBeam) +{ + int nbinsx(5), nbinsy(4); + double width(50.0), height(40.0); + double distance(100.0), u0(20.0), v0(10.0); + double dx = width/nbinsx; + double dy = height/nbinsy; + double alpha_i(10.0*Units::degree); + + RectangularDetector det(nbinsx, width, nbinsy, height); + + // detector perpendicular to direct beam + det.setPerpendicularToDirectBeam(distance, u0, v0); + EXPECT_EQ(distance, det.getDistance()); + EXPECT_EQ(u0, det.getU0()); + EXPECT_EQ(v0, det.getV0()); + EXPECT_TRUE(kvector_t() == det.getNormalVector()); + EXPECT_TRUE(kvector_t(0.0, -1.0, 0.0) == det.getDirectionVector()); + EXPECT_EQ(RectangularDetector::PERPENDICULAR_TO_DIRECT_BEAM, det.getDetectorArrangment()); + + // initializing with the simulation + GISASSimulation simulation; + simulation.setBeamParameters(1.0, alpha_i, 0.0); + det.init(&simulation); + kvector_t normal(distance*cos(alpha_i), 0.0, -1.0*distance*sin(alpha_i)); + EXPECT_TRUE(isEqual(normal, det.getNormalVector())); + EXPECT_TRUE(kvector_t(0.0, -1.0, 0.0) == det.getDirectionVector()); + + std::vector<SimulationElement> elements = det.createSimulationElements(simulation.getInstrument().getBeam()); + EXPECT_EQ(elements.size(), nbinsx*nbinsy); + + // lower left bin + double ds = v0 - dy/2.; + double alpha_x = alpha_i+std::atan(ds/distance); + double c = distance*std::sin(alpha_i) + ds*std::cos(alpha_i); + double x = c/std::tan(alpha_x); + kvector_t k(x, u0-dx/2., -c); + SimulationElement element = elements[0]; + EXPECT_FLOAT_EQ(phi(k), phi(element)); + EXPECT_FLOAT_EQ(alpha(k), alpha(element)); +} + + +TEST_F(RectangularDetectorTest, PerpToReflectedBeam) +{ + int nbinsx(5), nbinsy(4); + double width(50.0), height(40.0); + double distance(100.0), u0(20.0), v0(10.0); + double dx = width/nbinsx; + double dy = height/nbinsy; + double alpha_i(10.0*Units::degree); + + RectangularDetector det(nbinsx, width, nbinsy, height); + + // detector perpendicular to reflected beam + det.setPerpendicularToReflectedBeam(distance, u0, v0); + EXPECT_EQ(distance, det.getDistance()); + EXPECT_EQ(u0, det.getU0()); + EXPECT_EQ(v0, det.getV0()); + EXPECT_TRUE(kvector_t() == det.getNormalVector()); + EXPECT_TRUE(kvector_t(0.0, -1.0, 0.0) == det.getDirectionVector()); + EXPECT_EQ(RectangularDetector::PERPENDICULAR_TO_REFLECTED_BEAM, det.getDetectorArrangment()); + + // initializing with the simulation + GISASSimulation simulation; + simulation.setBeamParameters(1.0, alpha_i, 0.0); + det.init(&simulation); + kvector_t normal(distance*cos(alpha_i), 0.0, 1.0*distance*sin(alpha_i)); + EXPECT_TRUE(isEqual(normal, det.getNormalVector())); + EXPECT_TRUE(kvector_t(0.0, -1.0, 0.0) == det.getDirectionVector()); + + // checking detector elements + std::vector<SimulationElement> elements = det.createSimulationElements(simulation.getInstrument().getBeam()); + EXPECT_EQ(elements.size(), nbinsx*nbinsy); + + double ds = v0 - dy/2.; + double alpha_x = alpha_i - std::atan(ds/distance); + double c = distance*std::sin(alpha_i) - std::cos(alpha_i)*ds; + double x = c/std::tan(alpha_x); + + kvector_t k(x, u0-dx/2., c); + SimulationElement element = elements[0]; + EXPECT_FLOAT_EQ(phi(k), phi(element)); + EXPECT_FLOAT_EQ(alpha(k), alpha(element)); + +} + +// detector perpendicular to reflected beam, when direct beam position is known +TEST_F(RectangularDetectorTest, PerpToReflectedBeamDpos) +{ + int nbinsx(5), nbinsy(4); + double width(50.0), height(40.0); + double distance(100.0), u0(20.0), v0(10.0); + double dx = width/nbinsx; + double dy = height/nbinsy; + double alpha_i(10.0*Units::degree); + + RectangularDetector det(nbinsx, width, nbinsy, height); + + // detector perpendicular to reflected beam + det.setPerpendicularToReflectedBeam(distance); + EXPECT_EQ(distance, det.getDistance()); + EXPECT_EQ(0.0, det.getU0()); + EXPECT_EQ(0.0, det.getV0()); + EXPECT_EQ(0.0, det.getDirectBeamU0()); + EXPECT_EQ(0.0, det.getDirectBeamV0()); + + double dbeam_u0 = u0; + double dbeam_v0 = -distance*std::tan(alpha_i*2.0) + v0; + det.setDirectBeamPosition(dbeam_u0, dbeam_v0); + + EXPECT_EQ(dbeam_u0, det.getDirectBeamU0()); + EXPECT_EQ(dbeam_v0, det.getDirectBeamV0()); + EXPECT_TRUE(kvector_t() == det.getNormalVector()); + EXPECT_TRUE(kvector_t(0.0, -1.0, 0.0) == det.getDirectionVector()); + EXPECT_EQ(RectangularDetector::PERPENDICULAR_TO_REFLECTED_BEAM_DPOS, det.getDetectorArrangment()); + + // initializing with the simulation + GISASSimulation simulation; + simulation.setBeamParameters(1.0, alpha_i, 0.0); + det.init(&simulation); + + kvector_t normal(distance*cos(alpha_i), 0.0, 1.0*distance*sin(alpha_i)); + EXPECT_TRUE(isEqual(normal, det.getNormalVector())); + EXPECT_TRUE(kvector_t(0.0, -1.0, 0.0) == det.getDirectionVector()); + EXPECT_EQ(u0, det.getU0()); + EXPECT_EQ(v0, det.getV0()); + + // checking detector elements + std::vector<SimulationElement> elements = det.createSimulationElements(simulation.getInstrument().getBeam()); + EXPECT_EQ(elements.size(), nbinsx*nbinsy); + + double ds = v0 - dy/2.; + double alpha_x = alpha_i - std::atan(ds/distance); + double c = distance*std::sin(alpha_i) - std::cos(alpha_i)*ds; + double x = c/std::tan(alpha_x); + + kvector_t k(x, u0-dx/2., c); + SimulationElement element = elements[0]; + EXPECT_FLOAT_EQ(phi(k), phi(element)); + EXPECT_FLOAT_EQ(alpha(k), alpha(element)); +} + + +#endif diff --git a/Tests/UnitTests/TestCore/main.cpp b/Tests/UnitTests/TestCore/main.cpp index 9555fd15ca61597aa121401ed7decf4069b977a7..0bdbfec27347910d52693daa0a794aacd35e6a77 100644 --- a/Tests/UnitTests/TestCore/main.cpp +++ b/Tests/UnitTests/TestCore/main.cpp @@ -55,6 +55,7 @@ #include "PolygonTest.h" #include "DetectorMaskTest.h" #include "Shape2DTest.h" +#include "RectangularDetectorTest.h" diff --git a/dev-tools/python-bindings/settings_core.py b/dev-tools/python-bindings/settings_core.py index c9d5989ece47077f3238dc504273987e2e34bdd1..de5487c1bb9fdf55154d9305e081f00c6e9aa319 100644 --- a/dev-tools/python-bindings/settings_core.py +++ b/dev-tools/python-bindings/settings_core.py @@ -226,7 +226,7 @@ def ManualClassTunings(mb): methods_to_exclude=[ "phi", "theta", "cosTheta", "sin2Theta", "getPhi", "getTheta", "setPhi", "setTheta", "setR", "setMag", "perp", "perp2", "setPerp", "angle", "unit", "orthogonal", "rotated", "rotatedX", - "rotatedY", "rotatedZ", "cross", "dot" + "rotatedY", "rotatedZ", "cross", "dot", "normalize" ] classes_to_exclude = ["BasicVector3D<std::complex<double> >", "BasicVector3D<double>", "BasicVector3D<int>"] utils_build.ExcludeMemberFunctionsForClasses(mb, methods_to_exclude, classes_to_exclude) @@ -387,7 +387,6 @@ def ManualClassTunings(mb): cl.member_function("createOutputData").call_policies = call_policies.return_value_policy(call_policies.manage_new_object) cl.member_function("createRelativeDifferenceHistogram").call_policies = call_policies.return_value_policy(call_policies.manage_new_object) - cl = mb.class_("Histogram1D") cl.member_function("getBinCenters").exclude() cl.member_function("getBinValues").exclude() @@ -399,7 +398,6 @@ def ManualClassTunings(mb): cl.member_function("getBinValuesNumpy").alias = "getBinValues" cl.member_function("getBinErrorsNumpy").alias = "getBinErrors" - # cl = mb.class_("Histogram2D") for fun in cl.member_functions(): @@ -413,6 +411,9 @@ def ManualClassTunings(mb): # cl.member_function("readHistogram").call_policies = call_policies.return_value_policy(call_policies.manage_new_object) cl.member_function("readIntensityData").call_policies = call_policies.return_value_policy(call_policies.manage_new_object) + cl = mb.class_("IDetector2D") + cl.member_function("setDetectorParameters").exclude() + # excluding specific member functions def ManualExcludeMemberFunctions(mb):