Commit 7b99955f authored by Janik Zikovsky's avatar Janik Zikovsky
Browse files

Refs #3008: More algos

parent 2288b60d
......@@ -107,7 +107,7 @@ private:
/// Loop over the workspace and determine the rebin parameters (Xmin,Xmax,step) for each group.
/// The result is stored in group2params
void determineRebinParameters();
int validateSpectrumInGroup(int64_t spectrum_number);
int validateSpectrumInGroup(specid_t spectrum_number);
/// Shared pointer to a mutable input workspace
API::MatrixWorkspace_sptr matrixInputW;
......@@ -121,15 +121,15 @@ private:
// This map does not need to be ordered, just a lookup for udet
/// typedef for the storage of the UDET-group mapping
typedef std::map<int64_t, int64_t> udet2groupmap;
typedef std::map<detid_t, int> udet2groupmap;
// This map needs to be ordered to process the groups in order.
/// typedef for the storage of each group's X vector
typedef std::map<int64_t, boost::shared_ptr<MantidVec> > group2vectormap;
typedef std::map<int, boost::shared_ptr<MantidVec> > group2vectormap;
/// Map from udet to group
udet2groupmap udet2group;
/// The list of group numbers
std::vector<int64_t> groupAtWorkspaceIndex;
std::vector<int> groupAtWorkspaceIndex;
/// Map from the group number to the group's X vector
group2vectormap group2xvector;
/// Map from the group number to the group's summed weight vector
......
......@@ -76,7 +76,7 @@ private:
void exec();
void getGeometry(API::MatrixWorkspace_const_sptr WS, int64_t mon0Spec, int64_t mon1Spec, double &monitor0Dist, double &monitor1Dist) const;
std::vector<int64_t> getMonitorSpecIndexs(API::MatrixWorkspace_const_sptr WS, int64_t specNum1, int64_t specNum2) const;
std::vector<size_t> getMonitorSpecIndexs(API::MatrixWorkspace_const_sptr WS, int64_t specNum1, int64_t specNum2) const;
double timeToFly(double s, double E_KE) const;
double getPeakCentre(API::MatrixWorkspace_const_sptr WS, const int64_t monitIn, const double peakTime);
void extractSpec(int64_t specInd, double start, double end);
......
......@@ -129,10 +129,10 @@ protected:
void readGroupingFile(const std::string& groupingFilename);
/// Grouping map
Mantid::API::IndexToIndexMap detId_to_group;
std::map<detid_t, int> detId_to_group;
/// Map from detector ID to the offset (used in alignment)
std::map<int64_t, double> detId_to_offset;
std::map<detid_t, double> detId_to_offset;
/// Pointer to the raw ghost map info
std::vector<GhostDestinationValue> * rawGhostMap;
......@@ -147,10 +147,10 @@ protected:
Mantid::API::MatrixWorkspace_const_sptr inputW;
/// Mapping between indices
Mantid::API::IndexToIndexMap * input_detectorIDToWorkspaceIndexMap;
detid2index_map * input_detectorIDToWorkspaceIndexMap;
/// Map where KEY = pixel ID; value = tof to D conversion factor (tof * factor = d).
std::map<int64_t, double> * tof_to_d;
std::map<detid_t, double> * tof_to_d;
};
} // namespace Algorithms
......
......@@ -49,10 +49,9 @@ namespace Mantid
{
public:
explicit InputWSDetectorInfo(API::MatrixWorkspace_sptr input);
bool aDetecIsMaskedinSpec(int64_t SpecIndex) const;
void maskAllDetectorsInSpec(int64_t SpecIndex);
int64_t getSpecNum(int64_t SpecIndex) const;
std::vector<int64_t> getDetectors(int64_t SpecIndex) const;
bool aDetecIsMaskedinSpec(specid_t SpecIndex) const;
void maskAllDetectorsInSpec(specid_t SpecIndex);
std::vector<detid_t> getDetectors(specid_t SpecIndex) const;
protected:
/// a pointer the workspace with the detector information
const API::MatrixWorkspace_sptr m_Input;
......
......@@ -67,10 +67,10 @@ private:
virtual void initDocs();
#ifndef HAS_UNORDERED_MAP_H
/// Typedef for detector to value map
typedef std::map<int64_t,bool> udet2valuem;
typedef std::map<detid_t,bool> udet2valuem;
#else
// Typedef for det to value map
typedef std::tr1::unordered_map<int64_t,bool> udet2valuem;
typedef std::tr1::unordered_map<detid_t,bool> udet2valuem;
#endif
/// A map of detector numbers to mask boolean
udet2valuem umap;
......
......@@ -973,7 +973,7 @@ namespace Mantid
//Didn't find it. Try to use the RHS map.
//First, we have to get the (single) detector ID of the LHS
std::vector<int64_t>::const_iterator lhsDets_it = lhsDets.begin();
std::vector<detid_t>::const_iterator lhsDets_it = lhsDets.begin();
int64_t lhs_detector_ID = *lhsDets_it;
//Now we use the RHS map to find it. This only works if both the lhs and rhs have 1 detector per pixel
......
......@@ -287,14 +287,15 @@ void ConjoinWorkspaces::checkForOverlap(API::MatrixWorkspace_const_sptr ws1, API
// Loop through the first workspace adding all the spectrum numbers & UDETS to a set
const Axis* axis1 = ws1->getAxis(1);
const SpectraDetectorMap& specmap1 = ws1->spectraMap();
std::set<int64_t> spectra, detectors;
const int64_t& nhist1 = ws1->getNumberHistograms();
for (int64_t i = 0; i < nhist1; ++i)
std::set<specid_t> spectra;
std::set<detid_t> detectors;
const size_t& nhist1 = ws1->getNumberHistograms();
for (size_t i = 0; i < nhist1; ++i)
{
const int64_t spectrum = axis1->spectraNo(i);
const specid_t spectrum = axis1->spectraNo(i);
spectra.insert(spectrum);
const std::vector<int64_t> dets = specmap1.getDetectors(spectrum);
std::vector<int64_t>::const_iterator it;
const std::vector<detid_t> dets = specmap1.getDetectors(spectrum);
std::vector<detid_t>::const_iterator it;
for (it = dets.begin(); it != dets.end(); ++it)
{
detectors.insert(*it);
......@@ -304,10 +305,10 @@ void ConjoinWorkspaces::checkForOverlap(API::MatrixWorkspace_const_sptr ws1, API
// Now go throught the spectrum numbers & UDETS in the 2nd workspace, making sure that there's no overlap
const Axis* axis2 = ws2->getAxis(1);
const SpectraDetectorMap& specmap2 = ws2->spectraMap();
const int64_t& nhist2 = ws2->getNumberHistograms();
for (int64_t j = 0; j < nhist2; ++j)
const size_t& nhist2 = ws2->getNumberHistograms();
for (size_t j = 0; j < nhist2; ++j)
{
const int64_t spectrum = axis2->spectraNo(j);
const specid_t spectrum = axis2->spectraNo(j);
if (checkSpectra)
{
if ( spectrum > 0 && spectra.find(spectrum) != spectra.end() )
......@@ -316,8 +317,8 @@ void ConjoinWorkspaces::checkForOverlap(API::MatrixWorkspace_const_sptr ws1, API
throw std::invalid_argument("The input workspaces have overlapping spectrum numbers");
}
}
std::vector<int64_t> dets = specmap2.getDetectors(spectrum);
std::vector<int64_t>::const_iterator it;
std::vector<detid_t> dets = specmap2.getDetectors(spectrum);
std::vector<detid_t>::const_iterator it;
for (it = dets.begin(); it != dets.end(); ++it)
{
if ( detectors.find(*it) != detectors.end() )
......
......@@ -207,11 +207,11 @@ void DetectorEfficiencyCor::correctForEfficiency(int64_t spectraIn)
const MantidVec eValues = m_inputWS->readE(spectraIn);
// get a pointer to the detectors that created the spectrum
const int64_t specNum = m_inputWS->getAxis(1)->spectraNo(spectraIn);
const std::vector<int64_t> dets = m_inputWS->spectraMap().getDetectors(specNum);
const specid_t specNum = m_inputWS->getAxis(1)->spectraNo(spectraIn);
const std::vector<detid_t> dets = m_inputWS->spectraMap().getDetectors(specNum);
std::vector<int64_t>::const_iterator it = dets.begin();
std::vector<int64_t>::const_iterator iend = dets.end();
std::vector<detid_t>::const_iterator it = dets.begin();
std::vector<detid_t>::const_iterator iend = dets.end();
if ( it == iend )
{
throw Exception::NotFoundError("No detectors found", spectraIn);
......
......@@ -468,23 +468,23 @@ void DiffractionFocussing2::execEvent()
* @param spectrum_number :: The spectrum number in the workspace
* @return Group number if successful otherwise return -1
*/
int DiffractionFocussing2::validateSpectrumInGroup(int64_t spectrum_number)
int DiffractionFocussing2::validateSpectrumInGroup(specid_t spectrum_number)
{
// Get the spectra to detector map
const API::SpectraDetectorMap& spectramap = matrixInputW->spectraMap();
const std::vector<int64_t> dets = spectramap.getDetectors(spectrum_number);
const std::vector<detid_t> dets = spectramap.getDetectors(spectrum_number);
if (dets.empty()) // Not in group
{
std::cout << spectrum_number << " <- this spectrum is empty!\n";
return -1;
}
std::vector<int64_t>::const_iterator it = dets.begin();
std::vector<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
return -1;
const int64_t group = (*mapit).second;
int64_t new_group;
const int group = (*mapit).second;
int new_group;
for (it + 1; it != dets.end(); it++) // Loop other all other udets
{
mapit = udet2group.find((*it));
......
......@@ -105,12 +105,12 @@ namespace Mantid
{
++countSpec;
y = deadValue;
const int64_t specNo = specAxis->spectraNo(i);
const specid_t specNo = specAxis->spectraNo(i);
// Write the spectrum number to file
file << i << " " << specNo;
// Get the list of detectors for this spectrum and iterate over
const std::vector<int64_t> dets = specMap.getDetectors(specNo);
std::vector<int64_t>::const_iterator it;
const std::vector<detid_t> dets = specMap.getDetectors(specNo);
std::vector<detid_t>::const_iterator it;
for (it = dets.begin(); it != dets.end(); ++it)
{
// Write the detector ID to file, log & the FoundDead output property
......
......@@ -101,7 +101,7 @@ void GetEi::exec()
g_log.information() << "Based on the user selected energy the second peak will be searched for at TOF " << peakLoc1 << " micro seconds +/-" << boost::lexical_cast<std::string>(100.0*HALF_WINDOW) << "%\n";
// get the histograms created by the monitors
std::vector<int64_t> indexes = getMonitorSpecIndexs(inWS, mon1Spec, mon2Spec);
std::vector<size_t> indexes = getMonitorSpecIndexs(inWS, mon1Spec, mon2Spec);
g_log.information() << "Looking for a peak in the first monitor spectrum, spectra index " << indexes[0] << std::endl;
double t_monitor0 = getPeakCentre(inWS, indexes[0], peakLoc0);
......@@ -135,7 +135,7 @@ void GetEi::getGeometry(API::MatrixWorkspace_const_sptr WS, int64_t mon0Spec, in
const IObjComponent_sptr source = WS->getInstrument()->getSource();
// retrieve a pointer to the first detector and get its distance
std::vector<int64_t> dets = WS->spectraMap().getDetectors(mon0Spec);
std::vector<detid_t> dets = WS->spectraMap().getDetectors(mon0Spec);
if ( dets.size() != 1 )
{
g_log.error() << "The detector for spectrum number " << mon0Spec << " was either not found or is a group, grouped monitors are not supported by this algorithm\n";
......@@ -163,12 +163,12 @@ void GetEi::getGeometry(API::MatrixWorkspace_const_sptr WS, int64_t mon0Spec, in
* @return the indexes of the histograms created by the detector whose ID were passed
* @throw NotFoundError if one of the requested spectrum numbers was not found in the workspace
*/
std::vector<int64_t> GetEi::getMonitorSpecIndexs(API::MatrixWorkspace_const_sptr WS, int64_t specNum1, int64_t specNum2) const
std::vector<size_t> GetEi::getMonitorSpecIndexs(API::MatrixWorkspace_const_sptr WS, int64_t specNum1, int64_t specNum2) const
{// getting spectra numbers from detector IDs is hard because the map works the other way, getting index numbers from spectra numbers has the same problem and we are about to do both
std::vector<int64_t> specInds;
std::vector<size_t> specInds;
// get the index number of the histogram for the first monitor
std::vector<int64_t> specNumTemp(&specNum1, &specNum1+1);
std::vector<specid_t> specNumTemp(&specNum1, &specNum1+1);
WS->getIndicesFromSpectra(specNumTemp, specInds);
if ( specInds.size() != 1 )
{// the monitor spectrum isn't present in the workspace, we can't continue from here
......@@ -177,7 +177,7 @@ std::vector<int64_t> GetEi::getMonitorSpecIndexs(API::MatrixWorkspace_const_sptr
}
// nowe the second monitor
std::vector<int64_t> specIndexTemp;
std::vector<size_t> specIndexTemp;
specNumTemp[0] = specNum2;
WS->getIndicesFromSpectra(specNumTemp, specIndexTemp);
if ( specIndexTemp.size() != 1 )
......
......@@ -141,7 +141,7 @@ namespace Mantid
for (size_t inPixelId = 0; inPixelId < numInPixels; inPixelId++)
{
//Find the input workspace index corresponding to this input Pixel ID
IndexToIndexMap::iterator it;
detid2index_map::iterator it;
it = input_detectorIDToWorkspaceIndexMap->find(inPixelId);
if (it != input_detectorIDToWorkspaceIndexMap->end())
......
......@@ -32,11 +32,11 @@ InputWSDetectorInfo::InputWSDetectorInfo(API::MatrixWorkspace_sptr input) :
* @param SpecIndex :: The number of spectrum, starting at zero is passed to axis::spectraNo(.)
* @return True if there is a masked detector, otherwise false
*/
bool InputWSDetectorInfo::aDetecIsMaskedinSpec(int64_t SpecIndex) const
bool InputWSDetectorInfo::aDetecIsMaskedinSpec(specid_t SpecIndex) const
{
const std::vector<int64_t> dets = getDetectors(SpecIndex);
const std::vector<detid_t> dets = getDetectors(SpecIndex);
// we are going to go through all of them, if you know this is not neccessary then change it
std::vector<int64_t>::const_iterator it;
std::vector<detid_t>::const_iterator it;
for ( it = dets.begin(); it != dets.end(); ++it)
{
if (m_RInstru->getDetector(*it).get()->isMasked()) return true;
......@@ -50,11 +50,11 @@ bool InputWSDetectorInfo::aDetecIsMaskedinSpec(int64_t SpecIndex) const
* @throw IndexError if the spectra index number isn't in the workspace
* @throw NotFoundError if we can't get a pointer to the detector that the detector map says is linked to the spectrum
*/
void InputWSDetectorInfo::maskAllDetectorsInSpec(int64_t SpecIndex)
void InputWSDetectorInfo::maskAllDetectorsInSpec(specid_t SpecIndex)
{
std::vector<int64_t> dets = getDetectors(SpecIndex);
std::vector<detid_t> dets = getDetectors(SpecIndex);
// there may be many detectors that are responsible for the spectrum, loop through them
std::vector<int64_t>::const_iterator it;
std::vector<detid_t>::const_iterator it;
int64_t missing = 0;
for ( it = dets.begin(); it != dets.end(); ++it)
{
......@@ -81,19 +81,15 @@ void InputWSDetectorInfo::maskAllDetectorsInSpec(int64_t SpecIndex)
SpecIndex);
}
}
/// convert spectrum index to spectrum number
int64_t InputWSDetectorInfo::getSpecNum(int64_t SpecIndex) const
{
return m_Input->getAxis(1)->spectraNo(SpecIndex);
}
/**A spectrum can be generated by one or many detectors, this function returns their IDs
* @param SpecIndex :: The number of the spectrum as listed in memory, starting at zero, is passed to axis::spectraNo(int)
* @return An array of detector identification numbers
* @throw IndexError if you give it an index number that's out of range
*/
std::vector<int64_t> InputWSDetectorInfo::getDetectors(int64_t SpecIndex) const
std::vector<detid_t> InputWSDetectorInfo::getDetectors(specid_t SpecIndex) const
{
return m_Input->spectraMap().getDetectors(getSpecNum(SpecIndex));
return m_Input->spectraMap().getDetectors(m_Input->getAxis(1)->spectraNo(SpecIndex));
}
}// end namespace Algorithms
......
......@@ -74,15 +74,15 @@ void MaskDetectorsIf::init()
void MaskDetectorsIf::exec()
{
retrieveProperties();
const int64_t nspec=inputW->getNumberHistograms();
const size_t nspec=inputW->getNumberHistograms();
const API::SpectraDetectorMap& spectramap = inputW->spectraMap();
for (int64_t i=0;i<nspec;++i)
for (size_t i=0;i<nspec;++i)
{
// Get the spectrum number
const int64_t spec = inputW->getAxis(1)->spectraNo(i);
const specid_t spec = inputW->getAxis(1)->spectraNo(i);
// Get the list of udets contributing to this spectra
std::vector<int64_t> dets = spectramap.getDetectors(spec);
std::vector<detid_t> dets = spectramap.getDetectors(spec);
if (dets.empty())
continue;
else
......@@ -91,7 +91,7 @@ void MaskDetectorsIf::exec()
if (compar_f(val,value))
{
for (unsigned int j=0;j<dets.size();++j)
umap.insert(std::make_pair<int64_t,bool>(dets[j],select_on));
umap.insert(std::make_pair<detid_t,bool>(dets[j],select_on));
}
}
double p=static_cast<double>(i)/static_cast<double>(nspec);
......
......@@ -143,9 +143,9 @@ void MergeRuns::buildAdditionTables()
//This is the workspace against which everything will be added
EventWorkspace_sptr lhs = inEventWS[0];
int64_t lhs_nhist = lhs->getNumberHistograms();
size_t lhs_nhist = lhs->getNumberHistograms();
IndexToIndexMap * lhs_det_to_wi = NULL;
detid2index_map * lhs_det_to_wi = NULL;
try
{
lhs_det_to_wi = lhs->getDetectorIDToWorkspaceIndexMap(true);
......@@ -155,7 +155,7 @@ void MergeRuns::buildAdditionTables()
//If it fails, then there are some grouped detector IDs, and the map cannot exist
}
for (int64_t workspaceNum=1; workspaceNum < static_cast<int64_t>(inEventWS.size()); workspaceNum++)
for (size_t workspaceNum=1; workspaceNum < inEventWS.size(); workspaceNum++)
{
//Get the workspace
EventWorkspace_sptr ews = inEventWS[workspaceNum];
......@@ -166,19 +166,19 @@ void MergeRuns::buildAdditionTables()
AdditionTable * table = new AdditionTable();
//Loop through the input workspace indices
int64_t nhist = ews->getNumberHistograms();
for (int64_t inWI = 0; inWI < nhist; inWI++)
size_t nhist = ews->getNumberHistograms();
for (size_t inWI = 0; inWI < nhist; inWI++)
{
//Get the set of detectors in the output
std::set<int64_t>& inDets = ews->getEventList(inWI).getDetectorIDs();
std::set<detid_t>& inDets = ews->getEventList(inWI).getDetectorIDs();
bool done=false;
//First off, try to match the workspace indices. Most times, this will be ok right away.
int64_t outWI = inWI;
size_t outWI = inWI;
if (outWI < lhs_nhist) //don't go out of bounds
{
std::set<int64_t>& outDets = lhs->getEventList(outWI).getDetectorIDs();
std::set<detid_t>& outDets = lhs->getEventList(outWI).getDetectorIDs();
//Checks that inDets is a subset of outDets
if (std::includes(outDets.begin(), outDets.end(), inDets.begin(), inDets.end()))
......@@ -194,11 +194,11 @@ void MergeRuns::buildAdditionTables()
//Didn't find it. Try to use the LHS map.
//First, we have to get the (single) detector ID of the RHS
std::set<int64_t>::iterator inDets_it = inDets.begin();
int64_t rhs_detector_ID = *inDets_it;
std::set<detid_t>::iterator inDets_it = inDets.begin();
detid_t rhs_detector_ID = *inDets_it;
//Now we use the LHS map to find it. This only works if both the lhs and rhs have 1 detector per pixel
IndexToIndexMap::iterator map_it = lhs_det_to_wi->find(rhs_detector_ID);
detid2index_map::iterator map_it = lhs_det_to_wi->find(rhs_detector_ID);
if (map_it != lhs_det_to_wi->end())
{
outWI = map_it->second; //This is the workspace index in the LHS that matched rhs_detector_ID
......@@ -219,7 +219,7 @@ void MergeRuns::buildAdditionTables()
// NOTE: This can be SUPER SLOW!
for (outWI=0; outWI < lhs_nhist; outWI++)
{
std::set<int64_t>& outDets2 = lhs->getEventList(outWI).getDetectorIDs();
std::set<detid_t>& outDets2 = lhs->getEventList(outWI).getDetectorIDs();
//Another subset check
if (std::includes(outDets2.begin(), outDets2.end(), inDets.begin(), inDets.end()))
{
......
......@@ -150,7 +150,7 @@ API::MatrixWorkspace_sptr NormaliseToMonitor::getInWSMonitorSpectrum(API::Matrix
{
throw std::runtime_error("MonitorSpectrum must not be negative");
}
SpectraAxis::spec2index_map specs;
spec2index_map specs;
const SpectraAxis* axis = dynamic_cast<const SpectraAxis*>(inputWorkspace->getAxis(1));
if ( ! axis)
{
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment