Mantid
Loading...
Searching...
No Matches
IEventList.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 +
11#include <boost/python/class.hpp>
12#include <boost/python/enum.hpp>
13#include <boost/python/make_function.hpp>
14#include <boost/python/register_ptr_to_python.hpp>
15#include <vector>
16
22
23using namespace Mantid::PythonInterface;
24using namespace boost::python;
25
27
28namespace {
29void addPulsetimes(IEventList &self, const NDArray &data) {
31}
32
33void maskCondition(IEventList &self, const NDArray &data) {
35}
36} // namespace
37
39using return_clone_numpy = return_value_policy<Policies::VectorToNumpy>;
40
42 register_ptr_to_python<IEventList *>();
43
44 enum_<EventType>("EventType")
45 .value("TOF", TOF)
46 .value("WEIGHTED", WEIGHTED)
47 .value("WEIGHTED_NOTIME", WEIGHTED_NOTIME)
48 .export_values();
49
50 class_<IEventList, bases<Mantid::API::ISpectrum>, boost::noncopyable>("IEventList", no_init)
51 .def("getEventType", &IEventList::getEventType, args("self"), "Return the type of events stored.")
52 .def("switchTo", &IEventList::switchTo, args("self", "newType"), "Switch the event type to the one specified")
53 .def("clear", &IEventList::clear, args("self", "removeDetIDs"), "Clears the event list")
54 .def("isSortedByTof", &IEventList::isSortedByTof, args("self"), "Returns true if the list is sorted in TOF")
55 .def("getNumberEvents", &IEventList::getNumberEvents, args("self"),
56 "Returns the number of events within the list")
57 .def("getMemorySize", &IEventList::getMemorySize, args("self"), "Returns the memory size in bytes")
58 .def("integrate", &IEventList::integrate, args("self", "minX", "maxX", "entireRange"),
59 "Integrate the events between a range of X values, or all events.")
60 .def("convertTof", (void (IEventList::*)(const double, const double)) & IEventList::convertTof,
61 args("self", "factor", "offset"), "Convert the time of flight by tof'=tof*factor+offset")
62 .def("scaleTof", &IEventList::scaleTof, args("self", "factor"),
63 "Convert the tof units by scaling by a multiplier.")
64 .def("addTof", &IEventList::addTof, args("self", "offset"), "Add an offset to the TOF of each event in the list.")
65 .def("addPulsetime", &IEventList::addPulsetime, args("self", "seconds"),
66 "Add an offset to the pulsetime (wall-clock time) of each event in "
67 "the list.")
68 .def("addPulsetimes", &addPulsetimes, args("self", "seconds"),
69 "Add offsets to the pulsetime (wall-clock time) of each event in "
70 "the list.")
71 .def("maskTof", &IEventList::maskTof, args("self", "tofMin", "tofMax"),
72 "Mask out events that have a tof between tofMin and tofMax "
73 "(inclusively)")
74 .def("maskCondition", &maskCondition, args("self", "mask"), "Mask out events by the condition vector")
75 .def("getTofs", (std::vector<double>(IEventList::*)(void) const) & IEventList::getTofs, args("self"),
76 return_clone_numpy(), "Get a vector of the TOFs of the events")
77 .def("getWeights", (std::vector<double>(IEventList::*)(void) const) & IEventList::getWeights, args("self"),
78 return_clone_numpy(), "Get a vector of the weights of the events")
79 .def("getWeightErrors", (std::vector<double>(IEventList::*)(void) const) & IEventList::getWeightErrors,
80 args("self"), return_clone_numpy(), "Get a vector of the weights of the events")
81 .def("getPulseTimes", &IEventList::getPulseTimes, args("self"), "Get a vector of the pulse times of the events")
82 .def("getPulseTimesAsNumpy",
83 make_function(&IEventList::getPulseTimes, return_value_policy<Policies::VectorToNumpy>()),
84 "Get a vector of the pulse times of the events")
85 .def("getPulseTimeMax", &IEventList::getPulseTimeMax, args("self"),
86 "The maximum pulse time for the list of the events.")
87 .def("getPulseTimeMin", &IEventList::getPulseTimeMin, args("self"),
88 "The minimum pulse time for the list of the events.")
89 .def("getTofMin", &IEventList::getTofMin, args("self"), "The minimum tof value for the list of the events.")
90 .def("getTofMax", &IEventList::getTofMax, args("self"), "The maximum tof value for the list of the events.")
91 .def("multiply", (void (IEventList::*)(const double, const double)) & IEventList::multiply,
92 args("self", "value", "error"),
93 "Multiply the weights in this event "
94 "list by a scalar variable with an "
95 "error; though the error can be 0.0")
96 .def("divide", (void (IEventList::*)(const double, const double)) & IEventList::divide,
97 args("self", "value", "error"),
98 "Divide the weights in this event "
99 "list by a scalar with an "
100 "(optional) error.");
101}
#define GET_POINTER_SPECIALIZATION(TYPE)
Definition: GetPointer.h:17
return_value_policy< Policies::VectorToNumpy > return_clone_numpy
return_value_policy for copied numpy array
Definition: IEventList.cpp:39
void export_IEventList()
Definition: IEventList.cpp:41
IEventList : Interface to Mantid::DataObjects::EventList class, used to expose to PythonAPI.
Definition: IEventList.h:26
virtual void addPulsetime(const double seconds)=0
Add a value to the pulse time values.
virtual void addTof(const double offset)=0
Add a value to the TOF values.
virtual Mantid::API::EventType getEventType() const =0
Return the current event type for the list.
virtual Mantid::Types::Core::DateAndTime getPulseTimeMax() const =0
Get the maximum pulse time from the list.
virtual std::size_t getNumberEvents() const =0
Get the number of events from the list.
virtual Mantid::Types::Core::DateAndTime getPulseTimeMin() const =0
Get the minimum pulse time from the list.
virtual void maskCondition(const std::vector< bool > &mask)=0
Mask the events by the condition vector.
virtual void scaleTof(const double factor)=0
Scale the TOF values by a constant.
virtual std::vector< double > getWeights() const =0
Return the list of event weight values.
virtual double integrate(const double minX, const double maxX, const bool entireRange) const =0
Integrate the event list.
virtual std::vector< Mantid::Types::Core::DateAndTime > getPulseTimes() const =0
Return the list of pulse time values.
virtual void maskTof(const double tofMin, const double tofMax)=0
Mask a given TOF range.
virtual void multiply(const double value, const double error=0.0)=0
Multiply event list by a constant with error.
virtual bool isSortedByTof() const =0
IS the list sorted by TOF?
virtual void convertTof(std::function< double(double)> func, const int sorting=0)=0
Convert the TOF values.
virtual void divide(const double value, const double error=0.0)=0
Divide event list by a constant with error.
virtual void clear(const bool removeDetIDs)=0
Clear the event list.
virtual std::vector< double > getTofs() const =0
Return the list of TOF values.
virtual void switchTo(Mantid::API::EventType newType)=0
Switch to a new event type within the list.
virtual void addPulsetimes(const std::vector< double > &seconds)=0
Add a separate value to each of the pulse time values.
virtual double getTofMin() const =0
Get the minimum TOF from the list.
virtual double getTofMax() const =0
Get the maximum TOF from the list.
size_t getMemorySize() const override=0
Get memory size of event list.
virtual std::vector< double > getWeightErrors() const =0
Return the list of event weight error values.
Thin object wrapper around a numpy array.
Definition: NDArray.h:31
EventType
What kind of event list is being stored.
Definition: IEventList.h:18
@ WEIGHTED_NOTIME
Definition: IEventList.h:18
Converter taking an input numpy array and converting it to a std::vector.