Skip to content

Commit

Permalink
Make function not to inherit from IPeakFunction. Refs #6716.
Browse files Browse the repository at this point in the history
  • Loading branch information
wdzhou authored and abuts committed Mar 28, 2013
1 parent 64cbe27 commit 194253a
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

#include "MantidKernel/System.h"
#include "MantidAPI/IPeakFunction.h"
#include "MantidAPI/IFunctionWithLocation.h"
#include "MantidAPI/IFunctionMW.h"
#include "MantidAPI/IFunction1D.h"
#include "MantidGeometry/Crystal/UnitCell.h"
#include "MantidKernel/Logger.h"
#include <complex>
Expand Down Expand Up @@ -41,7 +43,7 @@ namespace CurveFitting
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/

class DLLExport ThermalNeutronBk2BkExpConvPVoigt : virtual public API::IPeakFunction,
class DLLExport ThermalNeutronBk2BkExpConvPVoigt : virtual public API::ParamFunction,public virtual API::IFunction1D,
virtual public API::IFunctionMW
{
public:
Expand All @@ -53,10 +55,12 @@ namespace CurveFitting
virtual const std::string category() const { return "Peak";}

/// Overwrite IPeakFunction base class methods
virtual double centre()const;
virtual double height()const;
virtual double fwhm()const;
virtual void setHeight(const double h);
double centre()const;
double height()const;
double fwhm()const;
void setHeight(const double h);

void setPeakRadius(const int& r);

//--------------- ThermalNeutron peak function special ---------------------------------------
/// Set Miller Indicies
Expand Down Expand Up @@ -88,6 +92,8 @@ namespace CurveFitting
/// Override setting a new value to a parameter by name
void setParameter(const std::string& name, const double& value, bool explicitlySe=true);

void function1D(double* out, const double* xValues, const size_t nData)const;

protected:
//----- Overwrite IFunction ------------------------------------------------
/// Fuction local
Expand All @@ -100,6 +106,8 @@ namespace CurveFitting
/// Overwrite IFunction base class method, which declare function parameters
virtual void init();

static int s_peakRadius;

private:
/// Static reference to the logger class
static Kernel::Logger& g_log;
Expand All @@ -117,8 +125,10 @@ namespace CurveFitting
const bool explicitoutput=false) const;

/// Set 2 functions to be hidden from client
/*
virtual void setCentre(const double c);
virtual void setFwhm(const double w);
*/

//------------------------------------------ Variables --------------------------------------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -422,14 +422,6 @@ namespace CurveFitting
return m_centre;
}

/** Set peak center. Not allowed
*/
void ThermalNeutronBk2BkExpConvPVoigt::setCentre(const double c)
{
UNUSED_ARG(c);
throw std::invalid_argument("ThermalNuetronBk2BkExpConvPV: do not allow to set peak's centre");
}

/** Set peak height
*/
void ThermalNeutronBk2BkExpConvPVoigt::setHeight(const double h)
Expand All @@ -456,17 +448,9 @@ namespace CurveFitting
return m_fwhm;
}

/** Set peak's FWHM
*/
void ThermalNeutronBk2BkExpConvPVoigt::setFwhm(const double w)
{
UNUSED_ARG(w);
throw std::invalid_argument("Unable to set FWHM");
}

//------------- Private Function To Calculate Peak Profile --------------------------------------------
/** Calcualte H and eta for the peak
*/
*/
void ThermalNeutronBk2BkExpConvPVoigt::calHandEta(double sigma2, double gamma, double& H, double& eta) const
{
// 1. Calculate H
Expand Down Expand Up @@ -689,5 +673,54 @@ namespace CurveFitting
return exp_e1;
}

//----------------------------------------------------------------------------------------------
/** (Migrated from IPeakFunction)
* General implementation of the method for all peaks. Limits the peak evaluation to
* a certain number of FWHMs around the peak centre. The outside points are set to 0.
* Calls functionLocal() to compute the actual values
* @param out :: Output function values
* @param xValues :: X values for data points
* @param nData :: Number of data points
*/
void ThermalNeutronBk2BkExpConvPVoigt::function1D(double* out, const double* xValues, const size_t nData)const
{
double c = this->centre();
double dx = fabs(s_peakRadius*this->fwhm());
int i0 = -1;
int n = 0;
for(size_t i = 0; i < nData; ++i)
{
if (fabs(xValues[i] - c) < dx)
{
if (i0 < 0) i0 = static_cast<int>(i);
++n;
}
else
{
out[i] = 0.0;
}
}
if (i0 < 0 || n == 0) return;
this->functionLocal(out+i0, xValues+i0, n);

return;
}

/// Default value for the peak radius
int ThermalNeutronBk2BkExpConvPVoigt::s_peakRadius = 5;

//----------------------------------------------------------------------------------------------
/** Set peak radius
*/
void ThermalNeutronBk2BkExpConvPVoigt::setPeakRadius(const int& r)
{
if (r > 0)
{
s_peakRadius = r;
std::string setting = boost::lexical_cast<std::string>(r);
Kernel::ConfigService::Instance().setString("curvefitting.peakRadius",setting);
}
}

} // namespace CurveFitting
} // namespace Mantid

0 comments on commit 194253a

Please sign in to comment.