  PINOCCHIO (PINpointing Orbit-Crossing Collapsed Hierarchical Objects) is a
new algorithm for identifying dark matter halos in a given numerical
realisation of the linear density field in a hierarchical universe (Monaco et
al. 2001). It is shown that Lagrangian perturbation theory, and in particular
its ellipsoidal truncation, is able to predict accurately the collapse, in the
orbit-crossing sense, of generic mass elements. Some points that have undergone
orbit crossing are assigned to the network of filaments and sheets that
connects the halos; it is demonstrated that this network resembles closely that
found in N-body simulations. The code generates a catalogue of dark matter
halos with known mass, position, velocity, merging history and angular
momentum. It is shown that the predictions of the code are very accurate when
compared with the results of large N-body simulations that cover a range of
cosmological models, box sizes and numerical resolutions. The mass function is
recovered with an accuracy of better than 10 per cent in number density for
halos with at least 30-50 particles. A similar accuracy is reached in the
estimate of the correlation length r_0. The good agreement is still valid on
the object-by-object level, with 70-100 per cent of the objects with more than
50 particles in the simulations also identified by our algorithm. For these
objects the masses are recovered with an error of 20-40 per cent, and positions
and velocities with a root mean square error of ~1-2 Mpc (0.5-2 grid lengths)
and ~100 km/s, respectively. The recovery of the angular momentum of halos is
considerably noisier and accuracy at the statistical level is achieved only by
introducing free parameters. The algorithm requires negligible computer time as
compared with performing a numerical $N$-body simulation.
