Esempio n. 1
0
def extract(infile, col_1, col_2, col_3=0):
    get = GetData(infile)
    data = get.data_column()
    turn = data[col_1]
    value = data[col_2]
    if col_3 == 0:
        return turn, value
    else:
        value_2 = data[col_3]
        return turn, value, value_2
Esempio n. 2
0
def extract(infile, col_1, col_2, col_3=0):
    get = GetData(infile)
    data = get.data_column()
    turn = data[col_1]
    value = data[col_2]
    if col_3 == 0:
        return turn, value
    else:
        value_2 = data[col_3]
        return turn, value, value_2
Esempio n. 3
0
def get_turns(infile):
    get = GetData(infile)
    data = get.data_column()
    x = np.asarray(data[0], dtype='float64')
    y = np.asarray(data[2], dtype='float64')
    if 'b1' in infile:
        name = txt.replace('b1.txt', '').upper()
    elif 'b2' in infile:
        name = txt.replace('b2.txt', '').upper()
    elif infile == 'data_turn.txt':
        name = 'Collimation system'
    return x, y, name
Esempio n. 4
0
def get_turns(infile):
    get = GetData(infile)
    data = get.data_column()
    x = np.asarray(data[0], dtype='float64')
    y = np.asarray(data[2], dtype='float64')
    if 'b1' in infile:
        name = txt.replace('b1.txt', '').upper()
    elif 'b2' in infile:
        name = txt.replace('b2.txt', '').upper()
    elif infile == 'data_turn.txt':
        name = 'Collimation system'
    return x, y, name
Esempio n. 5
0
def get_data(infile):
    get = GetData(infile)
    data = get.data_column()

    x  = np.asarray(data[0])
    xp = data[1]
    y  = data[2]
    yp = data[3]

    sigma_x = np.std(x)
    sigma_y = np.std(y)
    mu, std = norm.fit(x)
    return sigma_x, sigma_y, mu, std, x, y
Esempio n. 6
0
def get_data(infile):
    get = GetData(infile)
    data = get.data_column()

    x = np.asarray(data[0])
    xp = data[1]
    y = data[2]
    yp = data[3]

    sigma_x = np.std(x)
    sigma_y = np.std(y)
    mu, std = norm.fit(x)
    return sigma_x, sigma_y, mu, std, x, y
Esempio n. 7
0
def get_ap(infile):
    if os.stat(infile).st_size == 0:
        print '>> ' + infile  + ' file is empty'
        return 0
    else:
        get         = GetData(infile)
        data        = get.data_column(dtype='string')
        name        = data[0]
        s           = np.asarray(data[1], dtype='float64')
        l           = np.asarray(data[2], dtype='float64')
        aper1       = np.asarray(data[3], dtype='float64')
        aper2       = np.asarray(data[4], dtype='float64')
        aper3       = np.asarray(data[5], dtype='float64')
        aper4       = np.asarray(data[6], dtype='float64')
        apertype    = np.asarray(data[7])
    return name, s, l, aper1, aper2, aper3, aper4, apertype
Esempio n. 8
0
def get_ap(infile):
    if os.stat(infile).st_size == 0:
        print '>> ' + infile + ' file is empty'
        return 0
    else:
        get = GetData(infile)
        data = get.data_column(dtype='string')
        name = data[0]
        s = np.asarray(data[1], dtype='float64')
        l = np.asarray(data[2], dtype='float64')
        aper1 = np.asarray(data[3], dtype='float64')
        aper2 = np.asarray(data[4], dtype='float64')
        aper3 = np.asarray(data[5], dtype='float64')
        aper4 = np.asarray(data[6], dtype='float64')
        apertype = np.asarray(data[7])
    return name, s, l, aper1, aper2, aper3, aper4, apertype
Esempio n. 9
0
def get_twiss(infile):
    if os.stat(infile).st_size == 0:
        print '>> ' + infile  + ' file is empty'
        return 0
    else:
        get     = GetData(infile)
        data    = get.data_column(dtype='string')
        name    = data[1]
        s       = np.asarray(data[2])
        l       = np.asarray(data[3])
        x       = np.asarray(data[4])
        y       = np.asarray(data[5])
        betx    = np.asarray(data[6])
        bety    = np.asarray(data[7])
        alfx    = np.asarray(data[8])
        alfy    = np.asarray(data[9])
        dx      = np.asarray(data[12])
        dy      = np.asarray(data[13])
        px      = np.asarray(data[16])
        py      = np.asarray(data[17])

    return name, s, l, x, y, betx, bety, alfx, alfy, dx, dy, px, py
