  We present results from SPH-cosmological simulations, including
self-consistent modelling of SN feedback and chemical evolution, of galaxies
belonging to two clusters and twelve groups. We reproduce the mass-metallicity
(ZM) relation of galaxies classified in two samples according to their
star-forming activity, as parametrized by their sSFR, across a redshift range
up to z=2.
  Its slope shows irrelevant evolution in the passive sample, being steeper in
groups than in clusters. However, the sub-sample of high-mass passive galaxies
only is characterized by a steep increase of the slope with redshift, from
which it can be inferred that the bulk of the slope evolution of the ZM
relation is driven by the more massive passive objects. (...ABRIDGED...)
  The ZM relation for the star-forming sample reveals an increasing scatter
with redshift, indicating that it is still being built at early epochs. The
star-forming galaxies make up a tight sequence in the SFR-M_* plane at high
redshift, whose scatter increases with time alongside with the consolidation of
the passive sequence. We also confirm the anti-correlation between sSFR and
stellar mass, pointing at a key role of the former in determining the galaxy
downsizing, as the most significant means of diagnostics of the star formation
efficiency. Likewise, an anti-correlation between sSFR and metallicity can be
established for the star-forming galaxies, while on the contrary more active
galaxies in terms of simple SFR are also metal-richer.
  We discuss these results in terms of the mechanisms driving the evolution
within the high- and low-mass regimes at different epochs: mergers,
feedback-driven outflows and the intrinsic variation of the star formation
efficiency.

Cosmology and Nongalactic Astrophysics;Astrophysics of Galaxies