当前位置: 首页>>代码示例>>C++>>正文


C++ api::MatrixWorkspace_const_sptr类代码示例

本文整理汇总了C++中mantid::api::MatrixWorkspace_const_sptr的典型用法代码示例。如果您正苦于以下问题:C++ MatrixWorkspace_const_sptr类的具体用法?C++ MatrixWorkspace_const_sptr怎么用?C++ MatrixWorkspace_const_sptr使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了MatrixWorkspace_const_sptr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: setup

void MantidMatrix::setup(Mantid::API::MatrixWorkspace_const_sptr ws, int start,
                         int end) {
  if (!ws) {
    QMessageBox::critical(0, "WorkspaceMatrixModel error",
                          "2D workspace expected.");
    m_rows = 0;
    m_cols = 0;
    m_startRow = 0;
    m_endRow = 0;
    return;
  }

  m_workspace = ws;
  m_workspaceTotalHist = static_cast<int>(ws->getNumberHistograms());
  m_startRow = (start < 0 || start >= m_workspaceTotalHist) ? 0 : start;
  m_endRow = (end < 0 || end >= m_workspaceTotalHist || end < start)
                 ? m_workspaceTotalHist - 1
                 : end;
  m_rows = m_endRow - m_startRow + 1;
  m_cols = static_cast<int>(ws->blocksize());
  if (ws->isHistogramData())
    m_histogram = true;
  connect(this, SIGNAL(needsUpdating()), this, SLOT(repaintAll()));

  m_bk_color = QColor(128, 255, 255);
  m_matrix_icon = getQPixmap("mantid_matrix_xpm");
  m_column_width = 100;
}
开发者ID:mducle,项目名称:mantid,代码行数:28,代码来源:MantidMatrix.cpp

示例2: checkForSpectraAxes

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;
    }
  }
}
开发者ID:trnielsen,项目名称:mantid,代码行数:25,代码来源:MantidWSIndexDialog.cpp

示例3: plotMiniplot

  /**
   * Creates and returns a "mini plot", from the given QwtPlot and QwtPlotCurve objects, as well as the given workspace
   * and workspace index.
   *
   * @param plot      :: the QwtPlot object
   * @param curve     :: the QwtPlotCurve object
   * @param workspace :: the workspace to use
   * @param wsIndex   :: the workspace index
   *
   * @returns the resulting QwtPlotCurve object
   */
  QwtPlotCurve* IDATab::plotMiniplot(QwtPlot* plot, QwtPlotCurve* curve, const std::string & workspace, size_t wsIndex)
  {
    if ( curve != NULL )
    {
      curve->attach(0);
      delete curve;
      curve = 0;
    }

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

    size_t nhist = ws->getNumberHistograms();
    if ( wsIndex >= nhist )
    {
      showInformationBox("Error: Workspace index out of range.");
      return NULL;
    }

    using Mantid::MantidVec;
    const MantidVec & dataX = ws->readX(wsIndex);
    const MantidVec & dataY = ws->readY(wsIndex);

    curve = new QwtPlotCurve();
    curve->setData(&dataX[0], &dataY[0], static_cast<int>(ws->blocksize()));
    curve->attach(plot);

    plot->replot();

    return curve;
  }
开发者ID:trnielsen,项目名称:mantid,代码行数:41,代码来源:IDATab.cpp

示例4: generateWsIndexIntervals

void MantidWSIndexDialog::generateWsIndexIntervals()
{
  // Get the available interval for each of the workspaces, and then
  // present the user with interval which is the INTERSECTION of each of
  // those intervals.
  QList<QString>::const_iterator it = m_wsNames.constBegin();
  
  // Cycle through the workspaces ...
  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;
    
    const int endWs = static_cast<int>(ws->getNumberHistograms() - 1);//= static_cast<int> (end->first);

    Interval interval(0,endWs);
    // If no interval has been added yet, just add it ...
    if(it == m_wsNames.constBegin())
      m_wsIndexIntervals.addInterval(interval);
    // ... else set the list as the intersection of what's already there
    // and what has just been added.
    else
      m_wsIndexIntervals.setIntervalList(IntervalList::intersect(m_wsIndexIntervals,interval));
  }
}
开发者ID:trnielsen,项目名称:mantid,代码行数:25,代码来源:MantidWSIndexDialog.cpp

