diff --git a/Framework/API/src/ExperimentInfo.cpp b/Framework/API/src/ExperimentInfo.cpp index ed0c4bd80351a75b6035741bcee78bdc7432dc8e..943e0c3af2669fcabe96b63ae22dea107cca249c 100644 --- a/Framework/API/src/ExperimentInfo.cpp +++ b/Framework/API/src/ExperimentInfo.cpp @@ -924,6 +924,7 @@ size_t ExperimentInfo::numberOfDetectorGroups() const { const std::set<detid_t> & ExperimentInfo::detectorIDsInGroup(const size_t index) const { + // TODO NO! This is wrong! const auto detID = sptr_instrument->getDetectorIDs()[index]; return m_detgroups.at(detID); } diff --git a/Framework/MDAlgorithms/inc/MantidMDAlgorithms/MDNormDirectSC.h b/Framework/MDAlgorithms/inc/MantidMDAlgorithms/MDNormDirectSC.h index 7a5e3bea51ef257648242bff8303b7fafce0ddc9..09414c9b161118e729decf67f7415c3c15857d14 100644 --- a/Framework/MDAlgorithms/inc/MantidMDAlgorithms/MDNormDirectSC.h +++ b/Framework/MDAlgorithms/inc/MantidMDAlgorithms/MDNormDirectSC.h @@ -60,11 +60,6 @@ private: void calculateNormalization(const std::vector<coord_t> &otherValues, const Kernel::Matrix<coord_t> &affineTrans); - std::vector<detid_t> removeGroupedIDs(const API::ExperimentInfo &exptInfo, - const std::vector<detid_t> &detIDs); - Geometry::IDetector_const_sptr - getThetaPhi(const detid_t detID, const API::ExperimentInfo &exptInfo, - double &theta, double &phi); std::vector<Kernel::VMD> calculateIntersections(const double theta, const double phi); diff --git a/Framework/MDAlgorithms/inc/MantidMDAlgorithms/MDNormSCD.h b/Framework/MDAlgorithms/inc/MantidMDAlgorithms/MDNormSCD.h index b7d0f3ddfad0703bf1c72cc1f3ca919735e3998a..8ba22641dfb9b96503ca5fb2f1d8bf218b749886 100644 --- a/Framework/MDAlgorithms/inc/MantidMDAlgorithms/MDNormSCD.h +++ b/Framework/MDAlgorithms/inc/MantidMDAlgorithms/MDNormSCD.h @@ -63,11 +63,6 @@ private: const API::MatrixWorkspace &integrFlux, size_t sp, std::vector<double> &yValues) const; - std::vector<detid_t> removeGroupedIDs(const API::ExperimentInfo &exptInfo, - const std::vector<detid_t> &detIDs); - Geometry::IDetector_const_sptr - getThetaPhi(const detid_t detID, const API::ExperimentInfo &exptInfo, - double &theta, double &phi); std::vector<Kernel::VMD> calculateIntersections(const double theta, const double phi); diff --git a/Framework/MDAlgorithms/src/MDNormDirectSC.cpp b/Framework/MDAlgorithms/src/MDNormDirectSC.cpp index 1429869d8b117bc49e3b6aee45cea24f9688d968..d4d7a5a0733ce25e5be3fa6373bcded39537ae23 100644 --- a/Framework/MDAlgorithms/src/MDNormDirectSC.cpp +++ b/Framework/MDAlgorithms/src/MDNormDirectSC.cpp @@ -3,6 +3,7 @@ #include "MantidAPI/CommonBinsValidator.h" #include "MantidAPI/InstrumentValidator.h" #include "MantidAPI/Run.h" +#include "MantidAPI/SpectrumInfo.h" #include "MantidAPI/WorkspaceHistory.h" #include "MantidDataObjects/EventWorkspace.h" #include "MantidDataObjects/MDEventWorkspace.h" @@ -442,14 +443,11 @@ void MDNormDirectSC::calculateNormalization( } const double protonCharge = exptInfoZero.run().getProtonCharge(); - auto instrument = exptInfoZero.getInstrument(); - std::vector<detid_t> detIDs = instrument->getDetectorIDs(true); - // Prune out those that are part of a group and simply leave the head of the - // group - detIDs = removeGroupedIDs(exptInfoZero, detIDs); + const SpectrumInfo spectrumInfo(exptInfoZero); // Mapping - const int64_t ndets = static_cast<int64_t>(detIDs.size()); + const int64_t ndets = + static_cast<int64_t>(exptInfoZero.numberOfDetectorGroups()); bool haveSA = false; API::MatrixWorkspace_const_sptr solidAngleWS = getProperty("SolidAngleWorkspace"); @@ -464,22 +462,15 @@ void MDNormDirectSC::calculateNormalization( for (int64_t i = 0; i < ndets; i++) { PARALLEL_START_INTERUPT_REGION - const auto detID = detIDs[i]; - double theta(0.0), phi(0.0); - bool skip(false); - try { - auto spectrum = getThetaPhi(detID, exptInfoZero, theta, phi); - if (spectrum->isMonitor() || spectrum->isMasked()) - continue; - } catch ( - std::exception &) // detector might not exist or has no been included - // in grouping - { - skip = true; // Intel compiler has a problem with continue inside a catch - // inside openmp... - } - if (skip) + if (!spectrumInfo.hasDetectors(i) || spectrumInfo.isMonitor(i) || + spectrumInfo.isMasked(i)) { continue; + } + const auto &detector = spectrumInfo.detector(i); + double theta = detector.getTwoTheta(m_samplePos, m_beamDir); + double phi = detector.getPhi(); + // If the dtefctor is a group, this should be the ID of the first detector + const auto detID = detector.getID(); // Intersections auto intersections = calculateIntersections(theta, phi); @@ -538,63 +529,6 @@ void MDNormDirectSC::calculateNormalization( PARALLEL_CHECK_INTERUPT_REGION } -/** - * Checks for IDs that are actually part of the same group and just keeps one - * from the group. - * For a 1:1 map, none will be removed. - * @param exptInfo An ExperimentInfo object that defines the grouping - * @param detIDs A list of existing IDs - * @return A new list of IDs - */ -std::vector<detid_t> -MDNormDirectSC::removeGroupedIDs(const ExperimentInfo &exptInfo, - const std::vector<detid_t> &detIDs) { - const size_t ntotal = detIDs.size(); - std::vector<detid_t> singleIDs; - singleIDs.reserve(ntotal / 2); // reserve half. In the case of 1:1 it will - // double to the correct size once - std::set<detid_t> groupedIDs; - - for (auto curID : detIDs) { - if (groupedIDs.count(curID) == 1) - continue; // Already been processed - - try { - const auto &members = exptInfo.getGroupMembers(curID); - singleIDs.push_back(*members.begin()); - groupedIDs.insert(members.begin(), members.end()); - } catch (std::runtime_error &) { - singleIDs.push_back(curID); - } - } - - g_log.debug() << "Found " << singleIDs.size() << " spectra from " - << detIDs.size() << " IDs\n"; - return singleIDs; -} - -/** - * Get the theta and phi angles for the given ID. If the detector was part of a - * group, - * as defined in the ExperimentInfo object, then the theta/phi are for the whole - * set. - * @param detID A reference to a single ID - * @param exptInfo A reference to the ExperimentInfo that defines that - * spectrum->detector mapping - * @param theta [Output] Set to the theta angle for the detector (set) - * @param phi [Output] Set to the phi angle for the detector (set) - * @return A poiner to the Detector object for this spectrum as a whole - * (may be a single pixel or group) - */ -Geometry::IDetector_const_sptr -MDNormDirectSC::getThetaPhi(const detid_t detID, const ExperimentInfo &exptInfo, - double &theta, double &phi) { - const auto spectrum = exptInfo.getDetectorByID(detID); - theta = spectrum->getTwoTheta(m_samplePos, m_beamDir); - phi = spectrum->getPhi(); - return spectrum; -} - /** * Calculate the points of intersection for the given detector with cuboid * surrounding the diff --git a/Framework/MDAlgorithms/src/MDNormSCD.cpp b/Framework/MDAlgorithms/src/MDNormSCD.cpp index 55ea9c055e41d848fac82cab6e2955cdea2ffa36..4d59359dfa0a8e0fa180ea11dd2dd3e05b67391d 100644 --- a/Framework/MDAlgorithms/src/MDNormSCD.cpp +++ b/Framework/MDAlgorithms/src/MDNormSCD.cpp @@ -3,6 +3,7 @@ #include "MantidAPI/CommonBinsValidator.h" #include "MantidAPI/InstrumentValidator.h" #include "MantidAPI/Run.h" +#include "MantidAPI/SpectrumInfo.h" #include "MantidAPI/WorkspaceHistory.h" #include "MantidAPI/WorkspaceUnitValidator.h" #include "MantidDataObjects/EventWorkspace.h" @@ -392,14 +393,11 @@ void MDNormSCD::calculateNormalization( } const double protonCharge = exptInfoZero.run().getProtonCharge(); - auto instrument = exptInfoZero.getInstrument(); - std::vector<detid_t> detIDs = instrument->getDetectorIDs(true); - // Prune out those that are part of a group and simply leave the head of the - // group - detIDs = removeGroupedIDs(exptInfoZero, detIDs); + const SpectrumInfo spectrumInfo(exptInfoZero); // Mappings - const int64_t ndets = static_cast<int64_t>(detIDs.size()); + const int64_t ndets = + static_cast<int64_t>(exptInfoZero.numberOfDetectorGroups()); const detid2index_map fluxDetToIdx = integrFlux->getDetectorIDToWorkspaceIndexMap(); const detid2index_map solidAngDetToIdx = @@ -410,22 +408,15 @@ void MDNormSCD::calculateNormalization( for (int64_t i = 0; i < ndets; i++) { PARALLEL_START_INTERUPT_REGION - const auto detID = detIDs[i]; - double theta(0.0), phi(0.0); - bool skip(false); - try { - auto spectrum = getThetaPhi(detID, exptInfoZero, theta, phi); - if (spectrum->isMonitor() || spectrum->isMasked()) - continue; - } catch ( - std::exception &) // detector might not exist or has no been included - // in grouping - { - skip = true; // Intel compiler has a problem with continue inside a catch - // inside openmp... - } - if (skip) + if (!spectrumInfo.hasDetectors(i) || spectrumInfo.isMonitor(i) || + spectrumInfo.isMasked(i)) { continue; + } + const auto &detector = spectrumInfo.detector(i); + double theta = detector.getTwoTheta(m_samplePos, m_beamDir); + double phi = detector.getPhi(); + // If the dtefctor is a group, this should be the ID of the first detector + const auto detID = detector.getID(); // Intersections auto intersections = calculateIntersections(theta, phi); @@ -575,63 +566,6 @@ void MDNormSCD::calcIntegralsForIntersections( } } -/** - * Checks for IDs that are actually part of the same group and just keeps one - * from the group. - * For a 1:1 map, none will be removed. - * @param exptInfo An ExperimentInfo object that defines the grouping - * @param detIDs A list of existing IDs - * @return A new list of IDs - */ -std::vector<detid_t> -MDNormSCD::removeGroupedIDs(const ExperimentInfo &exptInfo, - const std::vector<detid_t> &detIDs) { - const size_t ntotal = detIDs.size(); - std::vector<detid_t> singleIDs; - singleIDs.reserve(ntotal / 2); // reserve half. In the case of 1:1 it will - // double to the correct size once - std::set<detid_t> groupedIDs; - - for (auto curID : detIDs) { - if (groupedIDs.count(curID) == 1) - continue; // Already been processed - - try { - const auto &members = exptInfo.getGroupMembers(curID); - singleIDs.push_back(*members.begin()); - groupedIDs.insert(members.begin(), members.end()); - } catch (std::runtime_error &) { - singleIDs.push_back(curID); - } - } - - g_log.debug() << "Found " << singleIDs.size() << " spectra from " - << detIDs.size() << " IDs\n"; - return singleIDs; -} - -/** - * Get the theta and phi angles for the given ID. If the detector was part of a - * group, - * as defined in the ExperimentInfo object, then the theta/phi are for the whole - * set. - * @param detID A reference to a single ID - * @param exptInfo A reference to the ExperimentInfo that defines that - * spectrum->detector mapping - * @param theta [Output] Set to the theta angle for the detector (set) - * @param phi [Output] Set to the phi angle for the detector (set) - * @return A poiner to the Detector object for this spectrum as a whole - * (may be a single pixel or group) - */ -Geometry::IDetector_const_sptr -MDNormSCD::getThetaPhi(const detid_t detID, const ExperimentInfo &exptInfo, - double &theta, double &phi) { - const auto spectrum = exptInfo.getDetectorByID(detID); - theta = spectrum->getTwoTheta(m_samplePos, m_beamDir); - phi = spectrum->getPhi(); - return spectrum; -} - /** * Calculate the points of intersection for the given detector with cuboid * surrounding the