Ejemplo n.º 1
0
void MantidWSIndexDialog::checkForSpectraAxes()
{
  // Check to see if *all* workspaces have a spectrum axis.
  // If even one does not have a spectra axis, then we wont
  // ask the user to enter spectra IDs - only workspace indices.
  QList<QString>::const_iterator it = m_wsNames.constBegin();
  m_spectra = true;

  for ( ; it != m_wsNames.constEnd(); ++it )
  {
    Mantid::API::MatrixWorkspace_const_sptr ws = boost::dynamic_pointer_cast<const Mantid::API::MatrixWorkspace>(Mantid::API::AnalysisDataService::Instance().retrieve((*it).toStdString()));
    if ( NULL == ws ) continue;
    bool hasSpectra = false;
    for(int i = 0; i < ws->axes(); i++)
    {
      if(ws->getAxis(i)->isSpectra()) 
        hasSpectra = true;
    }
    if(hasSpectra == false)
    {
      m_spectra = false;
      break;
    }
  }
}
Ejemplo n.º 2
0
 /// function checks if source workspace still has information about detectors. Some ws (like rebinned one) do not have this information any more. 
 bool PreprocessDetectorsToMD::isDetInfoLost(Mantid::API::MatrixWorkspace_const_sptr inWS2D)const
 {
   auto pYAxis = dynamic_cast<API::NumericAxis *>(inWS2D->getAxis(1));
   // if this is numeric axis, then the detector's information has been lost:
   if(pYAxis)     return true; 
   return false;
 }
Ejemplo n.º 3
0
/**
 * Convert to the output dimensions
 * @param inputWs : Input Matrix workspace
 * @return workspace group containing output matrix workspaces of ki and kf
 */
Mantid::API::MatrixWorkspace_sptr ReflectometryTransform::execute(
    Mantid::API::MatrixWorkspace_const_sptr inputWs) const {
  auto ws = boost::make_shared<Mantid::DataObjects::Workspace2D>();

  ws->initialize(m_d1NumBins, m_d0NumBins,
                 m_d0NumBins); // Create the output workspace as a distribution

  // Mapping so that d0 and d1 values calculated can be added to the matrix
  // workspace at the correct index.
  const double gradD0 =
      double(m_d0NumBins) / (m_d0Max - m_d0Min); // The x - axis
  const double gradD1 =
      double(m_d1NumBins) / (m_d1Max - m_d1Min); // Actually the y-axis
  const double cxToIndex = -gradD0 * m_d0Min;
  const double cyToIndex = -gradD1 * m_d1Min;
  const double cxToD0 = m_d0Min - (1 / gradD0);
  const double cyToD1 = m_d1Min - (1 / gradD1);

  // Create an X - Axis.
  MantidVec xAxisVec = createXAxis(ws.get(), gradD0, cxToD0, m_d0NumBins,
                                   m_d0Label, "1/Angstroms");
  // Create a Y (vertical) Axis
  createVerticalAxis(ws.get(), xAxisVec, gradD1, cyToD1, m_d1NumBins, m_d1Label,
                     "1/Angstroms");

  // Loop over all entries in the input workspace and calculate d0 and d1
  // for each.
  auto spectraAxis = inputWs->getAxis(1);
  for (size_t index = 0; index < inputWs->getNumberHistograms(); ++index) {
    auto counts = inputWs->readY(index);
    auto wavelengths = inputWs->readX(index);
    auto errors = inputWs->readE(index);
    const size_t nInputBins = wavelengths.size() - 1;
    const double theta_final = spectraAxis->getValue(index);
    m_calculator->setThetaFinal(theta_final);
    // Loop over all bins in spectra
    for (size_t binIndex = 0; binIndex < nInputBins; ++binIndex) {
      const double wavelength =
          0.5 * (wavelengths[binIndex] + wavelengths[binIndex + 1]);
      double _d0 = m_calculator->calculateDim0(wavelength);
      double _d1 = m_calculator->calculateDim1(wavelength);

      if (_d0 >= m_d0Min && _d0 <= m_d0Max && _d1 >= m_d1Min &&
          _d1 <= m_d1Max) // Check that the calculated ki and kf are in range
      {
        const int outIndexX = static_cast<int>((gradD0 * _d0) + cxToIndex);
        const int outIndexZ = static_cast<int>((gradD1 * _d1) + cyToIndex);

        ws->dataY(outIndexZ)[outIndexX] += counts[binIndex];
        ws->dataE(outIndexZ)[outIndexX] += errors[binIndex];
      }
    }
  }
  return ws;
}
Ejemplo n.º 4
0
		/**
		 * Find all of the spectra in the workspace that have width data
		 *
		 * @param ws :: The workspace to search
		 */
		void JumpFit::findAllWidths(Mantid::API::MatrixWorkspace_const_sptr ws)
		{
			m_uiForm.cbWidth->clear();
			m_spectraList.clear();

			for (size_t i = 0; i < ws->getNumberHistograms(); ++i)
			{
				auto axis = dynamic_cast<Mantid::API::TextAxis*>(ws->getAxis(1));
        if(!axis)
          return;

        std::string title = axis->label(i);

				//check if the axis labels indicate this spectrum is width data
				size_t qLinesWidthIndex = title.find(".Width");
				size_t convFitWidthIndex = title.find(".FWHM");

				bool qLinesWidth = qLinesWidthIndex != std::string::npos;
				bool convFitWidth = convFitWidthIndex != std::string::npos;

				//if we get a match, add this spectrum to the combobox
				if(convFitWidth || qLinesWidth)
				{
					std::string cbItemName = "";
					size_t substrIndex = 0;

					if (qLinesWidth)
					{
						substrIndex = qLinesWidthIndex;
					}
					else if (convFitWidth)
					{
						substrIndex = convFitWidthIndex;
					}

					cbItemName = title.substr(0, substrIndex);
					m_spectraList[cbItemName] = static_cast<int>(i);
					m_uiForm.cbWidth->addItem(QString(cbItemName.c_str()));

					//display widths f1.f1, f2.f1 and f2.f2
					if (m_uiForm.cbWidth->count() == 3)
					{
						return;
					}
				}
			}
		}
