Skip to content

Commit

Permalink
Re #11868 Minor update + descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
raquelalvarezbanos committed Sep 29, 2015
1 parent eaee012 commit f4b6d6a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace Mantid {
namespace Algorithms {

/** CalMuonDetectorPhases : TODO: DESCRIPTION
/** CalMuonDetectorPhases : Calculate asymmetry and phase for each spectra in a workspace
Copyright © 2015 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge
National Laboratory & European Spallation Source
Expand Down Expand Up @@ -39,7 +39,7 @@ class DLLExport CalMuonDetectorPhases : public API::Algorithm {
virtual const std::string name() const { return "CalMuonDetectorPhases"; }
/// Summary of algorithms purpose
virtual const std::string summary() const {
return "Calculate Muon deadtime for each spectra in a workspace.";
return "Calculate asymmetry and phase for each spectra in a workspace.";
}

/// Algorithm's version for identification overriding a virtual method
Expand All @@ -48,16 +48,22 @@ class DLLExport CalMuonDetectorPhases : public API::Algorithm {
virtual const std::string category() const { return "Muon"; }

private:
// Overridden Algorithm methods
/// Initialise the algorithm
void init();
/// Execute the algorithm
void exec();
/// Validate the inputs
std::map<std::string, std::string> validateInputs();
/// Prepare workspace for fit
API::MatrixWorkspace_sptr
prepareWorkspace(const API::MatrixWorkspace_sptr &ws, double startTime,
double endTime);
/// Fit the workspace
API::ITableWorkspace_sptr fitWorkspace(const API::MatrixWorkspace_sptr &ws,
double freq);
/// Create the fitting function as string
std::string createFittingFunction(int nspec, double freq);
/// Extract asymmetry and phase from fitting results
API::ITableWorkspace_sptr
extractDetectorInfo(const API::ITableWorkspace_sptr &paramTab, size_t nspec);
};
Expand Down
31 changes: 25 additions & 6 deletions Code/Mantid/Framework/Algorithms/src/CalMuonDetectorPhases.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ using API::Progress;
DECLARE_ALGORITHM(CalMuonDetectorPhases)

//----------------------------------------------------------------------------------------------
/** Initialize the algorithm's properties.
/** Initializes the algorithm's properties.
*/
void CalMuonDetectorPhases::init() {

Expand Down Expand Up @@ -65,7 +65,7 @@ std::map<std::string, std::string> CalMuonDetectorPhases::validateInputs() {
return result;
}
//----------------------------------------------------------------------------------------------
/** Execute the algorithm.
/** Executes the algorithm.
*/
void CalMuonDetectorPhases::exec() {

Expand All @@ -89,7 +89,10 @@ void CalMuonDetectorPhases::exec() {
setProperty("DetectorTable", tab);
}

/** TODO Description
/** Fits each spectrum in the workspace to f(x) = A * sin( w * x + p)
* @param ws :: [input] The workspace to fit
* @param freq :: [input] Hint for the frequency (w)
* @return :: The table workspace storing the asymmetries and phases
*/
API::ITableWorkspace_sptr CalMuonDetectorPhases::fitWorkspace(const API::MatrixWorkspace_sptr &ws, double freq) {

Expand Down Expand Up @@ -131,7 +134,10 @@ API::ITableWorkspace_sptr CalMuonDetectorPhases::fitWorkspace(const API::MatrixW
return results;
}

/** TODO Description
/** Extracts detector asymmetries and phases from fitting results
* @param paramTable :: [input] Output parameter table resulting from the fit
* @param nspec :: [input] Number of detectors/spectra
* @return :: A new table workspace storing the asymmetries and phases
*/
API::ITableWorkspace_sptr CalMuonDetectorPhases::extractDetectorInfo(
const API::ITableWorkspace_sptr &paramTab, size_t nspec) {
Expand All @@ -153,6 +159,12 @@ API::ITableWorkspace_sptr CalMuonDetectorPhases::extractDetectorInfo(
size_t specRow = s * 3;
double asym = paramTab->Double(specRow,1);
double phase = paramTab->Double(specRow+2,1);
// Handle phases greather (less) than 2*PI (-2*PI)
if (phase > 2 * M_PI) {
phase = phase - 2 * M_PI;
} else if (phase < -2 * M_PI) {
phase = phase + 2 * M_PI;
}
// If asym<0, take the absolute value and add \pi to phase
// f(x) = A * sin( w * x + p) = -A * sin( w * x + p + PI)
if (asym<0) {
Expand All @@ -167,7 +179,10 @@ API::ITableWorkspace_sptr CalMuonDetectorPhases::extractDetectorInfo(
return tab;
}

/** TODO Description
/** Creates the fitting function f(x) = A * sin( w*x + p) as string
* @param nspec :: [input] The number of domains (spectra)
* @param freq :: [input] Hint for the frequency (w)
* @returns :: The fitting function as a string
*/
std::string CalMuonDetectorPhases::createFittingFunction(int nspec, double freq) {

Expand Down Expand Up @@ -196,7 +211,11 @@ std::string CalMuonDetectorPhases::createFittingFunction(int nspec, double freq)
return ss.str();
}

/** TODO Description
/** Extracts relevant data from a workspace and removes exponential decay
* @param ws :: [input] The input workspace
* @param startTime :: [input] First X value to consider
* @param endTime :: [input] Last X value to consider
* @return :: Pre-processed workspace to fit
*/
API::MatrixWorkspace_sptr
CalMuonDetectorPhases::prepareWorkspace(const API::MatrixWorkspace_sptr &ws,
Expand Down

0 comments on commit f4b6d6a

Please sign in to comment.