Skip to content

Commit

Permalink
Refs #11747 MDhisto to MDevent for integration
Browse files Browse the repository at this point in the history
  • Loading branch information
VickieLynch committed May 13, 2015
1 parent 5b15be5 commit a6a8efc
Show file tree
Hide file tree
Showing 5 changed files with 622 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Code/Mantid/Framework/MDAlgorithms/CMakeLists.txt
Expand Up @@ -19,6 +19,7 @@ set ( SRC_FILES
src/ConvToMDHistoWS.cpp
src/ConvToMDSelector.cpp
src/ConvertCWPDMDToSpectra.cpp
src/ConvertMDHistoToMDEventWorkspace.cpp
src/ConvertMDHistoToMatrixWorkspace.cpp
src/ConvertSpiceDataToRealSpace.cpp
src/ConvertToDetectorFaceMD.cpp
Expand Down Expand Up @@ -136,6 +137,7 @@ set ( INC_FILES
inc/MantidMDAlgorithms/CompareMDWorkspaces.h
inc/MantidMDAlgorithms/ConvToMDBase.h
inc/MantidMDAlgorithms/ConvertCWPDMDToSpectra.h
inc/MantidMDAlgorithms/ConvertMDHistoToMDEventWorkspace.h
inc/MantidMDAlgorithms/ConvertMDHistoToMatrixWorkspace.h
inc/MantidMDAlgorithms/ConvertSpiceDataToRealSpace.h
inc/MantidMDAlgorithms/ConvertToDetectorFaceMD.h
Expand Down Expand Up @@ -253,6 +255,7 @@ set ( TEST_FILES
CompareMDWorkspacesTest.h
ConvertCWPDMDToSpectraTest.h
ConvertEventsToMDTest.h
ConvertMDHistoToMDEventWorkspaceTest.h
ConvertMDHistoToMatrixWorkspaceTest.h
ConvertSpiceDataToRealSpaceTest.h
ConvertToDetectorFaceMDTest.h
Expand Down
@@ -0,0 +1,71 @@
#ifndef MANTID_MDALGORITHMS_ConvertMDHistoToMDEventWorkspace_H_
#define MANTID_MDALGORITHMS_ConvertMDHistoToMDEventWorkspace_H_

#include "MantidAPI/Algorithm.h"
#include "MantidDataObjects/MDEventWorkspace.h"
#include <deque>

namespace Mantid {
namespace MDAlgorithms {

/** ConvertMDHistoToMDEventWorkspace : Loads a file containing dimensionality and data for
an MDEventWorkspace. Handles either full mdevents for mdleanevents as input
data types.
@date 2012-07-11
Copyright &copy; 2012 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge
National Laboratory & European Spallation Source
This file is part of Mantid.
Mantid is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
Mantid is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
File change history is stored at: <https://github.com/mantidproject/mantid>
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class DLLExport ConvertMDHistoToMDEventWorkspace : public API::Algorithm {
public:
ConvertMDHistoToMDEventWorkspace();
virtual ~ConvertMDHistoToMDEventWorkspace();

virtual const std::string name() const;
/// Summary of algorithms purpose
virtual const std::string summary() const {
return "Reads an ASCII file containing MDEvent data and constructs an "
"MDEventWorkspace.";
}

virtual int version() const;
virtual const std::string category() const;

private:

/// Actual number of dimensions specified
size_t m_nDimensions;
/// Actual number of md events provided.
size_t m_nDataObjects;
/// call back to add event data
template <typename MDE, size_t nd>
void addEventsData(typename DataObjects::MDEventWorkspace<MDE, nd>::sptr outWs);
DataObjects::MDHistoWorkspace_sptr ws;

void init();
void exec();
};

} // namespace MDAlgorithms
} // namespace Mantid

#endif /* MANTID_MDALGORITHMS_ConvertMDHistoToMDEventWorkspace_H_ */
@@ -0,0 +1,134 @@
#include "MantidMDAlgorithms/ConvertMDHistoToMDEventWorkspace.h"

#include <iostream>
#include <fstream>

#include "MantidDataObjects/MDEventFactory.h"
#include "MantidDataObjects/MDEventInserter.h"
#include "MantidGeometry/MDGeometry/MDHistoDimension.h"

#include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/split.hpp>



namespace Mantid {
namespace MDAlgorithms {

using namespace API;
using namespace DataObjects;
using namespace Geometry;
using namespace Kernel;
// Register the algorithm into the AlgorithmFactory
DECLARE_ALGORITHM(ConvertMDHistoToMDEventWorkspace)

//----------------------------------------------------------------------------------------------
/** Constructor
*/
ConvertMDHistoToMDEventWorkspace::ConvertMDHistoToMDEventWorkspace() {}

//----------------------------------------------------------------------------------------------
/** Destructor
*/
ConvertMDHistoToMDEventWorkspace::~ConvertMDHistoToMDEventWorkspace() {}

//----------------------------------------------------------------------------------------------
/// Algorithm's name for identification. @see Algorithm::name
const std::string ConvertMDHistoToMDEventWorkspace::name() const {
return "ConvertMDHistoToMDEventWorkspace";
}

/// Algorithm's version for identification. @see Algorithm::version
int ConvertMDHistoToMDEventWorkspace::version() const { return 1; }

/// Algorithm's category for identification. @see Algorithm::category
const std::string ConvertMDHistoToMDEventWorkspace::category() const {
return "MDAlgorithms";
}

//----------------------------------------------------------------------------------------------

//----------------------------------------------------------------------------------------------
/** Initialize the algorithm's properties.
*/
void ConvertMDHistoToMDEventWorkspace::init() {
declareProperty(new WorkspaceProperty<API::IMDHistoWorkspace>(
"InputWorkspace", "", Direction::Input),
"An input IMDHistoWorkspace.");
declareProperty(new WorkspaceProperty<IMDEventWorkspace>(
"OutputWorkspace", "", Direction::Output),
"An output workspace.");
}

/**
Extracts mdevent information from the histo data and directs the creation of new
DataObjects on the workspace.
@param ws: Workspace to add the events to.
*/
template <typename MDE, size_t nd>
void ConvertMDHistoToMDEventWorkspace::addEventsData(
typename MDEventWorkspace<MDE, nd>::sptr outWs) {
/// Creates a new instance of the MDEventInserter.
MDEventInserter<typename MDEventWorkspace<MDE, nd>::sptr> inserter(outWs);
std::vector<Mantid::coord_t> centers(nd);

for (size_t i = 0; i < m_nDataObjects; ++i) {
float signal = static_cast<float>(ws->getSignalAt(i));
float error = static_cast<float>(ws->getErrorAt(i));
uint16_t run_no = 0;
int32_t detector_no = 0;
VMD boxCenter = ws->getCenter(i);
for (size_t j = 0; j < m_nDimensions; ++j) {
centers[j] = static_cast<float>(boxCenter[j]);
}
// Actually add the mdevent.
inserter.insertMDEvent(signal, error * error, run_no, detector_no,
centers.data());
}
}

//----------------------------------------------------------------------------------------------
/** Execute the algorithm.
*/
void ConvertMDHistoToMDEventWorkspace::exec() {
IMDHistoWorkspace_sptr inWS = getProperty("InputWorkspace");

ws = boost::dynamic_pointer_cast<MDHistoWorkspace>(inWS);
if (!ws)
throw std::runtime_error("InputWorkspace is not a MDHistoWorkspace");

// Calculate the dimensionality
m_nDimensions = ws->getNumDims();
// Calculate the actual number of columns in the MDEvent data.
uint64_t numPoints = ws->getNPoints();
m_nDataObjects = static_cast<size_t>(numPoints);

// Create a target output workspace.
IMDEventWorkspace_sptr outWs = MDEventFactory::CreateMDWorkspace(
m_nDimensions, "MDLeanEvent");
if (ws->getNumExperimentInfo() > 0) {
ExperimentInfo_sptr ei = ws->getExperimentInfo(0);
outWs->addExperimentInfo(ei);
}
outWs->setCoordinateSystem(ws->getSpecialCoordinateSystem());
// Extract Dimensions and add to the output workspace.
for (size_t i = 0; i < m_nDimensions; ++i) {
IMDDimension_const_sptr dim = ws->getDimension(i);
std::string id = dim->getDimensionId();
std::string name = dim->getName();
std::string units = dim->getUnits();
size_t nbins = dim->getNBins();

outWs->addDimension(MDHistoDimension_sptr(new MDHistoDimension(
id, name, units, dim->getMinimum(),
dim->getMaximum(), nbins)));
}

CALL_MDEVENT_FUNCTION(this->addEventsData, outWs)

// set output
this->setProperty("OutputWorkspace", outWs);
}

} // namespace Mantid
} // namespace MDAlgorithms
Expand Up @@ -737,7 +737,7 @@ IntegratePeaksMD2::checkOverlap(int i,
if (pos1.distance(pos2) < radius) {
g_log.warning() << " Warning: Peak integration spheres for peaks " << i
<< " and " << j << " overlap. Distance between peaks is "
<< pos1.distance(pos2) << std::endl;
<< pos1.distance(pos2) <<" "<<p1.getHKL()<<" "<<p2.getHKL()<< std::endl;
}
}
}
Expand Down

0 comments on commit a6a8efc

Please sign in to comment.