Ejemplo n.º 5
0
/**
 * Performs centre-point rebinning and produces an MDWorkspace
 * @param inputWs : The workspace you wish to perform centre-point rebinning on.
 * @param boxController : controls how the MDWorkspace will be split
 * @param frame: the md frame for the two MDHistoDimensions
 * @returns An MDWorkspace based on centre-point rebinning of the inputWS
 */
Mantid::API::IMDEventWorkspace_sptr ReflectometryTransform::executeMD(
    Mantid::API::MatrixWorkspace_const_sptr inputWs,
    BoxController_sptr boxController,
    Mantid::Geometry::MDFrame_uptr frame) const {
  auto dim0 = boost::make_shared<MDHistoDimension>(
      m_d0Label, m_d0ID, *frame, static_cast<Mantid::coord_t>(m_d0Min),
      static_cast<Mantid::coord_t>(m_d0Max), m_d0NumBins);
  auto dim1 = boost::make_shared<MDHistoDimension>(
      m_d1Label, m_d1ID, *frame, static_cast<Mantid::coord_t>(m_d1Min),
      static_cast<Mantid::coord_t>(m_d1Max), m_d1NumBins);

  auto ws = createMDWorkspace(dim0, dim1, boxController);

  auto spectraAxis = inputWs->getAxis(1);
  for (size_t index = 0; index < inputWs->getNumberHistograms(); ++index) {
    auto counts = inputWs->readY(index);
    auto wavelengths = inputWs->readX(index);
    auto errors = inputWs->readE(index);
    const size_t nInputBins = wavelengths.size() - 1;
    const double theta_final = spectraAxis->getValue(index);
    m_calculator->setThetaFinal(theta_final);
    // Loop over all bins in spectra
    for (size_t binIndex = 0; binIndex < nInputBins; ++binIndex) {
      const double &wavelength =
          0.5 * (wavelengths[binIndex] + wavelengths[binIndex + 1]);
      double _d0 = m_calculator->calculateDim0(wavelength);
      double _d1 = m_calculator->calculateDim1(wavelength);
      double centers[2] = {_d0, _d1};

      ws->addEvent(MDLeanEvent<2>(float(counts[binIndex]),
                                  float(errors[binIndex] * errors[binIndex]),
                                  centers));
    }
  }
  ws->splitAllIfNeeded(nullptr);
  ws->refreshCache();
  return ws;
}
Ejemplo n.º 6
0
/**
 *  @param g :: The Graph widget which will display the curve
 *  @param distr :: True for a distribution
 *  @param style :: The curve type to use
 */
