  We present an empirical model for the number of globular clusters (GCs) in
galaxies based on recent data showing a tight relationship between dark matter
halo virial masses and GC numbers. Based on these relations, our model forms
GCs in haloes with masses between $M_\mathrm{seedGC} = 3.2 \times
10^8\,\mathrm{M}_\odot$ and $4.7 \times 10^8\,\mathrm{M}_\odot$, depending on
the observations used for calibration. We confirm previous works that reported
the observed linear correlation as being a consequence of hierarchical merging
and its insensitivity to the exact GC formation processes at higher virial
masses. We find that the scatter of the linear relation is strongly correlated
with the relative amount of smooth accretion: the more dark matter is smoothly
accreted, the fewer GCs a halo has compared to other haloes of the same mass.
This scatter is smaller than that introduced by halo mass measurements,
indicating that the number of GCs in a galaxy is a good tracer for its dark
matter mass. Smooth accretion is also the reason for a lower average dark
matter mass per GC in low-mass haloes. The resulting linear relation and its
scatter are independent of redshift up to $z = 6$, as well as the average
amount of smooth accretion. Finally, we successfully reproduce the observed
general trend of GCs being old and the tendency of more massive haloes hosting
older GC systems, while failing to obtain the younger GC populations found in
some galaxies, clearly indicating the need for an additional GC formation
mechanism.
