Skip to content
This repository has been archived by the owner on Mar 27, 2024. It is now read-only.

Commit

Permalink
Finished the port of ExtResFixedLambda.
Browse files Browse the repository at this point in the history
Signed-off-by: Jay Jay Billings <billingsjj@ornl.gov>
  • Loading branch information
Jay Jay Billings committed Feb 6, 2015
1 parent b532e46 commit df9a521
Show file tree
Hide file tree
Showing 2 changed files with 138 additions and 13 deletions.
Expand Up @@ -138,7 +138,7 @@ public void convolute(double[] waveVector, double delQ0, double delQ1oQ,
double wavelength, int numPoints, int numLowPoints,
int numHighPoints, double[] refFit) {

double log2 = Math.log(2.0);
double ln2 = Math.log(2.0);
double qEff = 0.0, qRes = 0.0, rExp = 0.0, rNorm = 0.0;
double[] refTemp = new double[maxPoints];
int nStep = 0;
Expand All @@ -153,7 +153,7 @@ public void convolute(double[] waveVector, double delQ0, double delQ1oQ,
qEff = waveVector[i];
}
double qDel = delQ0 + qEff * delQ1oQ;
double twSgSq = 2.0 * qDel * qDel / (8.0 * log2);
double twSgSq = 2.0 * qDel * qDel / (8.0 * ln2);
if (twSgSq < 1.0e-10) {
twSgSq = 1.0e-10;
}
Expand Down Expand Up @@ -208,4 +208,81 @@ public void convolute(double[] waveVector, double delQ0, double delQ1oQ,
return;
}

/**
* This operation calculates the length of the low-Q extension of the data
* to be convoluted with the delt-Q full-width half-maximum Gaussian
* resolution function.
*
* @param q
* the wave vector (Q) plus additional space for the convolution.
* This array should have length = numPoints + numLowPoints.
* @param delQ0
* the zeroth order term of a Taylor expansion of the
* reflectometer resolution function dQ = dQ_0 + (dQ/Q)_1 x Q +
* ...
* @param delQ1oQ
* the zeroth order term of the Q resolution Taylor expansion
* @param numPoints
* the number of points in the wave vector
* @return numLowPoints the number of points in the low-Q extension to q
* used for convolution of the data with the resolution function.
* Returned by ExtResFixedLambda.
*/
public int getLowExtensionLength(double[] waveVector, double delQ0,
double delQ1oQ, int numPoints) {

double ln2 = Math.log(2.0);

// Determine the loq-Q extension
double qDel = delQ0 + waveVector[0] * delQ1oQ;
double qStep = waveVector[1] - waveVector[0];
double twSgSq = Math.max(2.0 * qDel * qDel / (8.0 * ln2), 1.0e-10);
int numLowPoints = 0;
double qR = 0.0;
while (qR * qR / twSgSq <= 6.908) {
numLowPoints++;
qR = qR + qStep;
}

return numLowPoints;
}

/**
* This operation calculates the length of the high-Q extension of the data
* to be convoluted with the delt-Q full-width half-maximum Gaussian
* resolution function.
*
* @param q
* the wave vector (Q) plus additional space for the convolution.
* This array should have length = numPoints + numLowPoints.
* @param delQ0
* the zeroth order term of a Taylor expansion of the
* reflectometer resolution function dQ = dQ_0 + (dQ/Q)_1 x Q +
* ...
* @param delQ1oQ
* the zeroth order term of the Q resolution Taylor expansion
* @param numPoints
* the number of points in the wave vector
* @return numHighPoints the number of points in the high-Q extension to q
* used for convolution of the data with the resolution function.
* Returned by ExtResFixedLambda.
*/
public int getHighExtensionLength(double[] waveVector, double delQ0,
double delQ1oQ, int numPoints) {

double ln2 = Math.log(2.0);

// Determine the high-Q extension
double qDel = delQ0 + waveVector[numPoints - 1] * delQ1oQ;
double qStep = waveVector[numPoints - 1] - waveVector[numPoints - 2];
double twSgSq = 2.0 * qDel * qDel / (8.0 * ln2);
int numHighPoints = 0;
double qR = 0.0;
while (qR * qR / twSgSq <= 6.908) {
numHighPoints++;
qR = qR + qStep;
}

return numHighPoints;
}
}
Expand Up @@ -104,6 +104,53 @@ public static void setUpBeforeClass() throws Exception {

}