示例5: double

/**
 * 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;
}
开发者ID:liyulun,项目名称:mantid,代码行数:60,代码来源:ReflectometryTransform.cpp

示例6: OrientedLattice

/** function retrieves copy of the oriented lattice from the workspace */
boost::shared_ptr<Geometry::OrientedLattice>
MDWSDescription::getOrientedLattice(
    Mantid::API::MatrixWorkspace_const_sptr inWS2D) {
  // try to get the WS oriented lattice
  boost::shared_ptr<Geometry::OrientedLattice> orl;
  if (inWS2D->sample().hasOrientedLattice())
    orl = boost::shared_ptr<Geometry::OrientedLattice>(
        new Geometry::OrientedLattice(inWS2D->sample().getOrientedLattice()));

  return orl;
}
开发者ID:rosswhitfield,项目名称:mantid,代码行数:12,代码来源:MDWSDescription.cpp

示例7: generateSpectraIdIntervals

void MantidWSIndexDialog::generateSpectraIdIntervals()
{
  // Get the list of available intervals for each of the workspaces, and then
  // present the user with intervals which are the INTERSECTION of each of
  // those lists of intervals.
  QList<QString>::const_iterator it = m_wsNames.constBegin();
  
  // Cycle through the workspaces ...
  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;
    Mantid::spec2index_map * spec2index = ws->getSpectrumToWorkspaceIndexMap();
    
    Mantid::spec2index_map::const_iterator last = spec2index->end();
    --last;
    Mantid::spec2index_map::const_iterator first = spec2index->begin();
    
    const int startSpectrum = static_cast<int> (first->first);
    const int endSpectrum = static_cast<int> (last->first);
    const int size = static_cast<int> (spec2index->size());
    if(size == (1 + endSpectrum - startSpectrum))
    {
      // Here we make the assumption (?) that the spectra IDs are sorted, and so
      // are a list of ints from startSpectrum to endSpectrum without any gaps.
      Interval interval(startSpectrum, endSpectrum);
      if(it == m_wsNames.constBegin())
        m_spectraIdIntervals.addInterval(interval);
      else
        m_spectraIdIntervals.setIntervalList(IntervalList::intersect(m_spectraIdIntervals,interval));
    }
    else
    {
      // The spectra IDs do not appear to be an uninterrupted list of numbers,
      // and so we must go through each one and construct the intervals that way.
      // TODO - is this at all feasible for large workspaces, and/or many workspaces?
      ++last;
      for ( ; first != last; ++first) 
      {
        const int spectraId = static_cast<int> (first->first);
        
        Interval interval(spectraId);
        if(it == m_wsNames.constBegin())
          m_spectraIdIntervals.addInterval(interval);
        else
          m_spectraIdIntervals.setIntervalList(IntervalList::intersect(m_spectraIdIntervals,interval));
      }
    }
  }
}
开发者ID:trnielsen,项目名称:mantid,代码行数:50,代码来源:MantidWSIndexDialog.cpp

示例8: fillNormalizationCombobox

void StepScan::fillNormalizationCombobox( const Mantid::API::MatrixWorkspace_const_sptr & ws )
{
  // If there are more than 3 entries in the combobox (nothing, time, proton_charge) then
  // remove any stale ones
  while ( m_uiForm.normalization->count() > 3 )
  {
    m_uiForm.normalization->removeItem(m_uiForm.normalization->count()-1);
  }

  for ( std::size_t i = 0; i < ws->getNumberHistograms(); ++i )
  {
    const std::string monitorName = ws->getDetector(i)->getName();
    m_uiForm.normalization->addItem( QString::fromStdString( monitorName ) );
  }
}
开发者ID:trnielsen,项目名称:mantid,代码行数:15,代码来源:StepScan.cpp

示例9: sumDetectorsUniform

