Aligning photos taken at different focus distances to merge into a single extended Depth of Field image.

Panorama tools is particularly useful for this process since it allows
sub-pixel alignment and has a sophisticated lens correction model for
applying distortion - Even photos taken years apart with different cameras
can be aligned perfectly.

Most tools for HDR generation such as photomatix have some level of
automatic alignment, so this may be sufficient for most purposes. Otherwise the hdrprep perl script
automates the process described below:

Create a few hundred control points between each pair of consecutive photos with the g key in the control point tab.

Fine tune all points (available in the Edit menu)

Delete any control points with a correlation less than 90% (i.e. open the control point list (F3 or the Show Control Points icon in the toolbar), press the select by distance button, enter -0.9, and hit the delete button).

Optimise positions (ctrl-T), select points by distance again but this time enter 0.2. Optimise again.

Adjust the field-of view in the stitching tab to something slightly smaller than the input size so there are no transparent edges.