/**
* This class tests
* {@link ReflectivityCalculator#getExtensionLengths(double[], double, double, double, int, int, int)}
* .
*/
@Test
public void testGetExtensionLengths() {
// Load the convolution file
Form form = reader.read(project.getFile("getExtensionLengths.csv"));
ListComponent<String[]> lines = (ListComponent<String[]>) form
.getComponent(1);
assertEquals(403, lines.size());

// Get the parameters and reference output values
String line[] = lines.get(0);
double delQ0 = Double.valueOf(line[0]);
double delQ1oQ = Double.valueOf(line[1]);
double wavelength = Double.valueOf(line[2]);
int numPoints = Integer.valueOf(line[3]);
int refNumLowPoints = Integer.valueOf(line[4]);
int refNumHighPoints = Integer.valueOf(line[5]);

// Load the q array. They are padded by numLowPoints for the
// convolution.
double[] waveVector = new double[lines.size() - 1];
for (int i = 0; i < lines.size() - 1; i++) {
line = lines.get(i + 1);
waveVector[i] = Double.valueOf(line[0]);
}
assertEquals(numPoints, waveVector.length);
assertEquals(4.401373320E-01, waveVector[numPoints - 1], 0.0);

// Call the function
int numLowPoints = 0, numHighPoints = 0;
ReflectivityCalculator calculator = new ReflectivityCalculator();
numLowPoints = calculator.getLowExtensionLength(waveVector, delQ0, delQ1oQ,
numPoints);
numHighPoints = calculator.getHighExtensionLength(waveVector, delQ0, delQ1oQ,
numPoints);

// Check the high and low extension lengths
assertEquals(refNumLowPoints, numLowPoints);
assertEquals(refNumHighPoints, numHighPoints);

return;
}

/**
* This class tests
* {@link ReflectivityCalculator#convolute(double[], double, double, double, int, int, double[])}
Expand All @@ -128,8 +175,8 @@ public void testConvolute() {

// Load the q and refFit arrays. They are padded by numLowPoints for the
// convolution.
double[] waveVector = new double[lines.size()-1];
double[] refRefFit = new double[lines.size()-1]; // Reference!
double[] waveVector = new double[lines.size() - 1];
double[] refRefFit = new double[lines.size() - 1]; // Reference!
for (int i = 0; i < lines.size() - 1; i++) {
line = lines.get(i + 1);
waveVector[i] = Double.valueOf(line[0]);
Expand All @@ -140,13 +187,13 @@ public void testConvolute() {

// Load the tiles
form = reader.read(project.getFile("getSpecRefSqrdMod_q841.csv"));
ListComponent<String []> tileLines = (ListComponent<String[]>) form
ListComponent<String[]> tileLines = (ListComponent<String[]>) form
.getComponent(1);
Tile[] tiles = loadTiles(tileLines);
assertEquals(173, tiles.length);

// Compute the initial value of refFit
double[] refFit = new double[lines.size()-1];
double[] refFit = new double[lines.size() - 1];
double qEff = 0.0;
ReflectivityCalculator calculator = new ReflectivityCalculator();
for (int i = 0; i < numHighPoints + numLowPoints + numPoints; i++) {
Expand All @@ -155,15 +202,15 @@ public void testConvolute() {
} else {
qEff = waveVector[i];
}
refFit[i] = calculator.getModSqrdSpecRef(qEff,wavelength,tiles);
System.out.println(i + " " + refFit[i]);
refFit[i] = calculator.getModSqrdSpecRef(qEff, wavelength, tiles);
}

// Do the convolution and check the result
calculator.convolute(waveVector, delQ0, delQ1oQ, wavelength, numPoints,
numLowPoints, numHighPoints, refFit);
for (int i = 0; i < refFit.length; i++) {
assertEquals(refRefFit[i], refFit[i], Math.abs(refRefFit[i])/1.0e-4);
assertEquals(refRefFit[i], refFit[i],
Math.abs(refRefFit[i]) / 1.0e-4);
}

return;
Expand Down Expand Up @@ -201,7 +248,8 @@ public void testGetSpecRefSqrdMod() {
System.out.println(specRefSqrd + " " + expectedSpecRefSqrd);
System.out.println("RERR = " + (specRefSqrd - expectedSpecRefSqrd)
/ expectedSpecRefSqrd);
assertEquals(expectedSpecRefSqrd, specRefSqrd, Math.abs(expectedSpecRefSqrd)/1.0e-4);
assertEquals(expectedSpecRefSqrd, specRefSqrd,
Math.abs(expectedSpecRefSqrd) / 1.0e-4);

// Get the two single parameters and the final result out of the data
// for the second test case
Expand All @@ -220,7 +268,7 @@ public void testGetSpecRefSqrdMod() {
System.out.println("RERR = " + (specRefSqrd - expectedSpecRefSqrd)
/ expectedSpecRefSqrd);
assertEquals(expectedSpecRefSqrd, specRefSqrd,
Math.abs(expectedSpecRefSqrd/1.0e-4));
Math.abs(expectedSpecRefSqrd / 1.0e-4));

return;
}
Expand Down

0 comments on commit df9a521

Please sign in to comment.