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
Michael Wedel
committed
May 22, 2015
1 parent
c3295ac
commit 6bf72dc
Showing
9 changed files
with
229 additions
and
23 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
69 changes: 69 additions & 0 deletions
69
Code/Mantid/Framework/CurveFitting/inc/MantidCurveFitting/PoldiCalibrationProfile.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,69 @@ | ||
#ifndef MANTID_CURVEFITTING_POLDICALIBRATIONFUNCTION_H_ | ||
#define MANTID_CURVEFITTING_POLDICALIBRATIONFUNCTION_H_ | ||
|
||
#include "MantidCurveFitting/Gaussian.h" | ||
|
||
namespace Mantid { | ||
namespace CurveFitting { | ||
|
||
/** PoldiCalibrationProfile | ||
Instrument parameters at POLDI are calibrated using an additional parameter | ||
that changes the slope of Bragg lines in the POLDI 2D data. If the | ||
instrument is calibrated properly, the parameter is 0. | ||
Since silicon powder is used as standard, peak profiles are always Gaussian, | ||
so the Gaussian function from this module is re-used. The additional | ||
parameter depends on 2theta, so it can only be used in conjunction with the | ||
PoldiSpectrumCalibrationFunction in the SINQ module. If used otherwise | ||
it will behave like Gaussian with an additional parameter that does nothing. | ||
@author Michael Wedel, Paul Scherrer Institut - SINQ | ||
@date 04/05/2015 | ||
Copyright © 2015 PSI-NXMM | ||
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://github.com/mantidproject/mantid> | ||
Code Documentation is available at: <http://doxygen.mantidproject.org> | ||
*/ | ||
class DLLExport PoldiCalibrationProfile : public Gaussian { | ||
public: | ||
~PoldiCalibrationProfile() {} | ||
|
||
std::string name() const { return "PoldiCalibrationProfile"; } | ||
|
||
double centre() const; | ||
|
||
void functionLocal(double *out, const double *xValues, | ||
const size_t nData) const; | ||
void functionDerivLocal(API::Jacobian *out, const double *xValues, | ||
const size_t nData); | ||
|
||
// void functionDerivLocal(API::Jacobian *out, const double *xValues, const | ||
// size_t nData); | ||
|
||
protected: | ||
double getAbsoluteShift() const; | ||
|
||
void init(); | ||
}; | ||
|
||
} // namespace CurveFitting | ||
} // namespace Mantid | ||
|
||
#endif /* MANTID_CURVEFITTING_POLDICALIBRATIONFUNCTION_H_ */ |
68 changes: 68 additions & 0 deletions
68
Code/Mantid/Framework/CurveFitting/src/PoldiCalibrationProfile.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,68 @@ | ||
#include "MantidCurveFitting/PoldiCalibrationProfile.h" | ||
#include "MantidAPI/FunctionFactory.h" | ||
|
||
namespace Mantid { | ||
namespace CurveFitting { | ||
|
||
using namespace API; | ||
|
||
DECLARE_FUNCTION(PoldiCalibrationProfile) | ||
|
||
void PoldiCalibrationProfile::functionLocal(double *out, const double *xValues, | ||
const size_t nData) const { | ||
|
||
const double height = getParameter("Height"); | ||
const double peakCentre = getParameter("PeakCentre"); | ||
const double shift = getAbsoluteShift(); | ||
const double realCentre = peakCentre + peakCentre * shift; | ||
|
||
const double weight = pow(1 / getParameter("Sigma"), 2); | ||
|
||
for (size_t i = 0; i < nData; i++) { | ||
double diff = xValues[i] - realCentre; | ||
out[i] = height * exp(-0.5 * diff * diff * weight); | ||
} | ||
} | ||
|
||
void PoldiCalibrationProfile::functionDerivLocal(Jacobian *out, | ||
const double *xValues, | ||
const size_t nData) { | ||
const double height = getParameter("Height"); | ||
const double peakCentre = getParameter("PeakCentre"); | ||
const double shift = getAbsoluteShift(); | ||
const double realCentre = peakCentre + peakCentre * shift; | ||
|
||
const double weight = pow(1 / getParameter("Sigma"), 2); | ||
const double factor = getAttribute("DeltaTheta").asDouble() / 1000.0; | ||
|
||
for (size_t i = 0; i < nData; i++) { | ||
double diff = xValues[i] - realCentre; | ||
double e = exp(-0.5 * diff * diff * weight); | ||
double b = e * height * diff * weight; | ||
out->set(i, 0, e); | ||
out->set(i, 1, b * (1.0 + shift)); | ||
out->set(i, 2, -0.5 * diff * diff * height * | ||
e); // derivative with respect to weight not sigma | ||
out->set(i, 3, b * factor * peakCentre); | ||
} | ||
} | ||
|
||
double PoldiCalibrationProfile::centre() const { | ||
return getParameter("PeakCentre") + | ||
getParameter("PeakCentre") * getAbsoluteShift(); | ||
} | ||
|
||
double PoldiCalibrationProfile::getAbsoluteShift() const { | ||
return getParameter("Slope") * 1.e-3 * getAttribute("DeltaTheta").asDouble(); | ||
} | ||
|
||
/// Initialize Gaussian parameters and declare additional parameter. | ||
void PoldiCalibrationProfile::init() { | ||
Gaussian::init(); | ||
|
||
declareParameter("Slope"); | ||
declareAttribute("DeltaTheta", IFunction::Attribute(0.0)); | ||
} | ||
|
||
} // namespace CurveFitting | ||
} // namespace Mantid |
44 changes: 44 additions & 0 deletions
44
Code/Mantid/Framework/CurveFitting/test/PoldiCalibrationProfileTest.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,44 @@ | ||
#ifndef MANTID_CURVEFITTING_POLDICALIBRATIONFUNCTIONTEST_H_ | ||
#define MANTID_CURVEFITTING_POLDICALIBRATIONFUNCTIONTEST_H_ | ||
|
||
#include <cxxtest/TestSuite.h> | ||
|
||
#include "MantidCurveFitting/PoldiCalibrationProfile.h" | ||
|
||
using namespace Mantid::CurveFitting; | ||
using namespace Mantid::API; | ||
|
||
class PoldiCalibrationProfileTest : 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 PoldiCalibrationProfileTest *createSuite() { | ||
return new PoldiCalibrationProfileTest(); | ||
} | ||
static void destroySuite(PoldiCalibrationProfileTest *suite) { delete suite; } | ||
|
||
void testParameters() { | ||
PoldiCalibrationProfile fn; | ||
fn.initialize(); | ||
|
||
Gaussian gaussian; | ||
gaussian.initialize(); | ||
|
||
TS_ASSERT_EQUALS(fn.nParams(), gaussian.nParams() + 1); | ||
} | ||
|
||
void testDerivatives() { | ||
PoldiCalibrationProfile fn; | ||
fn.initialize(); | ||
|
||
fn.setParameter("Height", 2.0); | ||
fn.setParameter("PeakCentre", 1.1); | ||
fn.setParameter("Sigma", 0.01); | ||
fn.setParameter("Slope", 0.001); | ||
fn.setAttribute("DeltaTheta", IFunction::Attribute(0.01)); | ||
|
||
|
||
} | ||
}; | ||
|
||
#endif /* MANTID_CURVEFITTING_POLDICALIBRATIONFUNCTIONTEST_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
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
24 changes: 14 additions & 10 deletions
24
Code/Mantid/Framework/SINQ/src/PoldiUtilities/PoldiSpectrumCalibrationFunction.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 |
---|---|---|
@@ -1,21 +1,25 @@ | ||
#include "MantidSINQ/PoldiUtilities/PoldiSpectrumCalibrationFunction.h" | ||
#include "MantidAPI/FunctionFactory.h" | ||
|
||
namespace Mantid | ||
{ | ||
namespace Poldi | ||
{ | ||
namespace Mantid { | ||
namespace Poldi { | ||
|
||
PoldiSpectrumCalibrationFunction::PoldiSpectrumCalibrationFunction() : | ||
PoldiSpectrumDomainFunction() | ||
{ | ||
using namespace API; | ||
|
||
} | ||
DECLARE_FUNCTION(PoldiSpectrumCalibrationFunction) | ||
|
||
PoldiSpectrumCalibrationFunction::getPeakCenter(const Poldi2DHelper_sptr &poldi2DHelper) const | ||
{ | ||
PoldiSpectrumCalibrationFunction::PoldiSpectrumCalibrationFunction() | ||
: PoldiSpectrumDomainFunction() {} | ||
|
||
void PoldiSpectrumCalibrationFunction::init() { | ||
setDecoratedFunction("PoldiCalibrationProfile"); | ||
} | ||
|
||
void PoldiSpectrumCalibrationFunction::functionModificationHook( | ||
const Poldi2DHelper_sptr &poldi2DHelper) const { | ||
m_profileFunction->setAttribute( | ||
"DeltaTheta", IFunction::Attribute(poldi2DHelper->deltaTwoTheta / 2.0)); | ||
} | ||
|
||
} // namespace Poldi | ||
} // namespace Mantid |
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