9#include "MantidDataObjects/DllConfig.h"
22namespace DataObjects {
44template <
size_t nd>
class MDLeanEvent;
64template <
size_t nd>
class MANTID_DATAOBJECTS_DLL
MDLeanEvent {
73 template <
class Accessor>
80 static std::enable_if_t<std::is_same<EventAccessor, typename Accessor::EventAccessType>::value>
82 event.convertToCoordinates(space);
84 static std::enable_if_t<std::is_same<EventAccessor, typename Accessor::EventAccessType>::value>
86 event.convertToIndex(space);
89 typename std::enable_if<std::is_same<EventAccessor, typename Accessor::EventAccessType>::value,
MortonT>::type
128 index = morton_index::coordinatesToIndex<nd, IntT, MortonT>(center, space);
138 auto coords = morton_index::indexToCoordinates<nd, IntT, MortonT>(
index, space);
139 for (
unsigned i = 0; i < nd; ++i)
140 center[i] = coords[i];
148 enum { is_full_mdevent =
false };
161 : signal(float(signal)), errorSquared(float(errorSquared)) {}
169 MDLeanEvent(
const float signal,
const float errorSquared) : signal(signal), errorSquared(errorSquared) {}
180 : signal(signal), errorSquared(errorSquared) {
181 for (
size_t i = 0; i < nd; i++)
182 center[i] = centers[i];
193 : signal(float(signal)), errorSquared(float(errorSquared)) {
194 for (
size_t i = 0; i < nd; i++)
195 center[i] = centers[i];
198#ifdef COORDT_IS_FLOAT
207 MDLeanEvent(
const float signal,
const float errorSquared,
const double *centers)
208 : signal(signal), errorSquared(errorSquared) {
209 for (
size_t i = 0; i < nd; i++)
210 center[i] =
static_cast<coord_t>(centers[i]);
218 for (
size_t i = 0; i < nd; i++)
219 center[i] =
rhs.center[i];
255#ifdef COORDT_IS_FLOAT
261 void setCenter(
const size_t n,
const double value) { center[
n] =
static_cast<coord_t>(
value); }
270 for (
size_t i = 0; i < nd; i++)
271 center[i] = centers[i];
296 float getError()
const {
return float(sqrt(errorSquared)); }
301 void setSignal(
const float newSignal) { signal = newSignal; }
339 size_t &
ncols,
double &totalSignal,
double &totalErrSq) {
341 size_t nEvents = mdLeanEvents.size();
342 data.resize(nEvents *
ncols);
349 data[dataIndex++] =
static_cast<coord_t>(mdLeanEvent.signal);
350 data[dataIndex++] =
static_cast<coord_t>(mdLeanEvent.errorSquared);
351 for (
size_t d = 0;
d < nd;
d++)
352 data[dataIndex++] = mdLeanEvent.center[
d];
354 totalSignal +=
signal_t(mdLeanEvent.signal);
355 totalErrSq +=
signal_t(mdLeanEvent.errorSquared);
367 bool reserveMemory =
true) {
369 size_t numColumns = (nd + 2);
370 size_t numEvents = coord.size() / numColumns;
371 if (
numEvents * numColumns != coord.size())
372 throw(std::invalid_argument(
"wrong input array of data to convert to "
373 "lean events, suspected column data for "
374 "different dimensions/(type of) events "));
384 size_t ii = i * numColumns;
387 const coord_t *centers = &(coord[ii + 2]);
390 events.emplace_back(
static_cast<signal_t>(coord[ii]),
static_cast<signal_t>(coord[ii + 1]), centers);
const std::vector< double > & rhs
double value
The value of the point.
std::map< DeltaEMode::Type, std::string > index
Templated class holding data about a neutron detection event in N-dimensions (for example,...
MDLeanEvent(const float signal, const float errorSquared, const coord_t *centers)
Constructor with signal and error and an array of centers.
uint16_t getExpInfoIndex() const
size_t getNumDims() const
Returns the number of dimensions in the event.
MDLeanEvent()
Empty constructor.
void convertToIndex(const morton_index::MDSpaceBounds< nd > &space)
Calculate Morton index for center coordinates for given space and ovveride the memory used for storin...
MDLeanEvent & operator=(MDLeanEvent other)
static void eventsToData(const std::vector< MDLeanEvent< nd > > &mdLeanEvents, std::vector< coord_t > &data, size_t &ncols, double &totalSignal, double &totalErrSq)
const coord_t * getCenter() const
Returns the array of coordinates.
void setCoords(const coord_t *centers)
Sets all the coordinates.
float getSignal() const
Returns the signal (weight) of this event.
coord_t * getCenterNonConst()
Returns the array of coordinates, as a pointer to a non-const array.
float errorSquared
The square of the error carried in this event.
MDLeanEvent(const double signal, const double errorSquared)
Constructor with signal and error.
typename morton_index::IndexTypes< nd, coord_t >::IntType IntT
Additional index type defenitions.
void setSignal(const float newSignal)
Set the signal of the event.
MDLeanEvent(const float signal, const float errorSquared)
Constructor with signal and error.
float getError() const
Returns the error (not squared) of this event.
int32_t getDetectorID() const
float getErrorSquared() const
Returns the error (squared) of this event.
uint16_t getGoniometerIndex() const
MDLeanEvent(const double signal, const double errorSquared, const coord_t *centers)
Constructor with signal and error and an array of centers.
static std::string getTypeName()
static void dataToEvents(const std::vector< coord_t > &coord, std::vector< MDLeanEvent< nd > > &events, bool reserveMemory=true)
void setCenter(const size_t n, const coord_t value)
Sets the n-th coordinate axis value.
typename morton_index::IndexTypes< nd, coord_t >::MortonType MortonT
void setErrorSquared(const float newerrorSquared)
Set the squared error of the event.
void convertToCoordinates(const morton_index::MDSpaceBounds< nd > &space)
Calculate coordinates of the center of event from it Morton index in known space and oveerride index ...
friend void swap(MDLeanEvent &first, MDLeanEvent &second)
float signal
The signal (aka weight) from the neutron event.
MDLeanEvent(const MDLeanEvent &rhs)
Copy constructor.
coord_t getCenter(const size_t n) const
std::size_t numEvents(Nexus::File &file, bool &hasTotalCounts, bool &oldNeXusFileNames, const std::string &prefix)
Get the number of events in the currently opened group.
void swap(MDLeanEvent< nd > &first, MDLeanEvent< nd > &second)
Helper class which provides the Collimation Length for SANS instruments.
float coord_t
Typedef for the data type to use for coordinate axes in MD objects such as MDBox, MDEventWorkspace,...
double signal_t
Typedef for the signal recorded in a MDBox, etc.
Eigen::Array< float, static_cast< int >(ND), 2 > MDSpaceBounds
Structure to mark the classes, which can switch the "physical" meaning of the union used in MDLeanEve...
Internal structure to avoid the direct exposing of API functions, which change the state of event (sw...
static std::enable_if_t< std::is_same< EventAccessor, typename Accessor::EventAccessType >::value > convertToCoordinates(MDLeanEvent< nd > &event, const morton_index::MDSpaceBounds< nd > &space)
static std::enable_if_t< std::is_same< EventAccessor, typename Accessor::EventAccessType >::value > convertToIndex(MDLeanEvent< nd > &event, const morton_index::MDSpaceBounds< nd > &space)
static std::enable_if< std::is_same< EventAccessor, typenameAccessor::EventAccessType >::value, MortonT >::type getIndex(const MDLeanEvent< nd > &event)
typename UnderlyingInt< FP >::type IntType
typename MortonIndex< ND *sizeof(FP)>::type MortonType