/** * Executes the algorithm * */ void ConvertToConstantL2::exec() { initWorkspaces(); // Calculate the number of spectra in this workspace const size_t numberOfSpectra = m_inputWS->getNumberHistograms(); API::Progress prog(this, 0.0, 1.0, numberOfSpectra); int64_t numberOfSpectra_i = static_cast<int64_t>(numberOfSpectra); // cast to make openmp happy const auto &inputSpecInfo = m_inputWS->spectrumInfo(); auto &outputDetInfo = m_outputWS->mutableDetectorInfo(); // Loop over the histograms (detector spectra) PARALLEL_FOR_IF(Kernel::threadSafe(*m_inputWS, *m_outputWS)) for (int64_t i = 0; i < numberOfSpectra_i; ++i) { PARALLEL_START_INTERUPT_REGION m_outputWS->setHistogram(i, m_inputWS->histogram(i)); // Should not move the monitors if (inputSpecInfo.isMonitor(i)) continue; // Throw if detector doesn't exist or is a group if (!inputSpecInfo.hasUniqueDetector(i)) { const auto errorMsg = boost::format("The detector for spectrum number %d was either not " "found, or is a group.") % i; throw std::runtime_error(errorMsg.str()); } // subract the diference in l2 double thisDetL2 = inputSpecInfo.l2(i); double deltaL2 = std::abs(thisDetL2 - m_l2); double deltaTOF = calculateTOF(deltaL2); deltaTOF *= 1e6; // micro sec // position - set all detector distance to constant l2 double r, theta, phi; V3D oldPos = inputSpecInfo.position(i); oldPos.getSpherical(r, theta, phi); V3D newPos; newPos.spherical(m_l2, theta, phi); const auto detIndex = inputSpecInfo.spectrumDefinition(i)[0]; outputDetInfo.setPosition(detIndex, newPos); m_outputWS->mutableX(i) -= deltaTOF; prog.report("Aligning elastic line..."); PARALLEL_END_INTERUPT_REGION } // end for i PARALLEL_CHECK_INTERUPT_REGION this->setProperty("OutputWorkspace", this->m_outputWS); }
std::pair<int, double> ConvertEmptyToTof::findAverageEppAndEpTof(const std::map<int, int> &eppMap) { double l1 = getL1(m_inputWS); double wavelength = getPropertyFromRun<double>(m_inputWS, "wavelength"); std::vector<double> epTofList; std::vector<int> eppList; double firstL2 = getL2(m_inputWS, eppMap.begin()->first); for (const auto &epp : eppMap) { double l2 = getL2(m_inputWS, epp.first); if (!areEqual(l2, firstL2, 0.0001)) { g_log.error() << "firstL2=" << firstL2 << " , " << "l2=" << l2 << '\n'; throw std::runtime_error("All the pixels for selected spectra must have " "the same distance from the sample!"); } else { firstL2 = l2; } epTofList.push_back( (calculateTOF(l1, wavelength) + calculateTOF(l2, wavelength)) * 1e6); // microsecs eppList.push_back(epp.first); g_log.debug() << "WS index = " << epp.first << ", l1 = " << l1 << ", l2 = " << l2 << ", TOF(l1+l2) = " << *(epTofList.end() - 1) << '\n'; } double averageEpTof = std::accumulate(epTofList.begin(), epTofList.end(), 0.0) / static_cast<double>(epTofList.size()); int averageEpp = roundUp( static_cast<double>(std::accumulate(eppList.begin(), eppList.end(), 0)) / static_cast<double>(eppList.size())); g_log.debug() << "Average epp=" << averageEpp << " , Average epTof=" << averageEpTof << '\n'; return std::make_pair(averageEpp, averageEpTof); }