Skip to content
Snippets Groups Projects
HFIRSANSNormalise.cpp 2.26 KiB
Newer Older
//----------------------------------------------------------------------
// Includes
//----------------------------------------------------------------------
#include "MantidWorkflowAlgorithms/HFIRSANSNormalise.h"
#include "MantidAPI/MatrixWorkspace.h"
#include "MantidKernel/ListValidator.h"

#include <boost/algorithm/string.hpp>
#include "Poco/NumberFormatter.h"
namespace Mantid {
namespace WorkflowAlgorithms {

using namespace Kernel;
using namespace API;

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

void HFIRSANSNormalise::init() {
  declareProperty(
      new WorkspaceProperty<>("InputWorkspace", "", Direction::Input),
      "Workspace to be corrected");
  std::vector<std::string> normOptions{"Monitor", "Timer"};
  this->declareProperty("NormalisationType", "Monitor",
                        boost::make_shared<StringListValidator>(normOptions),
                        "Type of Normalisation to use");
  declareProperty(
      new WorkspaceProperty<>("OutputWorkspace", "", Direction::Output),
      "Corrected workspace");
  declareProperty("OutputMessage", "", Direction::Output);
void HFIRSANSNormalise::exec() {
  MatrixWorkspace_sptr inputWS = getProperty("InputWorkspace");
  MatrixWorkspace_sptr outputWS = getProperty("OutputWorkspace");
  std::string normalisation = getProperty("NormalisationType");

  // Get the monitor or timer
  boost::algorithm::to_lower(normalisation);
  double norm_count =
      inputWS->run().getPropertyValueAsType<double>(normalisation);
  if (boost::iequals(normalisation, "monitor")) {
    factor = 1.0e8 / norm_count;
    factor = 1.0 / norm_count;
  IAlgorithm_sptr scaleAlg = createChildAlgorithm("Scale");
  scaleAlg->setProperty("InputWorkspace", inputWS);
  scaleAlg->setProperty("OutputWorkspace", outputWS);
  scaleAlg->setProperty("Factor", factor);
  scaleAlg->setProperty("Operation", "Multiply");
  scaleAlg->executeAsChildAlg();
  MatrixWorkspace_sptr scaledWS = scaleAlg->getProperty("OutputWorkspace");

  setProperty("OutputWorkspace", scaledWS);
  setProperty("OutputMessage", "Normalisation by " + normalisation + ": " +
                                   Poco::NumberFormatter::format(norm_count));
}

} // namespace WorkflowAlgorithms
} // namespace Mantid