From e267f13ae3c96b722e2e9b8f0020e1e8ca4dfc8e Mon Sep 17 00:00:00 2001
From: Martyn Gigg <martyn.gigg@stfc.ac.uk>
Date: Wed, 31 Mar 2010 15:27:57 +0000
Subject: [PATCH] Converted libISISGetEi to version 2 of GetEi and removed
 selection box from Homer interface. Re #1163

---
 Code/Mantid/Algorithms/Algorithms.vcproj      |   8 +
 .../{libISISGetEi.h => GetEi2.h}              |  62 +++----
 .../src/{libISISGetEi.cpp => GetEi2.cpp}      | 169 +++---------------
 .../scripts/Excitations/CommonFunctions.py    |   3 +-
 .../scripts/Excitations/ConversionLib.py      |  39 ++--
 .../scripts/Excitations/ExcitDefaults.py      |   4 +-
 .../scripts/Excitations/GUI_Interface.py      |   4 +-
 .../MantidQt/CustomInterfaces/inc/Homer.ui    |  60 ++-----
 .../CustomInterfaces/src/deltaECalc.cpp       |  29 +--
 9 files changed, 108 insertions(+), 270 deletions(-)
 rename Code/Mantid/Algorithms/inc/MantidAlgorithms/{libISISGetEi.h => GetEi2.h} (51%)
 rename Code/Mantid/Algorithms/src/{libISISGetEi.cpp => GetEi2.cpp} (78%)

diff --git a/Code/Mantid/Algorithms/Algorithms.vcproj b/Code/Mantid/Algorithms/Algorithms.vcproj
index 9d07b4f8ede..e879d9efd29 100644
--- a/Code/Mantid/Algorithms/Algorithms.vcproj
+++ b/Code/Mantid/Algorithms/Algorithms.vcproj
@@ -322,6 +322,10 @@
 				RelativePath=".\src\GetEi.cpp"
 				>
 			</File>
+			<File
+				RelativePath=".\src\GetEi2.cpp"
+				>
+			</File>
 			<File
 				RelativePath=".\src\HRPDSlabCanAbsorption.cpp"
 				>
@@ -732,6 +736,10 @@
 				RelativePath=".\inc\MantidAlgorithms\GetEi.h"
 				>
 			</File>
+			<File
+				RelativePath=".\inc\MantidAlgorithms\GetEi2.h"
+				>
+			</File>
 			<File
 				RelativePath=".\test\getEitest.h"
 				>
diff --git a/Code/Mantid/Algorithms/inc/MantidAlgorithms/libISISGetEi.h b/Code/Mantid/Algorithms/inc/MantidAlgorithms/GetEi2.h
similarity index 51%
rename from Code/Mantid/Algorithms/inc/MantidAlgorithms/libISISGetEi.h
rename to Code/Mantid/Algorithms/inc/MantidAlgorithms/GetEi2.h
index 6faf603af05..fe274370dcb 100644
--- a/Code/Mantid/Algorithms/inc/MantidAlgorithms/libISISGetEi.h
+++ b/Code/Mantid/Algorithms/inc/MantidAlgorithms/GetEi2.h
@@ -1,5 +1,5 @@
-#ifndef MANTID_DATAHANDLING_LIBISISGETEI_H_
-#define MANTID_DATAHANDLING_LIBISISGETEI_H_
+#ifndef MANTID_ALGORITHMS_GETEI2_H_
+#define MANTID_ALGORITHMS_GETEI2_H_
 
 //----------------------------------------------------------------------
 // Includes
@@ -27,8 +27,8 @@ namespace Algorithms
     <LI>IncidentEnergy - The calculated energy</LI>
     </UL>
 
-    @author Steve Williams STFC Rutherford Appleton Laboratory
-    @date 27/07/2009
+    @author Martyn Gigg STFC Rutherford Appleton Laboratory
+    @date 31/03/2010
 
     Copyright &copy; 2008-9 STFC Rutherford Appleton Laboratory
 
@@ -50,11 +50,11 @@ namespace Algorithms
     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 libISISGetEi : public API::Algorithm
+    class DLLExport GetEi2 : public API::Algorithm
     {
     public:
       /// empty contructor calls the base class constructor
-      libISISGetEi() : Algorithm() {}
+      GetEi2() : Algorithm() {}
 
       /// Initialize the algorithm
       void init();
@@ -62,38 +62,38 @@ namespace Algorithms
       void exec();
 
       /// Algorithm's name for identification overriding a virtual method
-      virtual const std::string name() const { return "libISISGetEi"; }
+      virtual const std::string name() const { return "GetEi"; }
       /// Algorithm's version for identification overriding a virtual method
-      virtual const int version() const { return 1; }
+      virtual const int version() const { return 2; }
       /// Algorithm's category for identification overriding a virtual method
       virtual const std::string category() const{return "CorrectionFunctions";}
-     
+
     private:
-    void advanceProgress(double toAdd);
-    void getGeometry(DataObjects::Workspace2D_const_sptr WS, int mon0Spec, int mon1Spec, double &monitor0Dist, double &monitor1Dist) const;
-    std::vector<int> getMonitorSpecIndexs(DataObjects::Workspace2D_const_sptr WS, int specNum1, int specNum2) const;
-    double timeToFly(double s, double E_KE) const;
-    double getPeakCentre(API::MatrixWorkspace_const_sptr WS, const int monitIn, const double peakTime);
-    void extractSpec(int specInd, double start, double end);
-    double getPeakFirstMoments(API::MatrixWorkspace_sptr WS, const double tMin, const double tMax);
-    void getPeakMean(const MantidVec& Xs, const MantidVec& Ys, const MantidVec& Es, const double prominence, double &area, double &c, double &c_fwhm, double &w, double &xbar);
-    void integrate(double &bkgd_m, double &bkgd_err_m, const MantidVec &x, const MantidVec &y, const MantidVec &e, const double start, const double end);
-    API::MatrixWorkspace_sptr smooth(API::MatrixWorkspace_sptr WS);
-    API::MatrixWorkspace_sptr reBin(API::MatrixWorkspace_sptr WS, const double first, const double width, const double end);
-    double neutron_E_At(double speed) const;
-    /// An estimate of the percentage of the algorithm runtimes that has been completed 
-  double m_fracCompl;
-  /// name of the tempory workspace that we create and will contain the monitor histogram that we're examining
-  API::MatrixWorkspace_sptr m_tempWS;
+      void advanceProgress(double toAdd);
+      void getGeometry(DataObjects::Workspace2D_const_sptr WS, int mon0Spec, int mon1Spec, double &monitor0Dist, double &monitor1Dist) const;
+      std::vector<int> getMonitorSpecIndexs(DataObjects::Workspace2D_const_sptr WS, int specNum1, int specNum2) const;
+      double timeToFly(double s, double E_KE) const;
+      double getPeakCentre(API::MatrixWorkspace_const_sptr WS, const int monitIn, const double peakTime);
+      void extractSpec(int specInd, double start, double end);
+      double getPeakFirstMoments(API::MatrixWorkspace_sptr WS, const double tMin, const double tMax);
+      void getPeakMean(const MantidVec& Xs, const MantidVec& Ys, const MantidVec& Es, const double prominence, double &area, double &c, double &c_fwhm, double &w, double &xbar);
+      void integrate(double &bkgd_m, double &bkgd_err_m, const MantidVec &x, const MantidVec &y, const MantidVec &e, const double start, const double end);
+      API::MatrixWorkspace_sptr smooth(API::MatrixWorkspace_sptr WS);
+      API::MatrixWorkspace_sptr reBin(API::MatrixWorkspace_sptr WS, const double first, const double width, const double end);
+      double neutron_E_At(double speed) const;
+      /// An estimate of the percentage of the algorithm runtimes that has been completed 
+      double m_fracCompl;
+      /// name of the tempory workspace that we create and will contain the monitor histogram that we're examining
+      API::MatrixWorkspace_sptr m_tempWS;
 
-    // for estimating algorithm progress
-  static const double CROP;                                ///< fraction of algorithm time taken up with running CropWorkspace
-  static const double GET_COUNT_RATE;                      ///< fraction of algorithm taken by a single call to ConvertToDistribution
-  static const double FIT_PEAK;                            ///< fraction required to find a peak
+      // for estimating algorithm progress
+      static const double CROP;                                ///< fraction of algorithm time taken up with running CropWorkspace
+      static const double GET_COUNT_RATE;                      ///< fraction of algorithm taken by a single call to ConvertToDistribution
+      static const double FIT_PEAK;                            ///< fraction required to find a peak
 
     };
 
-  } // namespace Algorithms
+} // namespace Algorithms
 } // namespace Mantid
 
-#endif /*MANTID_DATAHANDLING_LIBISISGETEI_H_*/
\ No newline at end of file
+#endif /*MANTID_ALGORITHMS_GETEI2_H_*/
\ No newline at end of file
diff --git a/Code/Mantid/Algorithms/src/libISISGetEi.cpp b/Code/Mantid/Algorithms/src/GetEi2.cpp
similarity index 78%
rename from Code/Mantid/Algorithms/src/libISISGetEi.cpp
rename to Code/Mantid/Algorithms/src/GetEi2.cpp
index c883a261a08..3aea2e102ec 100644
--- a/Code/Mantid/Algorithms/src/libISISGetEi.cpp
+++ b/Code/Mantid/Algorithms/src/GetEi2.cpp
@@ -1,4 +1,4 @@
-#include "MantidAlgorithms/libISISGetEi.h"
+#include "MantidAlgorithms/GetEi2.h"
 #include "MantidKernel/ArrayProperty.h"
 #include "MantidKernel/FileProperty.h"
 #include "MantidKernel/PhysicalConstants.h"
