diff --git a/Device/Detector/FlatDetector.cpp b/Device/Detector/FlatDetector.cpp index c1c67bf076130ed4ce181dfc76d1a1cb597a4a2b..37b3e43dd1b18c2e61c9232c293e165a2d86019c 100644 --- a/Device/Detector/FlatDetector.cpp +++ b/Device/Detector/FlatDetector.cpp @@ -21,15 +21,17 @@ #include "Base/Util/Assert.h" #include "Device/Beam/Beam.h" #include "Device/Resolution/IDetectorResolution.h" +#include <iostream> #include <numbers> using std::numbers::pi; -#include <iostream> FlatDetector::FlatDetector(size_t nxbins, size_t nybins, double width, double height, const Beam& beam, NominalNormal nominalNormal, double distance, double offcenter_w, double offcenter_h, double pitch, double yaw, double roll) - : m_nominalNormal(nominalNormal) + : IDetector(new Frame(newEquiDivision("u (mm)", nxbins, 0.0, width), + newEquiDivision("v (mm)", nybins, 0.0, height))) + , m_nominalNormal(nominalNormal) , m_u0(width / 2 + offcenter_w) , m_v0(height / 2 + offcenter_h) , m_distance(distance) @@ -61,11 +63,6 @@ FlatDetector::FlatDetector(size_t nxbins, size_t nybins, double width, double he const R3 u_direction = d2 * ym_unit - ym_unit.dot(m_normal_to_detector) * m_normal_to_detector; m_u_unit = u_direction.unit_or_throw(); m_v_unit = m_u_unit.cross(m_normal_to_detector).unit_or_throw(); - - Scale* x = newEquiDivision("u (mm)", nxbins, 0.0, width); - Scale* y = newEquiDivision("v (mm)", nybins, 0.0, height); - Frame* f = new Frame(x, y); - setFrame(f); } FlatDetector::~FlatDetector() = default; diff --git a/Device/Detector/IDetector.cpp b/Device/Detector/IDetector.cpp index 6b3fbdc6e8c40fb3060129d54118114a0927fc1a..03ffed8dceaacb3139088c64d2f8400463cb6a82 100644 --- a/Device/Detector/IDetector.cpp +++ b/Device/Detector/IDetector.cpp @@ -68,7 +68,13 @@ std::pair<double, double> RoiOfAxis::bounds() const //... class IDetector -IDetector::IDetector() = default; +IDetector::IDetector(Frame* frame) + : m_frame(frame) + , m_mask(new MaskStack) +{ + ASSERT(frame); + ASSERT(frame->rank() == 2); +} IDetector::IDetector(const IDetector& other) : INode() @@ -82,14 +88,6 @@ IDetector::IDetector(const IDetector& other) IDetector::~IDetector() = default; -void IDetector::setFrame(Frame* frame) -{ - ASSERT(frame); - ASSERT(frame->rank() == 2); - m_frame.reset(frame); - m_mask.reset(new MaskStack()); -} - const Frame& IDetector::frame() const { ASSERT(m_frame); diff --git a/Device/Detector/IDetector.h b/Device/Detector/IDetector.h index a9565d6972c7d585fb292ed6da358b03f80a1717..f5ea4a3aabffccf5721f41bcf732c5077b1c7ba4 100644 --- a/Device/Detector/IDetector.h +++ b/Device/Detector/IDetector.h @@ -17,18 +17,17 @@ #include "Base/Types/ICloneable.h" #include "Device/Pol/PolFilter.h" -#include <functional> class Beam; class Datafield; -class MaskStack; class Frame; class IDetectorResolution; class IPixel; class IResolutionFunction2D; class IShape2D; -struct RoiOfAxis; +class MaskStack; class Scale; +struct RoiOfAxis; //! Abstract base for 2D detectors, realized by FlatDetector and SphericalDetector. //! @@ -45,14 +44,13 @@ class Scale; class IDetector : public ICloneable, public INode { public: - IDetector(); + //! Constructor that takes ownership of Frame. + IDetector(Frame* frame); ~IDetector() override; IDetector* clone() const override = 0; - void setFrame(Frame* frame); - //! Sets the polarization analyzer characteristics of the detector void setAnalyzer(R3 Bloch_vector = {}, double mean_transmission = 0.5); void setAnalyzer(R3 direction, double efficiency, double transmission); // OBSOLETE since v21 diff --git a/Device/Detector/SphericalDetector.cpp b/Device/Detector/SphericalDetector.cpp index e0668a336252c4692f024b3c661e117867dc7253..85949296969d26662673e0d623a05125ce6c14e0 100644 --- a/Device/Detector/SphericalDetector.cpp +++ b/Device/Detector/SphericalDetector.cpp @@ -22,16 +22,11 @@ #include "Device/Beam/Beam.h" #include "Device/Resolution/IDetectorResolution.h" -SphericalDetector::SphericalDetector(const Frame& frame) -{ - setFrame(frame.clone()); -} - SphericalDetector::SphericalDetector(size_t n_phi, double phi_min, double phi_max, size_t n_alpha, double alpha_min, double alpha_max) + : IDetector(new Frame(newEquiDivision("phi_f (rad)", n_phi, phi_min, phi_max), + newEquiDivision("alpha_f (rad)", n_alpha, alpha_min, alpha_max))) { - setFrame(new Frame(newEquiDivision("phi_f (rad)", n_phi, phi_min, phi_max), - newEquiDivision("alpha_f (rad)", n_alpha, alpha_min, alpha_max))); } SphericalDetector::SphericalDetector(size_t n_bin, double width, double phi, double alpha) diff --git a/Device/Detector/SphericalDetector.h b/Device/Detector/SphericalDetector.h index 8edb8f0052b98bb5fc584c6e8fdf758ba8c2e5b8..d928088a2966ae889fbf12ac28e7141d902a9046 100644 --- a/Device/Detector/SphericalDetector.h +++ b/Device/Detector/SphericalDetector.h @@ -23,8 +23,6 @@ class IPixel; class SphericalDetector : public IDetector { public: - SphericalDetector(const Frame&); - //! Returns a detector with given phi and alpha axes. //! @param n_phi number of phi-axis bins //! @param phi_min low edge of first phi-bin diff --git a/Tests/Unit/Device/RegionOfInterestTest.cpp b/Tests/Unit/Device/RegionOfInterestTest.cpp index e614a649aad664b096743e90559e9991205a6a9e..0a5498f4e7089e72a84187bb00b75c0a5430fe72 100644 --- a/Tests/Unit/Device/RegionOfInterestTest.cpp +++ b/Tests/Unit/Device/RegionOfInterestTest.cpp @@ -8,8 +8,7 @@ TEST(RegionOfInterestTest, constructor) { - SphericalDetector detector( - Frame(newEquiDivision("axis0", 8, -3.0, 5.0), newEquiDivision("axis1", 4, 0.0, 4.0))); + SphericalDetector detector(8, -3.0, 5.0, 4, 0.0, 4.0); // creating region of interest double xlow(-1.9), ylow(1.1), xup(2.9), yup(2.85); @@ -34,8 +33,7 @@ TEST(RegionOfInterestTest, constructor) TEST(RegionOfInterestTest, largeArea) { - SphericalDetector detector( - Frame(newEquiDivision("axis0", 8, -3.0, 5.0), newEquiDivision("axis1", 4, 0.0, 4.0))); + SphericalDetector detector(8, -3.0, 5.0, 4, 0.0, 4.0); // creating region of interest double xlow(-3.9), ylow(-1.1), xup(6.9), yup(5.85); @@ -56,8 +54,7 @@ TEST(RegionOfInterestTest, largeArea) TEST(RegionOfInterestTest, clone) { - SphericalDetector detector( - Frame(newEquiDivision("axis0", 8, -3.0, 5.0), newEquiDivision("axis1", 4, 0.0, 4.0))); + SphericalDetector detector(8, -3.0, 5.0, 4, 0.0, 4.0); // creating region of interest double xlow(-1.9), ylow(1.1), xup(2.9), yup(2.85); diff --git a/Tests/Unit/Device/SphericalDetectorTest.cpp b/Tests/Unit/Device/SphericalDetectorTest.cpp index ce466d3b1abec11b4077d2eebad748d758e37e29..f2b870382263e23efa2b97d47d659ad817d3c1ab 100644 --- a/Tests/Unit/Device/SphericalDetectorTest.cpp +++ b/Tests/Unit/Device/SphericalDetectorTest.cpp @@ -12,20 +12,6 @@ #include "Tests/GTestWrapper/google_test.h" #include <memory> -// Construction of the detector with axes. -TEST(SphericalDetectorTest, constructionWithAxes) -{ - auto* axis0 = newEquiDivision("axis0", 10, 0.0, 10.0); - auto* axis1 = newEquiDivision("axis1", 20, 0.0, 20.0); - SphericalDetector detector(Frame(axis0->clone(), axis1->clone())); - - // checking dimension and axes - EXPECT_EQ(axis0->min(), detector.axis(0).min()); - EXPECT_EQ(axis0->max(), detector.axis(0).max()); - EXPECT_EQ(axis1->min(), detector.axis(1).min()); - EXPECT_EQ(axis1->max(), detector.axis(1).max()); -} - // Construction of the detector via classical constructor. TEST(SphericalDetectorTest, constructionWithParameters) { @@ -57,8 +43,7 @@ TEST(SphericalDetectorTest, createDetectorMap) // Testing region of interest. TEST(SphericalDetectorTest, regionOfInterest) { - SphericalDetector detector( - Frame(newEquiDivision("axis0", 8, -3.0, 5.0), newEquiDivision("axis1", 4, 0.0, 4.0))); + SphericalDetector detector(8, -3.0, 5.0, 4, 0.0, 4.0); // creating region of interest double xlow(-2.0), ylow(1.0), xup(4.0), yup(3.0); diff --git a/auto/Wrap/libBornAgainDevice.py b/auto/Wrap/libBornAgainDevice.py index 87b54ea758e5859db202e89af35a0de471a8eb0e..0cbe30f4040aa092188b7b33ed4ddb3bfde7fc55 100644 --- a/auto/Wrap/libBornAgainDevice.py +++ b/auto/Wrap/libBornAgainDevice.py @@ -2655,10 +2655,6 @@ class IDetector(libBornAgainBase.ICloneable, libBornAgainParam.INode): r"""clone(IDetector self) -> IDetector""" return _libBornAgainDevice.IDetector_clone(self) - def setFrame(self, frame): - r"""setFrame(IDetector self, Frame frame)""" - return _libBornAgainDevice.IDetector_setFrame(self, frame) - def setAnalyzer(self, *args): r""" setAnalyzer(IDetector self, R3 Bloch_vector={}, double mean_transmission=0.5) @@ -2854,7 +2850,6 @@ class SphericalDetector(IDetector): def __init__(self, *args): r""" - __init__(SphericalDetector self, Frame arg2) -> SphericalDetector __init__(SphericalDetector self, size_t n_phi, double phi_min, double phi_max, size_t n_alpha, double alpha_min, double alpha_max) -> SphericalDetector __init__(SphericalDetector self, size_t n_bin, double width, double phi, double alpha) -> SphericalDetector __init__(SphericalDetector self, SphericalDetector other) -> SphericalDetector diff --git a/auto/Wrap/libBornAgainDevice_wrap.cpp b/auto/Wrap/libBornAgainDevice_wrap.cpp index cd17c2b93e88c81f8829908251d88b43f4bea15f..ff345d4e187910bd6f1baa7edc412c2fe331aa0b 100644 --- a/auto/Wrap/libBornAgainDevice_wrap.cpp +++ b/auto/Wrap/libBornAgainDevice_wrap.cpp @@ -35545,45 +35545,6 @@ fail: } -SWIGINTERN PyObject *_wrap_IDetector_setFrame(PyObject *self, PyObject *args) { - PyObject *resultobj = 0; - IDetector *arg1 = (IDetector *) 0 ; - Frame *arg2 = (Frame *) 0 ; - void *argp1 = 0 ; - int res1 = 0 ; - void *argp2 = 0 ; - int res2 = 0 ; - PyObject *swig_obj[2] ; - - if (!SWIG_Python_UnpackTuple(args, "IDetector_setFrame", 2, 2, swig_obj)) SWIG_fail; - res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_IDetector, 0 | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "IDetector_setFrame" "', argument " "1"" of type '" "IDetector *""'"); - } - arg1 = reinterpret_cast< IDetector * >(argp1); - res2 = SWIG_ConvertPtr(swig_obj[1], &argp2,SWIGTYPE_p_Frame, 0 | 0 ); - if (!SWIG_IsOK(res2)) { - SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "IDetector_setFrame" "', argument " "2"" of type '" "Frame *""'"); - } - arg2 = reinterpret_cast< Frame * >(argp2); - { - try { - (arg1)->setFrame(arg2); - } catch (const std::exception& ex) { - // message shown in the Python interpreter - const std::string msg { - "BornAgain C++ Exception: " + std::string(ex.what()) - }; - SWIG_exception(SWIG_RuntimeError, msg.c_str()); - } - } - resultobj = SWIG_Py_Void(); - return resultobj; -fail: - return NULL; -} - - SWIGINTERN PyObject *_wrap_IDetector_setAnalyzer__SWIG_0(PyObject *self, Py_ssize_t nobjs, PyObject **swig_obj) { PyObject *resultobj = 0; IDetector *arg1 = (IDetector *) 0 ; @@ -38857,40 +38818,6 @@ SWIGINTERN PyObject *OffspecDetector_swiginit(PyObject *SWIGUNUSEDPARM(self), Py } SWIGINTERN PyObject *_wrap_new_SphericalDetector__SWIG_0(PyObject *self, Py_ssize_t nobjs, PyObject **swig_obj) { - PyObject *resultobj = 0; - Frame *arg1 = 0 ; - void *argp1 = 0 ; - int res1 = 0 ; - SphericalDetector *result = 0 ; - - if ((nobjs < 1) || (nobjs > 1)) SWIG_fail; - res1 = SWIG_ConvertPtr(swig_obj[0], &argp1, SWIGTYPE_p_Frame, 0 | 0); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "new_SphericalDetector" "', argument " "1"" of type '" "Frame const &""'"); - } - if (!argp1) { - SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "new_SphericalDetector" "', argument " "1"" of type '" "Frame const &""'"); - } - arg1 = reinterpret_cast< Frame * >(argp1); - { - try { - result = (SphericalDetector *)new SphericalDetector((Frame const &)*arg1); - } catch (const std::exception& ex) { - // message shown in the Python interpreter - const std::string msg { - "BornAgain C++ Exception: " + std::string(ex.what()) - }; - SWIG_exception(SWIG_RuntimeError, msg.c_str()); - } - } - resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_SphericalDetector, SWIG_POINTER_NEW | 0 ); - return resultobj; -fail: - return NULL; -} - - -SWIGINTERN PyObject *_wrap_new_SphericalDetector__SWIG_1(PyObject *self, Py_ssize_t nobjs, PyObject **swig_obj) { PyObject *resultobj = 0; size_t arg1 ; double arg2 ; @@ -38961,7 +38888,7 @@ fail: } -SWIGINTERN PyObject *_wrap_new_SphericalDetector__SWIG_2(PyObject *self, Py_ssize_t nobjs, PyObject **swig_obj) { +SWIGINTERN PyObject *_wrap_new_SphericalDetector__SWIG_1(PyObject *self, Py_ssize_t nobjs, PyObject **swig_obj) { PyObject *resultobj = 0; size_t arg1 ; double arg2 ; @@ -39016,7 +38943,7 @@ fail: } -SWIGINTERN PyObject *_wrap_new_SphericalDetector__SWIG_3(PyObject *self, Py_ssize_t nobjs, PyObject **swig_obj) { +SWIGINTERN PyObject *_wrap_new_SphericalDetector__SWIG_2(PyObject *self, Py_ssize_t nobjs, PyObject **swig_obj) { PyObject *resultobj = 0; SphericalDetector *arg1 = 0 ; void *argp1 = 0 ; @@ -39058,20 +38985,12 @@ SWIGINTERN PyObject *_wrap_new_SphericalDetector(PyObject *self, PyObject *args) if (!(argc = SWIG_Python_UnpackTuple(args, "new_SphericalDetector", 0, 6, argv))) SWIG_fail; --argc; - if (argc == 1) { - int _v = 0; - int res = SWIG_ConvertPtr(argv[0], 0, SWIGTYPE_p_Frame, SWIG_POINTER_NO_NULL | 0); - _v = SWIG_CheckState(res); - if (_v) { - return _wrap_new_SphericalDetector__SWIG_0(self, argc, argv); - } - } if (argc == 1) { int _v = 0; int res = SWIG_ConvertPtr(argv[0], 0, SWIGTYPE_p_SphericalDetector, SWIG_POINTER_NO_NULL | 0); _v = SWIG_CheckState(res); if (_v) { - return _wrap_new_SphericalDetector__SWIG_3(self, argc, argv); + return _wrap_new_SphericalDetector__SWIG_2(self, argc, argv); } } if (argc == 4) { @@ -39096,7 +39015,7 @@ SWIGINTERN PyObject *_wrap_new_SphericalDetector(PyObject *self, PyObject *args) _v = SWIG_CheckState(res); } if (_v) { - return _wrap_new_SphericalDetector__SWIG_2(self, argc, argv); + return _wrap_new_SphericalDetector__SWIG_1(self, argc, argv); } } } @@ -39134,7 +39053,7 @@ SWIGINTERN PyObject *_wrap_new_SphericalDetector(PyObject *self, PyObject *args) _v = SWIG_CheckState(res); } if (_v) { - return _wrap_new_SphericalDetector__SWIG_1(self, argc, argv); + return _wrap_new_SphericalDetector__SWIG_0(self, argc, argv); } } } @@ -39146,7 +39065,6 @@ SWIGINTERN PyObject *_wrap_new_SphericalDetector(PyObject *self, PyObject *args) fail: SWIG_Python_RaiseOrModifyTypeError("Wrong number or type of arguments for overloaded function 'new_SphericalDetector'.\n" " Possible C/C++ prototypes are:\n" - " SphericalDetector::SphericalDetector(Frame const &)\n" " SphericalDetector::SphericalDetector(size_t,double,double,size_t,double,double)\n" " SphericalDetector::SphericalDetector(size_t,double,double,double)\n" " SphericalDetector::SphericalDetector(SphericalDetector const &)\n"); @@ -43812,7 +43730,6 @@ static PyMethodDef SwigMethods[] = { { "ResolutionFunction2DGaussian_swiginit", ResolutionFunction2DGaussian_swiginit, METH_VARARGS, NULL}, { "delete_IDetector", _wrap_delete_IDetector, METH_O, "delete_IDetector(IDetector self)"}, { "IDetector_clone", _wrap_IDetector_clone, METH_O, "IDetector_clone(IDetector self) -> IDetector"}, - { "IDetector_setFrame", _wrap_IDetector_setFrame, METH_VARARGS, "IDetector_setFrame(IDetector self, Frame frame)"}, { "IDetector_setAnalyzer", _wrap_IDetector_setAnalyzer, METH_VARARGS, "\n" "IDetector_setAnalyzer(IDetector self, R3 Bloch_vector={}, double mean_transmission=0.5)\n" "IDetector_setAnalyzer(IDetector self, R3 direction, double efficiency, double transmission)\n" @@ -43868,7 +43785,6 @@ static PyMethodDef SwigMethods[] = { { "OffspecDetector_swigregister", OffspecDetector_swigregister, METH_O, NULL}, { "OffspecDetector_swiginit", OffspecDetector_swiginit, METH_VARARGS, NULL}, { "new_SphericalDetector", _wrap_new_SphericalDetector, METH_VARARGS, "\n" - "SphericalDetector(Frame arg1)\n" "SphericalDetector(size_t n_phi, double phi_min, double phi_max, size_t n_alpha, double alpha_min, double alpha_max)\n" "SphericalDetector(size_t n_bin, double width, double phi, double alpha)\n" "new_SphericalDetector(SphericalDetector other) -> SphericalDetector\n"