BGV - BSRT - BPM Data X-Check

Init


In [1]:
from __future__ import print_function, division
from datetime import datetime, timedelta
from pytimber import LoggingDB
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
from itertools import cycle

ldb = LoggingDB()

In [2]:
# BSRT
sigma = ['LHC.BSRT.5L4.B2:FIT_SIGMA_V', 'LHC.BSRT.5L4.B2:FIT_SIGMA_H']
lsf = ['LHC.BSRT.5L4.B2:LSF_V', 'LHC.BSRT.5L4.B2:LSF_H']
pos = ['LHC.BSRT.5L4.B2:FIT_POSITION_V', 'LHC.BSRT.5L4.B2:FIT_POSITION_H']
beta = ['LHC.BSRT.5L4.B2:BETA_V', 'LHC.BSRT.5L4.B2:BETA_H']  # This needs timestamps from the hole fill

# BPM
bpm_data = ['LHC.BOFSU:POSITIONS_V', 'LHC.BOFSU:POSITIONS_H']
bpm_nvar = ['LHC.BOFSU:BPM_NAMES_V', 'LHC.BOFSU:BPM_NAMES_H']
bpm_n = ['.5L4.B2', '.6L4.B2', '.7L4.B2']
bpm_d = [135.338, 172.338, 268.942]

# CTRL - BGV
fillnum = 5570
t1, t2 = datetime(2016, 12, 3, 13, 10), datetime(2016, 12, 3, 13, 15)  # Take into account summer time (UTC+1)
bgv_beta = {'h': 225.76, 'v': 158.93}  # \pm .43, \pm .13
bgv_pos = 220   # make sure position signs etc are OK w.r.t BPMs

General fill data


In [3]:
fill = ldb.getLHCFillData(fillnum)
tf1, tf2 = fill['startTime'], fill['endTime']
print('Fill %s\n\tStart: %s\tEnd  :%s' % (fill["fillNumber"], datetime.utcfromtimestamp(tf1),
                                               datetime.utcfromtimestamp(tf2)))
for item in fill['beamModes']:
    if item['mode'] == 'STABLE':
        break

print("Mode: %s\n\tStart: %s\tEnd  :%s" % (item["mode"], datetime.utcfromtimestamp(item['startTime']),
                                           datetime.utcfromtimestamp(item['endTime'])))


Fill 5570
	Start: 2016-12-03 02:24:33.702000	End  :2016-12-03 13:16:59.331000
Mode: STABLE
	Start: 2016-12-03 07:05:08.394000	End  :2016-12-03 13:10:47.520000

BSRT Data


In [4]:
bsrt = {}

Beta measurements


In [6]:
d_beta = ldb.get(beta, tf1, tf2)

minFmt = mdates.DateFormatter('%Y-%m-%d %H:%M')

f = plt.figure()
ax = f.add_subplot(111)
for k, d in d_beta.iteritems():
    print("%s\t: x: %s\ty: %s" % (k, str(d[0].size), str(d[1].shape)))
    x = [datetime.utcfromtimestamp(ts) for ts in d[0]]
    y = d[1]
    # get the last beta measurement before the beggining of the daq
    ind_min = np.argmin(np.absolute(filter(lambda x: x.days < 0, np.subtract(x, t1))))
    bsrt["b_%s" % k[-1].lower()] = y[ind_min]
    print('\tIndex = %d\tValue = %.1f' % (ind_min, y[ind_min]))

    ax.plot(x, y, lw=3, label=k)

ax.set_ylabel('Value [m]', fontsize=12)
ax.legend(loc=3, numpoints=1, framealpha=.7)
ax.grid(which='both', lw=2)
ax.set_ylim((100, 400))
ax.set_title('[BSRT] Beta')
ax.xaxis.set_major_formatter(minFmt)

f.autofmt_xdate()

plt.show()

print(bsrt)


LHC.BSRT.5L4.B2:BETA_H	: x: 2	y: (2,)
	Index = 1	Value = 200.0
LHC.BSRT.5L4.B2:BETA_V	: x: 2	y: (2,)
	Index = 1	Value = 330.0
{u'b_h': 200.0, u'b_v': 330.0}

Sigma Measurements


In [7]:
d_lsf = ldb.get(lsf, tf1, tf2)

