Пример #1
0
def _calc_particle_info(bunch):
    from synergia.foundation import pconstants
    particle = bunch.particle
    particle_enums = get_enums(_SCHEMA, 'Particle')
    if particle == particle_enums.other:
        return
    mass = 0
    charge = 0
    if particle == particle_enums.proton:
        mass = pconstants.mp
        charge = pconstants.proton_charge
    # No antiprotons yet - commented out to avoid assertion error
    #elif particle == particle_enums.antiproton:
    #    mass = pconstants.mp
    #    charge = pconstants.antiproton_charge
    elif particle == particle_enums.electron:
        mass = pconstants.me
        charge = pconstants.electron_charge
    elif particle == particle_enums.positron:
        mass = pconstants.me
        charge = pconstants.positron_charge
    elif particle == particle_enums.negmuon:
        mass = pconstants.mmu
        charge = pconstants.muon_charge
    elif particle == particle_enums.posmuon:
        mass = pconstants.mmu
        charge = pconstants.antimuon_charge
    else:
        assert False, 'unknown particle: {}'.format(particle)
    bunch.mass = mass
    bunch.charge = charge
Пример #2
0
def _calc_bunch_parameters(bunch):
    bunch_def = bunch.beam_definition
    bunch_enums = get_enums(_SCHEMA, 'BeamDefinition')
    mom = foundation.Four_momentum(bunch.mass)
    _calc_particle_info(bunch)
    try:
        if bunch_def == bunch_enums.energy:
            mom.set_total_energy(bunch.energy)
        elif bunch_def == bunch_enums.momentum:
            mom.set_momentum(bunch.momentum)
        elif bunch_def == bunch_enums.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,
    }