I'd say that if it's sweet, you could use "pastel" for most cases, I'd use "tarta" for cakes or pies and depending the size, a pastry could be a "pastel" or "pastelillo".
"bizcocho" is definitely for sponge cakes, and a cupcake is a "magdalena".
If the pastry or pie is salty, like shepherd's pie or chicken pot pie, that would be "empanada" or if it's small, "empanadilla".
"Torta" doesn't sound familiar to me, it's probably the more localized term of all meaning that it would be probably different depending on the country and even the region.