/** Creates a mapping based on a fixed number of groups for a given instrument *component * * @param compName Name of component in instrument * @param numGroups Number of groups to group detectors into * @param inst Pointer to instrument * @param prog Progress reporter * @returns :: Map of detector IDs to group number */ std::map<detid_t, int> makeGroupingByNumGroups(const std::string compName, int numGroups, Instrument_const_sptr inst, Progress &prog) { std::map<detid_t, int> detIDtoGroup; // Get detectors for given instument component std::vector<IDetector_const_sptr> detectors; inst->getDetectorsInBank(detectors, compName); size_t numDetectors = detectors.size(); // Sanity check for following calculation if (numGroups > static_cast<int>(numDetectors)) throw std::runtime_error("Number of groups must be less than or " "equal to number of detectors"); // Calculate number of detectors per group int detectorsPerGroup = static_cast<int>(numDetectors) / numGroups; // Map detectors to group for (unsigned int detIndex = 0; detIndex < numDetectors; detIndex++) { int detectorID = detectors[detIndex]->getID(); int groupNum = (detIndex / detectorsPerGroup) + 1; // Ignore any detectors the do not fit nicely into the group divisions if (groupNum <= numGroups) detIDtoGroup[detectorID] = groupNum; prog.report(); } return detIDtoGroup; }