/**
 * Sum counts in detectors for purposes of rough plotting against the units on the x-axis.
 * Assumes that all spectra share the x vector.
 *
 * @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.
 */
void InstrumentActor::sumDetectorsUniform(QList<int>& dets, std::vector<double>&x, std::vector<double>&y) const
{

    size_t wi;
    bool isDataEmpty = dets.isEmpty();

    if ( !isDataEmpty )
    {
        try {
            wi = getWorkspaceIndex( dets[0] );
        } catch (Mantid::Kernel::Exception::NotFoundError &) {
            isDataEmpty = true; // Detector doesn't have a workspace index relating to it
        }
    }

    if ( isDataEmpty )
    {
        x.clear();
        y.clear();
        return;
    }

    // find the bins inside the integration range
    size_t imin,imax;
    getBinMinMaxIndex(wi,imin,imax);

    Mantid::API::MatrixWorkspace_const_sptr ws = getWorkspace();
    const Mantid::MantidVec& X = ws->readX(wi);
    x.assign(X.begin() + imin, X.begin() + imax);
    if ( ws->isHistogramData() )
    {
        // calculate the bin centres
        std::transform(x.begin(),x.end(),X.begin() + imin + 1,x.begin(),std::plus<double>());
        std::transform(x.begin(),x.end(),x.begin(),std::bind2nd(std::divides<double>(),2.0));
    }
    y.resize(x.size(),0);
    // sum the spectra
    foreach(int id, dets)
    {
        try {
            size_t index = getWorkspaceIndex( id );
            const Mantid::MantidVec& Y = ws->readY(index);
            std::transform(y.begin(),y.end(),Y.begin() + imin,y.begin(),std::plus<double>());
        } catch (Mantid::Kernel::Exception::NotFoundError &) {
            continue; // Detector doesn't have a workspace index relating to it
        }
    }
}
开发者ID:stothe2,项目名称:mantid,代码行数:56,代码来源:InstrumentActor.cpp

示例10: runPreprocessDetectorsToMDChildUpdatingMasks

    DataObjects::TableWorkspace_sptr  ConvertToMDParent::runPreprocessDetectorsToMDChildUpdatingMasks(Mantid::API::MatrixWorkspace_const_sptr InWS2D,
      const std::string &OutWSName,const std::string &dEModeRequested,Kernel::DeltaEMode::Type &Emode)
    {
      // prospective result
      DataObjects::TableWorkspace_sptr TargTableWS;

      // if input workspace does not exist in analysis data service, we have to add it there to work with the Child Algorithm 
      std::string InWSName = InWS2D->getName();
      if(!API::AnalysisDataService::Instance().doesExist(InWSName))
      {
        throw std::runtime_error("Can not retrieve input matrix workspace "+InWSName+" from the analysis data service");
      }

      Mantid::API::Algorithm_sptr childAlg = createChildAlgorithm("PreprocessDetectorsToMD",0.,1.);
      if(!childAlg)throw(std::runtime_error("Can not create child ChildAlgorithm to preprocess detectors"));
      childAlg->setProperty("InputWorkspace",InWSName);
      childAlg->setProperty("OutputWorkspace",OutWSName);
      childAlg->setProperty("GetMaskState",true);
      childAlg->setProperty("UpdateMasksInfo",true);
      childAlg->setProperty("OutputWorkspace",OutWSName);

      // check and get energy conversion mode to define additional ChildAlgorithm parameters
      Emode = Kernel::DeltaEMode().fromString(dEModeRequested);
      if(Emode == Kernel::DeltaEMode::Indirect) 
        childAlg->setProperty("GetEFixed",true); 


      childAlg->execute();
      if(!childAlg->isExecuted())throw(std::runtime_error("Can not properly execute child algorithm PreprocessDetectorsToMD"));

      TargTableWS = childAlg->getProperty("OutputWorkspace");
      if(!TargTableWS)throw(std::runtime_error("Can not retrieve results of child algorithm PreprocessDetectorsToMD"));

      return TargTableWS;
    }
开发者ID:jkrueger1,项目名称:mantid,代码行数:35,代码来源:ConvertToMDParent.cpp

