************************************************************************
 							
Today I learned the following about magnet "tolerances". (12/13/96)
This discussion is relevant for CAMAC controlled devices, and not
necessarilly correct for BITBUS controlled devices.

First "Check tolerance"...determination of whether to perturb DAC if
asked to trim:

Magnet will not perturb if either:

	|BACT - BDES|
	------------- < TOLS(2)
	    BDES
or

	|BACT - BDES| < TOLS(1)     is true.


Magnet will be "green" if either:

	|BACT - BDES|
	------------- < TOLS(4)
	    BDES
or

	|BACT - BDES| < TOLS(3)     is true.


************************************************************************
Use of ATOL for Calibrate:

A calibration is performed in which magnet DAC is swept from IMMS prediced
min to max, n determined by NSCY or CALIB diagnostic setup. The data of
DAC vs READBACK is then fitted to a line. Those fit results are then
compared to the DVI database, and calibration is successful (putting the
measured fit results into DVIC) if both:

	|DVI(1) - MEASURED OFFSET|
       ----------------------------   <   ATOL(1)
            |MEASURED SLOPE|

and
	|DVI(2) - MEASURED SLOPE |
       ----------------------------   <   ATOL(2)
            |MEASURED SLOPE|

are true.
	so that in effect ATOL(2) is used as a "fractional" test of the
	fitted slope, and ATOL(1) is used as an absolute (i.e. AMPERES)
	test of the fitted offset.

************************************************************************
Use of ATOL for STDZ :     

As for STDZ, today (12/18/96) William and I looked at ref_rmx_mgnt:stdzall and
think that the following is probibly true:

At each STDZ point (MIN,MAX, and NSCY times) the code gets IACT and compares
it with IDES, IDES presumably IMMS(1) or IMMS(2), piped into DVIC?
The current is "OK" at each point if:

	ABS(IDES-IACT) < the greater of:
				ATOL(2)* ABS(IDES)
			            and
				ATOL(1)

	so that in effect, ATOL(2) is used as a "fractional" test of the
	"high current" points, and ATOL(1) is used as an absolute (i.e.
	error in AMPERES) of the "low current" points.

************************************************************************
About RAMP for LGPS: (1/9/97)

	Two entries are indices. First is "normal" ramp rate, second is
"fast" ramp rate; second used for (???). Index refers to following table
which describes the FULL SCALE DAC RAMP TIME in seconds. 

	INDEX	F.S. Ramp Time (sec)
	0              1094
	1              545 
	2              273 
	3              136 
	4              68  
	5              17   
	6              4     
	7            no ramp

	If interested in AMPS/SEC translate table entry in the following
manner (for PSC2):
                                     
      ramp rate(AMPS/SEC) =         65536          <-- 16384 for PSC
                            ------------------- 
                            table entry * DVI(2)

************************************************************************
Loss of STDZ: (2/9/04 with major enhancement 9/27/04)

       Posed with the question "what will cause a standardized magnet
to lose standardization?" William and I learned the following:
The relevant codes live in ref_:[rmx.mgnt]STDZCHK.F86
                           ref_:[rmx.mgnt]MAGTRCK.F86 
                   and     ref_:[rmx.mgnt]MGNTDOPOLY.F86 
   
       The unsatisfactory answer is that if the following test:

ABS(IACT-IMAX) > 4.0 * CURRENT_TOL    fails then STDZ is lost.

What are the constituents of this test?

IACT is clearly the current presently measured. 

IMAX is tricky. People always think that IMAX is the "maximum current the
power supply can do". This is not true. IMAX is the biggest current seen
since STDZ has happened. If a magnet is STDZ ok at 100 amps and IMAX is 
100 amps, and BDES is changed and trimmed to 110 amps, IMAX gets replaced
with value 110 amps and STDZ is still OK. (Assuming STDZ upwards). Note
that for magnets which use IVBD instead of IVBU all this is done backwards.

Our greatest difficulty is understanding CURRENT_TOL. For this purpose

CURRENT_TOL = ABS(CHCK_TOLERANCE * DC_DB) 

We find:

