Skip to content
Snippets Groups Projects
Commit 92aa0a66 authored by Savici, Andrei T.'s avatar Savici, Andrei T.
Browse files

Allow MDNormSCD to work on merged workspaces

parent 363738dc
No related merge requests found
...@@ -55,13 +55,15 @@ private: ...@@ -55,13 +55,15 @@ private:
DataObjects::MDHistoWorkspace_sptr binInputWS(); DataObjects::MDHistoWorkspace_sptr binInputWS();
void createNormalizationWS(const DataObjects::MDHistoWorkspace &dataWS); void createNormalizationWS(const DataObjects::MDHistoWorkspace &dataWS);
std::vector<coord_t> std::vector<coord_t>
getValuesFromOtherDimensions(bool &skipNormalization) const; getValuesFromOtherDimensions(bool &skipNormalization,
uint16_t expInfoIndex=0) const;
Kernel::Matrix<coord_t> Kernel::Matrix<coord_t>
findIntergratedDimensions(const std::vector<coord_t> &otherDimValues, findIntergratedDimensions(const std::vector<coord_t> &otherDimValues,
bool &skipNormalization); bool &skipNormalization);
void cacheDimensionXValues(); void cacheDimensionXValues();
void calculateNormalization(const std::vector<coord_t> &otherValues, void calculateNormalization(const std::vector<coord_t> &otherValues,
const Kernel::Matrix<coord_t> &affineTrans); const Kernel::Matrix<coord_t> &affineTrans,
uint16_t expInfoIndex);
void calcIntegralsForIntersections(const std::vector<double> &xValues, void calcIntegralsForIntersections(const std::vector<double> &xValues,
const API::MatrixWorkspace &integrFlux, const API::MatrixWorkspace &integrFlux,
size_t sp, size_t sp,
...@@ -91,7 +93,10 @@ private: ...@@ -91,7 +93,10 @@ private:
Kernel::V3D m_beamDir; Kernel::V3D m_beamDir;
/// ki-kf for Inelastic convention; kf-ki for Crystallography convention /// ki-kf for Inelastic convention; kf-ki for Crystallography convention
std::string convention; std::string convention;
/// internal flag to accumulate to an existing workspace
bool m_accumulate{false}; bool m_accumulate{false};
/// number of experiment infos
uint16_t m_numExptInfos;
}; };
} // namespace MDAlgorithms } // namespace MDAlgorithms
......
...@@ -144,20 +144,26 @@ void MDNormSCD::exec() { ...@@ -144,20 +144,26 @@ void MDNormSCD::exec() {
m_normWS->setDisplayNormalization(Mantid::API::NoNormalization); m_normWS->setDisplayNormalization(Mantid::API::NoNormalization);
setProperty("OutputNormalizationWorkspace", m_normWS); setProperty("OutputNormalizationWorkspace", m_normWS);
// Check for other dimensions if we could measure anything in the original m_numExptInfos = outputWS->getNumExperimentInfo();
// data // loop over all experiment infos
bool skipNormalization = false; for (uint16_t expInfoIndex = 0; expInfoIndex < m_numExptInfos;
const std::vector<coord_t> otherValues = expInfoIndex++) {
getValuesFromOtherDimensions(skipNormalization); // Check for other dimensions if we could measure anything in the original
const auto affineTrans = // data
findIntergratedDimensions(otherValues, skipNormalization); bool skipNormalization = false;
cacheDimensionXValues(); const std::vector<coord_t> otherValues =
getValuesFromOtherDimensions(skipNormalization, expInfoIndex);
if (!skipNormalization) { const auto affineTrans =
calculateNormalization(otherValues, affineTrans); findIntergratedDimensions(otherValues, skipNormalization);
} else { cacheDimensionXValues();
g_log.warning("Binning limits are outside the limits of the MDWorkspace. "
if (!skipNormalization) {
calculateNormalization(otherValues, affineTrans, expInfoIndex);
} else {
g_log.warning("Binning limits are outside the limits of the MDWorkspace. "
"Not applying normalization."); "Not applying normalization.");
}
m_accumulate = true;
} }
} }
...@@ -269,12 +275,14 @@ void MDNormSCD::createNormalizationWS(const MDHistoWorkspace &dataWS) { ...@@ -269,12 +275,14 @@ void MDNormSCD::createNormalizationWS(const MDHistoWorkspace &dataWS) {
* Retrieve logged values from non-HKL dimensions * Retrieve logged values from non-HKL dimensions
* @param skipNormalization [InOut] Updated to false if any values are outside * @param skipNormalization [InOut] Updated to false if any values are outside
* range measured by input workspace * range measured by input workspace
* @param expInfoIndex current experiment info index
* @return A vector of values from other dimensions to be include in normalized * @return A vector of values from other dimensions to be include in normalized
* MD position calculation * MD position calculation
*/ */
std::vector<coord_t> std::vector<coord_t>
MDNormSCD::getValuesFromOtherDimensions(bool &skipNormalization) const { MDNormSCD::getValuesFromOtherDimensions(bool &skipNormalization,
const auto &runZero = m_inputWS->getExperimentInfo(0)->run(); uint16_t expInfoIndex) const {
const auto &currentRun = m_inputWS->getExperimentInfo(expInfoIndex)->run();
std::vector<coord_t> otherDimValues; std::vector<coord_t> otherDimValues;
for (size_t i = 3; i < m_inputWS->getNumDims(); i++) { for (size_t i = 3; i < m_inputWS->getNumDims(); i++) {
...@@ -282,7 +290,7 @@ MDNormSCD::getValuesFromOtherDimensions(bool &skipNormalization) const { ...@@ -282,7 +290,7 @@ MDNormSCD::getValuesFromOtherDimensions(bool &skipNormalization) const {
float dimMin = static_cast<float>(dimension->getMinimum()); float dimMin = static_cast<float>(dimension->getMinimum());
float dimMax = static_cast<float>(dimension->getMaximum()); float dimMax = static_cast<float>(dimension->getMaximum());
auto *dimProp = dynamic_cast<Kernel::TimeSeriesProperty<double> *>( auto *dimProp = dynamic_cast<Kernel::TimeSeriesProperty<double> *>(
runZero.getProperty(dimension->getName())); currentRun.getProperty(dimension->getName()));
if (dimProp) { if (dimProp) {
coord_t value = static_cast<coord_t>(dimProp->firstValue()); coord_t value = static_cast<coord_t>(dimProp->firstValue());
otherDimValues.push_back(value); otherDimValues.push_back(value);
...@@ -393,19 +401,20 @@ void MDNormSCD::cacheDimensionXValues() { ...@@ -393,19 +401,20 @@ void MDNormSCD::cacheDimensionXValues() {
* m_normWS * m_normWS
* @param otherValues * @param otherValues
* @param affineTrans * @param affineTrans
* @param expInfoIndex current experiment info index
*/ */
void MDNormSCD::calculateNormalization( void MDNormSCD::calculateNormalization(
const std::vector<coord_t> &otherValues, const std::vector<coord_t> &otherValues,
const Kernel::Matrix<coord_t> &affineTrans) { const Kernel::Matrix<coord_t> &affineTrans, uint16_t expInfoIndex) {
API::MatrixWorkspace_const_sptr integrFlux = getProperty("FluxWorkspace"); API::MatrixWorkspace_const_sptr integrFlux = getProperty("FluxWorkspace");
integrFlux->getXMinMax(m_kiMin, m_kiMax); integrFlux->getXMinMax(m_kiMin, m_kiMax);
API::MatrixWorkspace_const_sptr solidAngleWS = API::MatrixWorkspace_const_sptr solidAngleWS =
getProperty("SolidAngleWorkspace"); getProperty("SolidAngleWorkspace");
const auto &exptInfoZero = *(m_inputWS->getExperimentInfo(0)); const auto &currentExptInfo = *(m_inputWS->getExperimentInfo(expInfoIndex));
using VectorDoubleProperty = Kernel::PropertyWithValue<std::vector<double>>; using VectorDoubleProperty = Kernel::PropertyWithValue<std::vector<double>>;
auto *rubwLog = auto *rubwLog =
dynamic_cast<VectorDoubleProperty *>(exptInfoZero.getLog("RUBW_MATRIX")); dynamic_cast<VectorDoubleProperty *>(currentExptInfo.getLog("RUBW_MATRIX"));
if (!rubwLog) { if (!rubwLog) {
throw std::runtime_error( throw std::runtime_error(
"Wokspace does not contain a log entry for the RUBW matrix." "Wokspace does not contain a log entry for the RUBW matrix."
...@@ -413,12 +422,12 @@ void MDNormSCD::calculateNormalization( ...@@ -413,12 +422,12 @@ void MDNormSCD::calculateNormalization(
} else { } else {
Kernel::DblMatrix rubwValue( Kernel::DblMatrix rubwValue(
(*rubwLog)()); // includes the 2*pi factor but not goniometer for now :) (*rubwLog)()); // includes the 2*pi factor but not goniometer for now :)
m_rubw = exptInfoZero.run().getGoniometerMatrix() * rubwValue; m_rubw = currentExptInfo.run().getGoniometerMatrix() * rubwValue;
m_rubw.Invert(); m_rubw.Invert();
} }
const double protonCharge = exptInfoZero.run().getProtonCharge(); const double protonCharge = currentExptInfo.run().getProtonCharge();
const auto &spectrumInfo = exptInfoZero.spectrumInfo(); const auto &spectrumInfo = currentExptInfo.spectrumInfo();
// Mappings // Mappings
const int64_t ndets = static_cast<int64_t>(spectrumInfo.size()); const int64_t ndets = static_cast<int64_t>(spectrumInfo.size());
...@@ -432,7 +441,9 @@ void MDNormSCD::calculateNormalization( ...@@ -432,7 +441,9 @@ void MDNormSCD::calculateNormalization(
std::vector<std::array<double, 4>> intersections; std::vector<std::array<double, 4>> intersections;
std::vector<double> xValues, yValues; std::vector<double> xValues, yValues;
std::vector<coord_t> pos, posNew; std::vector<coord_t> pos, posNew;
auto prog = make_unique<API::Progress>(this, 0.3, 1.0, ndets); double progStep = 0.7 / m_numExptInfos;
auto prog = make_unique<API::Progress>(this, 0.3 + progStep * expInfoIndex,
0.3 + progStep * (expInfoIndex + 1.), ndets);
// cppcheck-suppress syntaxError // cppcheck-suppress syntaxError
PRAGMA_OMP(parallel for private(intersections, xValues, yValues, pos, posNew) if (Kernel::threadSafe(*integrFlux))) PRAGMA_OMP(parallel for private(intersections, xValues, yValues, pos, posNew) if (Kernel::threadSafe(*integrFlux)))
for (int64_t i = 0; i < ndets; i++) { for (int64_t i = 0; i < ndets; i++) {
......
...@@ -18,6 +18,9 @@ The algorithm :ref:`MDNormSCDPreprocessIncoherent ...@@ -18,6 +18,9 @@ The algorithm :ref:`MDNormSCDPreprocessIncoherent
<algm-MDNormSCDPreprocessIncoherent>` can be used to process Vanadium <algm-MDNormSCDPreprocessIncoherent>` can be used to process Vanadium
data for the Solid Angle and Flux workspaces. data for the Solid Angle and Flux workspaces.
.. Note::
As of :ref:`Release 3.14.0 <v3.14.0>`, the algorithm can handle merged MD workspaces. Make sure all original MDEvent workspaces have the same dimensions
Usage Usage
----- -----
.. Try not to use files in your examples, .. Try not to use files in your examples,
......
...@@ -26,6 +26,7 @@ Improvements ...@@ -26,6 +26,7 @@ Improvements
############ ############
- :ref:`IntegratePeaksProfileFitting <algm-IntegratePeaksProfileFitting>` now supports MaNDi, TOPAZ, and CORELLI. Other instruments can easily be added as well. - :ref:`IntegratePeaksProfileFitting <algm-IntegratePeaksProfileFitting>` now supports MaNDi, TOPAZ, and CORELLI. Other instruments can easily be added as well.
- :ref:`MDNormSCD <algm-MDNormSCD>` now can handle merged MD workspaces.
Bugfixes Bugfixes
######## ########
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment