コード例 #1
0
/// calculate distance from source to sample or detector
double ModeratorTzero::CalculateL1(Mantid::API::MatrixWorkspace_sptr inputWS, size_t i){
  double L1(0);
  // Get detector position
  IDetector_const_sptr det;
  try
  {
    det = inputWS->getDetector(i);
  }
  catch (Exception::NotFoundError&)
  {
    return 0;
  }

  if( det->isMonitor() )
  {
    L1=m_instrument->getSource()->getDistance(*det);
  }
  else
  {
    IComponent_const_sptr sample = m_instrument->getSample();
    try
    {
      L1 = m_instrument->getSource()->getDistance(*sample);
    }
    catch (Exception::NotFoundError &)
    {
      g_log.error("Unable to calculate source-sample distance");
      throw Exception::InstrumentDefinitionError("Unable to calculate source-sample distance", inputWS->getTitle());
    }
  }
  return L1;
}
コード例 #2
0
/** Executes the algorithm
 *
 */
void SumNeighbours::exec()
{
  // Try and retrieve the optional properties
  SumX = getProperty("SumX");
  SumY = getProperty("SumY");


  // Get the input workspace
  Mantid::API::MatrixWorkspace_sptr inWS = getProperty("InputWorkspace");
  Mantid::Geometry::IDetector_const_sptr det = inWS->getDetector(0);
  // Check if grandparent is rectangular detector
  boost::shared_ptr<const Geometry::IComponent> parent = det->getParent()->getParent();
  boost::shared_ptr<const RectangularDetector> rect = boost::dynamic_pointer_cast<const RectangularDetector>(parent);
  
  Mantid::API::MatrixWorkspace_sptr outWS;

  IAlgorithm_sptr smooth = createChildAlgorithm("SmoothNeighbours");
  smooth->setProperty("InputWorkspace", inWS);
  if (rect)
  {
    smooth->setProperty("SumPixelsX",SumX);
    smooth->setProperty("SumPixelsY",SumY);
  }
  else
  {
    smooth->setProperty<std::string>("RadiusUnits","NumberOfPixels");
    smooth->setProperty("Radius",static_cast<double>(SumX*SumY*SumX*SumY));
    smooth->setProperty("NumberOfNeighbours",SumX*SumY*SumX*SumY*4);
    smooth->setProperty("SumNumberOfNeighbours",SumX*SumY);
  }
  smooth->executeAsChildAlg();
  // Get back the result
  outWS = smooth->getProperty("OutputWorkspace");
  //Cast to the matrixOutputWS and save it
  this->setProperty("OutputWorkspace", outWS);

}