예제 #1
0
/** Initialize a workspace from its parent
 * This sets values such as title, instrument, units, sample, spectramap.
 * This does NOT copy any data.
 *
 * @deprecated Replaced by functions in MantidDataObjects/WorkspaceCreation.h
 * @param parent :: the parent workspace
 * @param child :: the child workspace
 * @param differentSize :: A flag to indicate if the two workspace will be
 *different sizes
 */
void WorkspaceFactoryImpl::initializeFromParent(
    const MatrixWorkspace &parent, MatrixWorkspace &child,
    const bool differentSize) const {
  child.setTitle(parent.getTitle());
  child.setComment(parent.getComment());
  child.copyExperimentInfoFrom(&parent);
  child.setYUnit(parent.m_YUnit);
  child.setYUnitLabel(parent.m_YUnitLabel);
  child.setDistribution(parent.isDistribution());

  // Only copy the axes over if new sizes are not given
  if (!differentSize) {
    // Only copy mask map if same size for now. Later will need to check
    // continued validity.
    child.m_masks = parent.m_masks;
  }

  // Same number of histograms = copy over the spectra data
  if (parent.getNumberHistograms() == child.getNumberHistograms()) {
    child.m_isInitialized = false;
    for (size_t i = 0; i < parent.getNumberHistograms(); ++i)
      child.getSpectrum(i).copyInfoFrom(parent.getSpectrum(i));
    child.m_isInitialized = true;
    // We use this variant without ISpectrum update to avoid costly rebuilds
    // triggered by setIndexInfo(). ISpectrum::copyInfoFrom sets invalid flags
    // for spectrum definitions, so it is important to call this *afterwards*,
    // since it clears the flags:
    child.setIndexInfoWithoutISpectrumUpdate(parent.indexInfo());
  }

  // deal with axis
  for (size_t i = 0; i < parent.m_axes.size(); ++i) {
    if (parent.m_axes[i]->isSpectra()) {
      // By default the child already has a spectra axis which
      // does not need to get cloned from the parent.
      continue;
    }
    const bool isBinEdge =
        dynamic_cast<const BinEdgeAxis *const>(parent.m_axes[i]) != nullptr;
    const size_t newAxisLength =
        child.m_axes[i]->length() + (isBinEdge ? 1 : 0);
    const size_t oldAxisLength = parent.m_axes[i]->length();

    // Need to delete the existing axis created in init above
    delete child.m_axes[i];
    child.m_axes[i] = nullptr;
    if (newAxisLength == oldAxisLength) {
      // Now set to a copy of the parent workspace's axis
      child.m_axes[i] = parent.m_axes[i]->clone(&child);
    } else {
      // Call the 'different length' clone variant
      child.m_axes[i] = parent.m_axes[i]->clone(newAxisLength, &child);
    }
  }
}
예제 #2
0
/**
 * Checks if the spectra at the given index of either input workspace is masked.
 * If so then the output spectra has zeroed data
 * and is also masked.
 * @param lhsSpectrumInfo :: The LHS spectrum info object
 * @param rhsSpectrumInfo :: The RHS spectrum info object
 * @param index :: The workspace index to check
 * @param out :: A pointer to the output workspace
 * @param outSpectrumInfo :: The spectrum info object of `out`
 * @returns True if further processing is not required on the spectra, false if
 * the binary operation should be performed.
 */
bool BinaryOperation::propagateSpectraMask(const SpectrumInfo &lhsSpectrumInfo,
                                           const SpectrumInfo &rhsSpectrumInfo,
                                           const int64_t index,
                                           MatrixWorkspace &out,
                                           SpectrumInfo &outSpectrumInfo) {
  bool continueOp(true);

  if ((lhsSpectrumInfo.hasDetectors(index) &&
       lhsSpectrumInfo.isMasked(index)) ||
      (rhsSpectrumInfo.hasDetectors(index) &&
       rhsSpectrumInfo.isMasked(index))) {
    continueOp = false;
    out.getSpectrum(index).clearData();
    PARALLEL_CRITICAL(setMasked) { outSpectrumInfo.setMasked(index, true); }
  }
예제 #3
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!");
  }
}
예제 #4
0
void addFullInstrumentToWorkspace(MatrixWorkspace &workspace,
                                  bool includeMonitors, bool startYNegative,
                                  const std::string &instrumentName) {
  auto instrument = boost::make_shared<Instrument>(instrumentName);
  instrument->setReferenceFrame(
      boost::make_shared<ReferenceFrame>(Y, Z, Right, ""));
  workspace.setInstrument(instrument);

  const double pixelRadius(0.05);
  Object_sptr pixelShape = ComponentCreationHelper::createCappedCylinder(
      pixelRadius, 0.02, V3D(0.0, 0.0, 0.0), V3D(0., 1.0, 0.), "tube");

  const double detZPos(5.0);
  // Careful! Do not use size_t or auto, the unisgned will break the -=2 below.
  int ndets = static_cast<int>(workspace.getNumberHistograms());
  if (includeMonitors)
    ndets -= 2;
  for (int i = 0; i < ndets; ++i) {
    std::ostringstream lexer;
    lexer << "pixel-" << i << ")";
    Detector *physicalPixel =
        new Detector(lexer.str(), workspace.getAxis(1)->spectraNo(i),
                     pixelShape, instrument.get());
    int ycount(i);
    if (startYNegative)
      ycount -= 1;
    const double ypos = ycount * 2.0 * pixelRadius;
    physicalPixel->setPos(0.0, ypos, detZPos);
    instrument->add(physicalPixel);
    instrument->markAsDetector(physicalPixel);
    workspace.getSpectrum(i).setDetectorID(physicalPixel->getID());
  }

  // Monitors last
  if (includeMonitors) // These occupy the last 2 spectra
  {
    Detector *monitor1 =
        new Detector("mon1", workspace.getAxis(1)->spectraNo(ndets),
                     Object_sptr(), instrument.get());
    monitor1->setPos(0.0, 0.0, -9.0);
    instrument->add(monitor1);
    instrument->markAsMonitor(monitor1);
    workspace.getSpectrum(ndets).setDetectorID(ndets + 1);

    Detector *monitor2 =
        new Detector("mon2", workspace.getAxis(1)->spectraNo(ndets) + 1,
                     Object_sptr(), instrument.get());
    monitor2->setPos(0.0, 0.0, -2.0);
    instrument->add(monitor2);
    instrument->markAsMonitor(monitor2);
    workspace.getSpectrum(ndets + 1).setDetectorID(ndets + 2);
  }

  // Define a source and sample position
  // Define a source component
  ObjComponent *source = new ObjComponent(
      "moderator",
      ComponentCreationHelper::createSphere(0.1, V3D(0, 0, 0), "1"),
      instrument.get());
  source->setPos(V3D(0.0, 0.0, -20.0));
  instrument->add(source);
  instrument->markAsSource(source);

  // Define a sample as a simple sphere
  ObjComponent *sample = new ObjComponent(
      "samplePos",
      ComponentCreationHelper::createSphere(0.1, V3D(0, 0, 0), "1"),
      instrument.get());
  instrument->setPos(0.0, 0.0, 0.0);
  instrument->add(sample);
  instrument->markAsSamplePos(sample);
  // chopper position
  Component *chop_pos = new Component("chopper-position",
                                      Kernel::V3D(0, 0, -10), instrument.get());
  instrument->add(chop_pos);
}