=========================================================================
  Procedures for machine studies measuring beam size using sextupoles
=========================================================================
18 February 2021 jac. Updated 2 November 2021.

---------------------------------------------------------------------------------------------
* To start gdl vbsm monitoring (SW):
>gdl vbsm_pos

* To start gdl monitoring of DTT tunes(SW,JAC):
>gdl dtt_tunes (the .inp files must be in the local directory)

* To read the tunes once (JAC):
>/home/critten/linux_lib/production/bin/read_dtt_freq

BEWARE: if a .inp file of the same name exists in the directory
/nfs/cesr/online/acc_control/program_info/gdl/
it will be chosen by default over the .inp file in the local directory.
This can be circumvented with, for example,
>gdl ./vbsm_pos
---------------------------------------------------------------------------------------------

* To perform a coarse (0+-3000cu) scan of a single quadrupole
* with pauses to take TbT data
CesrV> call k2scan_coarse.cesrv [sextupole index 8-10, 12-45, 47, 52, 54-89, 91]
---------------------------------------------------------------------------------------------

* To perform a fine (-3000cu to +3000cu in 11 steps) scan of a single sextupole
* with pauses to take TbT data
CesrV> call k2scan_fine.cesrv [sextupole index 8-10, 12-45, 47, 52, 54-89, 91]
---------------------------------------------------------------------------------------------

* To start the calibration loop over all sextupoles including pauses
* to take TbT data (DCS, JAC):
>/home/dcs16/linux_lib/production/bin/cesrv_cl calsex_loop.cesrv
This CesrV script is available here:
https://www.classe.cornell.edu/~critten/chessu/ms_sextupoles/calsex_loop.cesrv

---------------------------------------------------------------------------------------------
* To take one set of turn-by-turn orbit data (VK):
>cbpm_tbt_positrons
Choose 8192 turns. If the data-taking is too time-consuming, use 4096 turns.
The DTT can be locked during the data-taking.

* To take a certain number of TbT data sets, currently three (VK):
> source /home/critten/ms_sextupoles/take_TBT.sh
NB: This script will write zero's in the field "The locked freq" when lock
has been lost. The values from the digital tune tracker register 
continue to update.

---------------------------------------------------------------------------------------------
* New version of CesrV which writes both phase and orbit data (DCS):
>/home/dcs16/linux_lib/production/bin/cesrv_cl

CesrV documentation is here (JAC):
https://cesrwww.lepp.cornell.edu/wiki/CESR/CESRV

To calibrate a sextupole, for example:

CesrV> calib  sex_09aw [cu1] [cu2] phase_tbt ! cu1, cu2 optional, see below.

If cu1 and cu2 not present, the sextupole settings used are +- half this value
CesrV>set logic%sex_calib_delta_cu = 30000
The equivalent value used during the 10/28/2002 calibrations was 8000.
Those calibrations were accurate to about rms 7%.

Number of bump settings for each sextupole
CesrV>set logic%sex_calib_n_bump_set = 2

This dQ value is used to set the closed bump magnitude.
Leave it at default
CesrV>set logic%sdQ_max_quad_calib = 2e-2


Nearly all sextupoles have length 0.272 m and dk2/dcu = 1.53e-4
So the range in k2L is from -1.25 to 1.25 m^-2.

---------------------------------------------------------------------------------------------
* The digital tune tracker must be locked during the sextupole calibrations
Detailed information here (JSh):
https://www.classe.cornell.edu/~critten/chessu/ms_sextupoles/DTT_operation.pdf

If the settings have been tuned, then this shell command will suffice to lock the tunes (JSh):
>tt_lock_acq

---------------------------------------------------------------------------------------------
*Detailed info on sextupole calibration dated (28 Nov 2018) here (JAC):
/nfs/cesr/online/machine_data/constants/calib/sextupole.cal

---------------------------------------------------------------------------------------------
*Sextupole settings as of 15 Feb 2021) are here (JAC):
https://www.classe.cornell.edu/~critten/chessu/ms_sextupoles/cesrv_sextupoles_15feb2021.txt

This file was obtained with
CesrV>&show sex

---------------------------------------------------------------------------------------------
* In addition to the gdl monitoring described above, newin can also be used.
* To start newin vbsm monitoring (JAC):
>newin newin_vbsm

* To start newin monitoring of DTT tunes(JAC):
> newin dtt_tunes

* To start newin monitoring of DTT tunes and bunch current(JAC):
> newin newin_dtt_current

* To see which nodes are being logged, for example (SBP):
> whlog ttrack

---------------------------------------------------------------------------------------------
* To set/read individual sextupole settings in cu:
$fff vxputn csr_sext_cur 8 8 <cu>
$fff vxgetn csr_sext_cur 8 8

These can be done with spawn commands in CesrV

---------------------------------------------------------------------------------------------
* In addition to the gdl and newin monitoring, dtp can also be used to write a tune logging file:
> dtp dtt_tunes.ctl
<return> to accept the default data file name.
Choice TD to begin taking data.
The control file (dtt_tunes.ctl) and the data file (DTT_TUNES.hh-mm)
are found in the directory /nfs/cesr/online/acc_control/program_info/dtp

---------------------------------------------------------------------------------------------
* Yet another way to record DTT tunes, currently set up for every 3 seconds(VK):
> source /home/critten/ms_sextupoles/take_tunes_with_rms.sh

The output file can be converted to a simpler format with

>/nfs/opt/root-6.13.02.sl7/bin/root -l read_and_plot_tune.C

by changing the input file name in the .C file.
