/**
   * Redraw the raw input plot
   */
  void IndirectDiagnostics::slicePlotRaw()
  {
    QString filename = m_uiForm.dsInputFiles->getFirstFilename();

    // Only update if we have a different file
    if(filename == m_lastDiagFilename)
      return;

    m_lastDiagFilename = filename;

    disconnect(m_dblManager, SIGNAL(valueChanged(QtProperty*, double)), this, SLOT(updatePreviewPlot()));
    disconnect(m_blnManager, SIGNAL(valueChanged(QtProperty*, bool)), this, SLOT(updatePreviewPlot()));

    setDefaultInstDetails();

    if ( m_uiForm.dsInputFiles->isValid() )
    {
      QFileInfo fi(filename);
      QString wsname = fi.baseName();

      int specMin = static_cast<int>(m_dblManager->value(m_properties["SpecMin"]));
      int specMax = static_cast<int>(m_dblManager->value(m_properties["SpecMax"]));

      if(!loadFile(filename, wsname, specMin, specMax))
      {
        emit showMessageBox("Unable to load file.\nCheck whether your file exists and matches the selected instrument in the EnergyTransfer tab.");
        return;
      }

      Mantid::API::MatrixWorkspace_sptr input = boost::dynamic_pointer_cast<Mantid::API::MatrixWorkspace>(
          Mantid::API::AnalysisDataService::Instance().retrieve(wsname.toStdString()));

      const Mantid::MantidVec & dataX = input->readX(0);
      std::pair<double, double> range(dataX.front(), dataX.back());

      plotMiniPlot(input, 0, "SlicePlot");
      setXAxisToCurve("SlicePlot", "SlicePlot");

      setPlotRange("SlicePeak", m_properties["PeakStart"], m_properties["PeakEnd"], range);
      setPlotRange("SliceBackground", m_properties["BackgroundStart"], m_properties["BackgroundEnd"], range);

      replot("SlicePlot");
    }
    else
    {
      emit showMessageBox("Selected input files are invalid.");
    }

    connect(m_dblManager, SIGNAL(valueChanged(QtProperty*, double)), this, SLOT(updatePreviewPlot()));
    connect(m_blnManager, SIGNAL(valueChanged(QtProperty*, bool)), this, SLOT(updatePreviewPlot()));

    updatePreviewPlot();
  }
/**
 * Create the vector of rebin parameters
 * @param toMatch :: A shared pointer to the workspace with the desired binning 
 * @param rb_params :: A vector to hold the rebin parameters once they have been calculated
 */
void RebinToWorkspace::createRebinParameters(Mantid::API::MatrixWorkspace_sptr toMatch, std::vector<double> & rb_params)
{
  using namespace Mantid::API;

  const MantidVec & matchXdata = toMatch->readX(0);
  //params vector should have the form [x_1, delta_1,x_2, ... ,x_n-1,delta_n-1,x_n), see Rebin.cpp
  rb_params.clear();
  int xsize = (int)matchXdata.size();
  rb_params.reserve(xsize*2);
  for( int i = 0; i < xsize; ++i )
  {
    //bin bound
    rb_params.push_back(matchXdata[i]);
    //Bin width
    if( i < xsize - 1) rb_params.push_back(matchXdata[i + 1] - matchXdata[i]);
  }
}
Beispiel #3
0
/**
 * Create the vector of rebin parameters
 * @param toMatch :: A shared pointer to the workspace with the desired binning
 * @returns :: A vector to hold the rebin parameters once they have been
 * calculated
 */
