Newer
Older
m_signals[i] = (m_signals[i] == 0.0);
m_errorsSquared[i] = 0;
Janik Zikovsky
committed
}
}
//----------------------------------------------------------------------------------------------
/** Turn this workspace into a boolean workspace, where
* signal[i] -> becomes true (1.0) if it is < b[i].
* signal[i] -> becomes false (0.0) otherwise
* Errors are set to 0.
*
* @param b :: workspace on the RHS of the comparison.
*/
void MDHistoWorkspace::lessThan(const MDHistoWorkspace &b) {
checkWorkspaceSize(b, "lessThan");
for (size_t i = 0; i < m_length; ++i) {
m_signals[i] = (m_signals[i] < b.m_signals[i]) ? 1.0 : 0.0;
m_errorsSquared[i] = 0;
}
//----------------------------------------------------------------------------------------------
/** Turn this workspace into a boolean workspace, where
* signal[i] -> becomes true (1.0) if it is < signal.
* signal[i] -> becomes false (0.0) otherwise
* Errors are set to 0.
*
* @param signal :: signal value on the RHS of the comparison.
*/
void MDHistoWorkspace::lessThan(const signal_t signal) {
for (size_t i = 0; i < m_length; ++i) {
m_signals[i] = (m_signals[i] < signal) ? 1.0 : 0.0;
m_errorsSquared[i] = 0;
}
//----------------------------------------------------------------------------------------------
/** Turn this workspace into a boolean workspace, where
* signal[i] -> becomes true (1.0) if it is > b[i].
* signal[i] -> becomes false (0.0) otherwise
* Errors are set to 0.
*
* @param b :: workspace on the RHS of the comparison.
*/
void MDHistoWorkspace::greaterThan(const MDHistoWorkspace &b) {
checkWorkspaceSize(b, "greaterThan");
for (size_t i = 0; i < m_length; ++i) {
m_signals[i] = (m_signals[i] > b.m_signals[i]) ? 1.0 : 0.0;
m_errorsSquared[i] = 0;
}
//----------------------------------------------------------------------------------------------
/** Turn this workspace into a boolean workspace, where
* signal[i] -> becomes true (1.0) if it is > signal.
* signal[i] -> becomes false (0.0) otherwise
* Errors are set to 0.
*
* @param signal :: signal value on the RHS of the comparison.
*/
void MDHistoWorkspace::greaterThan(const signal_t signal) {
for (size_t i = 0; i < m_length; ++i) {
m_signals[i] = (m_signals[i] > signal) ? 1.0 : 0.0;
m_errorsSquared[i] = 0;
}
//----------------------------------------------------------------------------------------------
/** Turn this workspace into a boolean workspace, where
* signal[i] -> becomes true (1.0) if it is == b[i].
* signal[i] -> becomes false (0.0) otherwise
* Errors are set to 0.
*
* @param b :: workspace on the RHS of the comparison.
* @param tolerance :: accept this deviation from a perfect equality
*/
void MDHistoWorkspace::equalTo(const MDHistoWorkspace &b,
const signal_t tolerance) {
checkWorkspaceSize(b, "equalTo");
for (size_t i = 0; i < m_length; ++i) {
signal_t diff = fabs(m_signals[i] - b.m_signals[i]);
m_signals[i] = (diff < tolerance) ? 1.0 : 0.0;
m_errorsSquared[i] = 0;
}
//----------------------------------------------------------------------------------------------
/** Turn this workspace into a boolean workspace, where
* signal[i] -> becomes true (1.0) if it is == signal.
* signal[i] -> becomes false (0.0) otherwise
* Errors are set to 0.
*
* @param signal :: signal value on the RHS of the comparison.
* @param tolerance :: accept this deviation from a perfect equality
*/
void MDHistoWorkspace::equalTo(const signal_t signal,
const signal_t tolerance) {
for (size_t i = 0; i < m_length; ++i) {
signal_t diff = fabs(m_signals[i] - signal);
m_signals[i] = (diff < tolerance) ? 1.0 : 0.0;
m_errorsSquared[i] = 0;
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
}
//----------------------------------------------------------------------------------------------
/** Copy the values from another workspace onto this workspace, but only
* where a mask is true (non-zero)
*
* For example, in matlab or numpy python, you might write something like:
* "mask = (array < 5.0); array[mask] = other[mask];"
*
* The equivalent here is:
* mask = array;
* mask.lessThan(5.0);
* array.setUsingMask(mask, other);
*
* @param mask :: MDHistoWorkspace where (signal == 0.0) means false, and
*(signal != 0.0) means true.
* @param values :: MDHistoWorkspace of values to copy.
*/
void MDHistoWorkspace::setUsingMask(const MDHistoWorkspace &mask,
const MDHistoWorkspace &values) {
checkWorkspaceSize(mask, "setUsingMask");
checkWorkspaceSize(values, "setUsingMask");
for (size_t i = 0; i < m_length; ++i) {
if (mask.m_signals[i] != 0.0) {
m_signals[i] = values.m_signals[i];
m_errorsSquared[i] = values.m_errorsSquared[i];
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
}
//----------------------------------------------------------------------------------------------
/** Copy the values from another workspace onto this workspace, but only
* where a mask is true (non-zero)
*
* For example, in matlab or numpy python, you might write something like:
* "mask = (array < 5.0); array[mask] = other[mask];"
*
* The equivalent here is:
* mask = array;
* mask.lessThan(5.0);
* array.setUsingMask(mask, other);
*
* @param mask :: MDHistoWorkspace where (signal == 0.0) means false, and
*(signal != 0.0) means true.
* @param signal :: signal to set everywhere mask is true
* @param error :: error (not squared) to set everywhere mask is true
*/
void MDHistoWorkspace::setUsingMask(const MDHistoWorkspace &mask,
const signal_t signal,
const signal_t error) {
signal_t errorSquared = error * error;
checkWorkspaceSize(mask, "setUsingMask");
for (size_t i = 0; i < m_length; ++i) {
if (mask.m_signals[i] != 0.0) {
m_signals[i] = signal;
m_errorsSquared[i] = errorSquared;
}
/**
Setter for the masking region.
Does not perform any clearing. Multiple calls are compounded.
@param maskingRegion : Implicit function defining mask region.
*/
void MDHistoWorkspace::setMDMasking(
Mantid::Geometry::MDImplicitFunction *maskingRegion) {
if (maskingRegion != NULL) {
for (size_t i = 0; i < this->getNPoints(); ++i) {
// If the function masks the point, then mask it, otherwise leave it as it
// is.
if (maskingRegion->isPointContained(this->getCenter(i))) {
m_masks[i] = true;
/**
* Set the masking
* @param index : linear index to mask
* @param mask : True to mask. False to clear.
*/
void MDHistoWorkspace::setMDMaskAt(const size_t &index, bool mask) {
m_masks[index] = mask;
/// Clear any existing masking.
void MDHistoWorkspace::clearMDMasking() {
for (size_t i = 0; i < this->getNPoints(); ++i) {
m_masks[i] = false;
uint64_t MDHistoWorkspace::getNEvents() const {
volatile uint64_t cach = this->m_nEventsContributed;
if (cach != this->m_nEventsContributed) {
if (!m_numEvents)
m_nEventsContributed = std::numeric_limits<uint64_t>::quiet_NaN();
else
m_nEventsContributed = sumNContribEvents();
return m_nEventsContributed;
}
uint64_t MDHistoWorkspace::sumNContribEvents() const {
uint64_t sum(0);
for (size_t i = 0; i < m_length; ++i)
sum += uint64_t(m_numEvents[i]);
return sum;
}
/**
* Get the Q frame system (if any) to use.
// clang-format off
GCC_DIAG_OFF(strict-aliasing)
// clang-format on
Kernel::SpecialCoordinateSystem
MDHistoWorkspace::getSpecialCoordinateSystem() const {
MDFramesToSpecialCoordinateSystem converter;
auto coordinatesFromMDFrames = converter(this);
auto coordinates = m_coordSystem;
if (coordinatesFromMDFrames) {
coordinates = coordinatesFromMDFrames.get();
}
return coordinates;
// clang-format off
GCC_DIAG_ON(strict-aliasing)
// clang-format on
Set the special coordinate system (if any) to use.
@param coordinateSystem : Special coordinate system to use.
void MDHistoWorkspace::setCoordinateSystem(
const Kernel::SpecialCoordinateSystem coordinateSystem) {
m_coordSystem = coordinateSystem;
}
/**
* Static helper method.
* @return The size of an element in the MDEventWorkspace.
*/
size_t MDHistoWorkspace::sizeOfElement() {
return (3 * sizeof(signal_t)) + sizeof(bool);
}
/**
Preferred normalization to use for visual purposes.
*/
MDNormalization MDHistoWorkspace::displayNormalization() const {
return m_displayNormalization; // Normalize by the number of events.
/**
Preferred normalization to use for visual purposes.
*/
MDNormalization MDHistoWorkspace::displayNormalizationHisto() const {
return displayNormalization(); // Normalize by the number of events.
void MDHistoWorkspace::setDisplayNormalization(
const Mantid::API::MDNormalization &preferredNormalization) {
m_displayNormalization = preferredNormalization;
}
} // namespace Mantid
} // namespace DataObjects