Beispiel #1
0
###############################################################################
# extraction section
last_z = beam[it_z, 0, :]
last_itz = it_z

for i in range(0, nb_part):
    it_z = last_itz

    [beam, it_z] = transport_input('transport_file_ESS.txt',
                                   beam,
                                   refE,
                                   i,
                                   N_segments,
                                   gap,
                                   k1,
                                   k2,
                                   last_z,
                                   last_itz,
                                   Brho_factor,
                                   kill_lost_particles,
                                   gap_X=gapX,
                                   paraxial_correction=paraxial_correction,
                                   dpz_tolerance=dpzTolerance)

E_list_in = np.vectorize(PtoE)(ref_p * (1 + beam[0, 6, :]))
DeltaE = refE / 100
nb_part_in_ESS = ((E_list_in < refE + DeltaE) &
                  (E_list_in > refE - DeltaE)).sum()
nb_part_in_ESS2 = ((E_list_in < refE + 2 * DeltaE) &
                   (E_list_in > refE - 2 * DeltaE)).sum()
Beispiel #2
0
#Gaussian_fit(beam[it_z,4,:],[30., 0., 0.001])

##################################################################
# GTR

input_file = "D:/beamline/transport/Transport code/inputs/GTR 3T magnets double achromat after buncher.txt"

gap = 0.03
k1 = 0.7
k2 = 0

last_itz = it_z

for i in range(0, nb_part):
    it_z = last_itz
    [beam, it_z] = transport_input(input_file, beam, refE, i, N_segments, gap,
                                   k1, k2, beam[it_z, 0, 0], it_z)
    L = 0.1
    [beam[:, :, i], it_z] = collimator(L, 0.02, 'tantalum', beam[:, :, i],
                                       it_z, 10, refE)
    L = 0.1
    [beam[:, :, i], it_z] = drift(L, beam[:, :, i], refE, it_z, 1)

plt.figure(10)
plt.plot(beam[0:it_z, 0, :], beam[0:it_z, 1, :])
plt.title('X')
plt.ylim((-0.05, 0.05))
plt.grid(which='major')
plt.figure(11)
plt.plot(beam[0:it_z, 0, :], beam[0:it_z, 3, :])
plt.title('Y')
plt.ylim((-0.05, 0.05))
Beispiel #3
0
    #    #divX = 0.01
    #    #divY = 0.01

    p = EtoP(E)
    dponp = (p - ref_p) / ref_p
    beam[0, :, i] = np.array([z, sizeX, divX, sizeY, divY, 0, dponp])

###############################################################################
# extraction section
last_z = beam[it_z, 0, :]
last_itz = it_z

for i in range(0, nb_part):
    it_z = last_itz
    [beam, it_z] = transport_input('transport_file_ESS.txt', beam, refE, i,
                                   N_segments, gap, k1, k2, last_z, last_itz,
                                   Brho_factor, kill_lost_particles)

E_list_in = np.vectorize(PtoE)(ref_p * (1 + beam[0, 6, :]))
DeltaE = refE / 100
nb_part_in_ESS = ((E_list_in < refE + DeltaE) &
                  (E_list_in > refE - DeltaE)).sum()
nb_part_in_ESS2 = ((E_list_in < refE + 2 * DeltaE) &
                   (E_list_in > refE - 2 * DeltaE)).sum()

E_list_out_ESS = np.vectorize(PtoE)(ref_p * (1 + beam[it_z, 6, :]))
E_list_out_ESS[np.isnan(E_list_out_ESS)] = 0

nb_part_out_ESS = ((E_list_out_ESS < refE + DeltaE) &
                   (E_list_out_ESS > refE - DeltaE)).sum()