std::vector<double> RebinToWorkspace::createRebinParameters(
    Mantid::API::MatrixWorkspace_sptr toMatch) {
  using namespace Mantid::API;

  const MantidVec &matchXdata = toMatch->readX(0);
  // params vector should have the form [x_1, delta_1,x_2, ...
  // ,x_n-1,delta_n-1,x_n), see Rebin.cpp
  std::vector<double> rb_params;
  int xsize = static_cast<int>(matchXdata.size());
  rb_params.reserve(xsize * 2);
  for (int i = 0; i < xsize; ++i) {
    // bin bound
    rb_params.push_back(matchXdata[i]);
    // Bin width
    if (i < xsize - 1)
      rb_params.push_back(matchXdata[i + 1] - matchXdata[i]);
  }
  return rb_params;
}
Beispiel #4
0
void ISISDiagnostics::handleNewFile() {
  if (!m_uiForm.dsInputFiles->isValid())
    return;

  QString filename = m_uiForm.dsInputFiles->getFirstFilename();

  QFileInfo fi(filename);
  QString wsname = fi.baseName();

  int specMin = static_cast<int>(m_dblManager->value(m_properties["SpecMin"]));
  int specMax = static_cast<int>(m_dblManager->value(m_properties["SpecMax"]));

  if (!loadFile(filename, wsname, specMin, specMax)) {
    emit showMessageBox("Unable to load file.\nCheck whether your file exists "
                        "and matches the selected instrument in the "
                        "EnergyTransfer tab.");
    return;
  }

  Mantid::API::MatrixWorkspace_sptr input =
      boost::dynamic_pointer_cast<Mantid::API::MatrixWorkspace>(
          Mantid::API::AnalysisDataService::Instance().retrieve(
              wsname.toStdString()));

  const Mantid::MantidVec &dataX = input->readX(0);
  QPair<double, double> range(dataX.front(), dataX.back());
  int previewSpec =
      static_cast<int>(m_dblManager->value(m_properties["PreviewSpec"])) -
      specMin;

  m_uiForm.ppRawPlot->clear();
  m_uiForm.ppRawPlot->addSpectrum("Raw", input, previewSpec);

  setPlotPropertyRange(m_uiForm.ppRawPlot->getRangeSelector("SlicePeak"),
                       m_properties["PeakStart"], m_properties["PeakEnd"],
                       range);
  setPlotPropertyRange(m_uiForm.ppRawPlot->getRangeSelector("SliceBackground"),
                       m_properties["BackgroundStart"],
                       m_properties["BackgroundEnd"], range);

  m_uiForm.ppRawPlot->resizeX();
}
Beispiel #5
0
/**
 * Sum counts in detectors for purposes of rough plotting against the units on the x-axis.
 * Assumes that all spectra have different x vectors.
 *
 * @param dets :: A list of detector IDs to sum.
 * @param x :: (output) Time of flight values (or whatever values the x axis has) to plot against.
 * @param y :: (output) The sums of the counts for each bin.
 * @param size :: (input) Size of the output vectors.
 */
void InstrumentActor::sumDetectorsRagged(QList<int> &dets, std::vector<double> &x, std::vector<double> &y, size_t size) const
{
    if ( dets.isEmpty() || size == 0 )
    {
        x.clear();
        y.clear();
        return;
    }

    Mantid::API::MatrixWorkspace_const_sptr ws = getWorkspace();
    //  create a workspace to hold the data from the selected detectors
    Mantid::API::MatrixWorkspace_sptr dws = Mantid::API::WorkspaceFactory::Instance().create(ws,dets.size());

    // x-axis limits
    double xStart = maxBinValue();
    double xEnd = minBinValue();

    size_t nSpec = 0; // number of actual spectra to add
    // fill in the temp workspace with the data from the detectors
    foreach(int id, dets)
    {
        try {
            size_t index = getWorkspaceIndex( id );
            dws->dataX(nSpec) = ws->readX(index);
            dws->dataY(nSpec) = ws->readY(index);
            dws->dataE(nSpec) = ws->readE(index);
            double xmin = dws->readX(nSpec).front();
            double xmax = dws->readX(nSpec).back();
            if ( xmin < xStart )
            {
                xStart = xmin;
            }
            if ( xmax > xEnd )
            {
                xEnd = xmax;
            }
            ++nSpec;
        } catch (Mantid::Kernel::Exception::NotFoundError &) {
            continue; // Detector doesn't have a workspace index relating to it
        }
    }

    if ( nSpec == 0 )
    {
        x.clear();
        y.clear();
        return;
    }

    // limits should exceed the integration range
    if ( xStart < minBinValue() )
    {
        xStart = minBinValue();
    }

    if ( xEnd > maxBinValue() )
    {
        xEnd = maxBinValue();
    }

    double dx = (xEnd - xStart) / static_cast<double>(size - 1);
    std::string params = QString("%1,%2,%3").arg(xStart).arg(dx).arg(xEnd).toStdString();
    std::string outName = "_TMP_sumDetectorsRagged";

    try
    {
        // rebin all spectra to the same binning
        Mantid::API::IAlgorithm * alg = Mantid::API::FrameworkManager::Instance().createAlgorithm("Rebin",-1);
        alg->setProperty( "InputWorkspace", dws );
        alg->setPropertyValue( "OutputWorkspace", outName );
        alg->setPropertyValue( "Params", params );
        alg->execute();

        ws = boost::dynamic_pointer_cast<Mantid::API::MatrixWorkspace>(Mantid::API::AnalysisDataService::Instance().retrieve(outName));
        Mantid::API::AnalysisDataService::Instance().remove( outName );

        x = ws->readX(0);
        y = ws->readY(0);
        // add the spectra
        for(size_t i = 0; i < nSpec; ++i)
        {
            const Mantid::MantidVec& Y = ws->readY(i);
            std::transform( y.begin(), y.end(), Y.begin(), y.begin(), std::plus<double>() );
        }
    }
    catch(std::invalid_argument&)
    {
        // wrong Params for any reason
        x.resize(size,(xEnd + xStart)/2);
        y.resize(size,0.0);
    }

}