Esempio n. 10
0
def get_twiss(infile):
    if os.stat(infile).st_size == 0:
        print '>> ' + infile + ' file is empty'
        return 0
    else:
        get = GetData(infile)
        data = get.data_column(dtype='string')
        name = data[1]
        s = np.asarray(data[2])
        l = np.asarray(data[3])
        x = np.asarray(data[4])
        y = np.asarray(data[5])
        betx = np.asarray(data[6])
        bety = np.asarray(data[7])
        alfx = np.asarray(data[8])
        alfy = np.asarray(data[9])
        dx = np.asarray(data[12])
        dy = np.asarray(data[13])
        px = np.asarray(data[16])
        py = np.asarray(data[17])

    return name, s, l, x, y, betx, bety, alfx, alfy, dx, dy, px, py
Esempio n. 11
0
#!/usr/bin/env python
import sys

from util import GetData

infile = sys.argv[1]

data = GetData(infile).data_column(dtype='string')
name = data['NAME']
mux  = data['MUX']
muy  = data['MUY']
betx = data['BETX']
bety = data['BETY']
alfx = data['ALFX']
alfy = data['ALFY']
s    = data['S']

outfile = 'crab_installation.txt'

with open(outfile, 'w') as f:
    for n, ss, mx, my, bx, by, ax, ay in zip(name, s, mux, muy, betx, bety, alfx, alfy):
        if n.startswith('ACF'):
            print >> f, n, ss, mx, my, bx, by, ax, ay
Esempio n. 12
0
# Constants
# --------------------------------------------------------------------
m_p = 938.272046e6  # Proton mass [eV/c^2]
c = 299792458  # Speed of light [m/s]
gamma_rel = energy/m_p  # Relativistic gamma
beta_rel = np.sqrt(1-(1/gamma_rel**2))  # Relativistic beta
emittance_geom = emittance_norm/(beta_rel*gamma_rel)
sigma_x = np.sqrt(emittance_geom*beta_x)
sigma_y = np.sqrt(emittance_geom*beta_y)

with open(outfile,'w') as f:
    for item in os.listdir(rootdir):
        if os.path.isdir(item):
            infile = os.path.join(os.path.join(rootdir, item), 'dump.txt')
            phase = int(item.strip('job_'))
        get = GetData(infile)
        data_dict = get.data_column(column=0, regex=r'1\b')
        for turn, x, xp, y, yp in zip(data_dict[1], data_dict[3], data_dict[4], data_dict[5], data_dict[6]):
            x = float(data_dict[3])*1e-3
            xp = float(data_dict[4])*1e-3
            y = float(data_dict[5])*1e-3
            yp = float(data_dict[6])*1e-3
            # Sigma matrix for X
            term_1_x = mean(np.multiply(x,x)) - np.multiply(mean(x), mean(x))
            term_2_x = mean(np.multiply(x,xp)) - np.multiply(mean(x),mean(xp))
            term_3_x = mean(np.multiply(xp,x)) - np.multiply(mean(xp), mean(x))
            term_4_x = mean(np.multiply(xp,xp)) - np.multiply(mean(xp),mean(xp))
            # Sigma matrix for Y
            term_1_y = mean(np.multiply(y,y)) - np.multiply(mean(y), mean(y))
            term_2_y = mean(np.multiply(y,yp)) - np.multiply(mean(y),mean(yp))
            term_3_y = mean(np.multiply(yp,y)) - np.multiply(mean(yp), mean(y))
