esrf

Beamline Instrument Software Support
SPEC Macro documentation: [ Macro Index | BCU Home ]

PSEARCH.MAC
See other macros in category: All
Description:
    Peak searching and fitting with energy calibration
Documentation:
    DESCRIPTION
    Psearch.mac is the spec front end to the psearch external program to search and fit peaks. The basic algorithm consists of removing first all peaks (above a certain statistical threshold), fitting a back ground function, isolating groups of peaks and trying to fit multipletts in an iterative procedure. The macros in this macro set are not directly used by the user, but provide the peak fitting to other macro sets. The macro set also provides the necessary functions to calibrate spectra in energy. The initial width estimation and the Energy-channel relation are:
    E=ea + eb ch + ec ch^2 ; FWHM = sqrt( wa^2 + wb E + (wc E)^2 )

    EXAMPLE
    These example are not really meant to be typed in by the user. They should give you an example how to use the psearch function in your macros.
      
    
      ps_calib
        FWHM = sqr[a^2 + b*ch]
        Term (a) in channels (5)? 
        Term (b) in channels (0.04)? 
          54 Peaks found
          No        Position  Intensity       FWHM Flag
           1       51.284000      599.0      3.780   2
           2       53.000000      368.0      3.645   2
           ......
           8      232.835007     7014.0      8.290   3
           9      248.266006    26738.0      6.822   3
           ....
        No of 1. peak  (9)?     
        Energy at peak 9, channel 248.266006 (Int:26738.0) (8.0441)? 
        No of 2. peak  (54)? 
        Energy at peak 54, channel 3894.892090 (Int:1178503.0) (122.06)? 
        No of 3. peak (0 to end) (0)? 
        Linear FIT E= a + b*ch 
          CHI2:      0.000 ; a:       0.2817817  b:      0.03126613
        Do you accept the fit (YES)? 
        
        The energy calibration is done. It is stored in the global
        variables PS_EA , PS_EB, PS_EC. You can use the conversion
        macros : 
          ps_calcch <Energy> <Channel>
          ps_calcE  <Channel> <Energy>
          ps_Etoch group1 elem1 group2 elem2
          ps_Etoch group1 elem1 group2 elem2
      
      pssearch
        Asks for initial width parameters and displays the peaks in
        Energy.
    


    SETUP
    The program psearch must be accessible. (in the path)

    ATTENTION
    make sure psearch is in the path

    DEPENDENCIES
    The file psearch.mac has to be read in !done by: startup script

Macros:
    pssearch
    Usage: pssearch (data arr, first channel, no data, wa, wb, wc, usee, minint, maxerror)
    Searches the current data array for peaks. The Energy calibration must have been done before. The result is put into PS_PEAKS. Can be used interactively by the user or from other macros with given width parameters. Only if called with no parameter it will produce output. The number of found peaks is stored in PS_NOPEAKS.

    ps_dump
    Usage: ps_dump
    Displays a long list of peaks found

    ps_sdump
    Usage: ps_sdump
    Displays a short list of peaks found

    ps_show
    Usage: ps_show
    Displays the calibration parameters, number of peaks and a short list of the last found peaks.

    ps_calib
    Usage: ps_calib (data, firstch, nodata)
    Does a peaksearch on array data. Then asks the user for calibration energy of some peaks and fits a linear or quadratic function.

    ps_parinput
    Usage: ps_parinput
    Shows the calibration parameters and lets the user change them

    ps_calcE
    Usage: ps_calcE <Channel> <Energy>
    Converts from Energy to channel (channel to Energy). The first parameter is the value to convert and the second parameter a variable name where to put the converted value.

    ps_calcch
    Usage: ps_calcch (Energy)
    return the corresponding channel. Suppose that there is only a small quadratic correction

    ps_chtoE
    Usage: ps_chtoE (channel array, Energy array)
    Converts all the channels in source array[][column1] to energies and puts these values into destination array[][column2]. The calibration function E=a+b ch + c ch^2 is used.

    ps_Etoch
    Usage: ps_Etoch (Energy array, channel array)
    Converts all the energies in sorce array[][column1] to channels and puts these values into destination array[][column2]. The taylor expansion for the parabolic calibration function E=a+b ch + c ch^2 is used.

    pssetup
    Usage: pssetup
    defines the global variables and looks for psearch executable

Internal Macros:
    old_array_pipe
    Usage: old_array_pipe (program , arguments , array_in, array_out)
    like data_pipe but for arrays. This This needs the new version of the binary program psearch!!!!! Please update this program.

    _obsolete_array_pipe
    Usage: _obsolete_array_pipe(program , arguments , array_in, array_out,nodata)


    ps_psearch
    Usage: ps_psearch (data, data_col, minch, no, a, b, c, wa, wb, wc)
    Does the peak search for the array given in data. The data holds only counts. The corresponding channel numbers go from minch to minch + no - 1. The a, b and c parameters provide means to input an enery calibration (E = a + b * ch + c * ch * ch). The routine needs an estimate for the peak width. The parameters for this estimate are given by W(E) = sqrt (wa**2 + wb*E + (wc*E)**2). The results will be in the global array PS_PEAKS. The individual columns are:
    No Channel Counts FWHM Flag Energy FWHM-E.
    The calculation will always be done in channels, only the width parameters will be ajusted for the given calibration.

    ps_reject
    Usage: ps_reject ( minint, wa, wb, wc, %error, minE, maxE )
    FWHM = sqr[wa^2 + wb*E + (wc*E)^2]
    Deletes all peaks from the PS_PEAKS which do not fullfill the given conditions
    • minint < I
    • minE < E < maxE
    • FWHM is in %error of specified FWHM


    ps_testdata
    Usage: ps_testdata


    ps_calibration
    Usage: ps_calibration
    see ps_calib

    ps_ofit
    Usage: ps_ofit(ya,xa,no,order,verbose)
    Same functionality as ps_fit but for old type arrays

    ps_fit
    Usage: ps_fit (y, x, no of data points, order, verbose flag)
    Do a linear or quadratic fit y = a + b * x + c * x**2. The (a,b,c) parameters are returned in the global array PS_PAR. The return value of the function is the chi2 of the fit. If the verbose flag is set, the fitvalues are printed to the screen.

Filename: psearch.mac
Author: PSEARCH.MAC - JK 2.94 # DATE Fri Apr 12 11:19:16 METDST 1996 REV 1.4;
Last mod.: 08/08/2002 14:37 by berruyer