예제 #1
0
Peak PeakHKLErrors::createNewPeak(const Geometry::IPeak &peak_old,
                                  Geometry::Instrument_sptr instrNew, double T0,
                                  double L0) {
  Geometry::Instrument_const_sptr inst = peak_old.getInstrument();
  if (inst->getComponentID() != instrNew->getComponentID()) {
    g_log.error("All peaks must have the same instrument");
    throw std::invalid_argument("All peaks must have the same instrument");
  }

  double T = peak_old.getTOF() + T0;

  int ID = peak_old.getDetectorID();

  Kernel::V3D hkl = peak_old.getHKL();
  // peak_old.setDetectorID(ID); //set det positions
  Peak peak(instrNew, ID, peak_old.getWavelength(), hkl,
            peak_old.getGoniometerMatrix());

  Wavelength wl;

  wl.initialize(L0, peak.getL2(), peak.getScattering(), 0,
                peak_old.getInitialEnergy(), 0.0);

  peak.setWavelength(wl.singleFromTOF(T));
  peak.setIntensity(peak_old.getIntensity());
  peak.setSigmaIntensity(peak_old.getSigmaIntensity());
  peak.setRunNumber(peak_old.getRunNumber());
  peak.setBinCount(peak_old.getBinCount());

  //!!!peak.setDetectorID(ID);
  return peak;
}
예제 #2
0
/// Creates a LatticeDomain from an IPeaksWorkspace, using HKL and d-values.
void LatticeDomainCreator::createDomainFromPeaksWorkspace(
    const API::IPeaksWorkspace_sptr &workspace,
    boost::shared_ptr<API::FunctionDomain> &domain,
    boost::shared_ptr<API::FunctionValues> &values, size_t i0) {
  if (!workspace) {
    throw std::invalid_argument(
        "This function only works on an IPeaksWorkspace-object.");
  }

  size_t peakCount = workspace->getNumberPeaks();

  if (peakCount < 1) {
    throw std::range_error("Cannot create a domain for 0 peaks.");
  }

  std::vector<V3D> hkls;
  hkls.reserve(peakCount);

  std::vector<double> dSpacings;
  dSpacings.reserve(peakCount);

  for (size_t i = 0; i < peakCount; ++i) {
    Geometry::IPeak *currentPeak = workspace->getPeakPtr(static_cast<int>(i));
    V3D hkl = currentPeak->getHKL();

    if (hkl != V3D(0, 0, 0)) {
      hkls.push_back(hkl);
      dSpacings.push_back(currentPeak->getDSpacing());
    }
  }

  auto latticeDomain = new LatticeDomain(hkls);
  domain.reset(latticeDomain);

  if (!values) {
    auto functionValues = new FunctionValues(*domain);
    values.reset(functionValues);
  } else {
    values->expand(i0 + latticeDomain->size());
  }

  values->setFitData(dSpacings);

  // Set unit weights.
  values->setFitWeights(1.0);
}