Esempio n. 13
0
def get_dist(data_file, dir_core, dir_tail, core_weight, tail_weight):

    if data_file == 'loss_maps.txt':
        col_1 = 1
        col_2 = 3
    elif data_file == 'aperture.txt':
        col_1 = 0
        col_2 = 2

    x = []
    y = []
    if os.path.isfile(dir_core + '/' + data_file) and os.path.isfile(dir_tail + '/' + data_file):
        print ' '
        print '>> File ' + data_file + ' present for core and tail'

        get_core = GetData(dir_core + '/' + data_file)
        data_core = get_core.data_column(dtype='string')
        xc_coll = data_core[col_1]
        yc_coll = data_core[col_2]

        get_tail = GetData(dir_tail + '/' + data_file)
        data_tail = get_tail.data_column(dtype='string')
        xt_coll = data_tail[col_1]
        yt_coll = data_tail[col_2]

        for i, k in zip(xc_coll, yc_coll):
            for j, l in zip(xt_coll, yt_coll):
                if i == j:

                    x.append(float(i))
                    y.append(core_weight * float(k) + tail_weight * float(l))
                    xc_coll.remove(i)
                    yc_coll.remove(k)
                    xt_coll.remove(j)
                    yt_coll.remove(l)

        for i, k in zip(xc_coll, yc_coll):
            x.append(float(i))
            y.append(core_weight * float(k))
        for j, l in zip(xt_coll, yt_coll):
            x.append(float(j))
            y.append(tail_weight * float(l))

    elif os.path.isfile(dir_core + '/' + data_file) == False:
        print ' '
        print '>> File ' + data_file + ' present only for tail'

        get_tail = GetData(dir_tail + '/' + data_file)
        data_tail = get_tail.data_column(dtype='string')
        xt_coll = data_tail[col_1]
        yt_coll = data_tail[col_2]
        for j, l in zip(xt_coll, yt_coll):
            x.append(float(j))
            y.append(tail_weight * float(l))

    elif os.path.isfile(dir_tail + '/' + data_file) == False:
        print ' '
        print '>> File ' + data_file + ' present only for core'

        get_core = GetData(dir_core + '/' + data_file)
        data_core = get_core.data_column(dtype='string')
        xc_coll = data_core[col_1]
        yc_coll = data_core[col_2]
        for j, l in zip(xc_coll, yc_coll):
            x.append(float(j))
            y.append(core_weight * float(l))
    return x, y
Esempio n. 14
0
#!/usr/bin/env python

import subprocess

import numpy as np

from util import GetData

infile = 'seed_old.txt'
get = GetData(infile)
data = get.data_column(dtype='string')
seed = data[3]
jobs = range(1, 500 + 1)

for i, j in zip(seed, jobs):
    subprocess.call([
        'generate_distribution.py', '19968', '7e12', 'HL_coll', 'False', '1',
        '0.9', '2.5e-6', '2.5e-6', '0.003485', '-0.000764', '0.150739',
        '0.150235', '-7.5e-4', '0', '0', '295e-6', '0.003652', '0.000517',
        '0.0755', '1.13e-4', i
    ])
    subprocess.Popen(['rename.sh %s' % j], shell=True)
Esempio n. 15
0
#!/usr/bin/env python

import subprocess

import numpy as np

from util import GetData

infile = 'seed_old.txt'
get  = GetData(infile)
data = get.data_column(dtype='string')
seed = data[3]
jobs = range(1, 500 + 1)

for i, j in zip(seed, jobs):
    subprocess.call(['generate_distribution.py','19968','7e12','HL_coll','False', '1','0.9','2.5e-6','2.5e-6','0.003485','-0.000764','0.150739','0.150235','-7.5e-4','0','0','295e-6','0.003652','0.000517','0.0755','1.13e-4',i])
    subprocess.Popen(['rename.sh %s' % j], shell=True)
Esempio n. 16
0
import numpy as np
import matplotlib
from matplotlib import pyplot as plt
from matplotlib import rc
from matplotlib import rcParams

from util import GetData

# ------------------------------------------------------------------------------
# Constant voltage data loading
# ------------------------------------------------------------------------------
infile = sys.argv[1]
# title = sys.argv[2]

get = GetData(infile)
data = get.data_column()

turns = np.asarray(data[0], dtype='float64')
dx = np.asarray(data[1], dtype='float64')
dy = np.asarray(data[2], dtype='float64')
cx = np.asarray(data[3], dtype='float64')
cy = np.asarray(data[4], dtype='float64')

