Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/release-v3.11'
Browse files Browse the repository at this point in the history
  • Loading branch information
peterfpeterson committed Oct 5, 2017
2 parents 216e0fd + 6d9f23a commit 40aebb9
Show file tree
Hide file tree
Showing 112 changed files with 4,076 additions and 1,709 deletions.
4 changes: 2 additions & 2 deletions Framework/API/inc/MantidAPI/MatrixWorkspaceMDIterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ class DLLExport MatrixWorkspaceMDIterator : public IMDIterator {
/// The Y (vertical, e.g. spectra) dimension
Mantid::Geometry::IMDDimension_const_sptr m_dimY;

/// Blocksize of workspace
size_t m_blockSize;
/// vector of starting index of the unraveled data array
std::vector<size_t> m_startIndices;

/// Workspace index at which the iterator begins
size_t m_beginWI;
Expand Down
15 changes: 14 additions & 1 deletion Framework/API/inc/MantidAPI/WorkspaceGroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "MantidAPI/AnalysisDataService.h"

#include <Poco/NObserver.h>
#include <iterator>
#include <mutex>

namespace Mantid {
Expand Down Expand Up @@ -88,6 +89,19 @@ class MANTID_API_DLL WorkspaceGroup : public Workspace {
/// Prints the group to the screen using the logger at debug
void print() const;

/// Returns a non-const iterator pointing at the first element in the
/// workspace group
std::vector<Workspace_sptr>::iterator begin();
/// Returns a non-const iterator pointing at the last element in the workspace
/// group
std::vector<Workspace_sptr>::iterator end();
/// Returns a const iterator pointing at the first element in the workspace
/// group
std::vector<Workspace_sptr>::const_iterator begin() const;
/// Returns a const iterator pointing at the last element in the workspace
/// group
std::vector<Workspace_sptr>::const_iterator end() const;

/// @name Wrapped ADS calls
//@{

Expand All @@ -114,7 +128,6 @@ class MANTID_API_DLL WorkspaceGroup : public Workspace {
/// returns a copy as the internal vector can mutate while the vector is being
/// iterated over.
std::vector<std::string> getNames() const;

//@}

WorkspaceGroup(const WorkspaceGroup &ref) = delete;
Expand Down
7 changes: 4 additions & 3 deletions Framework/API/src/MatrixWorkspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,13 @@ const std::string MatrixWorkspace::toString() const {
std::ostringstream os;
os << id() << "\n"
<< "Title: " << getTitle() << "\n"
<< "Histograms: " << getNumberHistograms() << "\n";
<< "Histograms: " << getNumberHistograms() << "\n"
<< "Bins: ";

try {
os << "Bins: " << blocksize() << "\n";
os << blocksize() << "\n";
} catch (std::length_error &) {
os << "Bins: variable\n"; // TODO shouldn't use try/catch
os << "variable\n"; // TODO shouldn't use try/catch
}

if (isHistogramData())
Expand Down
22 changes: 15 additions & 7 deletions Framework/API/src/MatrixWorkspaceMDIterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ MatrixWorkspaceMDIterator::MatrixWorkspaceMDIterator(
m_center = VMD(2);
m_isBinnedData = m_ws->isHistogramData();
m_dimY = m_ws->getDimension(1);
m_blockSize = m_ws->blocksize();

m_beginWI = beginWI;
if (m_beginWI >= m_ws->getNumberHistograms())
Expand All @@ -48,7 +47,14 @@ MatrixWorkspaceMDIterator::MatrixWorkspaceMDIterator(
throw std::runtime_error(
"MatrixWorkspaceMDIterator: End point is before the start point.");

m_max = (m_endWI - m_beginWI) * m_blockSize;
// calculate the indices and the largest index we accept
m_max = 0;
m_startIndices.reserve(m_endWI - m_beginWI);
for (size_t i = m_beginWI; i < m_endWI; ++i) {
m_startIndices.push_back(m_max);
m_max += m_ws->readY(i).size();
}

m_xIndex = 0;
// Trigger the calculation for the first index
m_workspaceIndex = size_t(-1); // This makes sure calcWorkspacePos() updates
Expand All @@ -66,9 +72,11 @@ size_t MatrixWorkspaceMDIterator::getDataSize() const { return size_t(m_max); }
* @param index :: point to jump to. Must be 0 <= index < getDataSize().
*/
void MatrixWorkspaceMDIterator::jumpTo(size_t index) {
m_pos = uint64_t(index);
m_xIndex = m_pos % m_blockSize;
size_t newWI = m_beginWI + (m_pos / m_blockSize);
m_pos = static_cast<uint64_t>(index); // index into the unraveled workspace
const auto lower =
std::lower_bound(m_startIndices.begin(), m_startIndices.end(), index);
m_xIndex = m_pos - (*lower); // index into the Y[] array of the spectrum
size_t newWI = m_beginWI + std::distance(m_startIndices.begin(), lower);
calcWorkspacePos(newWI);
}

Expand Down Expand Up @@ -120,7 +128,7 @@ bool MatrixWorkspaceMDIterator::next() {
do {
m_pos++;
m_xIndex++;
if (m_xIndex >= m_blockSize) {
if (m_xIndex >= m_Y.size()) {
m_xIndex = 0;
this->calcWorkspacePos(m_workspaceIndex + 1);
}
Expand All @@ -133,7 +141,7 @@ bool MatrixWorkspaceMDIterator::next() {
// Go through every point;
m_pos++;
m_xIndex++;
if (m_xIndex >= m_blockSize) {
if (m_xIndex >= m_Y.size()) {
m_xIndex = 0;
this->calcWorkspacePos(m_workspaceIndex + 1);
}
Expand Down
41 changes: 40 additions & 1 deletion Framework/API/src/WorkspaceGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,48 @@ void WorkspaceGroup::print() const {
}
}

/**
* Returns an iterator pointing to the first element in the group.
*
* @return A non-const iterator pointing to the first workspace in this
* workspace group.
*/
std::vector<Workspace_sptr>::iterator WorkspaceGroup::begin() {
return m_workspaces.begin();
}

/**
* Returns a const iterator pointing to the first element in the group.
*
* @return A const iterator pointing to the first workspace in this
* workspace group.
*/
std::vector<Workspace_sptr>::const_iterator WorkspaceGroup::begin() const {
return m_workspaces.begin();
}

/**
* Returns an iterator pointing to the past-the-end element in the group.
*
* @return A non-const iterator pointing to the last workspace in this
* workspace group.
*/
std::vector<Workspace_sptr>::iterator WorkspaceGroup::end() {
return m_workspaces.end();
}

/** Returns a const iterator pointing to the past-the-end element in the group.
*
* @return A const iterator pointing to the last workspace in this
* workspace group.
*/
std::vector<Workspace_sptr>::const_iterator WorkspaceGroup::end() const {
return m_workspaces.end();
}

/**
* Remove a workspace pointed to by an index. The workspace remains in the ADS
*if it was there
* if it was there
*
* @param index :: Index of a workspace to delete.
*/
Expand Down
65 changes: 57 additions & 8 deletions Framework/API/test/MatrixWorkspaceMDIteratorTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ using namespace Mantid;
using namespace Mantid::API;
using namespace Mantid::Kernel;
using namespace Mantid::Geometry;
using namespace Mantid::HistogramData;

class MatrixWorkspaceMDIteratorTest : public CxxTest::TestSuite {
public:
Expand All @@ -23,12 +24,12 @@ class MatrixWorkspaceMDIteratorTest : public CxxTest::TestSuite {
ws->initialize(4, 6, 5);
NumericAxis *ax1 = new NumericAxis(4);
for (size_t wi = 0; wi < 4; wi++) {
ax1->setValue(wi, double(wi) * 2.0);
ax1->setValue(wi, static_cast<double>(wi) * 2.0);
for (size_t x = 0; x < 6; x++) {
ws->dataX(wi)[x] = double(x) * 2.0;
ws->dataX(wi)[x] = static_cast<double>(x) * 2.0;
if (x < 5) {
ws->dataY(wi)[x] = double(wi * 10 + x);
ws->dataE(wi)[x] = double((wi * 10 + x) * 2);
ws->dataY(wi)[x] = static_cast<double>(wi * 10 + x);
ws->dataE(wi)[x] = static_cast<double>((wi * 10 + x) * 2);
}
}
}
Expand Down Expand Up @@ -100,16 +101,17 @@ class MatrixWorkspaceMDIteratorTest : public CxxTest::TestSuite {

for (size_t i = 0; i < iterators.size(); i++) {
IMDIterator *it = iterators[i];
const double i_d = static_cast<double>(i);
// Only 5 elements per each iterator
TS_ASSERT_EQUALS(it->getDataSize(), 5);
TS_ASSERT_DELTA(it->getSignal(), double(i) * 10 + 0.0, 1e-5);
TS_ASSERT_DELTA(it->getSignal(), i_d * 10 + 0.0, 1e-5);
it->next();
TS_ASSERT_DELTA(it->getSignal(), double(i) * 10 + 1.0, 1e-5);
TS_ASSERT_DELTA(it->getError(), double(i) * 20 + 2.0, 1e-5);
TS_ASSERT_DELTA(it->getSignal(), i_d * 10 + 1.0, 1e-5);
TS_ASSERT_DELTA(it->getError(), i_d * 20 + 2.0, 1e-5);
// Coordinates at X index = 1
TS_ASSERT_DELTA(it->getCenter()[0], 3.0, 1e-5);
// And this coordinate is the spectrum number
TS_ASSERT_DELTA(it->getCenter()[1], double(i * 2), 1e-5);
TS_ASSERT_DELTA(it->getCenter()[1], i_d * 2, 1e-5);
TS_ASSERT(it->next());
TS_ASSERT(it->next());
TS_ASSERT(it->next());
Expand All @@ -128,6 +130,53 @@ class MatrixWorkspaceMDIteratorTest : public CxxTest::TestSuite {
}
delete it;
}

void testUnequalBins() {
boost::shared_ptr<MatrixWorkspace> ws = makeFakeWS();
// set the first spectrum to be different
ws->setHistogram(0, BinEdges({0, 1, 2}), Counts({10, 20}));

// quick checks to make sure things are returning the expected values
TS_ASSERT(!(ws->isCommonBins()));
TS_ASSERT_THROWS(ws->blocksize(), std::logic_error);
TS_ASSERT_EQUALS(ws->size(), 17);
// Split in 4 iterators
std::vector<IMDIterator *> iterators = ws->createIterators(4, nullptr);
TS_ASSERT_EQUALS(iterators.size(), 4);

for (size_t i = 0; i < iterators.size(); i++) {
IMDIterator *it = iterators[i];
const double i_d = static_cast<double>(i);
if (i == 0) {
// Only 5 elements per each iterator
TS_ASSERT_EQUALS(it->getDataSize(), 2);
TS_ASSERT_DELTA(it->getSignal(), 10.0, 1e-5);
it->next();
TS_ASSERT_DELTA(it->getSignal(), 20., 1e-5);
TS_ASSERT_DELTA(it->getError(), std::sqrt(20), 1e-5);
// Coordinates at X index = 1
TS_ASSERT_DELTA(it->getCenter()[0], 1.5, 1e-5);
// And this coordinate is the spectrum number
TS_ASSERT_DELTA(it->getCenter()[1], 0.0, 1e-5);
} else {
// Only 5 elements per each iterator
TS_ASSERT_EQUALS(it->getDataSize(), 5);
TS_ASSERT_DELTA(it->getSignal(), i_d * 10 + 0.0, 1e-5);
it->next();
TS_ASSERT_DELTA(it->getSignal(), i_d * 10 + 1.0, 1e-5);
TS_ASSERT_DELTA(it->getError(), i_d * 20 + 2.0, 1e-5);
// Coordinates at X index = 1
TS_ASSERT_DELTA(it->getCenter()[0], 3.0, 1e-5);
// And this coordinate is the spectrum number
TS_ASSERT_DELTA(it->getCenter()[1], i_d * 2, 1e-5);
TS_ASSERT(it->next()); // more elements in i != 0
TS_ASSERT(it->next());
TS_ASSERT(it->next());
}
TS_ASSERT(!it->next());
delete it;
}
}
};

#endif /* MANTID_API_MATRIXWORKSPACEMDITERATORTEST_H_ */
2 changes: 1 addition & 1 deletion Framework/Algorithms/inc/MantidAlgorithms/PhaseQuadMuon.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,4 @@ class DLLExport PhaseQuadMuon : public API::Algorithm {
} // namespace Algorithms
} // namespace Mantid

#endif /*MANTID_ALGORITHM_PHASEQUAD_H_*/
#endif /*MANTID_ALGORITHM_PHASEQUAD_H_*/
14 changes: 7 additions & 7 deletions Framework/Algorithms/src/CalMuonDetectorPhases.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,22 +202,22 @@ void CalMuonDetectorPhases::extractDetectorInfo(
double asym = paramTab->Double(0, 1);
double phase = paramTab->Double(2, 1);
// If asym<0, take the absolute value and add \pi to phase
// f(x) = A * sin( w * x + p) = -A * sin( w * x + p + PI)
// f(x) = A * cos( w * x + p) = -A * cos( w * x + p - PI)
if (asym < 0) {
asym = -asym;
phase = phase + M_PI;
phase = phase - M_PI;
}
// Now convert phases to interval [0, 2PI)
int factor = static_cast<int>(floor(phase / 2 / M_PI));
int factor = static_cast<int>(floor(phase / (2. * M_PI)));
if (factor) {
phase = phase - factor * 2 * M_PI;
phase = phase - factor * 2. * M_PI;
}
// Copy parameters to new row in results table
API::TableRow row = resultsTab->appendRow();
row << static_cast<int>(spectrumNumber) << asym << phase;
}

/** Creates the fitting function f(x) = A * sin( w*x + p) + B as string
/** Creates the fitting function f(x) = A * cos( w*x + p) + B as string
* Two modes:
* 1) Fixed frequency, no background - for main sequential fit
* 2) Varying frequency, flat background - for finding frequency from asymmetry
Expand All @@ -234,10 +234,10 @@ std::string CalMuonDetectorPhases::createFittingFunction(double freq,
ss << "name=UserFunction,";
if (fixFreq) {
// no background
ss << "Formula=A*sin(w*x+p),";
ss << "Formula=A*cos(w*x+p),";
} else {
// flat background
ss << "Formula=A*sin(w*x+p)+B,";
ss << "Formula=A*cos(w*x+p)+B,";
ss << "B=0.5,";
}
ss << "A=0.5,";
Expand Down
Loading

0 comments on commit 40aebb9

Please sign in to comment.