Newer
Older
Dickon Champion
committed
//----------------------------------------------------------------------
// Includes
//----------------------------------------------------------------------
#include "MantidKernel/VectorHelper.h"
using namespace Mantid::API;
using namespace Mantid::Kernel;
namespace Mantid
{
namespace Algorithms
{
Russell Taylor
committed
// 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)
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>());
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
Steve Williams
committed
if (rhsE != 0)
std::transform(lhsE.begin(),lhsE.end(),EOut.begin(),std::bind2nd(VectorHelper::SumGaussError<double>(),rhsE));
else
EOut = lhsE;
}
Russell Taylor
committed
bool Plus::checkCompatibility(const API::MatrixWorkspace_const_sptr lhs,const API::MatrixWorkspace_const_sptr rhs) const
Russell Taylor
committed
{
Russell Taylor
committed
if ( lhs->size() > 1 && rhs->size() > 1 )
Russell Taylor
committed
{
Russell Taylor
committed
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;
}
Russell Taylor
committed
}
Russell Taylor
committed
Russell Taylor
committed
return BinaryOperation::checkCompatibility(lhs,rhs);
}
Steve Williams
committed
/** 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
*/
Sofia Antony
committed
void Plus::operateOnSample(const Sample& lhs, const Sample& rhs, Sample& ans) const
Steve Williams
committed
{
Sofia Antony
committed
ans.setProtonCharge( lhs.getProtonCharge() + rhs.getProtonCharge() );
Steve Williams
committed
}