@@ -18,7 +18,7 @@ namespace Algorithms
 {
 
 // Register the algorithm into the algorithm factory
-DECLARE_ALGORITHM(libISISGetEi)
+DECLARE_ALGORITHM(GetEi2)
 
 using namespace Kernel;
 using namespace API;
@@ -32,12 +32,12 @@ static const double BKGD_FAC=0.5;
 static const double NO_ESTIMATE=-1e200;
 
 // progress estimates
-const double libISISGetEi::CROP = 0.15;
-const double libISISGetEi::GET_COUNT_RATE = 0.15;
-const double libISISGetEi::FIT_PEAK = 0.2;
+const double GetEi2::CROP = 0.15;
+const double GetEi2::GET_COUNT_RATE = 0.15;
+const double GetEi2::FIT_PEAK = 0.2;
 
 
-void libISISGetEi::init()
+void GetEi2::init()
 
 {// Declare required input parameters for algorithm and do some validation here
   CompositeValidator<Workspace2D> *val = new CompositeValidator<Workspace2D>;
@@ -73,7 +73,7 @@ void libISISGetEi::init()
 *  @throw invalid_argument if a good peak fit wasn't made or the input workspace does not have common binning
 *  @throw runtime_error if there is a problem with the SpectraDetectorMap or a sub-algorithm falls over
 */
-void libISISGetEi::exec()
+void GetEi2::exec()
 {
   Workspace2D_const_sptr inWS = getProperty("InputWorkspace");
   const int mon1Spec = getProperty("Monitor1Spec");
@@ -129,7 +129,7 @@ void libISISGetEi::exec()
 *  @throw NotFoundError if no detector is found for the detector ID given
 *  @throw runtime_error if there is a problem with the SpectraDetectorMap
 */
-void libISISGetEi::getGeometry(DataObjects::Workspace2D_const_sptr WS, int mon0Spec, int mon1Spec, double &monitor0Dist, double &monitor1Dist) const
+void GetEi2::getGeometry(DataObjects::Workspace2D_const_sptr WS, int mon0Spec, int mon1Spec, double &monitor0Dist, double &monitor1Dist) const
 {
   const IObjComponent_sptr source = WS->getInstrument()->getSource();
 
@@ -163,7 +163,7 @@ void libISISGetEi::getGeometry(DataObjects::Workspace2D_const_sptr WS, int mon0S
 *  @return the indexes of the histograms created by the detector whose ID were passed
 *  @throw NotFoundError if one of the requested spectrum numbers was not found in the workspace
 */
-std::vector<int> libISISGetEi::getMonitorSpecIndexs(DataObjects::Workspace2D_const_sptr WS, int specNum1, int specNum2) const
+std::vector<int> GetEi2::getMonitorSpecIndexs(DataObjects::Workspace2D_const_sptr WS, int specNum1, int specNum2) const
 {// getting spectra numbers from detector IDs is hard because the map works the other way, getting index numbers from spectra numbers has the same problem and we are about to do both
   std::vector<int> specInds;
   
@@ -196,7 +196,7 @@ std::vector<int> libISISGetEi::getMonitorSpecIndexs(DataObjects::Workspace2D_con
 * @param E_KE kinetic energy in meV
 * @return the time to taken to travel that uninterrupted distance in seconds
 */
-double libISISGetEi::timeToFly(double s, double E_KE) const
+double GetEi2::timeToFly(double s, double E_KE) const
 {
   // E_KE = mv^2/2, s = vt
   // t = s/v, v = sqrt(2*E_KE/m)
@@ -211,14 +211,14 @@ double libISISGetEi::timeToFly(double s, double E_KE) const
 /** Looks for and examines a peak close to that specified by the input parameters and
 *  examines it to find a representative time for when the neutrons hit the detector
 *  @param WS the workspace containing the monitor spectrum
-*  @param monitIn the index of the histogram that contains the monitor spectrum
+*  @param monitIn Monitor index in the workspace
 *  @param peakTime the estimated TOF of the monitor peak in the time units of the workspace
 *  @return a time of flight value in the peak in microseconds
 *  @throw invalid_argument if a good peak fit wasn't made or the input workspace does not have common binning
 *  @throw out_of_range if the peak runs off the edge of the histogram
 *  @throw runtime_error a sub-algorithm just falls over
 */
-double libISISGetEi::getPeakCentre(API::MatrixWorkspace_const_sptr WS, const int monitIn, const double peakTime)
+double GetEi2::getPeakCentre(API::MatrixWorkspace_const_sptr WS, const int monitIn, const double peakTime)
 {
   double tMin = 0;
   double tMax = 0;
@@ -226,19 +226,21 @@ double libISISGetEi::getPeakCentre(API::MatrixWorkspace_const_sptr WS, const int
   if ( peakTime > 0.0 )
   {
     switch (monitIn)
-    {//MARI specific code
-      case 1 :
+    {
+      case 1:
         tMin = (1-MON1_TOF_WIN)*peakTime;
         tMax = (1+MON1_TOF_WIN)*peakTime;
         g_log.information() << "Based on the user selected energy the first peak will be searched for at TOF " << peakTime << " micro seconds +/-" << boost::lexical_cast<std::string>(100.0*MON1_TOF_WIN) << "%\n";
         break;
-      //MARI specific code
-      case 2 :
+      case 2:
         tMin = (1-MON2_TOF_WIN)*peakTime;
         tMax = (1+MON2_TOF_WIN)*peakTime;
         g_log.information() << "Based on the user selected energy the second peak will be searched for at TOF " << peakTime << " micro seconds +/-" << boost::lexical_cast<std::string>(100.0*MON2_TOF_WIN) << "%\n";
         break;
+      default:
+        throw std::runtime_error("Invalid monitor selected");
     }
+
   }
   else
   {
@@ -253,7 +255,7 @@ double libISISGetEi::getPeakCentre(API::MatrixWorkspace_const_sptr WS, const int
   // look out for user cancel messgages as the above command can take a bit of time
 //  advanceProgress(GET_COUNT_RATE);
 
-  return getPeakFirstMoments(m_tempWS, tMin, tMax );
+  return getPeakFirstMoments(m_tempWS, tMin, tMax);
 }
 /** Calls CropWorkspace as a sub-algorithm and passes to it the InputWorkspace property
 *  @param specInd the index number of the histogram to extract
@@ -263,7 +265,7 @@ double libISISGetEi::getPeakCentre(API::MatrixWorkspace_const_sptr WS, const int
 *  @throw runtime_error if the algorithm just falls over
 *  @throw invalid_argument if the input workspace does not have common binning
 */
-void libISISGetEi::extractSpec(int specInd, double start, double end)
+void GetEi2::extractSpec(int specInd, double start, double end)
 {
   IAlgorithm_sptr childAlg =
     createSubAlgorithm("CropWorkspace", 100*m_fracCompl, 100*(m_fracCompl+CROP) );
@@ -301,7 +303,7 @@ void libISISGetEi::extractSpec(int specInd, double start, double end)
 
 /** Implements the Fortran subroute IXFmoments_dataset_2d() from the libISIS
 */
-double libISISGetEi::getPeakFirstMoments(API::MatrixWorkspace_sptr WS, const double tMin, const double tMax)
+double GetEi2::getPeakFirstMoments(API::MatrixWorkspace_sptr WS, const double tMin, const double tMax)
 {
   // ! the original Fortran subroutine IXFunspike_1d() used by libISIS is more thorough it checks the errors too
   // calls SmoothData as a subalgorithm
@@ -360,7 +362,7 @@ double libISISGetEi::getPeakFirstMoments(API::MatrixWorkspace_sptr WS, const dou
   return T_Mean;
 }
 
-API::MatrixWorkspace_sptr libISISGetEi::smooth(API::MatrixWorkspace_sptr WS)
+API::MatrixWorkspace_sptr GetEi2::smooth(API::MatrixWorkspace_sptr WS)
 {
   IAlgorithm_sptr childAlg =
     createSubAlgorithm("SmoothData");
@@ -386,7 +388,7 @@ API::MatrixWorkspace_sptr libISISGetEi::smooth(API::MatrixWorkspace_sptr WS)
   return childAlg->getProperty("OutputWorkspace");
 }
 
-API::MatrixWorkspace_sptr libISISGetEi::reBin(API::MatrixWorkspace_sptr WS, const double first, const double width, const double end)
+API::MatrixWorkspace_sptr GetEi2::reBin(API::MatrixWorkspace_sptr WS, const double first, const double width, const double end)
 {
   IAlgorithm_sptr childAlg =
     createSubAlgorithm("Rebin");
@@ -414,7 +416,7 @@ API::MatrixWorkspace_sptr libISISGetEi::reBin(API::MatrixWorkspace_sptr WS, cons
   return childAlg->getProperty("OutputWorkspace");
 }
 
-void libISISGetEi::getPeakMean(const MantidVec& Xs, const MantidVec& Ys, const MantidVec& Es, const double prominence, double &area, double &c, double &c_fwhm, double &w, double &xbar)
+void GetEi2::getPeakMean(const MantidVec& Xs, const MantidVec& Ys, const MantidVec& Es, const double prominence, double &area, double &c, double &c_fwhm, double &w, double &xbar)
 {
   MantidVec::const_iterator peakIt = std::max_element(Ys.begin(), Ys.end());    //! position of peak
   unsigned int iPeak = peakIt - Ys.begin();
@@ -615,7 +617,7 @@ void libISISGetEi::getPeakMean(const MantidVec& Xs, const MantidVec& Ys, const M
   advanceProgress(FIT_PEAK);
 }
 
-void libISISGetEi::integrate(double &bkgd_m, double &bkgd_err_m, const MantidVec &x, const MantidVec &s, const MantidVec &e, const double xmin, const double xmax)
+void GetEi2::integrate(double &bkgd_m, double &bkgd_err_m, const MantidVec &x, const MantidVec &s, const MantidVec &e, const double xmin, const double xmax)
 {
   MantidVec::const_iterator lowit=std::lower_bound(x.begin(), x.end(), xmin);
   MantidVec::difference_type distmin=std::distance(x.begin(),lowit);
@@ -628,137 +630,20 @@ void libISISGetEi::integrate(double &bkgd_m, double &bkgd_err_m, const MantidVec
   bkgd_m=std::inner_product(s.begin()+distmin,s.begin()+distmax,widths.begin(),0.0);
   bkgd_err_m=std::inner_product(e.begin()+distmin,e.begin()+distmax,widths.begin(),0.0,std::plus<double>(),VectorHelper::TimesSquares<double>());
 
-//    unsigned int nx = s.size();
-//    unsigned int ml(0), mu(nx - 1);
-//    MantidVec::const_iterator lowit = std::lower_bound(x.begin(), x.end(), xmin);
-//    ml = lowit - x.begin();
-//    
-//    MantidVec::const_iterator highit = std::lower_bound(x.begin(), x.end(), xmax);
-//    mu = highit - x.begin();
-//   
-//
-//
-//    //! note: At this point, 0=<ml=<nx & xmin=<x(ml); 1=<mu=<nx & x(mu)=<xmax; BUT mu > ml-1
-//
-//    //! Perform integration:
-//    //! ----------------------
-//
-//    //! Calculate integral:
-//
-//    //!	if (mu<ml) then
-//    //!	special case of no data points in the integration range
-//    //!		ilo = max(ml-1,1)	! x(1) is end point if ml=1
-//    //!		ihi = min(mu+1,nx)	! x(mu) is end point if mu=nx
-//    //!		val = 0.5_dp * ((xmax-xmin)/(x(ihi)-x(ilo))) * &
-//    //!			&( s(ihi)*((xmax-x(ilo))+(xmin-x(ilo))) + s(ilo)*((x(ihi)-xmax)+(x(ihi)-xmin)) )
-//    //!	else
-//    //!	xmin and xmax are separated by at least one data point in x(:)
-//    //!	  sum over complete steps in the integration range:
-//    //!		if (mu > ml) then	! at least one complete step
-//    //!			val = sum((s(ml+1:mu)+s(ml:mu-1))*(x(ml+1:mu)-x(ml:mu-1)))
-//    //!		else
-//    //!			val = 0.0_dp
-//    //!		endif
-//    //!	  ends of the integration range:
-//    //!		if (ml>1) then	! x(1) is end point if ml=1
-//    //!			x1eff = (xmin*(xmin-x(ml-1)) + x(ml-1)*(x(ml)-xmin))/(x(ml)-x(ml-1))
-//    //!			s1eff = s(ml-1)*(x(ml)-xmin)/((x(ml)-x(ml-1)) + (xmin-x(ml-1)))
-//    //!			val = val + (x(ml)-x1eff)*(s(ml)+s1eff)
-//    //!		endif
-//    //!		if (mu<nx) then	! x(mu) is end point if mu=nx
-//    //!			xneff = (xmax*(x(mu+1)-xmax) + x(mu+1)*(xmax-x(mu)))/(x(mu+1)-x(mu))
-//    //!			sneff = s(mu+1)*(xmax-x(mu))/((x(mu+1)-x(mu)) + (x(mu+1)-xmax))
-//    //!			val = val + (xneff-x(mu))*(s(mu)+sneff)
-//    //!		endif
-//    //!		val = 0.5_dp*val
-//    //!	endif			
-//
-//    //! Calculate error on the integral:
-//
-//    if (mu<ml) 
-//    {
-//      throw std::out_of_range("Incorrect integration limits");
-//    }
-//
-//    //!	xmin and xmax are separated by at least one data point in x(:)
-//      // !	Set up effective end points:
-//    double x1eff(0.0), s1eff(0.0), e1eff(0.0);
-//    if (ml > 0) 
-//    {
-//      	// x(1) is end point if ml=1
-//          x1eff = (xmin*(xmin-x[ml-1]) + x[ml-1]*(x[ml]-xmin))/(x[ml]-x[ml-1]);
-//          s1eff = s[ml-1]*(x[ml]-xmin)/((x[ml]-x[ml-1]) + (xmin-x[ml-1]));
-//          e1eff = e[ml-1]*(x[ml]-xmin)/((x[ml]-x[ml-1]) + (xmin-x[ml-1]));
-//    }
-//    else 
-//    {
-//         x1eff = x[ml];
-//         s1eff = 0.0;
-//         e1eff = 0.0;
-//    }
-//    double xneff(0.0), sneff(0.0), eneff(0.0); 
-//    if ( mu < nx - 1 ) 
-//    {	
-//      // x(mu) is end point if mu=nx
-//          xneff = (xmax*(x[mu+1]-xmax) + x[mu+1]*(xmax-x[mu]))/(x[mu+1]-x[mu]);
-//          sneff = s[mu+1]*(xmax-x[mu])/((x[mu+1]-x[mu]) + (x[mu+1]-xmax));
-//          eneff = e[mu+1]*(xmax-x[mu])/((x[mu+1]-x[mu]) + (x[mu+1]-xmax));
-//    }
-//       else
-//       {
-//          xneff = x[nx -1];
-//          sneff = 0.0;
-//          eneff = 0.0;
-//      }
-//       //	xmin to x(ml):
-//       double val = (x[ml]-x1eff)*(s[ml]+s1eff);
-//         double err = std::pow(e1eff*(x[ml]-x1eff), 2);
-////       !	x(ml) to x(mu):
-//       if (mu==ml)
-//       {
-//         //! one data point, no complete intervals
-//         err = err + std::pow(e[ml]*(xneff-x1eff), 2);
-//       }
-//       else if (mu == ml+1)
-//       {
-//         //! one complete interval
-//          val = val + (s[mu]+s[ml])*(x[mu]-x[ml]);
-//          err = err + std::pow(e[ml]*(x[ml+1]-x1eff), 2) + std::pow(e[mu]*(xneff-x[mu-1]), 2);
-//       }
-//       else
-//       {
-//         // ! this is the whole trapezium summing
-////          val = val + sum( (s(ml+1:mu)+s(ml:mu-1))*(x(ml+1:mu)-x(ml:mu-1)) );
-//            std::vector<double> ssum(mu - ml, 0.0);
-//            std::transform(s.begin()+ml+1, s.begin()+mu, s.begin()+ml, ssum.begin(), std::plus<double>());
-//            std::vector<double> xdiff(mu - ml, 0.0);
-//            std::transform(x.begin()+ml+1, x.begin()+mu, x.begin()+ml, xdiff.begin(), std::minus<double>());
-//            val += std::inner_product(ssum.begin(), ssum.end(), xdiff.begin(), 0.0);
-//
-//          //err = err + (e(ml)*(x(ml+1)-x1eff))**2 + (e(mu)*(xneff-x(mu-1)))**2 
-//          //err = err+ sum((e(ml+1:mu-1)*(x(ml+2:mu)-x(ml:mu-2)))**2)
-//       }
-//
-//       //	x(mu) to xmax:
-//       val = val + (xneff-x[mu])*(s[mu]+sneff);
-//         err = err + std::pow(eneff*(xneff-x[mu]), 2);
-//
-//       bkgd_m = 0.5*val;
-//       bkgd_err_m = 0.0;//0.5*std::sqrt(err);
 }
 
 /** Get the kinetic energy of a neuton in joules given it speed using E=mv^2/2
 *  @param speed the instantanious speed of a neutron in metres per second
 *  @return the energy in joules
 */
-double libISISGetEi::neutron_E_At(double speed) const
+double GetEi2::neutron_E_At(double speed) const
 {
   // E_KE = mv^2/2
   return PhysicalConstants::NeutronMass*speed*speed/(2);
 }
 
 /// Update the percentage complete estimate assuming that the algorithm has completed a task with estimated RunTime toAdd
-void libISISGetEi::advanceProgress(double toAdd)
+void GetEi2::advanceProgress(double toAdd)
 {
   m_fracCompl += toAdd;
   progress(m_fracCompl);
diff --git a/Code/Mantid/PythonAPI/scripts/Excitations/CommonFunctions.py b/Code/Mantid/PythonAPI/scripts/Excitations/CommonFunctions.py
index 6a146d66b18..933f5b11064 100644
--- a/Code/Mantid/PythonAPI/scripts/Excitations/CommonFunctions.py
+++ b/Code/Mantid/PythonAPI/scripts/Excitations/CommonFunctions.py
@@ -98,13 +98,14 @@ def getRunName(path):
 #-- Holds data about the defaults used for diferent instruments (MARI, MAPS ...)
 class defaults:
   # set the defaults for a default machine. These default values for defaults won't work and so they must be overriden by the correct values for the machine when this is run
-  def __init__(self, background_range=(-1.0,-1.0), normalization='not set', instrument_pref='', white_beam_integr=(-1.0,-1.0), scale_factor=1, monitor1_integr=(-1.0e5, -1.0e5)):
+  def __init__(self, background_range=(-1.0,-1.0), normalization='not set', instrument_pref='', white_beam_integr=(-1.0,-1.0), scale_factor=1, monitor1_integr=(-1.0e5, -1.0e5), white_beam_scale = 1.0):
     self.background_range=background_range
     self.normalization=normalization
     self.instrument_pref=instrument_pref
     self.white_beam_integr=white_beam_integr
     self.scale_factor=scale_factor
     self.monitor1_integr=monitor1_integr
+    self.white_beam_scale = white_beam_scale
       
   # guess the filename from run number assuming global_getFileName_instrument_pref is setup
   def getFileName(self, runNumber):
diff --git a/Code/Mantid/PythonAPI/scripts/Excitations/ConversionLib.py b/Code/Mantid/PythonAPI/scripts/Excitations/ConversionLib.py
index e35cf320bdb..c2d8dd82c05 100644
--- a/Code/Mantid/PythonAPI/scripts/Excitations/ConversionLib.py
+++ b/Code/Mantid/PythonAPI/scripts/Excitations/ConversionLib.py
@@ -34,13 +34,14 @@ def NormaliseToWhiteBeam(instr, WBRun, toNorm, mapFile, detMask, prevNorm) :
     NormaliseTo(prevNorm, pNorm, 0, instr)
 
     ConvertUnits(pNorm, pNorm, "Energy", AlignBins=0)
-
+    
     #this both integrates the workspace into one bin spectra and sets up common bin boundaries for all spectra
     #    wb_rebin = str(wb_low_e) + ', ' + str(2.0*float(wb_high_e)) + ', ' + str(wb_high_e)
-    Rebin(pNorm, pNorm,
-      str(instr.white_beam_integr[0])+','+str(2.0*instr.white_beam_integr[1])+','+str(instr.white_beam_integr[1])  )
-   # shouldn't we do the correction? It affects things when the angles are different, would need a LoadDetectorInfo too
-  #  DetectorEfficiencyCor(pNorm, pNorm, IncidentE)  
+    low = instr.white_beam_integr[0]
+    hi = instr.white_beam_integr[1]
+    delta = 2.0*(hi - low)
+    Rebin(pNorm, pNorm, str(low)+','+str(delta)+','+str(hi)  )
+
     if detMask != '' :
       MaskDetectors(pNorm, SpectraList=detMask)
     
@@ -83,21 +84,16 @@ def retrieveSettings(instrum, back, runs):
   
   return (instru, TOFLow, TOFHigh, run_nums)
 
-def findPeaksOffSetTimeAndEi(workS, E_guess, getEi=True, detInfoFile='', GetEiType = 'MantidGetEi'):
+def findPeaksOffSetTimeAndEi(workS, E_guess, getEi=True, detInfoFile=''):
   if detInfoFile != '' :
     LoadDetectorInfo(workS, detInfoFile)             				                  #for details see www.mantidproject.org/LoadDetectorInfo
 
   runGetEi = str(getEi).lower() != 'fixei' and str(getEi).lower() != 'false'
   if not runGetEi :
     mtd.sendLogMessage('Getting peak times (the GetEi() energy will be overriden by '+str(E_guess)+' meV)')
-
-  #MARI specfic code GetEiData.FirstMonitor ?
-  if GetEiType.lower() == "mantidgetei":
-    GetEiData = GetEi(workS, 2, 3, E_guess)
-  else:
-    if E_guess == '':
-      E_guess = None
-    GetEiData = libISISGetEi(workS, 2, 3, E_guess)
+    
+  # Get incident energy
+  GetEiData = GetEi(workS, 2, 3, E_guess)
 
   if runGetEi : Ei = GetEiData.getPropertyValue('IncidentEnergy')
   else : Ei = E_guess
@@ -110,7 +106,7 @@ def findPeaksOffSetTimeAndEi(workS, E_guess, getEi=True, detInfoFile='', GetEiTy
   mtd.sendLogMessage('Adjusting the X-values so that the zero of time is when the peak was registered at the new origin , which monitor 2')
   src = workS.getInstrument().getSource().getName()                             #this name could be 'Moderator',  'undulator', etc.
   MoveInstrumentComponent(workS, src, X=p0.getX() , Y=p0.getY() ,Z=p0.getZ(), RelativePosition=False)
-  return [Ei, offSetTime]
+  return Ei, offSetTime
   
 # a workspace name that is very long and unlikely to have been created by the user before this script is run, it would be replaced  
 tempWS = '_ETrans_loading_tempory_WS'
@@ -119,7 +115,7 @@ tempWS = '_ETrans_loading_tempory_WS'
 # Applies unit conversion, detector convcy and grouping correction to a
 # raw file
 ###########################################
-def mono_sample(instrum, runs, Ei, d_rebin, wbrf, getEi=True, back='', norma='', det_map='', det_mask='', nameInOut = 'mono_sample_temporyWS', GetEiType = 'MantidGetEi') :
+def mono_sample(instrum, runs, Ei, d_rebin, wbrf, getEi=True, back='', norma='', det_map='', det_mask='', nameInOut = 'mono_sample_temporyWS') :
   (instru, TOFLow, TOFHigh, run_nums) = retrieveSettings(instrum, back, runs)
 
   #----Calculations start------------------
@@ -128,7 +124,7 @@ def mono_sample(instrum, runs, Ei, d_rebin, wbrf, getEi=True, back='', norma='',
     if pInOut.isGroup() : raise Exception("Workspace groups are not supported here")
 
     common.sumWorkspaces(pInOut, instru, run_nums)                              #the final workspace will take the X-values and instrument from the first workspace and so we don't need to rerun ChangeBinOffset(), MoveInstrumentComponent(), etc.
-    [Ei, offSet] = findPeaksOffSetTimeAndEi(pInOut, Ei, getEi, instru.getFileName(run_nums[0]),GetEiType )
+    Ei, offSet = findPeaksOffSetTimeAndEi(pInOut, Ei, getEi, instru.getFileName(run_nums[0]))
  
     if back != 'noback':                                                        #remove the count rate seen in the regions of the histograms defined as the background regions, if the user defined a region
       ConvertToDistribution(pInOut)                                             #deal correctly with changing bin widths
@@ -152,17 +148,14 @@ def mono_sample(instrum, runs, Ei, d_rebin, wbrf, getEi=True, back='', norma='',
       GroupDetectors(pInOut, pInOut, det_map, KeepUngroupedSpectra=0)
 
     ConvertToDistribution(pInOut)
-  
-#    CreateSingleValuedWorkspace(tempWS, instru.scale_factor)
-#    Multiply(pInOut, tempWS, pInOut)
-#    mantid.deleteWorkspace(tempWS)
-    pInOut *= instru.scale_factor                               #we need '*=' here '*' would do something very different
+    pInOut *= instru.scale_factor 
     
     #replaces inifinities and error values with large numbers. Infinity values can be normally be avoided passing good energy values to ConvertUnits
     ReplaceSpecialValues(pInOut, pInOut, 1e40, 1e40, 1e40, 1e40)
 
     NormaliseToWhiteBeam(instru, wbrf, pInOut, det_map, det_mask, norma)
-   
+    pInOut /= instru.white_beam_scale
+    
     return pInOut
 
   except Exception, reason:
diff --git a/Code/Mantid/PythonAPI/scripts/Excitations/ExcitDefaults.py b/Code/Mantid/PythonAPI/scripts/Excitations/ExcitDefaults.py
index 1f321b4bf6e..6659d534125 100644
--- a/Code/Mantid/PythonAPI/scripts/Excitations/ExcitDefaults.py
+++ b/Code/Mantid/PythonAPI/scripts/Excitations/ExcitDefaults.py
@@ -7,7 +7,9 @@ MARI = common.defaults(
   instrument_pref='MAR',
   white_beam_integr=(20.0,40.0),
   scale_factor=1.8182e8,
-  monitor1_integr=(1000,2000))
+  monitor1_integr=(1000,2000),
+  white_beam_scale=1000.
+  )
 
 MAPS = common.defaults(
   background_range=(12000.0, 18000.0),
diff --git a/Code/Mantid/PythonAPI/scripts/Excitations/GUI_Interface.py b/Code/Mantid/PythonAPI/scripts/Excitations/GUI_Interface.py
index 8007c6e64d2..a87623f5cc5 100644
--- a/Code/Mantid/PythonAPI/scripts/Excitations/GUI_Interface.py
+++ b/Code/Mantid/PythonAPI/scripts/Excitations/GUI_Interface.py
@@ -18,5 +18,5 @@ if DetectorMask != '' :
   badSpectra = FDOL.getPropertyValue('BadSpectraNums')
   mantid.deleteWorkspace('_ETrans_loading_bad_detector_WS')
 
-mtd.sendLogMessage("--Executing Python function: mono_sample('MAR', '|GUI_SET_RAWFILE_LIST|', |GUI_SET_E_GUESS|, |GUI_SET_BIN_BOUNDS|, |GUI_SET_WBV|, getEi=|GUI_SET_E|, back='('+|TOF_LOW|+','+|TOF_HIGH|+')', norma=|GUI_SET_NORM|, det_map=|GUI_SET_MAP_FILE|, det_mask=badSpectra, nameInOut='|GUI_SET_OUTWS|', GetEiType='|GUI_GETEI_TYPE|')--")
-mono_sample('MAR', '|GUI_SET_RAWFILE_LIST|', |GUI_SET_E_GUESS|, |GUI_SET_BIN_BOUNDS|, |GUI_SET_WBV|, getEi=|GUI_SET_E|, back='('+|TOF_LOW|+','+|TOF_HIGH|+')', norma=|GUI_SET_NORM|, det_map=|GUI_SET_MAP_FILE|, det_mask=badSpectra, nameInOut='|GUI_SET_OUTWS|', GetEiType='|GUI_GETEI_TYPE|')
+mtd.sendLogMessage("--Executing Python function: mono_sample('MAR', '|GUI_SET_RAWFILE_LIST|', |GUI_SET_E_GUESS|, |GUI_SET_BIN_BOUNDS|, |GUI_SET_WBV|, getEi=|GUI_SET_E|, back='('+|TOF_LOW|+','+|TOF_HIGH|+')', norma=|GUI_SET_NORM|, det_map=|GUI_SET_MAP_FILE|, det_mask=badSpectra, nameInOut='|GUI_SET_OUTWS|')--")
+mono_sample('MAR', '|GUI_SET_RAWFILE_LIST|', |GUI_SET_E_GUESS|, |GUI_SET_BIN_BOUNDS|, |GUI_SET_WBV|, getEi=|GUI_SET_E|, back='('+|TOF_LOW|+','+|TOF_HIGH|+')', norma=|GUI_SET_NORM|, det_map=|GUI_SET_MAP_FILE|, det_mask=badSpectra, nameInOut='|GUI_SET_OUTWS|')
diff --git a/Code/qtiplot/MantidQt/CustomInterfaces/inc/Homer.ui b/Code/qtiplot/MantidQt/CustomInterfaces/inc/Homer.ui
index 2daa30f7a9c..a9ab9b4eb58 100644
--- a/Code/qtiplot/MantidQt/CustomInterfaces/inc/Homer.ui
+++ b/Code/qtiplot/MantidQt/CustomInterfaces/inc/Homer.ui
@@ -8,7 +8,7 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>436</width>
+    <width>386</width>
     <height>465</height>
    </rect>
   </property>
@@ -153,6 +153,19 @@
           <bool>false</bool>
          </property>
          <layout class="QGridLayout" name="gridLayout_3" >
+          <item row="0" column="1" >
+           <spacer name="verticalSpacer_4" >
+            <property name="orientation" >
+             <enum>Qt::Vertical</enum>
+            </property>
+            <property name="sizeHint" stdset="0" >
+             <size>
+              <width>20</width>
+              <height>10</height>
+             </size>
+            </property>
+           </spacer>
+          </item>
           <item row="1" column="0" >
            <widget class="QLabel" name="lbNorm" >
             <property name="toolTip" >
@@ -289,52 +302,7 @@
             </property>
            </widget>
           </item>
-          <item row="0" column="1" >
-           <spacer name="verticalSpacer_4" >
-            <property name="orientation" >
-             <enum>Qt::Vertical</enum>
-            </property>
-            <property name="sizeHint" stdset="0" >
-             <size>
-              <width>20</width>
-              <height>10</height>
-             </size>
-            </property>
-           </spacer>
-          </item>
-          <item row="2" column="5" >
-           <widget class="QComboBox" name="getei_type" >
-            <property name="minimumSize" >
-             <size>
-              <width>90</width>
-              <height>0</height>
-             </size>
-            </property>
-            <item>
-             <property name="text" >
-              <string>MantidGetEi</string>
-             </property>
-            </item>
-            <item>
-             <property name="text" >
-              <string>libISISGetEi</string>
-             </property>
-            </item>
-           </widget>
-          </item>
          </layout>
-         <zorder>lbNorm</zorder>
-         <zorder>cbNormal</zorder>
-         <zorder>cbMonitors</zorder>
-         <zorder>pbBack</zorder>
-         <zorder>valBg</zorder>
-         <zorder>ckSumSpecs</zorder>
-         <zorder>ckFixEi</zorder>
-         <zorder>map_fileInput_lbName</zorder>
-         <zorder>map_fileInput_leName</zorder>
-         <zorder>valMap</zorder>
-         <zorder>map_fileInput_pbBrowse</zorder>
-         <zorder>getei_type</zorder>
         </widget>
        </item>
        <item row="2" column="0" colspan="6" >
diff --git a/Code/qtiplot/MantidQt/CustomInterfaces/src/deltaECalc.cpp b/Code/qtiplot/MantidQt/CustomInterfaces/src/deltaECalc.cpp
index 35e326adbfb..913a685d023 100644
--- a/Code/qtiplot/MantidQt/CustomInterfaces/src/deltaECalc.cpp
+++ b/Code/qtiplot/MantidQt/CustomInterfaces/src/deltaECalc.cpp
@@ -115,16 +115,6 @@ QString deltaECalc::createProcessingScript(const std::string &inFiles, const std
 
   m_pyScript.replace("|GUI_SET_WBV|", "'"+whiteB+"'");
 
-  QString eitype;
-  if( m_sets.getei_type->currentIndex() == 0 )
-  {
-    eitype = "MantidGetEi";
-  }
-  else
-  {
-    eitype = "libISISGetEi";
-  }
-  m_pyScript.replace("|GUI_GETEI_TYPE|", eitype);
   // use a FileProperty to check that the file exists
   std::vector<std::string> exts;
   exts.push_back("map"); exts.push_back("MAP");
@@ -144,20 +134,11 @@ QString deltaECalc::createProcessingScript(const std::string &inFiles, const std
 */
 void deltaECalc::createGetEIStatmens(QString &newScr)
 {
-  if (m_sets.getei_type->currentIndex() == 0 )
-  {//means we are going to run GetEi, this has a validator, check it
-   // create this algorithm for doing the validation, actually, depending on the user settings, getEi might not get run but the validation is good anyway
-     IAlgorithm_sptr gEi = AlgorithmManager::Instance().createUnmanaged("GetEi");
-     gEi->initialize();
-    //this e guess (approximate Ei value) doesn't always get used, it depends on the tests above. However, Pyhton requires that the '|' in the code is replaced by something
-    LEChkCpIn(newScr, "|GUI_SET_E_GUESS|", m_sets.leEGuess,
-      gEi->getProperty("EnergyEstimate"));
-  }
-  else
-  {
-    // going to run libISISGetEi"
-    m_pyScript.replace("|GUI_SET_E_GUESS|", "'"+m_sets.leEGuess->text()+"'");
-  }
+  // create this algorithm for doing the validation, actually, depending on the user settings, getEi might not get run but the validation is good anyway
+  IAlgorithm_sptr gEi = AlgorithmManager::Instance().createUnmanaged("GetEi");
+  gEi->initialize();
+  //this e guess (approximate Ei value) doesn't always get used, it depends on the tests above. However, Pyhton requires that the '|' in the code is replaced by something
+  LEChkCpIn(newScr, "|GUI_SET_E_GUESS|", m_sets.leEGuess, gEi->getProperty("EnergyEstimate"));
 
   // run getEi, unless the user checked the box 
   if (m_sets.ckFixEi->isChecked())
-- 
GitLab