コード例 #1
0
// calculate time from sample to detector
void ModeratorTzeroLinear::calculateTfLi(const SpectrumInfo &spectrumInfo,
                                         size_t i, double &t_f, double &L_i) {
  static const double convFact = 1.0e-6 * sqrt(2 * PhysicalConstants::meV /
                                               PhysicalConstants::NeutronMass);
  static const double TfError = -1.0; // signal error when calculating final
                                      // time

  if (!spectrumInfo.hasDetectors(i)) {
    t_f = TfError;
    return;
  }

  if (spectrumInfo.isMonitor(i)) {
    L_i = spectrumInfo.sourcePosition().distance(spectrumInfo.position(i));
    t_f = 0.0; // t_f=0.0 since there is no sample to detector path
  } else {
    L_i = spectrumInfo.l1();
    // Get final energy E_f, final velocity v_f
    auto wsProp = spectrumInfo.detector(i).getNumberParameter("Efixed");
    if (!wsProp.empty()) {
      double E_f = wsProp.at(0);         //[E_f]=meV
      double v_f = convFact * sqrt(E_f); //[v_f]=meter/microsec
      t_f = spectrumInfo.l2(i) / v_f;
    } else {
      g_log.debug() << "Efixed not found for detector " << i << '\n';
      t_f = TfError;
    }
  }
}
コード例 #2
0
ファイル: RemoveLowResTOF.cpp プロジェクト: mganeva/mantid
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;
}