We study mass-deformed N = 2 gauge theories from various points of view. Their partition functions can be computed via three dual approaches: firstly, (p, q)-brane webs in type II string theory using Nekrasov's instanton calculus, secondly, the (refined) topological string using the topological vertex formalism and thirdly, M theory via the elliptic genus of certain M-strings configurations. We argue for a large class of theories that these approaches yield the same gauge theory partition function which we study in detail. To make their modular properties more tangible, we consider a fourth approach by connecting the partition function to the equivariant elliptic genus of C 2 through a (singular) theta-transform. This form appears naturally as a specific class of one-loop scattering amplitudes in type II string theory on T 2 , which we calculate explicitly.