NAME

ahgainfit -- Calculate the time-dependent energy gain corrections using known calibration lines

USAGE

ahgainfit infile outfile

DESCRIPTION

'ahgainfit' calculates time-dependent energy gain corrections by comparing the theoretical and observed energies of a calibration line or line complex. For each run of the task, only one line may be specified to calculate the gain correction (see parameter 'linetocorrect'). 'ahgainfit' is a general task used directly in the scripts 'sxigainfit', 'hxigainfit', 'sgdgainfit' for the SXI HXI, and SGD respectively. For the SXS, the 'sxsgain' tasks uses the same core fitting function of 'ahgainfit'.

'ahgainfit' takes as input an event file with time and energy columns, and requires that the events are time ordered. The task accumulates spectra from events that are consecutive in time, with energy centered on the calibration feature and compares each spectrum from the events with a theoretical model of the calibration feature profile. The calibration feature used by 'ahgainfit' is specified by the parameter 'linetocorrect' as a string, and the names and energies of the features are specified in a calibration file (parameter 'linefitfile'). The calibration feature may be composed of many atomic or nuclear line components that are listed in the calibration file.

The energy range for the spectra constructed from the event file as well as from the theoretical profile, may be specified in two different ways. (1) The default energy range for the spectra is the smallest and largest energies of the line components, and expanded with the 'extraspread' parameter, i.e. [E_min - extraspread : E_max + extraspread]. It is recommended to set 'extraspread' larger than the sum of the natural width of the calibration feature, the value of the 'broadening' parameter, and the magnitude of the expected energy shift. (2) Alternatively, the energy range may be specified by setting the 'startenergy' and 'stopenergy' parameters. If these parameters are non-negative 'ahgainfit' uses their values to accumulate the spectra, instead of the range derived using the 'extraspread' setting. The energy column used to accumulate the spectra is specified by the 'energycol' parameter. The energy column is expected to be in units of channel, where the eV per channel is set by the 'evchannel' parameter. The spectra are binned according to the 'binwidth' parameter, where the 'binwidth' is in units of 'energycol' channels. The theoretical profile is constructed on a mesh defined by this energy range and 'binwidth', where each calibration line is assumed to be Lorentzian. The profile may be convolved with a Gaussian having the FWHM given by the 'broadening' parameter.

The number of events in each spectrum is defined by the 'numevent' and 'minevent' parameters. The task accumulates spectra with a number of events between 'minevent' and 'numevent'. However, if a spectrum has fewer than 'minevent' points, then it is combined with the previous spectrum if possible. Therefore all spectra have a size between 'minevent' and ('numevent+minevent-1'). To avoid having spectra accumulated over large gaps in time, the group of points in the spectrum is truncated when the time interval between consecutive events is greater than the 'gapdt' parameter. Adjacent spectra in time may share a percentage of their points based on the 'grpoverlap' parameter that may vary between 0 and 100. If 'grpoverlap' is set to 0, the consecutive spectra share no points in common; if set to 100 they share all points in common but one.

The spectra events may be simultaneously collected based on the value of a column present in the event file, given by the 'splitcol' parameter. This option may be used, for example, to find the gain correction for each layer of the HXI detector ('splitcol=LAYER'). If a GTI file is specified by the 'gtifile' parameter, events outside of these GTI intervals are excluded. Spectra are not accumulated across GTI intervals unless the 'spangti' parameter is set to 'yes'.

For each accumulated spectrum, 'ahgainfit' fits the theoretical profile to the data and also derives binned and unbinned averages. A least-squares method is used in the fitting. The fitted parameters are energy shift, scaling factor, background (unless the 'background' parameter is set to NONE), and, optionally, convolution width if 'fitwidth=yes'. The background is fit with a constant value if 'background' is set to CONSTANT, and a power-law if set to SLOPE. The unbinned average energy (as specified by 'energycol') is the sum of the energies in the spectrum divided by the number of events in the spectrum. The binned average energy is the weighted average derived by summing, over bins in the spectrum, the product of the energy and number of events per bin, and then dividing by the total number of events in the spectrum. The fitted gain correction is computed from the fitted shift with respect to the theoretical line profile. The binned average gain correction is computed from the difference between the profile and spectrum averages.

The default values for the parameters used in the fitting method ('minwidth0', 'maxitcycle', 'r2tol', 'searchstepshift', 'maxdshift', 'bisectolshift', 'searchstepwidth', 'maxdwidth', 'bisectolwidth', and 'minwidth') should not need to change since already optimized.