CHCK_TOLERANCE = MAX( TOLS(3),TOLS(4)*ABS(BDES) )

     Now rememember TOLS(3) is and absolute (i.e. B units) comparison 
                       relevant for making low B values be OK and that 
                    TOLS(4) is a fractional comparison relevant for making
                       large B values OK. 

     So this means CHCK_TOLERANCE is a thing with units of B.

DC_DB is advertised as the "slope of the IVB polymonial at BDES"...would 
have units amperes per unit B (with B generically listed meaning kGm for 
dipoles, kG for quadrupoles, kG/m for sextupoles).

From all this, is should be possible to detemine how much a given magnet
power supply can "droop" before STDZ is lost.

Let's try a (hypothetical) example:

50B1 (CA11 LGPS 41) magnet is configured to deflect a 28.5 GeV beam to
52SL2 and happens to be standardized OK. First tabulate the parameters
we will need:

BDES = 16.515 kGm
IACT = 350    amperes
IMAX = 350    amperes
TOLS = 3.00 e-3   7.00e-5   6.00e-3    1.40e-4
IVBU = -4.06 , 23.53 , -0.604 , 4.83e-2 , -1.66e-3 , 2.154e-5 , -1.092e-8

Now from above STDZ will be lost if 

ABS(IACT-IMAX) > 4.0 * CURRENT_TOL  or
ABS(IACT-IMAX) > 4.0 * ABS(CHCK_TOLERANCE * DC_DB)

  CHCK_TOLERANCE = MAX(TOLS(3),TOLS(4)*ABS(BDES))
                 = MAX(6.00e-3 kGm , 1.4e-4 * 16.515 kGm)
                 = MAX(6.00e-3 kGm , 2.31e-3 kGm)
                 = 6.00e-3 kGm

    DC_DB        = "slope of IVB polynomial at BDES"

now IVBU tells us:

                          amps*B          amps*B^2             amps*B^3
I(B)= -4.06 amps +  23.53 ----    - 0.604 ----     +   4.83e-2 ----     (etc.)
                          kGm            (kGm)^2              (kGm)^3

so...


dI(B)                     amps          2*B amps               3*B^2 amps
---- =      0    +  23.53 ---     -0.604 ----      +   4.83e-2 ----    (etc.)
 dB                       kGm           (kGm)^2                (kGm)^3
            

To simplify the example I'll only show three terms. You should evaluate
all terms.

        dI(B=16.515)          amps       2*(16.5kgm)amps            3*(16.5kgm)^2 amps
DC_DB = ---          =  23.53 ---  -0.604---               + 4.83e-2 ----          (etc)
        dB                    kGm        (kGm)^2                     (kGm)^3



                     = (23.53  - 0.604*2*16.515  + 4.83e-2*3*(16.515)^2)amps/kGm

            DC_DB    = 43.1 amps/kGm  (21.04 amps/kGm if I include all terms)
                                       (reader should confirm this as exercise)



So we have assembled:     DC_DB          = 21.04   amps/kGm     and
                          CHCK_TOLERANCE = 6.00e-3 kGm


Now back to our condition for STDZ to be lost:

ABS(IACT-IMAX) > 4.0 * ABS(CHCK_TOLERANCE * DC_DB)
ABS(IACT-350A) > 4.0 * ABS(6.00e-3 kGm    * 21.04  amps/kGm)
ABS(IACT-350A) > 4.0 * 0.126 AMPS
ABS(IACT-350A) > 0.50 AMPS

So for this example STDZ would be lost if IACT were to drop below 349.50 amps.

If reader is interested in applying this technique to a specific magnet,
I have written a matlab script which does this in:

               user_disk_slc:[hvs.matdata]stdzlost.m

which prompts user for a magnet device, gets the data from DB, and does
the number crunching shown above. 

For whatever reason (which I have not been able to flush out), errlog instances 
of lost standardize report a tolerance half what I determine here (as if the 
4*current_tol above were actually only 2*current_tol). In my matlab script I 
have employed a fudge in which the "4" value has been replaced by a "2" value,
and that makes the matlab script come up with the same answer as the control 
system errlog reporting on instances of lost standardize.
************************************************************************