Skip to content

Commit

Permalink
Checkpointing work on PoldiIndexKnownCompounds.
Browse files Browse the repository at this point in the history
Refs #10247.
  • Loading branch information
Michael Wedel committed Sep 19, 2014
1 parent ad05828 commit 04749b4
Show file tree
Hide file tree
Showing 5 changed files with 725 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Code/Mantid/Framework/SINQ/CMakeLists.txt
Expand Up @@ -6,6 +6,7 @@ set ( SRC_FILES
src/PoldiCalculateSpectrum2D.cpp
src/PoldiCreatePeaksFromCell.cpp
src/PoldiFitPeaks1D.cpp
src/PoldiIndexKnownCompounds.cpp
src/PoldiLoadChopperSlits.cpp
src/PoldiLoadIPP.cpp
src/PoldiLoadLog.cpp
Expand Down Expand Up @@ -49,6 +50,7 @@ set ( INC_FILES
inc/MantidSINQ/PoldiCalculateSpectrum2D.h
inc/MantidSINQ/PoldiCreatePeaksFromCell.h
inc/MantidSINQ/PoldiFitPeaks1D.h
inc/MantidSINQ/PoldiIndexKnownCompounds.h
inc/MantidSINQ/PoldiLoadChopperSlits.h
inc/MantidSINQ/PoldiLoadIPP.h
inc/MantidSINQ/PoldiLoadLog.h
Expand Down Expand Up @@ -107,6 +109,7 @@ set ( TEST_FILES
PoldiDetectorFactoryTest.h
PoldiDetectorTest.h
PoldiFitPeaks1DTest.h
PoldiIndexKnownCompoundsTest.h
PoldiInstrumentAdapterTest.h
PoldiPeakCollectionTest.h
PoldiPeakSearchTest.h
Expand Down
134 changes: 134 additions & 0 deletions Code/Mantid/Framework/SINQ/inc/MantidSINQ/PoldiIndexKnownCompounds.h
@@ -0,0 +1,134 @@
#ifndef MANTID_SINQ_POLDIINDEXKNOWNCOMPOUNDS_H_
#define MANTID_SINQ_POLDIINDEXKNOWNCOMPOUNDS_H_

#include "MantidSINQ/DllConfig.h"
#include "MantidAPI/Algorithm.h"
#include "MantidSINQ/PoldiUtilities/PoldiPeakCollection.h"

namespace Mantid
{
namespace Poldi
{

struct PeakCandidate
{
PeakCandidate() :
unindexed(),
candidate(),
score(0.0),
candidateCollection(0) { }

PeakCandidate(const PoldiPeak_sptr &unindexedPeak, const PoldiPeak_sptr &candidatePeak, size_t index) :
unindexed(unindexedPeak),
candidate(candidatePeak),
candidateCollection(index)
{
double peakD = unindexed->d();
double fwhm = candidate->fwhm(PoldiPeak::AbsoluteD);
double sigma = fwhm / (2.0 * sqrt(2.0 * log(2.0)));
double difference = (peakD - candidate->d()) / sigma;
score = candidate->intensity() / (sigma * sqrt(2.0 * M_PI)) * exp(-0.5*difference*difference);
}

bool operator <(const PeakCandidate &other) const
{
return score < other.score;
}

PoldiPeak_sptr unindexed;
PoldiPeak_sptr candidate;
double score;
size_t candidateCollection;
};

/** PoldiIndexKnownCompounds : TODO: DESCRIPTION
Copyright &copy; 2014 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory
This file is part of Mantid.
Mantid is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
Mantid is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
File change history is stored at: <https://github.com/mantidproject/mantid>
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class MANTID_SINQ_DLL PoldiIndexKnownCompounds : public API::Algorithm
{
public:
PoldiIndexKnownCompounds();
virtual ~PoldiIndexKnownCompounds();

virtual const std::string name() const;
virtual int version() const;
virtual const std::string category() const;
virtual const std::string summary() const;

virtual std::map<std::string, std::string> validateInputs();

void setMeasuredPeaks(const PoldiPeakCollection_sptr &measuredPeaks);
void setExpectedPhases(const std::vector<PoldiPeakCollection_sptr> &expectedPhases);

void initializeUnindexedPeaks();
void initializeIndexedPeaks(const std::vector<PoldiPeakCollection_sptr> &expectedPhases);

protected:
std::vector<API::Workspace_sptr> getWorkspaces(const std::vector<std::string> &workspaceNames) const;
std::vector<PoldiPeakCollection_sptr> getPeakCollections(const std::vector<API::Workspace_sptr> &workspaces) const;

std::vector<double> getTolerances(size_t size) const;
std::vector<double> getContributions(size_t size) const;
std::vector<double> getNormalizedContributions(const std::vector<double> &contributions) const;

void assignIntensityEstimates(const std::vector<PoldiPeakCollection_sptr> &peakCollections, const std::vector<double> &normalizedContributions) const;
void assignIntensityEstimates(const PoldiPeakCollection_sptr &peakCollection, double contribution) const;

double getMultiplicity(const PoldiPeakCollection_sptr &peakCollection, const Kernel::V3D &hkl) const;

void assignFwhmEstimates(const std::vector<PoldiPeakCollection_sptr> &peakCollections, const std::vector<double> &tolerances) const;
void assignFwhmEstimates(const PoldiPeakCollection_sptr &peakCollection, double tolerance) const;


void indexPeaks(const PoldiPeakCollection_sptr &unindexed, const std::vector<PoldiPeakCollection_sptr> &knownCompounds);
void assignCandidates(const std::vector<PeakCandidate> &candidates);

std::vector<PeakCandidate> getPeakCandidates(const PoldiPeak_sptr &peak, const std::vector<PoldiPeakCollection_sptr> &candidateCollections) const;
bool isCandidate(const PoldiPeak_sptr &measuredPeak, const PoldiPeak_sptr &possibleCandidate) const;

std::vector<PeakCandidate> getAllCandidates(const PoldiPeakCollection_sptr &unindexed, const std::vector<PoldiPeakCollection_sptr> &knownCompounds);

bool inPeakSet(const std::set<PoldiPeak_sptr> &peakSet, const PoldiPeak_sptr &peak) const;
double fwhmToSigma(double fwhm) const;
double sigmaToFwhm(double sigma) const;

void assignPeakIndex(const PeakCandidate &candidate);


PoldiPeakCollection_sptr m_measuredPeaks;
std::vector<PoldiPeakCollection_sptr> m_expectedPhases;

PoldiPeakCollection_sptr m_unindexedPeaks;
std::vector<PoldiPeakCollection_sptr> m_indexedPeaks;

private:
void init();
void exec();


};


} // namespace Poldi
} // namespace Mantid

#endif /* MANTID_SINQ_POLDIINDEXKNOWNCOMPOUNDS_H_ */

0 comments on commit 04749b4

Please sign in to comment.