Example #1
0
/**
Reduce the peak list by removing duplicates
then convert SXPeaks objects to PeakObjects and add them to the output workspace
@param pcv : current peak list containing potential duplicates
*/
void FindSXPeaks::reducePeakList(const peakvector &pcv) {
  double resol = getProperty("Resolution");
  peakvector finalv;
  bool found = false;
  for (std::size_t i = 0; i < pcv.size(); i++) {
    for (std::size_t j = 0; j < finalv.size(); j++) {
      if (pcv[i].compare(finalv[j], resol)) {
        finalv[j] += pcv[i];
        found = true;
        break;
      }
    }
    if (!found)
      finalv.push_back(pcv[i]);
    found = false;
  }

  for (std::size_t i = 0; i < finalv.size(); i++) {
    finalv[i].reduce();
    try {
      Geometry::IPeak *peak = m_peaks->createPeak(finalv[i].getQ());
      if (peak) {
        peak->setIntensity(finalv[i].getIntensity());
        peak->setDetectorID(finalv[i].getDetectorId());
        m_peaks->addPeak(*peak);
        delete peak;
      }
    } catch (std::exception &e) {
      g_log.error() << e.what() << std::endl;
    }
  }
}
Example #2
0
/**
Reduce the peak list by removing duplicates
then convert SXPeaks objects to PeakObjects and add them to the output workspace
@param pcv : current peak list containing potential duplicates
*/
void FindSXPeaks::reducePeakList(const peakvector &pcv) {
  double resol = getProperty("Resolution");
  peakvector finalv;

  for (const auto &currentPeak : pcv) {
    auto pos = std::find_if(finalv.begin(), finalv.end(),
                            [&currentPeak, resol](SXPeak &peak) {
                              bool result = currentPeak.compare(peak, resol);
                              if (result)
                                peak += currentPeak;
                              return result;
                            });
    if (pos == finalv.end())
      finalv.push_back(currentPeak);
  }

  for (auto &finalPeak : finalv) {
    finalPeak.reduce();
    try {
      Geometry::IPeak *peak = m_peaks->createPeak(finalPeak.getQ());
      if (peak) {
        peak->setIntensity(finalPeak.getIntensity());
        peak->setDetectorID(finalPeak.getDetectorId());
        m_peaks->addPeak(*peak);
        delete peak;
      }
    } catch (std::exception &e) {
      g_log.error() << e.what() << '\n';
    }
  }
}
Example #3
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);
}
Example #4
0
/**
Reduce the peak list by removing duplicates
then convert SXPeaks objects to PeakObjects and add them to the output workspace
@param pcv : current peak list containing potential duplicates
@param progress: a progress object
*/
void FindSXPeaks::reducePeakList(const peakvector &pcv, Progress &progress) {
  MatrixWorkspace_const_sptr localworkspace = getProperty("InputWorkspace");
  auto &goniometerMatrix = localworkspace->run().getGoniometer().getR();
  auto compareStrategy = getCompareStrategy();
  auto reductionStrategy = getReducePeakListStrategy(compareStrategy.get());
  auto finalv = reductionStrategy->reduce(pcv, progress);

  for (auto &finalPeak : finalv) {
    finalPeak.reduce();
    try {
      Geometry::IPeak *peak = m_peaks->createPeak(finalPeak.getQ());
      if (peak) {
        peak->setIntensity(finalPeak.getIntensity());
        peak->setDetectorID(finalPeak.getDetectorId());
        peak->setGoniometerMatrix(goniometerMatrix);
        m_peaks->addPeak(*peak);
        delete peak;
      }
    } catch (std::exception &e) {
      g_log.error() << e.what() << '\n';
    }
  }
}
Example #5
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;
}