-
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.
Added Min algorithm, and both Min and Max call Maxmin. Refs #4365
- Loading branch information
1 parent
47aeb94
commit a161291
Showing
5 changed files
with
193 additions
and
89 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
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
78 changes: 78 additions & 0 deletions
78
Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/Min.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,78 @@ | ||
#ifndef MANTID_ALGORITHMS_MIN_H_ | ||
#define MANTID_ALGORITHMS_MIN_H_ | ||
|
||
//---------------------------------------------------------------------- | ||
// Includes | ||
//---------------------------------------------------------------------- | ||
#include "MantidAPI/Algorithm.h" | ||
|
||
namespace Mantid | ||
{ | ||
namespace Algorithms | ||
{ | ||
/** Takes a 2D workspace as input and find the minimum in each 1D spectrum. | ||
The algorithm creates a new 1D workspace containing all minima as well as their X boundaries | ||
and error. This is used in particular for single crystal as a quick way to find strong peaks. | ||
Required Properties: | ||
<UL> | ||
<LI> InputWorkspace - The name of the Workspace2D to take as input </LI> | ||
<LI> OutputWorkspace - The name of the workspace in which to store the result </LI> | ||
</UL> | ||
Optional Properties (assume that you count from zero): | ||
<UL> | ||
<LI> Range_lower - The X value to search from (default min)</LI> | ||
<LI> Range_upper - The X value to search to (default max)</LI> | ||
<LI> StartSpectrum - Start spectrum number (default 0)</LI> | ||
<LI> EndSpectrum - End spectrum number (default max)</LI> | ||
</UL> | ||
@author L C Chapon, ISIS, Rutherford Appleton Laboratory | ||
@date 11/08/2009 | ||
Copyright © 2007-2010 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 Min : public API::Algorithm | ||
{ | ||
public: | ||
/// Default constructor | ||
Min() : API::Algorithm() {}; | ||
/// Destructor | ||
virtual ~Min() {}; | ||
/// Algorithm's name for identification overriding a virtual method | ||
virtual const std::string name() const { return "Min";} | ||
/// 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 "Arithmetic";} | ||
|
||
private: | ||
void initDocs(); | ||
// Overridden Algorithm methods | ||
void init(); | ||
void exec(); | ||
|
||
}; | ||
|
||
} // namespace Algorithm | ||
} // namespace Mantid | ||
|
||
#endif /*MANTID_ALGORITHMS_MIN_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
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,91 @@ | ||
/*WIKI* | ||
*WIKI*/ | ||
//---------------------------------------------------------------------- | ||
// Includes | ||
//---------------------------------------------------------------------- | ||
#include "MantidAlgorithms/Min.h" | ||
#include "MantidAPI/WorkspaceValidators.h" | ||
#include "MantidKernel/VectorHelper.h" | ||
#include "MantidAPI/Progress.h" | ||
|
||
namespace Mantid | ||
{ | ||
namespace Algorithms | ||
{ | ||
|
||
// Register the class into the algorithm factory | ||
DECLARE_ALGORITHM(Min) | ||
|
||
using namespace Kernel; | ||
using namespace API; | ||
|
||
/// Set the documentation strings | ||
void Min::initDocs() | ||
{ | ||
this->setWikiSummary("Takes a 2D workspace as input and find the minimum in each 1D spectrum. The algorithm creates a new 1D workspace containing all minima as well as their X boundaries and error. This is used in particular for single crystal as a quick way to find strong peaks."); | ||
this->setOptionalMessage("Takes a 2D workspace as input and find the minimum in each 1D spectrum. The algorithm creates a new 1D workspace containing all minima as well as their X boundaries and error. This is used in particular for single crystal as a quick way to find strong peaks."); | ||
} | ||
|
||
/** Initialisation method. | ||
* | ||
*/ | ||
void Min::init() | ||
{ | ||
declareProperty(new WorkspaceProperty<>("InputWorkspace","",Direction::Input,new HistogramValidator<>), | ||
"The name of the Workspace2D to take as input"); | ||
declareProperty(new WorkspaceProperty<>("OutputWorkspace","",Direction::Output), | ||
"The name of the workspace in which to store the result"); | ||
|
||
declareProperty("RangeLower",EMPTY_DBL(), | ||
"The X value to search from (default min)"); | ||
declareProperty("RangeUpper",EMPTY_DBL(), | ||
"The X value to search to (default max)"); | ||
BoundedValidator<int> *mustBePositive = new BoundedValidator<int>(); | ||
mustBePositive->setLower(0); | ||
declareProperty("StartWorkspaceIndex",0, mustBePositive, | ||
"Start spectrum number (default 0)"); | ||
// As the property takes ownership of the validator pointer, have to take care to pass in a unique | ||
// pointer to each property. | ||
declareProperty("EndWorkspaceIndex",EMPTY_INT(), mustBePositive->clone(), | ||
"End spectrum number (default max)"); | ||
} | ||
|
||
/** Executes the algorithm | ||
* | ||
* @throw runtime_error Thrown if algorithm cannot execute | ||
*/ | ||
void Min::exec() | ||
{ | ||
// Try and retrieve the optional properties | ||
double m_MinRange = getProperty("RangeLower"); | ||
double m_MaxRange = getProperty("RangeUpper"); | ||
int m_MinSpec = getProperty("StartWorkspaceIndex"); | ||
int m_MaxSpec = getProperty("EndWorkspaceIndex"); | ||
|
||
|
||
// Get the input workspace | ||
MatrixWorkspace_sptr inworkspace = getProperty("InputWorkspace"); | ||
|
||
|
||
// sub-algorithme does all of the actual work - do not set the output workspace | ||
IAlgorithm_sptr minAlgo = createSubAlgorithm("MaxMin", 0., 1.); | ||
minAlgo->setProperty("InputWorkspace", inworkspace); | ||
minAlgo->setProperty("RangeLower", m_MinRange); | ||
minAlgo->setProperty("RangeUpper", m_MaxRange); | ||
minAlgo->setProperty("StartWorkspaceIndex", m_MinSpec); | ||
minAlgo->setProperty("EndWorkspaceIndex", m_MaxSpec); | ||
minAlgo->setProperty("ShowMin",true); | ||
minAlgo->execute(); | ||
// just grab the child's output workspace | ||
MatrixWorkspace_sptr outputWS = minAlgo->getProperty("OutputWorkspace"); | ||
|
||
this->setProperty("OutputWorkspace", outputWS); | ||
|
||
} | ||
|
||
} // namespace Algorithms | ||
} // namespace Mantid |