void MantidMatrixCurve::init(Graph *g, bool distr,
                             GraphOptions::CurveType style) {
  // Will throw if name not found but return NULL ptr if the type is incorrect
  MatrixWorkspace_const_sptr workspace =
      AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(
          m_wsName.toStdString());

  if (!workspace) // The respective *Data classes will check for index validity
  {
    std::stringstream ss;
    ss << "Workspace named '" << m_wsName.toStdString()
       << "' found but it is not a MatrixWorkspace. ID='"
       << AnalysisDataService::Instance().retrieve(m_wsName.toStdString())->id()
       << "'";
    throw std::invalid_argument(ss.str());
  }

  // Set the curve name if it the non-naming constructor was called
  if (this->title().isEmpty()) {
    // If there's only one spectrum in the workspace, title is simply workspace
    // name
    if (workspace->getNumberHistograms() == 1)
      this->setTitle(m_wsName);
    else
      this->setTitle(createCurveName(workspace));
  }

  Mantid::API::MatrixWorkspace_const_sptr matrixWS =
      boost::dynamic_pointer_cast<const Mantid::API::MatrixWorkspace>(
          workspace);
  // we need to censor the data if there is a log scale because it can't deal
  // with negative values, only the y-axis has been found to be problem so far
  const bool log = g->isLog(QwtPlot::yLeft);

  // Y units are the same for both spectrum and bin plots, e.g. counts
  m_yUnits.reset(new Mantid::Kernel::Units::Label(matrixWS->YUnit(),
                                                  matrixWS->YUnitLabel()));

  if (m_indexType == Spectrum) // Spectrum plot
  {
    QwtWorkspaceSpectrumData data(*matrixWS, m_index, log, distr);

    setData(data);

    // For spectrum plots, X axis are actual X axis, e.g. TOF
    m_xUnits = matrixWS->getAxis(0)->unit();
  } else // Bin plot
  {
    QwtWorkspaceBinData data(*matrixWS, m_index, log);

    setData(data);

    // For bin plots, X axis are "spectra axis", e.g. spectra numbers
    m_xUnits = matrixWS->getAxis(1)->unit();
  }

  if (!m_xUnits) {
    m_xUnits.reset(new Mantid::Kernel::Units::Empty());
  }

  int lineWidth = 1;
  MultiLayer *ml = dynamic_cast<MultiLayer *>(g->parent()->parent()->parent());
  if (ml && (style == GraphOptions::Unspecified ||
             ml->applicationWindow()->applyCurveStyleToMantid)) {
    applyStyleChoice(style, ml, lineWidth);
  } else if (matrixWS->isHistogramData() && !matrixWS->isDistribution()) {
    setStyle(QwtPlotCurve::Steps);
    setCurveAttribute(
        Inverted,
        true); // this is the Steps style modifier that makes horizontal steps
  } else {
    setStyle(QwtPlotCurve::Lines);
  }
  g->insertCurve(this, lineWidth);

  // set the option to draw all error bars from the global settings
  if (hasErrorBars()) {
    setErrorBars(true, g->multiLayer()->applicationWindow()->drawAllErrors);
  }
  // Initialise error bar colour to match curve colour
  m_errorSettings->m_color = pen().color();
  m_errorSettings->setWidth(pen().widthF());

  connect(g, SIGNAL(axisScaleChanged(int, bool)), this,
          SLOT(axisScaleChanged(int, bool)));
  observePostDelete();
  connect(this, SIGNAL(resetData(const QString &)), this,
          SLOT(dataReset(const QString &)));
  observeAfterReplace();
  observeADSClear();
}