示例11: fillAddProperties

/** function extracts the coordinates from additional workspace properties and
*places them to proper position within
*  the vector of MD coordinates for the particular workspace.
*
*  @param inWS2D -- input workspace
*  @param dimPropertyNames  -- names of properties which should be treated as
*dimensions
*  @param AddCoord --
*
*  @return AddCoord       -- vector of additional coordinates (derived from WS
*properties) for current multidimensional event
*/
void MDWSDescription::fillAddProperties(
    Mantid::API::MatrixWorkspace_const_sptr inWS2D,
    const std::vector<std::string> &dimPropertyNames,
    std::vector<coord_t> &AddCoord) {
  size_t nDimPropNames = dimPropertyNames.size();
  if (AddCoord.size() != nDimPropNames)
    AddCoord.resize(nDimPropNames);

  for (size_t i = 0; i < nDimPropNames; i++) {
    // HACK: A METHOD, Which converts TSP into value, correspondent to time
    // scale of matrix workspace has to be developed and deployed!
    Kernel::Property *pProperty =
        (inWS2D->run().getProperty(dimPropertyNames[i]));
    Kernel::TimeSeriesProperty<double> *run_property =
        dynamic_cast<Kernel::TimeSeriesProperty<double> *>(pProperty);
    if (run_property) {
      AddCoord[i] = coord_t(run_property->firstValue());
    } else {
      // e.g Ei can be a property and dimension
      Kernel::PropertyWithValue<double> *proc_property =
          dynamic_cast<Kernel::PropertyWithValue<double> *>(pProperty);
      if (!proc_property) {
        std::string ERR =
            " Can not interpret property, used as dimension.\n Property: " +
            dimPropertyNames[i] + " is neither a time series (run) property "
                                  "nor a property with value<double>";
        throw(std::invalid_argument(ERR));
      }
      AddCoord[i] = coord_t(*(proc_property));
    }
  }
}
开发者ID:rosswhitfield,项目名称:mantid,代码行数:44,代码来源:MDWSDescription.cpp

示例12: isDetInfoLost

 /// 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;
 }
开发者ID:BigShows,项目名称:mantid,代码行数:8,代码来源:PreprocessDetectorsToMD.cpp

示例13: findAllWidths

		/**
		 * 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;
					}
				}
			}
		}
开发者ID:mkoennecke,项目名称:mantid,代码行数:52,代码来源:JumpFit.cpp

示例14: sumDetectors

/**
 * Sum counts in detectors for purposes of rough plotting against the units on the x-axis.
 * Checks (approximately) if the workspace is ragged or not and uses the appropriate summation
 * method.
 *
 * @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 :: (optional input) Size of the output vectors. If not given it will be determined automatically.
 */
void InstrumentActor::sumDetectors(QList<int> &dets, std::vector<double> &x, std::vector<double> &y, size_t size) const
{
    Mantid::API::MatrixWorkspace_const_sptr ws = getWorkspace();
    if ( size > ws->blocksize() || size == 0 )
    {
        size = ws->blocksize();
    }

    if ( m_ragged )
    {
        // could be slower than uniform
        sumDetectorsRagged( dets, x, y, size );
    }
    else
    {
        // should be faster than ragged
        sumDetectorsUniform( dets, x, y );
    }
}
开发者ID:stothe2,项目名称:mantid,代码行数:29,代码来源:InstrumentActor.cpp

示例15:

std::tuple<double, double, double> EnggDiffFittingModel::getDifcDifaTzero(
    Mantid::API::MatrixWorkspace_const_sptr ws) {
  const auto run = ws->run();

  const auto difc = run.getPropertyValueAsType<double>("difc");
  const auto difa = run.getPropertyValueAsType<double>("difa");
  const auto tzero = run.getPropertyValueAsType<double>("tzero");

  return std::tuple<double, double, double>(difc, difa, tzero);
}
开发者ID:DanNixon,项目名称:mantid,代码行数:10,代码来源:EnggDiffFittingModel.cpp


注:本文中的mantid::api::MatrixWorkspace_const_sptr类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。