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

See other macros in category: Detection MCA
    Multi Channel Analyser.
    These macros provide users with basic MCA commands, i.e. start, stop, init, read memory, etc..., as well as with more sophisticated features such as ROIs, channel calibration, peak search, data saving and recovering, etc...
    MCA control is inserted in SPEC internal code, making it possible to automatically operate the MCA, from standard SPEC counting and scanning commands, e.g. acquire, plot out, save spectrum for each point of a scan. A Graphical User Interface is also available.

    About the usage of the Graphical User Interface (GUI) : it is at the moment only capable of monitoring the data acquired, as there is no connection between SPEC and that GUI, appart from the spectrum data itself and its calibration parameters, both stored in shared memory. For instance, the ROIs defined from SPEC or from the GUI are not connected together. They are two seperate sets of ROI definitions. The GUI is not capable of sending control commands to the hardware. Be more particularly aware that the acquisition times are not known by the GUI, so if you save the spectrum from the GUI, they wont be included in the file. rather use SPEC for saving your data. The GUI is a display.


    Hardware supported :
    SILENA Memory Buffer.
    remote controlled through GPIB. SPEC can address it in 3 different ways:
    Direct from SPEC.
    In SPEC config, select MCA TYPE Silena 73XX MCA (GPIB), TCP MODE.
    The GPIB interface can be any of those supported by SPEC.
    Device server McaSICL.
    In SPEC config, select MCA TYPE ESRF MCA, TCP MODE.
    The GPIB is addressed by the device server, so you do not necessarily need to declare it in SPEC, but only HP E2050 LAN/HPIB controller is supported; McaSICL server runs on HP-UX machines only.
    Device server McaMB.
    In SPEC config, select MCA TYPE ESRF MCA, TCP MODE.
    The GPIB is addressed by the device server, so you do not necessarily need to declare it in SPEC, but only Themis T409 VME Board is supported; McaMB server runs on OS9 crates.
    It is remote controlled via Ethernet LAN. SPEC addresses it through a device server, called McaAIM that runs on HP-UX machines. In SPEC config, select MCA TYPE ESRF MCA, TCP MODE.
    MCA macros are able to detect that a MCA has been configured. If it happens that it is taken out, the macros disable themselves automatically, as well as they enable back in case of a MCA is configured again.

    Some Particular settings:
    Both COUNTERS and MCA are operated simultaneously from ct and scans commands if mcaon is set. mcaoff disables the MCA to be addressed from those commands.

    On the other hand, mcaacq always run the MCA, but never run the counters, whatever mcaon or mcaoff is set. mcasetup AUTO-RUN option (toggling enabled /disabled) does the same as mcaon / mcaoff.
     command		mcaon		mcaoff
    mcaacq		MCA			MCA

    The real time is the clock time. The live time is the real time substracted the electronics dead time.
    	real = live + dead
    Ininternal synchromode, MCA acquisitions terminate when the amount of time elapsed, either real or live in respect of mcasetup time mode settings, matches the time the MCA internal timer was preset with.

    In external synchro mode, MCA acquisitions from ct and scans, are externally (hardware) gated by the SPEC timer (vct6 or whatever timer has a gate output). The real or live time modes are not relevant in those cases . Nevertheless, the external synchro mode never affects mcaacq, which still presets MCA timer, in real or live time mode regarding mcasetup settings.

    In any case, SPEC always waits for an acquisition to terminate before going to the next step.
    	MCA setup		MCA elapsed times		SPEC timer 
      Synchro	Time mode	real		live
      internal	real	preset		preset-dead	preset
      internal	live	preset+dead	preset 		preset
    external	not relevant	~preset		~preset-dead	preset

    Hardware and software initialisation and setup.
    The same but without any input; default/current values are set.
    Display MCA configuration and status.
    Start an acquisition.
    Stop an acquisition.
    Read the MCA memory.
    Report the MCA elapsed times.
    Clear the MCA memory.
    MCA acquisition.
    Disable MCA control from scans and ct.
    Enable back MCA control from scans and ct.
    Save spectrum to disk file.
    Load back spectrum from disk file.
    define ROIs.
    mcacal, mcacalm
    Computer aided and manual calibration of the MCA.
    Better use the GUI if it is installed.
    Show calibration fit parameters or input new parameters.
    Toggle between channel (uncalib) and calibrated mode.
    Switch the GUI off.
    Switch the GUI on.
    Plot the current MCA data when GUI is off.
    A screen plot of the current MCA data in cplot format.
    A printer plot of the current MCA data in cplot format.

    mcaroi roi1
    ROI       |   Channels    | Energy                      | ROI  | Roi 
    names     | first | last  | min          | max          |ACTIVE| numbers
    roi       | 0     | 8191  | 0.0000       | 0.0000       |  -   | 0
    roi1      | 0     | 511   | 0.0000       | 0.0000       |  X   | 1
    Sets ROI number 1 as the one active.

    Counters roi1 and roi are declared in config.
    Fri Dec  1 10:41:57 1995
         Seconds = 1
             MCA = 5340 (5340/s)
           MCA 1 = 292 (292/s)
    The MCA acquires data on the wider range over the counter-assigned-ROIs plus the active ROI. The eventually saved spectrum is limited to the active ROI, while each counter-assigned-ROIs reports integrated counts value over the particular ROI they are assigned to.
    ascan m0 0 10 5 1
    Total 11 points, 11 seconds
    Scan  37   Fri Dec  1 10:56:08 1995   file = ./data/test  mcl  user = lagier
    ascan  m0 0 10  10 1
       Motor 0 MCA 1  MCA    Seconds 
      0    0.0000       292      5340     	    1
      1    2.0000       328      5363          1 
      2    4.0000       299      5400          1 
      3    6.0000       299      5333          1 
      4    8.0000       328      5398          1 
      5   10.0000       328      5400          1 
    A spectrum is accumulated at each scan step.

    MCA macro user hook:
    Users can hook their own macro to those macros, using "cdef()".
    called when looping in "mca_waitcounts", i.e. "mcaacq".
    called at the end of "mcastart", i.e. just after device startup.
    called from "mcaacq", while waiting for the acquisition is over, and after keyboard input ("mca_key").

      those macros use:
    • the binary psearch, that must be in PATH
    • the macros:
      • psearch.mac for spectrum calibration
      • cplot.mac for cplot
      • saveload.mac for data saving
      • stlocal.mac for crying and various things
      • pseudo.mac for pseudo counting
      • menu.mac for menu handling
      that must be loaded together with the mca.mac file.

    Usage: mcasetup [adc] [tmode] [gsz] [g] [cal] [Xlbl] [Xun] [nclr] [sleep] [bgnd] [gui] [log] [dots] [lines] [ebars] [flag] [red] [synchr]
    Sets the MCA hardware and software up. You can either give all the parameters on the command line or use the menu that shows up when typing "mcasetup" alone.
      Input arguments description. [variable name, default value]
    • adc: active adc number (1 or 2). [MCA_ADCNO, 1]
    • tmode: 1 if live time, 2 if real time. [MCA_TMODE, 2]
    • gsz: MCA memory group size in channels. [MCA_MEMGRPSIZE, 8192]
    • g: MCA selected memory group. [MCA_MEMGRP[1] , 0]
    • cal: 1 if spectrum is calibrated, 0 otherwise. [MCA_ENERGY, 0]
    • Xlbl: X plot label for calibrated spectrum. [MCA_CP_XLBL, "Energy"]
    • Xun: X unit for calibrated spectrum. [MCA_CP_XUNT, "KeV"]
    • nclr: 0 for memory clearing prior to acquisition, 1 otherwise. [MCA_SAVEBUFFER, 0]
    • sleep: number of sec. sleeping between run plot updates. [MCA_DISP_SEC, 0]
    • bgnd: 1 if you want background substraction in ROIs counts. [MCA_BACKSUB, 0]
    • gui: 1 for gui plot. [MCA_GUI, 0]
    • log: 1 for log plot. [MCA_LOG, 0]
    • dots: 1 for large dots in plot. [MCA_DOTS, 0]
    • lines: 1 for lines plotting. [MCA_LINES, 0]
    • ebars: 1 for error bars plotting. [MCA_EBARS, 0]
    • flag: data saving flag [MCA_FLAG, 0]
      • 0x01 save spectrum during scans to a file.
      • 0x02 save spectrum after each other acquisition to a file.
      • 0x04 save to specific MCA file, otherwise use scans file [DATAFILE].
    • red: data reduction coefficient, to be applied at saving.[MCA_REDUCTION, 1]
    • synchr: MCA acquisition is hard-synchronized with SPEC configured timer. [MCA_SYNCHRO, 0]

    NB :
    It is possible to have the last acquisition elapsed times values reported in counters by simply configuring the counters you need out of mcaLt, mcaRt and mcaDt mnemonics, respectively standing for Live, Real and Dead times.

    Usage: mcaoff
    Disables the MCA.
    The MCA is no longer addressed during standard SPEC operation ("ct", scans ..), but still from "mcaacq".

    Usage: mcaon
    Enables back the MCA.

    Usage: mcainit
    Initialises the MCA macros and hardware. Can be called at startup to re-setup things without giving any parameter, nor calling any menu. The current or default parameters are then set. Default are mensionned together with mcasetup description.

    Usage: mcaacq [preset_seconds] [roi | first] [last]
    Acquires data with the MCA only. The rest of counters configured in SPEC are not addressed by this command. If you need it, use standard ct command. (don't forgot, mcasetup set AUTO-RUN mode <ON>, or mcaon).
    mcaacqconsists in the following sequence:
    • stopping any already running acquisition.
    • clearing (if setup) the active MCA memory group.
    • preseting the time.
    • starting the acquisition.
    • polling the device till time is over.
      • reading the MCA buffer.
      • plotting the data spectrum.
    • saving (if setup) the acquired spectrum to disk file.

    The MCA memory is read within the range specified, or if none, the active ROI .
    If the requested preset time is 0 or un-specified, the acquisition is started "for ever"; press "control-C" or "s" or "q" to stop it.
    Pressing "c" would clear the memory on the fly. If the GUI is not active, you can also change the plot update intervals (press "u"), change the plot x or y ranges (press "x" or "y"), integrate counts on region (press "i"), toggles plot attributes such as lines (press "l"), large dots ("d") and log y("g"). Meanwhile, the acquisition goes on.

    Usage: mcaclear
    Clears the active MCA memory group.

    Usage: mcastart [preset_seconds]
    Presets and starts an acquisition.

    Usage: mcastop
    Stops acquisition if running.

    Usage: mcahalt
    Send "stop acquisition" signal whatever is the status of the device. It might happen that the device server gives a meaningless error message, if the status is already "IDLE".

    Usage: mcaread [roi|first] [last]
    Reads the MCA memory within the range specified.

    Usage: mcatimes
    Reports the MCA elapsed live , real and dead times.

    Usage: mcastat
    Prints out a detailed status of the SPEC MCA registers.

    Usage: mcaroi [no|name] [<first> <last>] [name]
    ROIs definition.
    detail of usage:
    mcaroi no first last counter
    modifies ROI number "no".
    mcaroi no
    sets ROI "no" as the active one.
    mcaroi no counter
    associates name "counter", which is eventually a counter mnemonic in config, with ROI number "no".
    calls the ROI menu.
    Each ROI is referrenced to by a number that is set by the software. You can use the ROI names to referrence them as well. The active ROI is used as the default operation range when no other range is specified. ROIs which names are configured counter mnemonics are automatically set as pseudo counters to report integrated counts value over the corresponding ROI.

    Usage: mcanewfile [file_name]
    Sets a new file prefix and initialises the spectrum run number, which appears in the file name as e.g. PREFIX_001.mca. But when spectrum was taken during a scan, the file name changes for PREFIX_001_000.mca, where first number is the scan number (SCAN_N) and second one the point number in the scan.

    Usage: mcasave [roi|min] [max] [-silent]
    Saves acquired data to disk file.
    If a range is specified, the data are saved within that range, otherwise the whole spectrum is dumped to the file. The file is either the standard scanfile or a private MCA file, depending on "mcasetup" entries.
    If standard scanfile is used, each spectrum originated from out of a scan (ct or mcaacq) is nevertheless referenced to a "scan number". (SCAN_N is incremented).
    If a private file is used, it must have been set a prefix using "mcanewfile" command. Then each spectrum is saved to a different file. The file name extensions gives the information on its origin. see mcanewfile.
    The file syntax is standard and MCA mixed. MCA syntax is described below:
    Each MCA related line holds the character "@".
    MCA file syntax:
    #@MCA %%16C
    Format string passed to data_dump() function. This format string is held by the global variable "MCA_FMT" and can then been adapted to particular needs. "%%16C" is the default. It dumps data on 1 line, cut every 16 points:
    @A 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\
     0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\
     0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\
     0 0 0 0 0 0 0 0 0 0 0 ...
    "%%16" would do the same without any backslash, "1" would dump 1 point per line, ...
    #@CHANN 1024 0 1023 1
    number of data points, first MCA channel, last one, reduction factor.
    #@CTIME 1 17 17
    Time preset, MCA elapsed live time, MCA elapsed real time.
    #@CALIB 0 1 0
    Calibration parameters as "a b c", in "E = a + b*ch + c*ch^2".
    @A 0 0 0....
    MCA data. Each value is the content of one channel, or an integrated value over several channels if a reduction was applied.
    Data reduction is useful in some cases to minimize file sizes, which might grow very fast and eventually fill up the disk.
    It consists of:
    • averaging counts every "factor" points.
    • multiplying by "factor" each integer average to get an integrated value.
    When "-silent" the macro does not ask for a user comment.

    Usage: mcaload <file> <scan_no> [scanpt_no] [0|1]
    Loads spectrum from a file.
    The loaded spectrum is stored into WS memory as if it would have just been acquired. If file is a standard scan file, spectra are referrenced to by their "scan" number, and eventually their "scan_point" number. Both numbers must be 0 when loading data from private MCA files. 4th argument to 1 means that the calibration parameters are to be loaded from the file as well. In that case any other current calibration is overwritten. To avoid it, "mcasave" it with the current spectrum, before "mcaload"ing.
    Reduced data channel numbering starts from the first channel value (prior to reduction) added integer part of half the "factor", every next point incremented by "factor" .....

    Usage: mcapar
    Shows calibration fit parameters or inputs new parameters.

    Usage: mcaE
    Toggles between channel (uncalib) and calibrated mode.

    Usage: mcacal
    Computer aided energy calibration of the MCA.

    Usage: mcacalm
    Manual calibration of the MCA.

    Usage: mcapeak
    Peak search on the current spectrum.

    Usage: mcashow
    Shows peaks found.

    Usage: mcacplot [first|roi] [last]
    A screen plot of the current MCA data in cplot format. Part of the plot parameters are taken from "mcasetup", rest from "cpsetup" settings.

    Usage: mcapplot [first|roi] [last]
    A printer plot of the current MCA data in cplot format. That follows the same rules as "mcacplot" macro.

    Usage: mcaguion
    Turns MCA Graphical Interface on.

    Usage: mcaguioff
    Turns MCA Graphical Interface off.

    Usage: mcasplot [xmin] [xmax] [ymin] [ymax]
    Plots the current MCA data spectrum. Does nothing when using GUI.
    Detail of usage:
    mcasplot first last [ymin ymax]
    plots acquired spectrum between the limits specified. Eventually, "ymin" and "ymax" are Y limits values so that you may Y-rescale your plot.
    mcasplot roino [ymin ymax]
    plots acquired spectrum within ROI specified.
    plots the whole acquired spectrum

Internal Macros:
    Usage: mcaunsetup
    Setup file service.

    Usage: mca_defaults [mask]
    Sets default values to some global variables.

    Usage: mca_max_channels (size)
    Returns installed device full memory size. If the device is disconneted, the size specified as input is returned, so that simulation mode or loaded data analysis are possible.

    Usage: mca_device
    Checks wether a MCA is configured and reads in its device server name or its device type. If it appears that no device is configured, it makes that the mca macros detach themselves from the SPEC standard ones.

    Usage: mca_state ()
    Checks MCA State. (acquiring, idle, disconnected or not configured)

    Usage: mca_setup (adc,tm,sz,g,cal,lbl,un,nclr,slp,bgd,lg,dt,ln,eb,flag,red,syn)
    Reads in setup parameters and do the setup. see "mcasetup" for details

    Usage: mca_dosetup ()
    Does the actual setup, i.e. hardware setup, general operation setup and subsequent software setup.

    Usage: mca_hdwsetup()
    hardware setup, i.e. Adc selection, Memory initialisation, and operation setup, i.e. time mode and soft preset.

    Usage: mca_wait ()
    loops printing a message till the acquisition is finished.

    Usage: mca_firstinit()
    Does things that must or need only to be done once at startup.
    Loads roi from file, Reset|Declare shared memory ...

    Usage: mca_softsetup()
    software setup, i.e. inits memory and assign newly set up parameters to the relevant globals.

    Usage: mca_deldef()
    Un-hooks MCA operation from the standard macros.

    Usage: mca_roideldef ()
    Un-hooks ROI operation from the standard macros.

    Usage: mca_cdef()
    Hooks MCA operation to the standard macros.

    Usage: mca_saveroihead
    Saves to DATAFILE MCA ROIS description.

    Usage: mca_roicdef ()
    Hooks ROI operation to the standard macros.

    Usage: mca_config
    "config" / "reconfig" service. Hooked to "config_mac".

    Usage: mca_setupmenu
    MCA menu.

    Usage: mca_menu
    Display MCA General menu. (page 1)

    Usage: mca_calgrp
    Prepares MCA memory group setting.

    Usage: mca_cpmenu
    Display MCA CPLOT menu. (page 2)

    Usage: mca_setupchk
    Checks availability of some menu options.

    Usage: mca_io (command,argument,flag)
    Management of input/output to the MCA.
    flag 0: returns what mca_par() returns or argument if error occured (cheat a bit)
    flag 1: returns really what mca_par() returns.

    Usage: mca_waitcounts
    Plots and prints out times while waiting for the acquisition to complete. This is used by "mcaacq" macro.

    Usage: mca_key <key>
    Manages a menu which is callable using input keys. see "mcaacq".

    Usage: mca_preset (seconds)
    Sets the preset time value for the next acquisition.

    Usage: mca_read [first_ch] [last_ch]
    Read the MCA memory within the channel range specified. Default reads the whole memory.

    Usage: mca_times ()
    Reads in times elapsed. (Live, Real and Dead time).

    Usage: mca_readbuffer
    Reads in MCA spectrum and plots it. That macro is hooked to "user_getcounts".

    Usage: mca_getcounts <ROI_counter_mnemonic> <channel_min> <channel_max>
    Integrates counts on ROIs and updates SPEC counters register. This is hooked to "user_getcounts", one hook per counter-assigned ROI.

    Usage: mca_integrate (channel_min,channel_max)
    Integrates counts on channels region. This is called by "mca_getcounts". Does a backgroung substraction if that option is turned on in "mcasetup".

    Usage: mcaloadroi
    re-loads ROI definition from disk.

    Usage: mcasaveroi
    saves ROI definition to disk.

    Usage: mca_roinum (roi_id)
    Returns ROI number, or -1 if not found. "roi_id" is a ROI name or a ROI number.

    Usage: mca_roidisp ()
    Prints out ROI definition table.

    Usage: mca_roisetname (no,name)
    Assigns ROI number <no> with name <name>.

    Usage: mca_roisetrange (no,min,max)
    Assigns ROI number <no> with specified range.

    Usage: mca_roimenu
    ROI edition menu.

    Usage: _mca_roiadd
    New ROI input.

    Usage: _mca_roiname
    ROI name input.

    Usage: _mca_roirange
    ROI range input.

    Usage: _mca_roidel
    ROI deletion.

    Usage: _mca_roichange
    ROI modification.

    Usage: mca_fileheader(file)
    Opens next MCA private file, and writes header on it.

    Usage: mca_filename (prefix, number, suffix)
    Returns MCA private file name.

    Usage: MCA_SL
    Returns true when the saveload package macros are loaded.

    Usage: mca_sl_test [string]
    Checks if saveload macro package is loaded.

    Usage: mca_data_red()
    Applies data reduction on data in SPEC memory.
    The reduction consists of:
    • averaging counts every "factor" points.
    • multiplying by "factor" each integer average to get an integrated value.

    Usage: mca_savescanhead (ch_min,ch_max)
    Save file header during scans. Hooked to "measure2".

    Usage: mca_savescandata (ch_min,ch_max)
    Save MCA data during scans. Hooked to "user_scan_loop".

    Usage: mca_savectdata (ch_min,ch_max)
    Save header and data to file after a "ct". Hooked to "user_handlecounts".

    Usage: mca_saveacqdata (ch_min, ch_max, headline)
    Save header and data to file after a "mcaacq". Called from "mcaacq".

    Usage: mca_chtoE <array1> <col1> <array2> <col2>
    Same as ps_chtoE from psearch.mac package. i.e., converts all the channels in array1[][col1] to energies and puts these values into destination array2[][col2]. The calibration function E=a+b ch + c ch^2 is used.

    Usage: mca_tops
    Reads in parameters from shared memory (GUI).

    Usage: MCA_EA
    calibration parameter A.(Shared memory)

    Usage: MCA_EB
    calibration parameter B.(Shared memory)

    Usage: MCA_EC
    calibration parameter C.(Shared memory)

    Usage: mca_Ech <mode> <energy> <channel>
    Converts calibrated value into channels (mode 1) or reverse (mode 0) and returns the result.

    Usage: mca_calcE(x)
    Calculated the channel from the given Energy

    Usage: mca_calcch(en)
    Calculated the channel from the given Energy

    Usage: mca_fromps
    Writes out parameters to shared memory (GUI).

    Usage: MCA_PS
    Returns non 0 value if psearch macro package is loaded.

    Usage: mca_ps_test [string]
    Check if psearch macro package is loaded.

    Usage: mca_cplot
    Decides between data in memory or in files for cplot.

    Usage: mca_mplot
    Arranges cplot parameters for MCA private needs and calls cplot program. Recover previous cpsetup settings when finished.

    Usage: mca_fplot
    not implemented yet. foreseen for c-plotting MCA data from a file.

    Usage: mca_guirun
    Checks wether the GUI is running, otherwise starts it.

    Usage: mca_guistart ()
    Starts the Graphical Interface and returns its PID number.

    Usage: mca_plotit
    Just an indirection for mca_plot1 for the sake of the GUI.

    Usage: mca_plot1 (group,xelem,yelem,xmin,xmax,ymin,ymax)
    MCA running plot.

    Usage: mca_resize_to_roi <roi> <channel_min> <channel_max>
    Resises specified range to the specified roi. (in channels)

    Usage: mca_resize_to_last_read <channel_min> <channel_max>
    Resises specified range to the last read spectrum range. (in channels)

    Usage: mca_sharedarray_to_group
    Transfers data spectrum held in the shared memory into SPEC data group.

    Usage: mca_msgw (seconds)
    loops printing dots for the specified time (sec.).

    Usage: mca_getoffset (name,column,xmin)
    Returns array row number of first "xmin" value occurence in the specified array column.

    Usage: mca_getnpts (name,column,xmin,xmax)
    Returns number of points between first occurences of "xmin" and "xmax" in the specified array column.

    Usage: mca_const_utils_and_rdef
    Macro which is run once at mca.mac file loading to prepare things up.

    Usage: mcatcp

    Usage: mcadsstat

    Usage: mcacry

    Usage: mca_dump

    Usage: mcasimon

    Usage: mcasimoff

    Usage: mca_getroi <roi_number|roi_name> <mode> <first> <last>
    Converts ROI into <first> and <last> range limit.

    Usage: mca_roi_Ech
    Converts channels into calibrated value all over the defined ROI.

Filename: mca.mac
Author: MCA.MAC - Marie Claire LAGIER 21/02/94 changed by Elke RAABE 04/01/95
         - last modified  03/96: to use macros functions, shared arrays, GUI.
         -                01/96: to use mca_par() and saveload.mac.        
Last mod.: 12/08/2008 15:30 by rey