Newer
Older
Janik Zikovsky
committed
#include "MantidAlgorithms/CreatePeaksWorkspace.h"
#include "MantidKernel/System.h"
#include "MantidDataObjects/PeaksWorkspace.h"
#include "MantidAPI/MatrixWorkspace.h"
namespace Mantid {
namespace Algorithms {
Janik Zikovsky
committed
// Register the algorithm into the AlgorithmFactory
DECLARE_ALGORITHM(CreatePeaksWorkspace)
Janik Zikovsky
committed
using namespace Mantid::Kernel;
using namespace Mantid::API;
using namespace Mantid::DataObjects;
Janik Zikovsky
committed
//----------------------------------------------------------------------------------------------
/** Initialize the algorithm's properties.
*/
void CreatePeaksWorkspace::init() {
declareProperty(
make_unique<WorkspaceProperty<MatrixWorkspace>>(
"InstrumentWorkspace", "", Direction::Input, PropertyMode::Optional),
"An optional input workspace containing the default instrument for peaks "
"in this workspace.");
declareProperty("NumberOfPeaks", 1,
"Number of dummy peaks to initially create.");
declareProperty(make_unique<WorkspaceProperty<PeaksWorkspace>>(
"OutputWorkspace", "", Direction::Output),
Janik Zikovsky
committed
//----------------------------------------------------------------------------------------------
/** Execute the algorithm.
*/
void CreatePeaksWorkspace::exec() {
MatrixWorkspace_sptr instWS = getProperty("InstrumentWorkspace");
Janik Zikovsky
committed
auto out = boost::make_shared<PeaksWorkspace>();
setProperty("OutputWorkspace", out);
int NumberOfPeaks = getProperty("NumberOfPeaks");
if (instWS) {
Progress progress(this, 0, 1, NumberOfPeaks);
out->setInstrument(instWS->getInstrument());
// Create some default peaks
for (int i = 0; i < NumberOfPeaks; i++) {
out->addPeak(Peak(out->getInstrument(),
out->getInstrument()->getDetectorIDs(true)[0], 1.0));
Janik Zikovsky
committed
}
}
Janik Zikovsky
committed
} // namespace Mantid
} // namespace Algorithms