  We investigate the alignment of the spin of dark matter halos relative (i) to
the surrounding large-scale filamentary structure, and (ii) to the tidal tensor
eigenvectors using the Horizon 4pi dark matter simulation which resolves over
43 million dark matter halos at redshift zero.
  We detect a clear mass transition: the spin of dark matter halos above a
critical mass tends to be perpendicular to the closest filament, and aligned
with the intermediate axis of the tidal tensor, whereas the spin of low-mass
halos is more likely to be aligned with the closest filament. Furthermore, this
critical mass of 5 10^12 is redshift-dependent and scales as (1+z)^-2.5. We
propose an interpretation of this signal in terms of large-scale cosmic flows.
In this picture, most low-mass halos are formed through the winding of flows
embedded in misaligned walls; hence they acquire a spin parallel to the axis of
the resulting filaments forming at the intersection of these walls. On the
other hand, more massive halos are typically the products of later mergers
along such filaments, and thus they acquire a spin perpendicular to this
direction when their orbital angular momentum is converted into spin. We show
that this scenario is consistent with both the measured excess probabilities of
alignment w.r.t. the eigen-directions of the tidal tensor, and halo merger
histories. On a more qualitative level, it also seems compatible with 3D
visualization of the structure of the cosmic web as traced by "smoothed" dark
matter simulations or gas tracer particles. Finally, it provides extra support
to the disc forming paradigm presented by Pichon et al (2011) as it extends it
by characterizing the geometry of secondary infall at high redshift.