for k, d in d_lsf.iteritems():
    print("%s\t: x: %s\ty: %s" % (k, str(d[0].size), str(d[1].shape)))
    x = [datetime.utcfromtimestamp(ts) for ts in d[0]]
    y = d[1]
    # get the last beta measurement before the beggining of the daq
    ind_min = np.argmin(np.absolute(filter(lambda x: x.days < 0, np.subtract(x, t1))))
    bsrt["c_%s" % k[-1].lower()] = y[ind_min]
    print('\tIndex = %d\tValue = %.3f' % (ind_min, y[ind_min]))
    
print(bsrt)


LHC.BSRT.5L4.B2:LSF_V	: x: 2	y: (2,)
	Index = 1	Value = 0.291
LHC.BSRT.5L4.B2:LSF_H	: x: 2	y: (2,)
	Index = 1	Value = 0.294
{u'b_h': 200.0, u'c_h': 0.29399999999999998, u'b_v': 330.0, u'c_v': 0.29099999999999998}

In [15]:
d_sigma = ldb.get(sigma, t1, t2)

minFmt = mdates.DateFormatter('%Y-%m-%d %H:%M:%S')
ma = cycle(('+','1', 'x', '2', '3', '4', '|', '_'))

f = plt.figure()
ax = f.add_subplot(111)
for k, d in d_sigma.iteritems():
    print("%s\t: x: %s\ty: %s" % (k, str(d[0].size), str(d[1].shape)))
    s = k[-1].lower()
    x = [datetime.utcfromtimestamp(ts) for ts in d[0]]
    y = d[1].mean(axis=1)
    mu = y.mean()
    print('\tMean = %.3f\tSigma = %.3f' % (mu, y.std()))
    bsrt["s_m%s" % s] = mu
    bsrt["sc_m%s" % s] = np.sqrt(mu**2 - bsrt["c_%s" % s]**2)

    ax.plot(x, y, ls='None', marker=ma.next(), label=k)

ax.set_ylabel('Value [mm2]', fontsize=12)
ax.legend(loc=1, numpoints=1, framealpha=.7)
ax.grid(which='both', lw=2)
ax.set_title('[BSRT] Sigma')
ax.xaxis.set_major_formatter(minFmt)

f.autofmt_xdate()

plt.show()


LHC.BSRT.5L4.B2:FIT_SIGMA_H	: x: 268	y: (268, 21)
Shape: (268, 21)
	Mean = 0.350	Sigma = 0.004
LHC.BSRT.5L4.B2:FIT_SIGMA_V	: x: 268	y: (268, 21)
Shape: (268, 21)
	Mean = 0.366	Sigma = 0.009

In [8]:
# e = norm*(sigma**2 / beta(x))
norm = 6900/0.938  # normalization factor for emmitance

print('\n*** Mean Beam Size @BSRT\n\tmX=%.3f\tmY=%.3f\nmXY=%.3f'
      % (bsrt['s_mh'], bsrt['s_mv'], np.mean([bsrt['s_mh'], bsrt['s_mv']])))
e1x = norm*(bsrt['s_mh']**2/bsrt['b_h'])
e1y = norm*(bsrt['s_mv']**2/bsrt['b_v'])
print('\teX=%.3f\teY=%.3f' % (e1x, e1y))

print('\n*** Mean Beam Size @BSRT - Corrected (LSF)\n\tmX=%.3f\tmY=%.3f\nmXY=%.3f' 
      % (bsrt['sc_mh'], bsrt['sc_mv'], np.mean([bsrt['sc_mh'], bsrt['sc_mv']])))
e2x = norm*(bsrt['sc_mh']**2/bsrt['b_h'])
e2y = norm*(bsrt['sc_mv']**2/bsrt['b_v'])
print('\teX=%.3f\teY=%.3f' % (e2x, e2y))

# Extrapolating @BGV
print('\n*** Extrapolating @BGV')
mu1x = bsrt['s_mh']*np.sqrt(bgv_beta['h'] / bsrt['b_h'])
mu1y = bsrt['s_mv']*np.sqrt(bgv_beta['v'] / bsrt['b_v'])
print("\tmX = %.3f\tmY = %.3f" % (mu1x, mu1y))
print('mXY = %.3f' % (np.mean([mu1x, mu1y])))
em1x = norm*mu1x**2/bgv_beta['h']
em1y = norm*mu1y**2/bgv_beta['v']
print('\teX=%.3f\teY=%.3f' % (em1x, em1y))

