Mantid
Loading...
Searching...
No Matches
DetectorInfo.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
10#include "MantidKernel/Quat.h"
11#include "MantidKernel/V3D.h"
14#include "MantidPythonInterface/geometry/DetectorInfoPythonIterator.h"
15#include <boost/iterator/iterator_facade.hpp>
16#include <boost/python/class.hpp>
17#include <boost/python/copy_const_reference.hpp>
18#include <boost/python/copy_non_const_reference.hpp>
19#include <boost/python/iterator.hpp>
20#include <boost/python/return_by_value.hpp>
21#include <boost/python/return_value_policy.hpp>
22#include <iterator>
23
27using Mantid::PythonInterface::DetectorInfoPythonIterator;
28
31using namespace boost::python;
32using namespace Mantid::PythonInterface;
33
34namespace {
35// Helper method to make the python iterator
36DetectorInfoPythonIterator make_pyiterator(DetectorInfo &detectorInfo) {
37 return DetectorInfoPythonIterator(detectorInfo);
38}
40using return_readonly_numpy = return_value_policy<Policies::VectorRefToNumpy<Converters::WrapReadOnly>>;
41} // namespace
42
43// Export DetectorInfo
45
46 // Function pointers to distinguish between overloaded versions
47 bool (DetectorInfo::*isMonitor)(const size_t) const = &DetectorInfo::isMonitor;
48
49 bool (DetectorInfo::*isMasked)(const size_t) const = &DetectorInfo::isMasked;
50
51 double (DetectorInfo::*twoTheta)(const size_t) const = &DetectorInfo::twoTheta;
52
53 double (DetectorInfo::*azimuthal)(const size_t) const = &DetectorInfo::azimuthal;
54
56
58
59 void (DetectorInfo::*setMasked)(const size_t, bool) = &DetectorInfo::setMasked;
60
61 double (DetectorInfo::*l2)(const size_t) const = &DetectorInfo::l2;
62
63 // Export to Python
64 class_<DetectorInfo, boost::noncopyable>("DetectorInfo", no_init)
65
66 .def("__iter__", make_pyiterator)
67
68 .def("__len__", &DetectorInfo::size, (arg("self")),
69 "Returns the size of the DetectorInfo, i.e., the number of "
70 "detectors in the instrument.")
71
72 .def("size", &DetectorInfo::size, (arg("self")),
73 "Returns the size of the DetectorInfo, i.e., the number of "
74 "detectors in the instrument.")
75
76 .def("indexOf", &DetectorInfo::indexOf, (arg("self"), arg("detId")),
77 "Returns the index of the detector with the given id.")
78
79 .def("isMonitor", isMonitor, (arg("self"), arg("index")), "Returns True if the detector is a monitor.")
80
81 .def("isMasked", isMasked, (arg("self"), arg("index")), "Returns True if the detector is masked.")
82
83 .def("setMasked", setMasked, (arg("self"), arg("index"), arg("masked")),
84 "Set the mask flag of the detector where the detector is identified "
85 "by 'index'.")
86
87 .def("clearMaskFlags", &DetectorInfo::clearMaskFlags, (arg("self")), "Sets all mask flags to false (unmasked).")
88
89 .def("isEquivalent", &DetectorInfo::isEquivalent, (arg("self"), arg("other")),
90 "Returns True if the content of this "
91 "detector is equivalent to the content "
92 "of the other detector.")
93
94 .def("twoTheta", twoTheta, (arg("self"), arg("index")),
95 "Returns 2 theta (scattering angle w.r.t beam direction).")
96 .def("azimuthal", azimuthal, (arg("self"), arg("index")),
97 "Returns the out-of-plane angle in radians angle w.r.t. to "
98 "vecPointingHorizontal")
99 .def("position", position, (arg("self"), arg("index")),
100 "Returns the absolute position of the detector where the detector "
101 "is identified by 'index'.")
102
103 .def("rotation", rotation, (arg("self"), arg("index")),
104 "Returns the absolute rotation of the detector where the detector "
105 "is identified by 'index'.")
106 .def("detectorIDs", &DetectorInfo::detectorIDs, return_readonly_numpy(),
107 "Returns all detector ids sorted by detector index")
108 .def("l2", l2, (arg("self"), arg("index")), "Returns the l2 scattering distance")
109 .def("l1", &DetectorInfo::l1, arg("self"), "Returns the l1 scattering distance")
110 .def("hasMaskedDetectors", &DetectorInfo::hasMaskedDetectors, arg("self"),
111 "Returns if there are masked detectors");
112}
double position
Definition: GetAllEi.cpp:154
SpectrumInfoPythonIterator make_pyiterator(SpectrumInfo &spectrumInfo)
Mantid::Kernel::Quat(ComponentInfo::* rotation)(const size_t) const
void export_DetectorInfo()
DetectorInfoIterator for random access iteration over DetectorInfo.
Geometry::DetectorInfo is an intermediate step towards a DetectorInfo that is part of Instrument-2....
Definition: DetectorInfo.h:49
double twoTheta(const size_t index) const
Returns 2 theta (scattering angle w.r.t. to beam direction).
double l2(const size_t index) const
Returns L2 (distance from sample to spectrum).
bool hasMaskedDetectors() const
Returns true if there are masked detectors.
Kernel::Quat rotation(const size_t index) const
Returns the rotation of the detector with given index.
bool isMasked(const size_t index) const
Returns true if the detector is masked.
void setMasked(const size_t index, bool masked)
Set the mask flag of the detector with given index. Not thread safe.
const std::vector< detid_t > & detectorIDs() const
Returns a sorted vector of all detector IDs.
Kernel::V3D position(const size_t index) const
Returns the position of the detector with given index.
void clearMaskFlags()
Sets all mask flags to false (unmasked).
bool isEquivalent(const DetectorInfo &other) const
Returns true if the content of this is equivalent to the content of other.
double l1() const
Returns L1 (distance from source to sample).
size_t indexOf(const detid_t id) const
Returns the index of the detector with the given detector ID.
size_t size() const
Returns the size of the DetectorInfo, i.e., the number of detectors in the instrument.
bool isMonitor(const size_t index) const
Returns true if the detector is a monitor.
double azimuthal(const size_t index) const
Class for quaternions.
Definition: Quat.h:39
Class for 3D vectors.
Definition: V3D.h:34