Beispiel #4
0
def run_from_transport(input_file = "C:/TRANS/for001.dat", nb_part=1000, \
                       N_segments = 10, kill_lost_particles = True, \
                       refE = 160, old_refE = 160, DeltaE=0, E_dist='uniform',  \
                       DeltaX = 10**-5, DeltaY = 10**-5, size_dist='cst', \
                       DeltaDivX = 0.05, DeltaDivY = 0.05, div_dist='uniform', \
                       gap = 0.03, k1 = 0.5, k2 = 0, \
                       paraxial_correction = False, dpzTolerance = 10**-4, \
                       plot_results = True, output_results=True):
    """
    Compute trajectories of protons in beamline defined in the Transport file 'input_file'
    
    Definition of inputs:
        
    input_file = Transport input file.
    nb_part = number of particles to generate
    N_segments = number of points that represent the particle trajectory in each magnet
    kill_lost_particles = boolean to determine if paticle trajectories are stopped when they hit an element in the beamline
    refE = reference energy of the particle
    old_refE = reference energy in the Transport file (in case magnetic fields need to be scaled)
    E_dist = Statistical distribution of particle energies (uniform', 'normal' or 'cst')
    DeltaX = beam extention in X plane
    DeltaY = beam extention in Y plane
    size_dist = Statistical distribution of the beam size (uniform', 'normal' or 'cst')
    DeltaDivX = divergence in X plane
    DeltaDivY = divergence in Y plane
    div_dist = Statistical distribution of the beam divergence (uniform', 'normal' or 'cst')
    gap = vertical gap of dipoles (useful if kill_lost_particles = True)
    k1, k2 = fringe field parameters (see Transport manual)
    paraxial_correction = Boolean to correct the effective field for diverging particles (increases computation time)
    dpzTolerance = tolerance on normalized magnetic field in paraxial correction
    plot_results = boolean 
    output_results = boolean
    
    
    Definition of outputs:
        
    sigmaX, sigmaY = spot size at isocenter
    eff_ESS_dEonE_1pc, eff_GTR_dEonE_1pc = ESS and GTR effieciency for a dE/E=1% (if DeltaE high enough in input)    
    """

    split_transport_file(input_file)

    ref_p = EtoP(refE)
    #Brho  = 1/300*sqrt(refE**2+2*938*refE)

    Brho_factor = Brho_scaling(old_refE, refE)

    gapX = gap  # case of CCT magnets

    ########################################

    nb_pts_z = transport_count_lines(input_file, N_segments)

    ###############################################################################
    # initial conditions

    beam = np.empty(shape=[nb_pts_z, 7, nb_part])

    for i in range(0, nb_part):

        # initialize particle properties

        z = 0
        it_z = 0

        if size_dist == 'uniform':
            sizeX = DeltaX * np.random.uniform(-1, 1)
            sizeY = DeltaY * np.random.uniform(-1, 1)
        elif size_dist == 'normal':
            sizeX = DeltaX * np.random.normal(0, 1)
            sizeY = DeltaY * np.random.normal(0, 1)
        elif size_dist == 'cst':
            sizeX = DeltaX * (i - nb_part / 2) / nb_part * 2
            sizeY = DeltaY * (i - nb_part / 2) / nb_part * 2
        else:
            raise Exception('Distribution chosen for "size_dist" is not valid')

        if div_dist == 'uniform':
            divX = DeltaDivX * np.random.uniform(-1, 1)
            divY = DeltaDivY * np.random.uniform(-1, 1)
        elif div_dist == 'normal':
            divX = DeltaDivX * np.random.normal(0, 1)
            divY = DeltaDivY * np.random.normal(0, 1)
        elif div_dist == 'cst':
            divX = DeltaDivX * (i - nb_part / 2) / nb_part * 2
            divY = DeltaDivY * (i - nb_part / 2) / nb_part * 2
        else:
            raise Exception('Distribution chosen for "div_dist" is not valid')

        if E_dist == 'uniform':
            E = refE + DeltaE * np.random.uniform(-1, 1)
        elif E_dist == 'normal':
            E = refE + DeltaE * np.random.normal(0, 1)
        elif E_dist == 'cst':
            E = refE + DeltaE * (i - nb_part / 2) / nb_part * 2
        else:
            raise Exception('Distribution chosen for "E_dist" is not valid')

        p = EtoP(E)
        dponp = (p - ref_p) / ref_p
        beam[0, :, i] = np.array([z, sizeX, divX, sizeY, divY, 0, dponp])

    ###############################################################################
    # extraction section
    last_z = beam[it_z, 0, :]
    last_itz = it_z

    for i in range(0, nb_part):
        it_z = last_itz

        [beam, it_z] = transport_input('transport_file_ESS.txt',
                                       beam,
                                       refE,
                                       i,
                                       N_segments,
                                       gap,
                                       k1,
                                       k2,
                                       last_z,
                                       last_itz,
                                       Brho_factor,
                                       kill_lost_particles,
                                       gap_X=gapX,
                                       paraxial_correction=paraxial_correction,
                                       dpz_tolerance=dpzTolerance)

    E_list_in = np.vectorize(PtoE)(ref_p * (1 + beam[0, 6, :]))
    dEonE_1pc = refE / 100
    nb_part_in_ESS_dEonE1pc = ((E_list_in < refE + dEonE_1pc) &
                               (E_list_in > refE - dEonE_1pc)).sum()
    nb_part_in_ESS_dEonE2pc = ((E_list_in < refE + 2 * dEonE_1pc) &
                               (E_list_in > refE - 2 * dEonE_1pc)).sum()

    E_list_out_ESS = np.vectorize(PtoE)(ref_p * (1 + beam[it_z, 6, :]))
    E_list_out_ESS[np.isnan(E_list_out_ESS)] = 0

    nb_part_out_ESS_dEonE1pc = ((E_list_out_ESS < refE + dEonE_1pc) &
                                (E_list_out_ESS > refE - dEonE_1pc)).sum()

    ###############################################################################
    # gantry section
    last_z = beam[it_z, 0, :]
    last_itz = it_z
    it_z_GTR = it_z

    for i in range(0, nb_part):
        it_z = last_itz
        [beam, it_z] = transport_input('transport_file_GTR.txt',
                                       beam,
                                       refE,
                                       i,
                                       N_segments,
                                       gap,
                                       k1,
                                       k2,
                                       last_z,
                                       last_itz,
                                       Brho_factor,
                                       kill_lost_particles,
                                       gap_X=gapX,
                                       dpz_tolerance=dpzTolerance)

    # make plots
    if plot_results:
        [sigmaX, sigmaY] = plot_beam(input_file, beam, it_z, it_z_GTR, ref_p)
    else:
        [sigmaX, sigmaY] = get_spot_size(it_z, beam)

    # output results
    if output_results:

        eff_ESS_dEonE_1pc = nb_part_out_ESS_dEonE1pc / max(
            nb_part_in_ESS_dEonE1pc, 1) * 100
        print('ESS efficiency within E range [ %0.2f , %0.2f ] = %0.2f %%' %
              (refE - dEonE_1pc, refE + dEonE_1pc, eff_ESS_dEonE_1pc))

        E_list_out_GTR = np.vectorize(PtoE)(ref_p * (1 + beam[it_z, 6, :]))
        E_list_out_GTR[np.isnan(E_list_out_GTR)] = 0

        nb_part_out_GTR_dEonE1pc = ((E_list_out_GTR < refE + dEonE_1pc) &
                                    (E_list_out_GTR > refE - dEonE_1pc)).sum()

        eff_GTR_dEonE_1pc = nb_part_out_GTR_dEonE1pc / max(
            nb_part_out_ESS_dEonE1pc, 1) * 100

        print('GTR efficiency within E range [ %0.2f , %0.2f ] = %0.2f %%' %
              (refE - dEonE_1pc, refE + dEonE_1pc, eff_GTR_dEonE_1pc))
        print('Total efficiency within E range [ %0.2f , %0.2f ] = %0.2f %%' %
              (refE - dEonE_1pc, refE + dEonE_1pc, nb_part_out_GTR_dEonE1pc /
               max(nb_part_in_ESS_dEonE1pc, 1) * 100))

        nb_part_out_GTR_dEonE2pc = (
            (E_list_out_GTR < refE + 2 * dEonE_1pc) &
            (E_list_out_GTR > refE - 2 * dEonE_1pc)).sum()
        eff_tot_dEonE_2pc = nb_part_out_GTR_dEonE2pc / max(
            nb_part_in_ESS_dEonE2pc, 1) * 100

        print('Total efficiency within E range [ %0.2f , %0.2f ] = %0.2f %%' %
              (refE - 2 * dEonE_1pc, refE + 2 * dEonE_1pc, eff_tot_dEonE_2pc))

    return [sigmaX, sigmaY, eff_ESS_dEonE_1pc, eff_GTR_dEonE_1pc]
Beispiel #5
0
    divY = 0.05 * np.random.choice([-1, 0, 1])
    E = 160 + 3 * np.random.normal(0, 1)
    E = 160 + 10 * np.random.choice([-1, 0, 1])

    #divX = 0.05*np.random.choice([-1,0,1])
    #divY = 0.05*np.random.choice([-1,0,1])
    #divX = 0.05
    #divY = 0.05

    #E = 160
    p = EtoP(E)
    dponp = (p - ref_p) / ref_p
    beam[0, :, i] = np.array([z, .00001, divX, .00001, divY, 0, dponp])

    it_z = 0

    beam = transport_input(input_file, beam, refE, i, N_segments)

plt.figure(0)
plt.plot(beam[0:nb_pts_z, 0, :], beam[0:nb_pts_z, 1, :])
plt.title('X')
plt.grid(which='major')
plt.figure(1)
plt.plot(beam[0:nb_pts_z, 0, :], beam[0:nb_pts_z, 3, :])
plt.title('Y')
plt.grid(which='major')

plt.figure(3)
plt.hist(beam[it_z - 1, 5, :], 20, alpha=0.5, label="dL")
plt.legend(loc='upper right')