Skip to content

Commit

Permalink
Refs #9445. PoldiPeakCollection stores profile information
Browse files Browse the repository at this point in the history
PoldiPeakCollection can now store information about which profile
function has been used to fit the peak parameters. This is required for
possible peak integration in PoldiCalculateSpectrum2D.
  • Loading branch information
Michael Wedel committed May 21, 2014
1 parent 16fe428 commit 90e6ea4
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 15 deletions.
Expand Up @@ -49,7 +49,7 @@ class MANTID_SINQ_DLL PoldiPeakCollection
Integral
};

PoldiPeakCollection();
PoldiPeakCollection(IntensityType intensityType = Maximum);
PoldiPeakCollection(TableWorkspace_sptr workspace);
virtual ~PoldiPeakCollection() {}

Expand All @@ -58,23 +58,34 @@ class MANTID_SINQ_DLL PoldiPeakCollection
void addPeak(PoldiPeak_sptr newPeak);
PoldiPeak_sptr peak(size_t index) const;

TableWorkspace_sptr asTableWorkspace();

IntensityType intensityType() const;

void setProfileFunctionName(std::string newProfileFunction);
std::string getProfileFunctionName() const;

TableWorkspace_sptr asTableWorkspace();

protected:
void prepareTable(TableWorkspace_sptr table);
void dataToTableLog(TableWorkspace_sptr table);
void peaksToTable(TableWorkspace_sptr table);

void constructFromTableWorkspace(TableWorkspace_sptr tableWorkspace);
bool checkColumns(TableWorkspace_sptr tableWorkspace);
std::string getIntensityTypeFromTable(TableWorkspace_sptr tableWorkspace);

void recoverDataFromLog(TableWorkspace_sptr TableWorkspace);

std::string getIntensityTypeFromLog(LogManager_sptr tableLog);
std::string getProfileFunctionNameFromLog(LogManager_sptr tableLog);

std::string getStringValueFromLog(LogManager_sptr logManager, std::string valueName);

std::string intensityTypeToString(IntensityType type) const;
IntensityType intensityTypeFromString(std::string typeString) const;

std::vector<PoldiPeak_sptr> m_peaks;
IntensityType m_intensityType;
std::string m_profileFunctionName;
};

typedef boost::shared_ptr<PoldiPeakCollection> PoldiPeakCollection_sptr;
Expand Down
Expand Up @@ -14,9 +14,10 @@ namespace Poldi {
using namespace Mantid::API;
using namespace Mantid::DataObjects;

PoldiPeakCollection::PoldiPeakCollection() :
PoldiPeakCollection::PoldiPeakCollection(IntensityType intensityType) :
m_peaks(),
m_intensityType(Maximum)
m_intensityType(intensityType),
m_profileFunctionName()
{
}

Expand Down Expand Up @@ -47,31 +48,46 @@ PoldiPeak_sptr PoldiPeakCollection::peak(size_t index) const
return m_peaks[index];
}

PoldiPeakCollection::IntensityType PoldiPeakCollection::intensityType() const
{
return m_intensityType;
}

void PoldiPeakCollection::setProfileFunctionName(std::string newProfileFunction)
{
m_profileFunctionName = newProfileFunction;
}

std::string PoldiPeakCollection::getProfileFunctionName() const
{
return m_profileFunctionName;
}

TableWorkspace_sptr PoldiPeakCollection::asTableWorkspace()
{
TableWorkspace_sptr peaks = boost::dynamic_pointer_cast<TableWorkspace>(WorkspaceFactory::Instance().createTable());

prepareTable(peaks);
dataToTableLog(peaks);
peaksToTable(peaks);

return peaks;
}

PoldiPeakCollection::IntensityType PoldiPeakCollection::intensityType() const
{
return m_intensityType;
}

void PoldiPeakCollection::prepareTable(TableWorkspace_sptr table)
{
table->addColumn("str", "HKL");
table->addColumn("str", "d");
table->addColumn("str", "Q");
table->addColumn("str", "Intensity");
table->addColumn("str", "FWHM (rel.)");
}

void PoldiPeakCollection::dataToTableLog(TableWorkspace_sptr table)
{
LogManager_sptr tableLog = table->logs();
tableLog->addProperty<std::string>("IntensityType", intensityTypeToString(m_intensityType));
tableLog->addProperty<std::string>("ProfileFunctionName", m_profileFunctionName);
}

void PoldiPeakCollection::peaksToTable(TableWorkspace_sptr table)
Expand All @@ -92,7 +108,7 @@ void PoldiPeakCollection::constructFromTableWorkspace(TableWorkspace_sptr tableW
size_t newPeakCount = tableWorkspace->rowCount();
m_peaks.resize(newPeakCount);

m_intensityType = intensityTypeFromString(getIntensityTypeFromTable(tableWorkspace));
recoverDataFromLog(tableWorkspace);

for(size_t i = 0; i < newPeakCount; ++i) {
TableRow nextRow = tableWorkspace->getRow(i);
Expand Down Expand Up @@ -126,12 +142,28 @@ bool PoldiPeakCollection::checkColumns(TableWorkspace_sptr tableWorkspace)
return columnNames == shouldNames;
}

std::string PoldiPeakCollection::getIntensityTypeFromTable(TableWorkspace_sptr tableWorkspace)
void PoldiPeakCollection::recoverDataFromLog(TableWorkspace_sptr tableWorkspace)
{
LogManager_sptr tableLog = tableWorkspace->logs();

if(tableLog->hasProperty("IntensityType")) {
return tableLog->getPropertyValueAsType<std::string>("IntensityType");
m_intensityType = intensityTypeFromString(getIntensityTypeFromLog(tableLog));
m_profileFunctionName = getProfileFunctionNameFromLog(tableLog);
}

std::string PoldiPeakCollection::getIntensityTypeFromLog(LogManager_sptr tableLog)
{
return getStringValueFromLog(tableLog, "IntensityType");
}

std::string PoldiPeakCollection::getProfileFunctionNameFromLog(LogManager_sptr tableLog)
{
return getStringValueFromLog(tableLog, "ProfileFunctionName");
}

std::string PoldiPeakCollection::getStringValueFromLog(LogManager_sptr logManager, std::string valueName)
{
if(logManager->hasProperty(valueName)) {
return logManager->getPropertyValueAsType<std::string>(valueName);
}

return "";
Expand Down
30 changes: 30 additions & 0 deletions Code/Mantid/Framework/SINQ/test/PoldiPeakCollectionTest.h
Expand Up @@ -91,6 +91,36 @@ class PoldiPeakCollectionTest : public CxxTest::TestSuite
}
}

void testProfileFunctionName()
{
TestablePoldiPeakCollection collection;

TS_ASSERT(collection.m_profileFunctionName.empty());

collection.setProfileFunctionName("Gaussian");

TS_ASSERT_EQUALS(collection.m_profileFunctionName, "Gaussian");
}

void testProfileFunctionRevovery()
{
TestablePoldiPeakCollection collection;
collection.setProfileFunctionName("Gaussian");

TableWorkspace_sptr table = collection.asTableWorkspace();

TestablePoldiPeakCollection other(table);

TS_ASSERT_EQUALS(other.getProfileFunctionName(), "Gaussian");
}

void testMissingProfileFunction()
{
TestablePoldiPeakCollection collection(m_dummyData);
TS_ASSERT(collection.getProfileFunctionName().empty());
}


void testIntensityTypeFromString()
{
TestablePoldiPeakCollection collection;
Expand Down

0 comments on commit 90e6ea4

Please sign in to comment.