/** Convert the X range given into the unit of the input workspace * @param index :: The current spectrum index * @param startX :: Returns the start of the range in the workspace's unit * @param endX :: Returns the end of the range in the workspace's unit */ void RemoveBins::transformRangeUnit(const int& index, double& startX, double& endX) { const Kernel::Unit_sptr inputUnit = m_inputWorkspace->getAxis(0)->unit(); // First check for a 'quick' conversion double factor,power; if ( m_rangeUnit->quickConversion(*inputUnit,factor,power) ) { startX = factor * std::pow(m_startX,power); endX = factor * std::pow(m_endX,power); } else { double l1,l2,theta; this->calculateDetectorPosition(index,l1,l2,theta); std::vector<double> endPoints; endPoints.push_back(startX); endPoints.push_back(endX); std::vector<double> emptyVec; m_rangeUnit->toTOF(endPoints,emptyVec,l1,l2,theta,0,0.0,0.0); inputUnit->fromTOF(endPoints,emptyVec,l1,l2,theta,0,0.0,0.0); startX = endPoints.front(); endX = endPoints.back(); } if (startX > endX) { const double temp = startX; startX = endX; endX = temp; } g_log.debug() << "For index " << index << ", X range given corresponds to " << startX << "-" << endX << " in workspace's unit" << std::endl; return; }
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; }
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; }
void PawleyFunction::setMatrixWorkspace( boost::shared_ptr<const MatrixWorkspace> workspace, size_t wi, double startX, double endX) { if (workspace) { Axis *xAxis = workspace->getAxis(wi); Kernel::Unit_sptr wsUnit = xAxis->unit(); if (boost::dynamic_pointer_cast<Units::Empty>(wsUnit) || boost::dynamic_pointer_cast<Units::dSpacing>(wsUnit)) { m_wsUnit = m_dUnit; } else { double factor, power; if (wsUnit->quickConversion(*m_dUnit, factor, power)) { m_wsUnit = wsUnit; } else { throw std::invalid_argument("Can not use quick conversion for unit."); } } } m_wrappedFunction->setMatrixWorkspace(workspace, wi, startX, endX); }