  Beam lifetime in storage rings and colliders is affected by, among other
effects, lattice nonlinearities. Their control are of great benefit to the
dynamic aperture of an accelerator, whose enlargement leads in general to more
efficient injection and longer lifetime. This article describes a procedure to
evaluate and correct unwanted nonlinearities by using turn-by-turn beam
position monitor data, which is an evolution of previous works on the resonance
driving terms (RDTs). Effective sextupole magnetic errors and tilts at the ESRF
electron storage ring are evaluated and corrected (when possible) by using this
technique. For the first time, also octupolar RDTs could be measured and used
to define an octupolar model for the main quadrupoles. Most of the deviations
from the model observed in the sextupolar RDTs of the ESRF storage ring turned
out to be generated by focusing errors rather than by sextupole errors. These
results could be achieved thanks to new analytical formulas describing the
harmonic content of the nonlinear betatron motion to the second order. For the
first time, RDTs have been also used for beam-based calibration of individual
sextupole magnets. They also proved to be a powerful tool in predicting faulty
magnets and in validating magnetic models. This technique provides also a
figure of merit for a self-assessment of the reliability of the data analysis.
