Skip to content
Snippets Groups Projects
Plus.cpp 2.51 KiB
Newer Older
//----------------------------------------------------------------------
// Includes
//----------------------------------------------------------------------
Nick Draper's avatar
Nick Draper committed
#include "MantidAlgorithms/Plus.h"
#include "MantidKernel/VectorHelper.h"
Nick Draper's avatar
Nick Draper committed

using namespace Mantid::API;
using namespace Mantid::Kernel;

namespace Mantid
{
  namespace Algorithms
  {
    // Register the class into the algorithm factory
    DECLARE_ALGORITHM(Plus)

    void Plus::performBinaryOperation(const MantidVec& lhsX, const MantidVec& lhsY, const MantidVec& lhsE,
                                       const MantidVec& rhsY, const MantidVec& rhsE, MantidVec& YOut, MantidVec& EOut)
Nick Draper's avatar
Nick Draper committed
    {
      std::transform(lhsY.begin(),lhsY.end(),rhsY.begin(),YOut.begin(),std::plus<double>());
      std::transform(lhsE.begin(),lhsE.end(),rhsE.begin(),EOut.begin(),VectorHelper::SumGaussError<double>());
Nick Draper's avatar
Nick Draper committed
    }

    void Plus::performBinaryOperation(const MantidVec& lhsX, const MantidVec& lhsY, const MantidVec& lhsE,
                                       const double& rhsY, const double& rhsE, MantidVec& YOut, MantidVec& EOut)
    {
      std::transform(lhsY.begin(),lhsY.end(),YOut.begin(),std::bind2nd(std::plus<double>(),rhsY));
      // Only do E if non-zero, otherwise just copy
        std::transform(lhsE.begin(),lhsE.end(),EOut.begin(),std::bind2nd(VectorHelper::SumGaussError<double>(),rhsE));
    bool Plus::checkCompatibility(const API::MatrixWorkspace_const_sptr lhs,const API::MatrixWorkspace_const_sptr rhs) const
      if ( lhs->size() > 1 && rhs->size() > 1 )
        if ( lhs->YUnit() != rhs->YUnit() )
        {
          g_log.error("The two workspaces are not compatible because they have different units for the data (Y).");
          return false;
        }
        if ( lhs->isDistribution() != rhs->isDistribution() )
        {
          g_log.error("The two workspaces are not compatible because one is flagged as a distribution.");
          return false;
        }
      return BinaryOperation::checkCompatibility(lhs,rhs);
    }

    /** Adds the integrated proton currents, proton charges, of the two input
    *  workspaces together
    *  @param lhs one of the workspace samples to be summed
    *  @param rhs the other workspace sample to be summed
    *  @param ans the sample in the output workspace
    */
    void Plus::operateOnSample(const Sample& lhs, const Sample& rhs, Sample& ans) const
      ans.setProtonCharge( lhs.getProtonCharge() + rhs.getProtonCharge() );
Nick Draper's avatar
Nick Draper committed
  }
}