9#include "MantidDataObjects/DllConfig.h"
22namespace DataObjects {
44template <
size_t nd>
class MDLeanEvent;
60template <
size_t nd>
class MANTID_DATAOBJECTS_DLL
MDLeanEvent {
68 template <
class Accessor>
75 static std::enable_if_t<std::is_same<EventAccessor, typename Accessor::EventAccessType>::value>
77 event.convertToCoordinates(space);
79 static std::enable_if_t<std::is_same<EventAccessor, typename Accessor::EventAccessType>::value>
81 event.convertToIndex(space);
84 typename std::enable_if<std::is_same<EventAccessor, typename Accessor::EventAccessType>::value,
MortonT>::type
123 index = morton_index::coordinatesToIndex<nd, IntT, MortonT>(center, space);
133 auto coords = morton_index::indexToCoordinates<nd, IntT, MortonT>(
index, space);
134 for (
unsigned i = 0; i < nd; ++i)
135 center[i] = coords[i];
143 enum { is_full_mdevent =
false };
156 : signal(float(signal)), errorSquared(float(errorSquared)) {}
164 MDLeanEvent(
const float signal,
const float errorSquared) : signal(signal), errorSquared(errorSquared) {}
175 : signal(signal), errorSquared(errorSquared) {
176 for (
size_t i = 0; i < nd; i++)
177 center[i] = centers[i];
188 : signal(float(signal)), errorSquared(float(errorSquared)) {
189 for (
size_t i = 0; i < nd; i++)
190 center[i] = centers[i];
193#ifdef COORDT_IS_FLOAT
202 MDLeanEvent(
const float signal,
const float errorSquared,
const double *centers)
203 : signal(signal), errorSquared(errorSquared) {
204 for (
size_t i = 0; i < nd; i++)
205 center[i] =
static_cast<coord_t>(centers[i]);
213 for (
size_t i = 0; i < nd; i++)
214 center[i] =
rhs.center[i];
250#ifdef COORDT_IS_FLOAT
256 void setCenter(
const size_t n,
const double value) { center[
n] =
static_cast<coord_t>(
value); }
265 for (
size_t i = 0; i < nd; i++)
266 center[i] = centers[i];
291 float getError()
const {
return float(sqrt(errorSquared)); }
296 void setSignal(
const float newSignal) { signal = newSignal; }
334 size_t &
ncols,
double &totalSignal,
double &totalErrSq) {
336 size_t nEvents = mdLeanEvents.size();
337 data.resize(nEvents *
ncols);
344 data[dataIndex++] =
static_cast<coord_t>(mdLeanEvent.signal);
345 data[dataIndex++] =
static_cast<coord_t>(mdLeanEvent.errorSquared);
346 for (
size_t d = 0;
d < nd;
d++)
347 data[dataIndex++] = mdLeanEvent.center[
d];
349 totalSignal +=
signal_t(mdLeanEvent.signal);
350 totalErrSq +=
signal_t(mdLeanEvent.errorSquared);
362 bool reserveMemory =
true) {
364 size_t numColumns = (nd + 2);
365 size_t numEvents = coord.size() / numColumns;
366 if (
numEvents * numColumns != coord.size())
367 throw(std::invalid_argument(
"wrong input array of data to convert to "
368 "lean events, suspected column data for "
369 "different dimensions/(type of) events "));
379 size_t ii = i * numColumns;
382 const coord_t *centers = &(coord[ii + 2]);
385 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 ...
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, const NexusHDF5Descriptor &descriptor)
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