# ------------------------------------------------------------------------------
# PLOTTING
# ------------------------------------------------------------------------------
DPI = 500
textwidth = 3.25
font_spec = {
    "font.family": "serif",  # use as default font
Esempio n. 17
0
term_3_y = np.zeros(total_turns)
term_4_y = np.zeros(total_turns)

det_x = np.zeros(total_turns)
em_x = np.zeros(total_turns)

det_y = np.zeros(total_turns)
em_y = np.zeros(total_turns)

mean_x = np.zeros(total_turns)
mean_y = np.zeros(total_turns)

# ------------------------------------------------------------------------------
# Extraction and treatment of data
# ------------------------------------------------------------------------------
get = GetData(infile)
data = get.data_column()

turns = data[1]
x_tot = data[3]
xp_tot = data[4]
y_tot = data[5]
yp_tot = data[6]
z_tot = data[7]
e_tot = data[8]

tset=list(set(turns))

def get_turns(coord, turns):
    d = {}
    for t in set(turns):
Esempio n. 18
0
def get_dist(data_file, dir_core, dir_tail, core_weight, tail_weight):

    if data_file == 'loss_maps.txt':
        col_1 = 1
        col_2 = 3
    elif data_file == 'aperture.txt':
        col_1 = 0
        col_2 = 2

    x = []
    y = []
    if os.path.isfile(dir_core + '/' +
                      data_file) and os.path.isfile(dir_tail + '/' +
                                                    data_file):
        print ' '
        print '>> File ' + data_file + ' present for core and tail'

        get_core = GetData(dir_core + '/' + data_file)
        data_core = get_core.data_column(dtype='string')
        xc_coll = data_core[col_1]
        yc_coll = data_core[col_2]

        get_tail = GetData(dir_tail + '/' + data_file)
        data_tail = get_tail.data_column(dtype='string')
        xt_coll = data_tail[col_1]
        yt_coll = data_tail[col_2]

        for i, k in zip(xc_coll, yc_coll):
            for j, l in zip(xt_coll, yt_coll):
                if i == j:

                    x.append(float(i))
                    y.append(core_weight * float(k) + tail_weight * float(l))
                    xc_coll.remove(i)
                    yc_coll.remove(k)
                    xt_coll.remove(j)
                    yt_coll.remove(l)

        for i, k in zip(xc_coll, yc_coll):
            x.append(float(i))
            y.append(core_weight * float(k))
        for j, l in zip(xt_coll, yt_coll):
            x.append(float(j))
            y.append(tail_weight * float(l))

    elif os.path.isfile(dir_core + '/' + data_file) == False:
        print ' '
        print '>> File ' + data_file + ' present only for tail'

        get_tail = GetData(dir_tail + '/' + data_file)
        data_tail = get_tail.data_column(dtype='string')
        xt_coll = data_tail[col_1]
        yt_coll = data_tail[col_2]
        for j, l in zip(xt_coll, yt_coll):
            x.append(float(j))
            y.append(tail_weight * float(l))

    elif os.path.isfile(dir_tail + '/' + data_file) == False:
        print ' '
        print '>> File ' + data_file + ' present only for core'

        get_core = GetData(dir_core + '/' + data_file)
        data_core = get_core.data_column(dtype='string')
        xc_coll = data_core[col_1]
        yc_coll = data_core[col_2]
        for j, l in zip(xc_coll, yc_coll):
            x.append(float(j))
            y.append(core_weight * float(l))
    return x, y
Esempio n. 19
0
        plot_ip_labels(b2, height, text_size)
    else:
        print '>> Please input B1 or B2 as first argument'

    plt.subplots_adjust(left=0.16, bottom=0.19, right=0.94, top=0.88)
    plt.savefig('loss_map.png', dpi=1000)
    plt.savefig('loss_map.eps', format='eps', dpi=1000)
    plt.clf()

elif len(sys.argv) == 2:
    files = glob.glob('*.txt')
    for txt in files:
        if txt == 'loss_maps.txt':
            print ' '
            print '>> File ' + txt + ' present'
            get = GetData(txt)
            data = get.data_column(dtype='string')
            x_coll = np.asarray(data[1], dtype='float64')
            y_coll = np.asarray(data[3], dtype='float64')
        elif txt == 'aperture.txt':
            print ' '
            print '>> File ' + txt + ' present'
            get = GetData(txt)
            data = get.data_column(dtype='string')
            x_ap = np.asarray(data[0], dtype='float64')
            y_ap = np.asarray(data[2], dtype='float64')
    # ------------------------------------------------------------------------------
    # Plotting lossmaps
    # ------------------------------------------------------------------------------
    if os.path.exists('loss_maps.txt') == False and os.path.exists(
            'aperture.txt') == False:
Esempio n. 20
0
from util import GetData

get = GetData('data.txt')
# Turn 6, 8, 15


def get_tau(tau):
    data = get.data_column(column=0, regex=tau)
    return data[0], data[1], data[2], data[8]


tau_1, phase_1, turn_1, sigy_1 = get_tau(r'1')
tau_2, phase_2, turn_2, sigy_2 = get_tau(r'2')
tau_3, phase_3, turn_3, sigy_3 = get_tau(r'3')
tau_4, phase_4, turn_4, sigy_4 = get_tau(r'4')

max_1 = '217'
max_2 = '359'
max_3 = '359'
max_4 = '359'

for tau, phase, turn, sigy in zip(tau_1, phase_1, turn_1, sigy_1):
    if int(turn) == 1:
        offset = sigy
    if phase == max_1 and turn == '6':
        print float(sigy) - float(offset), tau, phase
    if phase == max_1 and turn == '8':
        print float(sigy) - float(offset), tau, phase
    if phase == max_1 and turn == '10':
        print float(sigy) - float(offset), tau, phase
Esempio n. 21
0
#!/usr/bin/env python
import sys

import numpy as np
from matplotlib import pyplot as plt
from matplotlib import rc
from matplotlib import rcParams

from util import GetData

infile_before = 'before.txt'
get_before = GetData(infile_before)
my_data_before = get_before.data_column(column=1, regex=r'2\b')
yp_before = my_data_before[6]
z_before = my_data_before[7]
delta_before = my_data_before[8]

infile_after = 'after.txt'
get_after = GetData(infile_after)
my_data_after = get_after.data_column(column=1, regex=r'2\b')
yp_after = my_data_after[6]
z_after = my_data_after[7]
delta_after = my_data_after[8]

y = []
x = []
for a, b, c, d, e, f in zip(yp_before, delta_before, z_before, yp_after,
                            delta_after, z_after):
    term_1 = d / (1 + e)
    term_2 = a / (1 + b)
    y.append((term_1 - term_2) * 7 * 1e12)
Esempio n. 22
0
# Constants
# --------------------------------------------------------------------
m_p = 938.272046e6  # Proton mass [eV/c^2]
c = 299792458  # Speed of light [m/s]
gamma_rel = energy / m_p  # Relativistic gamma
beta_rel = np.sqrt(1 - (1 / gamma_rel ** 2))  # Relativistic beta
emittance_geom = emittance_norm / (beta_rel * gamma_rel)
sigma_x = np.sqrt(emittance_geom * beta_x)
sigma_y = np.sqrt(emittance_geom * beta_y)

with open(outfile, "w") as f:
    for item in os.listdir(rootdir):
        if os.path.isdir(item):
            infile = os.path.join(os.path.join(rootdir, item), "dump.txt")
            phase = int(item.strip("job_"))
        get = GetData(infile)
        data_dict = get.data_column(column=0, regex=r"1\b")
        for turn, x, xp, y, yp in zip(data_dict[1], data_dict[3], data_dict[4], data_dict[5], data_dict[6]):
            x = float(data_dict[3]) * 1e-3
            xp = float(data_dict[4]) * 1e-3
            y = float(data_dict[5]) * 1e-3
            yp = float(data_dict[6]) * 1e-3
            # Sigma matrix for X
            term_1_x = mean(np.multiply(x, x)) - np.multiply(mean(x), mean(x))
            term_2_x = mean(np.multiply(x, xp)) - np.multiply(mean(x), mean(xp))
            term_3_x = mean(np.multiply(xp, x)) - np.multiply(mean(xp), mean(x))
            term_4_x = mean(np.multiply(xp, xp)) - np.multiply(mean(xp), mean(xp))
            # Sigma matrix for Y
            term_1_y = mean(np.multiply(y, y)) - np.multiply(mean(y), mean(y))
            term_2_y = mean(np.multiply(y, yp)) - np.multiply(mean(y), mean(yp))
            term_3_y = mean(np.multiply(yp, y)) - np.multiply(mean(yp), mean(y))
Esempio n. 23
0
# ------------------------------------------------------------------------------
sixtrack_particle_limit = 19968
turns = int(sys.argv[2])
simulated_particles = int(sys.argv[1]) * sixtrack_particle_limit
beam = sys.argv[3]

print ' '
print 'Number of simulated particles: ', simulated_particles, '(100 %)'
if not os.path.exists('tot/' + str(simulated_particles)):
    os.makedirs('tot/' + str(simulated_particles))

# ------------------------------------------------------------------------------
# Associating name with collimator ID
# ------------------------------------------------------------------------------
infile_2 = 'coll_summary.dat'
get_2 = GetData(infile_2)
get_2 = GetData(infile_2)
data_2 = get_2.data_column(dtype='string')

names_2 = data_2[1]
numbers = data_2[0]

numbers_dict = {}
for i in range(len(names_2)):
    numbers_dict[float(numbers[i])] = names_2[i]

# ------------------------------------------------------------------------------
# Associating name with position
# ------------------------------------------------------------------------------
if beam == 'B1':
    infile_3 = 'CollPositionsHL.b1.dat'