print('\n*** Extrapolating @BGV - Corrected (LSF)')
mu2x = bsrt['sc_mh']*np.sqrt(bgv_beta['h'] / bsrt['b_h'])
mu2y = bsrt['sc_mv']*np.sqrt(bgv_beta['v'] / bsrt['b_v'])
print("\tmX = %.3f\tmY = %.3f" % (mu2x, mu2y))
print('mXY = %.3f' % (np.mean([mu2x, mu2y])))
print('mXY = %.3f' % (np.sqrt((mu2x**2+mu2y**2)/2.0)))
em2x = norm*mu2x**2/bgv_beta['h']
em2y = norm*mu2y**2/bgv_beta['v']
print('\teX=%.3f\teY=%.3f' % (em2x, em2y))


*** Mean Beam Size @BSRT
	mX=0.350	mY=0.366
mXY=0.358
	eX=4.504	eY=2.992

*** Mean Beam Size @BSRT - Corrected (LSF)
	mX=0.190	mY=0.223
mXY=0.206
	eX=1.325	eY=1.104

*** Extrapolating @BGV
	mX = 0.372	mY = 0.254
mXY = 0.313
	eX=4.504	eY=2.992

*** Extrapolating @BGV - Corrected (LSF)
	mX = 0.202	mY = 0.154
mXY = 0.178
mXY = 0.180
	eX=1.325	eY=1.104

In [ ]:

Position Measurements


In [9]:
d_pos = ldb.get(pos, t1, t2)

minFmt = mdates.DateFormatter('%Y-%m-%d %H:%M:%S')
ma = cycle(('+','1', 'x', '2', '3', '4'))

f = plt.figure()
ax = f.add_subplot(111)
for k, d in d_pos.iteritems():
    print("%s\t: x: %s\ty: %s" % (k, str(d[0].size), str(d[1].shape)))
    x = [datetime.utcfromtimestamp(ts) for ts in d[0]]
    y = d[1].mean(axis=1)
    print('\tMean = %.3f\tSigma = %.3f' % (y.mean(), y.std()))
    bsrt["s_m%s" % k[-1].lower()] = y.mean()
    bsrt["s_s%s" % k[-1].lower()] = y.std()

    ax.plot(x, y, ls='None', marker=ma.next(), label=k)

ax.set_ylabel('Value [mm]', fontsize=12)
ax.legend(loc=5, numpoints=1, framealpha=.7)
ax.grid(which='both', lw=2)
ax.set_title('[BSRT] Position')
ax.xaxis.set_major_formatter(minFmt)

f.autofmt_xdate()

plt.show()


LHC.BSRT.5L4.B2:FIT_POSITION_H	: x: 268	y: (268, 21)
	Mean = -3.040	Sigma = 0.027
LHC.BSRT.5L4.B2:FIT_POSITION_V	: x: 268	y: (268, 21)
	Mean = 0.146	Sigma = 0.031
\begin{equation*} x = (-3.04 \pm 0.03) mm \end{equation*}\begin{equation*} y = (0.15 \pm 0.03) mm \end{equation*}

BPM data


In [10]:
bpm = {}

In [11]:
# Retrieve data from LogDB
n_bpm = ldb.get(bpm_nvar, tf1, tf2)
d_bpm = ldb.get(bpm_data, t1, t2)      

for k, d in n_bpm.iteritems():
    print("%s\t: x: %s\ty: %s" % (k, str(d[0].size), str(d[1].shape)))
for k, d in d_bpm.iteritems():
    print("%s\t: x: %s\ty: %s" % (k, str(d[0].size), str(d[1].shape)))


LHC.BOFSU:BPM_NAMES_V	: x: 1	y: (1, 1088)
LHC.BOFSU:BPM_NAMES_H	: x: 1	y: (1, 1088)
LHC.BOFSU:POSITIONS_V	: x: 330	y: (330, 1088)
LHC.BOFSU:POSITIONS_H	: x: 330	y: (330, 1088)

In [12]:
indexes = {'ih': [], 'iv': []}
tmp = []
for k, d in n_bpm.iteritems():
    print('%s' % k)
    for ind, name in enumerate(d[1][0]):
        for t in bpm_n:
            if t in name:
                indexes['i%s' % k[-1].lower()].append((int(ind), name))
                print('\t%d\t%s - %s' % (ind, k, name))
print('\n')

