Commit 31fdce88 authored by Zhang, Chen's avatar Zhang, Chen
Browse files

fix scope issue test and doc for selfscattering v1

parent aa23da01
......@@ -29,85 +29,85 @@ using Mantid::API::Algorithm_sptr;
using Mantid::API::AlgorithmManager;
using Mantid::API::MatrixWorkspace_sptr;
// generate incident spectrum data
std::vector<double> generateIncidentSpectrum(const Mantid::HistogramData::HistogramX &lambda, double phiMax = 6324.0,
double phiEpi = 786.0, double alpha = 0.099, double lambda1 = 0.67143,
double lambda2 = 0.06075, double lambdaT = 1.58) {
std::vector<double> amplitude;
const double dx = (lambda[1] - lambda[0]) / 2.0;
for (double x : lambda) {
if (x != lambda.back()) {
double deltaTerm = 1.0 / (1.0 + exp(((x + dx) - lambda1) / lambda2));
double term1 = phiMax * (pow(lambdaT, 4.0) / pow((x + dx), 5.0)) * exp(-pow((lambdaT / (x + dx)), 2.0));
double term2 = phiEpi * deltaTerm / (pow((x + dx), (1.0 + 2.0 * alpha)));
amplitude.emplace_back(term1 + term2);
class CalculatePlaczekSelfScatteringTest : public CxxTest::TestSuite {
public:
// generate incident spectrum data
std::vector<double> generateIncidentSpectrum(const Mantid::HistogramData::HistogramX &lambda, double phiMax = 6324.0,
double phiEpi = 786.0, double alpha = 0.099, double lambda1 = 0.67143,
double lambda2 = 0.06075, double lambdaT = 1.58) {
std::vector<double> amplitude;
const double dx = (lambda[1] - lambda[0]) / 2.0;
for (double x : lambda) {
if (x != lambda.back()) {
double deltaTerm = 1.0 / (1.0 + exp(((x + dx) - lambda1) / lambda2));
double term1 = phiMax * (pow(lambdaT, 4.0) / pow((x + dx), 5.0)) * exp(-pow((lambdaT / (x + dx)), 2.0));
double term2 = phiEpi * deltaTerm / (pow((x + dx), (1.0 + 2.0 * alpha)));
amplitude.emplace_back(term1 + term2);
}
}
return amplitude;
}
return amplitude;
}
// generate incident spectrum derivitive
std::vector<double> generateIncidentSpectrumPrime(const Mantid::HistogramData::HistogramX &lambda,
double phiMax = 6324.0, double phiEpi = 786.0, double alpha = 0.099,
double lambda1 = 0.67143, double lambda2 = 0.06075,
double lambdaT = 1.58) {
std::vector<double> amplitude;
const double dx = (lambda[1] - lambda[0]) / 2.0;
for (double x : lambda) {
if (x != lambda.back()) {
double deltaTerm = 1.0 / (1.0 + exp(((x + dx) - lambda1) / lambda2));
double term1 = phiMax * pow(lambdaT, 4.0) * exp(-pow((lambdaT / (x + dx)), 2.0)) *
(-5 * pow((x + dx), -6.0) + 2 * pow((x + dx), -8.0) * lambdaT);
double term2 = -phiEpi / pow((x + dx), (1.0 + 2.0 * alpha)) * deltaTerm *
((1.0 + 2.0 * alpha) / (x + dx) + (1 / deltaTerm - 1) / lambda2 * deltaTerm);
amplitude.emplace_back(term1 + term2);
// generate incident spectrum derivitive
std::vector<double> generateIncidentSpectrumPrime(const Mantid::HistogramData::HistogramX &lambda,
double phiMax = 6324.0, double phiEpi = 786.0, double alpha = 0.099,
double lambda1 = 0.67143, double lambda2 = 0.06075,
double lambdaT = 1.58) {
std::vector<double> amplitude;
const double dx = (lambda[1] - lambda[0]) / 2.0;
for (double x : lambda) {
if (x != lambda.back()) {
double deltaTerm = 1.0 / (1.0 + exp(((x + dx) - lambda1) / lambda2));
double term1 = phiMax * pow(lambdaT, 4.0) * exp(-pow((lambdaT / (x + dx)), 2.0)) *
(-5 * pow((x + dx), -6.0) + 2 * pow((x + dx), -8.0) * lambdaT);
double term2 = -phiEpi / pow((x + dx), (1.0 + 2.0 * alpha)) * deltaTerm *
((1.0 + 2.0 * alpha) / (x + dx) + (1 / deltaTerm - 1) / lambda2 * deltaTerm);
amplitude.emplace_back(term1 + term2);
}
}
return amplitude;
}
return amplitude;
}
// generate spectrum without detector info
MatrixWorkspace_sptr generateIncidentSpectrum() {
const double xStart = 0.2;
const double xEnd = 4.0;
const double xInc = 0.01;
std::vector<double> x;
std::vector<double> y;
std::vector<double> yPrime;
for (int i = 0; i < (xEnd - xStart) / xInc; i++) {
x.emplace_back(xStart + i * xInc);
}
y = generateIncidentSpectrum(x);
yPrime = generateIncidentSpectrumPrime(x);
for (double prime : yPrime) {
y.emplace_back(prime);
// generate spectrum without detector info
MatrixWorkspace_sptr generateIncidentSpectrum() {
const double xStart = 0.2;
const double xEnd = 4.0;
const double xInc = 0.01;
std::vector<double> x;
std::vector<double> y;
std::vector<double> yPrime;
for (int i = 0; i < (xEnd - xStart) / xInc; i++) {
x.emplace_back(xStart + i * xInc);
}
y = generateIncidentSpectrum(x);
yPrime = generateIncidentSpectrumPrime(x);
for (double prime : yPrime) {
y.emplace_back(prime);
}
Algorithm_sptr alg = AlgorithmManager::Instance().createUnmanaged("CreateWorkspace");
alg->initialize();
alg->setProperty("OutputWorkspace", "incident_spectrum_ws");
alg->setProperty("DataX", x);
alg->setProperty("DataY", y);
alg->setProperty("NSpec", 2);
alg->execute();
// retreve output workspace from ADS
MatrixWorkspace_sptr outWs =
Mantid::API::AnalysisDataService::Instance().retrieveWS<Mantid::API::MatrixWorkspace>("incident_spectrum_ws");
return outWs;
}
Algorithm_sptr alg = AlgorithmManager::Instance().createUnmanaged("CreateWorkspace");
alg->initialize();
alg->setProperty("OutputWorkspace", "incident_spectrum_ws");
alg->setProperty("DataX", x);
alg->setProperty("DataY", y);
alg->setProperty("NSpec", 2);
alg->execute();
// retreve output workspace from ADS
MatrixWorkspace_sptr outWs =
Mantid::API::AnalysisDataService::Instance().retrieveWS<Mantid::API::MatrixWorkspace>("incident_spectrum_ws");
return outWs;
}
// Add sample to workspace
void addSampleMaterialToWorkspace() {
Algorithm_sptr alg = AlgorithmManager::Instance().createUnmanaged("SetSampleMaterial");
alg->initialize();
alg->setProperty("InputWorkspace", "InputWorkspace");
alg->setProperty("ChemicalFormula", "Si");
alg->setProperty("SampleNumberDensity", 0.1);
alg->execute();
return;
}
// Add sample to workspace
void addSampleMaterialToWorkspace() {
Algorithm_sptr alg = AlgorithmManager::Instance().createUnmanaged("SetSampleMaterial");
alg->initialize();
alg->setProperty("InputWorkspace", "InputWorkspace");
alg->setProperty("ChemicalFormula", "Si");
alg->setProperty("SampleNumberDensity", 0.1);
alg->execute();
return;
}
class CalculatePlaczekSelfScatteringTest : 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 CalculatePlaczekSelfScatteringTest *createSuite() { return new CalculatePlaczekSelfScatteringTest(); }
......
......@@ -13,7 +13,7 @@ This algorithm takes an incident spectrum function and it's derivative, along wi
the workspace containing spectrum info and calculates the time-of-flight Placzek
scattering correction from the workspaces material sample and detector info.
[1]_ [2]_ [3]_ For obtaining the incident spectrum from a measurement (ie beam
monitors or calibrant sample), the :ref:FitIncidentSpectrum <algm-FitIncidentSpectrum>
monitors or calibrant sample), the :ref:`FitIncidentSpectrum <algm-FitIncidentSpectrum>`
can provide the necessary inputs.
Usage
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment