Skip to content

Commit

Permalink
DiffractionFocussing serial speedups. Refs #4208.
Browse files Browse the repository at this point in the history
Moved who calculates whether or not a pixel is masked and replaced a map with a vector.
  • Loading branch information
peterfpeterson committed Dec 8, 2011
1 parent 2ae1451 commit 05392d6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class DLLExport DiffractionFocussing2: public API::Algorithm
/// typedef for the storage of each group's X vector
typedef std::map<int, boost::shared_ptr<MantidVec> > group2vectormap;
/// Map from udet to group
udet2groupmap udet2group;
std::vector<int> udet2group;
/// The list of group numbers
std::vector<int> groupAtWorkspaceIndex;
/// Map from the group number to the group's X vector
Expand Down
40 changes: 17 additions & 23 deletions Code/Mantid/Framework/Algorithms/src/DiffractionFocussing2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ void DiffractionFocussing2::exec()
progress(0.2, "Determine Rebin Params");
udet2group.clear();
// std::cout << "(1) nGroups " << nGroups << "\n";
groupWS->makeDetectorIDToGroupMap(udet2group, nGroups);
groupWS->makeDetectorIDToGroupVector(udet2group, nGroups);
// std::cout << "(2) nGroups " << nGroups << "\n";

//This finds the rebin parameters (used in both versions)
Expand Down Expand Up @@ -520,9 +520,6 @@ void DiffractionFocussing2::execEvent()
*/
int DiffractionFocussing2::validateSpectrumInGroup(size_t wi)
{
// Get the spectra to detector map
//const std::set<detid_t> & dets
// = ((MatrixWorkspace_const_sptr)m_matrixInputW)->getSpectrum(wi)->getDetectorIDs();
const std::set<detid_t> & dets = m_matrixInputW->getSpectrum(wi)->getDetectorIDs();
if (dets.empty()) // Not in group
{
Expand All @@ -531,19 +528,14 @@ int DiffractionFocussing2::validateSpectrumInGroup(size_t wi)
}

std::set<detid_t>::const_iterator it = dets.begin();
udet2groupmap::const_iterator mapit = udet2group.find((*it)); //Find the first udet
if (mapit == udet2group.end()) // The first udet that contributes to this spectra is not assigned to a group
if (*it < 0) // bad pixel id
return -1;
const int group = (*mapit).second;
int new_group;

const int group = udet2group[*it];
it++;
for (; it != dets.end(); it++) // Loop other all other udets
for (; it != dets.end(); ++it) // Loop other all other udets
{
mapit = udet2group.find((*it));
if (mapit == udet2group.end()) // Group not assigned
return -1;
new_group = (*mapit).second;
if (new_group != group) // At least one udet does not belong to the same group
if (udet2group[*it] != group)
return -1;
}

Expand Down Expand Up @@ -579,12 +571,10 @@ void DiffractionFocussing2::determineRebinParameters()

// whether or not to bother checking for a mask
bool checkForMask = false;
{ // get rid of these objects quickly
Geometry::Instrument_const_sptr instrument = m_matrixInputW->getInstrument();
if (instrument != NULL)
{
checkForMask = ((instrument->getSource() != NULL) && (instrument->getSample() != NULL));
}
Geometry::Instrument_const_sptr instrument = m_matrixInputW->getInstrument();
if (instrument != NULL)
{
checkForMask = ((instrument->getSource() != NULL) && (instrument->getSample() != NULL));
}

groupAtWorkspaceIndex.resize(nHist);
Expand All @@ -594,24 +584,28 @@ void DiffractionFocussing2::determineRebinParameters()
groupAtWorkspaceIndex[wi] = group;
if (group == -1)
continue;

// the spectrum is the real thing we want to work with
const ISpectrum * spec = m_matrixInputW->getSpectrum(wi);

if (checkForMask)
{
Geometry::IDetector_const_sptr det = m_matrixInputW->getDetector(static_cast<size_t>(wi));
if ( (det == NULL) || (det->isMasked()) )
if (instrument->isDetectorMasked(spec->getDetectorIDs()))
{
groupAtWorkspaceIndex[wi] = -1;
continue;
}
}
gpit = group2minmax.find(group);

// Create the group range in the map if it isn't already there
if (gpit == group2minmax.end())
{
gpit = group2minmax.insert(std::make_pair(group,std::make_pair(BIGGEST,-1.*BIGGEST))).first;
}
const double min = (gpit->second).first;
const double max = (gpit->second).second;
const MantidVec& X = m_matrixInputW->readX(wi);
const MantidVec& X = spec->readX();
double temp = X.front();
if (temp < (min)) //New Xmin found
(gpit->second).first = temp;
Expand Down

0 comments on commit 05392d6

Please sign in to comment.