Esempio n. 1
0
double RemoveLowResTOF::calcTofMin(const std::size_t workspaceIndex) {
  const Kernel::V3D &sourcePos = m_instrument->getSource()->getPos();
  const Kernel::V3D &samplePos = m_sample->getPos();
  const Kernel::V3D &beamline = samplePos - sourcePos;
  double beamline_norm = 2. * beamline.norm();

  // Get a vector of detector IDs
  std::vector<detid_t> detNumbers;
  const std::set<detid_t> &detSet =
      m_inputWS->getSpectrum(workspaceIndex)->getDetectorIDs();
  detNumbers.assign(detSet.begin(), detSet.end());

  double tmin = 0.;
  if (isEmpty(m_wavelengthMin)) {
    std::map<detid_t, double> offsets; // just an empty offsets map
    double dspmap =
        Instrument::calcConversion(m_L1, beamline, beamline_norm, samplePos,
                                   m_instrument, detNumbers, offsets);

    // this is related to the reference tof
    double sqrtdmin =
        sqrt(m_Tmin / m_DIFCref) + m_K * log10(dspmap * m_DIFCref);
    if (sqrtdmin <= 0.)
      return 0.;
    tmin = sqrtdmin * sqrtdmin / dspmap;
    if (tmin != tmin) {
      g_log.warning() << "tmin is nan because dspmap = " << dspmap << ".\n";
    }
  } else {
    double l2 = 0;
    for (std::set<detid_t>::const_iterator it = detSet.begin();
         it != detSet.end(); ++it) {
      l2 += m_instrument->getDetector(*it)->getDistance(*m_sample);
    }
    l2 /= static_cast<double>(detSet.size());

    Kernel::Unit_sptr wavelength = UnitFactory::Instance().create("Wavelength");
    // unfortunately there isn't a good way to convert a single value
    std::vector<double> X(1), temp(1);
    X[0] = m_wavelengthMin;
    wavelength->toTOF(X, temp, m_L1, l2, 0., 0, 0., 0.);
    tmin = X[0];
  }

  g_log.debug() << "tmin[" << workspaceIndex << "] " << tmin << "\n";

  return tmin;
}
Esempio n. 2
0
double RemoveLowResTOF::calcTofMin(const std::size_t workspaceIndex,
                                   const SpectrumInfo &spectrumInfo) {

  const double l1 = spectrumInfo.l1();

  // Get a vector of detector IDs
  std::vector<detid_t> detNumbers;
  const auto &detSet = m_inputWS->getSpectrum(workspaceIndex).getDetectorIDs();
  detNumbers.assign(detSet.begin(), detSet.end());

  double tmin = 0.;
  if (isEmpty(m_wavelengthMin)) {
    std::map<detid_t, double> offsets; // just an empty offsets map
    Geometry::Instrument_const_sptr instrument = m_inputWS->getInstrument();
    double dspmap = Conversion::tofToDSpacingFactor(
        l1, spectrumInfo.l2(workspaceIndex),
        spectrumInfo.twoTheta(workspaceIndex), detNumbers, offsets);

    // this is related to the reference tof
    double sqrtdmin =
        sqrt(m_Tmin / m_DIFCref) + m_K * log10(dspmap * m_DIFCref);
    if (sqrtdmin <= 0.)
      return 0.;
    tmin = sqrtdmin * sqrtdmin / dspmap;
    if (tmin != tmin) {
      g_log.warning() << "tmin is nan because dspmap = " << dspmap << ".\n";
    }
  } else {
    const double l2 = spectrumInfo.l2(workspaceIndex);

    Kernel::Unit_sptr wavelength = UnitFactory::Instance().create("Wavelength");
    // unfortunately there isn't a good way to convert a single value
    std::vector<double> X(1), temp(1);
    X[0] = m_wavelengthMin;
    wavelength->toTOF(X, temp, l1, l2, 0., 0, 0., 0.);
    tmin = X[0];
  }

  g_log.debug() << "tmin[" << workspaceIndex << "] " << tmin << "\n";

  return tmin;
}