  Allpix$^2$ (read: Allpix Squared) is a generic, open-source software
framework for the simulation of silicon pixel detectors. Its goal is to ease
the implementation of detailed simulations for both single detectors and more
complex setups such as beam telescopes from incident radiation to the digitised
detector response. Predefined detector types can be automatically constructed
from simple model files describing the detector parameters.
  The simulation chain is arranged with the help of intuitive configuration
files and an extensible system of modules, which implement separate simulation
steps such as realistic charge carrier deposition with the Geant4 toolkit or
propagation of charge carriers in silicon using a drift-diffusion model.
Detailed electric field maps imported from TCAD simulations can be used to
precisely model the drift behaviour of charge carriers within the silicon,
bringing a new level of realism to Monte Carlo based simulations of particle
detectors.
  This paper provides an overview of the framework and a selection of different
simulation modules, and presents a comparison of simulation results with test
beam data recorded with hybrid pixel detectors. Emphasis is placed on the
performance of the framework itself, using a first-principles simulation of the
detectors without addressing secondary ASIC-specific effects.