The output file has two extensions. One extension, GRID_PROFILE, contains the energies and amplitudes of the theoretical profile used in the fitting procedure, including any convolution from the 'broadening' parameter. The other extension, DRIFT_ENERGY, reports the fitting results for each spectra in the following columns: TIME (midpoint of the time interval over which the spectrum is collected), splitcol (value of splitcol for spectrum as given by the 'splitcol' parameter; this column is absent if 'splitcol=NONE'), COR_FIT (energy correction factor from spectrum fit), COR_AVE (energy correction factor from spectrum average), CHISQ (reduced chi-squared of the fit), AVGUNBIN (average energy of events in spectrum prior to binning), AVGBIN (weighted spectrum average energy), AVGFIT (average energy from fit), SHIFT (fitted energy shift), SCALE (fitted vertical scaling factor), BGRND (fitted background), WIDTH (if 'fitwidth=no', same as broadening parameter; if 'fitwidth=yes', fitted width), TELAPSE (difference between times of first and last event in spectrum), EXPOSURE (calculated using the GTI), NEVENT (total number of events collected for this spectrum), BINMESH (array containing the count spectrum energy bins), SPECTRUM (array containing the observed binned count spectrum), FITPROF (array containing theoretical profile with fitted parameters applied). If the 'calcerr' parameter is set to 'yes', one-sigma errors for the SHIFT and WIDTH are calculated. The errors are calculated with chi-squared and maximum-likelihood methods and output in the columns SIGSHCHI2, SIGWDCHI2, SIGWDLIKE and SIGWDLIKE respectively. If 'writeerrfunc' parameter is set, the chi-squared and likelihood calculated valued are output in the arrays SHCHI2, SHLIKE, WDCHI2 and WDLIKE. The numbers of values output in these arrays are specified in the 'nerrshift' and 'nerrwidth' parameters, respectively.

PARAMETERS

infile [filename]
Input event file name. The file must have the TIME column filled.

outfile [filename]
Output gain correction file name.

(linefitfile = CALDB) [filename]
Input CALDB file containing parameters of the Lorentzian components used to construct the theoretical line profile. If the parameter is set to CALDB, the file is read from the calibration database.

(linetocorrect = Mnka) [string]
Calibration line to use for the gain correction. The value must match an extension in linefitfile.

(energycol = UPI) [string]
Name of energy column to use in gain fitting.

(splitcol = PIXEL) [string]
Column name used to separate the data.

(numevent = 250) [integer]
Number of events collected for each spectrum used to calculate a single gain correction.

(minevent = 150) [integer]
Minimum number of events required for a spectrum. If the length of a group is less than minevent, those points are included with the previous group for processing, if possible.

(gtifile = NONE) [filename]
Input GTI file with time intervals to consider. Set to NONE to use entire input file.

(gapdt = -1) [real]
The upper limit to the time interval between two consecutive events in the same spectrum used in fitting. Two consecutive events separated in time by more than this amount are assigned to different groups. If gapdt=-1, no limit is imposed.

(grpoverlap = 0) [real]
The percentage overlap between adjacent groups. For grpoverlap=100 adjacent groups are shifted by one event, for grpoverlap=0 adjacent groups are independent and share no events.

(startenergy = -1.) [real]
Beginning of energy range in eV over which the spectra are collected. If startenergy is negative, the first energy is automatically determined by the smallest energy in linefitfile for the selected calibration feature adjusted by the extraspread parameter.

(stopenergy = -1.) [real]
End of energy range in eV over which the spectra are collected. If stopenergy is negative, the final energy is automatically determined by the largest energy in linefitfile for the selected calibration feature adjusted by the extraspread parameter.

(extraspread = 10.) [real]
Energy in eV by which the energy range is extended on either side beyond the smallest and largest energy in the linefitfile for the selected calibration feature. This parameter may be overridden by the startenergy and stopenergy parameters.

(evchannel = 1.) [real]
Conversion factor from channel number (for energycol) to energy [eV/chan].

(binwidth = 1.) [integer]
Energy bin width, in units of channels, to use when collecting spectra.

(broadening = 1.0) [real]
FWHM of the Gaussian in eV used to initially broaden the theoretical line profile. If fitwidth is set to no, the profile width is fixed at this value.

(gridprofile = no) [boolean]
If gridprofile is set to yes, only output the theoretical profile including any convolution due to the broadening parameter; no fitting is conducted (yes/[no]).

(fitwidth = no) [boolean]
If fitwidth is set to yes, then fit the width of each spectra in addition to the energy shift (yes/[no]).

(background = CONST) [string]
Fitted background type (NONE, CONST, SLOPE).

(spangti = no) [boolean]
If spangti is set to yes, events in different intervals in gtifile may be collected in the same spectrum to be fit. If spangti is set to no, then groups of events used to construct the spectra must be from the same GTI. This parameter is ignored if gtifile is set to NONE (yes/[no]).

(avgwinrad = -1.) [real]
Radius of interval (in units of binwidth) used only to update the initial shift estimate prior to fitting. If avgwinrad is set to -1, this radius is automatically calculated based on the theoretical line profile and the broadening parameter. This is not used in calculating the average results.

