Skip to content

Commit

Permalink
Refs #9445. Fixed comments in PoldiCalculateSpectrum2D
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Wedel committed Jun 27, 2014
1 parent 3323293 commit 7031418
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 18 deletions.
Expand Up @@ -16,9 +16,16 @@ namespace Mantid
namespace Poldi
{

/** PoldiCalculateSpectrum2D : TODO: DESCRIPTION
/** PoldiCalculateSpectrum2D
Copyright © 2014 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory
An Algorithm to calculate a POLDI 2D-spectrum from a given table containing POLDI
peak data. A MatrixWorkspace containing a proper POLDI instrument definition is required
to determine output workspace dimensions etc.
@author Michael Wedel, Paul Scherrer Institut - SINQ
@date 16/05/2014
Copyright © 2014 PSI-MSS
This file is part of Mantid.
Expand Down
100 changes: 84 additions & 16 deletions Code/Mantid/Framework/SINQ/src/PoldiCalculateSpectrum2D.cpp
Expand Up @@ -29,8 +29,6 @@ namespace Poldi
using namespace Kernel;
using namespace DataObjects;


//----------------------------------------------------------------------------------------------
/** Constructor
*/
PoldiCalculateSpectrum2D::PoldiCalculateSpectrum2D():
Expand All @@ -40,15 +38,12 @@ namespace Poldi
{
}

//----------------------------------------------------------------------------------------------
/** Destructor
*/
PoldiCalculateSpectrum2D::~PoldiCalculateSpectrum2D()
{
}


//----------------------------------------------------------------------------------------------
/// Algorithm's name for identification. @see Algorithm::name
const std::string PoldiCalculateSpectrum2D::name() const { return "PoldiCalculateSpectrum2D";}

Expand All @@ -58,23 +53,28 @@ namespace Poldi
/// Algorithm's category for identification. @see Algorithm::category
const std::string PoldiCalculateSpectrum2D::category() const { return "SINQ\\Poldi\\PoldiSet";}

/// Very short algorithm summary. @see Algorith::summary
const std::string PoldiCalculateSpectrum2D::summary() const
{
return "Calculates a POLDI 2D-spectrum.";
}

//----------------------------------------------------------------------------------------------
/** Initialize the algorithm's properties.
*/
/// Initialization of algorithm properties.
void PoldiCalculateSpectrum2D::init()
{
declareProperty(new WorkspaceProperty<MatrixWorkspace>("InputWorkspace","",Direction::Input), "Measured POLDI 2D-spectrum.");
declareProperty(new WorkspaceProperty<TableWorkspace>("PoldiPeakWorkspace", "", Direction::Input), "Table workspace with peak information.");
declareProperty(new WorkspaceProperty<MatrixWorkspace>("OutputWorkspace","",Direction::Output), "Calculated POLDI 2D-spectrum");
}

//----------------------------------------------------------------------------------------------
/** Execute the algorithm.
/**
* Constructs a proper function from a peak collection
*
* This method constructs a Poldi2DFunction and assigns one PoldiSpectrumDomainFunction to it for
* each peak contained in the peak collection.
*
* @param peakCollection :: PoldiPeakCollection containing peaks with integral intensities
* @return Poldi2DFunction with one PoldiSpectrumDomainFunction per peak
*/
boost::shared_ptr<Poldi2DFunction> PoldiCalculateSpectrum2D::getFunctionFromPeakCollection(PoldiPeakCollection_sptr peakCollection)
{
Expand All @@ -94,11 +94,7 @@ namespace Poldi
return mdFunction;
}

void PoldiCalculateSpectrum2D::setTimeTransformer(PoldiTimeTransformer_sptr poldiTimeTransformer)
{
m_timeTransformer = poldiTimeTransformer;
}

/// Executes the algorithm
void PoldiCalculateSpectrum2D::exec()
{
TableWorkspace_sptr peakTable = getProperty("PoldiPeakWorkspace");
Expand All @@ -116,6 +112,15 @@ namespace Poldi
setProperty("OutputWorkspace", calculateSpectrum(peakCollection, ws));
}

/**
* Calculates the 2D spectrum in a MatrixWorkspace
*
* In this method the actual function calculation is performed using Fit.
*
* @param peakCollection :: PoldiPeakCollection
* @param matrixWorkspace :: MatrixWorkspace with POLDI instrument and correct dimensions
* @return MatrixWorkspace with the calculated data
*/
MatrixWorkspace_sptr PoldiCalculateSpectrum2D::calculateSpectrum(PoldiPeakCollection_sptr peakCollection, MatrixWorkspace_sptr matrixWorkspace)
{
PoldiPeakCollection_sptr integratedPeaks = getIntegratedPeakCollection(peakCollection);
Expand All @@ -141,11 +146,35 @@ namespace Poldi
return outputWs;
}

/**
* Constructs a PoldiTimeTransformer from given instrument and calls setTimeTransformer.
*
* @param poldiInstrument :: PoldiInstrumentAdapter with valid components
*/
void PoldiCalculateSpectrum2D::setTimeTransformerFromInstrument(PoldiInstrumentAdapter_sptr poldiInstrument)
{
setTimeTransformer(PoldiTimeTransformer_sptr(new PoldiTimeTransformer(poldiInstrument)));
}

/**
* Sets the time transformer object that is used for all calculations.
*
* @param poldiTimeTransformer
*/
void PoldiCalculateSpectrum2D::setTimeTransformer(PoldiTimeTransformer_sptr poldiTimeTransformer)
{
m_timeTransformer = poldiTimeTransformer;
}

/**
* Extracts time bin width from workspace parameter
*
* The method uses the difference between first and second x-value of the first spectrum as
* time bin width. If the workspace does not contain proper data (0 spectra or less than
* 2 x-values), the method throws an std::invalid_argument-exception. Otherwise it calls setDeltaT.
*
* @param matrixWorkspace :: MatrixWorkspace with at least one spectrum with at least two x-values.
*/
void PoldiCalculateSpectrum2D::setDeltaTFromWorkspace(MatrixWorkspace_sptr matrixWorkspace)
{
if(matrixWorkspace->getNumberHistograms() < 1) {
Expand All @@ -162,6 +191,11 @@ namespace Poldi
setDeltaT(matrixWorkspace->readX(0)[1] - matrixWorkspace->readX(0)[0]);
}

/**
* Assigns delta t, throws std::invalid_argument on invalid value (determined by isValidDeltaT).
*
* @param newDeltaT :: Value to be used as delta t for calculations.
*/
void PoldiCalculateSpectrum2D::setDeltaT(double newDeltaT)
{
if(!isValidDeltaT(newDeltaT)) {
Expand All @@ -171,11 +205,23 @@ namespace Poldi
m_deltaT = newDeltaT;
}

/**
* Checks whether delta t is larger than 0.
*
* @param deltaT :: Value to be checked for validity as a time difference.
* @return True if delta t is larger than 0, otherwise false.
*/
bool PoldiCalculateSpectrum2D::isValidDeltaT(double deltaT)
{
return deltaT > 0.0;
}

/**
* Tries to construct a PoldiPeakCollection from the supplied table.
*
* @param peakTable :: TableWorkspace with POLDI peak data.
* @return PoldiPeakCollection with the data from the table workspace.
*/
PoldiPeakCollection_sptr PoldiCalculateSpectrum2D::getPeakCollection(TableWorkspace_sptr peakTable)
{
try {
Expand All @@ -185,6 +231,20 @@ namespace Poldi
}
}

/**
* Return peak collection with integrated peaks
*
* This method takes a PoldiPeakCollection where the intensity is represented by the maximum. Then
* it takes the profile function stored in the peak collection, which must be the name of a registered
* IPeakFunction-implementation. The parameters height and fwhm are assigned, centre is set to 0 to
* avoid problems with the parameter transformation for the integration from -inf to inf. The profiles are
* integrated using a PeakFunctionIntegrator to the precision of 1e-10.
*
* The original peak collection is not modified, a new instance is created.
*
* @param rawPeakCollection :: PoldiPeakCollection
* @return PoldiPeakCollection with integrated intensities
*/
PoldiPeakCollection_sptr PoldiCalculateSpectrum2D::getIntegratedPeakCollection(PoldiPeakCollection_sptr rawPeakCollection)
{
if(!rawPeakCollection) {
Expand Down Expand Up @@ -248,14 +308,22 @@ namespace Poldi
* by deltaT. In the original code this is done at this point, so this behavior is kept
* for now.
*/
integratedPeak->setD(integratedPeak->d() - 0.0005);
integratedPeak->setIntensity(UncertainValue(integration.result / m_deltaT));
integratedPeakCollection->addPeak(integratedPeak);
}

return integratedPeakCollection;
}

/**
* Normalized the intensities of the given integrated peaks
*
* This function normalizes the peak intensities according to the source spectrum, the number of
* chopper slits and the number of detector elements.
*
* @param peakCollection :: PoldiPeakCollection with integrated intensities
* @return PoldiPeakCollection with normalized intensities
*/
PoldiPeakCollection_sptr PoldiCalculateSpectrum2D::getNormalizedPeakCollection(PoldiPeakCollection_sptr peakCollection)
{
if(!peakCollection) {
Expand Down

0 comments on commit 7031418

Please sign in to comment.