Пример #1
0
GeometryInfoFactory::GeometryInfoFactory(const MatrixWorkspace &workspace)
    : m_workspace(workspace), m_instrument(workspace.getInstrument()) {
  // Note: This does not seem possible currently (the instrument objects is
  // always allocated, even if it is empty), so this will not fail.
  if (!m_instrument)
    throw std::runtime_error("Workspace " + workspace.getName() +
                             " does not contain an instrument!");
}
Пример #2
0
/**
 * Fully masks one component named componentName
 * @param ws :: workspace with the respective instrument assigned
 * @param componentName :: must be a known CompAssembly.
 */
void CalculateEfficiency::maskComponent(MatrixWorkspace &ws,
                                        const std::string &componentName) {
  auto instrument = ws.getInstrument();
  try {
    boost::shared_ptr<const Geometry::ICompAssembly> component =
        boost::dynamic_pointer_cast<const Geometry::ICompAssembly>(
            instrument->getComponentByName(componentName));
    if (!component) {
      g_log.warning("Component " + componentName +
                    " expected to be a CompAssembly, e.g., a bank. Component " +
                    componentName + " not masked!");
      return;
    }
    std::vector<detid_t> detectorList;
    for (int x = 0; x < component->nelements(); x++) {
      boost::shared_ptr<Geometry::ICompAssembly> xColumn =
          boost::dynamic_pointer_cast<Geometry::ICompAssembly>((*component)[x]);
      for (int y = 0; y < xColumn->nelements(); y++) {
        boost::shared_ptr<Geometry::Detector> detector =
            boost::dynamic_pointer_cast<Geometry::Detector>((*xColumn)[y]);
        if (detector) {
          auto detID = detector->getID();
          detectorList.push_back(detID);
        }
      }
    }
    auto indexList = ws.getIndicesFromDetectorIDs(detectorList);
    auto &spectrumInfo = ws.mutableSpectrumInfo();
    for (const auto &idx : indexList) {
      ws.getSpectrum(idx).clearData();
      spectrumInfo.setMasked(idx, true);
    }
  } catch (std::exception &) {
    g_log.warning("Expecting the component " + componentName +
                  " to be a CompAssembly, e.g., a bank. Component not masked!");
  }
}