State-of-the-art data-acquisition systems for positron emission tomography (PET) block detectors use anger logic to determine preliminary 2-D coordinates of the detection location within the block. Typically, a crystal lookup table (CLT) is then used to map from this position to the index of the crystal in which the particle was actually absorbed. Depending on the complexity of the detector design, it is difficult to calculate these CLTs automatically without need for visual inspection and manual readjustment. We propose a novel technique to construct the CLT. The assignment problem is formulated as an optimization problem, where the number of free parameters is initially twice the number of crystals in the block. The core idea is to reduce the dimension of the search space by principal component analysis. The technique was tested successfully for three different block detector designs (Siemens ECAT Exact HR, Siemens microPET Focus 220, and a prototype block detector built of pixelated lutetium oxyorthosilicate crystals with avalanche photodiodes attached). Important virtues of the new algorithm are very fast processing and a high tolerance toward missing peaks, fused peaks, and nonlinear distortions. Furthermore, the algorithm calculates a performance control value that can be used to quickly identify problematic blocks.