(calcerr = no) [boolean]
Compute uncertainties on shift and width (yes/[no]).

(writeerrfunc = no) [boolean]
Output the array of chi-squared and likelihood calculated for the SHIFT and WIDTH (yes/[no]).

(minwidth0 = 1.0) [real]
Smallest width, in units of binwidth, allowed as the initial value in width fitting. This parameter provides a lower limit to the initial estimate of the width as computed by the fitting algorithm. The value must be greater than zero.

(maxitcylce = 5) [integer]
Maximum number of fitting iterations.

(r2tol = 0.001) [real]
Convergence criterion on R-squared for least-squared fitting. Once R-squared changes by less than this amount between fitting iterations, the procedure is finished. This parameter should not normally need to be changed from the default value.

(searchstepshift = 2.) [real]
Step size, in units of binwidth, used when searching for best-fit energy shift in either direction from the initial shift estimate based on the spectrum average. The final shift is obtained using the bisection method (see bisectolshift).

(maxdshift = 5.) [real]
Largest allowed deviation, in units of binwidth, from initial estimate of energy shift. If no solutions are found within this deviation at smaller or larger shifts from the initial estimate, then the fitting procedure fails for the spectrum.

(bisectolshift = .001) [real]
When the bisection method determines the energy shift to within this amount in units of binwidth, the fitting procedure is completed.

(searchstepwidth = 5.) [real]
Step size, in units of binwidth, used when searching for best-fit convolution width in either direction from the initial width estimate based on the difference between the profile and spectrum statistical variances. The final width is obtained using the bisection method (see bisectolwidth).

(maxdwidth = 10.) [real]
Largest allowed deviation, in units of binwidth, from initial estimate of convolution width. If no solutions are found within this deviation at smaller or larger widths from the initial estimate, then the fitting procedure fails for the spectrum.

(bisectolwidth = .001) [real]
When the bisection method determines the convolution width to within this amount in units of binwidth, the fitting is procedure is completed.

(minwidth = .5) [real]
Since the least-squares fitting functional is undefined when the width is zero, one must define a minimum allowed fitted width. If the fitting routine attempts to fit a width smaller than this value (in units of binwidth), the fitting procedure fails for the spectrum.

(nerrshift = 100) [int]
Number of shift values in uncertainty calculations.

(nerrwidth = 100) [int]
Number of width values in uncertainty calculations.

(shifterrfac = 3.0) [real]
Factor for determining domain of shift uncertainty arrays.

(widtherrfac = 4.0) [real]
Factor for determining domain of width uncertainty arrays.

(buffer = -1) [integer]
Rows to buffer (-1=auto, 0=none, >0=numrows).

(clobber = no) [boolean]
Overwrites the existing output file if set to yes (yes/[no]).

(chatter = 1) [integer]
Chatter level for output. Set to 0 to suppress output, or to 1, 2, or 3 for increasing the chatter of the output.

(logfile = !DEFAULT) [string]
Log filename. If set to DEFAULT uses the name of the task and, if preceded by '!', overwrite the file if it exists. If set to NONE no log file is created.

(debug = no) [boolean]
Diagnostic output is printed out on the screen if set to yes (yes/[no]).

(history = yes) [boolean]
Records tool parameters in HISTORY ([yes]/no).

(mode = ql) [string ql|hl|q]
Mode to query the parameter file. Acceptable values include: "ql (query and learn/remember), "hl" (hidden and learn/remember), "q" (query but don't remember), "h" (hidden).

EXAMPLES

  1. 1. Compute the gain correction for an SXI event file using Mn K lines as the theoretical profile. The theoretical profile is convolved with a 12 eV Gaussian and gains are computed separately for each CCD_ID.

      ahgainfit infile=event_in.fits outfile= drift_out.fits linetocorrect=Mnka energycol=PI splitcol=CCD_ID extraspread=20. \
      evchannel=6. broadening=12. fitwidth=yes
    
  2. Compute the gain correction for an HXI event file using Mn K lines as the theoretical profile. The theoretical profile is convolved with a 200 eV Gaussian and gains are computed separately for each SIDE.

      ahgainfit infile=event_in.fits outfile=drift_out.fits linetocorrect=Mnka energycol=PI splitcol=SIDE extraspread=400. evchannel=100. \
      broadening=200. fitwidth=yes
    
  3. Compute the gain correction for an SGD event file using the Sn119 line as the theoretical profile. The theoretical profile is convolved with a 1500 eV Gaussian and gains are computed separately for each MATTYPE.

      ahgainfit infile=event_in.fits outfile=drift_out.fits linetocorrect=Sn119 energycol=PI splitcol=MATTYPE extraspread=2500. evchannel=1750. \
      broadening=1500. fitwidth=yes
    

SEE ALSO

sxigainfit, hxigainfit, sgdgainfit, sxsgain

LAST MODIFIED

December 2016