  We study the relation between halo mass and its environment from a
probabilistic perspective. We find that halo mass depends not only on local
dark matter density, but also on non-local quantities such as the cosmic web
environment and the halo-exclusion effect. Given these accurate relations, we
have developed the HADRON-code (Halo mAss Distribution ReconstructiON), a
technique which permits us to assign halo masses to a distribution of haloes in
three-dimensional space. This can be applied to the fast production of mock
galaxy catalogues, by assigning halo masses, and reproducing accurately the
bias for different mass cuts. The resulting clustering of the halo populations
agree well with that drawn from the BigMultiDark $N$-body simulation: the power
spectra are within 1-$\sigma$ up to scales of $k=0.2\,h\,{\rm Mpc}^{-1}$, when
using augmented Lagrangian perturbation theory based mock catalogues. Only the
most massive haloes show a larger deviation. For these, we find evidence of the
halo-exclusion effect. A clear improvement is achieved when assigning the
highest masses to haloes with a minimum distance separation. We also compute
the 2- and 3-point correlation functions, and find an excellent agreement with
$N$-body results. Our work represents a quantitative application of the cosmic
web classification. It can have further interesting applications in the
multi-tracer analysis of the large-scale structure for future galaxy surveys.
