From e90c560bc1cacf13a26b37678e6b2fabec67af04 Mon Sep 17 00:00:00 2001
From: Wenduo Zhou <zhouw@ornl.gov>
Date: Mon, 10 Oct 2011 15:48:41 +0000
Subject: [PATCH] Add StripVanadiumPeaks2 to substitute StripVanadiumPeaks. 
 Refs #3935.

---
 .../Framework/Algorithms/CMakeLists.txt       |   3 +
 .../MantidAlgorithms/StripVanadiumPeaks2.h    |  65 +++++++++++
 .../Algorithms/src/StripVanadiumPeaks2.cpp    | 101 ++++++++++++++++++
 .../Algorithms/test/StripVanadiumPeaks2Test.h |  34 ++++++
 4 files changed, 203 insertions(+)
 create mode 100644 Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/StripVanadiumPeaks2.h
 create mode 100644 Code/Mantid/Framework/Algorithms/src/StripVanadiumPeaks2.cpp
 create mode 100644 Code/Mantid/Framework/Algorithms/test/StripVanadiumPeaks2Test.h

diff --git a/Code/Mantid/Framework/Algorithms/CMakeLists.txt b/Code/Mantid/Framework/Algorithms/CMakeLists.txt
index 03c13cedc57..338885da44f 100644
--- a/Code/Mantid/Framework/Algorithms/CMakeLists.txt
+++ b/Code/Mantid/Framework/Algorithms/CMakeLists.txt
@@ -152,6 +152,7 @@ set ( SRC_FILES
 	src/SphericalAbsorption.cpp
 	src/StripPeaks.cpp
 	src/StripVanadiumPeaks.cpp
+	src/StripVanadiumPeaks2.cpp
 	src/SumNeighbours.cpp
 	src/SumRowColumn.cpp
 	src/SumSpectra.cpp
@@ -321,6 +322,7 @@ set ( INC_FILES
 	inc/MantidAlgorithms/SphericalAbsorption.h
 	inc/MantidAlgorithms/StripPeaks.h
 	inc/MantidAlgorithms/StripVanadiumPeaks.h
+	inc/MantidAlgorithms/StripVanadiumPeaks2.h
 	inc/MantidAlgorithms/SumNeighbours.h
 	inc/MantidAlgorithms/SumRowColumn.h
 	inc/MantidAlgorithms/SumSpectra.h
@@ -471,6 +473,7 @@ set ( TEST_FILES
 	test/SpatialGroupingTest.h
 	test/SphericalAbsorptionTest.h
 	test/StripPeaksTest.h
+	test/StripVanadiumPeaks2Test.h
 	test/StripVanadiumPeaksTest.h
 	test/SumNeighboursTest.h
 	test/SumRowColumnTest.h
diff --git a/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/StripVanadiumPeaks2.h b/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/StripVanadiumPeaks2.h
new file mode 100644
index 00000000000..b5dc641a140
--- /dev/null
+++ b/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/StripVanadiumPeaks2.h
@@ -0,0 +1,65 @@
+#ifndef MANTID_ALGORITHMS_STRIPVANADIUMPEAKS2_H_
+#define MANTID_ALGORITHMS_STRIPVANADIUMPEAKS2_H_
+/*WIKI*
+TODO: Enter wiki description here.
+*WIKI*/
+    
+#include "MantidKernel/System.h"
+#include "MantidAPI/Algorithm.h"
+
+
+namespace Mantid
+{
+namespace Algorithms
+{
+
+  /** StripVanadiumPeaks2 : TODO: DESCRIPTION
+    
+    @author
+    @date 2011-10-07
+
+    Copyright &copy; 2011 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 StripVanadiumPeaks2 : public API::Algorithm
+  {
+  public:
+    StripVanadiumPeaks2();
+    ~StripVanadiumPeaks2();
+    
+    /// Algorithm's name for identification overriding a virtual method
+    virtual const std::string name() const { return "StripVanadiumPeaks"; }
+    /// Algorithm's version for identification overriding a virtual method
+    virtual int version() const { return 2; }
+    /// Algorithm's category for identification overriding a virtual method
+    virtual const std::string category() const { return "Diffraction"; }
+
+  private:
+    void init();
+
+    void exec();
+
+  };
+
+
+} // namespace Algorithms
+} // namespace Mantid
+
+#endif  /* MANTID_ALGORITHMS_STRIPVANADIUMPEAKS2_H_ */
diff --git a/Code/Mantid/Framework/Algorithms/src/StripVanadiumPeaks2.cpp b/Code/Mantid/Framework/Algorithms/src/StripVanadiumPeaks2.cpp
new file mode 100644
index 00000000000..86ca391ebaf
--- /dev/null
+++ b/Code/Mantid/Framework/Algorithms/src/StripVanadiumPeaks2.cpp
@@ -0,0 +1,101 @@
+#include "MantidAlgorithms/StripVanadiumPeaks2.h"
+#include "MantidKernel/System.h"
+
+using namespace Mantid::Kernel;
+using namespace Mantid::API;
+
+namespace Mantid
+{
+namespace Algorithms
+{
+
+DECLARE_ALGORITHM(StripVanadiumPeaks2)
+
+  //----------------------------------------------------------------------------------------------
+  /** Constructor
+   */
+  StripVanadiumPeaks2::StripVanadiumPeaks2()
+  {
+    // TODO Auto-generated constructor stub
+  }
+    
+  //----------------------------------------------------------------------------------------------
+  /** Destructor
+   */
+  StripVanadiumPeaks2::~StripVanadiumPeaks2()
+  {
+    // TODO Auto-generated destructor stub
+  }
+  
+  void StripVanadiumPeaks2::init(){
+    // Declare inputs and output.  Copied from StripPeaks
+
+    declareProperty(
+      new WorkspaceProperty<>("InputWorkspace","",Direction::Input),
+      "Name of the input workspace. If you use the default vanadium peak positions are used, the workspace must be in units of d-spacing." );
+
+    declareProperty(new WorkspaceProperty<>("OutputWorkspace","",Direction::Output),
+      "The name of the workspace to be created as the output of the algorithm.\n"
+      "If the input workspace is an EventWorkspace, then the output must be different (and will be made into a Workspace2D)." );
+
+    BoundedValidator<int> *min = new BoundedValidator<int>();
+    min->setLower(1.0);
+    // The estimated width of a peak in terms of number of channels
+    declareProperty("FWHM", 7, min,
+      "Estimated number of points covered by the fwhm of a peak (default 7)" );
+
+    // The tolerance allowed in meeting the conditions
+    declareProperty("Tolerance",4, min->clone(),
+      "A measure of the strictness desired in meeting the condition on peak candidates,\n"
+      "Mariscotti recommends 2 (default 4)");
+
+    BoundedValidator<int> *mustBePositive = new BoundedValidator<int>();
+    mustBePositive->setLower(0);
+    declareProperty("WorkspaceIndex",EMPTY_INT(),mustBePositive,
+      "If set, peaks will only be removed from this spectrum (otherwise from all)");
+
+    return;
+
+  }
+
+  void StripVanadiumPeaks2::exec(){
+
+    // 1. Process input/output
+    API::MatrixWorkspace_sptr inputWS = getProperty("InputWorkspace");
+    std::string outputWSName = getPropertyValue("OutputWorkspace");
+    int singleIndex = getProperty("WorkspaceIndex");
+    int param_fwhm = getProperty("FWHM");
+    int param_tolerance = getProperty("Tolerance");
+
+    bool singleSpectrum = !isEmpty(singleIndex);
+
+    // 2. Call StripPeaks
+    std::string peakpositions = "0.5044,0.5191,0.5350,0.5526,0.5936,0.6178,0.6453,0.6768,0.7134,0.7566,0.8089,0.8737,0.9571,1.0701,1.2356,1.5133,2.1401";
+
+    IAlgorithm_sptr alg1 = createSubAlgorithm("StripPeaks");
+    alg1->setProperty("InputWorkspace", inputWS);
+    alg1->setPropertyValue("OutputWorkspace", outputWSName);
+    alg1->setProperty("FWHM", param_fwhm);
+    alg1->setProperty("Tolerance", param_tolerance);
+    alg1->setProperty("PeakPositions", peakpositions);
+    if (singleSpectrum){
+      alg1->setProperty("WorkspaceIndex", singleIndex);
+    }
+
+    alg1->executeAsSubAlg();
+
+    // 3. Get and set output workspace
+    // API::MatrixWorkspace_sptr outputWS = boost::dynamic_pointer_cast<API::MatrixWorkspace_sptr>(AnalysisDataService::Instance().retrieve(outputWSName));
+    // boost::shared_ptr<API::Workspace> outputWS = AnalysisDataService::Instance().retrieve(outputWSName);
+    API::MatrixWorkspace_sptr outputWS = alg1->getProperty("OutputWorkspace");
+
+    this->setProperty("OutputWorkspace", outputWS);
+
+    return;
+  }
+
+
+
+} // namespace Mantid
+} // namespace Algorithms
+
diff --git a/Code/Mantid/Framework/Algorithms/test/StripVanadiumPeaks2Test.h b/Code/Mantid/Framework/Algorithms/test/StripVanadiumPeaks2Test.h
new file mode 100644
index 00000000000..a54c23b7162
--- /dev/null
+++ b/Code/Mantid/Framework/Algorithms/test/StripVanadiumPeaks2Test.h
@@ -0,0 +1,34 @@
+#ifndef MANTID_ALGORITHMS_STRIPVANADIUMPEAKS2TEST_H_
+#define MANTID_ALGORITHMS_STRIPVANADIUMPEAKS2TEST_H_
+
+#include <cxxtest/TestSuite.h>
+#include "MantidKernel/Timer.h"
+#include "MantidKernel/System.h"
+#include <iostream>
+#include <iomanip>
+
+#include "MantidAlgorithms/StripVanadiumPeaks2.h"
+
+using namespace Mantid;
+using namespace Mantid::Algorithms;
+using namespace Mantid::API;
+
+class StripVanadiumPeaks2Test : public CxxTest::TestSuite
+{
+public:
+  // This pair of boilerplate methods prevent the suite being created statically
+  // This means the constructor isn't called when running other tests
+  static StripVanadiumPeaks2Test *createSuite() { return new StripVanadiumPeaks2Test(); }
+  static void destroySuite( StripVanadiumPeaks2Test *suite ) { delete suite; }
+
+
+  void test_Something()
+  {
+  }
+
+
+};
+
+
+#endif /* MANTID_ALGORITHMS_STRIPVANADIUMPEAKS2TEST_H_ */
+
-- 
GitLab