Skip to content

Commit

Permalink
Refs #12585 create new algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
VickieLynch committed Jun 24, 2016
1 parent 498bb99 commit a91a4d7
Show file tree
Hide file tree
Showing 3 changed files with 209 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Framework/MDAlgorithms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ set ( SRC_FILES
src/IntegrateMDHistoWorkspace.cpp
src/IntegratePeaksMD.cpp
src/IntegratePeaksMD2.cpp
src/IntegratePeaksMDHisto.cpp
src/IntegratePeaksCWSD.cpp
src/InvalidParameter.cpp
src/InvalidParameterParser.cpp
Expand Down Expand Up @@ -185,6 +186,7 @@ set ( INC_FILES
inc/MantidMDAlgorithms/IntegrateMDHistoWorkspace.h
inc/MantidMDAlgorithms/IntegratePeaksMD.h
inc/MantidMDAlgorithms/IntegratePeaksMD2.h
inc/MantidMDAlgorithms/IntegratePeaksMDHisto.h
inc/MantidMDAlgorithms/IntegratePeaksCWSD.h
inc/MantidMDAlgorithms/InvalidParameter.h
inc/MantidMDAlgorithms/InvalidParameterParser.h
Expand Down Expand Up @@ -312,6 +314,7 @@ set ( TEST_FILES
IntegrateFluxTest.h
IntegrateMDHistoWorkspaceTest.h
IntegratePeaksMD2Test.h
IntegratePeaksMDHistoTest.h
IntegratePeaksMDTest.h
IntegratePeaksCWSDTest.h
InvalidParameterParserTest.h
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#ifndef MANTID_MDALGORITHMS_INTEGRATEPEAKSMDHISTO_H_
#define MANTID_MDALGORITHMS_INTEGRATEPEAKSMHISTO_H_

#include "MantidAPI/Algorithm.h"
#include "MantidAPI/IMDHistoWorkspace_fwd.h"
#include "MantidDataObjects/PeaksWorkspace.h"
#include "MantidKernel/System.h"
#include "MantidDataObjects/MDHistoWorkspace.h"

namespace Mantid {
namespace MDAlgorithms {

/** Integrate single-crystal peaks in reciprocal-space.
*
* @author Vickie Lynch
* @date 2016-06-23
*/
class DLLExport IntegratePeaksMDHisto : public API::Algorithm {
public:
/// Algorithm's name for identification
const std::string name() const override { return "IntegratePeaksMD"; };
/// Summary of algorithms purpose
const std::string summary() const override {
return "Integrate single-crystal peaks in reciprocal space, for "
"MDHistoWorkspaces.";
}

/// Algorithm's version for identification
int version() const override { return 1; };
/// Algorithm's category for identification
const std::string category() const override { return "MDAlgorithms\\Peaks"; }

private:
/// Initialise the properties
void init() override;
/// Run the algorithm
void exec() override;

};

} // namespace Mantid
} // namespace DataObjects

#endif /* MANTID_MDALGORITHMS_INTEGRATEPEAKSMDHISTO_H_ */
162 changes: 162 additions & 0 deletions Framework/MDAlgorithms/src/IntegratePeaksMDHisto.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
#include "MantidMDAlgorithms/IntegratePeaksMDHisto.h"

#include "MantidAPI/CommonBinsValidator.h"
#include "MantidAPI/InstrumentValidator.h"
#include "MantidAPI/WorkspaceUnitValidator.h"
#include "MantidDataObjects/EventWorkspace.h"
#include "MantidDataObjects/MDEventWorkspace.h"
#include "MantidDataObjects/MDHistoWorkspace.h"
#include "MantidGeometry/Instrument.h"
#include "MantidKernel/CompositeValidator.h"
#include "MantidKernel/TimeSeriesProperty.h"
#include "MantidKernel/VectorHelper.h"

namespace Mantid {
namespace MDAlgorithms {

using Mantid::Kernel::Direction;
using Mantid::API::WorkspaceProperty;
using namespace Mantid::DataObjects;
using namespace Mantid::API;
using namespace Mantid::Kernel;


// Register the algorithm into the AlgorithmFactory
DECLARE_ALGORITHM(IntegratePeaksMDHisto)

//----------------------------------------------------------------------------------------------
/**
* Constructor
*/
IntegratePeaksMDHisto::IntegratePeaksMDHisto()
: m_normWS(), m_inputWS(), m_hmin(0.0f), m_hmax(0.0f), m_kmin(0.0f),
m_kmax(0.0f), m_lmin(0.0f), m_lmax(0.0f), m_hIntegrated(true),
m_kIntegrated(true), m_lIntegrated(true), m_rubw(3, 3), m_kiMin(0.0),
m_kiMax(EMPTY_DBL()), m_hIdx(-1), m_kIdx(-1), m_lIdx(-1), m_hX(), m_kX(),
m_lX(), m_samplePos(), m_beamDir() {}


//----------------------------------------------------------------------------------------------
/**
* Initialize the algorithm's properties.
*/
void IntegratePeaksMDHisto::init() {
declareProperty(make_unique<WorkspaceProperty<IMDEventWorkspace>>(
"InputWorkspace", "", Direction::Input),
"An input Sample MDEventWorkspace in HKL.");

auto fluxValidator = boost::make_shared<CompositeValidator>();
fluxValidator->add<WorkspaceUnitValidator>("Momentum");
fluxValidator->add<InstrumentValidator>();
fluxValidator->add<CommonBinsValidator>();
auto solidAngleValidator = fluxValidator->clone();

declareProperty(make_unique<WorkspaceProperty<>>(
"FluxWorkspace", "", Direction::Input, fluxValidator),
"An input workspace containing momentum dependent flux.");
declareProperty(make_unique<WorkspaceProperty<>>("SolidAngleWorkspace", "",
Direction::Input,
solidAngleValidator),
"An input workspace containing momentum integrated vanadium "
"(a measure of the solid angle).");

declareProperty(make_unique<WorkspaceProperty<Workspace>>(
"OutputWorkspace", "", Direction::Output),
"A name for the output data MDHistoWorkspace.");
declareProperty(make_unique<WorkspaceProperty<Workspace>>(
"OutputNormalizationWorkspace", "", Direction::Output),
"A name for the output normalization MDHistoWorkspace.");
declareProperty(make_unique<WorkspaceProperty<PeaksWorkspace>>(
"PeaksWorkspace", "", Direction::Input),
"A PeaksWorkspace containing the peaks to integrate.");

declareProperty(
make_unique<WorkspaceProperty<PeaksWorkspace>>("OutputWorkspace", "",
Direction::Output),
"The output PeaksWorkspace will be a copy of the input PeaksWorkspace "
"with the peaks' integrated intensities.");
}

//----------------------------------------------------------------------------------------------
/**
* Execute the algorithm.
*/
void IntegratePeaksMDHisto::exec() {
/// Peak workspace to integrate
Mantid::DataObjects::PeaksWorkspace_sptr inPeakWS =
getProperty("PeaksWorkspace");

/// Output peaks workspace, create if needed
Mantid::DataObjects::PeaksWorkspace_sptr peakWS =
getProperty("OutputWorkspace");
if (peakWS != inPeakWS)
peakWS = inPeakWS->clone();

API::MatrixWorkspace_const_sptr integrFlux = getProperty("FluxWorkspace");
integrFlux->getXMinMax(m_kiMin, m_kiMax);
API::MatrixWorkspace_const_sptr solidAngleWS =
getProperty("SolidAngleWorkspace");

m_inputWS = getProperty("InputWorkspace");
if (inputEnergyMode() != "Elastic") {
throw std::invalid_argument("Invalid energy transfer mode. Algorithm "
"currently only supports elastic data.");
}
// Min/max dimension values
const auto hdim(m_inputWS->getDimension(0)), kdim(m_inputWS->getDimension(1)),
ldim(m_inputWS->getDimension(2));
m_hmin = hdim->getMinimum();
m_kmin = kdim->getMinimum();
m_lmin = ldim->getMinimum();
m_hmax = hdim->getMaximum();
m_kmax = kdim->getMaximum();
m_lmax = ldim->getMaximum();

const auto &exptInfoZero = *(m_inputWS->getExperimentInfo(0));
auto source = exptInfoZero.getInstrument()->getSource();
auto sample = exptInfoZero.getInstrument()->getSample();
if (source == nullptr || sample == nullptr) {
throw Kernel::Exception::InstrumentDefinitionError(
"Instrument not sufficiently defined: failed to get source and/or "
"sample");
}
m_samplePos = sample->getPos();
m_beamDir = m_samplePos - source->getPos();
m_beamDir.normalize();
}


auto prog = make_unique<API::Progress>(this, 0.3, 1.0, ndets);
PARALLEL_FOR1(integrPeaks)
for (int64_t i = 0; i < npeaks; i++) {
PARALLEL_START_INTERUPT_REGION

const auto peak = peaks[i];
int h = int(p.getH() + 0.5);
int k = int(p.getK() + 0.5);
int l = int(p.getL() + 0.5);
MDNormSCD(InputWorkspace = 'MDdata';
AlignedDim0='[H,0,0],'+str(H-0.5)+','+str(H+0.5)+',201';
AlignedDim1='[0,K,0],'+str(K-0.5)+','+str(K+0.5)+',201';
AlignedDim2='[0,0,L],'+str(L-0.5)+','+str(L+0.5)+',201';
FluxWorkspace = flux;
SolidAngleWorkspace = sa;
OutputWorkspace = 'mdout'+str(run)+'_'+str(i);
OutputNormalizationWorkspace = 'mdnorm'+str(run)+'_'+str(i))

PARALLEL_CRITICAL(updateMD) {
signal += m_normWS->getSignalAt(linIndex);
m_normWS->setSignalAt(linIndex, signal);
}
}
prog->report();

PARALLEL_END_INTERUPT_REGION
}
PARALLEL_CHECK_INTERUPT_REGION
}



} // namespace MDAlgorithms
} // namespace Mantid

0 comments on commit a91a4d7

Please sign in to comment.