f = plt.figure()
for cnt, (k, d) in enumerate(d_bpm.iteritems()):
    ma = cycle(('+','1', 'x', '2', '3', '4'))
    ax = f.add_subplot(int('21%s' % (cnt+1)))

    print("%s\t: x: %s\ty: %s" % (k, str(d[0].size), str(d[1].shape)))
    x = [datetime.utcfromtimestamp(ts) for ts in d[0]]

    s = k[-1].lower()
    for t in indexes['i%s' % s]:
        i, n = t
        y = d[1][:,i]
        mu, si = y.mean(), y.std()
        print('\t%s\t: Mean = %.3f\tSigma = %.3f' % (n, mu, si))
        try:
            bpm[n][s] = (mu, si)
        except KeyError:
            bpm[n] = {}
            bpm[n][s] = (mu, si)
        ax.plot(x, y, ls='None', marker=ma.next(), label=n)

    ax.set_ylabel('Value [um]', fontsize=12)
    ax.legend(loc=1, numpoints=1, framealpha=.7, bbox_to_anchor=(1.44, 1))
    ax.grid(which='both', lw=2)
    ax.set_title('[BPM] %s' % k)
    ax.xaxis.set_major_formatter(minFmt)

f.autofmt_xdate()

plt.show()


LHC.BOFSU:BPM_NAMES_V
	741	LHC.BOFSU:BPM_NAMES_V - BPM.7L4.B2
	742	LHC.BOFSU:BPM_NAMES_V - BPMYA.6L4.B2
	743	LHC.BOFSU:BPM_NAMES_V - BPMYB.5L4.B2
LHC.BOFSU:BPM_NAMES_H
	741	LHC.BOFSU:BPM_NAMES_H - BPM.7L4.B2
	742	LHC.BOFSU:BPM_NAMES_H - BPMYA.6L4.B2
	743	LHC.BOFSU:BPM_NAMES_H - BPMYB.5L4.B2


LHC.BOFSU:POSITIONS_V	: x: 330	y: (330, 1088)
	BPM.7L4.B2	: Mean = 283.926	Sigma = 7.240
	BPMYA.6L4.B2	: Mean = 128.585	Sigma = 7.594
	BPMYB.5L4.B2	: Mean = -421.907	Sigma = 7.618
LHC.BOFSU:POSITIONS_H	: x: 330	y: (330, 1088)
	BPM.7L4.B2	: Mean = -107.745	Sigma = 3.561
	BPMYA.6L4.B2	: Mean = 325.998	Sigma = 3.325
	BPMYB.5L4.B2	: Mean = 131.304	Sigma = 4.619

In [13]:
# Extrapolating @BGV
# BGV is after 5L4, 6L4 @-220m

for k, d in zip(bpm_n, bpm_d):
    for key in bpm.keys():
        if k in key:
            print("%s @ %s\t(%.1f, %.1f)" % (k, -d, bpm[key]['h'][0], bpm[key]['v'][0]))


.5L4.B2 @ -135.338	(131.3, -421.9)
.6L4.B2 @ -172.338	(326.0, 128.6)
.7L4.B2 @ -268.942	(-107.7, 283.9)

In [14]:
p1, p2, p3 = 'BPMYB.5L4.B2', 'BPMYA.6L4.B2', 'BPM.7L4.B2'

print('Extrapolating 5L4-6L4')
slope_h = (bpm[p2]['h'][0] - bpm[p1]['h'][0]) / (bpm_d[1] - bpm_d[0])
slope_v = (bpm[p2]['v'][0] - bpm[p1]['v'][0]) / (bpm_d[1] - bpm_d[0])

pos_h = np.rint(bpm[p2]['h'][0] + slope_h*(bgv_pos-bpm_d[1]))
pos_v = np.rint(bpm[p2]['v'][0] + slope_v*(bgv_pos-bpm_d[1]))
print('\t@BGV: (%d, %d) um' % (pos_h, pos_v))

print('Interpolating 6L4-7L4')
slope_h = (bpm[p3]['h'][0] - bpm[p2]['h'][0]) / (bpm_d[2] - bpm_d[1])
slope_v = (bpm[p3]['v'][0] - bpm[p2]['v'][0]) / (bpm_d[2] - bpm_d[1])

pos_h = np.rint(bpm[p2]['h'][0] + slope_h*(bgv_pos-bpm_d[1]))
pos_v = np.rint(bpm[p2]['v'][0] + slope_v*(bgv_pos-bpm_d[1]))
print('\t@BGV: (%d, %d) um' % (pos_h, pos_v))


Extrapolating 5L4-6L4
	@BGV: (577, 838) um
Interpolating 6L4-7L4
	@BGV: (112, 205) um

In [ ]: