Newer
Older
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
// NScD Oak Ridge National Laboratory, European Spallation Source,
// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
// SPDX - License - Identifier: GPL - 3.0 +
Janik Zikovsky
committed
#include "MantidAlgorithms/CreatePeaksWorkspace.h"
#include "MantidAPI/IMDEventWorkspace.h"
Janik Zikovsky
committed
#include "MantidAPI/MatrixWorkspace.h"
#include "MantidAPI/Run.h"
#include "MantidDataObjects/PeaksWorkspace.h"
#include "MantidGeometry/Instrument/Goniometer.h"
#include "MantidKernel/System.h"
Janik Zikovsky
committed
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(
std::make_unique<WorkspaceProperty<Workspace>>(
"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(std::make_unique<WorkspaceProperty<PeaksWorkspace>>(
"OutputWorkspace", "", Direction::Output),
Janik Zikovsky
committed
/** Execute the algorithm.
*/
void CreatePeaksWorkspace::exec() {
Workspace_sptr instWS = this->getProperty("InstrumentWorkspace");
MultipleExperimentInfos_sptr instMDWS =
std::dynamic_pointer_cast<MultipleExperimentInfos>(instWS);
ExperimentInfo_sptr ei;
Janik Zikovsky
committed
auto out = std::make_shared<PeaksWorkspace>();
setProperty("OutputWorkspace", out);
int NumberOfPeaks = getProperty("NumberOfPeaks");
if (instMDWS != nullptr) {
if (instMDWS->getNumExperimentInfo() > 0) {
out->setInstrument(instMDWS->getExperimentInfo(0)->getInstrument());
out->mutableRun().setGoniometer(
instMDWS->getExperimentInfo(0)->run().getGoniometer().getR(), false);
} else {
throw std::invalid_argument("InstrumentWorkspace has no ExperimentInfo");
}
} else {
ei = std::dynamic_pointer_cast<ExperimentInfo>(instWS);
if (ei) {
out->setInstrument(ei->getInstrument());
out->mutableRun().setGoniometer(ei->run().getGoniometer().getR(), false);
}
}
if (instMDWS || ei) {
Progress progress(this, 0.0, 1.0, NumberOfPeaks);
// 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 Algorithms