Esempio n. 1
0
def _import_bunch(lattice, data):
    from synergia.foundation import pconstants, Reference_particle, Four_momentum
    if not lattice.has_reference_particle():
        # create a default reference particle, proton,energy=1.5
        lattice.set_reference_particle(
            Reference_particle(pconstants.proton_charge,
                               Four_momentum(pconstants.mp, 1.5)))
    ref = lattice.get_reference_particle()
    bunch = data['models']['bunch']
    bunch['beam_definition'] = 'gamma'
    bunch['charge'] = ref.get_charge()
    four_momentum = ref.get_four_momentum()
    bunch['gamma'] = format_float(four_momentum.get_gamma())
    bunch['energy'] = format_float(four_momentum.get_total_energy())
    bunch['momentum'] = format_float(four_momentum.get_momentum())
    bunch['beta'] = format_float(four_momentum.get_beta())
    bunch['mass'] = format_float(four_momentum.get_mass())
    bunch['particle'] = 'other'
    if bunch['mass'] == pconstants.mp:
        if bunch['charge'] == pconstants.proton_charge:
            bunch['particle'] = 'proton'
        #TODO(pjm): antiproton (anti-proton) not working with synergia
    elif bunch['mass'] == pconstants.me:
        bunch['particle'] = 'positron' if bunch[
            'charge'] == pconstants.positron_charge else 'electron'
    elif bunch['mass'] == pconstants.mmu:
        bunch['particle'] = 'posmuon' if bunch[
            'charge'] == pconstants.antimuon_charge else 'negmuon'
Esempio n. 2
0
def _calc_bunch_parameters(bunch):
    from synergia.foundation import Four_momentum
    bunch_def = bunch['beam_definition']
    mom = Four_momentum(bunch['mass'])
    _calc_particle_info(bunch)
    try:
        if bunch_def == 'energy':
            mom.set_total_energy(bunch['energy'])
        elif bunch_def == 'momentum':
            mom.set_momentum(bunch['momentum'])
        elif bunch_def == 'gamma':
            mom.set_gamma(bunch['gamma'])
        else:
            assert False, 'invalid bunch def: {}'.format(bunch_def)
        bunch['gamma'] = format_float(mom.get_gamma())
        bunch['energy'] = format_float(mom.get_total_energy())
        bunch['momentum'] = format_float(mom.get_momentum())
        bunch['beta'] = format_float(mom.get_beta())
    except Exception as e:
        bunch[bunch_def] = ''
    return {
        'bunch': bunch,
    }
Esempio n. 3
0
def _calc_bunch_parameters(bunch):
    from synergia.foundation import Four_momentum
    bunch_def = bunch['beam_definition']
    mom = Four_momentum(bunch['mass'])
    _calc_particle_info(bunch)
    try:
        if bunch_def == 'energy':
            mom.set_total_energy(bunch['energy'])
        elif bunch_def == 'momentum':
            mom.set_momentum(bunch['momentum'])
        elif bunch_def == 'gamma':
            mom.set_gamma(bunch['gamma'])
        else:
            assert False, 'invalid bunch def: {}'.format(bunch_def)
        bunch['gamma'] = format_float(mom.get_gamma())
        bunch['energy'] = format_float(mom.get_total_energy())
        bunch['momentum'] = format_float(mom.get_momentum())
        bunch['beta'] = format_float(mom.get_beta())
    except Exception as e:
        bunch[bunch_def] = ''
    return {
        'bunch': bunch,
    }
Esempio n. 4
0
d = Lattice_element("quadrupole", "d")
d.set_double_attribute("l", quad_length)
d.set_double_attribute("k1", -strength)

# Define the fodo lattice itself, interpreting elements
# by their Mad8 definitions
lattice = Lattice("fodo", Mad8_adaptor_map())
# Add copies of the lattice elements to the fodo lattice
lattice.append(f)
lattice.append(o)
lattice.append(d)
lattice.append(o)

# Define a reference particle
total_energy = 1.5  # GeV
four_momentum = Four_momentum(pconstants.proton_mass, total_energy)
reference_particle = Reference_particle(pconstants.proton_charge,
                                        four_momentum)
lattice.set_reference_particle(reference_particle)

# Define a set of simulation steps
map_order = 1
steps_per_element = 2
stepper = Independent_stepper_elements(lattice, map_order, steps_per_element)

# Define a bunch
x_emit = 1.0e-6  # m-rad, RMS
y_emit = 1.0e-6  # m-rad, RMS
z_std = 0.01  # m
dpop = 1.0e-4  # unitless, RMS \frac{\delta p}{p_{tot}}
real_particles = 1.2e12  # unitless, meaningless in this simulation