  The galaxy luminosity function and galaxy stellar mass function are
fundamental statistics in the testing of galaxy formation models. Theoretical
predictions based on cosmological simulations can deviate from observations,
especially at the bright and faint ends. In this case, the mismatch may come
from missing physics, oversimplified or inaccurate model recipes, or
inappropriate methods of extracting basic astrophysical quantities from
simulations. The latter is a crucial aspect to consider to avoid misleading
conclusions when comparing simulations with observations. In this paper, we
have applied a new method to produce `observed' galaxies identified in mock
imaging of hydrodynamical simulations. We generate low-redshift mock galaxies
from the TNG100-1 simulation of IllustrisTNG and analyse them using standard
`observational' techniques to extract their main structural parameters. We show
that our technique can produce realistic surface-brightness distributions of
the simulated galaxies, including classical morphological substructures, such
as spiral arms and bars. In particular, we find a very good agreement of the
total luminosity and stellar mass versus halo mass relationships, and the
galaxy stellar mass versus size relationship between mock observations and real
galaxies. We also compare the luminosity function and the mass function of the
mock galaxy sample with literature data and find a good agreement at all
luminosity and mass scales. In particular, we find no significant tension at
the bright end of the galaxy luminosity function, as reported in many analyses
using simplified recipes to identify galaxy haloes, which in fact miscount the
contribution of the extended galaxy haloes around large galaxies. This
demonstrates the critical impact of using observational driven approaches to
the simulation analyses to produce realistic predictions to compare to
observations.
