# Macros to operate the mca (EPICS / Canberra) # # hp_mca.mac # # hp 01.02.2001 # hp 16.05.2001 # # # # This file redefines the normally empty user macros for scans and counting # requires hp_fio.mac to be loaded before this file is loaded # # # # global definitions # global MCA_data,MCA_channels,MCA_device,MCA_info,MCA_info_nr,MCA_info_name, \ MCA_epics_name,MCA_roi,MCA_roi_nr,MCA_roi_fields,MCA_roi_epics_names, \ MCA_roi_epics_prefix,MCA_cal_ch1,MCA_cal_ch2,MCA_cal_ener1,MCA_cal_ener2, \ MCA_NAME,MCA_NUMBER,MCA_ON,MCA_init_executed,MCA_fio_number # # EPICS name of the MCA record MCA_epics_name = "6idd:aim_adc1" # # number of channels MCA_channels = epics_get(sprintf("%s%s",MCA_epics_name,".NMAX")) # # mca device number, usually 0 MCA_device = 0 # # number of roi channels in use, fields used per roi, written into data file, # epics names prefix, epics names # Name is built this way: MCA_epics_name MCA_roi_epics_prefix roi_number MCA_roi_epics_names[] MCA_roi_nr = 10 MCA_roi_fields = 7 MCA_roi_fields_write = 1 MCA_roi_epics_prefix = ".R" MCA_roi_epics_names[0] = "" MCA_roi_epics_names[1] = "N" MCA_roi_epics_names[2] = "LO" MCA_roi_epics_names[3] = "HI" MCA_roi_epics_names[4] = "BG" MCA_roi_epics_names[5] = "P" MCA_roi_epics_names[6] = "NM" # # number of info channels in use, see mca additional information names MCA_info_nr = 3 # # mca additional information names MCA_info_name[0] = "elapsed_real_time" MCA_info_name[1] = "elapsed_live_time" MCA_info_name[2] = "dead_time_percentage" # # variables for energy calibration # MCA_cal_ch1 = 0 # MCA_cal_ch2 = 0 # MCA_cal_ener1 = 0 # MCA_cal_ener2 = 0 MCA_cal_ch1 = 973 MCA_cal_ch2 = 1088 MCA_cal_ener1 = 122 MCA_cal_ener2 = 136.5 # # initialise data array ulong array MCA_data[MCA_channels] # # initialise MCA_NAME, MCA_NUMBER and MCA_init_executed MCA_NAME = "test_" MCA_NUMBER = 0 MCA_init_executed = 0 # # initialise MCA_ON, automatic counting is only on, if MCA_ON > 0 MCA_ON = 0 # # # # ################################################################################ # # mca_mode_change # # hp 25.01.2001 # hp 17.05.2001 # # changes between the following modes: # 0 - MCA not in use # 1 - MCA in use but only ROIs are read out # 2 - MCA in use and a MCA spectrum is stored at each scan point # ################################################################################ # def mca_mode_change '{ local mode mode = MCA_ON if ($# == 0) { printf("\nmca_mode_change (hp) 17.05.2001\n\n") printf("The following modes are defined:\n") printf(" 0 - MCA not in use\n") printf(" 1 - MCA in use, only ROIs are read out\n") printf(" 2 - MCA in use, MCA spectrum stored at each scan point\n") mode = getval("Your choice",mode) } else { if ($# != 1) { printf("usage: mca_mode_change [value] (0,1,2)\n") exit } else { mode = $1 } } if ((mode == 0) || (mode == 1) || (mode == 2)) { MCA_ON = mode printf("\nNew mode: ") if (mode == 0) printf("0 - MCA not in use\n") if (mode == 1) printf("1 - MCA in use, only ROIs are read out\n") if (mode == 2) printf("2 - MCA in use, MCA spectrum stored at each scan point\n") } else { printf("Only 0, 1 and 2 are valid modes. mca_mode\nwas not changed!\n") exit } }' # # # # ################################################################################ # # mca_energy_calibration # # hp 25.01.2001 # hp 17.05.2001 # # macro to easily do an energy calibration # ################################################################################ # def mca_energy_calibration '{ local e1,e2 printf("\nmca_energy_calibration (hp) 17.05.2001\n\n") printf("Please enter the two calibration energies and the\n") printf("corresponding channel numbers:\n") MCA_cal_ener1 = getval("First energy",MCA_cal_ener1) MCA_cal_ch1 = getval("Channel number first energy",MCA_cal_ch1) MCA_cal_ener2 = getval("Second energy",MCA_cal_ener2) MCA_cal_ch2 = getval("Channel number second energy",MCA_cal_ch2) _mca_calc_energy_channel 0 e1 = channel_ener _mca_calc_energy_channel MCA_channels e2 = channel_ener printf("\nWith this calibration your MCA is working \nbetween %g keV and %g keV\n",e1,e2) }' # # # # ################################################################################# # # mca_new_filename # # hp 11.07.2000 # hp 16.05.2001 changed version of fio_new_filename # # creates new filename und number for the MCA files # ################################################################################# # def mca_new_filename ' { printf("\nmca_new_filename (hp) 16.05.2001\n") if ($# == 0) { _1 = getval("\nMCA file", MCA_NAME) _2 = MCA_NUMBER _2 = getval("Last MCA file number",_2) } else { _1 = "$1"; _2 = $2 } if (_1 == "") exit MCA_NAME = _1 MCA_NUMBER = _2 mca_fname = sprintf("%s%u.fio",MCA_NAME,MCA_NUMBER+1) if (file_info(mca_fname)) { print "Warning: file ",mca_fname," already exists." print "New output will be appended to old files!" print "You are strongly advised to change the file name!" } } ' # # # # ################################################################################# # # mca_count # # hp 02.02.2001 # # the mca counts for some time and afterwards the data is written to disk # ################################################################################ # def mca_count ' { local _ctime printf("\nmca_count (hp) 02.02.2001\n\n") if (($# != 0) && ($# != 1) && ($# != 2)) { eprint "usage mca_count filename counting_time" eprint "both arguments are optional, but if filename" eprint "is provided also counting_time has to be provided." exit } if ($# == 0) { _ctime = COUNT } else if ($# == 1) { _ctime = $1 } else if ($# == 2) { _ctime = $2 } _mca_count _ctime if ($# == 2) { mca_fname = "$1" } else { MCA_NUMBER += 1 mca_fname = sprintf("%s%u.fio",MCA_NAME,MCA_NUMBER) printf("Saving MCA spectrum in file %s\n",mca_fname) } if (file_info(mca_fname)) { eprint "Warning: file ",mca_fname," already exists." eprint "Change MCA names using the command mca_new_filename." eprint "Data was not written to disk, emergency exit!" exit } _mca_save_data } ' # # # # ################################################################################# # # _mca_count # # hp 01.02.2001 # # the mca counts for a certain amount of time # ################################################################################ # def _mca_count ' { local ct_time,mca_on_store if (MCA_ON >= 3) MCA_ON -= 1 ct_time = $#?($1):COUNT if(ct_time == 0) exit if(ct_time > 0) { mca_par("real") } else { mca_par("integral") } if (MCA_ON == 0) { mca_on_store = MCA_ON MCA_ON = 2 } else { mca_on_store = -1 } ct ct_time if (mca_on_store >= 0) { MCA_ON = mca_on_store } } ' # # # # ################################################################################# # # _mca_wait_until_started # # hp 17.05.2001 # # wait until MCA started counting # ################################################################################ # def _mca_wait_until_started ' { local status status = "" while (status != "Acquire") { sleep(0.05) status = epics_get(sprintf("%s%s",MCA_epics_name,".ACQG")) # p status } sleep(0.01) } ' # # # # ################################################################################# # # user_precount # # hp 16.05.2001 # # executed before counting is done (normally defined empty in standart.mac) # ################################################################################ # def user_precount ' { if (MCA_ON > 0) { if (MCA_init_executed == 0) _mca_init mca_par("clear") mca_par("preset",fabs(COUNT_TIME)+1) mca_par("run") _mca_wait_until_started } } ' # # # # ################################################################################# # # user_getcounts # # hp 16.05.2001 # # executed after counting is done (in scans) (normally defined empty in standart.mac) # ################################################################################ # def user_getcounts ' { if (MCA_ON > 0) { sleep(0.05) mca_par("halt") sleep(0.1) _mca_read_data } if (MCA_ON > 2) { if (FIO_NAME != "") { MCA_fio_number +=1 mca_fname = sprintf("%s%u_%u.fio",FIO_NAME,FIO_NUMBER,MCA_fio_number) } else { MCA_NUMBER += 1 mca_fname = sprintf("%s%u.fio",MCA_NAME,MCA_NUMBER) } if (file_info(mca_fname)) { eprint "Warning: file ",mca_fname," already exists." eprint "Change MCA names using the command mca_new_filename." eprint "Data was not written to disk, emergency exit!" exit } _mca_save_data } } ' # # # # ################################################################################# # # user_ct # # hp 16.05.2001 # # executed after counting is done (in ct) (normally defined empty in standart.mac) # ################################################################################ # def user_ct ' { if (MCA_ON > 0) { local i,j user_getcounts for(j=0;j= 0) { for(i=0;iMCA_channels)) { printf("_mca_calc_energy_channel: Channel out of range\n") exit } if (MCA_cal_ch1 == MCA_cal_ch2) { channel_ener = 0 } else { channel_ener = MCA_cal_ener1+(channel-MCA_cal_ch1) \ *(MCA_cal_ener2-MCA_cal_ener1)/(MCA_cal_ch2-MCA_cal_ch1) } } ' # # # # ################################################################################# # # _mca_wait_until_ready # # hp 02.02.2001 # # waits until the mca finished counting, makes only sence if preset to a counting time # ################################################################################ # def _mca_wait_until_read ' { local wait_time,u1,u2 wait_time = 0.5 u1 = mca_par("preset") if (u1 == 0) exit u1 = 0 u2 = mca_par("elapsed_real") while (u2>u1) { u1 = u2 sleep(wait_time) u2 = mca_par("elapsed_real") } } ' # # # # ################################################################################# # # _mca_read_data # # hp 01.02.2001 # hp 16.02.2001 sleep command is necessary for EPICS otherwise somtimes the following # epics_get commands do not get the correct results # # reads the data from the aim # ################################################################################ # def _mca_read_data ' { # p "reading mca data ..." if (MCA_ON > 1) { mca_sget(MCA_device,MCA_data) sleep(0.1) } if (MCA_info_nr>0) _mca_get_info if (MCA_roi_nr>0) _mca_get_roi } ' # # # # ################################################################################# # # _mca_get_info # # hp 01.02.2001 # # reads additional information from EPICS # ################################################################################ # def _mca_get_info ' { MCA_info[0] = mca_par("elapsed_real") MCA_info[1] = mca_par("elapsed_live") MCA_info[2] = mca_par("dead") } ' # # # # ################################################################################# # # _mca_get_roi # # hp 01.02.2001 # # reads information about the regions of interest (roi) from EPICS # ################################################################################ # def _mca_get_roi ' { local i,j,k if ($# == 1) { k = fabs(int($1)) if (k>MCA_roi_fields) k = MCA_roi_fields } else { k = MCA_roi_fields } for(j=0;j= 0) { for(i=0;i