<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:

def add_quantities(d, coords=None, massE=0.511e6):
    '''
    Add physically interesting quantities to
    pext data.

    Parameters:
    -----------
      d      : pext array

    Keywords:
    ---------
      coords : sequence of positions for angle calculation. None
               or by default, calculate no angles.
               For 2D, takes the angle depending on the order passed,
               so this can be used for left-handed coordinate systems
               like LSP's xz.
      massE  : rest mass energy of particles.
    Returns a copy with the quantities appended.
    '''
    keys,items = zip(*calc_quantities(d,coords=coords,massE=massE).items());
    return rfn.rec_append_fields(
        d, keys, items);