Typically, a detector refinement program will append newly calculated values to the end of the file. This way, the file contains a history of how and when parameters were modified. When reading the file, applications use the last entries for any parameter.
Example of an SXDETECTOR file:
#Created on 2001.09.12 #Initial values npix 256 144 size of detector (fast,slow) mmpix 1.1 2.0 mm/pixel cpix 128 72 estimated beam center in pixels ringmm 125 ammonium sulfate radius in mm samplemm 2000 sample-detector distance in mm lambda 1.54 X-Ray wavelength #Created/updated on 2001.09.13 by sxrefpar #Refined cpix, mmpix, ringmm npix 256 144 mmpix 1.085397 2.000000 cpix 127.345520 69.081398 ringmm 124.775032 samplemm 2000.0000 lambda 1.540000
In this example, we see that the file was created by hand with initial values, and refined using sxrefpar, which modified the estimated center, mm/pixel and ring radius.
sxrefpar | Refine detector parameters using ammonium sulfate ring |
sxangle | Produce counts vs angle for a specified ring of data |
sxcentermass | Using the center of mass of a direct beam shot, determine beam center. |
Usage: sxrefpar [-c xc,yc] [-m xmm,ymm] [-r mmlo,mmhi] [-b binsize] sxfilename xc,yc -- initial center in detector pixel coordinates xmm,ymm -- initial mm/pixel in x- and y- directions mmlo,mmhi -- rings are in range mmlo to mmhi mm from center binsize -- number of mm per bin for ravaging sxfilename -- path (name) of the SAXS data file
Sxrefpar uses default parameters, then the values in the SXDETECTOR file, and finally the parameters specified on the command line. Using these, it finds the ammonium sulfate ring, calculates its center and radius, and uses this information to refine the estimated beam center, pixel size and ring radius. It writes these updated values to the SXDETECTOR file.
In the event that sxrefpar cannot find or read the SXDETECTOR file, it prints an error message, but proceeds using default and command-line values. If it thinks it is successful in its refinement, sxrefpar will create an SXDETECTOR file.
Sxrefpar, using the initial parameters, determines the radius of the ammonium sulfate ring using 40-degree wedges of data, originating at the estimated center, and centered on 0, 90, 180 and 270 degrees (i.e., along each axis). Using these radii, the center and pixel size are recalcualted (with the y-pixel size being held constant). The cycle is repeated 10 times.
Unless the beam has moved substantially, sxrefpar should be able to home in with no parameters specified on the command line.
usage: sx2k_angle [-m x,y] [-c x,y] [-r r1,r2] [-b w] sxfilename -m: mm/pixel -c: center in pixels -r: ring is between r1 and r2 mm -b: number of equal arcs in circleSxangle produces a list of average counts per pixel, vs angle, for the specified SAXS data file. You should specify -b and -r on the command line (the defaults might be meaningless). Most commonly, if the ammonium sulfate ring is determined to be at 127.44 mm, you would use something like -r 125.44,129.44.
Why is this interesting. Tests show that there can be wide variations in average counts as you go around the ammonium sulfate ring. So this information may be useful in deciding how good the data is.
Sxangle has not yet been converted to use the SXDETECTOR file. Therefore, after refining the parameters with sxdetpar, you should examine the file, and use the information for the -c and -m switches to sxangle.
usage: sxcentermass [-c x,y] [-b w] sxfilename -c: estimated center in pixels -b: use center +/- b pixels in y, +/- 2b pixels in x
Refines beam center using wieghted average of pixels, using the data found in sxfilename. This program isprobably unnecessary, although it can provide an initial value to feed into sxrefpar.
Sxrefpar, using the initial parameters, determines the radius of the ammonium sulfate ring using 40-degree wedges of data, originating at the estimated beam center, and centered on 0, 90, 180 and 270 degrees (i.e., along each axis). Using these radii, the beam center and pixel size are recalcualted (with the y-pixel size being held constant). The cycle is repeated 10 times.
Along each radius, Sxrefpar first guesses where the peak is. It uses that guess to determine initial values for the parameters of a gaussian, which it then fits to the data. The refined center of the gaussian is taken as the center of the ring.
The ratio of the diameters along the y- and x-axis is used to recalculate the pixel size.
The algorithm seems quite stable, with limited test data. The same center and pixel size are arrived at within a few hundreths of a mm for the center, or a few microns for the pixel size, over a large range of initial conditions.
The GRIDLS program from Bevington (1969) was used as a base. Thie is a program that searches the space of parameters being refined to find the best fit.
Bevington gives an example fitting a gaussian + quadradic function. I modified it to fit a gaussian + straight line. The method with no weighting of data is used.
The parameters being refined are the radius of the peak (mean of the gaussian distribution), sigma for the distribution, slope and intercept for the straight line on which the gaussian rests, and a scale factor for the gaussian.
The actual data used to fit the gaussian is the radially-average data, gathered in bins of fixed size (generally 2mm). It might be better to simply use the unbinned data, providing both the x (radius) and y (counts) coordinate to the fitting routine.
The tricky part is initializing and terminating the search. I terminate the search when chi-squared is less than 1, or chi-squared changes by less than 2%, or 12 iterations over parameter space have been completed.
The GRIDLS algorithm searches parameter space for values that best fit the data. IT must begin with initial guesses, and initial deltas (step sizes to use in changing the parameters).
I assume that the ammonium sulfate ring is the highest feature along a radius. So the radius of the highest bin is taken as the initial mean of the gaussian distribution. From there, I move back along the radius toward the center, looking for the low point before counts start increasing. I am confident of finding such a valley, because the gaussian is on top of a line that slopes down as it moves out from the center, and because there is a secondary gaussian peak just inward from the main one. The distance from this valley to the mean is taken as the initial guess for 3-sigma. The parameters of a straight line running from the inward valley, to a point equidistant outside the peak, are used.
usage: sxravage [-m x,y] [-c x,y] [-r r1,r2] [-b w] filename -m: mm/pixel -c: center in pixels -r: ravage between r1 and r2 mm -b: bin width in mm
Meant mainly as a diagnostic program, sxravage calculates and prints out the radial averages. It has not yet been modified to use the SXDETECTOR file, so parameters must be specified on the command line.
Sxgauss takes as input binned, averaged data, as produced by sxravage. Using the algorithms described above, it calculates the parameters for the gaussian peak representing the ammonium sulfate ring.
Output from sxravage must be filtered through awk before being fed into sxgauss.