Esempio n. 1
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);

}
Esempio n. 2
0
void InstrumentWindowPickTab::updateSelectionInfo(int detid)
{
  if (m_instrWindow->blocked()) 
  {
    m_selectionInfoDisplay->clear();
    return;
  }
  if (detid >= 0)
  {
    InstrumentActor* instrActor = m_instrWindow->getInstrumentActor();
    Mantid::Geometry::IDetector_const_sptr det = instrActor->getInstrument()->getDetector(detid);
    QString text = "Selected detector: " + QString::fromStdString(det->getName()) + "\n";
    text += "Detector ID: " + QString::number(detid) + '\n';
    QString wsIndex;
    try {
      wsIndex = QString::number(instrActor->getWorkspaceIndex(detid));
      updatePlot(detid); // Update the plot if the detector links to some data
    } catch (Mantid::Kernel::Exception::NotFoundError) {
      // Detector doesn't have a workspace index relating to it
      wsIndex = "None";
      m_plot->clearCurve(); // Clear the plot window
      m_plot->replot();
    }
    text += "Workspace index: " + wsIndex + '\n';
    Mantid::Kernel::V3D pos = det->getPos();
    text += "xyz: " + QString::number(pos.X()) + "," + QString::number(pos.Y()) + "," + QString::number(pos.Z())  + '\n';
    double r,t,p;
    pos.getSpherical(r,t,p);
    text += "rtp: " + QString::number(r) + "," + QString::number(t) + "," + QString::number(p)  + '\n';
    Mantid::Geometry::ICompAssembly_const_sptr parent = boost::dynamic_pointer_cast<const Mantid::Geometry::ICompAssembly>(det->getParent());
    if (parent)
    {
      QString textpath;
      while (parent)
      {
        textpath="/"+QString::fromStdString(parent->getName())+textpath;
        parent=boost::dynamic_pointer_cast<const Mantid::Geometry::ICompAssembly>(parent->getParent());
      }
      text += "Component path:" +textpath+"/"+ QString::fromStdString(det->getName()) +'\n';
    }
    const double integrated = instrActor->getIntegratedCounts(detid);
    const QString counts = integrated == -1.0 ? "N/A" : QString::number(integrated);
    text += "Counts: " + counts + '\n';
    m_selectionInfoDisplay->setText(text);
  }
  else
  {
    m_selectionInfoDisplay->clear();
    m_plot->clearCurve(); // Clear the plot window
    m_plot->replot();
  }
}
/**
 * Update the info window with information for a selected detector.
 * @param detid :: ID of the selected detector.
 */
void InstrumentWindowPickTab::updateSelectionInfo(int detid)
{
    if (m_freezePlot)
    {   // freeze the plot for one update
        m_freezePlot = false;
        return;
    }
    if (m_instrWindow->blocked())
    {
        m_selectionInfoDisplay->clear();
        return;
    }
    if (detid >= 0)
    {
        InstrumentActor* instrActor = m_instrWindow->getInstrumentActor();
        Mantid::Geometry::IDetector_const_sptr det = instrActor->getInstrument()->getDetector(detid);
        QString text = "Selected detector: " + QString::fromStdString(det->getName()) + "\n";
        text += "Detector ID: " + QString::number(detid) + '\n';
        QString wsIndex;
        try {
            wsIndex = QString::number(instrActor->getWorkspaceIndex(detid));
            updatePlot(detid); // Update the plot if the detector links to some data
        } catch (Mantid::Kernel::Exception::NotFoundError &) {
            // Detector doesn't have a workspace index relating to it
            wsIndex = "None";
            m_plot->clearCurve(); // Clear the plot window
            m_plot->replot();
        }
        text += "Workspace index: " + wsIndex + '\n';
        Mantid::Kernel::V3D pos = det->getPos();
        text += "xyz: " + QString::number(pos.X()) + "," + QString::number(pos.Y()) + "," + QString::number(pos.Z())  + '\n';
        double r,t,p;
        pos.getSpherical(r,t,p);
        text += "rtp: " + QString::number(r) + "," + QString::number(t) + "," + QString::number(p)  + '\n';
        Mantid::Geometry::ICompAssembly_const_sptr parent = boost::dynamic_pointer_cast<const Mantid::Geometry::ICompAssembly>(det->getParent());
        if (parent)
        {
            QString textpath;
            while (parent)
            {
                textpath="/"+QString::fromStdString(parent->getName())+textpath;
                parent=boost::dynamic_pointer_cast<const Mantid::Geometry::ICompAssembly>(parent->getParent());
            }
            text += "Component path:" +textpath+"/"+ QString::fromStdString(det->getName()) +'\n';
        }
        const double integrated = instrActor->getIntegratedCounts(detid);
        const QString counts = integrated == -1.0 ? "N/A" : QString::number(integrated);
        text += "Counts: " + counts + '\n';
        QString xUnits;
        if (m_selectionType > SingleDetectorSelection && !m_plotSum)
        {
            switch(m_tubeXUnits)
            {
            case DETECTOR_ID:
                xUnits = "Detector ID";
                break;
            case LENGTH:
                xUnits = "Length";
                break;
            case PHI:
                xUnits = "Phi";
                break;
            default:
                xUnits = "Detector ID";
            }
        }
        else
        {
            xUnits = QString::fromStdString(instrActor->getWorkspace()->getAxis(0)->unit()->caption());
            //xUnits = "Time of flight";
        }
        text += "X units: " + xUnits + '\n';
        m_selectionInfoDisplay->setText(text);
    }
    else
    {
        m_selectionInfoDisplay->clear();
        m_plot->clearCurve(); // Clear the plot window
        m_plot->replot();
    }
}