-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9e69caa
commit 7b76b1b
Showing
3 changed files
with
220 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/AlignAndFocusPowder.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
#ifndef MANTID_ALGORITHM_AlignAndFocusPowder_H_ | ||
#define MANTID_ALGORITHM_AlignAndFocusPowder_H_ | ||
|
||
//---------------------------------------------------------------------- | ||
// Includes | ||
//---------------------------------------------------------------------- | ||
#include "MantidAPI/Algorithm.h" | ||
#include "MantidAPI/DeprecatedAlgorithm.h" | ||
#include <Poco/NObserver.h> | ||
|
||
namespace Mantid | ||
{ | ||
namespace Algorithms | ||
{ | ||
/** | ||
This is a parent algorithm that uses several different child algorithms to perform it's task. | ||
Takes a workspace as input and the filename of a grouping file of a suitable format. | ||
The input workspace is | ||
1) Converted to d-spacing units | ||
2) Rebinnned to a common set of bins | ||
3) The spectra are grouped according to the grouping file. | ||
Required Properties: | ||
<UL> | ||
<LI> InputWorkspace - The name of the 2D Workspace to take as input </LI> | ||
<LI> GroupingFileName - The path to a grouping file</LI> | ||
<LI> OutputWorkspace - The name of the 2D workspace in which to store the result </LI> | ||
</UL> | ||
The structure of the grouping file is as follows: | ||
# Format: number UDET offset select group | ||
0 611 0.0000000 1 0 | ||
1 612 0.0000000 1 0 | ||
2 601 0.0000000 0 0 | ||
3 602 0.0000000 0 0 | ||
4 621 0.0000000 1 0 | ||
@author Vickie Lynch, SNS | ||
@date 07/16/2012 | ||
Copyright © 2008 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://svn.mantidproject.org/mantid/trunk/Code/Mantid> | ||
Code Documentation is available at: <http://doxygen.mantidproject.org> | ||
*/ | ||
class DLLExport AlignAndFocusPowder : public API::Algorithm, public API::DeprecatedAlgorithm | ||
{ | ||
public: | ||
/// Constructor | ||
AlignAndFocusPowder(); | ||
/// Destructor | ||
virtual ~AlignAndFocusPowder() {}; | ||
/// Algorithm's name for identification overriding a virtual method | ||
virtual const std::string name() const { return "AlignAndFocusPowder";} | ||
/// Algorithm's version for identification overriding a virtual method | ||
virtual int version() const { return 1;} | ||
/// Algorithm's category for identification overriding a virtual method | ||
virtual const std::string category() const { return "Diffraction";} | ||
|
||
private: | ||
/// Sets documentation strings for this algorithm | ||
virtual void initDocs(); | ||
// Overridden Algorithm methods | ||
void init(); | ||
void exec(); | ||
API::MatrixWorkspace_sptr convertUnitsToDSpacing(const API::MatrixWorkspace_sptr& workspace); | ||
void RebinWorkspace(API::MatrixWorkspace_sptr& workspace); | ||
void calculateRebinParams(const API::MatrixWorkspace_const_sptr& workspace,double& min,double& max,double& step); | ||
|
||
}; | ||
|
||
} // namespace Algorithm | ||
} // namespace Mantid | ||
|
||
#endif /*MANTID_ALGORITHM_AlignAndFocusPowder_H_*/ |
126 changes: 126 additions & 0 deletions
126
Code/Mantid/Framework/Algorithms/src/AlignAndFocusPowder.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
/*WIKI* | ||
*WIKI*/ | ||
//---------------------------------------------------------------------- | ||
// Includes | ||
//---------------------------------------------------------------------- | ||
#include "MantidAlgorithms/AlignAndFocusPowder.h" | ||
#include "MantidAPI/FileProperty.h" | ||
#include "MantidAPI/MatrixWorkspace.h" | ||
#include "MantidDataHandling/LoadCalFile.h" | ||
#include "MantidDataObjects/GroupingWorkspace.h" | ||
#include "MantidDataObjects/MaskWorkspace.h" | ||
#include "MantidDataObjects/OffsetsWorkspace.h" | ||
#include "MantidDataObjects/Workspace2D.h" | ||
#include "MantidKernel/System.h" | ||
|
||
using Mantid::Geometry::Instrument_const_sptr; | ||
using namespace Mantid::Kernel; | ||
using namespace Mantid::API; | ||
using namespace Mantid::DataObjects; | ||
|
||
namespace Mantid | ||
{ | ||
namespace Algorithms | ||
{ | ||
|
||
// Register the class into the algorithm factory | ||
DECLARE_ALGORITHM(AlignAndFocusPowder) | ||
|
||
/// Constructor | ||
AlignAndFocusPowder::AlignAndFocusPowder() : API::Algorithm(), API::DeprecatedAlgorithm() | ||
{ | ||
this->useAlgorithm("AlignAndFocusPowder version 2"); | ||
} | ||
|
||
/// Sets documentation strings for this algorithm | ||
void AlignAndFocusPowder::initDocs() | ||
{ | ||
this->setWikiSummary("Algorithm to focus powder diffraction data into a number of histograms according to a grouping scheme defined in a [[CalFile]]. "); | ||
this->setOptionalMessage("Algorithm to focus powder diffraction data into a number of histograms according to a grouping scheme defined in a CalFile."); | ||
} | ||
|
||
|
||
using namespace Kernel; | ||
using API::WorkspaceProperty; | ||
using API::MatrixWorkspace_sptr; | ||
using API::MatrixWorkspace; | ||
using API::FileProperty; | ||
|
||
/** Initialisation method. Declares properties to be used in algorithm. | ||
* | ||
*/ | ||
void AlignAndFocusPowder::init() | ||
{ | ||
declareProperty( | ||
new WorkspaceProperty<MatrixWorkspace>("InputWorkspace","",Direction::Input), | ||
"The input workspace" ); | ||
|
||
declareProperty( | ||
new WorkspaceProperty<MatrixWorkspace>("OutputWorkspace","",Direction::Output), | ||
"The result of diffraction focussing of InputWorkspace" ); | ||
|
||
declareProperty("Params","","The binning parameters"); | ||
|
||
declareProperty(new FileProperty("CalFileName", "", FileProperty::OptionalLoad, ".cal"), | ||
"The name of the CalFile with offset, masking, and grouping data" ); | ||
|
||
declareProperty(new WorkspaceProperty<GroupingWorkspace>("GroupingWorkspace","",Direction::Input, PropertyMode::Optional), | ||
"Optional: An GroupingWorkspace workspace giving the grouping info."); | ||
|
||
declareProperty(new WorkspaceProperty<OffsetsWorkspace>("OffsetsWorkspace","",Direction::Input, PropertyMode::Optional), | ||
"Optional: An OffsetsWorkspace workspace giving the detector calibration values."); | ||
|
||
declareProperty(new WorkspaceProperty<MatrixWorkspace>("MaskWorkspace","",Direction::Input, PropertyMode::Optional), | ||
"Optional: An Workspace workspace giving which detectors are masked."); | ||
|
||
} | ||
|
||
/** Executes the algorithm | ||
* | ||
* @throw Exception::FileError If the grouping file cannot be opened or read successfully | ||
* @throw runtime_error If unable to run one of the sub-algorithms successfully | ||
*/ | ||
void AlignAndFocusPowder::exec() | ||
{ | ||
// retrieve the properties | ||
MatrixWorkspace_sptr inputWS = getProperty("InputWorkspace"); | ||
std::string calFileName=getProperty("CalFileName"); | ||
OffsetsWorkspace_sptr offsetsWS = getProperty("OffsetsWorkspace"); | ||
MatrixWorkspace_sptr maskWS = getProperty("MaskWorkspace"); | ||
GroupingWorkspace_sptr groupWS = getProperty("GroupingWorkspace"); | ||
|
||
// Get the input workspace | ||
if ((!offsetsWS || !maskWS || !groupWS) && !calFileName.empty()) | ||
{ | ||
// Load the .cal file | ||
IAlgorithm_sptr alg = createSubAlgorithm("LoadCalFile"); | ||
alg->setPropertyValue("CalFilename", calFileName); | ||
alg->setProperty("InputWorkspace", inputWS); | ||
if(groupWS) alg->setProperty<bool>("MakeGroupingWorkspace", false); | ||
if(offsetsWS) alg->setProperty<bool>("MakeOffsetsWorkspace", false); | ||
if(maskWS)alg->setProperty<bool>("MakeMaskWorkspace", false); | ||
std::string instName = inputWS->getInstrument()->getName(); | ||
alg->setProperty<std::string>("WorkspaceName", instName); | ||
alg->executeAsSubAlg(); | ||
groupWS = alg->getProperty("OutputGroupingWorkspace"); | ||
offsetsWS = alg->getProperty("OutputOffsetsWorkspace"); | ||
maskWS = alg->getProperty("OutputMaskWorkspace"); | ||
AnalysisDataService::Instance().add(instName+"_group", groupWS); | ||
AnalysisDataService::Instance().add(instName+"_offsets", offsetsWS); | ||
AnalysisDataService::Instance().add(instName+"_mask", maskWS); | ||
} | ||
|
||
std::string params = getProperty("Params"); | ||
API::IAlgorithm_sptr rebinAlg = createSubAlgorithm("Rebin"); | ||
rebinAlg->setProperty<MatrixWorkspace_sptr>("InputWorkspace", inputWS); | ||
rebinAlg->setProperty("Params",params); | ||
rebinAlg->setProperty("PreserveEvents", true); | ||
rebinAlg->executeAsSubAlg(); | ||
MatrixWorkspace_sptr outputWS = rebinAlg->getProperty("OutputWorkspace"); | ||
setProperty("OutputWorkspace",outputWS); | ||
|
||
} | ||
|
||
} // namespace Algorithm | ||
} // namespace Mantid |